[antlr-interest] Left recursion removal

Johannes Luber jaluber at gmx.de
Tue May 8 13:31:49 PDT 2007


Johannes Luber wrote:
> How do I check best that array_creation_expression has to be used as
> left-most token when the optional subrule "('.' identifier
> type_argument_list? | '(' argument_list? ')' | '++' | '--')?" has been
> used (and the opposite - no occurrence of the optional subrule requires
> no array_creation_expression)? Can I do it with actions or do I have to
> check it in another pass over the grammar (which would be doable but
> require one pass more than already planned)?

After removal of the left-recursion and some studying with the help
ANTLRworks I could safely remove the optional rule and end with this:

primary_expression
    :    (array_creation_expression
         |    literal
         |    simple_name
         |    parenthesized_expression
         |    predefined_type '.' identifier type_argument_list?
         |    qualified_alias_member '.' identifier type_argument_list?
         |    this_access
         |    base_access
         |    object_creation_expression
         |    delegate_creation_expression
         |    typeof_expression
         |    checked_expression
         |    unchecked_expression
         |    default_value_expression
         |    anonymous_method_expression
         |    sizeof_expression
         |    {isUnsafeContext}?=> pointer_member_access
         |    {isUnsafeContext}?=> pointer_element_access
         |    {allowOrcas}?=> anonymous_object_creation_expression)
         ('.' identifier type_argument_list?
         |    '(' argument_list? ')'
         |    '[' expression_list ']'
         |    '++'
         |    '--')*
	;

So, with this rule the question remains: How do I proceed? I've reformed
only one rule of originally 7. Should I repeat the same process with all
of them as the final rule and then combining equal parts into separate
rules? What about rules which have been only referenced in one of the
reformed rules? Can I skip the process for them?

Best regards,
Johannes Luber


More information about the antlr-interest mailing list