Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不使用LPeg模块的情况下在lua中输入lex用户?_Lua_Lexer - Fatal编程技术网

如何在不使用LPeg模块的情况下在lua中输入lex用户?

如何在不使用LPeg模块的情况下在lua中输入lex用户?,lua,lexer,Lua,Lexer,我查看了其他已回答的问题(即安装和使用LPeg),但没有找到任何工作解释。我正在用Lua制作一种非常基本的编程语言(我知道怎么做),但对于某些事情,比如变量,我只需要一个lexer。以下是我的两个函数,我在command(cmd)函数中使用了string.match lot: function screen (action, actionvar) if action = "clear" then os.execute("clear") elseif action = "cls" then os

我查看了其他已回答的问题(即安装和使用LPeg),但没有找到任何工作解释。我正在用Lua制作一种非常基本的编程语言(我知道怎么做),但对于某些事情,比如变量,我只需要一个lexer。以下是我的两个函数,我在command(cmd)函数中使用了string.match lot:

function screen (action, actionvar) 
if action = "clear" then
os.execute("clear")
elseif action = "cls" then
os.execute("cls")
elseif action = "showText" then
print(actionvar)
end
end


function command (cmd)
if string.match(cmd, "screen") then
    if string.match(cmd, "clear") then
        screen(clear)
    elseif string.match(cmd, "cls") then
        screen(cls)
    end
    -- it must be showText or improper cmd.
    if string.match(cmd, "showText") then

    else
    print("Error: Unrecognized screen command.")
    return null
    end
end
end

这方面的习惯用法是为每个命令定义函数并将它们放入表中。然后解析每一行,提取命令和参数,并将它们传递给正确的函数。此外,您还应该返回nil(notnull),即使未定义null,它也将返回nil。然后解析每一行,提取命令和参数,并将它们传递给正确的函数。此外,您应该返回nil(非null),即使未定义null时,它也将是nil。