antlr

ANTLRv4: non-greedy rules

旧时模样 提交于 2019-12-30 07:12:17
问题 I'm reading the definite ANTLR4 reference and have a question regarding one of the examples (p. 76): STRING: '"' (ESC|.)*? '"'; fragment ESC: '\\"' | '\\\\' ; The rule matches a typical C++ string - a char sequence included in "" , which can contain \" too. In my expectation, the rule STRING should match the smallest string possible because of the non-greedy construct. So if it sees a \" it would map \ to . and " to " at the end of the rule, since this would result in the smallest string

Syntax of semantic predicates in Antlr4

放肆的年华 提交于 2019-12-30 06:06:46
问题 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. 回答1: There is now just a single type of semantic

Syntax of semantic predicates in Antlr4

放肆的年华 提交于 2019-12-30 06:06:10
问题 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. 回答1: There is now just a single type of semantic

How could I generate Java CFG(Control Flow Graph) using antlr?

做~自己de王妃 提交于 2019-12-30 05:25:10
问题 I am trying to analyse Java code sturcture. So, I generated a Java parser and lexer by using ANTLRv3 and java grammar code... but I don't know how could I generate Context Flow Graph using the generated parser and lexer. I tried to learn how to do this through tutorial page, but the tutorial page has already disappeared. Could you give me a way how to do this? or tutorial page? Thank you. 回答1: AFAIK, ANTLR provides no specific help in building a control flow graph. You can build one yourself

How to get ANTLR 3.2 to exit upon first error?

本小妞迷上赌 提交于 2019-12-30 04:34:08
问题 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? 回答1: I posted this question

Is there a way to generate unit test to test my grammar

假如想象 提交于 2019-12-29 09:11:15
问题 I created my grammar using antlr4 but I want to test robustess is there an automatic tool or a good way to do that fast Thanks :) 回答1: The only way I found to create unit tests for a grammar is to create a number of examples from a written spec of the given language. This is neither fast, nor complete, but I see no other way. You could be tempted to create test cases directly from the grammar (writing a tool for that isn't that hard). But think a moment about this. What would you test then?

ANTRL4: Can't get Python ANTLR to generate a graphic of the parse tree

﹥>﹥吖頭↗ 提交于 2019-12-29 08:03:31
问题 I have a simple HelloWorld.g4 grammar (see it at the bottom). I am able to successfully generate the .py files using this: set CLASSPATH=.;antlr-complete.jar;%CLASSPATH% java org.antlr.v4.Tool -Dlanguage=Python2 HelloWorld.g4 Now I would like to use the TestRig with the -gui flag to generate a parse tree GUI. I have the ANTRL Python runtime installed ( antlr4-python2-runtime-4.5.tar.gz ). I can open a Python interpreter and type: import antlr4 and the interpreter recognizes the antlr4 module.

ANTRL4: Can't get Python ANTLR to generate a graphic of the parse tree

时间秒杀一切 提交于 2019-12-29 08:03:13
问题 I have a simple HelloWorld.g4 grammar (see it at the bottom). I am able to successfully generate the .py files using this: set CLASSPATH=.;antlr-complete.jar;%CLASSPATH% java org.antlr.v4.Tool -Dlanguage=Python2 HelloWorld.g4 Now I would like to use the TestRig with the -gui flag to generate a parse tree GUI. I have the ANTRL Python runtime installed ( antlr4-python2-runtime-4.5.tar.gz ). I can open a Python interpreter and type: import antlr4 and the interpreter recognizes the antlr4 module.

ANTLR and Android

百般思念 提交于 2019-12-29 07:19:10
问题 is there any guide how to use ANTLR on Android? I have found some ANTLR portation for Android but it looks like being without any tutorial or manual. Do you know where to find some? (and yes, I have been googling...) Thx 回答1: After reading the README from this ANTLR port: AntlrJavaRuntime - Earlence Fernandes, The CRePE Project, VU Amsterdam ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The Runtime is available as an external library against which apps can link. It

ANTLR: From CommonTree to useful object graph

白昼怎懂夜的黑 提交于 2019-12-28 13:37:09
问题 I started using ANTLR today and I've created a basic parser. After parsing I end up with a tree. To me it seems like this is just a bunch of String s put together in a tree structure of Tree -nodes. That's not very useful to me. I'd like to have a graph of objects. To clarify (this is an example, and not my real application): For "5-1+6" I seem to end up with: new String("PLUS") new String("MINUS") new String("5") new String("1") new String("6") What I would find more useful: new Plus( new