label x assigned to a block which is not a set
Asked Answered
C

1

15

trying out upgrading antlr4, I have 2 lines in the grammar that produce the error message:

label tok assigned to a block which is not a set

Specifically for a grammar line that looks like this:

contextRadius: tok=('radius' 'change-authorize-nas-ip') (IP4_ADDRESS|IP6_ADDRESS) 'encrypted' 'key' ID 'port' INT_TOK 'event-timestamp-window' INT_TOK 'no-reverse-path-forward-check'
    ;

What does this imply, exactly - to be a "block which is not set" and is there a general solution?

Cowbell answered 17/1, 2013 at 14:25 Comment(1)
I figured this out, basically I think ANTLR is implying that I'm not using the token. In one case I just removed the "tok=". In the second case, I removed a single set of parens that were not needed. So (IP4_ADDRESS) became just: IP4_ADDRESS So now the generator tool produces code, but the lexer and parser have compilation errors. Will report that separate issue on a new thread.Cowbell
B
17

The improper label is the following:

tok=('radius' 'change-authorize-nas-ip')

In this case, ANTLR doesn't know whether to assign the token 'radius' or the token 'change-authorize-nas-ip' to the label tok. Starting with ANTLR 4, rather than generate code with unclear semantics an error is produced. You'll want to either remove the label tok or move it to the intended item. In other words, use one of the following three forms.

('radius' 'change-authorize-nas-ip')
(tok='radius' 'change-authorize-nas-ip')
('radius' tok='change-authorize-nas-ip')

The reason labels are allowed on blocks in grammars is to support items like the following. This block is a set, meaning the contents can be collapsed to matching exactly one token from a fixed set of allowed tokens. The particular item matched by the set is then assigned to x.

x=('a' | 'b')
Buell answered 17/1, 2013 at 14:53 Comment(1)
Do all the items in the set have to be the same type? I'm getting this error and my block produces at most one item, but it chooses from 3 alternates of different types.Translator

© 2022 - 2024 — McMap. All rights reserved.