BEST代写-线上编程学术专家

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

C++代写 | Problem I. Scanning

C++代写 | Problem I. Scanning

本次加拿大代写是C++语法扫描和解析相关的assignment

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
}
is:
INT int
WAIN wain
LPAREN (
INT int
ID a
COMMA ,
INT int
ID b
RPAREN )
LBRACE {
RETURN return
ID a
PLUS +
ID b
SEMI ;
RBRACE }

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 asm.zip 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.

bestdaixie

评论已关闭。