forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortran.g4
72 lines (55 loc) · 1.07 KB
/
fortran.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
grammar fortran;
module
: 'module' IDENT 'implicit none' decl* ('contains' subroutine+ )? 'end' IDENT?
;
decl
: private_decl
| public_decl
| var_decl
;
private_decl
: 'private'
;
public_decl
: 'public' IDENT (',' IDENT)*
;
var_decl
: type (',' modifier)* '::' var_sym_decl (',' var_sym_decl)*
;
var_sym_decl
: IDENT ('=' expr)?
;
expr
: IDENT | NUMBER | fn_call
;
fn_call
: IDENT '(' expr? ')'
;
type
: 'integer' | 'char' | 'real' | 'logical'
;
modifier
: 'parameter' | 'intent' | 'dimension' | 'allocatable' | 'pointer'
;
subroutine
: 'subroutine' IDENT decl* statement* 'end' 'subroutine'?
;
statement
: IDENT '=' expr
| fn_call
;
NUMBER
: ([0-9]+ '.' [0-9]* | '.' [0-9]+) ([eEdD] [+-]? [0-9]+)?
| [0-9]+ ([eEdD] [+-]? [0-9]+)?
;
IDENT
: ('a' .. 'z' | 'A' .. 'Z') ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_')*
;
COMMENT
: '!' ~[\r\n]* -> skip;
LINE_CONTINUATION
: '&' -> skip
;
WS
: [ \t\r\n] -> skip
;