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, 22.06.2019 04:30
Kyle, a receptionist for a building supply company, recently won an award for saving his company money on their phone system. after being presented with kyle's research, the company changed the way in which it made long-distance phone calls and cut their expenses in this area by 75 percent. the new system the kyle's company most likely adopted was wired communications switching stations voip hdtv
Answers: 3
question
Computers and Technology, 22.06.2019 15:00
Which of the following statements tests if students have a grade of 70 or above, as well as fewer than five absences? a: if(grade > = 70 and daysabsent < = 5): b: if(grade > = 70 or daysabsent < = 5): c: if(grade > 70 and daysabsent < = 5): d: if(grade > 70 or daysabsent < = 5): i took the test the answer is a
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
question
Computers and Technology, 23.06.2019 07:50
Apython programming question: assume s is a string of lower case characters. write a program that prints the number of times the string 'bob' occurs in s. for example, if s = 'azcbobobegghakl', then your program should print number of times bob occurs is: 2
Answers: 3
You know the right answer?
Implementing a Scanner and Parser for a Simple Language A compiler converts a source language prog...
Questions
question
Mathematics, 11.01.2021 18:20
question
Mathematics, 11.01.2021 18:20
question
Mathematics, 11.01.2021 18:20
question
Mathematics, 11.01.2021 18:20
Questions on the website: 13722359