1 Star 0 Fork 0

fork-man / compiler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
interpreter.html 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
HOHD 提交于 2021-01-09 16:44 . 赋值操作
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
let tokenzier = (code) => {
// 字符串下标
let current = 0
// 结果、词法列表
let tokens = []
let LETTERS = /[a-z|A-Z]/i
while (current < code.length) {
let char = code[current]
if (LETTERS.test(char)) {
let value = ''
//英文字符字面量可能不是一个字符
//索引我们循环知道不是英文字符
while (LETTERS.test(char)) {
value += char
char = code[++current]
}
//push 一个词法、同时也是一个Json
tokens.push({
'type': 'name',
value
})
current++
continue
}
//操作符压入,等号是赋值操作
if ('=' == char) {//let a = '=' //
tokens.push({
type: 'operator',
value: char
})
}
current++
continue
}//while end
return tokens
}//function end
// 测试代码
let simpleCode = `
let a = 20
println -> a
`
console.info(tokenzier(simpleCode))
</script>
</body>
</html>
1
https://gitee.com/fork-man/compiler.git
git@gitee.com:fork-man/compiler.git
fork-man
compiler
compiler
master

搜索帮助