Implement a scanner for the Mojo language, which takes
input from the standard input stream (System.in), writes error
messages to the standard error stream (System.err), and writes output
to the standard output stream (System.out). The scanner should print
each recognized token and its corresponding lexeme on the standard output one
line at a time. Input files can be any sequence of Mojo tokens.
Use the following template for your JavaCC specification file
Parser.jj
:
PARSER_BEGIN(Parser) public class Parser { } PARSER_END(Parser) TOKEN_MGR_DECLS : { int comment, pragma; public static void main(String[] args) { SimpleCharStream stream = new SimpleCharStream(System.in); ParserTokenManager scanner = new ParserTokenManager(stream); while (true) { try { Token token = scanner.getNextToken(); for (Token t = token.specialToken; t != null; t = t.specialToken) System.out.println(tokenImage[t.kind] + " " + t); if (token.kind == EOF) break; System.out.println(tokenImage[token.kind] + " " + token); } catch (TokenMgrError e) { System.err.println(e.getMessage()); break; } } } }To run your scanner simply invoke the class ParserTokenManager to read from standard input (System.in):
java ParserTokenManager
You should turn in just your JavaCC file (Parser.jj), which implements your scanner, using the turnin command available on CS Unix machines.
Grading will be done using automated scripts to compare your output with a model solution. You should ensure that the output file consists solely of tokens and lexeme strings, one per line of output, as they are scanned from the input. White space and comments should be silently discarded.