In the first half of the semester, you will be developing an interpreter for a simple scripting language named SILLY (Simple, Interpreted, Limited Language for You). The EBNF grammar rules for SILLY v. 20.0 are as follows:
Recall that |
denotes alternatives within a rule, [ ]
denotes an optional (0 or 1) element, and { }
denotes a repetitive (0 or arbitrarily many) element. There are no spaces between the characters in an identifier, integer, or string. Otherwise, tokens in the other rules are all separated by whitespace.
Answer the following questions about the syntax of SILLY v. 20 based on the above grammar rules.
id
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
A x1 1x x_1 _x1 a1_b2 a1$b2
expr
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
4 -1 + x 1 + -x ( ( 2 ) ) ( 2 * a ) + 1 1 + ( 2 * a ) not flag not not flag
not true or false 3 + 4 * 5 8 / 4 / 2
vardec
) require a semicolon at the end? Justify your answer by referring to the appropriate grammar rule(s).
repeat
)? Justify your answer by referring to the appropriate grammar rule(s).
if
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
if 2 == 3 { } else if true { if ( a > b ) { { output ; } output "yes" ; max = a ; } min = b ; } else { max = b ; min = a ; }
if
) that is as short as
possible, in terms of number of tokens (where keywords such as if
and true
each count as only one token).while
) that is as short as
possible, in terms of number of tokens (where keywords such as while
and true
each count as only one token).subdecl
) and provide a parse tree for it.
subcall
) and provide a parse tree for it.