-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage.g4
54 lines (44 loc) · 1.52 KB
/
Language.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
grammar Language;
// program: expression|;
program: ( expression (NL | EOF) )* EOF? # instructionLine;
expression:
(Int | Bool) # literal // used to be constant
| Identifier typeBinding? # variable
| expression expression # application
| Lambda Identifier typeBinding? '.' expression # abstraction
| Identifier typeBinding? '=' expression # assign
| condition # conditional // used to be ifThenElse
| expression Operator expression # binaryExpression
| 'print' expression # printInstruction
| 'import' Identifier # importInstruction
| '(' expression ')' # brackets;
body: expression ;
condition: 'if' expression 'then' body 'else' body
| '(' expression '->' body '|' body ')';
// leafType: TypeIdentifier;
// nodeType: TypeIdentifier '->' TypeIdentifier;
// type: leafType
// | nodeType
// | '(' type ')';
typeBinding: ':' type;
type: TypeIdentifier #leafType
| type '->' type #nodeType
| '(' type ')' #typeBrackets;
// imports: 'import' Identifier | '(' imports ')';
Lambda: '\\' | 'λ';
Bool : 'tru' | 'fls' | 'true' | 'false';
Int: [0-9]+;
Identifier: ('a' ..'z') ('a' ..'z' | 'A' ..'Z' | '0' ..'9')*;
TypeIdentifier: ('A' ..'Z') ('a' ..'z')*;
Operator: ('!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '-' | '+' | '=' | '<' | '>' | '/' | '.')+;
// '+'
// | '-'
// | '*'
// | '/'
// | '<'
// | '>'
// | '<='
// | '>='
// | '==';
WS: [ \t\r]+ -> skip;
NL: [\n;]+;