-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpl_draft.par
97 lines (80 loc) · 2.89 KB
/
xpl_draft.par
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
//Meta information
#parser "XPL";
#description "eXample Programming Language (Draft)";
#copyright "In the public domain, 2011";
#version "0.1";
#prefix "xpl";
//Precedence and associativity
#left "=";
#left "=="
"!="
"<="
">="
'>'
'<'
;
#left '+'
'-'
;
#left '*'
'/'
;
//Regular expressions
@string '"' !'"'* '"'
;
@identifier 'A-Za-z_' 'A-Za-z0-9_'*
;
//Lexemes
#lexeme real
;
real -> real_integer '.' real_fraction
| real_integer '.'?
| '.' real_fraction
;
real_integer -> real_integer '0-9'
| '0-9'
;
real_fraction -> real_fraction '0-9'
| '0-9'
;
//Whitespace grammar construct
#whitespaces whitespace
;
whitespace -> ' \r\n\t'+
| "//" !'\n'* '\n'
;
//Goal symbol
program$ -> statement*
;
statement -> "if" '(' expression ')' statement
| "if" '(' expression ')' statement
"else" statement
| "while" '(' expression ')' statement
| '{' statement* '}'
| expression ';'
| ';'
;
expression -> variable "=" expression
| expression "==" expression
| expression "!=" expression
| expression '>' expression
| expression '<' expression
| expression "<=" expression
| expression ">=" expression
| expression '+' expression
| expression '-' expression
| expression '*' expression
| expression '/' expression
| '-' expression #precedence '*'
| '(' expression ')'
| real
| @string
| variable
| function '(' parameter_list? ')'
;
parameter_list -> parameter_list ',' expression
| expression
;
variable
function -> @identifier
;