static bool ActionOnExpandParameterList(SyntaxStack ss, Production pp, string token) { List <Symbol> lsym = new List <Symbol>(); IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; IDeclTypeAttribute dp = null; switch (pp.prodno) { case (27): // Parameter_List_Tail -> Comma Parameter_Declaration Parameter_List_Tail dp = pp.inh[2] as IDeclTypeAttribute; foreach (Symbol sym in sp.lsym) { dp.lsym.Add(sym); } break; // Parameter_List_Tail ->Lambda case (28): dp = ss.ss[ss.sp - 4] as IDeclTypeAttribute; // dump symbols to Direct_Declarator_Tail foreach (Symbol sym in sp.lsym) { lsym.Add(sym); } dp.stype.Push(BuildType(TypeOperator.FUNCTION, null, 0, lsym)); break; } return(true); }
static bool ActionOnLoadNumToDirectDeclTail(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 4] as IDeclTypeAttribute; // Direct_declarator_Tail sp.stype.Push(BuildType(TypeOperator.ARRAY, null, Convert.ToInt16(token), null)); return(true); }
static bool ActionOnProcessTempDeclarator(SyntaxStack ss, Production pp) { SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; // Declarator IDeclTypeAttribute ip = ss.ss[ss.sp - 4] as IDeclTypeAttribute; // Direct_Declarator_Tail Type ty = null, tty = null; for (int _j = 0; _j < sp.np; _j++) { tty = BuildType(TypeOperator.POINTER, tty, 4, null); } for (int _j = 0; _j < sp.stype.Count; _j++) { ty = sp.stype.Pop(); tty = BuildType(ty.op, tty, ty.size, ty.lsym); } ty = sp.tmpty; while (ty != null && ty.type != null) { ty = ty.type; } if (sp.tmpty == null) { sp.tmpty = tty; } else { ty.type = tty; } ip.tmpty = sp.tmpty; ip.id = sp.id; return(true); }
static bool BuildBaseType(SyntaxStack ss, Production pp, string token) { SDeclTypeAttribute sp = ss.ss[ss.sp - 2] as SDeclTypeAttribute; // Type_specifier string ty = token.ToUpper(); switch (ty) { case ("CHAR"): sp.basety = BuildType(TypeOperator.CHAR, null, 1, null); break; case ("INT"): sp.basety = BuildType(TypeOperator.INT, null, 2, null); break; case ("LONG"): sp.basety = BuildType(TypeOperator.LONG, null, 4, null); break; case ("VOID"): sp.basety = BuildType(TypeOperator.VOID, null, 0, null); break; } return(true); }
static bool ActionOnLoadIdToDirectDeclTail(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 3] as IDeclTypeAttribute; // Direct_declarator_Tail sp.id = token.ToUpper(); return(true); }
static bool AddStorageClassModifier(SyntaxStack ss, Production pp, string token) { SDeclTypeAttribute sp = ss.ss[ss.sp - 2] as SDeclTypeAttribute; string ty = token.ToUpper(); switch (ty) { case ("AUTO"): sp.sclass = StorageClass.AUTO; break; case ("STATIC"): sp.sclass = StorageClass.STATIC; break; case ("EXTERN"): sp.sclass = StorageClass.EXTERN; break; case ("REGISTER"): sp.sclass = StorageClass.REGISTER; break; } return(true); }
static bool BuildPointerType(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 4] as IDeclTypeAttribute; sp.basety = BuildType(TypeOperator.POINTER, sp.basety, 4, null); return(true); }
static bool ActionLoadStorageClassModifier(SyntaxStack ss, Production pp) { IDeclTypeAttribute ip = ss.ss[ss.sp - 7] as IDeclTypeAttribute; SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; ip.sclass = sp.sclass; return(true); }
static bool ActionLoadSignSpecifier(SyntaxStack ss, Production pp) { IDeclTypeAttribute ip = ss.ss[ss.sp - 5] as IDeclTypeAttribute; SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; ip.signed = sp.signed; return(true); }
static bool ActionOnExpandDeclarator(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; //Declarator IDeclTypeAttribute dp = null; dp = pp.inh[0] as IDeclTypeAttribute; // Pointer dp.basety = sp.basety; dp.sclass = sp.sclass; return(true); }
static bool ActionOnLoadParameterList(SyntaxStack ss, Production pp) { SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; IDeclTypeAttribute ip = ss.ss[ss.sp - 3] as IDeclTypeAttribute; Type ty; int nitems = 0; for (int _j = 0; _j < sp.np; _j++) { sp.basety = BuildType(TypeOperator.POINTER, sp.basety, 4, null); } nitems = sp.stype.Count; for (int _j = 0; _j < nitems; _j++) { ty = sp.stype.Pop(); sp.basety = BuildType(ty.op, sp.basety, ty.size, ty.lsym); } ty = sp.tmpty; while (ty != null && ty.type != null) { ty = ty.type; } if (ty != null) { ty.type = sp.basety; sp.basety = sp.tmpty; } // create a sym Symbol sym = new Symbol(); sym.name = sp.id; sym.sclass = sp.sclass; sym.type = sp.basety; if (ScanParameterList(ip.lsym, sym.name)) { ip.lsym.Add(sym); } else { ErrMsg = "duplicate parameter name : " + sym.name; return(false); } return(true); }
static bool ActionOnExpandParameterDeclarationTail(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; IDeclTypeAttribute dp = null; switch (pp.prodno) { case (30): // Parameter_Declaration_Tail -> Declarator dp = pp.inh[0] as IDeclTypeAttribute; dp.basety = sp.basety; dp.sclass = sp.sclass; break; } return(true); }
static bool ActionOnExpandParameterTypeList(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute dp = null; switch (pp.prodno) { case (24): dp = ss.ss[ss.sp - 4] as IDeclTypeAttribute; break; case (25): dp = ss.ss[ss.sp - 4] as IDeclTypeAttribute; // dump empty arg list to Direct_Declarator_Tail dp.stype.Push(BuildType(TypeOperator.FUNCTION, null, 0, null)); // no argument break; } return(true); }
static bool ActionLoadBaseType(SyntaxStack ss, Production pp) { IDeclTypeAttribute ip = ss.ss[ss.sp - 3] as IDeclTypeAttribute; // Declarator SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; // Type_specifier switch (sp.basety.op) { case (TypeOperator.VOID): case (TypeOperator.CHAR): case (TypeOperator.INT): case (TypeOperator.LONG): ip.basety = sp.basety; ip.basety.signed = ip.signed; break; } return(true); }
static bool ActionProcessSymbolTableDeclarator(SyntaxStack ss, Production pp) { SDeclTypeAttribute sp = ss.ss[ss.sp - 1] as SDeclTypeAttribute; // Declarator Type ty; int nitems = 0; for (int _j = 0; _j < sp.np; _j++) { sp.basety = BuildType(TypeOperator.POINTER, sp.basety, 4, null); } nitems = sp.stype.Count; for (int _j = 0; _j < nitems; _j++) { ty = sp.stype.Pop(); sp.basety = BuildType(ty.op, sp.basety, ty.size, ty.lsym); } ty = sp.tmpty; while (ty != null && ty.type != null) { ty = ty.type; } if (ty != null) { ty.type = sp.basety; sp.basety = sp.tmpty; } Symbol sym = new Symbol(); sym.name = sp.id; sym.sclass = sp.sclass; sym.type = sp.basety; if (CheckInvalidType(sp.basety)) { return(false); } EAGrammar._type = _FormatType(sym); // formatted output return(true); }
static bool ActionAddSignSpecifier(SyntaxStack ss, Production pp, string token) { SDeclTypeAttribute sp = ss.ss[ss.sp - 2] as SDeclTypeAttribute; string ty = token.ToUpper(); switch (ty) { case ("SIGNED"): sp.signed = SignSpecifier.SIGNED; break; case ("UNSIGNED"): sp.signed = SignSpecifier.UNSIGNED; break; } return(true); }
static bool ActionOnExpandDirectDeclTail(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; // Direct_Declarator_Tail IDeclTypeAttribute ip = null; switch (pp.prodno) { case (19): // Direct_Declarator_Tail -> LQParen Num RQParen Direct_Declator_Tail ip = pp.inh[3] as IDeclTypeAttribute; ip.basety = sp.basety; ip.tmpty = sp.tmpty; ip.sclass = sp.sclass; ip.np = sp.np; ip.id = sp.id; __Copy_Stack(ip.stype, sp.stype); break; case (20): // Direct_Declarator_Tail -> LParen Parameter_Type_list RParen Direct_Declator_Tail ip = pp.inh[3] as IDeclTypeAttribute; ip.basety = sp.basety; ip.tmpty = sp.tmpty; ip.sclass = sp.sclass; ip.np = sp.np; ip.id = sp.id; __Copy_Stack(ip.stype, sp.stype); break; case (21): // Direct_Declarator_Tail -> Lambda SDeclTypeAttribute dp = ss.ss[ss.sp - 2] as SDeclTypeAttribute; // Declarator dp.basety = sp.basety; dp.tmpty = sp.tmpty; dp.sclass = sp.sclass; dp.np = sp.np; dp.id = sp.id; __Copy_Stack(dp.stype, sp.stype); break; } return(true); }
static bool ActionOnExpandDirectDecl(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; // Direct_Declarator IDeclTypeAttribute ip = null; switch (pp.prodno) { case (17): // Direct_Declarator -> Id Direct_Declarator_Tail ip = pp.inh[1] as IDeclTypeAttribute; ip.basety = sp.basety; ip.sclass = sp.sclass; ip.np = sp.np; break; case (18): // Direct_Declarator -> LParen Declarator RParen Direct_Declator_Tail ip = pp.inh[3] as IDeclTypeAttribute; ip.basety = sp.basety; ip.sclass = sp.sclass; ip.np = sp.np; break; } return(true); }
static bool ActionOnExpandPointer(SyntaxStack ss, Production pp, string token) { IDeclTypeAttribute sp = ss.ss[ss.sp - 1] as IDeclTypeAttribute; // Pointer IDeclTypeAttribute ip = null; switch (pp.prodno) { case (22): // Pointer -> Star Pointer ip = pp.inh[1] as IDeclTypeAttribute; ip.basety = sp.basety; ip.sclass = sp.sclass; ip.np = sp.np; ip.np++; break; case (23): // Pointer -> Lambda (copy rule) ip = ss.ss[ss.sp - 4] as IDeclTypeAttribute; // Direct_Declarator ip.basety = sp.basety; ip.sclass = sp.sclass; ip.np = sp.np; break; } return(true); }