コード例 #1
0
        private BaseAst GetAstNode(TokenModel token)
        {
            switch (token.Token)
            {
            case TokenTypes.FunctionRW:
                return(ConvertTo <FunctionAst>(token, AstNodeTypes.Function));

            case TokenTypes.IfRW:
                return(ConvertTo <IfAst>(token, AstNodeTypes.If));

            case TokenTypes.ForRW:
                return(ConvertTo <ForAst>(token, AstNodeTypes.For));

            case TokenTypes.WhileRW:
                return(ConvertTo <WhileAst>(token, AstNodeTypes.While));

            case TokenTypes.GotoRW:
                return(ConvertTo <GotoAst>(token, AstNodeTypes.Goto));

            case TokenTypes.ReturnRW:
                return(ConvertTo <BaseAst>(token, AstNodeTypes.Return));

            case TokenTypes.Number:
                NumberAst number = ConvertTo <NumberAst>(token, AstNodeTypes.Number);
                int       num;
                if (!TryParseNumber(number.TokenText, out num))
                {
                    return(BaseAst.GetErrorAstNode(string.Format("Nespravny format cisla, radek {0}, sloupec {1}", number.TokenStartLine, number.TokenStartColumn)));
                }
                number.Number = num;
                return(number);

            case TokenTypes.BraceLeft:
                return(ConvertTo <BlockAst>(token, AstNodeTypes.Block));

            case TokenTypes.Equals:
            case TokenTypes.Plus:
            case TokenTypes.Minus:
            case TokenTypes.Multi:
            case TokenTypes.PlusPlus:
            case TokenTypes.MinusMinus:
            case TokenTypes.EqualsEquals:
            case TokenTypes.Less:
            case TokenTypes.More:
            case TokenTypes.LessOrEquals:
            case TokenTypes.MoreOrEquals:
            case TokenTypes.NotEquals:
            case TokenTypes.Or:
            case TokenTypes.And:
            case TokenTypes.Neg:
                OperatorAst op = ConvertTo <OperatorAst>(token, AstNodeTypes.Operator);
                SetOperatorPriority(op);
                return(op);

            case TokenTypes.Error:
                return(ConvertTo <BaseAst>(token, AstNodeTypes.None));

            default:
                return(ConvertTo <BaseAst>(token, AstNodeTypes.Variable));
            }
        }
コード例 #2
0
 private void SetNumber(NumberAst token)
 {
 }