コード例 #1
0
        //---------------------
        // Парсер бинарных выражений
        //---------------------

        private static ASTNode MemberBinOperation()
        {
            ASTNode node = null;

            switch (curTok.token)
            {
            case Tokens.Token.ID:
                string nameID = curTok.subString;
                Point  point  = new Point(curTok.y, curTok.x);
                node = new IdentificatorAST(nameID, point);
                GetNextToken();
                if (curTok.token == Tokens.Token.BRACKET_L)
                {
                    return(new IdentificatorAST(nameID, point, new BracketsAST(ParseBrackets(true)), true));
                }
                //return new BracketsAST(node, ParseBrackets(true));
                return(node);

            case Tokens.Token.STRING:
                node = new StringAST(curTok.subString);
                break;

            case Tokens.Token.CHAR:
                node = new CharAST(curTok.subString, new Point(curTok.y, curTok.x));
                break;

            case Tokens.Token.PARENTHESIS_L:
                node = ParseParenthesis();
                break;

            case Tokens.Token.BOOL:
                node = new BoolAST(curTok.subString, null, new Point(curTok.y, curTok.x));
                break;

            case Tokens.Token.INT_VALUE:
            case Tokens.Token.DOUBLE_VALUE:
            case Tokens.Token.X16_VALUE:
            case Tokens.Token.X8_VALUE:
            case Tokens.Token.X2_VALUE:
                node = new NumAST(curTok.token, curTok.subString);
                break;

            default:
                ConsoleHelper.WriteErrorAST("Impossible token in this area", curTok.y, curTok.x);
                break;
            }
            GetNextToken();
            return(node);
        }
コード例 #2
0
        private ConfAST ProgramConfig(bool nested = false)
        {
            if (!nested)
            {
                Eat(TokenType.CONF);
            }
            StringToken idToken = Eat(TokenType.ID) as StringToken;
            WordAST     wordAST = new WordAST(idToken);
            AST         valueAST;

            if (currentToken.Type == TokenType.FROM)
            {
                Eat(TokenType.FROM);
                if (currentToken.Type == TokenType.TRUE || currentToken.Type == TokenType.FALSE)
                {
                    BoolToken valueToken = Eat(currentToken.Type) as BoolToken;
                    valueAST = new BoolAST(valueToken);
                }
                else if (currentToken.Type == TokenType.STRING)
                {
                    StringToken valueToken = Eat(TokenType.STRING) as StringToken;
                    valueAST = new StringAST(valueToken);
                }
                else
                {
                    valueAST = ValueExpr();
                }
                Eat(TokenType.SEMIC);
            }
            else if (currentToken.Type == TokenType.DOT)
            {
                Eat(TokenType.DOT);
                valueAST = ProgramConfig(true);
            }
            else
            {
                Eat(TokenType.COLON);
                valueAST = ConfList();
                Eat(TokenType.END);
            }
            return(new ConfAST(wordAST, valueAST, nested));
        }
コード例 #3
0
        private static ASTNode MemberBoolBinOperation(bool isAndOp = false)
        {
            GetNextToken();
            switch (curTok.token)
            {
            case Tokens.Token.BOOL:
                return(new BoolAST(curTok.subString, new Point(curTok.y, curTok.x)));

            case Tokens.Token.STRING:
            case Tokens.Token.CHAR:
            case Tokens.Token.INT_VALUE:
            case Tokens.Token.DOUBLE_VALUE:
            case Tokens.Token.X16_VALUE:
            case Tokens.Token.X8_VALUE:
            case Tokens.Token.X2_VALUE:
            case Tokens.Token.ID:
                ASTNode leftNode = MemberBinOperation();
                ASTNode leftNodeExp;

                if (curTok.token == Tokens.Token.OP)
                {
                    leftNodeExp = ParseBinaryOperation(leftNode);
                }
                else
                {
                    leftNodeExp = leftNode;
                }

                if (curTok.token == Tokens.Token.BOOL_OP)
                {
                    string op = curTok.subString;
                    GetNextToken();
                    ASTNode rightNodeExp = MemberBinOperation();
                    if (rightNodeExp == null)
                    {
                        ConsoleHelper.WriteErrorAST("Expected 'x'", curTok.y, curTok.x);
                    }
                    if (isAndOp)
                    {
                        ASTNode nodeExprLeft = new BinaryExprAST(op, leftNodeExp, rightNodeExp, new Point(curTok.y, curTok.x));
                        ASTNode boolNode     = new BoolAST(nodeExprLeft, new Point(curTok.y, curTok.x));
                        return(boolNode);
                    }
                    string opBool;
                    if (curTok.token == Tokens.Token.BOOL_OP_AND)
                    {
                        opBool = curTok.subString;
                        ASTNode nodeExprLeft = new BinaryExprAST(op, leftNodeExp, rightNodeExp, new Point(curTok.y, curTok.x));
                        ASTNode boolNode     = new BoolAST(nodeExprLeft, new Point(curTok.y, curTok.x));
                        ASTNode nodeExpRight = new BinaryExprAST(opBool, boolNode, MemberBoolBinOperation(true), new Point(curTok.y, curTok.x));
                        ASTNode nodeBool;
                        while (curTok.token != Tokens.Token.PARENTHESIS_R)
                        {
                            string  boolor       = curTok.subString;
                            ASTNode memberBoolOr = MemberBoolBinOperation(curTok.token == Tokens.Token.BOOL_OP_AND);
                            nodeExpRight = new BinaryExprAST(boolor, memberBoolOr, nodeExpRight, new Point(curTok.y, curTok.x));
                        }
                        nodeBool = nodeExpRight;
                        return(new BoolAST(nodeBool, new Point(curTok.y, curTok.x)));
                    }
                    else if (curTok.token == Tokens.Token.BOOL_OP_OR)
                    {
                        opBool = curTok.subString;
                        ASTNode nodeExprLeft = new BinaryExprAST(op, leftNodeExp, rightNodeExp, new Point(curTok.y, curTok.x));
                        ASTNode boolNode     = new BoolAST(nodeExprLeft, new Point(curTok.y, curTok.x));
                        ASTNode nodeExpRight = new BinaryExprAST(opBool, boolNode, MemberBoolBinOperation(), new Point(curTok.y, curTok.x));
                        return(new BoolAST(nodeExpRight, new Point(curTok.y, curTok.x)));
                    }
                    else
                    {
                        ASTNode nodeExpr = new BinaryExprAST(op, leftNodeExp, rightNodeExp, new Point(curTok.y, curTok.x));
                        return(new BoolAST(nodeExpr, new Point(curTok.y, curTok.x)));
                    }
                }
                ConsoleHelper.WriteErrorAST("Expected 'boolean'", curTok.y, curTok.x);
                return(null);

            case Tokens.Token.PARENTHESIS_L:
                return(ParseParenthesis());

            default:
                ConsoleHelper.WriteErrorAST("Impossible token in this area", curTok.y, curTok.x);
                break;
            }
            return(null);
        }
コード例 #4
0
 private bool Visit(BoolAST boolAST)
 {
     return(boolAST.Bool);
 }
コード例 #5
0
 internal BoolAST BoolASTVisit(BoolAST node)
 {
     valueStack.Push(LLVM.ConstInt(LLVM.Int8Type(), Convert.ToUInt64(node.Value), new LLVMBool(0)));
     return(node);
 }