Radicalc  Check-in [39762d28d8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:rejecting keywords as identifiers, and parsing return
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:39762d28d851ee3e0396ac70a1a0592015e6d5c70c8f0690442fde10309b8240
User & Date: athaudia 2017-07-30 11:04:26
Context
2017-07-30
11:59
operator precedence implemented (i think) check-in: 848be520eb user: athaudia tags: trunk
11:04
rejecting keywords as identifiers, and parsing return check-in: 39762d28d8 user: athaudia tags: trunk
10:53
parsing assignment check-in: ccea242283 user: athaudia tags: trunk
Changes

Changes to src/radicalc.ne.

5
6
7
8
9
10
11

12






13
14
15
16
17
18
19
..
40
41
42
43
44
45
46

47
48
49
50
51
52
53
..
83
84
85
86
87
88
89







90
91
92
93
94
95
96
%}

Type -> ":" _ ident {%
	function(d) {return d[2]}
%}

ident -> [a-zA-Z] [a-zA-Z_0-9]:* {%

	function(d) {return d[0] + d[1].join("")}






%}

FunDef -> "fun" __ ident _ "(" _ FunDefParams:? _ ")" _ Type:? NL
Block
"end" NL {%
	function(d) { return {
		name: d[2],
................................................................................

Stmt ->
	IfStmt    {% id %}
|	WhileStmt {% id %}
|	Expr      {% function(d) {return {type: "stmtExpr", expr: d[0]}} %}
|	VarDef    {% id %}
|	Assign    {% id %}


IfStmt -> "if" _ Expr _ NL Block (_ "else" NL Block):? _ "end" {%
	function(d) { return {
		type: "if",
		cond: d[2],
		ifBlock: d[5],
		elseBlock: d[6]?d[6][3]:null
................................................................................
Assign -> ident _ "=" _ Expr {%
	function(d) { return {
		type: "assign",
		name: d[0],
		expr: d[4]
	}}
%}








Expr ->
	FunCall {% id %}
|	VarUse  {% id %}
|	LitInt  {% id %}
|	LitStr  {% id %}








>
|
>
>
>
>
>
>







 







>







 







>
>
>
>
>
>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%}

Type -> ":" _ ident {%
	function(d) {return d[2]}
%}

ident -> [a-zA-Z] [a-zA-Z_0-9]:* {%
	function(d, l, r) {
		var str = d[0] + d[1].join("");
		var keywords = ["else", "end", "fun", "if", "return", "var", "while"];
		if(keywords.indexOf(str) == -1)
			return str;
		else
			return r;
	}
%}

FunDef -> "fun" __ ident _ "(" _ FunDefParams:? _ ")" _ Type:? NL
Block
"end" NL {%
	function(d) { return {
		name: d[2],
................................................................................

Stmt ->
	IfStmt    {% id %}
|	WhileStmt {% id %}
|	Expr      {% function(d) {return {type: "stmtExpr", expr: d[0]}} %}
|	VarDef    {% id %}
|	Assign    {% id %}
|	Return    {% id %}

IfStmt -> "if" _ Expr _ NL Block (_ "else" NL Block):? _ "end" {%
	function(d) { return {
		type: "if",
		cond: d[2],
		ifBlock: d[5],
		elseBlock: d[6]?d[6][3]:null
................................................................................
Assign -> ident _ "=" _ Expr {%
	function(d) { return {
		type: "assign",
		name: d[0],
		expr: d[4]
	}}
%}

Return -> "return" (_ Expr):? {%
	function(d) { return {
		type: "return",
		expr: d[1]?d[1][1]:null
	}}
%}

Expr ->
	FunCall {% id %}
|	VarUse  {% id %}
|	LitInt  {% id %}
|	LitStr  {% id %}