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 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 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 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 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 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 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); }
public SDeclTypeAttribute(SDeclTypeAttribute ip) { nTerm = ip.nTerm; sym = ip.sym; basety = ip.basety; tmpty = ip.tmpty; signed = ip.signed; sclass = ip.sclass; size = ip.size; id = ip.id; np = ip.np; foreach (Symbol ssym in ip.lsym) { lsym.Add(ssym); } __Copy_Stack(stype, ip.stype); FireAction = ip.FireAction; }
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); }
public bool Parse() { bool fret = false; Production pp = null; object sym = Stack.Top(); SynthesizedAttribute syn = sym as SynthesizedAttribute; if (syn != null) { if (syn.FireAction != null) { fret = syn.FireAction(Stack, pp); if (fret == false) { return(fret); } } Stack.Pop(); //DumpStack(); return(true); } SemanticAction sma = sym as SemanticAction; if (sma != null) { Stack.Pop(); sym = Stack.Top(); } InheritedAttribute inh = sym as InheritedAttribute; if (inh != null) { if (token != TokenLookup.TokenKind.UnKnown) { pp = (Production)M[(int)inh.nTerm.Category, (int)token]; } if (pp == null) { MessageBox.Show(" syntax error !"); return(false); } if (sma != null) { fret = sma.FireAction(Stack, pp, lexx.TokenValue); // copy inherited top down into next production fields if (fret == false) { return(fret); } } Stack.Pop(); for (int j = pp.rhs.Count - 1; j >= 0; j--) { Terminal tt = pp.rhs[j] as Terminal; if (tt != null && tt.Token == TokenLookup.TokenKind.Lambda) { continue; } if (pp.synth != null && pp.synth[j] != null) { if (pp.synth[j] is SDeclTypeAttribute) { SDeclTypeAttribute sa = (SDeclTypeAttribute)pp.synth[j] as SDeclTypeAttribute; Stack.Push(new SDeclTypeAttribute(sa)); } pp.synth[j].Clear(); } if (tt != null) { Stack.Push(pp.rhs[j]); } if (pp.inh != null && pp.inh[j] != null) { if (pp.inh[j] is IDeclTypeAttribute) { IDeclTypeAttribute ie = pp.inh[j] as IDeclTypeAttribute; Stack.Push(new IDeclTypeAttribute(ie)); } else { Stack.Push(new InheritedAttribute(pp.inh[j])); } pp.inh[j].Clear(); } //} if (pp.action != null && pp.action[j] != null) { Stack.Push(pp.action[j]); } } //DumpStack(); } else // is a Terminal or EOI { Terminal tt = sym as Terminal; if (token == TokenLookup.TokenKind.EOI) { _curline = 1; MessageBox.Show("stream successfully parsed "); return(false); } else if (token == tt.Token) { if (sma != null) { fret = sma.FireAction(Stack, null, lexx.TokenValue); if (fret == false) { return(fret); } } Stack.Pop(); token = lexx.getToken(); return(true); } else { MessageBox.Show("Unexpected token : " + token + ", expected : " + tt.Token); return(false); } } return(true); }