antlr3

Antlr3 matching tokens without whitespace

元气小坏坏 提交于 2019-12-23 21:06:13
问题 Given the input "term >1" , the number(1) and comparison operator(>) should generate seperate nodes in an AST. How can this be achieved? In my tests matching only occured if "c" and "1" where seperated with a space like so " term < 1 ". Current grammar: startExpression : orEx; expressionLevel4 : LPARENTHESIS! orEx RPARENTHESIS! | atomicExpression; expressionLevel3 : (fieldExpression) | expressionLevel4 ; expressionLevel2 : (nearExpression) | expressionLevel3 ; expressionLevel1 :

boolean and arithmetic expression grammar in ANTLR

夙愿已清 提交于 2019-12-23 11:11:47
问题 I'm trying to write a grammar for arithmetic and boolean expressions. I don't understand what I'm doing wrong. For my grammar, ANTLR says: [fatal] rule logic_atom has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option. But I can't do a left-factoring. And I don't want to touch arith_expr , because for this I have a code. Error in logic_atom : LBR logic_expr RBR | cmp_expr ; My

Antlr parser for and/or logic - how to get expressions between logic operators?

南笙酒味 提交于 2019-12-23 03:55:58
问题 I am using ANTLR to create an and/or parser+evaluator. Expressions will have the format like: x eq 1 && y eq 10 (x lt 10 && x gt 1) OR x eq -1 I was reading this post on logic expressions in ANTLR Looking for advice on project. Parsing logical expression and I found the grammar posted there a good start: grammar Logic; parse : expression EOF ; expression : implication ; implication : or ('->' or)* ; or : and ('&&' and)* ; and : not ('||' not)* ; not : '~' atom | atom ; atom : ID | '('

Including external C library with Xcode

不羁岁月 提交于 2019-12-23 03:25:11
问题 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

Looking for Antlr 3 / C sample main()

让人想犯罪 __ 提交于 2019-12-23 01:41:45
问题 I see a few sample main() for C floating about, e.g. http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 and http://www.antlr.org/api/C/index.html The dereference seems to be AST. I don't know what that is , and - please excuse me - don't want to if I can avoid it. I woudl like to just define the lexer & grammar (for modem AT commands) and have the main() auto-generated, or cut/pasted from somewhere. Ons slight twist is that most examples seem to read from a file,

Status of Javascript in antlr 3.4 or 3.5 [closed]

佐手、 提交于 2019-12-22 11:14:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . 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

ANTLR lexer rule consumes characters even if not matched?

痴心易碎 提交于 2019-12-22 06:09:21
问题 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

How can I modify the text of tokens in a CommonTokenStream with ANTLR?

自作多情 提交于 2019-12-21 02:00:58
问题 I'm trying to learn ANTLR and at the same time use it for a current project. I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is being broken up into the appropriate tokens. Now, I would like to be able to modify the text of certain tokens in this stream, and display the now modified source code. For example I've tried: import org.antlr.runtime.*; import java.util.*; public

Antlr3: Could not match token in parser rules which is used in lexer rule

旧城冷巷雨未停 提交于 2019-12-20 07:27:58
问题 I have lexer rules in Antlr3 as: HYPHEN : '-'; TOKEN : HYPHEN CHARS; CHARS : 'a' ..'z'; Parser rule is as: exp : CHARS | some complex expression; parser_rule : exp HYPHEN exp; If I try to match 'abc-abc' with parser_rule, It fails. Because lexer creates TOKEN for HYPHEN exp. How can I match it correctly with parser_rule. 回答1: In ANTLR lexer, the lexer rule that can match the longest sub-sequence of input is used. So your input abc-abc will be tokenized as CHARS("abc") TOKEN("-abc") and

Extend ANTLR3 AST's

余生颓废 提交于 2019-12-19 04:05:48
问题 With ANTLR2, you could define something like this in grammar definition file: options { language = "CSharp"; namespace = "Extended.Tokens"; } tokens { TOKEN<AST=Extended.Tokens.TokenNode>; } And then, you could create a class: public class TokenNode: antlr.BaseAST { ... } Any ideea if something like this can be used (delegate class creation to AST factory instead of me doing the tree replication manually)? It's not working just by simple grammar definition copy from old to new format, and I