A compiler converts a source language program into a target language
program. There are some basic stages in compilation process, including
scanning, parsing, semantic analysis, and code generation. For this
assignment, you will implement a scanner and parser for a small language
with its grammar given in BNF notation. The language literals are
enclosed with ‘ ‘ in the CFG below
Context Free Grammar:
<program> -> <stmtlist>'end'
<stmtlist> -><stmt>| <stmt><stmtlist>
<stmt> -> ID '=' <expr>
|'read' ID
|'write' <expr>
<expr> -> <term> {('+'|'-')<term>}
<term> -> <factor> {('*'|'/') <factor>}
<factor> -> ID
| INT_CONSTANT
|'('<expr>')'
The possible set of tokens, represented with regular expressions, includes:
ASSIGN -> =
PLUS -> +
MINUS -> -
TIMES -> *
DIV -> /
LPAREN ->(
RPAREN -> )
ID -> letter(letter|digit)*
Except read, write, and end.
INT_CONSTANT -> digit digit*
LETTER ->[a-zA-Z]
DIGIT ->[0-9]
Your task is to implement a scanner and a parser for this simple language.
Miscellaneous:
1. You may use any language of your choice to write your program. However, your program must compile and run on pluto.
2. Programs can be read from keyboard instead of file.
3. Sample runs can be found in hw2 (will be provided later).
Submission notes
1. All your source code
2. Brief documentation or readme file (i.e. no more than a page), to include the following
a. Instructions on how to build and execute your program
b. Any difficulties you encountered in designing/writing your program
c. What you learn/find from or reflection of this assignment.


0 comments