Exemplo n.º 1
0
Arquivo: cli.cs Projeto: master/plil
        public static void Main()
        {
            String[] args = Environment.GetCommandLineArgs();
            CmdIo source = new CmdIo();
            try {
                source = new CmdIo(args);
                Tok tokenizer = new Tok(source);
                Lib funclibrary = new Lib();

                Parser parser = new Parser(source, tokenizer, funclibrary);
                parser.parse_and_compile();
                source.Finish();
            } catch {
                source.Message("plil: compiler error.");
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
Arquivo: syn.cs Projeto: 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();
        }
Exemplo n.º 4
0
Arquivo: syn.cs Projeto: 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()));
            }
        }
Exemplo n.º 5
0
Arquivo: syn.cs Projeto: master/plil
 public Parser(Io i, Tok t, Lib l)
 {
     io = i;
     tok = t;
     lib = l;
 }
Exemplo n.º 6
0
 public Parser(Io i, Tok t, Lib l)
 {
     io  = i;
     tok = t;
     lib = l;
 }
Exemplo n.º 7
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()));
                }
            }
        }