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)

var 2 = var2 - var 1

end

Input programs containing syntax errors:

total = var1 + var2;

loop (var1 < var2)

loop (var3 > var4)

var 2 = var2 - var 1

end

The keyword begin is missing

begin

total = var1 + var2;

loop (var1 < var2)

loop (var3 > var4)

var 2 = var2 - var 1

end

The last statement shouldn't end with a semicolon.

begin

total = var1 + var2;

loop (var1 < var2)

var 2 = var2 - var1

end

The keywords loops is misspelled.

Solution Preview :

Prepared by a verified Expert
Programming Languages: Implement a lexical and syntax analyzer based on the
Reference No:- TGS02181595

Now Priced at $30 (50% Discount)

Recommended (93%)

Rated (4.5/5)