You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to BNFC Developers and Users
Hi all,
I have a general question about how to best use BNFC.
I would love to work with an ideal grammar that is not adapted to any particular parsing algorithms. However, I always find myself having to write grammars that are adapted so that parser generators know how to parse them well, which makes them harder to read in the abstract. For example, regardless of whether BNFC can handle this particular case, think of the following production:
A ::= (B)*
Some parsing algorithms would like that to be:
A ::= epsilon
A ::= A B
Others would prefer to see:
A ::= epsilon
A ::= B A
Both of those generate B*, which maybe can be proven in some cases.
What would be the best way to approach describing the translation of a grammar, from its ideal, potentially ambiguous form, to a more concrete, easy-to-parse form?
Thanks,
Ivan
Andreas Abel
unread,
Jun 22, 2020, 2:07:55 PM6/22/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to bnfc...@googlegroups.com
Hi Ivan,
since BNFC serves mostly LR-parser generators in its backends (exception
is the Java/ANTLR backend), lists should be written in right-recursive
style since these are handled more efficiently by some LR parsers than
left-recursive lists (which are also handled by LR parser). In
contrast, LL parsers such as ANTLR fare better with left-recursion.
> A ::= epsilon
> A ::= A B
This is left-recursion suited for LL parsing.
> A ::= epsilon
> A ::= B A
This is right-recursion generally favored for LR parsing.
However, in BNFC you do not really have to worry, since there are
dedicated list constructions. The pragma
terminator A "";
allows you to use [A] for white-space separated lists of A.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to BNFC Developers and Users
Thanks. I know. I used lists as a example of a common case in which translation is used in parser generators, but that's why I said "regardless of whether BNFC can handle this particular case".
My question is more general than that.
What is the best way to establish that correspondence between a language's "ideal" grammar and the one that has been altered to facilitate parsing?