Question: Implementing a Scanner and Parser for a Simple Language A compiler converts a source language program into a target language program. There are some basic

 Implementing a Scanner and Parser for a Simple Language
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:  ->'end'  ->| ----- note: this is equivalent to |  -> ID '='  |'read' ID |'write'   ->  {('+'|'-')}  ->  {('*'|'/') }  -> ID | INT_CONSTANT |'('')' 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. 

follow the following : 1. You may use any language of your choice to write your program. Howeprogram must compile and run on pluto or vcl. 2. Programs can be read from keyboard instead of file. 3. Sample runs can be found Note : All your source code 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. 

The output should be like this

Output for Assigment 2 File sample1 contains read a read b result = (a + b)/2 write result end starting the process... Call lex...read Enter  Enter  Enter  Call lex...a Call lex...read Exit  Enter  Enter  Call lex...b Call lex...result Exit  Enter  Enter  Call lex...= Call lex...( Enter  Enter  Enter  Call lex...a Enter  Enter  Enter  Call lex...+ Exit  Exit  Call lex...b Enter  Enter  Call lex...) Exit  Exit  Exit  Call lex.../ Exit  Call lex...2 Enter  Call lex...write Exit  Exit  Exit  Exit  Enter  Enter  Call lex...result Enter  Enter  Enter  Call lex...end Exit  Exit  Exit  Exit  Enter  Exit  Exit  Exit  Exit  Exit  This is a valid program File sample2 contains read a read b result = (a+b/2 write result end starting the process... Call lex...read Enter  Enter  Enter  Call lex...a Call lex...read Exit  Enter  Enter  Call lex...b Call lex...result Exit  Enter  Enter  Call lex...= Call lex...( Enter  Enter  Enter  Call lex...a Enter  Enter  Enter  Call lex...+ Exit  Exit  Call lex...b Enter  Enter  Call lex.../ Exit  Call lex...2 Enter  Call lex...write Exit  Exit  Exit  ERROR: No closing parentheses. File sample3 contains read a read b result = (a + b) * 2 write result starting the process... Call lex...read Enter  Enter  Enter  Call lex...a Call lex...read Exit  Enter  Enter  Call lex...b Call lex...result Exit  Enter  Enter  Call lex...= Call lex...( Enter  Enter  Enter  Call lex...a Enter  Enter  Enter  Call lex...+ Exit  Exit  Call lex...b Enter  Enter  Call lex...) Exit  Exit  Exit  Call lex...* Exit  Call lex...2 Enter  Call lex...write Exit  Exit  Exit  Exit  Enter  Enter  Call lex...result Enter  Enter  Enter  Call lex...EOF Exit  Exit  Exit  Exit  Enter  ERROR: no ending File sample4 contains read a read b result = ( a + b) 2 write result end starting the process... Call lex...read Enter  Enter  Enter  Call lex...a Call lex...read Exit  Enter  Enter  Call lex...b Call lex...result Exit  Enter  Enter  Call lex...= Call lex...( Enter  Enter  Enter  Call lex...a Enter  Enter  Enter  Call lex...+ Exit  Exit  Call lex...b Enter  Enter  Call lex...) Exit  Exit  Exit  Call lex...2 Exit  Exit  Exit  Exit  Enter  Enter  ERROR: Invalid statement. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!