[antlr-interest] One of a type in a list of many - an ANTLR grammar
question
Mike Ventham
mike at doublevdesign.co.uk
Thu Feb 2 15:05:40 PST 2006
I've been using ANTLR for a couple of days and have been writing a parser for
a format for which I have the BNF. The .g file is about 2100 lines.
There are several places where there is a one of a type in a list of
properties.
For example:-
nonCondLayers ::= '(' 'nonConductiveLayer' {nonCondLayer} ')'
nonCondLayer ::= '(' 'layer' layerName {<nonCondLayerType> property} ')'
## The {<x> y} means 0 or 1 "x" in a list with 0 or more "y"s in any order
## e.g x y y or y x y or x or y y
nonCondLayerType ::= '(' 'type' nonCondLayerTypeEnum ')'
nonCondLayerTypeEnum ::= "VARIANTHOLE"
property ::= noTypeProperty | integerProperty | floatingProperty |
stringProperty
noTypeProperty ::= '(' 'property' propName propVal ')'
integerProperty ::= '(' 'propertyI' propName propVal ')'
floatingProperty ::= '(' 'propertyF' propName propVal ')'
stringProperty ::= '(' 'propertyS' propName propVal ')'
propName ::= identifier
propVal ::= integerValue | floatingValue | string
I get nondeterminism warnings for these lines as well.
I used the rules:
nonCondLayers : LPAREN! "nonConductiveLayer" (nonCondLayer)* RPAREN!
;
nonCondLayer : LPAREN! "layer" layerName ((nonCondLayerType)?
property)* RPAREN!
;
However this seems to cause a hang when parsing the file but changing to
nonCondLayer : LPAREN! "layer" layerName (nonCondLayerType)?
(property)* RPAREN!
;
works OK but won't handle the case " property nonCondLayerType property "
Would
nonCondLayer : LPAREN! "layer" layerName (property)*
(nonCondLayerType)? (property)* RPAREN!
;
be any better?
Any help appreciated!
P.S. Is there any best practice dealing with nested bracket format
files? I couldn't
find an example.
Regards
Mike
Mike Ventham
Chief Technical Consultant
Double V Design & Support Services
Langarth, Stoke Road, Westbury-sub-Mendip
Wells, Somerset, BA5 1HD, UK.
Tel : 44 (0)1749 871104 Fax: 44 (0)7974 141685
Mob : 44 (0)7971 553260
Email : mike at doublevdesign.co.uk
Web : http://www.doublevdesign.co.uk
More information about the antlr-interest
mailing list