示例#1
0
 public DenfItem(String tokenName, TypePtr typePtr, String kind, int line)
 {
     this.tokenName = tokenName;
     this.typePtr   = typePtr;
     this.kind      = kind;
     this.line      = line;
 }
示例#2
0
        private void AnalHeadDeclaration()
        {
            Stack <Token> rec = new Stack <Token>();
            int           state = 0;
            int           counter = 0, tempCount = 0;
            String        nowType = "";

            while (input.Count() != 0)
            {
                Token nowSymbol = input.Pop();
                rec.Push(nowSymbol);
                switch (state)
                {
                case 0:
                    if (nowSymbol.code == sheet.grammer.Symbol2Code["int"] ||
                        nowSymbol.code == sheet.grammer.Symbol2Code["float"] ||
                        nowSymbol.code == sheet.grammer.Symbol2Code["char"])
                    {
                        nowType = nowSymbol.content;
                        state   = 1;
                    }
                    else
                    {
                        state = 4;
                    }
                    break;

                case 1:
                    if (nowSymbol.code == sheet.grammer.Symbol2Code["identifier"])
                    {
                        TypePtr type = typeList.FindType(nowType);
                        if (type != null)
                        {
                            denfList.list.Add(new Pair <string, DenfItem>(nowSymbol.content, new varKind(nowSymbol.content, type, Access.dir, 0, off, nowSymbol.line)));
                            off += type.size;
                            tempCount++;
                        }
                        state = 2;
                    }
                    else
                    {
                        state = 4;
                    }
                    break;

                case 2:
                    if (nowSymbol.code == sheet.grammer.Symbol2Code[";"])
                    {
                        rec.Clear();
                        counter  += tempCount;
                        tempCount = 0;
                        state     = 0;
                    }
                    else if (nowSymbol.code == sheet.grammer.Symbol2Code[","])
                    {
                        state = 3;
                    }
                    else
                    {
                        state = 4;
                    }
                    break;

                case 3:
                    if (nowSymbol.code == sheet.grammer.Symbol2Code["identifier"])
                    {
                        TypePtr type = typeList.FindType(nowType);
                        if (type != null)
                        {
                            denfList.list.Add(new Pair <string, DenfItem>(nowSymbol.content, new varKind(nowSymbol.content, type, Access.dir, 0, off, nowSymbol.line)));
                            off += type.size;
                            tempCount++;
                        }
                        state = 2;
                    }
                    else
                    {
                        state = 4;
                    }
                    break;
                }
                if (state == 4)
                {
                    recover(rec);
                    Console.WriteLine("Detected " + counter + " pre-definition.");
                    break;
                }
            }
        }
示例#3
0
        private void AnalTypedefStruct()
        {
            Stack <Token> newInput = new Stack <Token>();

            while (input.Count != 0)
            {
                Token tk = input.Pop();
                if (tk.code == 39)
                {
                    Token srcType    = input.Pop();
                    Token targetType = input.Pop();
                    bool  flag       = false;
                    if (typeList.FindType(srcType.content) != null)
                    {
                        denfList.list.Add(new Pair <string, DenfItem>(targetType.content, new typeKind(targetType.content, typeList.FindType(srcType.content), targetType.line)));
                        flag = true;
                    }
                    if (flag == false)
                    {
                        Console.WriteLine($"Error: symbol {srcType.content} undefined.");
                    }
                    input.Pop();
                }
                else if (tk.code == 40)
                {
                    String fieldName = input.Pop().content;
                    input.Pop();
                    offStack.Push(off);
                    off = 0;
                    var structType = new RecordTypePtr(fieldName);
                    while (input.Peek().content != "}")
                    {
                        String  typeName = input.Pop().content;
                        TypePtr type     = typeList.FindType(typeName);
                        while (input.Peek().content != ";")
                        {
                            Token idenTk = input.Pop();
                            if (idenTk.code == sheet.grammer.Symbol2Code["identifier"])
                            {
                                structType.AddBody(new RecordBody(idenTk.content, type, structType.size));
                                off += typeList.FindType(typeName).size;
                            }
                        }
                        input.Pop();
                    }
                    typeList.list.Add(structType);
                    denfList.list.Add(new Pair <string, DenfItem>(fieldName, new fieldKind(fieldName, structType, off, tk.line)));
                    input.Pop();
                    input.Pop();
                    off = offStack.Pop();
                }
                else
                {
                    foreach (var item in denfList.list)
                    {
                        if (tk.content == item.First)
                        {
                            tk.content = item.Second.typePtr.typeName;
                            tk.code    = sheet.grammer.Symbol2Code[tk.content];
                        }
                    }
                    newInput.Push(tk);
                }
            }
            while (newInput.Count != 0)
            {
                input.Push(newInput.Pop());
            }
            foreach (var item in input)
            {
                Console.WriteLine(item.content + " " + item.code);
            }
        }
示例#4
0
 public RecordBody(String name, TypePtr typePtr, int offset)
 {
     this.name    = name;
     this.typePtr = typePtr;
     this.offset  = offset;
 }
示例#5
0
 public ArrayTypePtr(int length, TypePtr elementTy) : base("Array")
 {
     this.length    = length;
     this.elementTy = elementTy;
     size           = length * elementTy.size;
 }
示例#6
0
 public Express(TypePtr type, String iden)
 {
     this.type = type;
     this.iden = iden;
 }
示例#7
0
 public varKind(String tokenName, TypePtr typePtr, Access access, int level, int off, int line) : base(tokenName, typePtr, "varKind", line)
 {
     this.access = access;
     this.level  = level;
     this.off    = off;
 }
示例#8
0
 public typeKind(String tokenName, TypePtr typePtr, int line) : base(tokenName, typePtr, "typeKind", line)
 {
 }
示例#9
0
 public formalRouteKind(String tokenName, TypePtr typePtr, int level, int off, int line) : base(tokenName, typePtr, "actualRouteKind", line)
 {
     this.level = level;
     classType  = ClassType.formal;
     this.off   = off;
 }
示例#10
0
 public actualRouteKind(String tokenName, TypePtr typePtr, int level, int line) : base(tokenName, typePtr, "actualRouteKind", line)
 {
     this.level = level;
     classType  = ClassType.actual;
     forward    = false;
 }
示例#11
0
 public fieldKind(String tokenName, RecordTypePtr typePtr, int off, int line) : base(tokenName, typePtr, "fieldKind", line)
 {
     this.off      = off;
     this.hostType = typePtr;
 }
示例#12
0
        int BSXRP_SetupTable(BytePtr cl, int ncl,
            TypePtr<ushort> tc, TypePtr<ushort> tm, BytePtr tl,
            TypePtr<short> ti, TypePtr<short> tn)
        {
            int[] cnt = new int[16];
            int[] nc = new int[16];
            int[] nn = new int[16];
            int[] nf = new int[16];
            int i, j, k, k2, l, ff;

            for (i = 0; i < 16; i++) { cnt[i] = 0; nc[i] = 0; nn[i] = -1; nf[i] = -1; }
            for (i = 0; i < 256; i++) ti[i] = -1;

            for (i = 0; i < ncl; i++) cnt[cl[i]]++;
            cnt[0] = 0;

            #if true
            j = cl[0];
            for (i = 15; i >= 1; i--)
                if (cnt[i]!=0) break;
            if (j > i) j = i;
            if (i==0) return (-12);	//no codes

            j = 1;
            for (i = 1; i < 16; i++)
            {
                j <<= 1;
                j -= cnt[i];

                //		dyPrintf("%d %d %d\n", i, j, cnt[i]);
                if (j < 0) return (-10);	//over subscribed
            }
            if ((j > 0) && ((ncl - cnt[0]) != 1))
                return (-11);	//incomplete set
            #endif

            j = 0;
            for (i = 1; i < 16; i++)
            {
                j = (j + cnt[i - 1]) << 1;
                nc[i] = j;
            }

            for (i = 0; i < ncl; i++)
            {
                l = cl[i];
                if (l==0) continue;

                tl[i] = cl[i];
                tm[i] = (ushort)((1 << tl[i]) - 1);
                tc[i] = (ushort)(nc[l]++);

                if (nn[l] >= 0)
                {
                    tn[nn[l]] = (short)i;
                    nn[l] = i;
                }
                else
                {
                    nf[l] = i;
                    nn[l] = i;
                }
            }

            j = -1; ff = -1;
            for (i = 1; i < 16; i++)
            {
                if (nf[i] >= 0)
                {
                    if (ff < 0) ff = nf[i];
                    if (j >= 0) tn[j] = (short)nf[i];
                    j = nn[i];
                }
            }
            if (j >= 0) tn[j] = -1;

            for (i = ff; i != 0xFFFF; i = tn[i])
            {
                l = cl[i];
                if (l <= 8)
                {
                    k2 = tc[i] << (8 - l);
                    j = 1 << (8 - l);
                    while ((j--)!=0)
                    {
                        //k = BSXRP_TransposeByte(k2++);
                        k = k2++;
                        if (ti[k] == -1) ti[k] = (short)i;
                    }
                }
                else
                {
                    k2 = tc[i] >> (l - 8);
                    //k = BSXRP_TransposeByte(k2);
                    k = k2;
                    if (ti[k] == -1) ti[k] = (short)i;
                }

                k2 = (tc[i]) << (16 - l);
                //k = BSXRP_TransposeWord(k2++);
                k = k2++;
                tc[i] = (ushort)k;
            }

            j = 0;
            for (i = 0; i < 256; i++) if (ti[i] == -1)
                {
                    Console.Write("table bad index {0}\n", i);
                    j = -9;
                }
            return (j);
        }