home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.compilers
- Path: sparky!uunet!world!iecc!compilers-sender
- From: "James A. Cadwell" <cadwell@seattleu.edu>
- Subject: In lex, how do I begin in a state??
- Reply-To: "James A. Cadwell" <cadwell@seattleu.edu>
- Organization: Seattle University
- Date: Sat, 21 Nov 1992 03:29:14 GMT
- Approved: compilers@iecc.cambridge.ma.us
- Message-ID: <92-11-122@comp.compilers>
- Keywords: lex, question, comment
- Sender: compilers-sender@iecc.cambridge.ma.us
- Lines: 26
-
- 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]
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-