home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / compiler / 1930 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.2 KB  |  40 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!world!iecc!compilers-sender
  3. From: "James A. Cadwell" <cadwell@seattleu.edu>
  4. Subject: In lex, how do I begin in a state??
  5. Reply-To: "James A. Cadwell" <cadwell@seattleu.edu>
  6. Organization: Seattle University
  7. Date: Sat, 21 Nov 1992 03:29:14 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-11-122@comp.compilers>
  10. Keywords: lex, question, comment
  11. Sender: compilers-sender@iecc.cambridge.ma.us
  12. Lines: 26
  13.  
  14. In lex, one uses BEGIN STATE-NAME in an action to place lex in a
  15. state.  My question is: how do I begin in a state?? That is, have
  16. a state in effect before any input is read.
  17.  
  18. Thanks,
  19.  
  20. Jim Cadwell    cadwell@sumax.seattleu.edu
  21. [In short, you have to execute a BEGIN before the lexer starts scanning.
  22. Code put at the front of the rules section is run whenever you call yylex(),
  23. so you could do something like this:
  24.  
  25. %%
  26. %{
  27.     static int first_time = 1;
  28.  
  29.     if(first_time) {
  30.         BEGIN FOOSTATE;
  31.         first_time = 0;
  32.     }
  33. ...
  34.  
  35. The new version of O'Reilly's lex&yacc, much of which I wrote, explains this
  36. in more detail. -John]
  37. -- 
  38. Send compilers articles to compilers@iecc.cambridge.ma.us or
  39. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  40.