antlr3

What does ^ and ! stand for in ANTLR grammar

时光怂恿深爱的人放手 提交于 2019-12-07 05:04:31
问题 I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology. 回答1: Have a look at the ANTLR Cheat Sheet: ! don't include in AST ^ make AST root node And ^ can also be used in rewrite rules: ... -> ^( ... ) . For example, the following two parser rules are equivalent: expression : A '+'^ A ';'! ; and: expression : A '+' A ';' -> ^('+' A A) ; Both create the following AST: + / \ A A In other words: the + is made as root, the two A 's its children, and the ; is

“FOLLOW_set_in_”… is undefined in generated parser

北慕城南 提交于 2019-12-07 01:40:22
问题 I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable. I use AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 apparently does not support C target). The problem is with expression rules. I have rules prio14Expression to prio0Expression which handle operator precedence. To problem is at priority 2, which evaluates prefix and postfix

ANTLR3 throws internal error with java.lang.NullPointerException

帅比萌擦擦* 提交于 2019-12-06 16:21:58
问题 I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error Here is the Sample.g grammar Sample; options { memoize=true; output=AST; } tokens { RegExp; } RegExpression: '/' (a=~('/' | NL))+ '/' -> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ ) ; fragment NL: '\n' | '\r'; ANY : . ; I run the command: java -jar antlr-3.5.2-complete.jar -print Sample.g and it gives this: error(10): internal error: Sample.g : java.lang.NullPointerException org.antlr

Including external C library with Xcode

安稳与你 提交于 2019-12-06 15:14:42
I have a built C static library (the Antlr 3 C library). It is installed properly and works (i.e., I can run gcc -o parser lexer.c parser.c -lantlr3c just fine). In Xcode, however, I get an error. I've added -lantlr3c in the "other linker flags" build setting. ld: library not found for -lantlr3c Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 Several other questions I've found here ( 1 , 2 , 3 , 4 ) generally have answers targeting Xcode 3. I'm using Xcode 4.1, in an iOS static library project. I'm currently building the unit test

How Lexer lookahead works with greedy and non-greedy matching in ANTLR3 and ANTLR4?

五迷三道 提交于 2019-12-06 12:49:41
问题 If someone would clear my mind from the confusion behind look-ahead relation to tokenizing involving greery/non-greedy matching i'd be more than glad. Be ware this is a slightly long post because it's following my thought process behind. I'm trying to write antlr3 grammar that allows me to match input such as: "identifierkeyword" I came up with a grammar like so in Antlr 3.4: KEYWORD: 'keyword' ; IDENTIFIER : (options {greedy=false;}: (LOWCHAR|HIGHCHAR))+ ; /** lowercase letters */ fragment

Parse stacked comparison expression into logical Conjunction Tree with antlr3

痞子三分冷 提交于 2019-12-06 12:45:56
问题 I have run into a problem, when i tried to parse a stacked arithmetic comparison expression: "1<2<3<4<5" into a logical Tree of Conjunctions: CONJUNCTION(COMPARISON(1,2,<) COMPARISON(2,3,<) COMPARISON(3,4,<) COMPARISON(4,5,<)) Is there a way in Antlr3 Tree Rewrite rules to iterate through matched tokens and create the result Tree from them in the target language (I'm using java)? So i could make COMPARISON nodes from element x, x-1 of matched 'addition' tokens. I know i can reference the last

simple criteria expression parser with antlr3

故事扮演 提交于 2019-12-06 10:36:44
I want to create a simple criteria expression parser with antlr3 Updated: separate AND OR expression rules to support AND/OR different hierarchy, but got another problems: if the expression is something like: a = 1 and b = 2 and c = 3 The tree should be as following according to current implement: = = (a = 1)(b = 2)(c = 3) But I want to generate it as follows: = = (a = 1)(b = 2) (c = 3) First "and" should be higher priority than another, because I want to parse all the expression as left exp and right exp. I think I need to re-write the rule in the "subcond" To make a = 1 and b = 2 and c = 3 -

Python+ANTLR4: No module named antlr4

╄→гoц情女王★ 提交于 2019-12-06 08:53:24
I would like to use ANTLR4 with Python 2.7 and for this I did the following: I installed the package antlr4-4.6-1 on Arch Linux with sudo pacman -S antlr4 . I wrote a MyGrammar.g4 file and successfully generated Lexer and Parser Code with antlr4 -Dlanguage=Python2 MyGrammar.g4 Now executing for example the generated Lexer code with python2 MyGrammarLexer.py results in the error ImportError: No module named antlr4 . What could to be the problem? FYI: I have both Python2 and Python3 installed - I don't know if that might cause any trouble. You need to install antlr4 for python through pip : sudo

regresion: Antlr C target follow set generates reference to undeclared identifier

戏子无情 提交于 2019-12-06 06:52:15
ANTLRWorks 1.5rc1 successfully generated the C target code for this grammar with no warnings or errors but the C target code would not compile. ANTLRWorks 1.5 generated the same bad C target code but the console listed many template errors. ANTLRWorks 1.4.3 generated valid C target code that compiles without error. error C2065: 'FOLLOW_set_in_sqlCOMP_OP2185' : undeclared identifier Rule sqlCOMP_OP is referenced from multiple boolean expression rules All of the rules that generated references to undefined identifiers were of the form: fule: (Tokena | Tokenb | Tokenc)? Tokend; or there were

ANTLR grammar for scheme R5RS

你说的曾经没有我的故事 提交于 2019-12-06 05:09:31
I'm beginner in ANTLR and I'm learning it by an example. I use C as my target language. The example is a Scheme R5RS grammar file taken from this question , with a little modification(rename the grammar name and add some options with the grammar specification untouched). antlr generated the lexer and parser, and I compile it with a test main() in which I just do some initialization and simply call the parser. When runing the test program with a piece of scheme code, the parser detect some syntax error(which should not happen!) main function in test.c #include <stdio.h> #include "r5rsLexer.h"