CptS 355 Syntax Exercises

In class: Friday, Sept. 21

Consider an expression language with the following binary infix operators:

*, /, not
+, -, mod
=, <, >, <=, >=
and
or
Operators higher on the list have higher precedence. Operators on the same line have the same precedence. All operators associate to the left except and and or which associate to the right..

Parenthesize the subexpressions of the following expressions to show the order in which the operators are evaluated:

b - 1 * a / c mod d
a or c + d and e
a > b or c or d <= 17
Write a grammar for the language that reflects the precedence and associativity rules given.

Give parse trees for each of the expressions above according to your grammar

Change the grammar to allow parenthesized sub-expressions.