Is there a collection of "best practices" somewhere or where could it be placed?

102 views
Skip to first unread message

Onur

unread,
Jun 18, 2014, 4:21:23 AM6/18/14
to antlr-di...@googlegroups.com
When stumbling upon questions in places like stackoverflow I often find grammars that are not very well organized, i.e. they may parse a given file, but are difficult to work with afterwards.

If there would be a set of "rules of thumb" and/or set of grammars with comments why the grammar was build this specific way, they could serve as a guideline to newbies.

I would be willing to contribute but don't know exactly where would be the best place to put this list.


Jonathan Coveney

unread,
Jun 19, 2014, 5:34:35 PM6/19/14
to antlr-di...@googlegroups.com
There is a repository of grammars here: https://github.com/antlr/grammars-v4


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Onur

unread,
Jun 21, 2014, 9:20:06 AM6/21/14
to antlr-di...@googlegroups.com
I know that collection. But most (if not all) are not suited to be easily processed afterwards. Take a look at the java expression rule:


If you want to transform this into your own internal representation, how could you easily figure out, which operation is "inside" the found expression? How to easily access the subexpressions?

I'm pretty sure they are all correct and probably efficient parsers, but they are not (yet) suited to be easily used after the parsing has been done (which at least in my cases took much longer than building the grammar).

Terence Parr

unread,
Jun 21, 2014, 10:48:47 AM6/21/14
to antlr-di...@googlegroups.com

On Jun 21, 2014, at 6:20 AM, Onur <fras...@gmail.com> wrote:

> I know that collection. But most (if not all) are not suited to be easily processed afterwards. Take a look at the java expression rule:
>
> https://github.com/antlr/grammars-v4/blob/master/java/Java.g4#L497
>
> If you want to transform this into your own internal representation, how could you easily figure out, which operation is "inside" the found expression? How to easily access the subexpressions?

You just have to add “# label” to the alts and it’ll alter the parse tree nodes/listeners to suit.

Ter

Onur

unread,
Jun 22, 2014, 5:22:48 AM6/22/14
to antlr-di...@googlegroups.com
I know how to "fix" this. But I wonder how long it will take a beginner to come to this solution. In my opinion some simply copy and paste a grammar, maybe modfiy it a bit to match their need and then don't know how to proceed (at least you get this impression from looking at some questions that arise at e.g. stackoverflow). This is where a "complete" example of a lexer/parser and some postprocessing into an internal structure might be of help. Something like the Cymbol language in your book maybe, just more "worked out". But if you plan to put this in the new edition of "language implementation patterns" this would be fine too ;-).

Terence Parr

unread,
Jun 22, 2014, 11:37:15 AM6/22/14
to antlr-di...@googlegroups.com
thinking of updating that book during sabbatical in 2016.
T
Reply all
Reply to author
Forward
0 new messages