-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRockstar.g4
142 lines (110 loc) · 3.96 KB
/
Rockstar.g4
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
135
136
137
138
139
140
141
142
parser grammar Rockstar;
options { tokenVocab=RockstarLexer; }
program: (NL|WS)* (statementList | functionDeclaration)* WS*;
statementList: statement+;
statement: (ifStmt | inputStmt | outputStmt | assignmentStmt | incrementStmt | decrementStmt | loopStmt | returnStmt | continueStmt | breakStmt) (NL+?|EOF);
expression: functionCall
| lhe=expression WS op=(KW_MULTIPLY|KW_DIVIDE) WS rhe=expression
| lhe=expression WS op=(KW_ADD|KW_SUBTRACT) WS rhe=expression
| lhe=expression WS comparisionOp WS rhe=expression
| lhe=expression WS op=(KW_AND|KW_OR|KW_NOR) WS rhe=expression
| (literal|variable|constant)
;
functionCall: functionName=variable WS KW_TAKING WS argList;
argList: (variable|literal) ((WS KW_AND|COMMA) WS (variable|literal))*;
functionDeclaration: functionName=variable WS KW_TAKES WS paramList NL statementList NL;
paramList: variable ((COMMA? WS KW_AND WS | COMMA | AMPERSAND | APOSTROPHED_N) variable)*;
comparisionOp: KW_IS
| KW_NOT_EQUAL
| KW_IS WS (KW_GREATER|KW_LESS) WS KW_THAN
| KW_IS WS KW_AS WS (KW_GREATER_EQUAL|KW_LESS_EQUAL) WS KW_AS
;
assignmentStmt: variable (APOSTROPHE_S | WS (KW_IS|KW_WAS_WERE)) WS (poeticNumberLiteral|constant|literal)
| KW_LET WS variable WS KW_BE WS expression
| KW_PUT WS expression WS KW_INTO WS variable
| variable WS KW_SAYS WS poeticStringLiteral
;
inputStmt: KW_LISTEN WS KW_TO WS variable;
outputStmt: KW_SAY WS expression;
ifStmt: KW_IF WS expr=expression NL statementList (KW_ELSE NL statementList)?;
loopStmt: KW_LOOP WS expr=expression NL statementList;
incrementStmt: KW_BUILD WS variable WS ups;
ups: KW_UP (COMMA WS KW_UP)*;
decrementStmt: KW_KNOCK WS variable WS downs;
downs: KW_DOWN (COMMA WS KW_DOWN)*;
returnStmt: KW_GIVE WS KW_BACK WS expression;
continueStmt: KW_CONTINUE;
breakStmt: KW_BREAK;
constant: CONSTANT_UNDEFINED
| CONSTANT_NULL
| CONSTANT_TRUE
| CONSTANT_FALSE
| CONSTANT_EMPTY
;
literal: NUMERIC_LITERAL | STRING_LITERAL;
variable: COMMON_VARIABLE_PREFIXES WS WORD
| NOUN (WS NOUN)*
| PRONOUNS
;
poeticNumberLiteral: poeticNumberLiteralWord poeticNumberLiteralDecimalSeparator? (WS poeticNumberLiteralWord poeticNumberLiteralDecimalSeparator?)*;
poeticNumberLiteralWord: COMMON_VARIABLE_PREFIXES
| allKeywords
| PRONOUNS
| WORD
| NOUN
;
poeticNumberLiteralDecimalSeparator: DOT;
poeticStringLiteral: poeticStringLiteralWord poeticStringLiteralGarbage* (WS poeticStringLiteralGarbage* poeticStringLiteralWord poeticStringLiteralGarbage*)*;
poeticStringLiteralGarbage: DOT
| COMMA
| QUESTION_MARK
| EXCLAMATION_MARK
| AMPERSAND
;
poeticStringLiteralWord: COMMON_VARIABLE_PREFIXES
| PRONOUNS
| CONSTANT_UNDEFINED
| CONSTANT_NULL
| CONSTANT_TRUE
| CONSTANT_FALSE
| allKeywords
| WORD
| NOUN
;
allKeywords: KW_PUT
| KW_INTO
| KW_SAYS
| KW_TAKING
| KW_TAKES
| KW_LISTEN
| KW_TO
| KW_SAY
| KW_LOOP
| KW_IF
| KW_ELSE
| KW_BUILD
| KW_UP
| KW_KNOCK
| KW_DOWN
| KW_GIVE
| KW_BACK
| KW_CONTINUE
| KW_BREAK
| KW_NOT
| KW_MULTIPLY
| KW_DIVIDE
| KW_ADD
| KW_SUBTRACT
| KW_IS
| KW_NOT_EQUAL
| KW_WAS_WERE
| KW_THAN
| KW_AS
| KW_GREATER
| KW_LESS
| KW_GREATER_EQUAL
| KW_LESS_EQUAL
| KW_AND
| KW_OR
| KW_NOR
;