antlr3

ANTLR - Distinguish 'IS NOT NULL' from 'IS NULL'

走远了吗. 提交于 2019-12-08 11:14:45
问题 How can I differentiate ' IS NOT NULL ' from ' IS NULL '? 'IS' and 'IS NOT' are defined in a parser rule, and 'NULL' in another rule, and the second follows the first. What happens is that when I write 'IS NULL', the Parser is excepting 'IS NOT NULL' because both second words begin with 'N' . How can I distinguish both? Grammar File query : expr EOF -> ^(QUERY expr) ; expr : logical_expr ; logical_expr : equality_expr (logical_op^ equality_expr)* ; equality_expr : ID equality_op atom -> ^

ANTLR trying to match token within longer token

泄露秘密 提交于 2019-12-08 06:45:23
问题 I'm new to ANTLR, and trying following grammar in ANTLRWorks1.4.3. command : 'go' SPACE+ 'to' SPACE+ destination ; destination : (UPPER | LOWER) (UPPER | LOWER | DIGIT)* ; SPACE : ' ' ; UPPER : 'A'..'Z' ; LOWER : 'a'..'z' ; DIGIT : '0'..'9' ; This seems to work OK, except when the 'destination' contains first two chars of keywords 'go' and 'to'. For instance, if I give following command: go to Glasgo the node-tree is displayed as follows: I was expecting it to match fill word as destination.

Compiling an ANTLR 3 grammar in C

天涯浪子 提交于 2019-12-08 05:20:59
问题 I've been trying to learn ANTLR and get it working with C output code using this tutorial (also referenced in this question). I successfully got ANTLR to generate the lexer and parser as C source, but I cannot get them to compile using gcc on Mac OS X Snow Leopard (i686-apple-darwin10-gcc-4.2.1). Below is the result when I try to compile the "SimpleCalcLexer.c". dyn-72-33-132-199:Desktop bf$ gcc -o lexer SimpleCalcLexer.c Undefined symbols: "_main", referenced from: start in crt1.10.6.o "

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

馋奶兔 提交于 2019-12-07 20:18:20
问题 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

Generating a JavaScript SQL parser for SQLite3 (with Lemon? ANTLR3?)

寵の児 提交于 2019-12-07 19:41:52
问题 For the last couple of weeks i've been diving into the pretty world of parsing SQL statements into something managable, only to find out that i'll probably need a full lexer/parser to properly handle all the allowed tokens/formats to do the same thing. I'm mostly interested in the create table statements, but a full generic parser would be even nicer, since nobody on the web seems to have this yet. I'm no computer graduate, but a self-taught man, so this is quite the learning curve for me.

Solving ANTLR Mutually left-recursive rules

£可爱£侵袭症+ 提交于 2019-12-07 17:52:14
问题 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' | '(' | ')'

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

南笙酒味 提交于 2019-12-07 15:38:12
问题 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.

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

三世轮回 提交于 2019-12-07 15:27:03
问题 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

ANTLR generating invalid java exceptions throws code

女生的网名这么多〃 提交于 2019-12-07 07:53:26
问题 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 /

ANTLR Implicit Multiplication

非 Y 不嫁゛ 提交于 2019-12-07 07:07:06
问题 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