parsing - The following sets of rules are mutually left-recursive TREE GRAMMAR -


i have complete parser grammer generates ast correct using rewrite rules , tree operators. @ moment stuck @ phase of creating tree grammar.i have error:

the following sets of rules mutually left-recursive [direct_declarator, declarator] , [abstract_declarator, direct_abstract_declarator]

rewrite syntax or operator no output option; setting output=ast

here tree grammar.

tree grammar walker;  options {   language = java;   tokenvocab = c2p;   astlabeltype = commontree;   backtrack = true; }  @header   { package com.frankdaniel.compiler; }  translation_unit      :  ^(program (^(function external_declaration))+)     ;   external_declaration options {k=1;}     : (declaration_specifiers? declarator declaration*)=> function_definition      | declaration     ;    function_definition     :   declaration_specifiers? declarator (declaration+ compound_statement|compound_statement)      ;  declaration      : 'typedef' declaration_specifiers? init_declarator_list         | declaration_specifiers init_declarator_list?      ;  declaration_specifiers     :   ( type_specifier|type_qualifier)+     ;  init_declarator_list     : ^(init_declarator_list init_declarator+)     ;  init_declarator     : declarator (assign^ initializer)?       ;   type_specifier : (const)? (void | char | int | float );   type_id     :   identifier         //{system.out.println($identifier.text+" type");}     ;  type_qualifier     : const      ;  declarator     : pointer? direct_declarator     | pointer     ;  direct_declarator     :   (identifier|declarator) declarator_suffix*     ;     declarator_suffix     :   constant_expression     |   parameter_type_list     |   identifier_list      ;  pointer     : times type_qualifier+ pointer?     | times pointer     | times     ;  parameter_type_list     : parameter_list     ;  parameter_list     : ^(parameter_list parameter_declaration)     ;  parameter_declaration     : declaration_specifiers (declarator|abstract_declarator)*     ;  identifier_list     : ^(identifier_list identifier+)     ;  type_name     : specifier_qualifier_list abstract_declarator?     ; specifier_qualifier_list     : ( type_qualifier | type_specifier )+     ;  abstract_declarator     : pointer direct_abstract_declarator?     | direct_abstract_declarator     ;  direct_abstract_declarator     :   (abstract_declarator | abstract_declarator_suffix ) abstract_declarator_suffix*     ;  abstract_declarator_suffix     :   constant_expression     |   parameter_type_list     ;  initializer     : assignment_expression     | initializer_list?     ;  initializer_list     : ^(initializer_list initializer+)     ;   // expressions argument_expression_list     :   ^(expression_list assignment_expression+)     ;  multiplicative_expression     : ^((times|div|mod)  cast_expression cast_expression);   additive_expression     : ^((plus|minus) multiplicative_expression  multiplicative_expression);    cast_expression     : ^(cast_expression type_name cast_expression)     | unary_expression      ;  unary_expression     : postfix_expression     | pplus unary_expression     | mminus unary_expression     | unary_operator cast_expression     ;  postfix_expression     :   primary_expression         (   expression         |   argument_expression_list         |   identifier         |   identifier         |   pplus         |   mminus         )*       ;  unary_operator     : times     | plus     | minus     | not     ;  primary_expression     : identifier     | constant     | expression     ;  constant      :   hex_literal     |   octal_literal     |   decimal_literal     |   character_literal     |   string_literal     |   floating_point_literal     ;  ////////////////////////////////////////////////////////  expression     : ^(expression assignment_expression+)     ;  constant_expression     : conditional_expression     ;  assignment_expression     : ^(assignment_operator lvalue assignment_expression)     | conditional_expression     ;  lvalue     :   unary_expression     ;  assignment_operator     : assign      ;     conditional_expression : (logical_or_expression) (questionmark expression colon conditional_expression)?; logical_or_expression : ^(or logical_and_expression logical_and_expression); logical_and_expression : ^(and equality_expression equality_expression);  //equality_expression : (a=relational_expression) ((e=equal|e=nonequal)^ b=relational_expression)?; equality_expression : ^((equal|nonequal) relational_expression relational_expression);  //relational_expression : additive_expression ((st|gt|steq|gteq)^ additive_expression)* ; relational_expression : ^((st|gt|steq|gteq) additive_expression additive_expression);    // statements statement     : compound_statement     | expression_statement     | selection_statement     | iteration_statement      | jump_statement     ;  compound_statement     : ^(statement declaration* statement_list? )     ;  statement_list     : statement+     ;  expression_statement     :expression     ;  selection_statement     :^(if expression statement (^(else statement))? )     |^(switch expression statement)     ;  iteration_statement     : ^(while expression statement)     | ^(do statement ^(while expression))     | ^(for expression_statement expression_statement expression? statement)     ;  jump_statement     : continue     | break     | return     | ^(return expression)     ; 

it seems obvious following 2 rules left recursive:

{code} declarator : pointer? direct_declarator | pointer ;

direct_declarator : (identifier|declarator) declarator_suffix* ;
{code}

rule "declarator" has reference "direct_declarator", , "direct_declarator" has reference "declarator", , there's no other predicates pilot rule evaluation.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -