Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » AST-Question
AST-Question [message #1858033] Sun, 12 March 2023 11:08 Go to next message
Frank Behr is currently offline Frank BehrFriend
Messages: 5
Registered: March 2023
Junior Member
This grammar

Program:
    (statements+=Statement)*;

Statement:
    AssignmentStatement;
    
AssignmentStatement:
    Variable EqualOperator AdditionExpression; 
    
AdditionExpression:
    Number AdditionOperator Number;

AdditionOperator:
	AddOp="+";

EqualOperator:
	"=";	

Number:
	INT;
	
Variable:
	VAR;
	
terminal VAR:('a'..'z');    


gives me, for

x=1+2

in the outline window of the DSLRuntime Eclipse application, the
tree

ProjectName
    +


How do I extend the grammar so that

ProjectName
    +
      1
      2


is generated? In the end, I would like to have:

ProjectName
    =
      x
      +
       1
       2  

corresponding to

  =
 / \
x   +
   / \
  1   2



I have been experimenting and studying examples for quite some time, but I am not getting any closer.

Thank you very much :-)
Re: AST-Question [message #1858034 is a reply to message #1858033] Sun, 12 March 2023 11:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
please read

https://www.eclipse.org/Xtext/documentation/307_special_languages.html#expressions
https://medium.com/typefox/parsing-expressions-with-xtext-86fb5855d420


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: AST-Question [message #1858035 is a reply to message #1858034] Sun, 12 March 2023 11:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i propose to test with unit test
you can also use EmfFormatter.objToStr to see a representation of the ast


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Invalid plugin configuration: sourceRoots
Next Topic:Perplexing Verilog Operator Grammar: Replication Operator
Goto Forum:
  


Current Time: Fri Apr 19 02:10:30 GMT 2024

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

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

Back to the top