For this assignment, we will be writing a parser that is able to parse an input file written in our Tiny grammar. You should finish writing the Parser class that Ive provided. Your Parser class should print:
Each time it enters or leaves a rule and what the rule is:Entering RULENAME RuleExiting RULENAME RuleThere are two exceptions: the ID and the INT rules. In this grammar, ID and INT are also Token names, so we will not print when we are entering or exiting those rules since we can just check the token type.
Each time it recognizes a token and what the token was:Found TOKENTYPE Token: LEXEMEFor rules with Epsilon definitions, you should also indicate if that definition was chosen:Did not find TOKENTYPE or TOKENTYPE Token, choosing EPSILON production
Something, everytime it catches an error:Expected TOKENTYPE found LEXEMEWhen the error could have been multiple things, separate the token types with the word orExpected TOKENTYPE or TOKENTYPE or TOKENTYPEfound LEXEME
How many parse errors were foundThere were X parse errors found.
Parser.rb extends Scanner.rb The lexer that you wrote for your last assignment and provides a framework for a topdown, recursivedescent parser of the TINY language. The parser stays one token ahead in the Token stream lookahead and uses the Token to predict how to continue parsing the current instruction and which method to call next.
The consume method calls nextToken in the scanner. The current lookahead Token is discarded, and the next Token in the stream is retrieved. Whitespace Tokens are discarded.
The matchdtype method tries to match the lookahead Token with the provided type dtype. If a match is found, consume is called to retrieve the next Token. Otherwise an error message is displayed and then consume is called to retrieve the next token.
The program method is first called to parse a TINY program. Since a TINY program consists of a sequence of statements, program calls statement repeatedly until it encounters the EOF token.
Complete the parser by providing methods for the appropriate BNF rules in TINY.
I have given you my lexer and token ruby classes. I have also partially written the parser for you and have written a main.rb file that can run your ruby parser. Your assignment is to FINISH WRITING THE PARSER parser.rb.
I have also included 5 sample input files that you can use to test your program once youve finished writing it.
input13.txt should complete with no parse errors.
input45.txt should have parse errors.
Below are screenshots of what your output should look like, based on the input files Ive provided.
input3.txt
input4.txt
input5.txt
Reviews
There are no reviews yet.