Question: In this project you are to implement a scanner and a recursive descent parser for a small programming language ( let ' s call it
In this project you are to implement a scanner and a recursive descent parser for a small programming language lets call it Hawk Your program will take as input a program written in the provided language. In addition to parsing the input programs, your program must generate the proper errors when encountered.
The following is the grammar that you will use:This grammar has rules. It also has reserved words in it indicating that they cannot be used for identifiers. Nonterminal symbols are those that are capitalized, and terminal symbols are those that are lowercase. Many rules have alternative choices, for example Rule has two alternatives, one without an else, and one with and else.
The following are the lexemes for the language:
Reserved words: program, begin, end, if then, else, input, output, int, while, loop.
Operators: assignment : less than greater than equals not equals plus minus multiply divide and parentheses.
The ; is also used to terminate statements and the and the : are used when declaring variables.
Identifiers: start with a letter or an followed by any number of letters, digits or underscores.
Numbers: Either integer numbers max digits or floating point numbers max digits
Upon encountering a variable in a declaration section, you must add it to the symbol table. This means that a redeclaration of a variable should produce an error and exit the program. The use of a variable before it is declared should also produce an error indicating an undeclared identifier and exit the program.
Other errors that could be generated upon scanning and parsing a program:
Illegal symbol
Illegal identifier
Illegal number
Parse errors encountered by expecting a symbol and not getting that symbol.
All errors must indicate the line number in the file. All error message must be descriptive as well indicating what happened precisely. Upon encountering an error, you must exit the program immediately after reporting the error and its location.
You will be provided with some test cases to use to test your program. However, your implementation should work with other test cases. So you are encouraged to generate your own test cases to make them work with your parser.
Programs that pass the parser and the scanner should output the lefthand side of the rules that it followed. No need to worry about producing rules and as they are more about the scanner than the parser. Make sure no spaces before or after the output are produced. You must produce the output as describe, see the below examples. Programs that have errors should produce the same output until they reach an error and then produce a statement indicating the error type and exit.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
