コード例 #1
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);
        }
コード例 #2
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var action = thread.rs().Action.At(Span);
            var name   = AstNode1.ToString(thread);

            action[name] = action.Base().Invoke("InitializeCharacter", Location.Line, name);
            thread.rs().Cast.Add(name, action[name]);
            return(base.ReallyDoEvaluate(thread));
        }
コード例 #3
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var tw = thread.tc().Writer;

            tw.WriteLine();
            tw.WriteLine("\tactivate_character({0}, {1});", Location.Line, AstNode1.ToString(thread));
            AstNode2.Evaluate(thread);
            return(this);
        }
コード例 #4
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var action = thread.rs().Action;
            var person = thread.rs().Cast[AstNode1.ToString()];

            action.At(Span).Invoke(action.Base(), "Activate", Location.Line, person);
            AstNode2.Evaluate(thread);
            return(base.ReallyDoEvaluate(thread));
        }
コード例 #5
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));
        }
コード例 #6
0
 protected override object ReallyDoEvaluate(ScriptThread thread)
 {
     if (AstNode1 is NegativeComparativeTermNode)
     {
         return(AstNode1.Evaluate(thread));
     }
     else
     {
         return(AstNode2.Evaluate(thread));
     }
 }
コード例 #7
0
 protected override object ReallyDoEvaluate(ScriptThread thread)
 {
     if (AstNode1 is NonnegatedComparisonNode)
     {
         return(AstNode1.Evaluate(thread));
     }
     else
     {
         return(!(AstNode2.Evaluate(thread) as Operand));
     }
 }
コード例 #8
0
 protected override object ReallyDoEvaluate(ScriptThread thread)
 {
     if (AstNode1 is NonnegatedComparisonNode)
     {
         return(AstNode1.Evaluate(thread));
     }
     else
     {
         return(string.Format("!{0}", AstNode2.Evaluate(thread) as string));
     }
 }
コード例 #9
0
 protected override object ReallyDoEvaluate(ScriptThread thread)
 {
     if (AstNode1 is PositiveComparativeNode)
     {
         return(AstNode1.Evaluate(thread) as Operand);
     }
     else
     {
         return(AstNode2.Evaluate(thread) as Operand);
     }
 }
コード例 #10
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);
        }
コード例 #11
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var term    = AstNode1.Term;
            var strTerm = term != null?term.ToString() : null;

            if (strTerm == "more" || strTerm == "less")
            {
                var st1 = AstNode1.Evaluate(thread) as string;
                var st2 = AstNode2.Evaluate(thread) as string;
                return(st1 + ' ' + st2);
            }
            else
            {
                return(AstNode1.Evaluate(thread));
            }
        }
コード例 #12
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            if (AstNode1 is UnconditionalSentenceNode)
            {
                AstNode1.Evaluate(thread);
            }
            else
            {
                var tw = thread.tc().Writer;
                tw.WriteLine("\t\tif({0}) {{", AstNode1.ToString(thread));
                AstNode2.Evaluate(thread);
                tw.WriteLine("\t}");
            }

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #13
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            if (AstNode1 is UnconditionalSentenceNode)
            {
                AstNode1.Evaluate(thread);
            }
            else
            {
                var action = thread.rs().Action.At(Span);
                action.If(AstNode1.Evaluate(thread) as Operand);
                AstNode2.Evaluate(thread);
                action.End();
            }

            return(base.ReallyDoEvaluate(thread));
        }
コード例 #14
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);
        }
コード例 #15
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);
        }
コード例 #16
0
 protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
 {
     AstNode1.Evaluate(thread);
     AstNode2.Evaluate(thread);
     return(base.ReallyDoEvaluate(thread));
 }
コード例 #17
0
 protected override object ReallyDoEvaluate(ScriptThread thread)
 {
     return(AstNode1.Evaluate(thread));
 }
コード例 #18
0
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            var tw = thread.tc().Writer;

            tw.WriteLine("\t\tCharacter\t{0} = InitializeCharacter({2},\"{0}\");\t\t{1}", AstNode1.ToString(thread), AstNode2.ToString(thread), Location.Line);
            return(this);
        }