"got \"" + ret + "\"");
}
}
}
var tests = [
{
text: "123",
expect: 123
},
{
text: "1 + 2 + 3",
expect: 6
},
{
text: "10 - 1 - 11",
expect: -2
},
{
text: "1 + 2 * 3 - 4",
expect: 3
},
{
text: "1 + 2 * 3 - 4 / 2",
expect: 5
},
{
text: "",
expect: null
},
{
text: "a",
expect: null
},
{
text: "10 a ",
expect: null
},
{
text: "10 + ",
expect: null
},
{
text: " + 2",
expect: null
},
];
unit_test(tests);
编程阅历:分歧性每个代码里有意义的函数和变量都像人物一样。之前怎样命名,之后也一样,异样的意思不要有多余的表示。而且保持它们的出场顺序不变。
var TOK_END = 0,
TOK_NUM = 1;
var OP_END = 0,
OP_NUM = 1,
OP_ADD = 2,
OP_SUB = 3,
OP_MUL = 4,
OP_DIV = 5;
function calc_run(text) {
}
function calc_parse(text) {
}
function calc_parse_expr(parser, level) {
}
function calc_parse_unary(parser) {
}
function next_token(parser) {
}
function parse_number(parser) {
}
function calc_exec(code) {
}
function unit_test(tests) {
}
var tests = [
];
unit_test(tests);
https://github.com/hongzhidao/the-craft-of-programming
在开源浪潮下,写好的代码尤其重要!
【编辑引荐】
浅谈前端开发学习与开展
3D图示Python标准自学教程基础篇(2)_面向对象OOP编程
java零基础快速入门-IO流,网络编程以及反射和设计形式
PyFlink 开发环境利器:Zeppelin Notebook
完美抠图王冰冰!字节实习生开发的AI,完成4K60帧视频实时抠图
(责任编辑:admin)