antlr3

Solving ANTLR Mutually left-recursive rules

China☆狼群 提交于 2019-12-06 03:54:38
the 'expr' rule in the ANTLR grammar below obviously mutually left-recursive. As a ANTLR newbie it's difficult to get my head around solving this. I've read "Resolving Non-LL(*) Conflicts" in the ANTLR reference book, but I still don't see the solution. Any pointers? LPAREN : ( '(' ) ; RPAREN : ( ')' ); AND : ( 'AND' | '&' | 'EN' ) ; OR : ( 'OR' | '|' | 'OF' ); NOT : ('-' | 'NOT' | 'NIET' ); WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; WORD : (~( ' ' | '\t' | '\r' | '\n' | '(' | ')' | '"' ))*; input : expr EOF; expr : (andexpr | orexpr | notexpr | atom); andexpr : expr AND expr;

Status of Javascript in antlr 3.4 or 3.5 [closed]

大城市里の小女人 提交于 2019-12-06 03:03:22
What is the status of the JavaScript target in ANTLR 3.4 or 3.5? I have been looking online for an answer to this question but so far I have found nothing. I know that it was broken in v3.2 and then it was fixed in v3.3, but it's not listed in the ANTLR 3.4 release notes as a target that is consistent with ANTLR 3.4. I have a project in which I need to convert the Java target ANTLR grammar which I had previously written to JavaScript and I want to make sure that the JavaScript target is supported by ANTLR 3.4 or 3.5 before I proceed. Bart Kiers ANTLR 3.1 and 3.2 had some bugs w.r.t. generating

How to get line number in ANTLR3 tree-parser @init action

僤鯓⒐⒋嵵緔 提交于 2019-12-05 21:08:16
In ANTLR, version 3, how can the line number be obtained in the @init action of a high-level tree-parser rule? For example, in the @init action below, I'd like to push the line number along with the sentence text. sentence @init { myNodeVisitor.pushScriptContext( new MyScriptContext( $sentence.text )); } : assignCommand | actionCommand; finally { m_nodeVisitor.popScriptContext(); } I need to push the context before the execution of the actions associated with symbols in the rules. Some things that don't work: Using $sentence.line -- it's not defined, even though $sentence.text is. Moving the

How do I install ANTLR IDE with Eclipse Juno and PDT (PHP)

[亡魂溺海] 提交于 2019-12-05 18:24:26
I develop in both PHP and Java. Eclipse PDT appears to require DLTK 4.0, which it has no problem getting. ANTLR IDE appears to require DLTK3. I've tried copying the plugins 3.0 into my Eclipse plugins / features directory: http://download.eclipse.org/technology/dltk/downloads/drops/R3.0/S-3.0.1-201108261011/ This worked on a machine without PDT, but I can't get it to work when I have PDT. I have also tried using the marketplace, but I get the same dependency errors. Note I'm on 64bit Linux. Try to add the DLTK 3.0 repository and then install ANTLR again, so maybe Eclipse can fetch the plugin

ANTLR Implicit Multiplication

纵饮孤独 提交于 2019-12-05 18:12:55
I'm new to ANTLR, and I'm trying to expand upon the example of a simple calculator presented here . Specifically, I've tried adding some simple functions, negative numbers and so on, to familiarize myself with ANTLR. However, I've run into a bit of a problem trying to implement "implicit" multiplication (for example, 3cos(2)sin(2) would be interpreted as 3*cos(2)*sin(2)). I've found a question on Stack Overflow with the same kind of problem ( here ). The general form of the solution to that problem looks like what I'd found on my own, so I'm not sure where my problem lies. My grammar is below.

ANTLR parser hanging at proxy.handshake call

久未见 提交于 2019-12-05 17:17:21
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 ES3Lexer(MyChars); CommonTokenStream MyTokens = new CommonTokenStream(MyLexer); MyTokens.setTokenSource

ANTLR generating invalid java exceptions throws code

南笙酒味 提交于 2019-12-05 16:08:49
I've been using ANTLRwork 1.5 these days, together with antlr runtime 3.5. Here is a weird thing i found: Antlr is generating this kind of java code for me: public final BLABLABLAParser.addExpression_return addExpression() throws { blablabla... } notice that this function throws nothing, and this is invalid in java. So I need to correct these mistakes manually. Anyone knows why? here is the sample grammar, it's directly taken from the book Language implementation patterns . // START: header // START: header grammar Cymbol; // my grammar is called Cymbol options { output = AST; ASTLabelType =

ANTLR lexer rule consumes characters even if not matched?

笑着哭i 提交于 2019-12-05 10:16:13
I've got a strange side effect of an antlr lexer rule and I've created an (almost) minimal working example to demonstrate it. In this example I want to match the String [0..1] for example. But when I debug the grammar the token stream that reaches the parser only contains [..1] . The first integer, no matter how many digits it contains is always consumed and I've got no clue as to how that happens. If I remove the FLOAT rule everything is fine so I guess the mistake lies somewhere in that rule. But since it shouldn't match anything in [0..1] at all I'm quite puzzled. I'd be happy for any

“FOLLOW_set_in_”… is undefined in generated parser

我们两清 提交于 2019-12-05 04:16:09
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 operators: ... prio3Expression: prio2Expression (('*' | '/' | '%') prio2Expression)*; prio2Expression: ('+

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

北城以北 提交于 2019-12-04 21:35:01
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 LOWCHAR : 'a'..'z'; /** uppercase letters */ fragment HIGHCHAR : 'A'..'Z'; parse: IDENTIFIER KEYWORD EOF