aboutsummaryrefslogtreecommitdiffstats
path: root/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext
blob: 8a510a1960fb2137f650f885887735b9801d2876 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
grammar org.eclipse.viatra.solver.language.SolverLanguage with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate solverLanguage "http://www.eclipse.org/viatra/solver/language/SolverLanguage"

Problem:
	statements+=Statement*;
Statement: Interpretation | Predicate;

@Override terminal STRING returns ecore::EString: '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"';
REALLiteral returns ecore::EBigDecimal: '-'? INT '.' INT;
INTLiteral returns ecore::EInt: '-'? INT;
BooleanValue: {BooleanTrue} 'true' | 'false' {BooleanFalse};
TruthValue: {True} 'true'  | {False} 'false'  | {Unknown} 'unknown' |  {Error} 'error' ;


///////////////////
// Core grammar
///////////////////
Interpretation: BasicInterpretation | DefaultInterpretation | CDInterpretation;

BasicInterpretation: symbol=Symbol ('(' (objects+=ComplexObject (',' objects+=ComplexObject)*)? ')')? ':' value = TruthValue;

Symbol: ModelSymbol | PartialitySymbol | DataSymbol;

ModelSymbol: name = ID;

PartialitySymbol: ExistSymbol | EqualsSymbol;
ExistSymbol:'exists'{ExistSymbol};
EqualsSymbol:'equals' {EqualsSymbol};

DataSymbol: BooleanSymbol | IntegerSymbol | RealSymbol | StringSymbol;
BooleanSymbol:'bool' {BooleanSymbol};
IntegerSymbol:'int' {IntegerSymbol};
RealSymbol: 'real' {RealSymbol};
StringSymbol:'string' {StringSymbol};

ComplexObject: Object | AllInstances | AllObjects;

Object: NamedObject | UnnamedObject | DataObject;
NamedObject: "'" name = ID "'";
UnnamedObject: name = ID;
DataObject: BooleanObject | IntObject | RealObject | StringObject;
BooleanObject: value = BooleanValue;
IntObject: value = INTLiteral;
RealObject: value = REALLiteral;
StringObject: value = STRING;

///////////////////
// Predicte grammar
///////////////////

Predicate:
	(isError?='error')? symbol = ModelSymbol ('(' (parameters += Parameter (',' parameters += Parameter)*)? ')')? ':-' ('false' | (bodies += PatternBody ('|' bodies += PatternBody)*)) '.'
;

Parameter: variable = Variable (':' type = Symbol)?;
PatternBody: {PatternBody} ('true' | constraints += Constraint*) ;
Polarity: {Positive} '+' | {Negative} '-';
Constraint: (polarity = Polarity)?  symbol = ModelSymbol 
	(('(' params += Literal? (',' params += Literal)* ')')?)
	|
	(closureType=ClosureType '(' params += Literal? (',' params += Literal)* ')');
ClosureType: {ReflexiveClosure} '*' | {IrreflexiveClosure} '+';
Literal: Variable | DataObject | NamedObject;
Variable: name = ID;

///////////////////
// Complex Interpretation grammar
///////////////////

AllInstances: ':' symbol = Symbol;
AllObjects: {AllObjects} '*';

///////////////////
// Defaul Interpretation grammar
///////////////////
DefaultInterpretation: 'default' interpretation = BasicInterpretation;

///////////////////
// Advanced Class-Diagram interpretations
///////////////////
CDInterpretation: ClassInterpretation | EnumInterpretation| GlobalRelationInterpretation;
ClassInterpretation:
	(abstract?='abstract')? 'class' symbol = ModelSymbol ('extends' supertypes += ModelSymbol+)?'{'
	fielt += FieldRelationInterpretation*
	'}'
;
EnumInterpretation: 'enum' Symbol = ModelSymbol '{' objects+=NamedObject+ '}';
FieldRelationInterpretation: (containment ?= 'containment')? symbol = ModelSymbol ':' multiplicity = MultiplicityDefinition? target = Symbol;
GlobalRelationInterpretation: (containment ?= 'containment')? 'relation' symbol = ModelSymbol ':' sourceMultiplicity = MultiplicityDefinition? source = Symbol targetMultiplicity = MultiplicityDefinition? target = Symbol;
MultiplicityDefinition: lower = INT '..' (upper = INT | unlimitedUpper?='*');

////SymbolIntroduction : Type | GlobalRelation | Predicate;
////Symbol: Type | Relation | Predicate | Variable | Element;
//
//////////////////////
//// Types
//////////////////////
//
//Type: TypeDeclaration | /*TypeDefinition |*/ TypeEnumeration;
//
//TypeDeclaration:
//	abstract?= 'abstract' 'class' name = ID ('extends' supertypes += [Type] (',' supertypes += [Type])) '{'
//		fieldDeclarations += FieldRelationDeclaration*
//	'}'
//;
//TypeEnumeration:
//	'enum' name = ID 'extends' supertypes += [Type] (',' supertypes += [Type]) '{'
//		(elements += Element)*
//	'}'
//;
//Element:
//	name = ID
//;
//
//////////////////////
//// Relations
//////////////////////
//
//Relation: FieldRelationDeclaration | GlobalRelationDeclaration | RelationEnumeration;
//GlobalRelation returns Relation: GlobalRelationDeclaration | /*RelationDefinition |*/ RelationEnumeration;
//
//FieldRelationDeclaration:
//	containment?='containment' target = [Type] name = ID
//;
//
//GlobalRelationDeclaration:
//	containment?='containment' 'relation' name = ID '(' source = [Type] ',' target = [Type] ')'
//;
//
//RelationEnumeration:
//	'relation' name = ID '{' links += Link* '}'
//;
//
//Link: '(' source = Element ',' target = Element ')';
//
//
//
//
//
//
//Model:
//	'model' '{'
//		atoms += Atom (',' atoms += Atom )
//	'}'
//;
//Atom: referredSymbol = [Symbol] '(' (params += Element (',' params += Element)*)? ')';
//
//ScopeDeclaration:
//	'scope'
//;
//