/
Syntax.lean
48 lines (43 loc) · 1.86 KB
/
Syntax.lean
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
/-
Copyright (c) 2022 Arthur Paulino. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arthur Paulino
-/
declare_syntax_cat literal
syntax ("-" noWs)? num : literal
syntax str : literal
syntax "true" : literal
syntax "false" : literal
syntax ("-" noWs)? scientific : literal
declare_syntax_cat binop
syntax " + " : binop
syntax " * " : binop
syntax " = " : binop
syntax " != " : binop
syntax " < " : binop
syntax " <= " : binop
syntax " > " : binop
syntax " >= " : binop
declare_syntax_cat expression
syntax literal : expression -- literal
syntax withPosition(
"[ " colGt literal,* " ]") : expression -- list
syntax:51 ident : expression -- variable
syntax:49 expression (colGt expression:50)+ : expression -- application
syntax:48 " ! " expression : expression -- the only unary op
syntax:48 expression binop expression : expression -- binary operator
syntax " ( " expression " ) " : expression
declare_syntax_cat program
declare_syntax_cat programSeq
syntax withPosition((colGe program)+) : programSeq -- seq
syntax "skip" : program
syntax withPosition(ident+ colGt " := " programSeq) : program -- decl
syntax expression : program -- eval
syntax withPosition(
"if " programSeq colGe " then "
colGt programSeq
(colGe " else "
colGt programSeq)?) : program -- fork
syntax withPosition("while " programSeq " do "
colGt programSeq) : program -- loop
syntax withPosition("!print " colGt expression) : program -- print