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: Hans Aberg
Subject: Re: The Bison Manual Example Infix Calculator
Date: Fri, 2 Aug 2002 12:41:37 +0200

Reply-to: address@hidden

At 04:05 -0400 2002/08/02, Donges, William E.,, III wrote:
>I am working with the infix calculator example in the bison manual and
>would like to alter it slightly to read its input from a c-string rather
>than from stdin. It seems to me that this should be a straight forward
>operation but nothing in the bison manual seems to cover this. What
>changes should be made to the yylex function or to the calc.y file in
>general to parse from a passed buffer rather then from stdin.

The Bison generated parser only reads the token numbers handed over by the
yylex function, and does not know or care about the origin, if it is from a
string or stream or whatever. So merely change your yylex function.

In yylex example of the manual, you can merely replace the getchar(), etc
calls,  top provide the characters from wherever you want them to be read.

Also note that you can generate more advanced lexers using Flex:
  Help-flex mailing list
  address@hidden
  http://mail.gnu.org/mailman/listinfo/help-flex

Such lexers can also be hooked up to read from strings.

  Hans Aberg





reply via email to

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