help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to resolve a shift/reduce conflict in simple grammar


From: John R. Levine
Subject: Re: How to resolve a shift/reduce conflict in simple grammar
Date: 27 Nov 2009 15:33:45 -0500
User-agent: Alpine 2.00 (BSF 1167 2008-08-23)

seq0        : '0' seq0 | '0' ;
seq1        : '1' seq1 | '1' ;
and '1' and to resolve it by the shift:

%right '0' '1'

but it would mask any other conflicts involving 0 and 1, so I'd use the
expect so you'll see any other unintended conflicts.


If you have a classic flex/bison setup and want this greedy behavior, I'd 
recommend simply putting the sequences in the lexer:

flex:
- - - - - - - - - -
0+ { yylval.num = strlen(yytext); return ZEROS; }
1+ { yylval.num = strlen(yytext); return ONES; }
- - - - - - - - - -

If it were indeed just a sequence of digit zero or one, I would agree, but I presume the actual stuff in the lists is considerably more complex.

Even if it were, your flex patterns won't work if the language allows white space or comments between the tokens.

R's,
John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]