0

Can anyone tell me how to write syntax on Treetop that supports both:

system u AAA1 car=5, motor=4

and

system u car=5, motor=4
Phrogz
  • 296,393
  • 112
  • 651
  • 745
Sokmesa Khiev
  • 2,910
  • 3
  • 19
  • 30

1 Answers1

2

You want to use an "Optional Expression" (see about 60% down on this page):

grammar Sokmesa
  rule line
    "system" wsp+ marker wsp+ (category wsp+)? attributelist
  end
  rule category
    "AAA1" # Or whatever
  end
  # Add rules for 'marker', 'wsp', and 'attributelist' here
end
Phrogz
  • 296,393
  • 112
  • 651
  • 745