コード例 #1
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var tw = thread.tc().Writer;

            tw.Write(format, Location.Line, AstNode2.ToString(thread), AstNode3.ToString(thread));
            return(this);
        }
コード例 #2
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var tw = thread.tc().Writer;

            tw.WriteLine("\tcomp1 = {0};", AstNode2.ToString(thread));
            tw.WriteLine("\tcomp2 = {0};", AstNode4.ToString(thread));
            tw.WriteLine("\ttruth_flag = {0};", AstNode3.ToString(thread));

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #3
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var action = thread.rs().Action.At(Span);

            action.Assign(action.Base().Property("Comp1"), AstNode2.Evaluate(thread) as Operand);
            action.Assign(action.Base().Property("Comp2"), AstNode4.Evaluate(thread) as Operand);
            action.Assign(action.Base().Property("TruthFlag"), AstNode3.Evaluate(thread) as Operand);

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #4
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var action = thread.rs().Action.At(Span);
            var cast   = thread.rs().Cast;

            if (AstNode1 is CharacterNode)
            {
                return((Operand)cast[String1].Property("Value"));
            }
            else if (AstNode1 is ConstantNode)
            {
                return(AstNode1.Evaluate(thread));
            }
            else if (AstNode1 is PronounNode)
            {
                return(action.Base().Invoke("ValueOf", Location.Line, AstNode1.Evaluate(thread) as Operand));
            }
            else if (AstNode1 is BinaryOperatorNode)
            {
                var operand1 = AstNode2.Evaluate(thread) as Operand;
                var operand2 = AstNode3.Evaluate(thread) as Operand;

                // THis is ugly; I apologize
                var term = Child1.ChildNodes[0].Term.Name;
                if (term == "the difference between")
                {
                    return(operand1 - operand2);
                }
                else if (term == "the product of")
                {
                    return(operand1 * operand2);
                }
                else if (term == "the quotient between")
                {
                    return(operand1 / operand2);
                }
                else if (term == "the remainder of the quotient between")
                {
                    return(operand1 % operand2);
                }
                else if (term == "the sum of")
                {
                    return(operand1 + operand2);
                }
            }
            else if (AstNode1 is UnaryOperatorNode)
            {
                return(action.Base().Invoke(AstNode1.Evaluate(thread) as String, Location.Line, AstNode2.Evaluate(thread) as Operand));
            }
            else
            {
                // error
            }
            return(base.ReallyDoEvaluate(thread));
        }
コード例 #5
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var sw = thread.tc().Writer;

            sw.WriteLine("/*********************************************************************");
            sw.WriteLine(" *   This C# program was generated by Shakespeare2CS by James Curran *");
            sw.WriteLine(" *   based on spl2c, the Shakespeare to C                            *");
            sw.WriteLine(" *          converter by Jon Åslund and Karl Hasselström.            *");
            sw.WriteLine(" *********************************************************************/");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using Shakespeare.Support;");
            sw.WriteLine();
            sw.WriteLine("namespace Shakespeare.Program");
            sw.WriteLine("{");
            sw.WriteLine("\tclass Program");
            sw.WriteLine("\t{");
            sw.WriteLine("\t\tstatic void Main(string[] args)");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\tvar script = new Script();");
            sw.WriteLine("\t\t\tscript.Action();");
            sw.WriteLine("\t\t}");
            sw.WriteLine("\t}");
            sw.WriteLine();
            sw.WriteLine("\t\tclass Script : Dramaturge");
            sw.WriteLine("\t\t{");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic Script()");
            sw.WriteLine("\t\t : base(Console.In, Console.Out)");
            sw.WriteLine("\t\t{ }");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic void Action()");
            sw.WriteLine("\t\t{");

            AstNode1.Evaluate(thread);              // Title
            sw.WriteLine();
            var cdl = AstNode2 as CharacterDeclarationListNode;

            foreach (var ch in cdl.Characters)
            {
                ch.Evaluate(thread);
            }

            sw.WriteLine();
            AstNode3.Evaluate(thread);

            sw.WriteLine("\t\t}");
            sw.WriteLine("\t}");
            sw.WriteLine("}");
            sw.Flush();
            sw.Close();
            return(sw);
        }
コード例 #6
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var rs = thread.rs();
            var ag = rs.AG;

            using (ag.Namespace("Shakespeare.Program"))
            {
                TypeGen scriptClass = ag.Public.Class("Script", typeof(Shakespeare.Support.Dramaturge));
                {
                    rs.Script = scriptClass;

                    var console = typeof(Console);

                    CodeGen ctor = scriptClass.Public.Constructor();
                    ctor.InvokeBase(Static.Property(console, "In"), Static.Property(console, "Out"));
                    {
                    }

                    CodeGen action = scriptClass.Public.Void("Action");
                    {
                        rs.Action = action;
                        action.At(Span);
                        AstNode1.Evaluate(thread);
                        var cdl = AstNode2 as CharacterDeclarationListNode;
                        foreach (var ch in cdl.Characters)
                        {
                            ch.Evaluate(thread);
                        }

                        AstNode3.Evaluate(thread);
                    }
                }
                scriptClass.Complete();

                TypeGen MyClass = ag.Public.Class("Program");
                CodeGen Main    = MyClass.Public.Static.Void("Main").Parameter <string[]>("args");
                {
                    var script = Main.Local(Exp.New(scriptClass.GetCompletedType()));
                    Main.Invoke(script, "Action");
                }
            }
            ag.Save();

            return(ag.GetAssembly().GetName().Name);
        }
コード例 #7
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var sw = thread.tc().Writer;

            sw.WriteLine("/********************************************************************");
            sw.WriteLine(" *   This C program was generated by spl2c, the Shakespeare to C    *");
            sw.WriteLine(" *          converter by Jon Åslund and Karl Hasselström.           *");
            sw.WriteLine(" ********************************************************************/");
            sw.WriteLine("");
            sw.WriteLine("/* libspl definitions and function prototypes */");
            sw.WriteLine("#include \"spl.h\"");
            sw.WriteLine("");
            sw.WriteLine("int main(void)");
            sw.WriteLine("{");
            AstNode1.Evaluate(thread);  // Title
            sw.WriteLine();
            var cdl = AstNode2 as CharacterDeclarationListNode;

            foreach (var ch in cdl.Characters)
            {
                sw.WriteLine(ch.Declaration);
            }

            sw.WriteLine("\tint comp1, comp2;");
            sw.WriteLine("\tglobal_initialize();");
            foreach (var ch in cdl.Characters)
            {
                sw.WriteLine(ch.Initialization);
            }

            sw.WriteLine();
            sw.WriteLine();
            AstNode3.Evaluate(thread);
            sw.WriteLine("\treturn 0;");
            sw.WriteLine("}");
            sw.Flush();
            sw.Close();
            return(sw);
        }
コード例 #8
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            if (AstNode1 is SecondPersonNode)
            {
                var tw = thread.tc().Writer;
                if (AstNode2 is BeNode)
                {
                    if (AstNode3 is ConstantNode)
                    {
                        tw.WriteLine("\t\tAssign({0}, {1});", Location.Line, AstNode3.Evaluate(thread) as string);
                    }
                    else                        // SECOND_PERSON BE Equality Value StatementSymbol
                    {
                        tw.WriteLine("\t\tAssign({0}, {1});", Location.Line, AstNode4.Evaluate(thread) as string);
                    }
                }
                else if (AstNode2 is UnarticulatedConstantNode)
                {
                    tw.WriteLine("\t\tAssign({0}, {1});", Location.Line, AstNode2.Evaluate(thread) as string);
                }
            }

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #9
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            if (AstNode1 is SecondPersonNode)
            {
                var action = thread.rs().Action.At(Span);
                if (AstNode2 is BeNode)
                {
                    if (AstNode3 is ConstantNode)
                    {
                        action.Invoke(action.Base(), "Assign", Location.Line, AstNode3.Evaluate(thread) as Operand);
                    }
                    else    // SECOND_PERSON BE Equality Value StatementSymbol
                    {
                        action.Invoke(action.Base(), "Assign", Location.Line, AstNode4.Evaluate(thread) as Operand);
                    }
                }
                else if (AstNode2 is UnarticulatedConstantNode)
                {
                    action.Invoke(action.Base(), "Assign", Location.Line, AstNode2.Evaluate(thread) as Operand);
                }
            }

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #10
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var tw = thread.tc().Writer;

            if (AstNode1 is CharacterNode)
            {
                return((AstNode1.Evaluate(thread) as string) + "->value");
            }
            else if (AstNode1 is ConstantNode)
            {
                return(AstNode1.Evaluate(thread));
            }
            else if (AstNode1 is PronounNode)
            {
                return(String.Format("value_of({0},{1})", Location.Line, AstNode1.Evaluate(thread) as string));
            }
            else if (AstNode1 is BinaryOperatorNode)
            {
                return(string.Format(AstNode1.ToString(), Location.Line, AstNode2.Evaluate(thread) as string, AstNode3.Evaluate(thread) as string));
            }
            else if (AstNode1 is UnaryOperatorNode)
            {
                AstNode1.Evaluate(thread);
                return(string.Format((AstNode1 as UnaryOperatorNode).FormatString, AstNode2.Evaluate(thread) as string));
            }
            else
            {
                // error
            }
            return(this);
        }