Related articles |
---|
Relaxed pattern recognition mars@realsoftware.com (2003-12-08) |
Re: Relaxed pattern recognition Ralf.Laemmel@cwi.nl (Ralf Laemmel) (2003-12-13) |
Re: Relaxed pattern recognition haberg@matematik.su.se (2003-12-13) |
Re: Relaxed pattern recognition cdodd@acm.org (Chris Dodd) (2003-12-13) |
From: | mars@realsoftware.com (Mars Saxman) |
Newsgroups: | comp.compilers |
Date: | 8 Dec 2003 00:26:39 -0500 |
Organization: | http://groups.google.com |
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
pattern.
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
for_line.
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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.