help-bison
[Top][All Lists]
Advanced

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

Re: Parse a string


From: Tim Van Holder
Subject: Re: Parse a string
Date: 30 Oct 2002 17:39:43 +0100

On Thu, 2002-10-31 at 00:44, Karlheinz Toni wrote:

> 1.)    How can one parse a string? So if I have got a text like “ I go
> shopping today” how can I parse each word of this string, what does
> the yylex-function look like

This is not a bison question (yylex is supplied by the user, possibly
through the use of a tool like lex or flex).

> 2.)    How can I parse the text of a file. All examples I found show
> how to parse user input, but what I want to do is write the text in a
> file and parse the text out of that file. What does the yylex function
> look like?

Using lex/flex, all you need to do is call yyrestart(FILE*) before
starting to call yylex() or yyparse().  So, (simplistic case):

FILE* f = fopen("myinput", "r");
  yyrestart(f);
  yyparse();
  fclose (f);

If you write your own yylex(), you are of course free to get the input
from wherever you like.

> Could anyone help me please. I don’t find any documentation on the
> web.
 
-- 
Tim Van Holder <address@hidden>
Anubex





reply via email to

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