dfz (11/30/82)
This is an answer to a "lex" question asked on the net-wizards newsgroup. I tried to mail to the individual concerned, but the mailer failed. To: Randy Bentson Address: harpo!decvax!cca!hplabs!hao!csu-cs!bentson@sri-unix Lex has the ability to allow the user to insert a user-tailored set of states in front of the lex-generated finite state machine. These states can be used to subdivide the lex-generated FSA into as many independent FSAs as the user desires. This trick comes in handy when performing lexical analysis upon an input which contains delimited sections in which the rules of analysis are very different from each other (e.g. comments or strings vs. C language text). The reason you don't see this treatment used for comments in most C compilers is that comments are stripped out by the C preprocessor, rather than by the lexical analyzer of the C parser. The technique for doing this is to use the "%start" directive (see the lex manual). I will show an example: --------------------------------------------------- %start normal comment %% <normal> ... { code for expression } <normal> ... { code for expression }
dfz (12/02/82)
This is an answer to a "lex" question asked on the net-wizards newsgroup. It's my second try to get it out on the net; "postnews" cut off all but 24 lines the last time. I tried to mail to the individual concerned, but the mailer failed. To: Randy Bentson Address: harpo!decvax!cca!hplabs!hao!csu-cs!bentson@sri-unix Lex has the ability to allow the user to insert a user-tailored set of states in front of the lex-generated finite state machine. These states can be used to subdivide the lex-generated FSA into as many independent FSAs as the user desires. This trick comes in handy when performing lexical analysis upon an input which contains delimited sections in which the rules of analysis are very different from each other (e.g. comments or strings vs. C language text). The reason you don't see this treatment used for comments in most C compilers is that comments are stripped out by the C preprocessor, rather than by the lexical analyzer of the C parser. The technique for doing this is to use the "%start" directive (see the lex manual). I will show an example: --------------------------------------------------- %start normal comment %% <normal> ... { code for expression } <normal> ... { code for expression }