[antlr-interest] global backtrack vs rule level backtrack

Seref Arikan serefarikan at kurumsalteknoloji.com
Sat Jan 7 07:21:23 PST 2012


Greetings,
The grammar I'll paste below has a problem with matching an input through
multiple alternatives. I have other questions about it, but what struck me
is when I introduce a global backtrack=true setting, it does not have the
same effect with introducing backtrack=true to every single rule. What is
the difference between these two approaches?

And here is the grammar (which has been saved from the mutual recursion
thanks to Jim).

grammar testg;
options{backtrack=true;}

rul     :  contains_expr    ;

contains_expr : 'CONTAINS' contains_expression
                  //'CONTAINS' contains_or
        ;

contains_expression  :  primary  (('OR'|'AND'|'XOR') primary)*
       ;

primary
 : '(' contains_expression ')'
 | class_expression
 ;


class_expression :   simple_class_expr
           | '(' simple_class_expr contains_expr ')'
           |( simple_class_expr contains_expr) //TODO: REMOVED THIS DUE TO
AMBIGUITY IT INTRODUCES...
        ;

simple_class_expr : identifier                         // RM_TYPE_NAME
               | identifier identifier                  // RM_TYPE_NAME
variable
               | archetype_class_expr
         | versioned_class_expression
         | version_class_expression
         // | identified_obj_expression                           // need
to be used once VersionedClassExpr is removed
        ;

identifier
    :    ID
    ;

archetype_class_expr
    :    '.ace'
    ;

versioned_class_expression
    :    '.vce'
    ;

version_class_expression
    :    '.vnce'
    ;

temp     :
        ;








ID  :    ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;


More information about the antlr-interest mailing list