public void TestTokenProperties()
    {
        IntegerToken            lhs    = new IntegerToken(2);
        ReturnAndIncrementToken result = new ReturnAndIncrementToken(0, lhs);

        Assert.AreEqual(lhs, result.Lhs);
    }
Beispiel #2
0
 public override string ToArmText()
 {
     return(this.Token switch
     {
         IntegerToken integerToken => integerToken.Value.ToString(),
         _ => throw new NotImplementedException(),
     });
Beispiel #3
0
        protected void AddToken(int lineNo, Match matcher)
        {
            string id       = matcher.Groups["id"].Value;
            string comments = matcher.Groups["comments"].Value;
            string integer  = matcher.Groups["integer"].Value;
            string str      = matcher.Groups["string"].Value;

            if (id != "")
            {
                if (comments == "")
                {
                    Token token;
                    if (integer != "")
                    {
                        token = new IntegerToken(lineNo, int.Parse(integer));
                    }
                    else if (str != "")
                    {
                        token = new StrToken(lineNo, ToStringLiteral(str));
                    }
                    else
                    {
                        token = new IdToken(lineNo, id);
                    }
                    queue.Enqueue(token);
                }
            }
        }
        public bool TryScan(Pointer pointer, out Token token)
        {
            token = null;

            if (pointer.Current != PLUS && pointer.Current != MINUS && !IsNumeric(pointer.Current))
            {
                return(false);
            }

            if ((pointer.Current == PLUS || pointer.Current == MINUS) && !IsNumeric(pointer.Next))
            {
                return(false);
            }

            string numericString = ScanNumericString(pointer, out bool isFloat);

            if (isFloat)
            {
                token = new RealToken(float.Parse(numericString));
            }
            else
            {
                token = new IntegerToken(int.Parse(numericString));
            }

            return(true);
        }
Beispiel #5
0
    public void TestTokenProperties()
    {
        IntegerToken rhs    = new IntegerToken(2);
        ExistsToken  result = new ExistsToken(0, rhs);

        Assert.AreEqual(rhs, result.Rhs);
    }
Beispiel #6
0
    public void TestTokenProperties()
    {
        IntegerToken            rhs    = new IntegerToken(2);
        IncrementAndReturnToken result = new IncrementAndReturnToken(0, rhs);

        Assert.AreEqual(rhs, result.Rhs);
    }
Beispiel #7
0
    public void TestTokenProperties()
    {
        IntegerToken    rhs    = new IntegerToken(2);
        ComplementToken result = new ComplementToken(0, rhs);

        Assert.AreEqual(rhs, result.Rhs);
    }
Beispiel #8
0
    public void TestTokenProperties()
    {
        IntegerToken    rhs    = new IntegerToken(2);
        IsNotEmptyToken result = new IsNotEmptyToken(0, rhs);

        Assert.AreEqual(rhs, result.Rhs);
    }
Beispiel #9
0
    public void TestTokenProperties()
    {
        IntegerToken        lhs    = new IntegerToken(1);
        IdentifierToken     rhs    = new IdentifierToken("blah");
        PropertyAccessToken result = new PropertyAccessToken(0, lhs, rhs);

        Assert.AreEqual(lhs, result.Host);
        Assert.AreEqual(rhs, result.Property);
    }
Beispiel #10
0
    public void TestTokenProperties()
    {
        IntegerToken lhs    = new IntegerToken(1);
        IntegerToken rhs    = new IntegerToken(2);
        OrToken      result = new OrToken(0, lhs, rhs);

        Assert.AreEqual(lhs, result.Lhs);
        Assert.AreEqual(rhs, result.Rhs);
    }
    public void TestTokenProperties()
    {
        BooleanToken             test          = new BooleanToken(true);
        IntegerToken             resultIfTrue  = new IntegerToken(1);
        IntegerToken             resultIfFalse = new IntegerToken(2);
        ConditionalOperatorToken result        = new ConditionalOperatorToken(0, test, resultIfTrue, resultIfFalse);

        Assert.AreEqual(test, result.Test);
        Assert.AreEqual(resultIfTrue, result.ResultIfTrue);
        Assert.AreEqual(resultIfFalse, result.ResultIfFalse);
    }
Beispiel #12
0
    public override bool Equals(object other, bool includeChildren)
    {
        if (!base.Equals(other, includeChildren))
        {
            return(false);
        }

        IntegerToken integerToken = (IntegerToken)other;

        return(Radix == integerToken.Radix);
    }
Beispiel #13
0
 public MemoryImmediate(
     OperatorToken leftBracket,
     IntegerToken immediateAddress,
     OperatorToken rightBracket)
     : base(
         OperandType.MemoryImmediate,
         leftBracket,
         immediateAddress,
         rightBracket)
 {
     ImmediateAddress = immediateAddress;
 }
        public static ArmExpressionAst ParseArmExpressionAst(TokenStream stream)
        {
            var peek = stream.Peek();

            return(peek switch
            {
                OpenParenToken _ => ArmExpressionParser.ParseArmSubexpressionAst(stream),
                IdentifierToken _ => ArmExpressionParser.ParseDottedNotationExpressionAst(stream),
                StringLiteralToken _ => ArmExpressionParser.ParseArmStringLiteralExpressionAst(stream),
                IntegerToken _ => ArmExpressionParser.ParseArmNumericLiteralExpressionAst(stream),
                _ => throw new InvalidOperationException(),
            });
Beispiel #15
0
    public bool Parse(ExpressionCompiler compiler)
    {
        int  i     = compiler.Pos;
        int  start = -1;
        char ch;

        while (i < compiler.Expression.Length)
        {
            ch = compiler.Expression[i++];

            if (start == -1)
            {
                if (char.IsWhiteSpace(ch))
                {
                    continue;
                }
                else if (char.IsDigit(ch))
                {
                    start = i - 1;
                }
                else
                {
                    return(false);
                }
            }
            else if (!char.IsDigit(ch))
            {
                --i;
                break;
            }
        }

        if (start != -1)
        {
            string s = new string(compiler.Expression, start, i - start);
            s = s.Trim();

            try {
                IntegerToken token = new IntegerToken(int.Parse(s), compiler.Pos);
                compiler.Parent.AddChild(token);
                compiler.Pos = i;

                return(true);
            } catch (System.FormatException e) {
                throw new ParserException("integer", compiler.Pos, "Unable to parse as int: " + s, e);
            }
        }

        return(false);
    }
Beispiel #16
0
 public BitnessDirectiveSymbol(
     DirectiveToken directive,
     IntegerToken bitness)
 {
     symbols.Add(directive);
     symbols.Add(bitness);
     Directive = directive.DirectiveType switch
     {
         DirectiveType.OperandSize => BitnessDirectiveType.Data,
         DirectiveType.AddressSize => BitnessDirectiveType.Address,
         _ => throw new InvalidOperationException($"Wrong directive type: {directive.DirectiveType}"),
     };
     Bitness = bitness.UnsignedValue switch
     {
         8 => DataWidth.Byte,
         16 => DataWidth.Word,
         32 => DataWidth.Dword,
         64 => DataWidth.Qword,
         _ => throw new InvalidOperationException($"Invalid bitness: {bitness.UnsignedValue}"),
     };
 }
Beispiel #17
0
 public static bool TryParseNumberToken(this string value, out Token numberToken)
 {
     if (value.Contains("."))
     {
         var splitValue = value.Split('.', 'e', 'E');
         if (splitValue.Length > 1 && splitValue[1].Length > 6)
         {
             if (!double.TryParse(value, out var d))
             {
                 numberToken = null;
                 return(false);
             }
             numberToken = new DoubleToken(d);
             return(true);
         }
         if (!float.TryParse(value, out var f))
         {
             numberToken = null;
             return(false);
         }
         numberToken = new FloatToken(f);
         return(true);
     }
     if (!long.TryParse(value, out var l))
     {
         numberToken = null;
         return(false);
     }
     if (l >= int.MinValue && l <= int.MaxValue)
     {
         numberToken = new IntegerToken((int)l);
         return(true);
     }
     numberToken = new LongToken(l);
     return(true);
 }
Beispiel #18
0
 private Expression BuildInteger(IntegerToken iToken)
 {
     return(new Integer(iToken.Value));
 }
Beispiel #19
0
    public void TestSimpleInteger()
    {
        ValueToken result = new IntegerToken(123);

        Assert.AreEqual(123, result.Value);
    }
Beispiel #20
0
        private Expression Factor()
        {
            Expression expr = null;

            switch (look.Tag)
            {
            case '(':
                Move();
                expr = Bool();
                Match(')');
                return(expr);

            case Tags.NUMBER:
                IntegerToken token = (IntegerToken)look;
                expr = new IntConstantExpression(token.Value);
                Move();
                return(expr);

            case Tags.REAL:
                RealToken realToken = (RealToken)look;
                expr = new FloatConstantExpression(realToken.Value);
                Move();
                return(expr);

            case Tags.TRUE:
                Move();
                return(BoolConstantExpression.True);;

            case Tags.FALSE:
                Move();
                return(BoolConstantExpression.False);

            case Tags.ID:
                Move();

                if (look.Tag == '(')
                {
                    return(FuncCallExpression());
                }
                else
                {
                    VariableUseExpression varUseExpr = VariableUseExpression();
                    if (look.Tag == Tags.INCR)
                    {
                        Expression incrExpr = UnaryArithmeticExpression.CreatePostIncrement(varUseExpr);
                        Move();
                        return(incrExpr);
                    }
                    if (look.Tag == Tags.DECR)
                    {
                        Expression decrExpr = UnaryArithmeticExpression.CreatePostDecrement(varUseExpr);
                        Move();
                        return(decrExpr);
                    }
                    if (look.Tag == '=')
                    {
                        Move();
                        return(new VariableAssignExpression(varUseExpr, Bool()));
                    }

                    return(varUseExpr);
                }
            }

            Error("Syntax error");
            return(null);
        }
Beispiel #21
0
 public Integer(IntegerToken t, SrcLoc location = null)
     :
     base(location)
 {
     Value = t;
 }
Beispiel #22
0
 private object IntegerValue(IntegerToken integerToken)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public IntegerConstExpression(IntegerToken value)
 {
     Value = value;
 }
Beispiel #24
0
 /// <summary>
 /// </summary>
 /// <param name="token"></param>
 public ArmNumericLiteralExpressionAst(IntegerToken token)
 {
     this.Token = token ?? throw new ArgumentNullException(nameof(token));
 }
Beispiel #25
0
    public bool Parse(ExpressionCompiler compiler)
    {
        int  i     = compiler.Pos;
        int  start = -1;
        char ch;

        while (i < compiler.Expression.Length)
        {
            ch = compiler.Expression[i++];

            if (start == -1)
            {
                if (char.IsWhiteSpace(ch))
                {
                    continue;
                }
                else if (ch == '0')
                {
                    if (i + 1 >= compiler.Expression.Length)
                    {
                        return(false);
                    }

                    char ch2 = compiler.Expression[i++];
                    char ch3 = compiler.Expression[i];

                    if (ch2 != 'b' || (ch3 != '0' && ch3 != '1'))
                    {
                        return(false);
                    }

                    start = i;
                }
                else
                {
                    return(false);
                }
            }
            else if (ch != '0' && ch != '1')
            {
                --i;
                break;
            }
        }

        if (start != -1)
        {
            string s = new string(compiler.Expression, start, i - start);
            s = s.Trim();

            try {
                int          value = Convert.ToInt32(s, 2);
                IntegerToken token = new IntegerToken(value, compiler.Pos, 2);

                compiler.Parent.AddChild(token);
                compiler.Pos = i;

                return(true);
            } catch (System.FormatException e) {
                throw new ParserException("binaryInteger", compiler.Pos, "Unable to parse as binary int: " + s, e);
            }
        }

        return(false);
    }
Beispiel #26
0
 public ANodeIntegerLiteral(IntegerToken itok)
     : base(itok.Location)
 {
     Integer = itok;
 }
Beispiel #27
0
        public void ReadNextToken()
        {
            SkipWhiteSpace();

            switch (_char)
            {
            case '\0':
                Token = EofToken.Instance;
                break;

            case '/':
                ReadNextCharacter();

                if (_char == '/')
                {
                    ReadNextCharacter();
                    Token = DoubleSlashToken.Instance;
                }
                else
                {
                    Token = SingleSlashToken.Instance;
                }

                break;

            case '[':
                ReadNextCharacter();
                Token = LeftBracketToken.Instance;
                break;

            case ']':
                ReadNextCharacter();
                Token = RightBracketToken.Instance;
                break;

            case '=':
                ReadNextCharacter();
                Token = EqualToken.Instance;
                break;

            case ',':
                ReadNextCharacter();
                Token = CommaToken.Instance;
                break;

            case '\"':
                ReadNextCharacter();
                Token = new StringToken(ReadNextString());
                break;

            case 'M':
            case 'm':
                ReadNextKeyword("MESSAGE", () => MessageToken.Instance);
                break;

            case 'W':
            case 'w':
                ReadNextKeyword("WARNING", () => WarningToken.Instance);
                break;

            case 'E':
            case 'e':
                ReadNextKeyword("ERROR", () => ErrorToken.Instance);
                break;

            case 'P':
            case 'p':
                ReadNextCharacter();

                if (char.ToUpper(_char) == 'R')
                {
                    ReadNextKeyword("ROJECT", () => ProjectToken.Instance);
                }
                else if (char.ToUpper(_char) == 'A')
                {
                    ReadNextKeyword("ATH", () => PathToken.Instance);
                }
                else
                {
                    throw new ScanException(Expression);
                }

                break;

            case 'T':
            case 't':
                ReadNextCharacter();

                if (char.ToUpper(_char) != 'A')
                {
                    throw new ScanException(Expression);
                }

                ReadNextCharacter();

                if (char.ToUpper(_char) == 'R')
                {
                    ReadNextKeyword("RGET", () => TargetToken.Instance);
                }
                else if (char.ToUpper(_char) == 'S')
                {
                    ReadNextKeyword("SK", () => TaskToken.Instance);
                }
                else
                {
                    throw new ScanException(Expression);
                }

                break;

            case 'I':
            case 'i':
                ReadNextKeyword("ID", () => IdToken.Instance);
                break;

            case 'N':
            case 'n':
                ReadNextKeyword("NAME", () => NameToken.Instance);
                break;

            default:
                if (char.IsDigit(_char))
                {
                    Token = new IntegerToken(ReadNextInteger());
                    break;
                }

                throw new ScanException(Expression);
            }
        }
Beispiel #28
0
 public IntegerConstantAstNode(IntegerToken value)
     : base(value.Line, value.Column)
 {
     Value = value;
 }
Beispiel #29
0
 public IntegerNode(IntegerToken token)
 {
     Contract.Requires <ArgumentNullException>(token != null);
     this.token = token;
 }
Beispiel #30
0
 public ImmediateOperand(IntegerToken integer)
     : base(OperandType.Immediate, integer)
 {
 }