-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFullForm.g4
executable file
·43 lines (35 loc) · 954 Bytes
/
FullForm.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
grammar FullForm;
import FullFormLexerRules;
// PARSER RULES
prog
: expr (NEWLINE+ expr?)*
;
expr
: numberLiteral #Number
| StringLiteral #StringLiteral
| symbol #SymbolLiteral
| expr LBRACKET expressionList RBRACKET #HeadExpression
;
expressionList // Can be empty.
: expr? (COMMA expr?)* #ExpressionListed
;
//Symbols and Contexts
symbol
: context? Name #ContextName
;
context
: BACKQUOTE? Name BACKQUOTE #SimpleContext
| Name BACKQUOTE Name BACKQUOTE #CompoundContext
;
//Numbers
numberLiteral
: MINUS? DIGITS NumberInBase numberLiteralPrecision? numberLiteralExponent? #NumberBaseN // Number in any base.
| MINUS? (DIGITS | DecimalNumber) numberLiteralPrecision? numberLiteralExponent? #NumberBaseTen // Number in base ten.
;
numberLiteralPrecision
: DOUBLEBACKQUOTE (DecimalNumber | DIGITS)
| BACKQUOTE (DecimalNumber | DIGITS)?
;
numberLiteralExponent
: (ASTERISKCARET (PLUS|MINUS)? DIGITS)
;