Using the AST without eclipse [message #893733] |
Thu, 05 July 2012 07:45  |
Eclipse User |
|
|
|
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 08:53   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03091 seconds