Skip to content
Advertisement

Tag: antlr4

Antlr4: getting an ordered list of tokens?

I have this parser rule: And I’m iterating over the pows using ctx.pow(), but I would like to know too what operator there was. Unfortunately, ctx.operator just gives the last one encountered and ctx.TIMES() just gives a dumb list with a reapeted ‘*’. Do I really have to do a sub-rule for that? Answer You can do operator +=: which

How to force ANTLR to parse all input CharStream

I’m using ANTLR4 to parse a syntax file. When I use BaseErrorListener to detect errors, I got a problem. When faced with an illegal input string, ANTLR automatically matches the appropriate branch and then ignores the subsequent stream of characters even if it contains errors. And I want to detect that error. Here are my g4 file and java file.

Advertisement