help-bison
[Top][All Lists]
Advanced

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

Re: lookahead and yytext


From: Brad
Subject: Re: lookahead and yytext
Date: Mon, 08 Mar 2010 21:54:22 -0600
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Pretty much. Part of what the single_identifier action does is copy yytext into a std::string, and then it's that std::string that I use from then on.

Actually, just now I changed that IDENTIFIER inside the field_declaration section to single_identifier, and now it works! Why would that make a difference?

-Brad

Chris verBurg wrote:

Are you strcpy'ing off the value of yytext before getting it from $3?

-Chris


On Mon, Mar 8, 2010 at 6:10 PM, Brad <address@hidden <mailto:address@hidden>> wrote:

    Doh, sorry about that. The extra single_identifier was left over
    from when I was trying to debug the problem. The original grammar
    that has the yytext issue didn't have the extra single_identifier.
    Ignore it.

    -Brad

    Chris verBurg wrote:

        Hey Brad,

        Do you mean to have "single_identifier" listed twice for the
        first method_header grammar?  That's the only thing I can
        think of that would cause this problem.  Honestly I wouldn't
        think it would get past the lexer, since "(" should have been
        returned as a LPAREN instead of a single_identifier.

        -Chris


        On Mon, Mar 8, 2010 at 5:21 PM, Brad <address@hidden
        <mailto:address@hidden> <mailto:address@hidden
        <mailto:address@hidden>>> wrote:

           Here is a snippet from my grammer that parses a C++-like
        language.

           field_declaration:
             modifiers_opt type IDENTIFIER SEMICOLON
             {
                 /* stuff */
             }
             ;

           method_header:
             modifiers_opt type single_identifier single_identifier
        LPAREN RPAREN
             {
                 /* stuff */
             }
             | modifiers_opt VOID single_identifier LPAREN RPAREN
             {
                 /* stuff */
             }
             ;

           single_identifier:
             IDENTIFIER { /* stuff with yytext */ }
             ;

           field_declaration and method_header are similar enough that
        Bison
           has to look for the following LPAREN (right?). The problem I'm
           having is that yytext inside single_identifier is a '('
        instead of
           the name of the method. So if I try to parse this line:

           int MyMethod()

           my parser thinks the method is called "(" instead of
        "MyMethod".
           Am I right that this is a lookahead issue? If it is, how do
        I fix it?


           _______________________________________________
           address@hidden <mailto:address@hidden>
        <mailto:address@hidden <mailto:address@hidden>>

           http://lists.gnu.org/mailman/listinfo/help-bison









reply via email to

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