Exemple #1
0
        public void Compile(string str)
        {
            str                = str.Replace("\0", "").Replace("\r", "");
            CompilingEngine    = this;
            compilingCode      = str;
            compilingPos       = 0;
            currentfunc        = BodyStatement;
            func_compile_stack = new Stack <string>();
            char ch;

            while (true)
            {
                PeekToWord();
                ch = Peek();
                switch (ch)
                {
                case EOF:
                    return;

                case '[':
                    currentfunc.AddStatement(CompileCallFuncStatement());
                    PeekToWord();
                    if (Peek() != ';')
                    {
                        throw new SyntaxException("函数调用结束后仍然出现语句,请检查是否缺少分号。", compilingPos);
                    }
                    break;

                default:
                {
                    string name = ch + PeekToBlankSym('=');
                    PeekToWord();
                    char p = Peek();
                    if (p == EOF)
                    {
                        throw new SyntaxException("不可分析的文件结尾。", compilingPos);
                    }
                    else if (p == '=')
                    {
                        currentfunc.AddStatement(CompileSetValStatement(name));
                    }
                    else
                    {
                        compilingPos--;
                        if (name == "func")
                        {
                            CompileFuncStatement();
                            currentfunc = BodyStatement;
                        }
                    }
                }
                break;
                }
            }
        }