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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 | 1
1
1
1
85
85
44
44
43
1
44
44
| (function(sc) {
"use strict";
require("../lang");
sc.lang.compiler = {
Token: {
CharLiteral: "Char",
EOF: "<EOF>",
FalseLiteral: "False",
FloatLiteral: "Float",
Identifier: "Identifier",
IntegerLiteral: "Integer",
Keyword: "Keyword",
Label: "Label",
NilLiteral: "Nil",
Punctuator: "Punctuator",
StringLiteral: "String",
SymbolLiteral: "Symbol",
TrueLiteral: "True",
SingleLineComment: "SingleLineComment",
MultiLineComment: "MultiLineComment"
},
Syntax: {
AssignmentExpression: "AssignmentExpression",
BlockExpression: "BlockExpression",
BinaryExpression: "BinaryExpression",
CallExpression: "CallExpression",
FunctionExpression: "FunctionExpression",
EnvironmentExpression: "EnvironmentExpression",
Identifier: "Identifier",
ListExpression: "ListExpression",
Literal: "Literal",
EventExpression: "EventExpression",
Program: "Program",
ThisExpression: "ThisExpression",
UnaryExpression: "UnaryExpression",
VariableDeclaration: "VariableDeclaration",
VariableDeclarator: "VariableDeclarator",
ValueMethodEvaluator: "ValueMethodEvaluator",
ValueMethodResult: "ValueMethodResult"
},
Message: {
UnexpectedToken: "Unexpected token #{0}",
UnexpectedNumber: "Unexpected number",
UnexpectedIdentifier: "Unexpected identifier",
UnexpectedKeyword: "Unexpected token #{0}",
UnexpectedLiteral: "Unexpected #{0}",
UnexpectedLabel: "Unexpected label",
UnexpectedReserved: "Unexpected reserved word",
UnexpectedEOS: "Unexpected end of input",
InvalidLHSInAssignment: "Invalid left-hand side in assignment",
Redeclaration: "'#{0} #{1}' has already been declared",
VariableNotDefined: "#{0} is not defined",
NotImplemented: "#{0} is not implemented",
},
Keywords: {
var: "keyword",
arg: "keyword",
const: "keyword",
this: "function",
thisThread: "function",
thisProcess: "function",
thisFunction: "function",
thisFunctionDef: "function",
},
binaryPrecedenceDefaults: {
"?": 1,
"??": 1,
"!?": 1,
"->": 2,
"||": 3,
"&&": 4,
"|": 5,
"&": 6,
"==": 7,
"!=": 7,
"===": 7,
"!==": 7,
"<": 8,
">": 8,
"<=": 8,
">=": 8,
"<<": 9,
">>": 9,
"+>>": 9,
"+": 10,
"-": 10,
"*": 11,
"/": 11,
"%": 11,
"!": 12
},
tokenize: function(source, opts) {
return new sc.lang.compiler.Lexer(source, opts).tokenize();
},
parse: function(source, opts) {
var lexer = new sc.lang.compiler.Lexer(source, opts);
return new sc.lang.compiler.Parser(null, lexer).parse();
},
compile: function(source, opts) {
var ast;
if (typeof source === "string") {
ast = sc.lang.compiler.parse(source, opts);
} else {
ast = source;
}
ast = new sc.lang.compiler.Rewriter().rewrite(ast);
return new sc.lang.compiler.CodeGen(null, opts).compile(ast);
}
};
})(sc);
|