Esempio n. 1
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);
        }
Esempio n. 2
0
        public BooleanExpr Parse(ParserContext context)
        {
            // Consume boolean literal token.
            Token token = context.Stream.Current;

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

            // Ensure captured token is a boolean.
            if (!TokenIdentifier.IsBoolean(token.Type))
            {
                throw new Exception($"Expected token type to be boolean, but got '{token.Type}'");
            }

            // Create the boolean expression entity.
            BooleanExpr booleanExpr = new BooleanExpr(token.Type, token.Value);

            // Return the boolean expression entity.
            return(booleanExpr);
        }