[antlr-interest] Re: Antlr grammar to parse Java classfile?

Ric Klaren klaren at cs.utwente.nl
Thu Dec 6 01:44:24 PST 2001


On Wed, Dec 05, 2001 at 09:25:54PM -0000, jsrs701 wrote:
TJP> Anyway, concerning the "match n times" thing.  You're right...it would 
TJP> be pretty useful.  What syntax is appropriate and how to do you say 
TJP> 0...n vs 1..n? 
> I'd vote for Perl's RE syntax...
> {n}    Match exactly n times
> {n,}   Match at least n times
> {n,m}  Match at least n, at most m times
> ...but I know the curly braces are gonna wreak havoc with the 
> existing ANTLR syntax.
TJP> Perhaps, for uniformity, we use my "element modifier 
TJP> syntax (e.g., "INT<AST=INTNode>"):

I'd go for the braces anytime in this case. Why break with 'normal' regular
expression syntax. Quite a lot of tools use this syntax. On the other
hand... using <> for this is ugly IMHO it applies a completely unrelated
antlr construct to another thing.

If the braces give too much trouble you might even think using brackets 

( ... )*[p1,p2]  or...

( ... )[p1,p2]*

Kindoff like a 'parameterized closure'. This is I think most consistent
with antlr's syntax currently.

If we're talking grammar extensions again we might consider this one again

( rule1 ... ruleN ) || ( TOKEN ) which should produce or

rule1 ... ruleN or...
rule1 .. ruleN TOKEN rule1 .. ruleN TOKEN rule1 .. ruleN

It is equivalent to ( rule1 .. ruleN ) ( TOKEN rule1 ... ruleN )* but if
you have action code somewhere in it you only have to maintain one piece in
stead of two pieces who are nearly identical. Cocktail's ell had this
syntax and I really miss it in antlr.

    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
Wit is cultured insolence. --- Aristotle

More information about the antlr-interest mailing list