-
Notifications
You must be signed in to change notification settings - Fork 0
/
toy.pest
60 lines (51 loc) · 1.54 KB
/
toy.pest
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
program = _{ SOI ~ init* ~ thread* ~ final ~ EOI }
thread = { "thread" ~ name ~ "{" ~ stmt* ~ "}" }
stmt = {
modify
| assign
| fence
| if
| while
}
stmts = { stmt* }
modify = { name ~ "=" ~ expr ~ ";" }
fence = { "Fence" ~ "(" ~ fencemarker ~ ")" ~ ";" }
assign = { "let" ~ name ~ ":" ~ "u32" ~ "=" ~ expr ~ ";" }
if = { "if" ~ "(" ~ condexpr ~ ")" ~ "{" ~ stmts ~ "}" ~ "else" ~ "{" ~ stmts ~ "}" }
while = { "while" ~ "(" ~ condexpr ~ ")" ~ "{" ~ stmt* ~ "}" }
init = { assign }
final = { "final" ~ "{" ~ assert* ~ "}" }
expr = { name | num }
fencemarker = { "WR" | "WW" | "RW" | "RR" }
assert = { "assert" ~ "(" ~ logicexpr ~ ")" ~ ";" }
condatom = {
condneg
| condparen
| condeq
| condleq
}
condneg = { "!" ~ condexpr }
condparen = { "(" ~ condexpr ~ ")" }
condeq = { expr ~ "==" ~ expr }
condleq = { expr ~ "<=" ~ expr }
// '&&' has lowest precedence
condexpr = { condatom ~ ("&&" ~ condatom)* }
logicatom = {
logicneg
| logicparen
| logiceq
| logicleq
}
logicneg = { "!" ~ logicexpr }
logicparen = { "(" ~ logicexpr ~ ")" }
logiceq = { logicint ~ "==" ~ logicint }
logicleq = { logicint ~ "<=" ~ logicint }
// '&&' has lowest precedence
logicexpr = { logicatom ~ ("&&" ~ logicatom)* }
logicint = { logicvar | num }
logicvar = @{ name ~ "." ~ name }
name = @{ ASCII_ALPHA ~ ASCII_ALPHANUMERIC* }
num = @{ ASCII_DIGIT+ }
WHITESPACE = _{ " " | NEWLINE }
// do not consume newline at end of a comment
COMMENT = _{ "//" ~ (!"\n" ~ ANY)* }