Relaxed pattern recognition (Mars Saxman)
8 Dec 2003 00:26:39 -0500

          From comp.compilers

Related articles
Relaxed pattern recognition (2003-12-08)
Re: Relaxed pattern recognition (Ralf Laemmel) (2003-12-13)
Re: Relaxed pattern recognition (2003-12-13)
Re: Relaxed pattern recognition (Chris Dodd) (2003-12-13)
| List of all articles for this month |

From: (Mars Saxman)
Newsgroups: comp.compilers
Date: 8 Dec 2003 00:26:39 -0500
Keywords: parse, question
Posted-Date: 08 Dec 2003 00:26:39 EST

I would like to write a parser using bison that deals with fragments
of source code that may or may not be complete. I would like to
construct an AST from the source code using whatever parts exist,
resolving them into more specific structures whenever they match some

Using the For statement from Basic, here's an example of what I have
in mind in pseudo-Bison-syntax:

line: token* ENDL;
for_line: FOR token* ENDL;
for_stmt: FOR ident '=' exp TO exp ENDL;
next_line: NEXT token* ENDL;
next_stmt: NEXT [ident] ENDL;
forloop: for_line line* next_line;

I imagine these productions as a sort of class hierarchy: a for_stmt
is-a for_line is-a line. forloop should match any sequence of lines
whose first line begins with FOR and whose last line begins with NEXT,
whether the FOR line is a correctly-formed for_stmt or just a

All of the bison (or yacc) examples I have seen expect to parse
correct code, and the behaviour when they find a syntax error is
simply to print a message and bail out. I'd like to pull as much
correct information as I can out of the token stream and return the
rest as more primitive productions.

Is this sort of thing possible with bison? Are there examples
available? Am I just overlooking something obvious?

Mars Saxman
REAL Software

Post a followup to this message

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