%strict %token ID INT NUM %right '=' %left '+' %% prog: /* empty */ | prog stmt ; stmt: expr ';' | decl ; expr: ID | NUM | INT '(' expr ')' /* typecast */ | expr '+' expr | expr '=' expr ; decl: INT declarator ';' | INT declarator '=' expr ';' ; declarator: ID | '(' declarator ')' ; %% =head1 C++ Ambiguities This grammar models a problematic part of the C++ grammar — the ambiguity between certain declarations and statements. For example, int (x) = y+z; parses as either an expr or a stmt. =head1 SEE ALSO =over 2 =item * L =item * L =item * L =item * L =item * Edward Willink's "Meta-Compilation for C++" PhD thesis at L =back =cut