override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { BinaryOperatorExpression tempB; UnaryOperatorExpression tempU; AssignmentExpression tempA; bool eval = false; System.Type type = exp.GetType(); if (type.Name == "UnaryOperatorExpression") { tempU = (UnaryOperatorExpression)exp; eval = outerPrecedence > 8; } if (type.Name == "BinaryOperatorExpression") { tempB = (BinaryOperatorExpression)exp; eval = outerPrecedence > BinaryOperatorExpression.precedences[tempB.op]; } if (type.Name == "AssignmentExpression") { tempA = (AssignmentExpression)exp; eval = outerPrecedence >= 1; } builder.Append(operators[op]); exp.Pretty(builder, 8, false); }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); builder.Append("return "); returnValue.Pretty(builder); builder.Append(";"); }
override public void Pretty(PrettyBuilder builder) { builder.Append(id.id); builder.Append("("); builder.Intersperse(exprList, ", "); builder.Append(")"); }
public override string ToString() { var builder = new PrettyBuilder(); Pretty(builder); return(builder.ToString()); }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage; {0} [-t | <filename>]", Process.GetCurrentProcess().ProcessName); return; } try { StreamReader input; if (args[0] == "-t") { input = new StreamReader(Console.OpenStandardInput()); } else { input = new StreamReader(args[0]); } var prg = input.ReadToEnd(); byte[] data = Encoding.ASCII.GetBytes(prg); MemoryStream stream = new MemoryStream(data, 0, data.Length); Strip stripper = new Strip(); Scanner l = new Scanner(stream); Parser p = new Parser(l); if (p.Parse()) { PrettyBuilder b = new PrettyBuilder(); p.program.Pretty(b); if (stripper.strip(prg).Equals(stripper.strip(b.ToString()))) { Console.WriteLine("True"); } else { Console.WriteLine("False"); Console.WriteLine(stripper.strip(b.ToString()) + "\n"); Console.WriteLine(stripper.strip(prg)); } } else { Console.WriteLine("False"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); builder.Append("{"); builder.Indent(); builder.PrettyStm(stmList); builder.Unindent(); builder.NewLine(); builder.Append("}"); }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); builder.Append("if("); exp.Pretty(builder); builder.Append(")"); //builder.Indent(); stm.Pretty(builder); //builder.Unindent(); //builder.NewLine(); }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); builder.Append(types[type] + " "); builder.Append(id.id); builder.Append("("); builder.Intersperse(arg, ", "); builder.Append(")"); stm.Pretty(builder); //builder.NewLine(); }
// public string Name ; // public Expression Argument; override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { if (outerPrecedence >= 4) { builder.Append("("); } builder.Append($"{Name} "); Argument.Pretty(builder, 4, false); if (outerPrecedence >= 4) { builder.Append(")"); } }
override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { bool eval = outerPrecedence > 1 || opposite && outerPrecedence == 1; if (eval) { builder.Append("("); } lo.Pretty(builder); builder.Append(" = "); ro.Pretty(builder); if (eval) { builder.Append(")"); } }
override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { bool eval = outerPrecedence > precedences[op] || opposite && outerPrecedence == precedences[op]; if (eval) { builder.Append("("); } left.Pretty(builder, precedences[op], false); builder.Append(" " + operators[op] + " "); right.Pretty(builder, precedences[op], true); if (eval) { builder.Append(")"); } }
// public string Name; // public string ArgumentName; // public Expression Body; // public Expression Recipient; override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { if (outerPrecedence > 1) { builder.Append("("); } builder.Append($"let {Name} {ArgumentName} = "); Body.Pretty(builder, 1, false); builder.Append(" in "); Recipient.Pretty(builder, 1, false); if (outerPrecedence > 1) { builder.Append(")"); } }
override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { var precedence = Precedences[Operator]; var associativity = Associativities[Operator]; if (outerPrecedence > precedence || opposite && outerPrecedence == precedence) { builder.Append("("); } Expression1.Pretty(builder, precedence, associativity == Associativity.Right); builder.Append(Strings[Operator]); Expression2.Pretty(builder, precedence, associativity == Associativity.Left); if (outerPrecedence > precedence || opposite && outerPrecedence == precedence) { builder.Append(")"); } }
// public Expression Expression1; // public Expression Expression2; override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { if (outerPrecedence > 0) { builder.Append("("); builder.Indent(); builder.NewLine(); } Expression1.Pretty(builder, 0, false); builder.Append(", "); builder.NewLine(); Expression2.Pretty(builder, 0, false); if (outerPrecedence > 0) { builder.Unindent(); builder.NewLine(); builder.Append(")"); builder.NewLine(); } }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); builder.Append("return;"); }
override public void Pretty(PrettyBuilder builder) { builder.Append(binvalue.ToString().ToLower()); }
override public void Pretty(PrettyBuilder builder) { builder.PrettyStm(stmList); }
override public void Pretty(PrettyBuilder builder) { builder.NewLine(); decl.Pretty(builder); builder.Append(";"); }
override public void Pretty(PrettyBuilder builder) { builder.Append(types[type] + " "); builder.Append(id.id); }
virtual public void Pretty(PrettyBuilder builder) { }
virtual public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { Pretty(builder); }
// public string Value; override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite) { builder.Append(Value); }
override public void Pretty(PrettyBuilder builder) { Pretty(builder, 8, false); }
override public void Pretty(PrettyBuilder builder) { builder.Append(id); }
override public void Pretty(PrettyBuilder builder) { builder.Append(num.ToString()); }
override public void Pretty(PrettyBuilder builder) { head.Pretty(builder); tail.Pretty(builder); }
public void Pretty(PrettyBuilder builder) { Pretty(builder, 0, false); }
public abstract void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite);
override public void Pretty(PrettyBuilder builder) { lo.Pretty(builder); builder.Append(" = "); ro.Pretty(builder); }