Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using the AST without eclipse
Using the AST without eclipse [message #893733] Thu, 05 July 2012 11:45 Go to next message
Alexander Savinov is currently offline Alexander SavinovFriend
Messages: 4
Registered: March 2012
Junior Member
Hi,

I have a defined Grammar and am using Xtext standalone to parse some text.

After parsing i would like to interpret the text that has been parsed.
If im getting it right Xtext creates an AST for parsing, so i would like to use the AST for some tests.

If read the user guide but could not find anything about using\getting the AST for manual work.

Or would be Xtend enough for this?

my grammar defines rules with sets like {(1,1), (1,2)} subsetof {(1,1)} OR {(2,2)} subsetof {(2,3)}
the (1,1) indicates an element of another tree which is created with java by another Tool. So what i need is to get the elements of my tree (no problem) and use the AST to check whether the rule is true or not.

Would Xtend work if i feed it with information from somewhere else?

best regards
Re: Using the AST without eclipse [message #893749 is a reply to message #893733] Thu, 05 July 2012 12:53 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
It's usually these step to load an Xtext file in standalone mode
1) call <yourlanguge>StandaloneSetup.doSetup() to create the injector
and register the language to the EMF registries
2) create an XtextResourceSet
3) load the file as a resource into the resource set
4) access the resource's contents. This will be the AST

You need the language runtime project as a jar on the classpath.

Building an interpreter usually boils down to implementing a visitor
that traverses the AST and executes it on its way. For an example, look
at the Simple Arithmetics language (new > example > xtext > simple
arithmetics example). Xtend is well suited for this task as it offers
dispatch methods and a powerful switch expression, such removing the
need for instanceof cascades.


Am 05.07.12 13:45, schrieb Alexander Savinov:
> Hi,
>
> I have a defined Grammar and am using Xtext standalone to parse some text.
>
> After parsing i would like to interpret the text that has been parsed.
> If im getting it right Xtext creates an AST for parsing, so i would like
> to use the AST for some tests.
>
> If read the user guide but could not find anything about using\getting
> the AST for manual work.
>
> Or would be Xtend enough for this?
>
> my grammar defines rules with sets like {(1,1), (1,2)} subsetof {(1,1)}
> OR {(2,2)} subsetof {(2,3)}
> the (1,1) indicates an element of another tree which is created with
> java by another Tool. So what i need is to get the elements of my tree
> (no problem) and use the AST to check whether the rule is true or not.
>
> Would Xtend work if i feed it with information from somewhere else?
>
> best regards


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Using the AST without eclipse [message #893770 is a reply to message #893749] Thu, 05 July 2012 13:35 Go to previous message
Alexander Savinov is currently offline Alexander SavinovFriend
Messages: 4
Registered: March 2012
Junior Member
thanks for the fast reply, will try it Smile
Previous Topic:Recursion without recursion?
Next Topic:Backward compatibilty of xtext versions in the future expectable?
Goto Forum:
  


Current Time: Fri Apr 26 19:38:27 GMT 2024

Powered by FUDForum. Page generated in 0.03250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top