Exemple #1
0
        private Node ParseLogicalOr()
        {
            var lNode = this.ParseLogicalXor();

            while (this.AreMoreTokens)
            {
                if (this.currentToken.Equals(TokenType.Symbol, "|"))
                {
                    this.ReadNextToken();
                    lNode = new LogicalOrNode(lNode, this.ParseLogicalXor());
                }
                else
                {
                    break;
                }
            }

            return(lNode);
        }
Exemple #2
0
        private Node ParseLogicalOr()
        {
            var lNode = this.ParseLogicalXor();

            while (this.AreMoreTokens)
            {
                if (this.currentToken.Equals(TokenType.Symbol, "|"))
                {
                    this.ReadNextToken();
                    lNode = new LogicalOrNode(lNode, this.ParseLogicalXor());
                }
                else
                {
                    break;
                }
            }

            return lNode;
        }
Exemple #3
0
        public BinaryExpressionNode ParseBinaryExpresssion(Token operatorToken, AstNode leftOperand, AstNode rightOperand)
        {
            BinaryExpressionNode expression = null;

            switch (operatorToken.Type)
            {
            case TokenType.Plus:
                expression = new AdditionNode(operatorToken.SourceLine);
                break;

            case TokenType.Minus:
                expression = new SubstractionNode(operatorToken.SourceLine);
                break;

            case TokenType.Asterisk:
                expression = new MultiplicationNode(operatorToken.SourceLine);
                break;

            case TokenType.Slash:
                expression = new DivisionNode(operatorToken.SourceLine);
                break;

            case TokenType.Equals:
                expression = new EqualsComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.NotEquals:
                expression = new NotEqualsComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.Less:
                expression = new LessComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.EqualsOrLess:
                expression = new EqualsOrLessComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.Greater:
                expression = new GreaterComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.EqualsOrGreater:
                expression = new EqualsOrGreaterComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.And:
                expression = new LogicalAndNode(operatorToken.SourceLine);
                break;

            case TokenType.Or:
                expression = new LogicalOrNode(operatorToken.SourceLine);
                break;

            default:
                throw new CompilerException($"`{MethodBase.GetCurrentMethod().Name}` called with a bad token. Expected a binary operator, token has type `{operatorToken.Type}` instead.");
            }
            expression.LeftOperand  = leftOperand;
            expression.RightOperand = rightOperand;
            return(expression);
        }
    // $ANTLR start "logicalORExpression"
    // JavaScript.g:251:1: logicalORExpression : logicalANDExpression ( ( LT )* ( '||' ( LT )* n= logicalANDExpression ) )* ;
    public JavaScriptParser.logicalORExpression_return logicalORExpression() // throws RecognitionException [1]
    {   
        JavaScriptParser.logicalORExpression_return retval = new JavaScriptParser.logicalORExpression_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken LT288 = null;
        IToken string_literal289 = null;
        IToken LT290 = null;
        JavaScriptParser.logicalANDExpression_return n = default(JavaScriptParser.logicalANDExpression_return);

        JavaScriptParser.logicalANDExpression_return logicalANDExpression287 = default(JavaScriptParser.logicalANDExpression_return);


        object LT288_tree=null;
        object string_literal289_tree=null;
        object LT290_tree=null;

        try 
    	{
            // JavaScript.g:252:2: ( logicalANDExpression ( ( LT )* ( '||' ( LT )* n= logicalANDExpression ) )* )
            // JavaScript.g:252:4: logicalANDExpression ( ( LT )* ( '||' ( LT )* n= logicalANDExpression ) )*
            {
            	root_0 = (object)adaptor.GetNilNode();

            	PushFollow(FOLLOW_logicalANDExpression_in_logicalORExpression2221);
            	logicalANDExpression287 = logicalANDExpression();
            	state.followingStackPointer--;
            	if (state.failed) return retval;
            	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, logicalANDExpression287.Tree);
            	// JavaScript.g:252:25: ( ( LT )* ( '||' ( LT )* n= logicalANDExpression ) )*
            	do 
            	{
            	    int alt150 = 2;
            	    alt150 = dfa150.Predict(input);
            	    switch (alt150) 
            		{
            			case 1 :
            			    // JavaScript.g:252:26: ( LT )* ( '||' ( LT )* n= logicalANDExpression )
            			    {
            			    	// JavaScript.g:252:28: ( LT )*
            			    	do 
            			    	{
            			    	    int alt148 = 2;
            			    	    int LA148_0 = input.LA(1);

            			    	    if ( (LA148_0 == LT) )
            			    	    {
            			    	        alt148 = 1;
            			    	    }


            			    	    switch (alt148) 
            			    		{
            			    			case 1 :
            			    			    // JavaScript.g:252:28: LT
            			    			    {
            			    			    	LT288=(IToken)Match(input,LT,FOLLOW_LT_in_logicalORExpression2224); if (state.failed) return retval;

            			    			    }
            			    			    break;

            			    			default:
            			    			    goto loop148;
            			    	    }
            			    	} while (true);

            			    	loop148:
            			    		;	// Stops C# compiler whining that label 'loop148' has no statements

            			    	// JavaScript.g:252:31: ( '||' ( LT )* n= logicalANDExpression )
            			    	// JavaScript.g:252:33: '||' ( LT )* n= logicalANDExpression
            			    	{
            			    		string_literal289=(IToken)Match(input,82,FOLLOW_82_in_logicalORExpression2230); if (state.failed) return retval;
            			    		if ( state.backtracking == 0 )
            			    		{string_literal289_tree = new LogicalOrNode(string_literal289) ;
            			    			root_0 = (object)adaptor.BecomeRoot(string_literal289_tree, root_0);
            			    		}
            			    		// JavaScript.g:252:56: ( LT )*
            			    		do 
            			    		{
            			    		    int alt149 = 2;
            			    		    int LA149_0 = input.LA(1);

            			    		    if ( (LA149_0 == LT) )
            			    		    {
            			    		        alt149 = 1;
            			    		    }


            			    		    switch (alt149) 
            			    			{
            			    				case 1 :
            			    				    // JavaScript.g:252:56: LT
            			    				    {
            			    				    	LT290=(IToken)Match(input,LT,FOLLOW_LT_in_logicalORExpression2236); if (state.failed) return retval;

            			    				    }
            			    				    break;

            			    				default:
            			    				    goto loop149;
            			    		    }
            			    		} while (true);

            			    		loop149:
            			    			;	// Stops C# compiler whining that label 'loop149' has no statements

            			    		PushFollow(FOLLOW_logicalANDExpression_in_logicalORExpression2242);
            			    		n = logicalANDExpression();
            			    		state.followingStackPointer--;
            			    		if (state.failed) return retval;
            			    		if ( state.backtracking == 0 ) adaptor.AddChild(root_0, n.Tree);

            			    	}


            			    }
            			    break;

            			default:
            			    goto loop150;
            	    }
            	} while (true);

            	loop150:
            		;	// Stops C# compiler whining that label 'loop150' has no statements


            }

            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }