Related articles |
---|
In lex, how do I begin in a state?? cadwell@seattleu.edu (James A. Cadwell) (1992-11-21) |
Re: In lex, how do I begin in a state?? eifrig@beanworld.cs.jhu.edu (1992-11-22) |
Re: In lex, how do I begin in a state?? tamdhu.ohm.york.ac.uk!rog@ohm.york.ac.uk (1992-11-25) |
Newsgroups: | comp.compilers |
From: | "James A. Cadwell" <cadwell@seattleu.edu> |
Organization: | Seattle University |
Date: | Sat, 21 Nov 1992 03:29:14 GMT |
Keywords: | lex, question, comment |
In lex, one uses BEGIN STATE-NAME in an action to place lex in a
state. My question is: how do I begin in a state?? That is, have
a state in effect before any input is read.
Thanks,
Jim Cadwell cadwell@sumax.seattleu.edu
[In short, you have to execute a BEGIN before the lexer starts scanning.
Code put at the front of the rules section is run whenever you call yylex(),
so you could do something like this:
%%
%{
static int first_time = 1;
if(first_time) {
BEGIN FOOSTATE;
first_time = 0;
}
...
The new version of O'Reilly's lex&yacc, much of which I wrote, explains this
in more detail. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.