help-bison
[Top][All Lists]
Advanced

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

Re: The Bison Manual Example Infix Calculator


From: Donges, William E.,, III
Subject: Re: The Bison Manual Example Infix Calculator
Date: Sat, 3 Aug 2002 00:21:00 -0400

Ok I have rewritten the yylex function in the example as follows

int yylex (char *s) {
        int c==s[0];

        /* skip white space  */
        for(;isspace(c);s++,c=s[0]);
        if (c == '.' || isdigit (c)) {
                sscanf(s,"%d",&yyval);
                for(;isdigit(c);s++,c=s[0]);
                return NUM;
        } else if (c == EOF) {
                return 0;
        } else {
                /* return single chars */
                return c;
        }
}

Which would seem to be what I want to do in this case, at least comparing it to 
the existing one which uses getchar, but I still dont understand how to tell 
the parser that I want to parse a string in main.


I mean if I have main setup as follows

int main() {
char *s="      3+2-10^5-8";
yyparse();
}


it of course will not do what I want... How do I actually get the 
string literal into yylex and parse the result? And how can I capture the 
resultant int or float to a variable rather then just having it displayed
to stdout? 




reply via email to

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