コード例 #1
0
        static void Branch()
        {
            int    target;
            string name;
            Label  lab;

            if (la.kind == brn_Sym)
            {
                Get();
            }
            else if (la.kind == bze_Sym)
            {
                Get();
            }
            else
            {
                SynErr(67);
            }
            string mnemonic = token.val;

            IO.Write(token.val);
            IO.Write("", 5);

            if (la.kind == number_Sym)
            {
                Number(out target);
                CodeGen.TwoWord(mnemonic, target);
            }
            else if (la.kind == identifier_Sym)
            {
                Ident(out name);
                LabelEntry entry = LabelTable.Find(name);
                if (entry == null)
                {
                    lab = new Label(!known);
                    int lineNumber = token.line;
                    LabelTable.Insert(new LabelEntry(name, lab, lineNumber));
                }
                else
                {
                    lab = entry.label;
                    entry.AddReference(token.line);
                }
                IO.Write(name);
                IO.Write("", 10 - name.Length);
                CodeGen.Branch(mnemonic, lab);
            }
            else
            {
                SynErr(68);
            }
        }
コード例 #2
0
        static void Label()
        {
            Expect(label_Sym);
            string     name       = token.val.Substring(0, token.val.Length - 1).ToLower();
            int        lineNumber = -token.line;
            LabelEntry entry      = LabelTable.Find(name);

            if (entry == null)      //new label to be defined
            {
                LabelTable.Insert(new LabelEntry(name, new Label(known), lineNumber));
            }
            else if (entry.label.IsDefined())
            {
                SemError("redefined label");
            }
            else
            {
                entry.label.Here();
                entry.AddReference(lineNumber); //label was defined here
            }
        }