Exemplo n.º 1
0
        private void LabelAssign()
        {
            if (Tokens.Count < 3)
            {
                return;
            }


            bool  isSuccess = false;
            Token t1        = Tokens.Pop();
            Token t2        = Tokens.Pop();
            Token t3        = Tokens.Pop();

            if (t1.Type == TokenType.Register &&
                t2.Type == TokenType.Operator &&
                t2.Value == ":=" &&
                t3.Type == TokenType.String)
            {
                if (Tokens.Peek().Type != TokenType.Semicolon)
                {
                    Error("No semicolon in operation", t3);
                }
                else
                {
                    Tokens.Pop();

                    byte          r1      = Convert.ToByte(t1.Value);
                    BinaryCommand prevCmd = new AssignConstCommand(0, r1);
                    Program.Add(prevCmd);
                    BinaryCommand cmd = new AddNextConstCommand(r1, r1);
                    Program.Add(cmd);

                    Label        label   = Mapper.Labels.Contains(t3.Value) ? (Label)Mapper.Labels[t3.Value] : null;
                    LabelAddress address = new LabelAddress(label);
                    if (label == null)
                    {
                        Mapper.Unreferenced.Add(new KeyValuePair <string, LabelAddress>(t3.Value, address));
                    }
                    Program.Add(address);

                    isSuccess = true;
                }
            }

            if (isSuccess)
            {
                return;
            }

            Tokens.Push(t3);
            Tokens.Push(t2);
            Tokens.Push(t1);
        }
Exemplo n.º 2
0
        private void ConstantAssign()
        {
            if (Tokens.Count < 3)
            {
                return;
            }


            bool  isSuccess = false;
            Token t1        = Tokens.Pop();
            Token t2        = Tokens.Pop();
            Token t3        = Tokens.Pop();


            if (t1.Type == TokenType.Register &&
                t2.Type == TokenType.Operator &&
                t2.Value == ":=" &&
                t3.Type == TokenType.Literal)
            {
                if (Tokens.Peek().Type != TokenType.Semicolon)
                {
                    Error("No semicolon in operation", t3);
                }
                else
                {
                    Tokens.Pop();
                    byte          r2  = Convert.ToByte(t1.Value);
                    byte          r1  = Convert.ToByte(t3.Value);
                    BinaryCommand cmd = new AssignConstCommand(r1, r2);
                    Program.Add(cmd);
                    isSuccess = true;
                }
            }


            if (isSuccess)
            {
                return;
            }

            Tokens.Push(t3);
            Tokens.Push(t2);
            Tokens.Push(t1);
        }