Earley syntax generator for Java

I'm looking for an Earley generator generator that is capable of generating Java output code, that is, it generates Java code for the lexer and parser, and allows you to include actions (implemented as Java code) that are executed for the grammar rules.

I looked at two Earley syntax generators that generate Java code ( Pep and PEN ) but none of them seem to allow actions to be embedded in the grammar.

+1


source to share


3 answers


If I understood your question, by "inserting actions into the grammar" you mean inserting semantic actions into the grammar so that they are done "inline" (for example, during the parsing phase when the input is processed).

Earley parsers are not suitable for this, because they allow any (even ambiguous) context-free language grammars. See: http://en.wikipedia.org/wiki/Earley_algorithm

Basically: for a given execution and a given state, the Earley parser contains all possible parsing states. The traditional approach (like Yacc / Bison) is to perform a semantic action after a rule or partial input has completed. But when parsing an ambiguous grammar (for example, a Reduce / Reduce conflict) and the Earley parser will take care of all the abbreviations, but because of this the ambiguity will not know what action should be taken.



A common way to use Earley parsers is to parse the input and get a forest of parsing trees on which you later perform the required actions (for example, discarding those you know are invalid or applying some semantic action on them).

However, there has been some research done on this topic trying to do some inline action (sorry, just found this link) http://www.springerlink.com/content/602270808666074p/

+3


source


Not sure if this is the answer, but one of the scanner generators I use regularly is JFlex , which outputs Java code.



It works closely with CUP , which is a little closer to action.

+1


source


none of them allow you to embed actions in the grammar.

In general, it is not recommended to include actions directly in the grammar. Better if actions are separated from grammar.

+1


source







All Articles