[antlr-interest] grammar problem with recursion?

Dervin Thunk dervin.thunk at gmail.com
Thu Aug 5 20:41:57 PDT 2010


Hello. I am new to ANTLR. Below is a grammar I wrote, and I'm trying to
test it with the following string, but it just stops before it even
consumes the n_pp... identifier, so it stops at the "conjunction"
rule. Any idea about what I could be doing wrong?

<teststring below>
s_n2 := n_pp_c-pl-crd_le & [ STEM < "100s" >,  SYNSEM [ LKEYS [
--COMPKEY _of_p_sel_rel,KEYREL.CARG "100" ], PHON.ONSET con ] ].


grammar tdl;

options
{
       language=Java;
       backtrack=true;
}

type_def
       :       type avm_def '.'
       ;

avm_def
       :       ':=' conjunction
       ;

conjunction
       :       term
       | (term '&' conjunction)
       ;

term
       :       type
       | STRING
       | feature_term
       | correference
       | list
       | diff_list
       ;

type
       :       ID
       ;

feature_term
       : '[' ']'
       | ('[' attr_val_list ']')
       ;

attr_val_list
       :       attr_val | (attr_val ',' attr_val)
       ;


attr_list
       : attribute
       | (attribute'.'attr_val_list)
       ;
attr_val
       : attr_list conjunction
       ;


attribute
       : ID
       ;

correference
       : '#' ID
       ;

diff_list
       :       '<!' '!>'
       | ('<!' conjunction_list '!>')
       ;

conjunction_list
       : conjunction
       | (conjunction ',' conjunction_list)
       ;

list
       :       '<' '>' | ('<' conjunction_list '>')
       | ('<' conjunction_list '>' ',' '...')
       |       ('<' conjunction_list '.' conjunction '>')
       ;


lex_entry
       :       lex_id avm_def
       ;

lex_id
       : ID
       ;


rule_entry
       :       rule_id avm_def
       ;

rule_id
       : ID
       ;

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

COMMENT
   :   '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
   |   ';' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
   |   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
   | '#|' ( options {greedy=false;} : . )* '|#' {$channel=HIDDEN;}
   ;

STRING
   :  '"' ( ESC_SEQ | ~('\\'|'"') )* '"' |
      '`' ( ESC_SEQ | ~('\\'|'"') )*
   ;

fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
   :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
   |   UNICODE_ESC
   |   OCTAL_ESC
   ;

fragment
UNICODE_ESC
   :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
   ;
fragment
OCTAL_ESC
   :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
   |   '\\' ('0'..'7') ('0'..'7')
   |   '\\' ('0'..'7')
   ;


More information about the antlr-interest mailing list