Exercise 4:

Grammar for Pascal expressions
The set of tokens is {=, <>, <, >, <=, >=, in, +, -, *, /, div, mod, not, and, or, [, ], (, ), ., ,, .., ^, nil, IDENT, NATURAL_LIT, REAL_LIT, CHAR_LIT, STRING_LIT}. Most of the tokens are keywords or special symbols, except for the uppercase-named ones, whose associated regular languages are:

The following table shows the list of Pascal operators, sorted by priority (from highest to lowest):

Category Operator Associativity
Unary not not Right
Multiplying operators * / div mod and Left
Adding operators and unary signs + - or Left (binary +, -, or) and Right (unary +, -)
Relational operators = <> < > <= >= in None

Note that unary signs (+ and -) do not have precedence over other adding or more prioritary operators. Thus, they cannot appear after any of them. For instance, “not -1” and “4 + -1” are not valid expression, because the unary sign - appears after some operator. On the other hand, “- not 1”, “-1 + 4” and “4 + (-1)” are valid. Moreover, “+2 < -1” is also valid, since < is a relational operator, and those have lower precedence.

At the bottom of the operator chain, we have a factor. A factor can be any of the following things: Remarks about the AST construction:
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.