/// <summary> /// Reads a conditional logical expression. /// </summary> /// <param name="parentProxy">Represents the parent item.</param> /// <param name="leftHandSide">The expression on the left hand side of the operator.</param> /// <param name="previousPrecedence">The precedence of the expression just before this one.</param> /// <returns>Returns the expression.</returns> private ConditionalLogicalExpression GetConditionalPreprocessorAndOrExpression( CodeUnitProxy parentProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence) { Param.AssertNotNull(parentProxy, "parentProxy"); Param.AssertNotNull(leftHandSide, "leftHandSide"); Param.Ignore(previousPrecedence); ConditionalLogicalExpression expression = null; this.AdvanceToNextConditionalDirectiveCodeSymbol(parentProxy); var expressionProxy = new CodeUnitProxy(this.document); // Create the operator symbol. OperatorSymbolToken operatorToken = this.PeekOperatorSymbolToken(); // Check the precedence of the operators to make sure we can gather this statement now. ExpressionPrecedence precedence = GetOperatorPrecedence(operatorToken.SymbolType); if (CheckPrecedence(previousPrecedence, precedence)) { // Add the operator token to the document and advance the symbol manager up to it. this.symbols.Advance(); expressionProxy.Children.Add(operatorToken); // Get the expression on the right-hand side of the operator. Expression rightHandSide = this.GetNextConditionalPreprocessorExpression(this.document, expressionProxy, precedence); if (rightHandSide == null) { throw new SyntaxException(this.document, operatorToken.LineNumber); } // Get the expression operator type. switch (operatorToken.SymbolType) { case OperatorType.ConditionalAnd: expression = new ConditionalAndExpression(expressionProxy, leftHandSide, rightHandSide); break; case OperatorType.ConditionalOr: expression = new ConditionalOrExpression(expressionProxy, leftHandSide, rightHandSide); break; default: throw new SyntaxException(this.document, operatorToken.LineNumber); } parentProxy.Children.Add(expression); } return(expression); }
/// <summary> /// Initializes the contents of the expression. /// </summary> private void Initialize() { this.leftHandSide.Value = this.FindFirstChildExpression(); if (this.leftHandSide.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } OperatorSymbolToken o = this.leftHandSide.Value.FindNextSibling <OperatorSymbolToken>(); if (o == null) { throw new SyntaxException(this.Document, this.LineNumber); } this.rightHandSide.Value = o.FindNextSiblingExpression(); if (this.rightHandSide.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } }