summaryrefslogtreecommitdiff
path: root/ipl/packs/euler/euler.grm
blob: 80f5b25ef35d09cf3248737d215cd53875f54f83 (plain)
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
start : program .
program = block ENDPROG!.
vardecl = new id NEWDECL! .
fordecl = formal id FORMALDECL! .
labdecl = label id LABELDECL! .
var = id VARID! {  "[" expr "]" SUBSCR! |  "." DOT! } .
logval = true LOGVALTRUE! .
logval = false LOGVALFALSE! .
number = realN | integerN.
reference = "@" var REFERENCE! .
#	listhead -> "(" LISTHD1!
#	listhead -> listhead expr "," LISTHD2!
#	listN -> listhead ")" LISTN1!
#	listN -> listhead expr ")" LISTN2!
listN = "(" LISTHD1! ( ")" LISTN1! | expr listTl ) .
listTl = ")" LISTN2! | "," LISTHD2! ( expr listTl | ")" LISTN1! ) .
prochead = "'" PROCHD! {  fordecl ";" PROCFORDECL! } .
procdef = prochead expr "'" PROCDEF! .
primary = var ( listN CALL! | VALUE!) | primary1 .
primary1 = logval LOADLOGVAL! | number LOADNUM! |
	symbol LOADSYMB!| reference |
	listN | tail primary UOP! | procdef |
	undef LOADUNDEF! | "[" expr "]" PARENS! | in INPUT! |
	isb var UOP! | isn var UOP! | isr var UOP! |
	isl var UOP! | isli var UOP! | isy var UOP! |
	isp var UOP! | isu var UOP! | abs primary UOP! |
	length var UOP! | integer primary UOP! |
	real primary UOP! | logical primary UOP! | list primary UOP! .
factor = primary factortail.
factortail = { "**" primary BOP! } .
term = factor termtail.
termtail = { "*" factor BOP! | "/" factor BOP! |
		div factor BOP! | mod factor BOP! } .
sum = ("+" term UPLUS! | "-" term NEG! | term) sumtail.
sumtail = { "+" term BOP! | "-" term BOP! } .
choice = sum choicetail.
choicetail = { min sum BOP! | max sum BOP! } .

relation = choice relationtail.
relationtail = [ "=" choice BOP! | "~=" choice BOP!
	| "<" choice BOP! | "<=" choice BOP!
	| ">" choice BOP! | ">=" choice BOP! ] .

negation =  "~" relation UOP! | relation .
conj = negation conjtail.
conjtail = [ and CONJHD! conj CONJ! ].
disj = conj disjtail.
disjtail = [ or DISJHD! disj DISJ! ] .
catenatail = { "&" primary BOP! }.

truepart = expr else TRUEPT! .
ifclause = if expr then IFCLSE! .

expr = var exprtail | expr1.
exprtail = "<-" expr BOP! |
	( listN CALL! | VALUE!)
	factortail
	termtail
	sumtail
	choicetail
	relationtail
	conjtail
	disjtail
	catenatail .

expr1 = block .
expr1 = ifclause truepart expr IFEXPR! .
expr1 = goto primary UOP! .
expr1 = out expr UOP! .
expr1 =	primary1
	factortail
	termtail
	sumtail
	choicetail
	relationtail
	conjtail
	disjtail
	catenatail .

expr1 =  ( "+" term UPLUS! | "-" term NEG! )
	sumtail
	choicetail
	relationtail
	conjtail
	disjtail
	catenatail .

expr1 = "~" relation UOP! conjtail disjtail catenatail .


stat = expr1
	| id ( ":" LABDEF! stat LABSTMT!
		| VARID! {  "[" expr "]" SUBSCR! |  "." DOT! }
			exprtail ) .

block = begin BEGIN!
		{ vardecl ";" BLKHD! | labdecl ";" BLKHD!}
		stat { ";" BLKBODY! stat } end BLK! .