aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.language/src/ca/mcgill/ecse/dslreasoner/VampireLanguage.xtext
blob: cd64055645421e57e459cf5972e1d75f1c9bcbfb (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
grammar ca.mcgill.ecse.dslreasoner.VampireLanguage with org.eclipse.xtext.common.Terminals hidden (WS)

generate vampireLanguage "http://www.mcgill.ca/ecse/dslreasoner/VampireLanguage"

//@@@@@@@@@@@
//2 things TODO:
//1. fix anotations (ln77)
//2. can only use declared variables in formula (ln 158)

//@@@@@@@@@@@

VampireModel:	
	(
//		includes += VLSInclude |
		comments += VLSComment | 
		confirmations += VLSConfirmations|
		formulas += VLSFofFormula |
		tfformulas += VLSTffFormula
		
	)*	
;

//////////////////////////////////
// VLS terminals
//////////////////////////////////

terminal ALPHA_NUMERIC:	( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_'); 
terminal UPPER_WORD_ID: ('A'..'Z') (ALPHA_NUMERIC)*;
terminal LOWER_WORD_ID: ('a'..'z') (ALPHA_NUMERIC)*;


//TODO MIGHT NEED TO IMPLEMENT SOME WAY TO ONLY CONSIDER WHAT IS INSIDE QUOTES AS NAME
//incorporate quotes in the line of calling. ex. "'" name=SINGLEQUOTE "'"
terminal DOUBLE_QUOTE: '"' ( '\\' ('"'|'\\') | !('\\'|'"') )* '"';//from terminal STRING rule, positive about this
terminal SINGLE_QUOTE: "'" ( '\\' ("'"|'\\') | !('\\'|"'") )+ "'";//from terminal STRING rule, positive about this

terminal SIGN: ('+' | '-');

terminal DOLLAR_ID: ('$') (LOWER_WORD_ID);
terminal DOUBLE_DOLLAR_ID: ('$$') (LOWER_WORD_ID);

terminal LITERAL: '0' | ('1'..'9') (INT)?;
terminal SIGNED_LITERAL: (SIGN)* (LITERAL);

//terminal UNSIGNED_REAL_FRAC_ID: (LITERAL) ('.') (INT);
//terminal UNSIGNED_REAL_EXP_ID: (LITERAL | UNSIGNED_REAL_FRAC_ID) ('Ee') (SIGN)* (INT) ;
//terminal SIGNED_REAL_ID: (SIGN)* (UNSIGNED_REAL_FRAC_ID | UNSIGNED_REAL_EXP_ID);
//
//terminal UNSIGNED_RAT_ID:  (LITERAL) ('/') ('1'..'9') (INT)? ;
//terminal SIGNED_RAT_ID: (SIGN)* (UNSIGNED_RAT_ID);

//Overwriting is necessary
//terminal ID: (!('\n'|'\r'))* ('\r'? '\n')?;
//terminal ANY_OTHER: ;
terminal SINGLE_COMMENT: '%' (!('\n'|'\r'))* ('\r'? '\n')?;
//terminal ID:  ( !('('|')'|'\r'|'\n') )+ ;


//////////////////////////////////
// VLS types
//////////////////////////////////

// <includes>
//VLSInclude:
//	'include(' fileName = SINGLE_QUOTE ( ',[' names += VLSName (','  names += VLSName)* ']' )?
//;

//VLSName:
//	name = (LOWER_WORD_ID | SINGLE_QUOTE | LITERAL | SIGNED_LITERAL)
//;

// <comments>
VLSComment:
	comment = SINGLE_COMMENT
	//need to add a new line at the end of the file for the case where the last line is a comment
;

//VLSConstantDeclaration: name = (LOWER_WORD_ID | SINGLE_QUOTE | DOLLAR_ID | DOUBLE_DOLLAR_ID );

VLSConfirmations:
	  {VLSSatisfiable} 'Satisfiable!' | 
	  {VLSWarning} "WARNING!" "Could" "not" "set" "resource" "limit:" "Virtual" "memory." |
	  {VLSTrying} 'TRYING' '[' name = LITERAL ']' |
	  {VLSFiniteModel} 'Finite' 'Model' 'Found!'
;

// <FOF formulas>
VLSFofFormula:
	'fof' '(' name = (LOWER_WORD_ID | SIGNED_LITERAL | SINGLE_QUOTE) ',' fofRole = VLSRole ',' fofFormula = VLSTerm (',' annotations = VLSAnnotation)? ')' '.'
;


VLSTffFormula:
	'tff' '(' name = VLSTffName ',' tffRole = VLSRole ',' fofFormula = VLSTffTerm (',' annotations = VLSAnnotation)? ')' '.'
;

VLSTffName:
	VLSTffDeclPred | VLSTffFinite | VLSTffDistinct
;

VLSTffDistinct:
	'distinct_domain'
;

VLSTffFinite:
	'finite_domain'
;

VLSTffDeclPred:
	'declare_' DOLLAR_ID | LOWER_WORD_ID
;


/*
//NAME
VLSName:
	//(atomic_Word = Atomic_Word | integer = Integer | single_quote_word = Single_Quote_Word)
	name = (LOWER_WORD_ID | SIGNED_INT_ID | SINGLE_QUOTE)
;
*/
//<ROLE>
VLSRole:
	"axiom" | "conjecture" | "hypothesis" | "definition" | "assumption" | "lemma"
	| "theorem" |	"corollary" | "negated_conjecture" | "plain" | "type" |
	"fi_domain" | "fi_functors" | "fi_predicates" | "unknown"
;

/*
//VLSRole:
//	VLSAxiom | VLSConjecture | VLSHypothesis | VLSDefinition |
//	VLSAssumption | VLSLemma | VLSTheorem | VLSCorollary | VLSNegated_Conjecture |
//	VLSPlain | VLSType |VLSFi_Domain | VLSFi_Functors | VLSFi_Predicates | VLSUnknown
//;
//
//VLSAxiom:
//	"axiom"
//;
//
//VLSConjecture:
//	"conjecture"
//;
//
//VLSHypothesis:
//	"hypothesis"
//;
//	
//VLSDefinition:
//	"definition"
//;
//
//VLSAssumption:
//	"assumption"
//;
//		
//VLSLemma:
//	"lemma"
//;
//			
//VLSTheorem:
//	"theorem"
//;
//				
//VLSCorollary:
//	"corollary"
//;
//			
//VLSNegated_Conjecture:
//	"negated_conjecture"	
//;
//
//VLSPlain:
//	"plain"
//;
//
//VLSType:
//	"type"
//;
//
//VLSFi_Domain:
//	"fi_domain"
//;
//
//VLSFi_Functors:
//	"fi_functors"
//;
//
//VLSFi_Predicates:
//	"fi_predicates"
//;
//
//VLSUnknown:
//	"unknown"
//;
*/

// <ANNOTATION>
// Not at all based on the website. based on what we think the output will be like 
VLSAnnotation:
	('[')? (name = (LOWER_WORD_ID  | SINGLE_QUOTE | VLSRole))? ( '('  followup = VLSAnnotationTerms ')' )? (']')?
;

VLSAnnotationTerms returns VLSAnnotation:
	terms += VLSAnnotation (',' terms += VLSAnnotation )*
;

//////////////////////////////////
// VLS Terms
//////////////////////////////////
VLSTffTerm:
	VLSTerm |
	VLSDeclaration
;

/////////////////
//TFF Specific
VLSDeclaration:
	VLSVariableDeclaration |
	VLSOtherDeclaration
	
;

VLSOtherDeclaration:
	name = VLSAtomicConstant ':' type = VLSTypeDef
;

VLSVariableDeclaration:
	name = VLSVariable ':' type = VLSTypeDef
;

VLSTypeDef:
	typeSig = VLSUnitaryTerm ('>' mapsTo = VLSAtomicConstant)? //might need to make VLSAtomic to include VLSVariable
;

VLSUnitaryTerm returns VLSTypeDef:
	initType = VLSAtomic ('*' nextType = VLSAtomicConstant)* //might need to make VLSAtomic to include VLSVariable
;
//TFF Specific
/////////////////

VLSTerm: 
	//( VLSLogic | VLSSequent)
	VLSBinary
;
//*
//VLSBinaryFormula
VLSBinary returns VLSTerm:
	VLSUnitaryFormula
	(
		(({VLSEquivalent.left = current} "<=>" |
			{VLSImplies.left = current} "=>" |
			{VLSRevImplies.left = current} "<=" |
			{VLSXnor.left = current} "<~>" |
			{VLSNor.left = current} "~|" |
			{VLSNand.left = current} "~&")	right = VLSUnitaryFormula) 
		| 
		({VLSAnd.left = current} '&' right = VLSUnitaryFormula)+
		|
		({VLSOr.left = current} '|' right = VLSUnitaryFormula)+
	)?
;

//VLSUnitaryFormula
VLSUnitaryFormula returns VLSTerm:
	VLSUniversalQuantifier  | VLSExistentialQuantifier | VLSUnaryNegation | VLSUnaryInfix 
	//| VLSEquality 
	|  '(' VLSTerm ')'
;

VLSUniversalQuantifier  returns VLSTerm:
	{VLSUniversalQuantifier} (("!") '[' variables += (VLSVariable | VLSVariableDeclaration) 
		(','  variables += (VLSVariable | VLSVariableDeclaration))* ']' ':'
	) operand = VLSUnitaryFormula
;

VLSExistentialQuantifier  returns VLSTerm:
	{VLSExistentialQuantifier} (("?") '[' variables += (VLSVariable | VLSVariableDeclaration) 
		(','  variables += (VLSVariable | VLSVariableDeclaration))* ']' ':'
	) operand = VLSUnitaryFormula
;

VLSUnaryNegation   returns VLSTerm:
	{VLSUnaryNegation} ('~') operand = VLSUnitaryFormula
;

VLSUnaryInfix returns VLSTerm:
	VLSAtomic (({VLSInequality.left = current} "!=" |
		{VLSEquality.left = current} "=" |	
		{VLSAssignment.left = current} ":=")
		right = VLSAtomic)? 
;

//NOT SUREEEE
//VLSEquality returns VLSTerm:
//	VLSFofTerm ({VLSEquality.left = current} "=" right = VLSFofTerm)?
//	
//;

/*
enum VLSDefinedFunctor:
		UMINUS='$uminus' | SUM='$sum' | DIFFERENCE='$difference' | PRODUCT='$product' | QUOTIENT='$quotient' | 
		QUOTIENT_E='$quotient_e' | QUOTIENT_T='$quotient_t' | QUOTIENT_F='$quotient_f' | REMAINDER_E='$remainder_e' |
		 REMAINDER_T='$remainder_t' | REMAINDER_F='$remainder_f' | FLOOR='$floor' | CEILING='$ceiling' |
		 TRUNCATE='$truncate' | ROUND='$round' | TO_INT='$to_int' | TO_RAT='$to_rat' | TO_REAL='$to_real'
    ;
*/

VLSAtomic returns VLSTerm:
	VLSAtomicConstant | VLSAtomicFunction | VLSVariable 
	| VLSDefinedTerm //temporary solution. this is only valid for equality, not for != or :=
	//| VLSEquality
;

VLSAtomicConstant returns VLSTerm:
	//{VLSConstant} name = VLSConstantDeclaration |
	{VLSConstant} name = (LOWER_WORD_ID | SINGLE_QUOTE | DOLLAR_ID | DOUBLE_DOLLAR_ID | VLSRole) |
	{VLSTrue} '$true' |
	{VLSFalse} '$false'
;

VLSAtomicFunction returns VLSTerm:
	//? on next line causes warning
	//TODO might need replace DOLLAR_ID with enum rule 
	//{VLSFunction} name = VLSConstantDeclaration ( '(' terms += VLSFofTerm (',' terms += VLSFofTerm)* ')' ) |
	{VLSFunction} constant = (LOWER_WORD_ID | SINGLE_QUOTE | DOLLAR_ID | DOUBLE_DOLLAR_ID | VLSRole ) ( '(' terms += VLSFofTerm (',' terms += VLSFofTerm)* ')') |
	{VLSLess} name = '$less' '(' terms += VLSFofTerm ',' terms += VLSFofTerm ')' 
;

VLSVariable :
	
	name = UPPER_WORD_ID
;

VLSFofTerm returns VLSTerm:
	//(VLSVariable | VLSFunction | VLSTffConditional | VLSTffLet | VLSTffTuple)
	(VLSVariable | VLSFunctionAsTerm | VLSDefinedTerm )
;

VLSFunctionAsTerm:
	//? on next line causes warning
	//TODO might need replace DOLLAR_ID with enum rule 
	functor = (LOWER_WORD_ID | SINGLE_QUOTE | DOLLAR_ID | DOUBLE_DOLLAR_ID ) ( '(' terms += VLSFofTerm (',' terms += VLSFofTerm)* ')')?
;

VLSDefinedTerm:
	{VLSInt} value = SIGNED_LITERAL |
//	{VLSReal} value = SIGNED_REAL_ID |
//	{VLSRational} value = SIGNED_RAT_ID |
	{VLSDoubleQuote} value = DOUBLE_QUOTE
;