Example #1
0
        public override string go()
        {
            string s = "";
            Lexems.Lexema l=null;
            while ((l = getToken()) != null)
            {
                lexems.Add(l);
            }
            string assignment = null;
            while ((assignment = new Assignment(this).go()) != null)
            {
                s += assignment+"\n";
            }

            return s;
        }
Example #2
0
File: ForToc.cs Project: 4e7/MetaL
        public override string go()
        {
            string register = "cx";
            string loop = "";
            string label = "LOOP" + root.loopCount.ToString() + ":";
            int loopCountQ = root.loopCount++;

            string header = label;

            Assignment a=new Assignment(this.parent);
            string assignment =a.go() ;
            header+= "\tmov "+register+"," + a.indetifier.Data+"\n";
            Lexems.Lexema l = getToken();
            if (l == null || l.GetType().Name != "To")
            {
                addError(new ToKeyWordMissed(), 0);
                if (l != null) this.lexems.Add(l);
            }

            while ((l = getToken()) != null)
            {
                this.lexems.Add(l);
            }

            int position = m_tokenPosition;
            Expression e = new Expression(this);
            string expression=e.go();
            string condition = "\txor "+register+"," + e.result +"\n\tdec "+e.result+ "\n\tjnz " + label+"\n";
            m_tokenPosition = position;

            loop += ";----------Begin loop " + (loopCountQ).ToString() + "----------------\n";
            loop += assignment+"\n";
            loop += expression;
            loop += header;
            loop += "\t\tpush "+register+"\n";
            loop += "\t\tpush " + e.result + "\n";
            loop += e.calculations;
            loop += "\t\tpop "+register+"\n";
            loop += "\t\tpop " + e.result + "\n";
            loop += condition;
            loop += ";----------End loop " + (loopCountQ ).ToString() + "----------------\n";

            return loop;
        }
Example #3
0
        public override string go()
        {
            string s = "";
            Lexems.Lexema l = getToken();
            string type = "";
            if (l != null)
            {
                type = l.GetType().Name;
            }
            else
            {
                return null;
            }
            switch (type)
            {
                case "Identifire":
                    {
                        wasIndetifier = true;
                        if (hasId(l.Data))
                        {
                            indetifier.Data = l.Data;
                        }
                        else
                        {
                            addError(new UndefindedIndefier(l.Data), 0); ;
                        }
                        Lexems.Lexema lt = null;
                        while ((lt = getToken()) != null && lt.GetType().Name != "Endl")
                        {
                            this.lexems.Add(lt);
                        }
                        if (lt == null)
                        {
                            addError(new EndlMissedError(), 0);
                        }
                        Assignment a=new Assignment(this);
                        a.indetifier = this.indetifier;
                        a.wasIndetifier = true;
                        string ass = a.go();
                        if (ass != null)
                        {
                            s += ass;
                        }

                    }
                    break;
                case "BinOperEqual":
                    {
                        if (wasIndetifier)
                        {
                            s += "\tmov " + indetifier.Data + ",ax";
                        }
                        else
                        {
                            addError(new IndetifierMissedError(), 0);
                        }
                        Lexems.Lexema lt = null;
                        while ((lt = getToken()) != null && lt.GetType().Name != "Endl")
                        {
                            this.lexems.Add(lt);
                        }
                        if (lt == null&&!wasIndetifier)
                        {
                            addError(new EndlMissedError(), 0);
                        }
                        Expression e=new Expression(this);
                        string result = e.go();
                        if (result != null)
                        {
                            s = result + "\tmov ax," + e.result + "\n" + s;
                        }
                    }
                    break;
                case "For":

                        if (wasIndetifier)
                        {
                            addError(new UnexpectedIndefier(this.indetifier.Data), 0);
                        }

                    return new ForTo(this.parent).go();
               /* case "Print":

                        if (wasIndetifier)
                        {
                            addError(new UnexpectedIndefier(this.indetifier.Data), 0);
                        }

                        return new Print(this.parent).go();
                 */
                default:
                    {
                        if (wasIndetifier)
                        {
                            this.lexems.Insert(0, indetifier);
                        }
                        Lexems.Lexema lt = null;
                        while ((lt = getToken()) != null && lt.GetType().Name != "Endl")
                        {
                            this.lexems.Add(lt);
                        }
                        if (lt == null)
                        {
                            addError(new EndlMissedError(), 0);
                        }

                        Expression e = new Expression(this);
                        string result = e.go();
                        if (result != null)
                        {
                            s = result;
                        }
                    }
                    break;

            }

            return s;
        }