help-bison
[Top][All Lists]
Advanced

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

yychar question


From: Davy Durham
Subject: yychar question
Date: Fri, 26 Jan 2001 10:17:14 -0600

Hey..... I was wondering if anyone knows if there could be a problem
with modifying yychar (the look-ahead token)...

    See, in my grammar I have these 2 rules that I really like the way
they are, except that they are ambiguous with a single look-ahead
token.  But I'm not here to wish bison generated an LR(k) or anything,
Infact I would need infinite look-ahead because the amount of tokens
between the beginning of the rule and then part where you *can*
distinguish is a list which can be any length...
    I could resolve the problem simply by having 1 of the rules have to
be prefixed with some symbol or keyword like '$' or something.... Then
if a '$' was encountered then that production (and no other) should
occur next in the token stream.... But since I want the rules to stay
the same and not burden the programmer about remembering to put that
prefix, I thought I'd help out bison a little by looking ahead myself...

    So, I changed my lexer to be able to get tokens from the past.. Now
when I'm about to get either rule I save the current token position,
then look ahead myself to see the distinguishing pattern is there.  And
based on that I rewind the lexer back to where it was then do or don't
synthetically insert that symbol that the programmer would have typed to
prefix the statement (actually it's a defined token, not a symbol)...
    However the way I insert that symbol is to modify yychar to be the
inserted symbol (and backup the lexer 1 more token so it will get the
look-ahead that I overwrote again).   I suppose I should not back it up
that extra amount if there wasn't a look-ahead token at all (by seeing
if yychar==YYEMPTY)...
    I just wanted to know if anyone could see a probem with actually
modifying yychar... I didn't want to use YYBACKUP because it errors if
there is already a look-ahead... I handle that problem by backing up the
lexer 1 extra token...

    If anything I think it's a pretty neat way of making bison be more
powerful than it is.. I would *not* want to do this all over a grammar..
I just REALLY like my grammar the way it is for the programmer...  And
it seems to be pretty solid; it passes all 60 or so test cases I
have..   If worse comes to worst and this idea just really craps out
with some source code, the worst I have to do is make the programmer put
a distinguishing character or keyword infront of one of the statement
types....

Thanks,
    Davy




reply via email to

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