/// <summary> /// Visits the un op node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitUnOpNode(UnOpNode node) { // evaluate the operand and then perform the unary operation to it IProperty operandEval = getEvaluation(node.Operand); return(unaryOperation(node.Operation, operandEval)); }
/// <summary> /// Parses the an expression into a node that implements IExpressionContainer interface. /// </summary> /// <returns>The next token.</returns> /// <param name="token">Token.</param> /// <param name="node">An IExpressionContainer.</param> private Token ParseExpression(Token token, IExpressionContainer node) { Token next; switch (token.Type) { case TokenType.INT_VAL: case TokenType.STR_VAL: case TokenType.BOOL_VAL: case TokenType.PARENTHESIS_LEFT: case TokenType.ID: // parse a binary operation BinOpNode binOp = nodeBuilder.CreateBinOpNode(node, token); // parse the first operand next = ParseOperand(token, binOp); // parse the rest of the operation return(ParseBinaryOp(next, binOp)); case TokenType.UNARY_OP_LOG_NEG: // parse a unary operation UnOpNode unOp = nodeBuilder.CreateUnOpNode(node, token); // parse the operation, then the operand next = ParseUnaryOp(token, unOp); return(ParseOperand(next, unOp)); default: throw new UnexpectedTokenException(token, TokenType.UNDEFINED, ParserConstants.EXPECTATION_SET_EXPRESSION); } }
public UnOpNode CreateUnOpNode(IExpressionContainer parent, Token t) { UnOpNode unOp = new UnOpNode(t); parent.AddExpression(unOp); return(unOp); }
/// <summary> /// Parses a unary operation into a UnOpNode. /// </summary> /// <returns>The next token.</returns> /// <param name="token">Token.</param> /// <param name="unOp">A UnOpNode.</param> private Token ParseUnaryOp(Token token, UnOpNode unOp) { switch (token.Type) { case TokenType.UNARY_OP_LOG_NEG: unOp.Operation = TokenType.UNARY_OP_LOG_NEG; unOp.Token = token; return(scanner.getNextToken(token)); default: throw new UnexpectedTokenException(token, TokenType.UNARY_OP_LOG_NEG, null); } }
/// <summary> /// Checks the static semantic constraints of an UnOpNode. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitUnOpNode(UnOpNode node) { // This is not a statement so it needs not to be actually checked here. // So, we pass it to the TypeCheckerVisitor instead. return(node.Accept(this.typeChecker)); }
/// <summary> /// Visits the un op node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitUnOpNode(UnOpNode node) { // return the evaluation of the node using a helper method return(VisitOperationNode(node)); }
/// <summary> /// Visits the un op node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitUnOpNode(UnOpNode node) { // let the evaluator evaluate this node return(node.Accept(evaluator)); }