Implement a lexical and syntax analyzer based on the


Programming Assignment

Implement a lexical and syntax analyzer based on the following grammar. Your analyzer should read an input test program from a file and then determine if it contains a syntax error. It does not have to show where the syntax error occurs or what kind of error it is.

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

Use the examples below to test your analyzer.
Input program with no syntax errors:

begin

total = var1 + var2;

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

end

Input programs containing syntax errors:

total = var1 + var2;

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

end

begin

total = var1 + var2;

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

end

The keyword begin is missing.

The last statement shouldn't end with a semicolon.

begin

total = var1 + var2;

lop (var1 < var2)
var2 = var2 - var1

end

The keyword loop is misspelled.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Implement a lexical and syntax analyzer based on the
Reference No:- TGS02191936

Expected delivery within 24 Hours