subject

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 foun.
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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 05:30
Sally is editing her science report about living things. she needs to copy a paragraph from her original report. order the steps sally needs to do to copy the text to her new document.
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
What machine listens for http requests to come in to a website’s domain? a. a router b. a browser c. a server d. a uniform resource locator
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
On early television stations, what typically filled the screen from around 11pm until 6am? test dummies test patterns tests testing colors
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
You know the right answer?
Implementing a Scanner and Parser for a Simple Language A compiler converts a source language prog...
Questions
question
Mathematics, 13.01.2021 08:30
question
Mathematics, 13.01.2021 08:40
question
Mathematics, 13.01.2021 08:40
question
Biology, 13.01.2021 08:40
Questions on the website: 13722367