Beispiel #1
0
 public ECustomFunction(EWord name, ETypeWord type, EProgram program, ETypeNameKey[] arguments)
 {
     this.name      = name;
     this.type      = type;
     this.arguments = arguments;
     this.program   = program;
 }
Beispiel #2
0
 public EFunctionOperation(EWord name, ETypeWord type, ETypeNameKey[] arguments, EOperation[] operations)
 {
     this.name      = name;
     this.type      = type;
     this.arguments = arguments;
     program        = new EProgram(operations);
 }
Beispiel #3
0
        // Run a program
        public static EVariable Run(EProgram program, EScope scope)
        {
            // Create a variable to assign the output to
            EVariable output = new EVVoid();

            // Loop over every instruction and return the last value
            EOperation[] operations = program.GetOperations();
            foreach (EOperation operation in operations)
            {
                output = operation.Exec(scope);
            }
            return(output);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                throw new ELangException("Please do not supply more than 1 argument");
            }

            Interpreter interpreter = new Interpreter();

            if (args.Length == 0)
            {
                while (true)
                {
                    Console.Write("> ");
                    string next = Console.ReadLine();
                    if (next == "quit")
                    {
                        break;
                    }

                    try
                    {
                        EProgram prog   = EParser.Program.Parse(next);
                        string   result = interpreter.Run(prog).ToString();
                        Console.WriteLine(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            else if (args.Length == 1)
            {
                try
                {
                    string   input = File.ReadAllText(args[0], Encoding.UTF8);
                    EProgram test  = EParser.Program.Parse(input);
                    //Console.WriteLine(test);
                    interpreter.Run(test);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            /* */
        }
Beispiel #5
0
 public EWhileOperation(ESolvable check, EOperation[] operations)
 {
     this.check = check;
     program    = new EProgram(operations);
 }
Beispiel #6
0
 public ECustomFunction(EWord name, ETypeWord type, EProgram program) : this(name, type, program, new ETypeNameKey[] { })
 {
 }
Beispiel #7
0
 public EVariable Run(EProgram program)
 {
     return(Run(program, scope));
 }
Beispiel #8
0
 public EIfOperation(ESolvable check, EOperation[] operations, EOperation[] elseOperations) :
     this(check, operations)
 {
     elseProgram = new EProgram(elseOperations);
 }