Use any programming language you prefer to write a


Submission: Please upload the following to the CMS.
1. Source code
2. A screen shot of the execution of your program including the input file you used

Use any programming language you prefer to write a recursive-descent parser that parses the language generated by the following EBNF descriptions. Your parser should detect whether or not the input program has any syntax errors. It does not have to specify what and where the error is.

→ begin end
{;}
|
=
→ identifier (An identifier is a string that begins with a letter followed by 0 or more letters and digits)
{ (+|-) }
→ while ()
® (< | >) (Assume that logic expressions have only less than or greater than operators)

You can use the following examples to test your parser.
An input program without syntax errors:

begin

total = var1 + var2;

while (var1 < var2)

     while ( var3 > var4)

                 var2 = var2 - var1

end

 

Some input programs with syntax errors:

 

total = var1 + var2;

while (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1

end

The keyword begin is missing

 

begin

total = var1 + var2;

while (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1;

end

The last statement should not end with a semicolon

 

begin

total = var1 + var2;

whie (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1

end

The keyword while is misspelled

Solution Preview :

Prepared by a verified Expert
Programming Languages: Use any programming language you prefer to write a
Reference No:- TGS0653890

Now Priced at $40 (50% Discount)

Recommended (98%)

Rated (4.3/5)