Project #1 Sample - Lexical Scanner

Version 1.0,
Due Date: Already Completed - find code here
Note:
This is a demonstration project, which you are not expected to implement.
Instead, you will implement the projects linked on the Synchronous pages.

Purpose:

The four sample projects focus on building software tools for code analysis in a series of steps, one step for each project. We will emphasize C++ code but want our tools to be easily extendable to other similar languages like C# and Java.
Code analysis consists of extracting lexical content from source code files, analyzing the code's syntax from its lexical content, and building an Abstract Syntax Tree (AST) that holds the results of our analysis. It is then fairly easy to build several backends that can do further analyses on the AST to construct code metrics, search for particular constructs, or some other interesting features of the code.
You will find it useful to look at the Parsing blog for a brief introduction to parsing and code analysis.
In this first project we will build and test a lexical scanner in C++ that consists of two packages:

Requirements:

Your Lexical Scanner:
  1. Shall be written in C++, using the standard C++ libraries. You may also use helper code provided in the course Repository.
  2. Shall use Visual Studio, Community Edition available at no cost.
  3. The tokenizer package shall provide a Toker class implemented using the State Pattern1.
  4. Single and double quoted strings shall be collected as single tokens. Comments shall be discarded2.
  5. The tokenizer shall support the collection of specified single characters as tokens, even if surrounded by other punctuators. Please make the characters { '.', ';', ':', '#', '=', '>', '<', '[', ']', '{', '}', '\n' } default single character tokens.
  6. The tokenizer shall supercede the above for specified two character sequences { "<<", ">>", "==", "::" } which shall be collected as two character tokens.
  7. Shall provide tokenizer member functions to provide alternate one and two character token sequences.
  8. Shall provide a semi-expression package as specified below.
  9. The semi-expression package shall provide a SemiExp class that holds an ordered sequence of tokens, collected from the tokenizer. The order is the order retrieved from the Toker class.
  10. This package shall use the characters { '{', '}', ';', ':', '\n' }. The character ':' is a terminator only if preceded by the keywords "public", "protected", or "private". The character '\n' is a terminator only if '#' is the first character on the line containing '\n'.
  11. Instances of the SemiExp class shall be indexable, with input an integer, and output the token at that index of the token collection held by the instance.
You may find that additional member functions will be useful for parsing C++ source code.

  1. Here's a reasonably useful tutorial on the State Pattern.
    You will find it useful to define character consumers as states, e.g., eatWhiteSpace, eatAlphNum, eatPunctuator, ...
  2. You may wish to make collecting comments as single tokens an option, but if so, please make discarding comments the default.

What you need to know:

In order to successfully meet these requirements you will need to know:
  1. The definition of the term package and have looked carefully at a few examples.
  2. How to use C++ inheritance and some of the simpler STL containers, e.g., std::vector<std::string>.