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); } }
public fieldKind(String tokenName, RecordTypePtr typePtr, int off, int line) : base(tokenName, typePtr, "fieldKind", line) { this.off = off; this.hostType = typePtr; }