Question: -> START: :END -> {; } -> = | = INT_LITERAL | = | = STRING_LITERAL | = INPUT | = INPUT |PRINT |PRINT |PRINT

-> START: :END

-> {;}

-> =

| = INT_LITERAL

| =

| = STRING_LITERAL

| = INPUT

| = INPUT

|PRINT

|PRINT

|PRINT STRING_LITERAL

-> +

|-

|

-> +[];

|+[];

|

-> a|b|c

->w| x|y|z

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 and work your way down. If you encounter any errors you must state that a syntax error has occurred and what statement it occurred on. You will then print out the statement in question. (This may not be as trivial as it sounds, remember you can use data-structures for your lexeme analyzer.) You do not have to try to recover, or state the error, or try to continue the parsing.

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

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!