Exemple #1
0
        public Expr Parse(TokenStream stream)
        {
            TokenType nextTokenType = stream.Peek().Type;

            // Variable declaration expression.
            if (TokenIdentifier.IsType(nextTokenType))
            {
                return(new VarDeclareExprParser().Parse(stream));
            }
            // Numeric expression.
            else if (TokenIdentifier.IsNumeric(nextTokenType))
            {
                return(new NumericExprParser().Parse(stream));
            }
            // Identifier expression.
            else if (nextTokenType == TokenType.Identifier)
            {
                return(new IdentifierExprParser().Parse(stream));
            }
            // Parentheses expression.
            else if (nextTokenType == TokenType.SymbolParenthesesL)
            {
                return(new ParenthesesExprParser().Parse(stream));
            }

            // At this point, return null.
            return(null);
        }
Exemple #2
0
        public Expr Parse(ParserContext context)
        {
            // Capture current token type.
            TokenType currentTokenType = context.Stream.Current.Type;

            // Pipe operation.
            if (currentTokenType == TokenType.SymbolColon)
            {
                return(new PipeParser().Parse(context));
            }
            // Numeric expression.
            else if (TokenIdentifier.IsNumeric(currentTokenType))
            {
                return(new NumericExprParser().Parse(context));
            }
            // Identifier expression.
            else if (currentTokenType == TokenType.Identifier)
            {
                return(new IdentifierExprParser().Parse(context));
            }
            // Parentheses expression.
            else if (currentTokenType == TokenType.SymbolParenthesesL)
            {
                return(new ParenthesesExprParser().Parse(context));
            }
            // String expression.
            else if (currentTokenType == TokenType.LiteralString)
            {
                return(new StringExprParser().Parse(context));
            }
            // Boolean expression.
            else if (TokenIdentifier.IsBoolean(currentTokenType))
            {
                return(new BooleanExprParser().Parse(context));
            }
            // Struct expression.
            else if (currentTokenType == TokenType.KeywordNew)
            {
                return(new StructExprParser().Parse(context));
            }
            // Array expression.
            else if (currentTokenType == TokenType.SymbolBracketL)
            {
                // TODO: Type is hard-coded for debugging purposes, not yet supported auto-type (might need infering?).
                return(new ArrayExprParser(PrimitiveTypeFactory.Int32()).Parse(context));
            }

            // At this point, return null.
            return(null);
        }
        public NumericExpr Parse(TokenStream stream)
        {
            // Consume numeric literal token.
            Token token = stream.Next();

            // Ensure captured token is numeric.
            if (!TokenIdentifier.IsNumeric(token))
            {
                throw new Exception($"Expected token to be classified as numeric, but got '{token.Type}'");
            }

            // Create the numeric expression entity.
            var numericExpr = new NumericExpr(token.Type, Resolvers.TypeFromToken(token), token.Value);

            // Return the numeric expression entity.
            return(numericExpr);
        }
Exemple #4
0
        public NumericExpr Parse(ParserContext context)
        {
            // Consume numeric literal token.
            Token token = context.Stream.Current;

            // Skip numeric literal token.
            context.Stream.Skip();

            // Ensure captured token is numeric.
            if (!TokenIdentifier.IsNumeric(token))
            {
                throw new Exception($"Expected token to be classified as numeric, but got '{token.Type}'");
            }

            // Create the numeric expression entity.
            NumericExpr numericExpr = new NumericExpr(token.Type, Resolvers.PrimitiveType(token), token.Value);

            // Return the numeric expression entity.
            return(numericExpr);
        }