[antlr-interest] single-pass pattern matching "for free"?
Sohail Somani
sohail at taggedtype.net
Sun Jan 15 12:50:35 PST 2006
On Sun, 2006-01-15 at 11:39 -0800, Terence Parr wrote:
> On Jan 14, 2006, at 8:09 PM, Sohail Somani wrote:
> > After some more thought, doesn't it seem like just a more concise
> > way to
> > specify tree parsing? What would the differences be?
>
> And that is the most important question of all! The answer is:
>
> 1. just listing a bunch of patterns is easier until you get a huge
> number of them, when it becomes hard to find bugs in rule applications.
Yes, I remember having to use Prolog. Which was the coolest thing, but
you really had to consciously keep the number of rules low.
> 2. patterns have no guarantee of coverage whereas a tree grammar does.
What does this mean?
> 3. patterns are floating in space w/o context; a grammar knows that
> expressions cannot occur outside of a method or var
> initialization...patterns could specify context, however, but it is
> not as clear as a grammar. want an action to execute when you see
> the '}' of a function, just stick an action after the '}' in the
> appropriate spot in the grammar.
This is probably the biggest reason. I guess rule-based translation
makes sense for simple translations but I can't see it working for full
translations.
> The translation of a pattern -> replacement system would be trivial
> for a simple system; just translate to ANTLR. Further, to separate
> the view from the controller, one could use templates on the right:
>
> "<a:expr>+<b:expr>" -> add(left=a,right=b)
or the equivalent in ST:
add(lexpr,rexpr)::<<
(<lexpr>) + (<rexpr>)
>>
Still haven't figured out how to get rid of
((((((((5))))))) + ((((((3)))))))) but it would probably require a
change in the grammar rules, is all.
I think this whole thread will converge to say: "Hey wait, what we got
is the best way".
> or some such just like an antlr grammar. The idea would be really
> groovy. You give me a grammar and then a list of patterns and I
> generate a combined new grammar that does exactly what you want,
> yanking in all the required tokens/rules. Now where is a grad
> student when I need some cheap smart labor! ;) Actually, that would
> make a damn fine paper and system.
Academia... shudder... (its ok, they feel the same way about me :D)
More information about the antlr-interest
mailing list