how to chain multiple flex scanners? (Paul van Bemmelen)
18 Aug 1999 03:37:05 -0400

          From comp.compilers

Related articles
how to chain multiple flex scanners? (1999-08-18)
Re: how to chain multiple flex scanners? (T.E.Dickey) (1999-08-21)
| List of all articles for this month |

From: (Paul van Bemmelen)
Newsgroups: comp.compilers
Date: 18 Aug 1999 03:37:05 -0400
Organization: TNO
Summary: chaining number of flex scanner, one bison, and having syntax error messages that tell you the correct line number and file name.
Keywords: lex, yacc, comment


Three line summary:
I want to chain a number of flex scanners and one bison parser, and
and also have syntax error messages that tell me the correct line number
and file name of the error.

I'm using flex and bison to parse some input format. The input format
basically is LALR(1) but has some quirks that require some
preprocessing before passing it to bison.

I would like to do the preprocessing with flex, using its STATE
mechanism (finite state automaton functionality).

Actually, the preprocessing consists of a number of steps (include
file expansion, variable expansion, table conversion, and
decryption. I think it's easiest to have each of these steps to be
handled by a separate flex scanner. Each flex scanner should pass its
output on to the next flex scanner, except for the last one who passes
its output on to bison.

So far, so good. Not too difficult. The complication arises from the
need for line number information and filename information when
producing syntax error messages.

I thought of prefixing each output line of the flex scanner with
linenumber information, but that requires carefull coding of the flex
scanner to strip those prefixes.

Anybody any other ideas?
Paul van Bemmelen | phone : +31 15 2697431
Crash Safety Centre | fax : +31 15 2624321
TNO Automotive | e-mail:
P.O. Box 6033
2600 JA Delft
The Netherlands
[If you're doing the scans in separate passes, I can't think of anything
much better. You can probably come up with generic lex rules that strip
out the line number stuff, e.g.:

"^L[0-9]{4}:" { linenumber = atoi(yytext+1); }


Post a followup to this message

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