[antlr-interest] single-pass pattern matching "for free"?
Terence Parr
parrt at cs.usfca.edu
Sat Jan 14 15:59:07 PST 2006
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!
Ter
More information about the antlr-interest
mailing list