Computer Science - programming assignment
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.
<program> ( begin <stmt_list> end
<stmt_list> ( <stmt> {;<stmt_list>}
<stmt> ( <assign_stmt> | <while_stmt>
<assign_stmt> ( <var> = <expr>
<var> ( identifier (An identifier is a string that begins with a letter followed by 0 or more letters and digits)
<expr> ( <var> { (+|-) <var>}
<while_stmt> ( while (<logic_expr>) <stmt>
<logic_expr> ( <var> (< | >) <var> (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:
Some input programs with syntax errors:
begin
total = var1 + var2;
while (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1
end
begin
total = var1 + var2;
while (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1;
end
total = var1 + var2;
while (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1
end
The last statement should not end with a semicolon
The keyword begin is missing
The keyword while is misspelled
begin
total = var1 + var2;
whie (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1
end