Esempio n. 1
0
        void label(Tok s)
        {
            Var    var    = new Var();
            String label1 = "L@@" + s.getValue();

            io.Message(s + "[Label]");
            var.setName(label1);
            var.setType(Var.VAR_LABEL);
            try
            {
                currenttree.add(var);
            }
            catch
            {
                io.Abort("PL0111: invalid label declaration");
            }
            if (tok.getId() != Tok.TOK_1_REL)
            {
                io.Abort("PL0112: ':' expected");
            }
            io.Message(tok + "[:]");
            last_label = s.getValue();
            tok.scan();
        }
Esempio n. 2
0
File: syn.cs Progetto: master/plil
        void label(Tok s)
        {
            Var var = new Var();
            String label1 = "L@@"+s.getValue();

            io.Message(s+"[Label]");
            var.setName(label1);
            var.setType(Var.VAR_LABEL);
            try
            {
                currenttree.add(var);
            }
            catch
            {
                io.Abort("PL0111: invalid label declaration");
            }
            if (tok.getId() != Tok.TOK_1_REL) io.Abort("PL0112: ':' expected");
            io.Message(tok+"[:]");
            last_label = s.getValue();
            tok.scan();
        }
Esempio n. 3
0
File: syn.cs Progetto: master/plil
        void ident_stmt(VarList curtree)
        {
            Tok s = new Tok(null);
            VarList vars = new VarList();
            Var V;
            int gotType = Tok.TOK_BINARY;

            s.setValue(tok.getValue());
            s.setId(tok.getId());
            tok.scan();

            switch (tok.getId()) {
            case Tok.TOK_1_EQUALS:
                if (curtree.FindByName(s.getValue()) == null) io.Abort("PL0137: undeclared variable");
                V = new Var(); V.setName(s.getValue()); vars.add(V);
                io.Message(s+"[Variable]");
                io.Message(tok+"[Equals]");
                tok.scan();
                gotType = bool_expr(0);
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(0).getName()).getTypeId());
                null_stmt();
                break;
            case Tok.TOK_1_COMMA:
                io.Message(s+"[Variable]");
                if (curtree.FindByName(s.getValue()) == null) io.Abort("PL0137: undeclared variable");
                V = new Var(); V.setName(s.getValue()); vars.add(V);
                while (tok.getId() != Tok.TOK_1_EQUALS)	{
                    if (tok.getFirstChar() != ',') io.Abort("PL0138: ',' or '=' expected");
                    io.Message(tok+"[Comma]");
                    tok.scan();

                    if (tok.getId() != Tok.TOK_IDENT) io.Abort("PL0139: ident expected");
                    if (curtree.FindByName(tok.getValue()) == null) io.Abort("PL0137: undeclared variable");
                    V = new Var(); V.setName(tok.getValue()); vars.add(V);
                    io.Message(tok+"[Variable]");
                    tok.scan();
                }
                io.Message(tok+"[Assign]");
                tok.scan();
                gotType = bool_expr(0);
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(0).getName()).getTypeId());
                null_stmt();
                break;
            case Tok.TOK_1_REL:
                label(s);
                break;
            default:
                io.Abort("PL0140: not found expected token ':', ',' or '='");
                break;
            }

            for (int i = 0; i < vars.Length(); i ++) {
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(i).getName()).getTypeId());
                emit.Store(curtree.FindByName(vars.FindByIndex(i).getName()));
                if (i < vars.Length() -1)
                    emit.Load(curtree.FindByName(vars.FindByIndex(0).getName()));
            }
        }
Esempio n. 4
0
        int ident()
        {
            int Typecast = Tok.TOK_VOID;

            if (io.getNextChar() == '(')
            {
                io.Message(tok + "[Ident]");

                Var e = call_construct(tok.getValue());
                Typecast = e.getTypeId();

                if (Typecast == Tok.TOK_VOID)
                {
                    io.Abort("PL0147: using void function where expecting a value");
                }

                emit.Call(e);
                tok.scan();
            }
            else
            {
                if (currenttree.FindByName(tok.getValue()) == null)
                {
                    io.Abort("PL0105: undeclared variable");
                }

                Typecast = currenttree.FindByName(tok.getValue()).getTypeId();
                emit.Load(currenttree.FindByName(tok.getValue()));

                io.Message(tok + "[Ident]");
                tok.scan();
            }
            return(Typecast);
        }
Esempio n. 5
0
        void ident_stmt(VarList curtree)
        {
            Tok     s    = new Tok(null);
            VarList vars = new VarList();
            Var     V;
            int     gotType = Tok.TOK_BINARY;

            s.setValue(tok.getValue());
            s.setId(tok.getId());
            tok.scan();

            switch (tok.getId())
            {
            case Tok.TOK_1_EQUALS:
                if (curtree.FindByName(s.getValue()) == null)
                {
                    io.Abort("PL0137: undeclared variable");
                }
                V = new Var(); V.setName(s.getValue()); vars.add(V);
                io.Message(s + "[Variable]");
                io.Message(tok + "[Equals]");
                tok.scan();
                gotType = bool_expr(0);
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(0).getName()).getTypeId());
                null_stmt();
                break;

            case Tok.TOK_1_COMMA:
                io.Message(s + "[Variable]");
                if (curtree.FindByName(s.getValue()) == null)
                {
                    io.Abort("PL0137: undeclared variable");
                }
                V = new Var(); V.setName(s.getValue()); vars.add(V);
                while (tok.getId() != Tok.TOK_1_EQUALS)
                {
                    if (tok.getFirstChar() != ',')
                    {
                        io.Abort("PL0138: ',' or '=' expected");
                    }
                    io.Message(tok + "[Comma]");
                    tok.scan();

                    if (tok.getId() != Tok.TOK_IDENT)
                    {
                        io.Abort("PL0139: ident expected");
                    }
                    if (curtree.FindByName(tok.getValue()) == null)
                    {
                        io.Abort("PL0137: undeclared variable");
                    }
                    V = new Var(); V.setName(tok.getValue()); vars.add(V);
                    io.Message(tok + "[Variable]");
                    tok.scan();
                }
                io.Message(tok + "[Assign]");
                tok.scan();
                gotType = bool_expr(0);
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(0).getName()).getTypeId());
                null_stmt();
                break;

            case Tok.TOK_1_REL:
                label(s);
                break;

            default:
                io.Abort("PL0140: not found expected token ':', ',' or '='");
                break;
            }

            for (int i = 0; i < vars.Length(); i++)
            {
                typeCheckAssign(gotType, curtree.FindByName(vars.FindByIndex(i).getName()).getTypeId());
                emit.Store(curtree.FindByName(vars.FindByIndex(i).getName()));
                if (i < vars.Length() - 1)
                {
                    emit.Load(curtree.FindByName(vars.FindByIndex(0).getName()));
                }
            }
        }