I have a simple grammar which allows the user to define some objects with attributes. For example:
carpark : my carpark
lots: 100
car: BMW
color: red
wheels: 4
motocycle
age: 4
color: red
carpark : my second carpark
car:...
...
car:...
...
...
I have created a grammar with ANTLR to check those simple assignments.
Now I have problems checking for example the order or the meaning of the assignments. Lets assume I can inherit from an existing carpark
carpark: my third carpark
extends: my second carpark
How should I check if 'my second carpark' already exists?
Further I want some of the attributes like color be optional, others mandatory and the order should not be important
car: BMW
color: red
age: 4
//should be allowed as
car: BMW
age: 4
color: red
A simple rule would be
cardefinition
: CAR COLON value NEWLINE attributedefinition*
;
attributedefinition
: attributekey COLON value NEWLINE!
;
But then mandatory attributes may not be defined. I could add an additional rule like mandatoryattributedefinition but then it is hard to allow definitions in any order
So should this kind of checking be part of the parser or a tree parser