Boris Grunwald
Boris Grunwald

Reputation: 2712

Extend Antlr grammar file with lists

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?

Upvotes: 1

Views: 209

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170148

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
 ;

Upvotes: 2

Related Questions