antlr4

Nested Boolean Expression Parser using ANTLR

牧云@^-^@ 提交于 2019-11-29 02:43:47
问题 I'm trying to parse a Nested Boolean Expression and get the individual conditions within the expression separately. For e.g., if the input string is: (A = a OR B = b OR C = c AND ((D = d AND E = e) OR (F = f AND G = g))) I would like to get the conditions with the correct order. i.e., D =d AND E = e OR F = f AND G = g AND A = a OR B = b OR C = c I'm using ANTLR 4 to parse the input text and here's my grammar: grammar SimpleBoolean; rule_set : nestedCondition* EOF; AND : 'AND' ; OR : 'OR' ;

antlr4-Can't load Hello as lexer or parser

只愿长相守 提交于 2019-11-29 02:05:14
问题 I recently have to use parser to do a project. I download ANTLR4 and follow the steps described in the book The Definitive ANTLR4 Reference . The following are the steps I type in command line: 1. export CLASSPATH=".:/<Mydirectory>/antlr-4.2.2-complete.jar:$CLASSPATH" 2. alias antlr4='java -jar /<My directory>/antlr-4.2.2-complete.jar' 3. alias grun='java org.antlr.v4.runtime.misc.TestRig' 4. antlr4 Hello.g4 All the things work fine, it generates java files that I need. However, after I enter

ANTLR 4 $channel = HIDDEN and options

烈酒焚心 提交于 2019-11-28 23:45:31
问题 I need help with my ANTLR 4 grammar after deciding to switch to v4 from v3. I am not very experienced with ANTLR so I am really sorry if my question is dumb ;) In v3 I used the following code to detect Java-style comments: COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} | '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} ; In v4 there are no rule-specific options. The actions (move to hidden channel) are also invalid. Could somebody please give me a hint how to do it in

Antlr4 Listeners and Visitors - which to implement?

情到浓时终转凉″ 提交于 2019-11-28 20:05:42
I'm reading "The Definitive Antlr 4 Reference" and get the idea in relation to how Listeners and Visitors work. The book explains particularly well how Listeners relate to SAX parsers and makes it obvious when methods are going to be called during the implementation of each. I can see also that listeners are quite good for transforming input to output but I would appreciate a short explanation/example as to when to use a Listener and when to use a Visitor (or should they both be used in certain cases?). My particular intention is to create an interpreter (Cucumber-style / TinyBasic Interpreter

antlr4 sql grammar

☆樱花仙子☆ 提交于 2019-11-28 19:32:54
Does ANTLR4 have a sql grammar available? If so, where can I find it? There is a link from the ANTLR wiki, but the link is broken: grammar list No, at the time of this writing, there is no v4 SQL grammar. All v4 grammar will be put into the following Github repository (as far as I can remember from the ANTLR mailing list): https://github.com/antlr/grammars-v4 The v3 grammars here now: http://antlr3.org/grammar/list.html EDIT - April 2018 There is now a user contributed MySQL grammar here: https://github.com/antlr/grammars-v4/tree/master/mysql Mike Koltsov Currently, there are plenty of sql

Once grammar is complete, what's the best way to walk an ANTLR v4 tree?

烈酒焚心 提交于 2019-11-28 15:44:23
Goal I'm working on a project to create a Varscoper for Coldfusion CFscript. Basically, this means checking through source code files to ensure that developers have properly var 'd their variables. After a couple of days of working with ANTLR V4 I have a grammar which generates a very nice parse tree in the GUI view. Now, using that tree I need a way to crawl up and down the nodes programmatically looking for variable declarations and ensure that if they are inside functions they have the proper scoping. If possible I would rather NOT do this in the grammar file as that would require mixing

Ambiguous call expression in ANTLR4 grammar

被刻印的时光 ゝ 提交于 2019-11-28 14:32:00
I have a simple grammar (for demonstration) grammar Test; program : expression* EOF ; expression : Identifier | expression '(' expression? ')' | '(' expression ')' ; Identifier : [a-zA-Z_] [a-zA-Z_0-9?]* ; WS : [ \r\t\n]+ -> channel(HIDDEN) ; Obviously the second and third alternatives in the expression rule are ambiguous. I want to resolve this ambiguity by permitting the second alternative only if an expression is immediately followed by a '(' . So the following bar(foo) should match the second alternative while bar (foo) should match the 1st and 3rd alternatives (even if the token between

ANTLR 4 Parser Grammar

你说的曾经没有我的故事 提交于 2019-11-28 14:07:15
How can I improve my parser grammar so that instead of creating an AST that contains couple of decFunc rules for my testing code. It will create only one and sum becomes the second root. I tried to solve this problem using multiple different ways but I always get a left recursive error. This is my testing code : f :: [Int] -> [Int] -> [Int] f x y = zipWith (sum) x y sum :: [Int] -> [Int] sum a = foldr(+) a This is my grammar: This is the image that has two decFunc in this link http://postimg.org/image/w5goph9b7/ prog : stat+; stat : decFunc | impFunc ; decFunc : ID '::' formalType ( ARROW

Compiling sample ANTRL4 output

不问归期 提交于 2019-11-28 13:57:29
From the Definitive ANTLR4 reference I have run through the first example and it has generated the JAVA target. In the directory C:\JavaLib I have antlr-4.5-complete.jar When I attempt to compile it with; javac -classpath C:\JavaLib *.java It creates the following error messages; helloBaseListener.java:13: error: class HelloBaseListener is public, should be declared in a file named HelloBaseListener.java public class HelloBaseListener implements HelloListener { ^ helloListener.java:9: error: class HelloListener is public, should be declared in a file named HelloListener.java public interface

How to collect errors during run time given by a parser in Antlr4

时间秒杀一切 提交于 2019-11-28 13:36:24
I have upgraded from Antlr 3 to Antlr 4. I was using this code to catch exceptions using this code. But this is not working for Antlr 4. partial class XParser { public override void ReportError(RecognitionException e) { base.ReportError(e); Console.WriteLine("Error in Parser at line " + ":" + e.OffendingToken.Column + e.OffendingToken.Line + e.Message); } } This is the error that appears 'Parser.ReportError(Antlr4.Runtime.RecognitionException)': no suitable method found to override In Antlr 4 what is the expected way of accumulating errors that occurs in the input stream. I was unable to find