[antlr-interest] single-pass pattern matching "for free"?

Nigel Sheridan-Smith nbsherid at secsme.org.au
Sat Jan 14 20:18:55 PST 2006


 
> Message: 7
> Date: Sat, 14 Jan 2006 15:59:07 -0800
> From: Terence Parr <parrt at cs.usfca.edu>
> Subject: [antlr-interest] single-pass pattern matching "for free"?
> To: ANTLR Interest <antlr-interest at antlr.org>
> Message-ID: <788FA521-8491-499D-B770-53A1FC0C925E at cs.usfca.edu>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
> 
> On Jan 14, 2006, at 3:40 PM, Nigel Sheridan-Smith wrote:
> > It seems that Andy's approach gives more granularity of control over
> > particular pattern matching and manipulation - things that would
> > have to be
> > coded as an action in an ANTLR tree-walker. However, the
> > disadvantage is
> > that it requires somebody to write such a rule engine to process
> > the 200 or
> > so rules that you have written. It does sound like it would be more
> > intuitive to write these rules in certain circumstances, depending
> > on what
> > patterns were acceptable.
> 
> Perhaps we can have the ease of specification of Andy's solution
> without having to handbuild a specific pattern engine...well, if
> we're going to only do a single linear check for a match, apply rule,
> and repeat.  Imagine a pattern engine like this:
> 
> <expr>+0 -> <expr>
> <expr>*0 -> 0
> 
> Can't we auto convert this to:
> 
> rules returns [String result]
>        :       => expr '+' INT {$INT.text.equals("0")}? {$result =
> $expr.text;}
>        |       => expr '*' INT {$INT.text.equals("0")}? {$result =
> $INT.text;}
>        ;
> 
> where assume for the moment that => on the front is a shorthand for
> back on this alt.
> 
> rule 'rules' would be checked against every char in the input stream
> until it found a match etc...  Very much like the fuzzy java parser I
> just built that scans incomplete or semi-bogus java code looking for
> recognizable stuff.
> 
> Would thing kind of thing be useful?  Best of both worlds?  For many
> applications, this would be great!
> 

Sounds good to me! But I think one of Andy's points was that not everything
in translation can be applied at the AST node level. You sometimes need to
look deeper (e.g. within strings), or broader (e.g. multiple lines of code).

Didn't Loring Craymer has some tree-rewriting syntax for ANTLR 2.8 (with the
special JPL/Caltech license)? How similar is that concept to this one? My
memory is pretty vague :-/

Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435



More information about the antlr-interest mailing list