1

I have the following assignment about extending an Antlr grammar.

enter image description here

What I've tried is:

enter image description here

I am not sure whether this is the correct solution or not. Can anyone guide me in the right direction?

sophros
  • 14,672
  • 11
  • 46
  • 75
Boris Grunwald
  • 2,602
  • 3
  • 20
  • 36

1 Answers1

2

2 problems here: 1) you have 2 the same alt-labels (# Lists), and 2) you only allow zero or a single expression in your list. It should be this:

expr
 : ...
 | '(' expr ')'                    # Parenthesis
 | '[' ( expr ( ',' expr )* )? ']' # Lists
 ;
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288