TASK: in this
assignment you will write a Java
program to implement a lexical analyzer (scanner) and a syntax analyzer(recursive
descent parser) for the following
language, which similar to the syntax of Ada:
******* GRAMMAR for
the parser **********************
<program> à
procedure name begin
<stmt_list> end ;
<stmt_list> à <stmt> ;{ <stmt_list}*
<stmt>à
<assign> | <if>
<if> à if ( <bool>
) then <stmt_list>
[ else <stmt_list>] endif;
!!! NOTE items that are bold are PART of the construct, and thus terminal
symbols
<assign> à
<var>: = <expr>; //
assignment is := in Ada
<expr> à <term> { ( + | - | * | / ) <term> }
<term> à
<var> | <int>
<bool> à <var>(= | !=) <int>
** NOTE THE name on
the procedure and end statement must match, and must be a valid identifier
********* description of identifiers, and integer literals for the scanner *****
<letter> à a
| b |
c | d
| e | … |
z | A
| … | Z
<digit> à 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<letterdigit> à <letter> | <digit>
<var> à <letter><letterdigit>*
<int> à <digit><digit>*
procedure calculate
begin
x := 10;
y := 3;
val1:= x - 6 + y;
end;
procedure sum
begin
x :=
10;
y := x
- 3
sum := x + y;
end ;
<<<< NOTE the missing semicolon in the second
expression. >>>>>>
**** These samples
can be saved into a file of type txt and
used as input to your lexical analyzer ***
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 1 | 2 |