%{
my $INT = '(int)\b';
my $ID = '([a-zA-Z_][a-zA-Z_0-9]*)';
my $NUM = '(\d+)';
my $ISDEC;
%}
%token NUM = /$NUM/
%token INT = /$INT/
%token ID = /$ID/
%right '='
%left '+'
%conflict decORexp { }
%explorer decORexp {
#print "***********************\n";
$ISDEC = $self->YYPreParse('decl',
#0xF # debug
);
if ($ISDEC) { $self->YYSetReduce2('ID:DEC' ); }
else { $self->YYSetReduce2('ID:EXP' ); }
}
%expect-rr 1 # expect 1 reduce-reduce conflict
%tree bypass
%%
prog:
%name EMPTY
/* empty */
| %name PROG
prog %decORexp? stmt
;
stmt:
%name EXP
expr ';'
| %name DECL
decl
;
expr:
%name ID:EXP
ID %PREC decORexp
| %name NUM
NUM
| %name TYPECAST
INT '(' expr ')' /* typecast */
| %name PLUS
expr '+' expr
| %name ASSIGN
expr '=' expr
;
decl:
%name DECLARATOR
INT declarator ';'
| %name DECLARATORINIT
INT declarator '=' expr ';'
;
declarator:
%name ID:DEC
ID %PREC decORexp
| '(' declarator ')'
;
%%
####################################################
=head1 SYNOPSIS
Compile it with
eyapp -C CplusplusExplorerOnly
This compiletion must produce warnings
eyapp -S decl -C CplusplusExplorerOnly
Execution:
./CplusplusExplorerOnly.pm -t -i -c 'int (x) + 2; int (z) = 4;'
=cut