Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C++代写 | Problem I. Scanning

C++代写 | Problem I. Scanning


Write a scanner (lexical analyzer) for the WLP4 programming language. Your
scanner should read a WLP4 program from standard input and identify the tokens,
in the order they appear in the input. For each token, your scanner should compute
the kind of the token and the lexeme (the string of characters making up the token),
and print it to standard output, one line per token.

For example, the correct output for this WLP4 program

// WLP4 program with two integer parameters, a and b
// returns the sum of a and b
int wain(int a, int b) {
return a + b; // unhelpful comment about summing a and b
INT int
WAIN wain
INT int
ID a
INT int
ID b
RETURN return
ID a
ID b

If the input cannot be scanned as a sequence of valid tokens (possibly separated by
white space as detailed in the WLP4LanguageSpecification.pdf), your program
should print a message containing the string ERROR (in upper case) to standard error.

We recommend that you try to make the error message informative.
Hint: You may wish to modify the starter code given in to solve this
problem. The scanner in the starter code uses the Simplified Maximal Munch
algorithm, together with a DFA for MIPS assembly language tokens, to repeatedly
recognize the longest prefix of a string that is a token and extract the tokens. You
should be able to replace the DFA with one which recognizes WLP4 tokens.