SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Xtext Grammar Language
Jan Köhnlein
2014, Kiel
grammar org.xtextcon.Statemachine 	
with org.eclipse.xtext.common.Terminals	
!
generate statemachine 	
"http://www.xtextcon.org/Statemachine"	
!
Statemachine:	
name=STRING	
elements+=Element*;	
!
Element:	
	 Event | State;	
	 	
Event:	
	 name=ID description=STRING?;	
!
State:	
	 'state' name=ID	
	 transitions+=Transition*;	
!
Transition:	
	 event=[Event] '=>' state=[State];
Precedences
Action, Assignment, Keyword, 

RuleCall, Parenthesized
Cardinalities *, +, ?

Predicates =>, ->
Group <blank>
Unordered Group &
Alternative |
AssignmentFirst:	
	 name=ID?;	
//	(name=ID)?;	
!
CardinalityFirst:	
	 'a' 'b'?;	
//	'a' ('b'?);	
!
PredicateFirst:	
	 =>'a' 'b';	
//	(=>'a') 'b';	
!
GroupFirst:	
	 'a' | 'b' 'c';	
//	'a' | ('b' 'c');
Syntactic Aspects
grammar org.xtextcon.Statemachine 	
with org.eclipse.xtext.common.Terminals	
!
generate statemachine 	
"http://www.xtextcon.org/Statemachine"	
!
Statemachine:	
name=STRING	
	 ('events' events+=Event+)?	
	 states+=State*;	
!
Event:	
	 name=ID description=STRING?;	
!
State:	
	 'state' name=ID	
	 transitions+=Transition*;	
!
Transition:	
	 event=[Event|ID] '=>' state=[State|ID];
Lexing
Lexer
Splits document text into tokens
Works before and independent of the parser
Token matching
First match wins
Precedence
All keywords
Local terminal rules
Terminal rules from super grammar
As last resort you can define a custom lexer
Lexing
// Examplen	
’Lamp’	
n	
events button_pressed	
n	
state on	
nt	
button_pressed => off	
n	
state off	
nt	
button_pressed => light
SL_COMMENT	
STRING 	
WS	
events WS ID 	
WS	
state ID 	
WS	
ID WS => WS ID 	
WS	
state ID 	
WS	
ID WS => WS ID
events

state

=>

ID

STRING

ML_COMMENT

SL_COMMENT	
WS	
ANY_OTHER
Tokens
Token StreamChar Stream
Terminal Rules
grammar org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT, SL_COMMENT)	
	 	 	 	 	 	 	 	 	 	 	 	
import "http://www.eclipse.org/emf/2002/Ecore" as ecore	
!
terminal ID 		 	 : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;	
terminal INT returns ecore::EInt: ('0'..'9')+;	
terminal STRING	 	 : 	
	 	 	 '"' ( '' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'') | !(''|'"') )* '"' |	
	 	 	 "'" ( '' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'') | !(''|"'") )* "'";	
	
terminal ML_COMMENT	: '/*' -> '*/';	
terminal SL_COMMENT : '//' !('n'|'r')* ('r'? 'n')?;	
!
terminal WS	 	 	 : (' '|'t'|'r'|'n')+;	
!
terminal ANY_OTHER	 : .;
Terminals in the Parser
Hidden Terminals
Are ignored by the parser inside the respective scope
Can be defined on grammar or rule level (inherited)



grammar org.eclipse.xtext.common.Terminals 

hidden(WS, ML_COMMENT, SL_COMMENT)
or on parser rules



QualifiedName hidden(): // strictly no whitespace	
ID ('.' ID)*;
Datatype Rules
Return a value (instead of an EObject)
Are processed by the parser
Superior alternative to terminal rules
Examples



Double returns ecore::EDouble hidden():

'-'? INT '.' INT ('e'|'E' '-'? INT)?;



QualifiedName: // returns ecore::EString (default)

ID ('.' ID)*;



ValidID:

ID | 'keyword0' | 'keyword1';
Transforms textual representation to value and back
For terminal and datatype rules
e.g. strips quotes (STRINGValueConverter)

remove leading ^ (IDValueConverter)
EMF defaults are often sufficient (EFactory)
Value Converter
class MyValueConverterService extends AbstractDeclarativeValueConverterService {	
	 	
	 @Inject MyValueConverter myValueConverter;	
!
	 @ValueConverter(rule = "MY_TERMINAL") def MY_TERMINAL() {	
	 	 return myValueConverter	
	 }	
}
Ambiguities
Example
Expression:	
	 If;	
	 	
If:	
	 Variable | 	
	 'if' condition=Expression 	
	 'then' then=Expression 	
	 ('else' else=Expression)?;	
	 	
Variable:	
	 name=ID;
warning(200): ...: Decision can match input such as "'else'" using multiple alternatives: 1, 2	
As a result, alternative(s) 2 were disabled for that input	
warning(200): ...: Decision can match input such as "'else'" using multiple alternatives: 1, 2	
As a result, alternative(s) 2 were disabled for that input
if cond1 then	
if cond2 then 	
foo	
else // dangling	
bar
Ambiguity Analysis
In the workflow, add
!
AntlrWorks www.antlr3.org/works/
fragment = DebugAntlrGeneratorFragment {	
	 options = auto-inject {}	
}
Ambiguity Resolution
Add keywords
Use syntactic predicates:

“If the predicated element matches in the current
decision, decide for it.”
plain

(=>'else' else=Expression)?; 

=>('else' else=Expression)?; // not so good
first-set

->('else' else=Expression)?;
Correspondence to Ecore
grammar org.xtextcon.Statemachine 	
with org.eclipse.xtext.common.Terminals	
!
generate statemachine 	
"http://www.xtextcon.org/Statemachine"	
!
Statemachine returns Statemachine:	
name=STRING	
	 ('events' events+=Event+)?	
	 states+=State*;	
!
Event returns Event:	
	 name=ID description=STRING?;	
!
State returns State:	
	 'state' name=ID	
	 transitions+=Transition*;	
!
Transition returns Transition:	
	 event=[Event|ID] '=>' state=[State|ID];
statemachine
name : String
Statemachine
name : String
Transition
name : String
State
name : String
description: String
Event
*
* *states events
transitions
event1
1
state
Supertypes
... 	
!
Element:	
	 Event | State;	
!
Event returns Event:	
	 name=ID description=STRING?;	
!
State returns State:	
	 'state' name=ID	
	 transitions+=Transition*;	
!
...
description: String
EventState
name : String
Element
name : String
Transition
Common features are promoted to the super type
Dispatcher rule Element needs not to be called
A rule can return a subtype of the specified return type
Imported EPackage
Workflow {	
bean = StandaloneSetup {	
	...	
	registerGeneratedEPackage =

“org.xtextcon.statemachine.StatemachinePackage”	
	registerGenModelFile = 

“platform:/resource/<path-to>/Statemachine.genmodel"	
}	
//generate statemachine "http://www.xtextcon.org/Statemachine"	
import "http://www.xtextcon.org/Statemachine"
AST Creation
EObject Creation
The current pointer
Points to the EObject returned by a parser rule call
Is set to null when entering the rule
On the first assignment the EObject is created and
assigned to current
Further assignments go to current
EObject Creation
Type :	
(Class | DataType) 'is' visibility=('public' |'private');	
	
DataType :	
'datatype' name=ID;	
	
Class :	
'class' name=ID;
datatype A is public
Type current = null;	
current = new DataType();	
current.setName(“A”);	
current.setVisibility(“public”);	
return current;
Actions
Alternative without assignment -> no returned object





Actions make sure an EObject is created
Specified type must be compatible with return type
Created element is assigned to current
BooleanLiteral:	
	 value?='true' | 'false';
BooleanLiteral returns Expression:	
	 {BooleanLiteral} (value?=‘true’ | ‘false');
The rule 'BooleanLiteral' may be consumed without object instantiation.
Add an action to ensure object creation, e.g. '{BooleanLiteral}'.
Left Recursion
Expression :	
  Expression '+' Expression |	
  Number;	
!
Number :	
value = INT;
The rule 'Expression' is left recursive.
Left Factoring
Expression:	
{Addition} left=Number ('+' right=Number)*;	
	
Number:	
value = INT;
1
// model	
Addition {	
	 left = Number {	
	 	 value = 1	
}	
}
Assigned Action
Addition returns Expression:	
Number ({Sum.left = current} '+' right=Number)*;	
	
Number:	
value = INT;
1
Expression current = null;	
current = new Number();	
current.setValue(1);	
return current;
// model	
Number {	
	 value = 1	
}
Assigned Action II
Addition returns Expression:	
Number ({Sum.left = current} '+' right=Number)*;	
	
Number:	
value = INT;
1 + 2
Expression current = null;	
current = new Number();	
current.setValue(1);	
Expression temp = new Sum();	
temp.setLeft(current);	
current = temp;	
…	
current.right = <second Number>;	
return current;
// model	
Addition {	
	 left = Number {	
	 	 value = 1	
}	
	 right = Number {	
	 	 value = 2	
	 }	
}
Assigned Action III
Creates a new element
makes it the parent of current
and sets current to it
Needed
normalizing left-factored grammars
infix operators
Best Practices
Best Practices
Use nsURIs for imported EPackages
Prefer datatype rules to terminal rules
Use syntactic predicates instead of backtracking
Be sloppy in the grammar but strict in validation

Más contenido relacionado

La actualidad más candente

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Mario Fusco
 

La actualidad más candente (20)

Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Php
PhpPhp
Php
 
Test-Driven Development of Xtext DSLs
Test-Driven Development  of Xtext DSLsTest-Driven Development  of Xtext DSLs
Test-Driven Development of Xtext DSLs
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
C#
C#C#
C#
 
1. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES61. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES6
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 

Destacado

Eclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with XtextEclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with Xtext
Sebastian Zarnekow
 
ARText - Driving Developments with Xtext
ARText - Driving Developments with XtextARText - Driving Developments with Xtext
ARText - Driving Developments with Xtext
Sebastian Benz
 

Destacado (20)

Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With Xtext
 
Using Xcore with Xtext
Using Xcore with XtextUsing Xcore with Xtext
Using Xcore with Xtext
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with Xtend
 
EMF - Beyond The Basics
EMF - Beyond The BasicsEMF - Beyond The Basics
EMF - Beyond The Basics
 
EMF Tips n Tricks
EMF Tips n TricksEMF Tips n Tricks
EMF Tips n Tricks
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java Developers
 
DSLs for Java Developers
DSLs for Java DevelopersDSLs for Java Developers
DSLs for Java Developers
 
Graphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagramGraphical Views For Xtext With FXDiagram
Graphical Views For Xtext With FXDiagram
 
Graphical Views For Xtext
Graphical Views For XtextGraphical Views For Xtext
Graphical Views For Xtext
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Eclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with XtextEclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with Xtext
 
Enhancing Xtext for General Purpose Languages
Enhancing Xtext for General Purpose LanguagesEnhancing Xtext for General Purpose Languages
Enhancing Xtext for General Purpose Languages
 
ARText - Driving Developments with Xtext
ARText - Driving Developments with XtextARText - Driving Developments with Xtext
ARText - Driving Developments with Xtext
 
From Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextFrom Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with Xtext
 
Xtext, diagrams and ux
Xtext, diagrams and uxXtext, diagrams and ux
Xtext, diagrams and ux
 
What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0What's Cooking in Xtext 2.0
What's Cooking in Xtext 2.0
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With Xtext
 
Scoping
ScopingScoping
Scoping
 
Scoping Tips and Tricks
Scoping Tips and TricksScoping Tips and Tricks
Scoping Tips and Tricks
 
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
 

Similar a The Xtext Grammar Language

java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
patforna
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 

Similar a The Xtext Grammar Language (20)

Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
Controle de estado
Controle de estadoControle de estado
Controle de estado
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
 
Json
JsonJson
Json
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Why Our Code Smells
Why Our Code SmellsWhy Our Code Smells
Why Our Code Smells
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Intro to Advanced JavaScript
Intro to Advanced JavaScriptIntro to Advanced JavaScript
Intro to Advanced JavaScript
 

Más de Dr. Jan Köhnlein

A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
Dr. Jan Köhnlein
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
Dr. Jan Köhnlein
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
Dr. Jan Köhnlein
 

Más de Dr. Jan Köhnlein (20)

The Eclipse Layout Kernel sirius con 2017
The Eclipse Layout Kernel   sirius con 2017The Eclipse Layout Kernel   sirius con 2017
The Eclipse Layout Kernel sirius con 2017
 
A New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEsA New Approach Towards Web-based IDEs
A New Approach Towards Web-based IDEs
 
Responsiveness
ResponsivenessResponsiveness
Responsiveness
 
Getting rid of backtracking
Getting rid of backtrackingGetting rid of backtracking
Getting rid of backtracking
 
XRobots
XRobotsXRobots
XRobots
 
Diagrams, Xtext and UX
Diagrams, Xtext and UXDiagrams, Xtext and UX
Diagrams, Xtext and UX
 
Diagram Editors - The FXed Generation
Diagram Editors - The FXed GenerationDiagram Editors - The FXed Generation
Diagram Editors - The FXed Generation
 
Code Generation With Xtend
Code Generation With XtendCode Generation With Xtend
Code Generation With Xtend
 
Eclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered SpeciesEclipse Diagram Editors - An Endangered Species
Eclipse Diagram Editors - An Endangered Species
 
Java DSLs with Xtext
Java DSLs with XtextJava DSLs with Xtext
Java DSLs with Xtext
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
A fresh look at graphical editing
A fresh look at graphical editingA fresh look at graphical editing
A fresh look at graphical editing
 
Android tutorial - Xtext slides
Android tutorial - Xtext slidesAndroid tutorial - Xtext slides
Android tutorial - Xtext slides
 
Eclipse meets e4
Eclipse meets e4Eclipse meets e4
Eclipse meets e4
 
Combining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling ToolsCombining Text and Graphics in Eclipse-based Modeling Tools
Combining Text and Graphics in Eclipse-based Modeling Tools
 
Combining Graphical and Textual
Combining Graphical and TextualCombining Graphical and Textual
Combining Graphical and Textual
 
Domain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse ModelingDomain Specific Languages With Eclipse Modeling
Domain Specific Languages With Eclipse Modeling
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Workshop On Xtext
Workshop On XtextWorkshop On Xtext
Workshop On Xtext
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 

The Xtext Grammar Language

  • 1. Xtext Grammar Language Jan Köhnlein 2014, Kiel
  • 2. grammar org.xtextcon.Statemachine with org.eclipse.xtext.common.Terminals ! generate statemachine "http://www.xtextcon.org/Statemachine" ! Statemachine: name=STRING elements+=Element*; ! Element: Event | State; Event: name=ID description=STRING?; ! State: 'state' name=ID transitions+=Transition*; ! Transition: event=[Event] '=>' state=[State];
  • 3. Precedences Action, Assignment, Keyword, 
 RuleCall, Parenthesized Cardinalities *, +, ?
 Predicates =>, -> Group <blank> Unordered Group & Alternative | AssignmentFirst: name=ID?; // (name=ID)?; ! CardinalityFirst: 'a' 'b'?; // 'a' ('b'?); ! PredicateFirst: =>'a' 'b'; // (=>'a') 'b'; ! GroupFirst: 'a' | 'b' 'c'; // 'a' | ('b' 'c');
  • 5. grammar org.xtextcon.Statemachine with org.eclipse.xtext.common.Terminals ! generate statemachine "http://www.xtextcon.org/Statemachine" ! Statemachine: name=STRING ('events' events+=Event+)? states+=State*; ! Event: name=ID description=STRING?; ! State: 'state' name=ID transitions+=Transition*; ! Transition: event=[Event|ID] '=>' state=[State|ID];
  • 7. Lexer Splits document text into tokens Works before and independent of the parser Token matching First match wins Precedence All keywords Local terminal rules Terminal rules from super grammar As last resort you can define a custom lexer
  • 8. Lexing // Examplen ’Lamp’ n events button_pressed n state on nt button_pressed => off n state off nt button_pressed => light SL_COMMENT STRING WS events WS ID WS state ID WS ID WS => WS ID WS state ID WS ID WS => WS ID events
 state
 =>
 ID
 STRING
 ML_COMMENT
 SL_COMMENT WS ANY_OTHER Tokens Token StreamChar Stream
  • 9. Terminal Rules grammar org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT, SL_COMMENT) import "http://www.eclipse.org/emf/2002/Ecore" as ecore ! terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; terminal INT returns ecore::EInt: ('0'..'9')+; terminal STRING : '"' ( '' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'') | !(''|'"') )* '"' | "'" ( '' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'') | !(''|"'") )* "'"; terminal ML_COMMENT : '/*' -> '*/'; terminal SL_COMMENT : '//' !('n'|'r')* ('r'? 'n')?; ! terminal WS : (' '|'t'|'r'|'n')+; ! terminal ANY_OTHER : .;
  • 11. Hidden Terminals Are ignored by the parser inside the respective scope Can be defined on grammar or rule level (inherited)
 
 grammar org.eclipse.xtext.common.Terminals 
 hidden(WS, ML_COMMENT, SL_COMMENT) or on parser rules
 
 QualifiedName hidden(): // strictly no whitespace ID ('.' ID)*;
  • 12. Datatype Rules Return a value (instead of an EObject) Are processed by the parser Superior alternative to terminal rules Examples
 
 Double returns ecore::EDouble hidden():
 '-'? INT '.' INT ('e'|'E' '-'? INT)?;
 
 QualifiedName: // returns ecore::EString (default)
 ID ('.' ID)*;
 
 ValidID:
 ID | 'keyword0' | 'keyword1';
  • 13. Transforms textual representation to value and back For terminal and datatype rules e.g. strips quotes (STRINGValueConverter)
 remove leading ^ (IDValueConverter) EMF defaults are often sufficient (EFactory) Value Converter class MyValueConverterService extends AbstractDeclarativeValueConverterService { @Inject MyValueConverter myValueConverter; ! @ValueConverter(rule = "MY_TERMINAL") def MY_TERMINAL() { return myValueConverter } }
  • 15. Example Expression: If; If: Variable | 'if' condition=Expression 'then' then=Expression ('else' else=Expression)?; Variable: name=ID; warning(200): ...: Decision can match input such as "'else'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ...: Decision can match input such as "'else'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input if cond1 then if cond2 then foo else // dangling bar
  • 16. Ambiguity Analysis In the workflow, add ! AntlrWorks www.antlr3.org/works/ fragment = DebugAntlrGeneratorFragment { options = auto-inject {} }
  • 17. Ambiguity Resolution Add keywords Use syntactic predicates:
 “If the predicated element matches in the current decision, decide for it.” plain
 (=>'else' else=Expression)?; 
 =>('else' else=Expression)?; // not so good first-set
 ->('else' else=Expression)?;
  • 19. grammar org.xtextcon.Statemachine with org.eclipse.xtext.common.Terminals ! generate statemachine "http://www.xtextcon.org/Statemachine" ! Statemachine returns Statemachine: name=STRING ('events' events+=Event+)? states+=State*; ! Event returns Event: name=ID description=STRING?; ! State returns State: 'state' name=ID transitions+=Transition*; ! Transition returns Transition: event=[Event|ID] '=>' state=[State|ID]; statemachine name : String Statemachine name : String Transition name : String State name : String description: String Event * * *states events transitions event1 1 state
  • 20. Supertypes ... ! Element: Event | State; ! Event returns Event: name=ID description=STRING?; ! State returns State: 'state' name=ID transitions+=Transition*; ! ... description: String EventState name : String Element name : String Transition Common features are promoted to the super type Dispatcher rule Element needs not to be called A rule can return a subtype of the specified return type
  • 21. Imported EPackage Workflow { bean = StandaloneSetup { ... registerGeneratedEPackage =
 “org.xtextcon.statemachine.StatemachinePackage” registerGenModelFile = 
 “platform:/resource/<path-to>/Statemachine.genmodel" } //generate statemachine "http://www.xtextcon.org/Statemachine" import "http://www.xtextcon.org/Statemachine"
  • 23. EObject Creation The current pointer Points to the EObject returned by a parser rule call Is set to null when entering the rule On the first assignment the EObject is created and assigned to current Further assignments go to current
  • 24. EObject Creation Type : (Class | DataType) 'is' visibility=('public' |'private'); DataType : 'datatype' name=ID; Class : 'class' name=ID; datatype A is public Type current = null; current = new DataType(); current.setName(“A”); current.setVisibility(“public”); return current;
  • 25. Actions Alternative without assignment -> no returned object
 
 
 Actions make sure an EObject is created Specified type must be compatible with return type Created element is assigned to current BooleanLiteral: value?='true' | 'false'; BooleanLiteral returns Expression: {BooleanLiteral} (value?=‘true’ | ‘false'); The rule 'BooleanLiteral' may be consumed without object instantiation. Add an action to ensure object creation, e.g. '{BooleanLiteral}'.
  • 27. Left Factoring Expression: {Addition} left=Number ('+' right=Number)*; Number: value = INT; 1 // model Addition { left = Number { value = 1 } }
  • 28. Assigned Action Addition returns Expression: Number ({Sum.left = current} '+' right=Number)*; Number: value = INT; 1 Expression current = null; current = new Number(); current.setValue(1); return current; // model Number { value = 1 }
  • 29. Assigned Action II Addition returns Expression: Number ({Sum.left = current} '+' right=Number)*; Number: value = INT; 1 + 2 Expression current = null; current = new Number(); current.setValue(1); Expression temp = new Sum(); temp.setLeft(current); current = temp; … current.right = <second Number>; return current; // model Addition { left = Number { value = 1 } right = Number { value = 2 } }
  • 30. Assigned Action III Creates a new element makes it the parent of current and sets current to it Needed normalizing left-factored grammars infix operators
  • 32. Best Practices Use nsURIs for imported EPackages Prefer datatype rules to terminal rules Use syntactic predicates instead of backtracking Be sloppy in the grammar but strict in validation