Skip to content

Instantly share code, notes, and snippets.

@gdeest
Created June 27, 2012 13:03
Show Gist options
  • Select an option

  • Save gdeest/3003950 to your computer and use it in GitHub Desktop.

Select an option

Save gdeest/3003950 to your computer and use it in GitHub Desktop.
grammar fr.irisa.cairn.interproc.simple.Simple with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
//import "http://gecosinterproc" as interproc
import "platform:/plugin/fr.irisa.cairn.interproc.simple/src/fr/irisa/cairn/interproc/gecos/extensions/gecosexts.ecore" as interproc
import "platform:/plugin/fr.irisa.cairn.gecos.model/model/gecos.cdfg.ecore#//core" as core
import "platform:/plugin/fr.irisa.cairn.gecos.model/model/gecos.cdfg.ecore#//instrs" as instrs
import "platform:/plugin/fr.irisa.cairn.gecos.model/model/gecos.cdfg.ecore#//types" as types
import "platform:/plugin/fr.irisa.cairn.gecos.model/model/gecos.cdfg.ecore#//blocks" as blocks
import "platform:/plugin/fr.irisa.cairn.gecos.model/model/gecos.cdfg.ecore#//annotations" as annot
//generate simple "http://www.Simple"
Program returns interproc::Program:
('typedef' typedefs+=Typedef+)?
(procedures+=Procedure)*
('var' (vars+=Symbol (',' vars+=Symbol)*)? ';')?
'begin'
body=Block
'end'
;
ProcedureSymbol returns core::ProcedureSymbol:
name=ID
;
ParameterSymbol returns core::ParameterSymbol:
name=ID ':' type=[types::Type]
;
Symbol returns core::Symbol:
name=ID ':' type=[types::Type]
;
Typedef returns types::EnumType:
name=ID '=' 'enum' '{' enumerators+=Enumerator (',' enumerators+=Enumerator)* '}' ';'
;
Enumerator returns types::Enumerator: name=enumID;
Procedure returns interproc::InterprocProcedure:
'proc' procSymbol=ProcedureSymbol '(' (inputVars+=ParameterSymbol (',' inputVars+=ParameterSymbol)*)? ')' 'returns' '(' (outputVars+=Symbol (',' outputVars+=Symbol)*)? ')'
('var' (vars+=Symbol (',' vars+=Symbol)*)? ';')?
'begin'
body=Block
'end'
;
Block returns blocks::CompositeBlock:
(annotations+=AnnotationMap)?
children+=Statement+
;
Statement returns blocks::Block:
(BasicBlock | IfStatement | WhileStatement) ';' annotations+=AnnotationMap?
;
BasicBlock returns blocks::BasicBlock:
instructions+=SkipStatement |
instructions+=HaltStatement |
instructions+=FailStatement |
instructions+=AssumeStatement |
instructions+=AssignmentStatement
;
SkipStatement returns instrs::GenericInstruction: name='skip';
HaltStatement returns instrs::GenericInstruction: name='halt';
FailStatement returns instrs::GenericInstruction: name='fail';
AssumeStatement returns instrs::GenericInstruction: name ='assume' children+=BooleanExpression;
AssignmentStatement returns instrs::SetInstruction: dest=AssignmentDest '=' source=AssignmentSource;
SymbolInstruction returns instrs::SymbolInstruction:
symbol=[core::Symbol|ID]
;
AssignmentDest returns instrs::Instruction:
SymbolInstruction |
{instrs::GenericInstruction} '(' (children+=SymbolInstruction (',' children+=SymbolInstruction)*)? ')'
;
AssignmentSource returns instrs::Instruction:
RandomExpr | CallInstruction | => BooleanExpression | NumericalExpression | EnumeratorInstruction
;
EnumeratorInstruction returns instrs::EnumeratorInstruction:
enumerator=[types::Enumerator|enumID]
;
CallInstruction returns instrs::CallInstruction:
children+=SymbolInstruction '(' (children+=SymbolInstruction (',' children+=SymbolInstruction)*)? ')'
;
RandomExpr returns instrs::GenericInstruction: name='random';
CondBlock returns blocks::BasicBlock:
instructions+=CondInstruction
;
CondInstruction returns instrs::CondInstruction:
cond=BooleanExpression
;
IfStatement returns blocks::IfBlock:
{blocks::IfBlock}
'if' condBlock=CondBlock 'then'
thenBlock=Block
('else'
elseBlock=Block
)?
'endif'
;
WhileStatement returns blocks::WhileBlock:
{blocks::WhileBlock}
'while' condition=CondBlock 'do'
body=Block
'done'
;
BooleanExpression returns instrs::Instruction:
OrExpression
;
OrExpression returns instrs::Instruction:
AndExpression ({instrs::GenericInstruction.children+=current} name='or' children+=AndExpression)*
;
AndExpression returns instrs::Instruction:
HighestBoolPrio ({instrs::GenericInstruction.children+=current} name='and' children+=HighestBoolPrio)*
;
HighestBoolPrio returns instrs::Instruction:
{instrs::GenericInstruction} name='not' children+=HighestBoolPrio | '(' BooleanExpression ')' | => BooleanAtom
;
BooleanAtom returns instrs::Instruction:
{interproc::BooleanInstruction} value=BooleanConstant | SymbolInstruction | RandomExpr | EnumeratorComparison | NumericalRelation
;
NumericalRelation returns instrs::GenericInstruction:
children+=NumericalExpression name=('<' | '<=' | '==' | '>=' | '>') children+=NumericalExpression
;
EnumeratorComparison returns instrs::GenericInstruction:
children+=SymbolInstruction name='==' children+=EnumeratorInstruction
;
NumericalExpression returns instrs::Instruction: AdditiveExpression;
AdditiveExpression returns instrs::Instruction:
MultiplicativeExpression ({instrs::GenericInstruction.children+=current} name=AdditiveOperator children+=MultiplicativeExpression)*
;
MultiplicativeExpression returns instrs::Instruction:
UnaryMinusExpression ({instrs::GenericInstruction.children+=current} name=MultiplicativeOperator children+=UnaryMinusExpression)*
;
UnaryMinusExpression returns instrs::Instruction:
{instrs::GenericInstruction} name=UnaryOperator children+=HighestPrioNum | HighestPrioNum
;
HighestPrioNum returns instrs::Instruction:
'(' NumericalExpression ')' | NumericalAtom
;
NumericalAtom returns instrs::Instruction:
SymbolInstruction |
{instrs::IntInstruction} value=LONG |
{instrs::FloatInstruction} value=REAL
;
/**** ANNOTATIONS ****/
AnnotationMap returns annot::StringToIAnnotationMap:
'/*' key=AnnotationKey value=Annotation '*/'
;
Annotation returns annot::ExtendedAnnotation:
{annot::ExtendedAnnotation} 'bottom' |
'{' fields+=AnnotAlt ('or' fields+=AnnotAlt)* '}'
;
/*Annotation returns annot::StringAnnotation:
{annot::StringAnnotation} content=('bottom' | )
;*/
//terminal ComplexAnnot: '{' -> '}';
AnnotAlt returns instrs::GenericInstruction:
'(' children+=AnnotBool ')' 'and' children+=DomainApproximation
;
AnnotBool returns instrs::GenericInstruction:
children+=AnnotBoolAtom ('and' children+=AnnotBoolAtom)*
;
AnnotBoolAtom returns instrs::Instruction:
{interproc::BooleanInstruction} value=BooleanConstant |
SymbolInstruction |
{instrs::GenericInstruction} name='not' children+=SymbolInstruction |
{instrs::GenericInstruction} children+=SymbolInstruction name='=' children+=EnumeratorInstruction
;
DomainApproximation returns instrs::GenericInstruction:
name='top' | {instrs::GenericInstruction} Constraints;
terminal Constraints: '[|' -> '|]';
///////////////////////
terminal AdditiveOperator returns ecore::EString: ('+'|'-')('_'('i'|'f'|'d'|'l'|'q')(','('?'|'n'|'0'|'+oo'|'-oo'))?)?;
terminal MultiplicativeOperator returns ecore::EString: ('*'|'/'|'%')('_'('i'|'f'|'d'|'l'|'q')(','('?'|'n'|'0'|'+oo'|'-oo'))?)?;
terminal UnaryOperator returns ecore::EString: ('-'|'cast'|'sqrt')('_'('i'|'f'|'d'|'l'|'q')(','('?'|'n'|'0'|'+oo'|'-oo'))?)?;
//terminal NumericalRelationalOperator returns ecore::EString: '<' | '<=' | '==' | '>=' | '>';
terminal AnnotationKey: 'L'('0'..'9')+'C'('0'..'9')+;
//terminal AnnotationContent: ('{' -> '}' | 'bottom');
//terminal AnnotationContent: '/*' -> '*/';
terminal BooleanConstant returns ecore::EBoolean: 'true' | 'false';
terminal REAL returns ecore::EDouble: ('0'..'9')+ '.' ('0'..'9')+;
terminal LONG returns ecore::ELong: ('0'..'9')+;
terminal INT returns ecore::EInt: '### So that Xtext does not lament about token "LONG" hiding token "INT".';
terminal ML_COMMENT: '### Overriding this ###';
terminal ID : '^'?('a'..'z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal enumID : '^'?('A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment