antlr3

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

老子叫甜甜 提交于 2019-12-02 13:44:43
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. 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 therefore will not match the expected CHARS HYPHEN CHARS . You should consider making TOKEN a parser rule instead

What is the equivalent for epsilon in ANTLR BNF grammar notation?

只愿长相守 提交于 2019-12-01 17:22:06
During taking advantage of ANTLR 3.3, I'm changing the current grammar to support inputs without parenthesis too. Here's the first version of my grammar : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ; IMPLIES : '->' ; SYMBOLS : ('a'..'z') | '~' ; OP : '(' ; CP : ')' ; prog : formula EOF ; formula : NOT formula | OP formula( AND formula CP | OR formula CP | IMPLIES formula CP) | SYMBOLS ; WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; Then I changed it this way to support the appropriate features : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ;

What is the equivalent for epsilon in ANTLR BNF grammar notation?

倖福魔咒の 提交于 2019-12-01 17:06:59
问题 During taking advantage of ANTLR 3.3, I'm changing the current grammar to support inputs without parenthesis too. Here's the first version of my grammar : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ; IMPLIES : '->' ; SYMBOLS : ('a'..'z') | '~' ; OP : '(' ; CP : ')' ; prog : formula EOF ; formula : NOT formula | OP formula( AND formula CP | OR formula CP | IMPLIES formula CP) | SYMBOLS ; WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; Then I changed it

ANTLR3 throws internal error with java.lang.NullPointerException

China☆狼群 提交于 2019-12-01 12:06:23
问题 I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error Here is the Sample.g grammar Sample; options { memoize=true; output=AST; } tokens { RegExp; } RegExpression: '/' (a=~('/' | NL))+ '/' -> ^(RegExp[$RegExpression.start, $RegExpression.text] $a+ ) ; fragment NL: '\n' | '\r'; ANY : . ; I run the command: java -jar antlr-3.5.2-complete.jar -print Sample.g and it gives this: error(10): internal error: Sample.g : java.lang.NullPointerException org.antlr

Antlr3.runtime access denied after updating deployed files

不羁的心 提交于 2019-12-01 05:36:26
We have an ASP.NET application that was written by a former employee that I have thus far been holding together with duct tape. The app was written with MVC, NHibernate and some other processes, none of which any of our other apps use, so I have very little idea on how to support these. To further complicate things, the original app was not built to deploy properly, so I have had to follow a set of instructions from said employee about which files to copy where to get the updates out manually. I attempted to do an update today, making a backup of the entire folder where the app resides in C:

caret prefix instead of postfix in antlr

流过昼夜 提交于 2019-12-01 03:57:16
问题 I know what the caret postfix means in antlr(ie. make root) but what about when the caret is the prefix as in the following grammar I have been reading(this grammar is brand new and done by a new team learning antlr).... selectClause : SELECT resultList -> ^(SELECT_CLAUSE resultList) ; fromClause : FROM tableList -> ^(FROM_CLAUSE tableList) ; Also, I know what => means but what about the -> ? What does -> imply? thanks, Dean 回答1: The ^ is used as an inline tree operator, indicating a certain

Antlr3.runtime access denied after updating deployed files

孤街浪徒 提交于 2019-12-01 03:37:02
问题 We have an ASP.NET application that was written by a former employee that I have thus far been holding together with duct tape. The app was written with MVC, NHibernate and some other processes, none of which any of our other apps use, so I have very little idea on how to support these. To further complicate things, the original app was not built to deploy properly, so I have had to follow a set of instructions from said employee about which files to copy where to get the updates out manually

Extend ANTLR3 AST's

こ雲淡風輕ζ 提交于 2019-11-30 23:24:42
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 tried to search their site and samples for somthing similar. Any hints? EDIT I'm not trying to create

if then else conditional evaluation

空扰寡人 提交于 2019-11-30 20:20:38
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 RCURLY!)?; Which works to generate a tree with three children. My problem is to avoid evaluating the

A simple ANTLR 3.4 example for C target runtime

只愿长相守 提交于 2019-11-30 16:04:57
问题 Does anyone know of (or have) a simple ANTLR 3.4 example main() function for C target? I'm trying to get started with ANTLR in C or C++, and all examples I see (including this) are out of date, e.g. they use functions that don't exist any more. There don't seem to be any examples with downloaded package itself, and the example on Wiki is out of date. 回答1: Untested. #include "YourLexer.h" #include "YourParser.h" int main() { uint8_t * bufferData; // Some memory with text in it uint32_t