Skip to content

Commit 64196ce

Browse files
committed
Variable initializers
1 parent a81706d commit 64196ce

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

examples/m1.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ module m1
33
private
44
public sp, dp, hp
55

6+
integer, parameter :: dp=kind(0.d0), & ! double precision
7+
hp=selected_real_kind(15), & ! high precision
8+
sp=kind(0.) ! single precision
69

710
end module

fortran.g4

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ public_decl
1919
;
2020

2121
var_decl
22-
: type (',' modifier)* '::' IDENT (',' IDENT)*
22+
: type (',' modifier)* '::' var_sym_decl (',' var_sym_decl)*
23+
;
24+
25+
var_sym_decl
26+
: IDENT ('=' expr)?
27+
;
28+
29+
expr
30+
: IDENT | NUMBER | fn_call
31+
;
32+
33+
fn_call
34+
: IDENT '(' expr ')'
2335
;
2436

2537
type
@@ -30,13 +42,22 @@ modifier
3042
: 'parameter' | 'intent' | 'dimension' | 'allocatable' | 'pointer'
3143
;
3244

45+
NUMBER
46+
: ([0-9]+ '.' [0-9]* | '.' [0-9]+) ([eEdD] [+-]? [0-9]+)?
47+
| [0-9]+ ([eEdD] [+-]? [0-9]+)?
48+
;
49+
3350
IDENT
3451
: ('a' .. 'z' | 'A' .. 'Z') ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_')*
3552
;
3653

3754
COMMENT
3855
: '!' ~[\r\n]* -> skip;
3956

57+
LINE_CONTINUATION
58+
: '&' -> skip
59+
;
60+
4061
WS
4162
: [ \t\r\n] -> skip
4263
;

0 commit comments

Comments
 (0)