antlr3

ANTLR How to differentiate input arguments of the same type

我的梦境 提交于 2019-12-11 14:44:47
问题 If I have my input message: name IS (Jon, Ted) IS NOT (Peter); I want this AST: name | |-----| IS IS NOT | | | Peter |----| Jon Ted But I'm receiving: name | |-----------------| IS IS NOT | | | | |----|-----| |----|-----| Jon Ted Peter Jon Ted Peter My Grammar file has: ... expression | NAME 'IS' OParen Identifier (Comma Identifier)* CParen 'IS NOT' OParen Identifier (Comma Identifier)* CParen -> ^(NAME ^('IS' ^(Identifier)*) ^('IS NOT' ^(Identifier)*)) ; ... NAME : 'name' ; Identifier : ('a'

Issues of Error handling with ANTLR3

独自空忆成欢 提交于 2019-12-11 12:04:34
问题 I tried error reporting in following manner. @members{ public String getErrorMessage(RecognitionException e,String[] tokenNames) { List stack=getRuleInvocationStack(e,this.getClass().getName()); String msg=null; if(e instanceof NoViableAltException){ <some code> } else{ msg=super.getErrorMessage(e,tokenNames); } String[] inputLines = e.input.toString().split("\r\n"); String line = ""; if(e.token.getCharPositionInLine()==0) line = "at \"" + inputLines[e.token.getLine() - 2]; else if(e.token

antlr is there any way to generate the visitor code(generic visitor)

南楼画角 提交于 2019-12-11 11:47:01
问题 We would like to have the CommonTree have a visit(OurVisitor visitor) method but CommonTree is not a generated class. Right now, we have this code ANTLRStringStream stream = new ANTLRStringStream(sql); NoSqlLexer lexer = new NoSqlLexer(stream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); NoSqlParser parser = new NoSqlParser(tokenStream); CommonTree tree = (CommonTree) parser.statement().getTree(); I can always externalize walking the tree, but it is nice to just call tree

ANTLR V3 SQL Grammar

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:38:01
问题 Where can I find sql grammars available for v3 of ANTLR? I have tried http://www.antlr.org/grammar/list, but the link is dead. 回答1: The servers are currently being adjusted for the ANTLR 4 release. The new home of ANTLR 3 is antlr3.org. The particular page you are asking about is here: http://antlr3.org/grammar/list.html 来源: https://stackoverflow.com/questions/14466254/antlr-v3-sql-grammar

Internal EBCDIC support for ANTLR 3.1.3?

余生颓废 提交于 2019-12-11 09:38:18
问题 I'm trying to use ANTLR 3.1.3 on a system with local EBCDIC char set Even a simple grammar like this: lexer grammar test; GENERIC_ID : (LETTER)* ; fragment LETTER : 'a' .. 'z' ; results in these errors during the initial compile (java org.antlr.Tool test.g): error(10): internal error: problem parsing group <unknown>: line 1:1: unexpected char: 0x7 : line 1:1: unexpected char: 0x7 org.antlr.stringtemplate.language.GroupLexer.nextToken(GroupLexer.java:233) antlr.TokenBuffer.fill(TokenBuffer

ANTLR v3 grammar for boolean/conditional expression

烂漫一生 提交于 2019-12-11 09:04:58
问题 I'm taking a first stab at creating a grammar for expressions like: (foo = bar or (bar = "bar" and baz = 45.43)) and test = true My grammar so far looks like: grammar filter; tokens { TRUE = 'true'; FALSE = 'false'; AND = 'and'; OR = 'or'; LT = '<'; GT = '>'; EQ = '='; NEQ = '!='; PATHSEP = '/'; LBRACK = '['; RBRACK = ']'; LPAREN = '('; RPAREN = ')'; } expression : or_expression EOF; or_expression : and_expression (OR or_expression)*; and_expression : term (AND term)*; term : atom ( operator

Can not provide for host variables in Antlr3 SQL grammar

余生颓废 提交于 2019-12-11 09:01:58
问题 I have a SQL grammar which do not have support for host variables. I want to provide support for host variables in that but a situation that I have encountered is tricky. There is SQL Identifier lexer rule in grammar, which supports alphanumeric along with some special characters '@', '#', '$ and '_'. Host variable's are dependent on language in which SQL is embedded. e.g. COBOL. COBOL identifiers allow additionally hyphen(-) in variable names (Some other differences in them). So I added LANG

Antlr AST generating (possible) madness

拜拜、爱过 提交于 2019-12-11 06:57:06
问题 Is the following even possible? I want to "reverse" the input given to antlr and make each token a child of the previous one. So, for the input (Assume each token is separated by the '.' char) : Stack.Overflow.Horse I would like my grammar to produce the following AST: Horse |---Overflow |---Stack So far, I've managed to reverse the nodes, but I'm unable to make them children of each other: function : ID PERIOD function -> function ID | ID ; ID : 'a'..'z'* ; 回答1: I don't think there's an easy

ANTLR: removing clutter

為{幸葍}努か 提交于 2019-12-11 06:54:57
问题 i'm learning ANTLR right now. Let's say, I have a VHDL code and would like to do some processing on the PROCESS blocks. The rest should be completely ignored. I don't want to describe the whole VHDL language, since I'm interested only in the process blocks. So I could write a rule that matches process blocks. But how do I tell ANTLR to match only the process block rule and ignore anything else? 回答1: I know next to no VHDL, so let's say you want to replace all single line comments in a (Java)

How to have both function calls and parenthetical grouping without backtrack

妖精的绣舞 提交于 2019-12-11 03:54:52
问题 Is there any way to specify a grammar which allows the following syntax: f(x)(g, (1-(-2))*3, 1+2*3)[0] which is transformed into (in pseudo-lisp to show order): (index ((f x) g (* (- 1 -2) 3) (+ (* 2 3) 1) ) 0 ) along with things like limited operator precedence etc. The following grammar works with backtrack = true, but I'd like to avoid that: grammar T; options { output=AST; backtrack=true; memoize=true; } tokens { CALL; INDEX; LOOKUP; } prog: (expr '\n')* ; expr : boolExpr; boolExpr :