Question 1 | Question 2 | Question 3
The grammer in CNF (note: choice of names for introduced non-terminals is not unique):
id → ID
eq → =
sem → ;
add → +
sub → -
stmt → id st1
st1 → eq st2
st2 → exp sem
exp → id tail
| ID
tail → add exp
| sub exp
grades → oneGrade grades → oneGrade COMMA grades
The rules with a common prefix are the ones with grades on the left. Here are the transformed rules:
grades → oneGrade grades' grades' → ε | COMMA grades
The rules with immediate left recursion are the ones with stars on the left. Here are the transformed rules:
stars → STAR stars' stars' → STAR stars' | ε
| Nonterminal X | FIRST(X) | FOLLOW(X) |
|---|---|---|
| program | { | EOF |
| stmts | ID, IF, ε | } |
| stmt | ID, IF | ID, IF, } |
| exp | ID | ;, ) |
| tail | +, -, ε | ;, ) |
Last Updated: 3/5/2025 © 2025 CS 536