示例#1
0
        public void parse_and_compile()
        {
            prolog();

            tree = new VarList();

            IDictionaryEnumerator libEnum = lib.get_enum();

            while (libEnum.MoveNext())
            {
                Var     procvar = new Var();
                LibFunc lfunc   = (LibFunc)libEnum.Value;

                procvar.setName(lfunc.nameShort);
                procvar.setType(Var.VAR_BLOCK);
                procvar.setTypeId(Tok.TOK_VOID);
                procvar.nodes = new VarList();

                for (int i = 0; i < lfunc.typeParams.Count; i++)
                {
                    Var param = new Var();
                    param.setName("PAR_" + i);
                    param.setType(Var.VAR_PARAM);
                    param.setTypeId((int)lfunc.typeParams[i]);
                    procvar.nodes.add(param);
                }

                tree.add(procvar);
            }

            io.ReadChar();
            tok.scan();
            declarations(tree);
            while (tok.NotEOF())
            {
                stmt(tree, null, null);
            }
            io.Message("compiled successfuly");
            io.TreeDraw(tree);
            epilog();
        }
示例#2
0
文件: syn.cs 项目: master/plil
        public void parse_and_compile()
        {
            prolog();

            tree = new VarList();

            IDictionaryEnumerator libEnum = lib.get_enum();

            while ( libEnum.MoveNext() ) {
                Var procvar = new Var();
                LibFunc lfunc = (LibFunc)libEnum.Value;

                procvar.setName(lfunc.nameShort);
                procvar.setType(Var.VAR_BLOCK);
                procvar.setTypeId(Tok.TOK_VOID);
                procvar.nodes = new VarList();

                for (int i = 0; i < lfunc.typeParams.Count; i++ ) {
                    Var param = new Var();
                    param.setName("PAR_"+i);
                    param.setType(Var.VAR_PARAM);
                    param.setTypeId((int)lfunc.typeParams[i]);
                    procvar.nodes.add(param);
                }

                tree.add(procvar);
            }

            io.ReadChar();
            tok.scan();
            declarations(tree);
            while (tok.NotEOF())
            {
                stmt(tree, null, null);
            }
            io.Message("compiled successfuly");
            io.TreeDraw(tree);
            epilog();
        }
示例#3
0
文件: syn.cs 项目: master/plil
        void proc_decl(VarList curtree, String label)
        {
            Var procvar = new Var();
            procvar.setName(label);
            procvar.setType(Var.VAR_BLOCK);
            procvar.setTypeId(Tok.TOK_VOID);

            if (label == null) io.Abort("PL0116: PROC declaration needs LABEL");
            io.Message(tok+"[PROC]");

            tok.scan();
            procvar.nodes = new VarList();

            if (tok.getId() == Tok.TOK_1_LBRACKET) {
                param(procvar.nodes);
                procvar.setNodesType(Var.VAR_PARAM);
            }

            switch (tok.getId()) {
            case Tok.TOK_RETURNS:
                io.Message(tok+"[RETURNS]");
                tok.scan();
                if (tok.getId() != Tok.TOK_1_LBRACKET)	io.Abort("PL0104: ')' expected.");
                io.Message(tok+"[(]");
                tok.scan();
                switch (tok.getId()) {
                    case Tok.TOK_FIXED:
                    case Tok.TOK_FLOAT:
                    case Tok.TOK_COMPLEX:
                    case Tok.TOK_REAL:
                    case Tok.TOK_BINARY:
                    case Tok.TOK_DECIMAL:
                        io.Message(tok+"[Type]");
                        procvar.setTypeId(tok.getId());
                        break;
                    default:
                        io.Abort("PL0115: type specifier expected");
                        break;
                }
                tok.scan();
                if (tok.getId() != Tok.TOK_1_RBRACKET) io.Abort("PL0114: ')' expected");
                io.Message(tok+"[)]");
                tok.scan();
                break;
            case Tok.TOK_RECURSIVE:
                io.Message(tok+"[RECURSIVE]");
                if (label.ToUpper() == "MAIN") io.Abort("PL0146: MAIN can not be RECURSIVE");
                tok.scan();
                break;

            }

            null_stmt();

            emit.FuncBegin(procvar);

            declarations(procvar.nodes);

            VarList prms = procvar.getParams();
            if (prms != null)
                for (int i = 0; i < prms.Length(); i++)
                    if (prms.FindByIndex(i).getTypeId() == 0)
                        io.Abort("PL0117: undeclared parameter");

            if (procvar.getLocals() != null) {
                emit.LocalVars(procvar.getLocals());
            }

            try
            {
                curtree.add(procvar);
            }
            catch
            {
                io.Abort("PL0120: invalid procedure declaration");
            }

            do {
                stmt(procvar.nodes, label, null);
            } while (tok.getId() != Tok.TOK_END);

            if (tok.getId() != Tok.TOK_END) io.Abort("PL0118: END expected");
            io.Message(tok+"[END]");
            tok.scan();

            if (tok.getValue() != label) io.Abort("PL0119: unclosed PROC");
            io.Message(tok+"[Label]");

            tok.scan();

            emit.Ret();
            emit.FuncEnd();

            if (io.getGenList()) emit.LIST();
            emit.IL();

            emit.Finish();
        }
示例#4
0
        void proc_decl(VarList curtree, String label)
        {
            Var procvar = new Var();

            procvar.setName(label);
            procvar.setType(Var.VAR_BLOCK);
            procvar.setTypeId(Tok.TOK_VOID);

            if (label == null)
            {
                io.Abort("PL0116: PROC declaration needs LABEL");
            }
            io.Message(tok + "[PROC]");

            tok.scan();
            procvar.nodes = new VarList();

            if (tok.getId() == Tok.TOK_1_LBRACKET)
            {
                param(procvar.nodes);
                procvar.setNodesType(Var.VAR_PARAM);
            }

            switch (tok.getId())
            {
            case Tok.TOK_RETURNS:
                io.Message(tok + "[RETURNS]");
                tok.scan();
                if (tok.getId() != Tok.TOK_1_LBRACKET)
                {
                    io.Abort("PL0104: ')' expected.");
                }
                io.Message(tok + "[(]");
                tok.scan();
                switch (tok.getId())
                {
                case Tok.TOK_FIXED:
                case Tok.TOK_FLOAT:
                case Tok.TOK_COMPLEX:
                case Tok.TOK_REAL:
                case Tok.TOK_BINARY:
                case Tok.TOK_DECIMAL:
                    io.Message(tok + "[Type]");
                    procvar.setTypeId(tok.getId());
                    break;

                default:
                    io.Abort("PL0115: type specifier expected");
                    break;
                }
                tok.scan();
                if (tok.getId() != Tok.TOK_1_RBRACKET)
                {
                    io.Abort("PL0114: ')' expected");
                }
                io.Message(tok + "[)]");
                tok.scan();
                break;

            case Tok.TOK_RECURSIVE:
                io.Message(tok + "[RECURSIVE]");
                if (label.ToUpper() == "MAIN")
                {
                    io.Abort("PL0146: MAIN can not be RECURSIVE");
                }
                tok.scan();
                break;
            }

            null_stmt();

            emit.FuncBegin(procvar);

            declarations(procvar.nodes);

            VarList prms = procvar.getParams();

            if (prms != null)
            {
                for (int i = 0; i < prms.Length(); i++)
                {
                    if (prms.FindByIndex(i).getTypeId() == 0)
                    {
                        io.Abort("PL0117: undeclared parameter");
                    }
                }
            }

            if (procvar.getLocals() != null)
            {
                emit.LocalVars(procvar.getLocals());
            }

            try
            {
                curtree.add(procvar);
            }
            catch
            {
                io.Abort("PL0120: invalid procedure declaration");
            }

            do
            {
                stmt(procvar.nodes, label, null);
            } while (tok.getId() != Tok.TOK_END);

            if (tok.getId() != Tok.TOK_END)
            {
                io.Abort("PL0118: END expected");
            }
            io.Message(tok + "[END]");
            tok.scan();

            if (tok.getValue() != label)
            {
                io.Abort("PL0119: unclosed PROC");
            }
            io.Message(tok + "[Label]");

            tok.scan();

            emit.Ret();
            emit.FuncEnd();

            if (io.getGenList())
            {
                emit.LIST();
            }
            emit.IL();

            emit.Finish();
        }