[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When %dprec and %merge aren't enough...
From: |
Hans Aberg |
Subject: |
Re: When %dprec and %merge aren't enough... |
Date: |
Fri, 14 Nov 2008 19:53:39 +0100 |
On 14 Nov 2008, at 19:35, Marcel Laverdet wrote:
This is a pretty good idea, but I'm not sure if it's possible. For
instance in the case of an if statement I modified my grammar as such:
if_statement:
t_IF t_LPAREN expression t_RPAREN {yyexpect_statement;}
statement t_ELSE statement
<...>
| t_IF t_LPAREN expression t_RPAREN {yyexpect_statement;}
statement %prec p_IF
<...>
;
Where yyexpect_statement is a macro I defined to set a global flag
and then the lexer checks and returns an appropriate t_LCURLY for
statements. The problem I'm seeing here is that the glr parser
defers my mid-action rule so the lexer can't adjust in time.
Indeed, for that reason, those two methods do not mix well. There has
been talk about admitting GLR actions that are executed immediately,
but don't hold your breath.
So you need the parts with the context switches being unambiguous. In
addition, lookahead is unpredictable, so typically context switches
should be put close to tokens. But one can go quite far with this
technique: one has been able to make C++ into a (non-GLR) LALR(1)
grammar this way.
http://www.parashift.com/c++-faq-lite/compiler-
dependencies.html#faq-38.11
Hans