grammar Example; options { k=1; output=AST; } entry : (my_rule)+ ; my_rule : tf_port_item SEMI ; tf_port_item : data_type ID variable_dimension ; data_type : 'bit' | 'byte' | 'real' // Comment this to suppress NoViableAlt | 'struct' | 'union' ( 'tagged' )? | 'enum' | 'virtual' | ps_identifier ; ps_identifier : ( ID COLON_COLON ) => ID COLON_COLON ID | ID ; variable_dimension : ( associative_dimension_1 ) => associative_dimension_1 variable_dimension // comment this line // ( associative_dimension_2 ) => associative_dimension_2 variable_dimension // and uncomment this one to suppress NoViableAlt ( with 'real' alt in data_type) | ( sized_or_unsized_dimension )* ; associative_dimension_1 : LBRACK ( STAR | data_type ) RBRACK ; associative_dimension_2 : ( LBRACK STAR ) => LBRACK STAR RBRACK | LBRACK data_type RBRACK ; sized_or_unsized_dimension : LBRACK ( NUMBER )? RBRACK ; /********** Lexer *************/ SEMI: ';'; STAR: '*'; LBRACK: '['; RBRACK: ']'; COLON_COLON: '::'; WS : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;} ; ID : ('a'..'z'|'A'..'Z'|'_') ('0'..'9'|'a'..'z'|'A'..'Z'|'_')* ; NUMBER : ('0'..'9')+ ;