public override CompilerParser VisitCondition([NotNull] CompilerParser.ConditionContext context) { // Если в качестве условия передан результат сравнения двух выражений if (context.left != null && context.right != null) { if (context.gt != null) { context.val = EvaluateExpression(context.left) > EvaluateExpression(context.right); } else if (context.lt != null) { context.val = EvaluateExpression(context.left) < EvaluateExpression(context.right); } else { context.val = context.not == null ? EvaluateExpression(context.left) == EvaluateExpression(context.right) : EvaluateExpression(context.left) != EvaluateExpression(context.right); } } else if (context.leftC != null && context.rightC != null) { Visit(context.leftC); Visit(context.rightC); if (context.AND() != null) { context.val = context.leftC.val && context.rightC.val; } else { context.val = context.leftC.val || context.rightC.val; } } // Если ID не пустой - читаем соответствующую переменную из памяти и инвертируем ее else if (context.ID() != null) { context.val = !Convert.ToBoolean(CompilerParser.memory[context.Stop.Text]); } // Если передана bool переменная else if (context.not == null) { context.val = Convert.ToBoolean(context.Start.Text); } else { context.val = !Convert.ToBoolean(context.Stop.Text); } return(null); }
/// <summary> /// Exit a parse tree produced by <see cref="CompilerParser.condition"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitCondition([NotNull] CompilerParser.ConditionContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="CompilerParser.condition"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitCondition([NotNull] CompilerParser.ConditionContext context) { return(VisitChildren(context)); }