示例#1
0
        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);
        }
示例#2
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.NewLine();
     builder.Append("return ");
     returnValue.Pretty(builder);
     builder.Append(";");
 }
示例#3
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.Append(id.id);
     builder.Append("(");
     builder.Intersperse(exprList, ", ");
     builder.Append(")");
 }
示例#4
0
        public override string ToString()
        {
            var builder = new PrettyBuilder();

            Pretty(builder);
            return(builder.ToString());
        }
示例#5
0
        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);
            }
        }
示例#6
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.NewLine();
     builder.Append("{");
     builder.Indent();
     builder.PrettyStm(stmList);
     builder.Unindent();
     builder.NewLine();
     builder.Append("}");
 }
示例#7
0
 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();
 }
示例#8
0
        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();
        }
示例#9
0
        // 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(")");
            }
        }
示例#10
0
        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(")");
            }
        }
示例#11
0
        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(")");
            }
        }
示例#12
0
        // 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(")");
            }
        }
示例#13
0
        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(")");
            }
        }
示例#14
0
        // 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();
            }
        }
示例#15
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.NewLine();
     builder.Append("return;");
 }
示例#16
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.Append(binvalue.ToString().ToLower());
 }
示例#17
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.PrettyStm(stmList);
 }
示例#18
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.NewLine();
     decl.Pretty(builder);
     builder.Append(";");
 }
示例#19
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.Append(types[type] + " ");
     builder.Append(id.id);
 }
示例#20
0
 virtual public void Pretty(PrettyBuilder builder)
 {
 }
示例#21
0
 virtual public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite)
 {
     Pretty(builder);
 }
示例#22
0
 // public string Value;
 override public void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite)
 {
     builder.Append(Value);
 }
示例#23
0
 override public void Pretty(PrettyBuilder builder)
 {
     Pretty(builder, 8, false);
 }
示例#24
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.Append(id);
 }
示例#25
0
 override public void Pretty(PrettyBuilder builder)
 {
     builder.Append(num.ToString());
 }
示例#26
0
 override public void Pretty(PrettyBuilder builder)
 {
     head.Pretty(builder);
     tail.Pretty(builder);
 }
示例#27
0
 public void Pretty(PrettyBuilder builder)
 {
     Pretty(builder, 0, false);
 }
示例#28
0
 public abstract void Pretty(PrettyBuilder builder, int outerPrecedence, bool opposite);
示例#29
0
 override public void Pretty(PrettyBuilder builder)
 {
     lo.Pretty(builder);
     builder.Append(" = ");
     ro.Pretty(builder);
 }