Exercise 1:

Simplified grammar for C expressions
The table below shows the list of C operators, sorted by priority (from highest to lowest).

Category Operator Associativity
Postfix unary () [] -> . ++ -- Left
Prefix unary + - ! ~ ++ -- (type) * & sizeof Right
Multiplicative * / % Left
Additive + - Left
Shift << >> Left
Relational < <= > >= Left
Equality == != Left
Bitwise AND & Left
Bitwise XOR ^ Left
Bitwise OR | Left
Logical AND && Left
Logical OR || Left
Conditional ?: Right
Assignment = += -= *= /= %= >>= <<= &= ^= |= Right
Comma , Left

The grammar of C expressions is not LL(1) because it has some conflicts: the cast operator ((type) expr) shares the first token “(” with a parenthesized expression. Moreover, the size-of operator (sizeof), can be applied to an expression (possibly starting with parenthesis) and to a type such as int, enclosed in parentheses. Thus, both cases share the first token “(”. We resolve these issues by disregarding the cast and size-of operators.

The set of tokens is {\{IDENT, NATURAL_LIT, FLOAT_LIT, CHAR_LIT, STRING_LIT, (, ), [, ], ->, ., ++, --, +, -, !, ~, *, &, /, %, <<, >>, <, <=, >, >=, ==, !=, ^, |, &&, ||, ?, :, ASSIGN_OP,,}\} (mind the last token, which is a comma). The regular language corresponding to each of the uppercase-named tokens is described as follows: Remarks about operators’ syntax and AST construction:
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.