Beispiel #1
0
        public override void ExitAssign(ssuplParser.AssignContext context)
        {
            // assign : ID EQ expr
            string vname = context.ID().GetText();

            if (!symtable.Contains(vname))
            {
                throw new Exception("Undeclared variable: " + vname);
            }
            code.Put(context,
                     code.Get(context.expr()),
                     "pop rax",
                     $"mov [${symtable.Get(vname).location}],rax"
                     );
        }
Beispiel #2
0
        public override void ExitAssign(ssuplParser.AssignContext context)
        {
            // assign : ID EQ expr
            string vname = context.ID().GetText();

            if (symtable.Get(vname).type != type(context.expr()))//invalid input check
            {
                throw new Exception("Type mismatch");
            }
            if (!symtable.Contains(vname))
            {
                throw new Exception("Undeclared variable: " + vname);
            }
            code.Put(context,
                     code.Get(context.expr()),
                     "pop rax",
                     $"mov [${symtable.Get(vname).location}],rax" //,
                                                                  //"push rax"
                     );
        }