[antlr-interest] Parse rule to add multiple homogeneous branches under a root node?
Peter Bosch
pbosch at highpointsoftware.com
Tue May 8 05:25:02 PDT 2012
Okay, I've tried to boil it down to a simple test case that illustrates
(probably in my parse rule) what I'm doing wrong. Target is C#.
//-----------------------------
// TreeTestInput.txt
Branch1
Branch2
Branch3
//-----------------------------
// Desired output:
ROOT
Branch1
Branch2
Branch3
//-----------------------------
// Actual output:
ROOT
Branch3
//-----------------------------
// TreeTest.g
grammar TreeTest;
options {
language=CSharp3;
output=AST;
}
tokens {
ROOT;
}
public parse
: ( r=BRANCH )* EOF -> ^(ROOT $r*)
;
BRANCH
: 'Branch' ('0'..'9')
;
EOL : ('\r'? '\n') {$channel=Hidden;} ;
WS : (' '|'\t'|'\f'| EOL)+ {$channel=Hidden;} ;
Peter Bosch
Highpoint Software Systems
E-mail : <mailto:pbosch at highpointsoftware.com> pbosch at highpointsoftware.com
Phone : 262-893-5400
P-Mail : S42 W27451 Oak Grove Lane Waukesha, WI, 53189
Useful and Usable Decision Support & Technical Software
More information about the antlr-interest
mailing list