Example #1
0
        private OperandAST parseOperand()
        {
            OperandFlag flag = OperandFlag.None;
            OperandType type = OperandType.Standard;

            // Look for <Flags>:
            var firstPeek  = lookAhead(0);
            var secondPeek = lookAhead(1);

            // Found flags
            if (isFlag(firstPeek) && secondPeek == ':')
            {
                // Parse and eat the flag
                flag = parseFlag(eatToken());

                // Eat :
                _ = eatToken();
            }

            // Look for <type>
            firstPeek = lookAhead(0);
            if (isType(firstPeek))
            {
                // Parse and eat the type
                type = parseType(eatToken());
            }

            firstPeek  = lookAhead(0);
            secondPeek = lookAhead(1);

            // It's a memory addresss
            if (firstPeek == '0' && secondPeek == 'x')
            {
                MemoryAddressAST memoryOperand = parseMemoryAddress();
                if (memoryOperand != null)
                {
                    memoryOperand.Flag = flag;
                    memoryOperand.Type = type;
                    return(memoryOperand);
                }
            }
            // Else it's a value
            else if (char.IsNumber(firstPeek))
            {
                return(new NumberAST
                {
                    Flag = flag,
                    Type = type,
                    Value = parseNumber()
                });
            }
            else
            {
                throw new ParserException($"Invalid token at column {_index}");
            }

            return(null);
        }
        public void ShouldParseOperandFlags(string input, OperandFlag operandFlag)
        {
            Parser parser = new Parser();
            var    tree   = parser.Parse(input);

            var condition = tree.Core.Conditions[0];

            Assert.Equal(ConditionCompare.Equals, condition.CompareOperator);
            Assert.Equal(0, condition.HitCount);
            Assert.IsType <MemoryAddressAST>(condition.Left);
            Assert.IsType <NumberAST>(condition.Right);

            var left  = condition.Left as MemoryAddressAST;
            var right = condition.Right as NumberAST;

            Assert.Equal(0x1234, left.Address);
            Assert.Equal(MemoryAddressKind.Int8, left.Kind);
            Assert.Equal(OperandType.Standard, left.Type);
            Assert.Equal(operandFlag, left.Flag);

            Assert.Equal(8, right.Value);
        }
Example #3
0
 public itemplate( OCE aOpCode, int aOperandCount, ulong[] aOperands, int OpCodeAdress, OperandFlag aFlag1, OperandFlag aFlag2, OperandFlag aFlag3, OperandFlag aFlag4, OperandFlag aFlag5 )
 {
     opcode = aOpCode;
     operands = aOperandCount;
     opd = aOperands;
     code = OpCodeAdress;
     flag1 = aFlag1;
     flag2 = aFlag2;
     flag3 = aFlag3;
     flag4 = aFlag4;
     flag5 = aFlag5;
 }
Example #4
0
 public itemplate( OCE aOpCode, int aOperandCount, ulong[] aOperands, int OpCodeAdress, OperandFlag aFlag1, OperandFlag aFlag2 )
 {
     opcode = aOpCode;
     operands = aOperandCount;
     opd = aOperands;
     code = OpCodeAdress;
     flag1 = aFlag1;
     flag2 = aFlag2;
     flag3 = OF.NONE;
     flag4 = OF.NONE;
     flag5 = OF.NONE;
 }