Пример #1
0
        private void ParseLine(string l, BinaryWriter stream)
        {
            l = l.Trim();
            if (l.StartsWith("push "))
            {
                ParsePush(l, stream);
            }
            else if (l.Equals("pop"))
            {
                ParsePop(l, stream);
            }
            else if (l.StartsWith("stloc "))
            {
                ParseStloc(l, stream);
            }
            else if (l.StartsWith("ldloc "))
            {
                ParseLdloc(l, stream);
            }
            else if (l.StartsWith("call "))
            {
                ParseCall(l, stream);
            }
            else if (l.Equals("ret"))
            {
                ParseRet(l, stream);
            }
            else if (l.StartsWith("jmp "))
            {
                ParseJmp(l, stream);
            }
            else if (l.StartsWith("je "))
            {
                ParseJe(l, stream);
            }
            else if (l.StartsWith("jn "))
            {
                ParseJn(l, stream);
            }
            else if (l.StartsWith("error "))
            {
                ParseError(l, stream);
            }
            else if (l.Equals("errorpop"))
            {
                ParseErrorPop(l, stream);
            }
            else if (l.StartsWith("newobj "))
            {
                ParseNewObj(l, stream);
            }
            else if (l.StartsWith("int "))
            {
                ParseInterupt(l, stream);
            }
            else if (l.Equals("newarray"))
            {
                ParseNewArray(l, stream);
            }
            else if (l.Equals("arrayset"))
            {
                ParseArraySet(l, stream);
            }
            else if (l.Equals("arrayget"))
            {
                ParseArrayGet(l, stream);
            }
            else if (l.Equals("convert"))
            {
                ParseConvert(l, stream);
            }

                //Console
            else if (l.Equals("con_print"))
            {
                ParseConPrint(l,stream);
            }
            else if (l.Equals("con_println"))
            {
                ParseConPrintln(l, stream);
            }
            else if (l.Equals("con_read"))
            {
                ParseConRead(l, stream);
            }
            else if (l.Equals("con_title"))
            {
                ParseConTitle(l, stream);
            }

            //Math
            else if (l.Equals("add"))
            {
                ParseAdd(l, stream);
            }
            else if (l.Equals("sub"))
            {
                ParseSub(l, stream);
            }
            else if (l.Equals("mul"))
            {
                ParseMul(l, stream);
            }
            else if (l.Equals("div"))
            {
                ParseDiv(l, stream);
            }
            else if (l.Equals("mod"))
            {
                ParseMod(l, stream);
            }

            //Comparing
            else if (l.Equals("cmp"))
            {
                ParseCmp(l, stream);
            }
            else if (l.Equals("cls"))
            {
                ParseCls(l, stream);
            }
            else if (l.Equals("cle"))
            {
                ParseCle(l, stream);
            }
            else if (l.Equals("cgt"))
            {
                ParseCgt(l, stream);
            }
            else if (l.Equals("cge"))
            {
                ParseCge(l, stream);
            }

            //Stack Saving
            else if (l.Equals("stacksave"))
            {
                ParseStackSave(l, stream);
            }
            else if (l.Equals("stackrestore"))
            {
                ParseStackRestore(l, stream);
            }

            //Threading
            else if (l.Equals("threadnew"))
            {
                ParseThreadNew(l, stream);
            }
            else if (l.StartsWith("threadstart"))
            {
                ParseThreadStart(l, stream);
            }
            else if (l.StartsWith("threadend"))
            {
                ParseThreadEnd(l, stream);
            }
            else if (l.StartsWith("threadload"))
            {
                ParseThreadLoad(l, stream);
            }
            else if (l.Equals("threadsleep"))
            {
                ParseThreadSleep(l, stream);
            }
            else if (l.Equals("threadpri"))
            {
                ParseThreadPriority(l, stream);
            }

            //Program running
            else if (l.StartsWith("entrypoint "))
            {
                ParseEntryPoint(l, stream);
            }
            else if (l.Equals("terminate"))
            {
                ParseTerminate(l, stream);
            }

            //Args
            else if (l.StartsWith("callargs "))
            {
                ParseCallArgs(l, stream);
            }
            else if (l.StartsWith("starg "))
            {
                ParseStArg(l, stream);
            }
            else if (l.StartsWith("ldarg "))
            {
                ParseLdArg(l, stream);
            }

            //String functions
            else if (l.Equals("str_concat"))
            {
                ParseStrConcat(l, stream);
            }
            else if (l.Equals("str_cmp"))
            {
                ParseStrCmp(l, stream);
            }
            else if (l.Equals("str_sub"))
            {
                ParseStrSub(l, stream);
            }
            else if (l.Equals("str_subl"))
            {
                ParseStrSubl(l, stream);
            }
            else if (l.Equals("str_split"))
            {
                ParseStrSplit(l, stream);
            }

            //Special
            else if (l.StartsWith(":"))
            {
                string lname = l.Substring(1);
                aLabel lbl = new aLabel() { index = len, name = lname };
                labels.Add(lbl);
                len--;
            }
            else if (l.StartsWith("func "))
            {
                string fname = l.Substring(5);
                aFunction f = new aFunction() { name = fname, address = len };
                if (isClass)
                {
                    cref.functions.Add(f);
                }
                else
                {
                    functions.Add(f);
                }
                len--;
            }
            else if (l.StartsWith("class "))
            {
                string cname = l.Substring(6);
                aClass c = new aClass() { name = cname , functions = new List<aFunction>() , fields = new List<aField>() };
                classes.Add(c);
                isClass = true;
                cref = c;
                len--;
            }
            else if (l.StartsWith("open "))
            {
                string name = l.Substring(5);
                string code = File.ReadAllText(name);
                string newcode = code.Replace("\r", "");

                string[] lines = newcode.Split('\n');

                foreach (string line in lines)
                {
                    ParseLine(line, stream);
                    len += 1;
                }
                len--;
            }
            else if (l.StartsWith("var private "))
            {
                if (isClass)
                {
                    string name = l.Substring(12);
                    aField f = new aField() { name = name , access = "pri" };
                    cref.fields.Add(f);
                }
                len--;
            }
            else if (l.StartsWith("var public "))
            {
                if (isClass)
                {
                    string name = l.Substring(11);
                    aField f = new aField() { name = name , access = "pub" };
                    cref.fields.Add(f);
                }
                len--;
            }
            else if (l.Equals("end"))
            {
                if (isClass)
                {
                    isClass = false;
                }
                len--;
            }
            else
            {
                len--;
            }
        }
Пример #2
0
        private void ParseLine(string l, BinaryWriter stream)
        {
            l = l.Trim();
            if (l.StartsWith("push "))
            {
                ParsePush(l, stream);
            }
            else if (l.Equals("pop"))
            {
                ParsePop(l, stream);
            }
            else if (l.StartsWith("stloc "))
            {
                ParseStloc(l, stream);
            }
            else if (l.StartsWith("ldloc "))
            {
                ParseLdloc(l, stream);
            }
            else if (l.StartsWith("call "))
            {
                ParseCall(l, stream);
            }
            else if (l.Equals("ret"))
            {
                ParseRet(l, stream);
            }
            else if (l.StartsWith("jmp "))
            {
                ParseJmp(l, stream);
            }
            else if (l.StartsWith("je "))
            {
                ParseJe(l, stream);
            }
            else if (l.StartsWith("jn "))
            {
                ParseJn(l, stream);
            }
            else if (l.StartsWith("error "))
            {
                ParseError(l, stream);
            }
            else if (l.Equals("errorpop"))
            {
                ParseErrorPop(l, stream);
            }
            else if (l.StartsWith("newobj "))
            {
                ParseNewObj(l, stream);
            }
            else if (l.StartsWith("int "))
            {
                ParseInterupt(l, stream);
            }
            else if (l.Equals("newarray"))
            {
                ParseNewArray(l, stream);
            }
            else if (l.Equals("arrayset"))
            {
                ParseArraySet(l, stream);
            }
            else if (l.Equals("arrayget"))
            {
                ParseArrayGet(l, stream);
            }
            else if (l.Equals("convert"))
            {
                ParseConvert(l, stream);
            }

            //Console
            else if (l.Equals("con_print"))
            {
                ParseConPrint(l, stream);
            }
            else if (l.Equals("con_println"))
            {
                ParseConPrintln(l, stream);
            }
            else if (l.Equals("con_read"))
            {
                ParseConRead(l, stream);
            }
            else if (l.Equals("con_title"))
            {
                ParseConTitle(l, stream);
            }

            //Math
            else if (l.Equals("add"))
            {
                ParseAdd(l, stream);
            }
            else if (l.Equals("sub"))
            {
                ParseSub(l, stream);
            }
            else if (l.Equals("mul"))
            {
                ParseMul(l, stream);
            }
            else if (l.Equals("div"))
            {
                ParseDiv(l, stream);
            }
            else if (l.Equals("mod"))
            {
                ParseMod(l, stream);
            }

            //Comparing
            else if (l.Equals("cmp"))
            {
                ParseCmp(l, stream);
            }
            else if (l.Equals("cls"))
            {
                ParseCls(l, stream);
            }
            else if (l.Equals("cle"))
            {
                ParseCle(l, stream);
            }
            else if (l.Equals("cgt"))
            {
                ParseCgt(l, stream);
            }
            else if (l.Equals("cge"))
            {
                ParseCge(l, stream);
            }

            //Stack Saving
            else if (l.Equals("stacksave"))
            {
                ParseStackSave(l, stream);
            }
            else if (l.Equals("stackrestore"))
            {
                ParseStackRestore(l, stream);
            }

            //Threading
            else if (l.Equals("threadnew"))
            {
                ParseThreadNew(l, stream);
            }
            else if (l.StartsWith("threadstart"))
            {
                ParseThreadStart(l, stream);
            }
            else if (l.StartsWith("threadend"))
            {
                ParseThreadEnd(l, stream);
            }
            else if (l.StartsWith("threadload"))
            {
                ParseThreadLoad(l, stream);
            }
            else if (l.Equals("threadsleep"))
            {
                ParseThreadSleep(l, stream);
            }
            else if (l.Equals("threadpri"))
            {
                ParseThreadPriority(l, stream);
            }

            //Program running
            else if (l.StartsWith("entrypoint "))
            {
                ParseEntryPoint(l, stream);
            }
            else if (l.Equals("terminate"))
            {
                ParseTerminate(l, stream);
            }

            //Args
            else if (l.StartsWith("callargs "))
            {
                ParseCallArgs(l, stream);
            }
            else if (l.StartsWith("starg "))
            {
                ParseStArg(l, stream);
            }
            else if (l.StartsWith("ldarg "))
            {
                ParseLdArg(l, stream);
            }

            //String functions
            else if (l.Equals("str_concat"))
            {
                ParseStrConcat(l, stream);
            }
            else if (l.Equals("str_cmp"))
            {
                ParseStrCmp(l, stream);
            }
            else if (l.Equals("str_sub"))
            {
                ParseStrSub(l, stream);
            }
            else if (l.Equals("str_subl"))
            {
                ParseStrSubl(l, stream);
            }
            else if (l.Equals("str_split"))
            {
                ParseStrSplit(l, stream);
            }

            //Special
            else if (l.StartsWith(":"))
            {
                string lname = l.Substring(1);
                aLabel lbl   = new aLabel()
                {
                    index = len, name = lname
                };
                labels.Add(lbl);
                len--;
            }
            else if (l.StartsWith("func "))
            {
                string    fname = l.Substring(5);
                aFunction f     = new aFunction()
                {
                    name = fname, address = len
                };
                if (isClass)
                {
                    cref.functions.Add(f);
                }
                else
                {
                    functions.Add(f);
                }
                len--;
            }
            else if (l.StartsWith("class "))
            {
                string cname = l.Substring(6);
                aClass c     = new aClass()
                {
                    name = cname, functions = new List <aFunction>(), fields = new List <aField>()
                };
                classes.Add(c);
                isClass = true;
                cref    = c;
                len--;
            }
            else if (l.StartsWith("open "))
            {
                string name    = l.Substring(5);
                string code    = File.ReadAllText(name);
                string newcode = code.Replace("\r", "");

                string[] lines = newcode.Split('\n');

                foreach (string line in lines)
                {
                    ParseLine(line, stream);
                    len += 1;
                }
                len--;
            }
            else if (l.StartsWith("var private "))
            {
                if (isClass)
                {
                    string name = l.Substring(12);
                    aField f    = new aField()
                    {
                        name = name, access = "pri"
                    };
                    cref.fields.Add(f);
                }
                len--;
            }
            else if (l.StartsWith("var public "))
            {
                if (isClass)
                {
                    string name = l.Substring(11);
                    aField f    = new aField()
                    {
                        name = name, access = "pub"
                    };
                    cref.fields.Add(f);
                }
                len--;
            }
            else if (l.Equals("end"))
            {
                if (isClass)
                {
                    isClass = false;
                }
                len--;
            }
            else
            {
                len--;
            }
        }