Question: -> START: :END -> {; } -> = | = INT_LITERAL | = | = STRING_LITERAL | = INPUT | = INPUT |PRINT |PRINT |PRINT
| = INT_LITERAL
|
|
|
| = INPUT
|PRINT
|PRINT
|PRINT STRING_LITERAL
|-
|
|
|
-> a|b|c
Make a top down parser for the grammar above. I need you to put it in a parse tree. (It is recommended that you use a generic tree structure provided by your language of choice.)
You will start with the abstraction
If there are no syntax errors then I want you to figure out a way to visualize the parse tree. I think Java has a library that will create it on a Swing Canvas (Jtree). If not you can print it out in text form for example:
Start:
a
=
` b
:End
Approximate pseudo-code for the parser:
void Program() {
lex()
if(currentToken!="START") {
print ERROR;
}
statement_list()
if(currentToken!="END")
{
print ERROR
}
}
void statement_list()
{
statement()
while(nextToken==";")
{
lex()
statement()
}
void statement(){
//some code here
}
}
I have already built the lexical analyzer for this assignment, so all I need is to build the Top-down parser. But if you want you can supply your own lexical analyzer
I would be glad to get any assitance for this assignment. Thanks in advance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
