antlr3

ANTLR3 C Target - parser return 'misses' out root element

≡放荡痞女 提交于 2019-12-11 03:45:35
问题 I'm trying to use the ANTLR3 C Target to make sense of an AST, but am running into some difficulties. I have a simple SQL-like grammar file: grammar sql; options { language = C; output=AST; ASTLabelType=pANTLR3_BASE_TREE; } sql : VERB fields; fields : FIELD (',' FIELD)*; VERB : 'SELECT' | 'UPDATE' | 'INSERT'; FIELD : CHAR+; fragment CHAR : 'a'..'z'; and this works as expected within ANTLRWorks. In my C code I have: const char pInput[] = "SELECT one,two,three"; pANTLR3_INPUT_STREAM pNewStrm =

Evaluate IF subtree in homogeneus AST

别来无恙 提交于 2019-12-11 03:16:27
问题 I'm building a tree walker for an homogeneus AST (all nodes have same class), what's the correct way to evaluate an if statement? My AST for if are like this: I would something that when parses an IF block, evaluates sequentially his CONDBLOCK children and if one of them is true, the tree walker doesn't evaluate the remaining. More clearly, my tree walker is something like: ifStat : ^(IF { jump=false; } condition* defcond?) condition : { if (jump) return retval; } ^(CONDBLOCK exp block) {

Get active Antlr rule

Deadly 提交于 2019-12-11 02:48:47
问题 Is it possible to get the "active" ANTLR rule from which a action method was called? Something like this log-function in Antlr-Pseudo-Code which should show the start and end position of some rules without hand over the $start- and $end-tokens with every log()-call: @members{ private void log() { System.out.println("Start: " + $activeRule.start.pos + "End: " + $activeRule.stop.pos); } } expr: multExpr (('+'|'-') multExpr)* {log(); } ; multExpr : atom('*' atom)* {log(); } ; atom: INT | ID {log

How to get rid of the following multiple alternatives warnings in my ANTLR3 grammar?

天大地大妈咪最大 提交于 2019-12-10 21:21:26
问题 [11:45:19] warning(200): mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input [11:45:19] warning(200): C:\Users\Jarrod Roberson\mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input I want to be able to nest functions inside other functions. myfunction(x) -> sqr(a) -> a * a, y -> sqr(x). here is the

ANTLR 3, what does LT!* mean?

南笙酒味 提交于 2019-12-10 19:29:50
问题 I was looking at the code for a Javascript grammar written in ANTLR 3, http://www.antlr3.org/grammar/1206736738015/JavaScript.g In many instances I found program : LT!* sourceElements LT!* EOF! ; what does LT!* mean ? EDIT: From http://ftp.camk.edu.pl/camk/chris/antlrman/antlrman.pdf I found that LT stands for LOOKAHEAD TOKEN but it is the N th look ahead token, where is the N part in the above ? 回答1: No, LT does not mean LOOKAHEAD TOKEN in this context. It is a token defined nearly at the

ANTLR grammar for scheme R5RS

跟風遠走 提交于 2019-12-10 11:25:17
问题 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

ANTLR : rules with arguments?

烈酒焚心 提交于 2019-12-10 11:16:24
问题 I am new to ANTLR. I started exploring ANTLR tutorials. I have seen example where return type have been defined for perticular rule(see below example ). Can I pass argument to rule as well ? I just have throught in my mind, i wanted to change the behavior of rule at a pertucular state based on argument provided to it . please help me if it passible in ANTLR or is it a good idea to do that ? atom returns [int value] : INT { $value = Integer.parseInt($INT.text); } | ID // variable reference {

Ignore some part of input when parsing with ANTLR

别来无恙 提交于 2019-12-09 20:34:48
问题 I'm trying to parse a language by ANTLR (ANTLRWorks-3.5.2). The goal is to enter complete input but Antlr gives a parse tree of defined parts in grammar and ignore the rest of inputs, for example this is my grammar : grammar asap; project : '/begin PROJECT' name module+ '/end PROJECT'; module : '/begin MODULE'name '/end MODULE'; name : IDENT ; IDENT : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|':'|'-')*; Given input: /begin PROJECT HybridSailboat_2 /begin MODULE engine /begin A2ML

How to resolve Antlr3 dependency hell

柔情痞子 提交于 2019-12-09 14:36:45
问题 I have a asp.net MVC 4 project with MEF and RavenBD. When the project loads it throws this exception : Could not load file or assembly Antlr3.Runtime.dll I have found that both RavenDB and WebGrease (installed with MVC 4) use Antlr3. But WebGrease comes with its own Antlr3 dll, signed by Microsoft - PublicKeyToken 31bf3856ad364e35 Antlr3 default PublicKeyToken is eb42632606e9261f. RavenDB and WebGrease use the same version of Antlr3 3.3.1.7705 How can I resolve this problem? 回答1:

Parsing a templating language

旧巷老猫 提交于 2019-12-08 14:48:29
I'm trying to parse a templating language and I'm having trouble correctly parsing the arbitrary html that can appear between tags. So far what I have is below, any suggestions? An example of a valid input would be {foo}{#bar}blah blah blah{zed}{/bar}{>foo2}{#bar2}This Should Be Parsed as a Buffer.{/bar2} And the grammar is: grammar g; options { language=Java; output=AST; ASTLabelType=CommonTree; } /* LEXER RULES */ tokens { } LD : '{'; RD : '}'; LOOP : '#'; END_LOOP: '/'; PARTIAL : '>'; fragment DIGIT : '0'..'9'; fragment LETTER : ('a'..'z' | 'A'..'Z'); IDENT : (LETTER | '_') (LETTER | '_' |