What are features of ANTLR that XText Does not provide?
Asked Answered
B

1

20

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?

Biomass answered 5/5, 2011 at 22:1 Comment(0)
A
23

You cannot specify semantic predicates in an Xtext grammar. Furthermore it's not possible to include arbitrary actions (read: target language code blocks) with Xtext. The only supported target platform is Java.

The good news is, that Xtext gains great benefit by inducing these constraints, e.g. you'll get an unparser that allows to serialize arbitrary models / syntax graphs that match your grammar. Speaking about syntax graphs, with Xtext you'll get a typed AST for your language that you can edit in your IDE.

A grammar feature that is unique in Xtext's representation are unordered groups. That is, you can directly express that certain elements in your grammar may occur in arbitrary order but each one only once. If you think about the java modifiers, this may be very handy:

  visibility=('public'|'private') // this is a mandatory assignment
& abstractOrFinal=('abstract'|'final')? // this is optional
& static?='static'? // this will become a boolean value in your ast

Have a look at the Xtext docs for more details on the grammar language.

Acrylonitrile answered 5/5, 2011 at 22:15 Comment(2)
The important point is, Xtext uses internally ANTLR and afaik, you surely know better, Xtext will sooner or later support more of the ANTLR features like operator precedence etc, right?:)Deaf
Xtext has the concept of Actions (not to be confused with Antlr's black box target language literals) to implement operator precedence. It works very well for us especially in an interactive environment where error recovery matters a lot. I doubt that we'll migrate the Antlr new scheme for the implementation of precendencies.Acrylonitrile

© 2022 - 2024 — McMap. All rights reserved.