antlr

ANTLR PCRE Grammar to JS Target

不想你离开。 提交于 2019-12-01 13:12:53
I'm trying to build Bart Kiers' ANTLR PCRE grammar (see: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html ) to a JS target. The only way I get get it to build is with global backtracking and memoization and it's generating code that is invalid here is the grammar: grammar PCRE; options { language=JavaScript; backtrack=true; memoize=true; } parse : regexAtom* EOF ; ... and the rest of the grammar as seen: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html The lexer is generating code that looks like: //$ANTLR 3.4 PCRE.g 2011-11-19 23:22:35 var PCRELexer = function(input, state) { //

Traversing a tree recursively in depth first problems

柔情痞子 提交于 2019-12-01 13:06:59
I'm trying to traverse a tree using ANTLR tree commands and recursion. The code I currently have is: public void traverseTree(Tree tree){ int counter = 0; System.out.println(tree.toString()); if (tree.getChildCount() > 0 && tree.getChild(0) != null){ System.out.println(tree.toString() + counter++); tree = tree.getChild(0); traverseTree(tree); } while (tree.getParent().getChild(tree.getChildIndex() + 1) != null){ System.out.println(tree.toString() + counter++); tree = tree.getParent().getChild(tree.getChildIndex() + 1); traverseTree(tree); } } But, well, it's not working. I'm getting a lot of

基于S2SH框架的项目—antlr-2.7.2.jar包冲突问题

微笑、不失礼 提交于 2019-12-01 12:27:31
java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I org.hibernate.hql.ast.HqlSqlWalker.generatePositionalParameter(HqlSqlWalker.java:896) org.hibernate.hql.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:4819) org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1373) org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243) org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3725) org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864) org.hibernate.hql.antlr.HqlSqlBaseWalker

ANTLR exception handling with “$”, Java

风流意气都作罢 提交于 2019-12-01 11:57:47
问题 For my grammar in ANTLR, my java code can catch and print errors for inputs containing "$". In my implementation, I need to print out "success" for successful input. So, I do following in my java code, CharStream charStream = new ANTLRFileStream(filePath); myLexer lexer = new myLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); myParser parser = new myParser(tokens); /*if there is an error throws an exception message*/ parser.program(); /*if there is an error find how many,

Traversing a tree recursively in depth first problems

廉价感情. 提交于 2019-12-01 10:44:49
问题 I'm trying to traverse a tree using ANTLR tree commands and recursion. The code I currently have is: public void traverseTree(Tree tree){ int counter = 0; System.out.println(tree.toString()); if (tree.getChildCount() > 0 && tree.getChild(0) != null){ System.out.println(tree.toString() + counter++); tree = tree.getChild(0); traverseTree(tree); } while (tree.getParent().getChild(tree.getChildIndex() + 1) != null){ System.out.println(tree.toString() + counter++); tree = tree.getParent().getChild

Writing language converter in ANTLR

老子叫甜甜 提交于 2019-12-01 08:42:42
I'm writing a converter between some dialects of the same programming language. I've found a grammar on the net - it's complex and handles all the cases. Now I'm trying to write the appropriate actions. Most of the input is just going to be rewritten to output. What I need to do is parse function calls, do my magic (rename function, reorder arguments, etc) and write it. I'm using AST as output. When I come across a function call, I build a custom object structure (from classes defined in my target language), call the appropriate function and I have a string that represents the transformed

Catching ANTLR's NoViableAltException in Java and ANTLRWorks Debugger

人走茶凉 提交于 2019-12-01 08:38:57
问题 Consider we try to feed some incorrect input text to some grammar (e.g. text which contains some unknown token). In ANTLRWorks during interpretation we will see NoViableAltException in graph. UPD: There are two cases when this exception appears: 1) Unexpected using of some known token, in this case we will receive something like line 5:36 no viable alternative at input ',' 2) Using unknown token type. For example grammar doesn't know anything about tokens, which start with @ symbol. And we

ANTLR String interpolation

三世轮回 提交于 2019-12-01 08:25:44
问题 I'm trying to write an ANTLR grammar that parses string interpolation expressions such as: my.greeting = "hello ${your.name}" The error I get is: line 1:31 token recognition error at: 'e' line 1:34 no viable alternative at input '<EOF>' MyParser.g4: parser grammar MyParser; options { tokenVocab=MyLexer; } program: variable EQ expression EOF; expression: (string | variable); variable: (VAR DOT)? VAR; string: (STRING_SEGMENT_END expression)* STRING_END; MyLexer.g4: lexer grammar MyLexer; START

What to use in ANTLR4 to resolve ambiguities (instead of syntactic predicates)?

放肆的年华 提交于 2019-12-01 08:10:55
问题 In ANTLR v3, syntactic predicates could be used to solve e.g., the dangling else problem. ANTLR4 seems to accept grammars with similar ambiguities, but during parsing it reports these ambiguities (e.g., "line 2:29 reportAmbiguity d=0 (e): ambigAlts={1, 2}, input=..."). It produces a parse tree, despite these ambiguities (by chosing the first alternative, according to the documentation). But what can I do, if I want it to chose some other alternative? In other words, how can I explicitly

Where to get Python ANTLR package to use StringTemplate?

随声附和 提交于 2019-12-01 06:43:38
问题 I'd like to do some code generation, and StringTemplate looks like a pretty good tool for the job. I easy_installed stringtemplate3 from PyPi, but when I try to import it I get: ImportError: No module named antlr I am confused by this because I thought that ANTLR depended on StringTemplate (as the website says), not the other way around. In any case, I cannot find the correct package to fix this. Installing antlr_python_runtime did not help. Any hints? 回答1: You need to have the python-antlr