Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Addition returns Expression:
Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*;
Multiplicatio...
Upcoming SlideShare
Loading in …5
×

Parsing Expression With Xtext

7,160 views

Published on

A slide show that shows how expression trees are created with Xtext.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Parsing Expression With Xtext

  1. 1. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition StackAST Grammar Text
  2. 2. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text
  3. 3. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text
  4. 4. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text
  5. 5. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text
  6. 6. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text
  7. 7. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication StackAST Grammar Text
  8. 8. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication 6.PrimaryExpression StackAST Grammar Text
  9. 9. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication 6.PrimaryExpression StackAST Grammar Text
  10. 10. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication 6.PrimaryExpression StackAST Grammar Text 1
  11. 11. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication 6.PrimaryExpression StackAST Grammar Text 1
  12. 12. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication StackAST Grammar Text 1 Reduce!
  13. 13. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 Reduce!
  14. 14. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1
  15. 15. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 +
  16. 16. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 + current = ruleMultiplication(); // {AdditionalExpression.left=current} AdditionalExpression temp = new AdditionalExpression(); temp.setLeft(current); current = temp:
  17. 17. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 +
  18. 18. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 +
  19. 19. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 +
  20. 20. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication StackAST Grammar Text 1 +
  21. 21. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition 5.Multiplication 6.PrimaryExpression StackAST Grammar Text 1 +
  22. 22. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression 4.Addition StackAST Grammar Text 1 + 20 Reduce!
  23. 23. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text 1 + 20 Reduce!
  24. 24. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text 1 + 20
  25. 25. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text 1 + 20
  26. 26. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 Reduce!
  27. 27. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 *
  28. 28. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 *
  29. 29. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 *
  30. 30. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 *
  31. 31. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text 1 + 20 * 2
  32. 32. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication 3.PrimaryExpression StackAST Grammar Text 1 + 20 * EOF 2
  33. 33. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 * EOF Reduce! 2
  34. 34. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition 2.Multiplication StackAST Grammar Text 1 + 20 * EOF 2
  35. 35. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 1.Addition StackAST Grammar Text 1 + 20 * EOF 2 Reduce!
  36. 36. Addition returns Expression: Multiplication ({AdditionalExpression.left=current} '+' right=Multiplication)*; Multiplication returns Expression: PrimaryExpression ({MultiplyExpression.left=current} '*' right=PrimaryExpression)*; PrimaryExpression returns Expression: {NumberLiteral} value=INT | '(' Addition ')'; ( 1 + 20 ) * 2 StackAST Grammar Text 1 + 20 * EOF 2 Finished!

×