antlr

Antlr left recursive problem

為{幸葍}努か 提交于 2019-11-30 19:09:02
问题 I have a left recursive issue in my Antlr grammar. While I think I understand why there is a problem I am unable to think of a solution. The issue is with the last line for my datatype rule. I have included the entire grammar for you to see: grammar Test; options {output=AST;ASTLabelType=CommonTree;} tokens {FUNCTION; ATTRIBUTES; CHILDREN; COMPOSITE;} program : function ; function : ID (OPEN_BRACKET (attribute (COMMA? attribute)*)? CLOSE_BRACKET)? (OPEN_BRACE function* CLOSE_BRACE)? SEMICOLON

Parse comment line

ⅰ亾dé卋堺 提交于 2019-11-30 18:53:01
Given the following basic grammar I want to understand how I can handle comment lines. Missing is the handling of the <CR><LF> which usually terminates the comment line - the only exception is a last comment line before the EOF, e. g.: # comment abcd := 12 ; # comment eof without <CR><LF> grammar CommentLine1a; //========================================================== // Options //========================================================== //========================================================== // Lexer Rules //========================================================== Int : Digit+ ;

Parsing Context Sensitive Language

吃可爱长大的小学妹 提交于 2019-11-30 18:52:20
i am reading the Definitive ANTLR reference by Terence Parr, where he says: Semantic predicates are a powerful means of recognizing context-sensitive language structures by allowing runtime information to drive recognition But the examples in the book are very simple. What i need to know is: can ANTLR parse context-sensitive rules like: xAy --> xBy If ANTLR can't parse these rules, is there is another tool that deals with context-sensitive grammars? ANTLR parses only grammars which are LL(*). It can't parse using grammars for full context-sensitive languages such as the example you provided. I

记一次antlr错误:ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.2ANTLR

落爺英雄遲暮 提交于 2019-11-30 18:33:38
使用idea运行重构好的spark sql,在编译期出现如下错误: ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.2ANTLR 原因: <dependency> <groupId>org.antlr</groupId> <artifactId>antlr4-runtime</artifactId> </dependency> 点击进入依赖,看当前antlr4的底层的依赖: <plugin> <groupId>org.antlr</groupId> <artifactId>antlr4-maven-plugin</artifactId> <version>4.5.3</version> <!-- use older version to process XPathLexer.g4, avoiding cyclic build dependency --> <executions> <execution> <id>antlr</id> <configuration> <sourceDirectory>src</sourceDirectory> </configuration> <goals> <goal>antlr4</goal> <

Syntax of semantic predicates in Antlr4

喜你入骨 提交于 2019-11-30 18:24:59
In What is a 'semantic predicate' in ANTLR3? Bart Kiers gives a very well overview about the different semantic predicates in Antlr3. Too bad the syntax/semantics were seemingly changed in Antlr4, so this does not compile: end_of_statement : ';' | EOF | {input.LT(1).getType() == RBRACE}? => ; RBRACE : '}' ; Could someone please tell me how to do the third case of end_of_statement : Accept if the next token is a '}' but do not consume it. There is now just a single type of semantic predicates, which looks like this: { <<boolean-epxression>> }? And the input attribute from the abstract class

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

How to Display ANTLR Tree GUI

半世苍凉 提交于 2019-11-30 14:09:32
How do you display the AST GUI if you have code like this, both of console or swing? My ANTLR is version 3. CharStream stream = new ANTLRStringStream("program XLSample1 =\n" + "constant one : Integer := 1;\n" + "constant two : Integer := 2;\n" + "var a, b,c : Integer := 42;\n" + "begin\n" + " x:= (12 + 6) - (7 * 41) - x mod y;\n" + " y := 21;\n" + "\n" + "if x < 10 then\n" + " y :=2;\n" + " elseif x < 20 then\n" + " y := 20;\n" + " else\n" + " y := 30;\n" + "end if; \n" + "end XLSample1."); SampleLexer lexer = new SampleLexer(stream); TokenStream tokenStream = new CommonTokenStream(lexer);

ANTLR grammar for reStructuredText (rule priorities)

懵懂的女人 提交于 2019-11-30 13:33:08
问题 First question stream Hello everyone, This could be a follow-up on this question: Antlr rule priorities I'm trying to write an ANTLR grammar for the reStructuredText markup language. The main problem I'm facing is : "How to match any sequence of characters (regular text) without masking other grammar rules?" Let's take an example with a paragraph with inline markup: In `Figure 17-6`_, we have positioned ``before_ptr`` so that it points to the element *before* the insert point. The variable `

How to get ANTLR 3.2 to exit upon first error?

时光毁灭记忆、已成空白 提交于 2019-11-30 13:26:44
In section 10.4, The Definitive ANTLR reference tells you to override mismatch() & recoverFromMismatchedSet() if you want to exit upon the first parsing error. But, at least in ANTLR 3.2, it appears that there is no mismatch() method, and the recoverFromMismatchedSet() documentation says that it is "Not Currently Used". So it appears things have changed since the book was published. What am I supposed to do instead to exit upon the first parsing error in ANTLR 3.2? I posted this question to anltr-interest, and Andrew Haritonkin answered. Bart K is half right; you need to override

In antlr4 lexer, How to have a rule that catches all remaining “words” as Unknown token?

我的梦境 提交于 2019-11-30 12:47:25
I have an antlr4 lexer grammar. It has many rules for words, but I also want it to create an Unknown token for any word that it can not match by other rules. I have something like this: Whitespace : [ \t\n\r]+ -> skip; Punctuation : [.,:;?!]; // Other rules here Unknown : .+? ; Now generated matcher catches '~' as unknown but creates 3 '~' Unknown tokens for input '~~~' instead of a single '~~~' token. What should I do to tell lexer to generate word tokens for unknown consecutive characters. I also tried "Unknown: . ;" and "Unknown : .+ ;" with no results. EDIT: In current antlr versions .+?