public override bool VisitCondElse(LatteParser.CondElseContext context) { return(context.expr() switch { LatteParser.ETrueContext _ => Visit(context.stmt()[0]), LatteParser.EFalseContext _ => Visit(context.stmt()[1]), _ => (Visit(context.stmt()[0]) && Visit(context.stmt()[1])) });
public override void EnterCondElse(LatteParser.CondElseContext context) { _environment.DetachVarEnv(); if (context.stmt()[0] is LatteParser.DeclContext) { _skipNextDecl = true; } var exprType = new ExpressionTypeVisitor().Visit(context.expr()); if (!exprType.Equals(new LatteParser.TBoolContext())) { _errorState.AddErrorMessage(new ErrorMessage( context.expr().start.Line, context.expr().start.Line, ErrorMessages.IfWrongCondition)); } }
public CondElse(LatteParser.CondElseContext context) { Expr = Exprs.Utils.ExprFromExprContext(context.expr()); var stmt1 = Utils.StmtFromStmtContext(context.stmt()[0]); TBlock = stmt1 switch { Block block => block, Stmt s => new Block(s) }; var stmt2 = Utils.StmtFromStmtContext(context.stmt()[1]); FBlock = stmt2 switch { Block block => block, Stmt s => new Block(s) }; }
public static Stmt StmtFromStmtContext(LatteParser.StmtContext context) { return(context switch { LatteParser.AssContext assContext => new Ass(assContext), LatteParser.BlockStmtContext blockStmtContext => new Block(blockStmtContext), LatteParser.CondContext condContext => new Cond(condContext), LatteParser.CondElseContext condElseContext => new CondElse(condElseContext), LatteParser.DeclContext declContext => new Decl(declContext), LatteParser.DecrContext decrContext => new Decr(decrContext), LatteParser.EmptyContext _ => new Empty(), LatteParser.IncrContext incrContext => new Incr(incrContext), LatteParser.RetContext retContext => new Ret(retContext), LatteParser.SExpContext sExpContext => new ExpStmt(sExpContext), LatteParser.StructAssContext structAssContext => new StructAss(structAssContext), LatteParser.StructDecrContext structDecrContext => new StructDecr(structDecrContext), LatteParser.StructIncrContext structIncrContext => new StructIncr(structIncrContext), LatteParser.VRetContext vRetContext => new Ret(vRetContext), LatteParser.WhileContext whileContext => new While(whileContext), _ => throw new ArgumentOutOfRangeException(nameof(context)) });
public override void ExitCondElse(LatteParser.CondElseContext context) { _environment.RestorePreviousVarEnv(); }