Beispiel #1
0
        static void ReadElement()
        {
            string  str;
            DesType des;

            if (la.kind == stringLit_Sym)
            {
                StringConst(out str);
                CodeGen.WriteString(str);
            }
            else if (la.kind == identifier_Sym)
            {
                Designator(out des);
                if (des.entry.kind != Kinds.Var)
                {
                    SemError("wrong kind of identifier");
                }
                switch (des.type)
                {
                case Types.intType:
                case Types.boolType:
                    CodeGen.Read(des.type); break;

                default:
                    SemError("cannot read this type"); break;
                }
            }
            else
            {
                SynErr(53);
            }
        }
Beispiel #2
0
        static void WriteElement()
        {
            int    expType;
            string str;

            if (la.kind == stringLit_Sym)
            {
                StringConst(out str);
                CodeGen.WriteString(str);
            }
            else if (StartOf(11))
            {
                Expression(out expType);
                if (!(IsArith(expType) || expType == Types.boolType))
                {
                    SemError("cannot write this type");
                }
                switch (expType)
                {
                case Types.intType:
                case Types.boolType:
                    CodeGen.Write(expType); break;

                default:
                    break;
                }
            }
            else
            {
                SynErr(54);
            }
        }
Beispiel #3
0
 static void HaltStatement()
 {
     Expect(halt_Sym);
     if (la.kind == lparen_Sym)
     {
         Get();
         Expect(stringLit_Sym);
         CodeGen.WriteString(token.val);
         Expect(rparen_Sym);
     }
     CodeGen.LeaveProgram();
     ExpectWeak(semicolon_Sym, 6);
 }