antlr3

if then else conditional evaluation

对着背影说爱祢 提交于 2020-01-11 02:20:06
问题 I have a language which basically is meant to map columns to a new structure in an array. The language is meant for product managers to define mappings without having to know a lot of programming details. I'm sure there is a lot more to improve here but this is what I have. The language works, mostly. The problem I have is with conditional statements. My parser has the following rule: conditionalexpr : IF^ LPAREN! (statement) RPAREN! THEN! LCURLY! statement RCURLY! (ELSE! LCURLY! statement

Ignore tokens in the token characters?

不想你离开。 提交于 2020-01-07 06:39:57
问题 I have the following token definition in my lexer defining a CharacterString (e.g. 'abcd'): CharacterString: Apostrophe (Alphanumeric)* Apostrophe ; Is it possible to ignore the two apostrophes to then be able to get the token string without them in the lexer (via $CharacterString.text->chars)? I tried ... CharacterString: Apostrophe { $channel = HIDDEN; } (Alphanumeric)* Apostrophe { $channel = HIDDEN; } ; ... without success... This case does not even match my string anymore (e.g. 'oiu'

ANTLR3 grammar does not match rule with predicate

这一生的挚爱 提交于 2020-01-06 04:16:29
问题 I have a combined grammar where I need to provide for two identifier lexer rules. Both identifiers can be used at the same time. Identifier1 comes before Identifer2 in grammar. First identifier is static, whereas second identifier rule changes on the basis of some flag.(Using predicate). I want the second identifier to match in parser rules. But as both identifiers may match some common inputs, It does not fall on identifer2. I have created small grammar to make it understandable. Grammar is

Combining Antlr 3.5.2 with StringTemplate 4 for code generation

怎甘沉沦 提交于 2020-01-05 13:09:37
问题 Current project I'm working on is limited to using antlr 3.5.2, but I would like to use the featureset of StringTemplate 4 for our code generation. Can antlr 3.5.2 generate a java treewalker that uses StringTemplate 4? (e.g. a tree grammer with output=template that results in a java file with ST* references instead of StringTemplate*) 回答1: The output=template option only supports StringTemplate 3. You can still support StringTemplate 4, but it would require using embedded actions or a hand

numerous template errors generating OracleSQL grammar using Antlr-3.5-complete.jar

倾然丶 夕夏残阳落幕 提交于 2020-01-04 05:55:07
问题 The same oracle SQL grammar generates without errors using Antlr-3.3-complete.jar and compiles successfully using Netbeans/GCC or Visual Studio. Generating the grammar with Antlr-3.5-complete.jar generates 23500 lines of warning messages describing template errors including several hundred exceptions. The code is generated using the following command line: java -d64 -Xmn2000M -Xmx8000M -jar antlr-3.5-complete.jar OracleSQL_v2.g antlr-3.5-complete.jar was downloaded from the antlr.org site on

'IDENTIFIER' rule also consumes keyword in ANTLR Lexer grammar

扶醉桌前 提交于 2020-01-02 05:24:07
问题 While working on Antlr 3.5 grammar for Java parsing noticed that ' IDENTIFIER ' rule consumes few Keywords in ANTLR Lexer grammar. The Lexer grammar is lexer grammar JavaLexer; options { //k=8; language=Java; filter=true; //backtrack=true; } @lexer::header { package java; } @lexer::members { public ArrayList<String> keywordsList = new ArrayList<String>(); } V_DECLARATION : ( ((MODIFIERS)=>tok1=MODIFIERS WS+)? tok2=TYPE WS+ var=V_DECLARATOR WS* ) {...}; fragment V_DECLARATOR : ( tok=IDENTIFIER

ANTLR parser hanging at proxy.handshake call

元气小坏坏 提交于 2020-01-02 05:14:18
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new

ANTLR parser hanging at proxy.handshake call

我只是一个虾纸丫 提交于 2020-01-02 05:14:05
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new

Extending simple ANTLR grammar to support input variables

て烟熏妆下的殇ゞ 提交于 2019-12-28 08:10:29
问题 I'm still on my quest for a really simple language and I know now that there are none. So I'm writing one myself using ANTLR3. I found a really great example in this answer: Exp.g: grammar Exp; eval returns [double value] : exp=additionExp {$value = $exp.value;} ; additionExp returns [double value] : m1=multiplyExp {$value = $m1.value;} ( '+' m2=multiplyExp {$value += $m2.value;} | '-' m2=multiplyExp {$value -= $m2.value;} )* ; multiplyExp returns [double value] : a1=atomExp {$value = $a1

Negating inside lexer- and parser rules

此生再无相见时 提交于 2019-12-28 02:55:26
问题 How can the negation meta-character, ~ , be used in ANTLR's lexer- and parser rules? 回答1: Negating can occur inside lexer and parser rules. Inside lexer rules you can negate characters, and inside parser rules you can negate tokens (lexer rules). But both lexer- and parser rules can only negate either single characters, or single tokens, respectively. A couple of examples: lexer rules To match one or more characters except lowercase ascii letters, you can do: NO_LOWERCASE : ~('a'..'z')+ ;