Skip to content

Commit ad80673

Browse files
committed
add "<<" and ">>" op
1 parent e8b3693 commit ad80673

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

demo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ println(car(cdr(cdr(cdr(cdr(x)))))); # 5
2626
code = fs-readFileSync("./demo");
2727
println(code);
2828
println(os-arch());
29+
println((1 << 1) == 2);

src/Environment.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ Environment.prototype.evaluate = evaluate
113113
// let { type: "let", vars: [ VARS... ], body: AST }
114114

115115
/**
116-
*
117116
*
118117
* @param {Object} expr
119118
* @param {Environment} env
@@ -188,8 +187,9 @@ function evaluate(expr, env) {
188187
}
189188
}
190189

190+
// check* functions are used to check the value type
191+
191192
/**
192-
*
193193
*
194194
* @param {any} x
195195
* @param {String} type
@@ -203,7 +203,6 @@ function checkType(x, type) {
203203
}
204204

205205
/**
206-
*
207206
*
208207
* @param {any} x
209208
* @returns {any} x
@@ -213,7 +212,6 @@ function checkNumber(x) {
213212
}
214213

215214
/**
216-
*
217215
*
218216
* @param {any} x
219217
* @returns {any} x
@@ -226,11 +224,10 @@ function checkDiv(x) {
226224
}
227225

228226
/**
229-
*
230227
*
231228
* @param {String} op
232229
* @param {any} a
233-
* @param {any} b
230+
* @param {any} b
234231
* @returns {any} operation result
235232
*/
236233
function applyOP(op, a, b) {
@@ -257,6 +254,10 @@ function applyOP(op, a, b) {
257254
return checkNumber(a) <= checkNumber(b)
258255
case '>=':
259256
return checkNumber(a) >= checkNumber(b)
257+
case '<<':
258+
return checkNumber(a) << checkNumber(b)
259+
case '>>':
260+
return checkNumber(a) >> checkNumber(b)
260261
case '==':
261262
return a === b
262263
case '!=':

src/parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ let PRECEDENCE = {
2929
">=": 7,
3030
"==": 7,
3131
"!=": 7,
32+
"<<": 8,
33+
">>": 8,
3234
"+": 10,
3335
"-": 10,
3436
"*": 20,
@@ -60,7 +62,7 @@ function parser(input) {
6062
}
6163

6264
function skipPunc(str) {
63-
// bug: cannot Identity `;`
65+
// !bug: cannot Identity `;`
6466
if (isPunc(str)) {
6567
input.next()
6668
} else {

0 commit comments

Comments
 (0)