Specification of Programming #2: Lexical Scanner             

                                                                                         

1. Read this overview description of the lexical scanner module and play with this zipped sample executable to get a sense of what the lexical scanner module can accomplish for us.

 

2. References: (i) Review Section 3.2 of C++ Primer (5th Ed.) to know basics of C++ string class and how to check whether a character is a letter, a digit, or else using library functions in the library <cctype>.  (ii) Review Section 3.5.4 about old c style character arrays and how to convert a numeric string (such as “1.23”) stored in a character array into the corresponding numerical value (such as 1.23) using the atof library function in the library <cstdlib>.

 

3. Download this code framework from the class website as a starting point to get a project of three files: lexScanner.h, lexScanner.cpp, and testScanner.cpp.

 

4. Implementing the LexicalScanner class: Complete the implementation of all the member functions of the LexicalScanner class in lexScanner.cpp

                                 i.         In Section 1, note that the getPerLineTokenVectFromOneStringObject method is already implemented for you and you can call it to extract all the tokens in a given string object and store the tokens as a vector of string (i.e. a PerLineTokenVect object). 

                               ii.         In section 2, there is a collection of member functions for checking the category of a given token. You should fill in code to complete the implementation of several functions as described by the comments to make the code fully functional.

                              iii.         In section 3, you should implement the getCategoryVectorFromTokenVector method, which can retrieve the category information from a given token vector and store them in a category vector.

                              iv.         In section 4, you need to implement the getLexicalInfo method, which is the most important member function to implement in the LexicalScanner class. To implement the getLexicalInfo method, you should use a loop to extract lexical information from the lines of statements one line at a time. The overall task of getLexicalInfo method is to extract from lines of statements and store the lexical information into a vector of token vectors and a vector of category vectors. This is very much like what you did in Lab#2 except that on each iteration (i) you should first call getPerLineTokenVectFromOneStringObject to retrieve the tokens from one line of statement and store them as a token vector, and (ii) you should then call getCategoryVectorFromTokenVector to retrieve the category information from the token vector and store them as a category vector.

                                v.         If you like, you can earn an extra bonus point by writing your own version of getPerLineTokenVectFromOneStringObject function in Section 1 and the displayLexicalInfo function in Section 5 in lexScanner.cpp totally from scratch.

 

5. Integration with the interface module

 

 

6. Submission: By the due date, compress and submit your Visual C++ 2103 programming project folder (with source .h & .cpp files in it) and the self-evaluation report of Programming #2 as a zip file under Canvas. Make sure you have done Step 5 to integrate both modules together and add an option of lexical analysis when interacting with the user.

 

 

Notes: