예제 #1
0
 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))
     });
예제 #2
0
        public override void EnterAss(LatteParser.AssContext context)
        {
            var id = context.ID().GetText();

            if (!_environment.NameToVarDef.ContainsKey(id))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.VarNotDefined(id));
            }

            var variable = _environment.NameToVarDef[id];
            var exprType = new ExpressionTypeVisitor().Visit(context.expr());

            if (!variable.Type.Equals(exprType) && !IsTypeParent(exprType, variable.Type))
            {
                StateUtils.InterruptWithMessage(
                    context.start.Line,
                    context.ID().Symbol.Column,
                    ErrorMessages.VarExprTypesMismatch(id));
            }
        }
예제 #3
0
 public override bool VisitAss(LatteParser.AssContext context)
 {
     return(false);
 }
예제 #4
0
파일: Ass.cs 프로젝트: Ogochi/LatteCompiler
 public Ass(LatteParser.AssContext context)
 {
     Id   = context.ID().GetText();
     Expr = Exprs.Utils.ExprFromExprContext(context.expr());
 }