antlr

What are features of ANTLR that XText Does not provide?

Deadly 提交于 2019-12-01 02:20:53
I just came across very nice tool Xtext to create DSL as well as IDE for editing. I did some search on the web and found people saying it does not provide all the features of ANTLR. I am using ANTLR as my parser generator. I am not even sure what features of ANTLR I will need to write complete parser for my language but ANTLR is around for quite a long time and probably supports more features than Xtext. Can anyone please give some examples of what CANNOT be specified in a Xtext grammar? You cannot specify semantic predicates in an Xtext grammar. Furthermore it's not possible to include

Help with left factoring a grammar to remove left recursion

倖福魔咒の 提交于 2019-12-01 01:57:23
问题 I have a small custom scripting language, and I am trying to update it to allow boolean expressions such as a > 2 and a > 2 and (b < 3 or c > 5) . It's the parenthetical expressions that I am having trouble with here. Here is a (edited since the original post based on the answer from @Bart Kiers) full grammar that exhibits the problem. This is a pared-down version of my actual grammar, but the problem occurs here too. grammar test; options { language = 'JavaScript'; output = AST; } statement

ANTLR4 parse tree simplification

二次信任 提交于 2019-12-01 01:18:14
Is there any means to get ANTLR4 to automatically remove redundant nodes in generated parse trees? More specifically, I've been experimenting with a grammar for GLSL and you end up with long linear sequences of "expressions" in the parse tree due to the rule forwarding needed to give the automatic handling of operator precedence. Most of the generated tree nodes are simply "forward to the next level of precedence", so don't provide any useful syntactic information - you only really need the last expression node in each sequence (i.e. the point at which the rule forwarding stopped), or the

Antlr left recursive problem

情到浓时终转凉″ 提交于 2019-12-01 00:46:48
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? -> ^(FUNCTION ID ^(ATTRIBUTES attribute*) ^(CHILDREN function*)) ; attribute : ID (COLON | EQUALS)

Are there tools to convert between ANTLR and other forms of BNF?

可紊 提交于 2019-12-01 00:34:59
问题 Are there any tools to convert ANTLR grammar syntax to and from other BNF syntaxes? There are several forms Backus-Naur Form (BNF, EBNF, ABNF, W3C-BNF, XBNF...) with specification, e.g. see this list. The ANTLR grammar syntax only seems to be described by examples. I know that ANTLR grammar files contain more than the specification of a context-free syntax, but you should be able to convert at least the common subset - has anyone done yet automatically? 回答1: Jakob wrote: The ANTLR grammar

ANTLRv4: non-greedy rules

半世苍凉 提交于 2019-11-30 23:43:11
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 possible. Instead of this, a \" is mapped to ESC . I have an understanding problem, since it is not what I

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

Is there a list of reserved words in ANTLR grammars?

自闭症网瘾萝莉.ら 提交于 2019-11-30 21:57:01
I recently created an ANTLR3 parser rule options : foo bar; which didn't compile and it took me some time to discover that options was a reserved word (AntlrWorks indicated an error but not why). Is there a list of reserved words in ANTLR and are there best practices in naming rules (which might help avoid this)? Bart Kiers The reserved words of ANTLR v3 are: Keyword | Description ---------+-------------------------------------------------------- scope | Dynamically-scoped attribute fragment | lexer rule is a helper rule, not real token for parser lexer | grammar type tree | grammar type

What are features of ANTLR that XText Does not provide?

别等时光非礼了梦想. 提交于 2019-11-30 21:57:00
问题 I just came across very nice tool Xtext to create DSL as well as IDE for editing. I did some search on the web and found people saying it does not provide all the features of ANTLR. I am using ANTLR as my parser generator. I am not even sure what features of ANTLR I will need to write complete parser for my language but ANTLR is around for quite a long time and probably supports more features than Xtext. Can anyone please give some examples of what CANNOT be specified in a Xtext grammar? 回答1:

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