-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.bnf
More file actions
134 lines (102 loc) · 4.36 KB
/
grammar.bnf
File metadata and controls
134 lines (102 loc) · 4.36 KB
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
-- AleScript Grammar for BNFC
-- Converted to proper BNFC syntax
-- Token definitions
token Identifier (letter | '_') (letter | digit | '_')* ;
token Number digit+ | digit+ '.' digit+ ;
token Percentage digit+ ('.' digit+)? '%' ;
token StringLit '"' ((char - ["\"\\"]) | ('\\' char))* '"' ;
comment "//" ;
-- List separators
separator Statement "" ;
separator nonempty Ingredient "," ;
separator nonempty Identifier "," ;
separator nonempty Expression "," ;
-- Top-level program
Prog. Program ::= [Statement] ;
-- Statement types
SBrewDecl. Statement ::= BrewDecl ;
SWaitStmt. Statement ::= WaitStmt ;
STasteStmt. Statement ::= TasteStmt ;
SToastStmt. Statement ::= ToastStmt ;
SAgeStmt. Statement ::= AgeStmt ;
SBlendStmt. Statement ::= BlendStmt ;
SFortifyStmt. Statement ::= FortifyStmt ;
SFilterStmt. Statement ::= FilterStmt ;
SConditional. Statement ::= Conditional ;
SLoop. Statement ::= Loop ;
SKegStmt. Statement ::= KegStmt ;
SBarrelDecl. Statement ::= BarrelDecl ;
SBarrelAdd. Statement ::= BarrelAdd ;
SBarrelRemove. Statement ::= BarrelRemove ;
SRecipeDecl. Statement ::= RecipeDecl ;
SRecipeCallStmt. Statement ::= RecipeCallStmt ;
SRelabelStmt. Statement ::= RelabelStmt ;
SReturnStmt. Statement ::= ReturnStmt ;
SComment. Statement ::= Comment ;
-- Brew declarations
BrewFrom. BrewDecl ::= "brew" Identifier "from" [Ingredient] "." ;
BrewExpr. BrewDecl ::= "brew" Identifier "=" Expression "." ;
-- Ingredients
SimpleIngredient. Ingredient ::= IngredientName ;
QuantifiedIngredient. Ingredient ::= Number IngredientName ;
Water. IngredientName ::= "water" ;
Barley. IngredientName ::= "barley" ;
Hops. IngredientName ::= "hops" ;
Yeast. IngredientName ::= "yeast" ;
-- Wait statements
WaitDays. WaitStmt ::= "wait" "for" Number "days" "." ;
WaitDay. WaitStmt ::= "wait" "for" Number "day" "." ;
-- Age statement
Age. AgeStmt ::= "age" Identifier "until" Percentage "." ;
-- Taste statement
Taste. TasteStmt ::= "taste" Identifier "." ;
-- Toast statement
Toast. ToastStmt ::= "toast" Expression "." ;
-- Blend statement
Blend. BlendStmt ::= "blend" Identifier "with" Identifier "." ;
-- Fortify statement
Fortify. FortifyStmt ::= "fortify" Identifier "by" Number "." ;
-- Filter statement
Filter. FilterStmt ::= "filter" Identifier "by" Number "." ;
-- Keg statement
Keg. KegStmt ::= "keg" Identifier "." ;
-- Conditionals
CondIf. Conditional ::= IfStmt ;
CondJudge. Conditional ::= JudgeStmt ;
IfSimple. IfStmt ::= "if" Comparison ":" [Statement] "end" "." ;
IfElse. IfStmt ::= "if" Comparison ":" [Statement] "else" ":" [Statement] "end" "." ;
JudgeSimple. JudgeStmt ::= "judge" "if" Comparison ":" [Statement] "end" "." ;
JudgeElse. JudgeStmt ::= "judge" "if" Comparison ":" [Statement] "else" ":" [Statement] "end" "." ;
-- Comparisons
CompIs. Comparison ::= Identifier "is" Percentage ;
CompStronger. Comparison ::= Identifier "is" "stronger" "than" Percentage ;
CompWeaker. Comparison ::= Identifier "is" "weaker" "than" Percentage ;
CompNotWeaker. Comparison ::= Identifier "is" "not" "weaker" "than" Percentage ;
CompNotStronger. Comparison ::= Identifier "is" "not" "stronger" "than" Percentage ;
CompIsNumber. Comparison ::= Identifier "is" Number ;
-- Loops
RepeatUntil. Loop ::= "repeat" "until" Comparison ":" [Statement] "end" "." ;
RepeatTimes. Loop ::= "repeat" Expression "times" ":" [Statement] "end" "." ;
RepeatEach. Loop ::= "repeat" "each" Identifier "in" Identifier ":" [Statement] "end" "." ;
-- Barrel operations
BarrelDef. BarrelDecl ::= "barrel" Identifier "=" "[" [Identifier] "]" "." ;
BarrelAddOp. BarrelAdd ::= "add" Identifier "to" Identifier "." ;
BarrelRemoveOp. BarrelRemove ::= "remove" Identifier "from" Identifier "." ;
BarrelPos. BarrelAccess ::= Identifier "position" Number ;
-- Recipe declarations and calls
RecipeDef. RecipeDecl ::= "recipe" Identifier "(" [Identifier] ")" [Statement] "end" "." ;
RecipeStmt. RecipeCallStmt ::= RecipeCall "." ;
RecCall. RecipeCall ::= Identifier "(" [Expression] ")" ;
-- Relabel statement
Relabel. RelabelStmt ::= "relabel" Identifier "as" Expression "." ;
-- Return statement
Return. ReturnStmt ::= Identifier ;
-- Comment (handled by comment directive)
CommentStmt. Comment ::= ;
-- Expressions
EIdentifier. Expression ::= Identifier ;
ENumber. Expression ::= Number ;
EString. Expression ::= StringLit ;
EPercentage. Expression ::= Percentage ;
ERecipeCall. Expression ::= RecipeCall ;
EBarrelAccess. Expression ::= BarrelAccess ;