lex: is NLSTATE always part of the language ?

Ralf Reche (CAT SDC Hamburg) <Ralf.Reche@hamburg.sc.philips.com>
21 Oct 1997 21:27:31 -0400

          From comp.compilers

Related articles
lex: is NLSTATE always part of the language ? Ralf.Reche@hamburg.sc.philips.com (Ralf Reche (CAT SDC Hamburg)) (1997-10-21)
Re: lex: is NLSTATE always part of the language ? vern@daffy.ee.lbl.gov (1997-10-26)
| List of all articles for this month |
From: Ralf Reche (CAT SDC Hamburg) <Ralf.Reche@hamburg.sc.philips.com>
Newsgroups: comp.compilers
Date: 21 Oct 1997 21:27:31 -0400
Organization: Philips Semiconductors RHW
Keywords: lex, question

Hi all,


I'm have written a lex program that BEGINs a new %State when a character ':'
appears at the beginning of the line. This character is then to be reused,
so I call yyless(0). But, also the 'beginning of line' state is to be reused,
and the standard documentation for lex does not provide a function for that.


I had a look at the C code produced by lex (on HP-UX and SunOS) and found a
definition for NLSTATE, that did just what I needed:


# define NLSTATE yyprevious=YYNEWLINE


When I use this in my lex program, everything is as I want it:


<INITIAL>^: { yyless(0); NLSTATE; BEGIN stateI; }
<stateI>^: { ... }


Now my question is whether this code is portable, i.e. do ALL (or
most) lex compilers define NLSTATE with this meaning? Or, is there a
more standard solution to my problem that I didn't see ? (there is
more than one line starting with ':')


  Thanks for any help, Ralf.


* Philips Semiconductors RHW Tel +49 (40) 5613-2963
* 21147 Hamburg, Germany Fax +49 (40) 5613-3313
* mailTo:Ralf.Reche@hamburg.sc.philips.com
[Flex, which is the version of lex most people use, doesn't have that. You
already have a start state telling you where you are, so just use that to
control the patterns you want. You may want two states, one for stateI at
the beginning of a line and the other for stateI elsewhere. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.