(→Solution) |
|||
Line 81: | Line 81: | ||
bfactor -> not bfactor | ( bexpr ) | true | false | bfactor -> not bfactor | ( bexpr ) | true | false | ||
− | 4. The following analysis considers the grammar defined in 3. | + | 4. The following analysis considers the grammar defined in 3 (again, terminals are in blue and non-terminals in black). |
<graph> | <graph> |
Consider the following grammar:
bexpr -> bexpr or bexpr | bterm bterm -> bterm and bterm | bfactor bfactor -> not bfactor | ( bexpr ) | true | false
1. The terminal symbols are all the symbols not defined by a rule: or, and, not, (, ), true, false.
2. The following trees are possible for true and false and true (an analogous analysis could be done for or). Terminals are in blue and non-terminals in black.
3. The following grammar selects left associativity for the binary operators (and and or):
bexpr -> bexpr or bterm | bterm bterm -> bterm and bfactor | bfactor bfactor -> not bfactor | ( bexpr ) | true | false
4. The following analysis considers the grammar defined in 3 (again, terminals are in blue and non-terminals in black).