antlr4

Call correct Antlr visitors without call all before visitors ultil match

痞子三分冷 提交于 2020-06-17 13:11:06
问题 I'm a little confused about how to do this. For example, I have this rule: stat : '(' expression ')' #ExpressionStatement; expression1 : expression2 ('==' expression2)* #ValidateExpression1 ; expression2 : literal ('!=' literal)* #ValidateExpression2 ; literal : ( 'true' | 'false') #literal ; In this case, if I pass "(true)" to the parser, how can I just visit VisitListeral() and return true instead visiting the entire tree until the match? In the visitor: VisitExpressionStatement() if I do

Call correct Antlr visitors without call all before visitors ultil match

可紊 提交于 2020-06-17 13:10:05
问题 I'm a little confused about how to do this. For example, I have this rule: stat : '(' expression ')' #ExpressionStatement; expression1 : expression2 ('==' expression2)* #ValidateExpression1 ; expression2 : literal ('!=' literal)* #ValidateExpression2 ; literal : ( 'true' | 'false') #literal ; In this case, if I pass "(true)" to the parser, how can I just visit VisitListeral() and return true instead visiting the entire tree until the match? In the visitor: VisitExpressionStatement() if I do

Is there a way to easily adapt the error messages of ANTLR4?

断了今生、忘了曾经 提交于 2020-06-08 12:01:31
问题 Currenlty I'm working on my own grammar and I would like to have specific error messages on NoViableAlternative , InputMismatch , UnwantedToken , MissingToken and LexerNoViableAltException . I already extended the Lexer.class and have overridden the notifyListeners to change the default error message token recognition error at: to my own one. As well I extended the DefaultErrorStrategy and have overridden all report methods, like reportNoViableAlternative , reportInputMismatch ,

What's the difference between ANTLR4's errorListener and errorHandler?

安稳与你 提交于 2020-05-29 05:54:25
问题 I want to get the specific error message of ANTLR4's parser. And I found that there are two way to handle error: errorListener and errorHandler. // set error handler parser.removeErrorListeners(); parser.addErrorListener(new QueryErrorListener()); parser.setErrorHandler(new BailErrorStrategy()); But I'm confused about the difference between them. I found that, errorListener can get the specific error message, but it can only print it or log it, can't throw a exception. The implemention of

How to do Priority of Operations (+ * - /) in my grammars?

爷,独闯天下 提交于 2020-05-23 19:17:17
问题 I define my own grammars using antlr 4 and I want to build tree true According to Priority of Operations (+ * - /) .... I find sample on do Priority of Operations (* +) it work fine ... I try to edit it to add the Priority of Operations (- /) but I failed :( the grammars for Priority of Operations (+ *) is : println:PRINTLN expression SEMICOLON {System.out.println($expression.value);}; expression returns [Object value]: t1=factor {$value=(int)$t1.value;} (PLUS t2=factor{$value=(int)$value+

Antlr javascript with webpack

做~自己de王妃 提交于 2020-05-15 11:33:50
问题 I am trying to use webpack with antlr 4 javascript target. I am following this document. https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md If I understand correctly , webpack will merge all the files from antlr4 javascript runtime librarty and the generated files (Lexer.js, Listener.js and Parser.js) in one single file. I need to include only this one file in my html. I don't understand this part of the document where it's asking to exclude node.js module. Can someone

Antlr javascript with webpack

蓝咒 提交于 2020-05-15 11:31:26
问题 I am trying to use webpack with antlr 4 javascript target. I am following this document. https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md If I understand correctly , webpack will merge all the files from antlr4 javascript runtime librarty and the generated files (Lexer.js, Listener.js and Parser.js) in one single file. I need to include only this one file in my html. I don't understand this part of the document where it's asking to exclude node.js module. Can someone

ANTLR Nested Functions

六眼飞鱼酱① 提交于 2020-05-13 14:13:22
问题 Is ANTLR right for this project? I'm looking to process and transform a string entered in by a user which may include custom functions. For example, the user might write something like $CAPITALIZE('word') in a string and I want to perform the actual transformation in the background using StringUtils. I would imagine the users will sometimes write nested functions like: $RIGHT_PAD($RIGHT($CAPITALIZE('a123456789'),6),3,'0') Where the expected output would be a string value of 'A12345000'. I

ANTLR Nested Functions

柔情痞子 提交于 2020-05-13 14:05:27
问题 Is ANTLR right for this project? I'm looking to process and transform a string entered in by a user which may include custom functions. For example, the user might write something like $CAPITALIZE('word') in a string and I want to perform the actual transformation in the background using StringUtils. I would imagine the users will sometimes write nested functions like: $RIGHT_PAD($RIGHT($CAPITALIZE('a123456789'),6),3,'0') Where the expected output would be a string value of 'A12345000'. I

Antlr4 Javascript Visitor

血红的双手。 提交于 2020-04-07 02:56:35
问题 I'm currently trying to develope a JavaScript Compiler with the help of an Antlr4 Visitor. I've got this already implemented with Java but cannot figure out how to do this in JavaScript. Probably somebody can answer me a few questions? 1: In Java there is a Visitor.visit function. If im right this isn't possibile with Javascript. Is there a work around for this? 2: My Javascript Visitor got all the generated visiting functions but when I use console.log(ctx) the context is undefined. Any idea