正在抽空看lua的语法分析(lparse.c), 这个过程也是断断续续的。这里的记录也将会是断断续续的,等到全部看透就再写一篇补充之。
看语法分析前得先看词法分析, 就一个llex.c 代码很简单,读取文件,每次取出一个有效的token,或者保留字,或者变量或者值等等。其中保留字有以下这么多种:
const char *const luaX_tokens [] = {
"and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "if",
"in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while",
"..", "...", "==", ">=", "<=", "~=",
"<number>", "<name>", "<string>", "<eof>",
NULL
};
全都用luaS_fix api永驻过。
此外通过llex中函数skip_sep可以看出, 5.1的注释支持如下的写法, lua语法掌握不好, 这个还是第一次知道。
--[=====
这里是注释
=====]--
static int skip_sep (LexState *ls) {
int count = 0;
int s = ls->current;
lua_assert(s == '[' || s == ']');
save_and_next(ls);
while (ls->current == '=') {
save_and_next(ls);
count++