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. 21 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. 21 based on the above grammar rules.
id
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
Q b4 4b a_101 _a101 CU#1
expr
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
4 ( 4 ) x + 1 ( -1 + x ) ( 1 + -x ) ( ( 2 * a ) + 1 ) flag ( not flag ) ( not not flag )
( not true or false ) ( 3 + 4 * 5 ) ( 8 / 4 / 2 )
if
abstraction at the root). If invalid, briefly describe what aspect violates the rules.
if true if ( a > b ) if ( avg >= 90 ) { if x x = 2 max = a output "A" repeat 5 y = 3 elseif elseif ( avg >= 80 ) x = ( x + 1 ) end max = b output "B" end end elseif ( avg >= 70 ) end output "C" end
if
) that is as short as
possible, in terms of number of tokens (where keywords such as if
and end
each count as only one token).repeat
) that is as short as
possible, in terms of number of tokens (where keywords such as repeat
and end
each count as only one token).subdecl
) that is as short as
possible, in terms of number of tokens (where keywords such as sub
and end
each count as only one token).subcall
) that is as short as
possible, in terms of number of tokens (where keywords such as call
and end
each count as only one token).