public static string getCoolType(this CoolParser.ExpresionContext s) { try { var p = (CoolParser.InfixExpContext)(s); return("INT"); } catch (Exception) { } try { var p = (CoolParser.IntExpContext)(s); return("INT"); } catch (Exception) { } try { var p = (CoolParser.NotExpContext)(s); return("BOOL"); } catch (Exception) { } try { var p = (CoolParser.LessEqualExpContext)(s); return("BOOL"); } catch (Exception) { } try { var p = (CoolParser.LessExpContext)(s); return("BOOL"); } catch (Exception) { } try { var p = (CoolParser.EqualsExpContext)(s); return("BOOL"); } catch (Exception) { } try { var p = (CoolParser.StringExpContext)(s); return("STRING"); } catch (Exception) { } try { var p = (CoolParser.NewTypeExpContext)(s); return(p.t.Text); } catch (Exception) { } try { var p = (CoolParser.AssignExpContext)(s); return(p.e.getCoolType()); } catch (Exception) { } //TODO: fix this :( try { var p = (CoolParser.IdentifierExpContext)(s); return(SymbolTable.Symbols.Peek()[(p as CoolParser.IdentifierExpContext).id.Text].Type); } catch (Exception) { /*throw; */ } return("VOID?"); }
//public override object VisitFormal([NotNull] CoolParser.FormalContext context) //{ // return VisitChildren(context); //} //public override object private void VisitExpr(CoolParser.ExpresionContext context) { try { CoolParser.MethodFeatureContext p = (CoolParser.MethodFeatureContext)context.Parent; dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; return; } catch (Exception) { } try { CoolParser.AttribFeatureContext p = (CoolParser.AttribFeatureContext)context.Parent; dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; return; } catch (Exception) { } try { CoolParser.ExpresionContext p = (CoolParser.ExpresionContext)context.Parent; dotcode += p.GetType().Name.Substring(0, p.GetType().Name.Length - 7) + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; return; } catch (Exception) { } //switch (context.Parent) //{ // case CoolParser.MethodFeatureContext p: // dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; // break; // case CoolParser.AttribFeatureContext p: // dotcode += p.id.Text + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; // break; // case CoolParser.ExpresionContext p: // dotcode += p.GetType().Name.Substring(0, p.GetType().Name.Length - 7) + "->" + "\"" + context.GetType().Name.Substring(0, context.GetType().Name.Length - 7) + "\"" + "\n"; // break; // default: // break; //} ////return VisitChildren(context); }
public NotNode(CoolParser.ExpresionContext expresionContext, Node s) : base(s.Childs) { this.expresionContext = expresionContext; this.s = s; }