antlrworks

Hints regarding the use of ANTLR v3 generated files in Flash Builder 4.5.1

霸气de小男生 提交于 2019-12-07 18:31:11
问题 According to these instructions, I'm trying to use ANTLR generated *.as files in a current Flash Builder 4.5.1 project. Therefore, I added this ANTLR's Actionscript runtime to my project - without problems. I compiled lexer/parser specs using ANTLRWorks without problems too. I added the language option to the source *.g file to make ANTLR generate Actionscript sources: options { backtrack = true; memoize = true; k=2; output = AST; language=ActionScript; // Added this ASTLabelType = CommonTree

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 /

What does ^ and ! stand for in ANTLR grammar

时光怂恿深爱的人放手 提交于 2019-12-07 05:04:31
问题 I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology. 回答1: Have a look at the ANTLR Cheat Sheet: ! don't include in AST ^ make AST root node And ^ can also be used in rewrite rules: ... -> ^( ... ) . For example, the following two parser rules are equivalent: expression : A '+'^ A ';'! ; and: expression : A '+' A ';' -> ^('+' A A) ; Both create the following AST: + / \ A A In other words: the + is made as root, the two A 's its children, and the ; is

“FOLLOW_set_in_”… is undefined in generated parser

北慕城南 提交于 2019-12-07 01:40:22
问题 I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable. I use AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 apparently does not support C target). The problem is with expression rules. I have rules prio14Expression to prio0Expression which handle operator precedence. To problem is at priority 2, which evaluates prefix and postfix

Hints regarding the use of ANTLR v3 generated files in Flash Builder 4.5.1

淺唱寂寞╮ 提交于 2019-12-06 13:38:29
According to these instructions , I'm trying to use ANTLR generated *.as files in a current Flash Builder 4.5.1 project. Therefore, I added this ANTLR's Actionscript runtime to my project - without problems. I compiled lexer/parser specs using ANTLRWorks without problems too. I added the language option to the source *.g file to make ANTLR generate Actionscript sources: options { backtrack = true; memoize = true; k=2; output = AST; language=ActionScript; // Added this ASTLabelType = CommonTree; } Unfortunately, the ANTLR/ANTLRworks generated Actionscript code is buggy: Catch statements read

ANTLR4: implicit or explicit token definition

倖福魔咒の 提交于 2019-12-06 08:04:07
问题 What are the benefits and drawbacks of using explicit token definitions in ANTLR4? I find the text in single parentheses more descriptive and easier to use than creating a separate token and using that in place of the text. E.g.: grammar SimpleTest; top: library | module ; library: 'library' library_name ';' ; library_name: IDENTIFIER; module: MODULE module_name ';' ; module_name: IDENTIFIER; MODULE: 'module' ; IDENTIFIER: [a-zA-Z0-9]+; The generated tokens are: T__0=1 T__1=2 MODULE=3

How to deal with list return values in ANTLR

北城以北 提交于 2019-12-06 02:58:40
问题 What is the correct way to solve this problem in ANTLR: I have a simple grammar rule, say for a list with an arbitrary number of elements. list : '[]' | '[' value (COMMA value)* ']' If I wanted to assign a return value for list, and have that value be the actual list of returned values from the production, what is the proper way to do it? The alternatives I'm entertaining are: create my own stack in the global scope to keep track of these lists Try to inspect the tree nodes below me and

ANTLR generating invalid java exceptions throws code

南笙酒味 提交于 2019-12-05 16:08:49
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 // START: header grammar Cymbol; // my grammar is called Cymbol options { output = AST; ASTLabelType =

ANTLR lexer rule consumes characters even if not matched?

笑着哭i 提交于 2019-12-05 10:16:13
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 rule. But since it shouldn't match anything in [0..1] at all I'm quite puzzled. I'd be happy for any

“FOLLOW_set_in_”… is undefined in generated parser

我们两清 提交于 2019-12-05 04:16:09
I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable. I use AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 apparently does not support C target). The problem is with expression rules. I have rules prio14Expression to prio0Expression which handle operator precedence. To problem is at priority 2, which evaluates prefix and postfix operators: ... prio3Expression: prio2Expression (('*' | '/' | '%') prio2Expression)*; prio2Expression: ('+