This is an exercise from the book: The ANSI C Programming Language, but with a more advanced implementation.
I extended the grammar by eliminating left recursivity and applying left factoring.
dcl ==> A dirdcl
A ==> * A | epsilon
dirdcl ==> id dirdcl1 | ( dcl ) dirdcl1
dirdcl1 ==> ( ) dirdcl1 | [ dirdcl2 | epsilon
dirdcl2 ==> ] dirdcl1 | number ] dirdcl1
* | ( | ) | [ | ] | number | id | $ | |
---|---|---|---|---|---|---|---|---|
dcl | dcl ==> A dirdcl | dcl ==> A dirdcl | dcl ==> A dirdcl | |||||
A | A ==> * A | A ==> epsilon | A ==> epsilon | |||||
dirdcl | dirdcl ==> ( dcl ) dirdcl1 | dirdcl ==> id dirdcl1 | ||||||
dirdcl1 | dirdcl1 ==> ( ) dirdcl1 | dirdcl1 ==> epsilon | dirdcl1 ==> [ dirdcl2 | dirdcl1 ==> epsilon | ||||
dirdcl2 | dirdcl2 ==> ] dirdcl1 | dirdcl2 ==> number ] dirdcl1 |
- The program only supports identifiers with one character.
- Supports one-digit array lengths.
- No support for function args.
- No support for constants declaration.