Exemple #1
0
 void programmes()
 {
     Unit = new CompilationUnit(); ProgramDeclaration p = null;
     program(ref p);
     Unit.Program = p;
     Expect(26);
 }
Exemple #2
0
    void program(ref ProgramDeclaration p)
    {
        List <VariableDeclaration> vl = new List <VariableDeclaration>(); List <MethodDeclaration> ml = new List <MethodDeclaration>(); Statement s = null;

        Expect(3);
        p = new ProgramDeclaration {
            Location = new Location(t.line, t.col, t.charPos)
        };
        Expect(1);
        p.Name = t.val;
        Expect(19);
        if (la.kind == 4)
        {
            variable_declarations(ref vl);
        }
        else if (la.kind == 6 || la.kind == 7)
        {
        }
        else
        {
            SynErr(40);
        }
        p.Variables = vl;
        method_declarations(ref ml);
        p.Methods = ml;
        block_stmt(ref s);
        p.Block = s;
    }
Exemple #3
0
        /// <summary>
        /// Start the program by finding the entry point and calling it
        /// </summary>
        internal void Start()
        {
            if (State != AlgorithmInterpreterState.Ready && State != AlgorithmInterpreterState.Stopped && State != AlgorithmInterpreterState.StoppedWithError)
            {
                throw new InvalidOperationException("Unable to start a algorithm interpreter which is not stopped.");
            }

            ChangeState(this, new AlgorithmInterpreterStateEventArgs(AlgorithmInterpreterState.Preparing));

            Initialize();

            var entryPointMethod = ProgramDeclaration.GetEntryPointMethod();
            var i = 0;
            ClassInterpreter entryPointClass = null;

            if (entryPointMethod == null)
            {
                ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MissingEntryPointMethodException(ProgramDeclaration.EntryPointPath)), GetDebugInfo()));
                return;
            }

            ChangeState(this, new AlgorithmInterpreterStateEventArgs(AlgorithmInterpreterState.Running));

            while (i < Classes.Count && entryPointClass == null)
            {
                if (Classes[i].ClassDeclaration.Name.ToString() == ProgramDeclaration.EntryPointPath)
                {
                    entryPointClass = Classes[i];
                }

                i++;
            }

            if (entryPointClass == null)
            {
                ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MissingEntryPointMethodException(ProgramDeclaration.EntryPointPath)), GetDebugInfo()));
                return;
            }

            // TODO: try to use the Instanciate & InvokeMethod interpreter's functions
            EntryPointInstance = entryPointClass.CreateNewInstance();
            EntryPointInstance.StateChanged           += ChangeState;
            EntryPointInstance.OnGetParentInterpreter += new Func <ProgramInterpreter>(() => this);
            EntryPointInstance.OnDone += new Action <ClassInterpreter>((cl) =>
            {
                cl.StateChanged -= ChangeState;
            });
            EntryPointInstance.Initialize();
            EntryPointInstance.CreateNewInstanceCallConstructors(null);

            EntryPointInstance.EntryPoint.StateChanged           += ChangeState;
            EntryPointInstance.EntryPoint.OnGetParentInterpreter += new Func <ClassInterpreter>(() => EntryPointInstance);
            EntryPointInstance.EntryPoint.OnDone += new Action <MethodInterpreter>((met) =>
            {
                met.Dispose();
                met.StateChanged -= ChangeState;
            });
            EntryPointInstance.EntryPoint.Initialize();
            EntryPointInstance.EntryPoint.Run(false, new Collection <object>(), Guid.Empty);

            EntryPointInstance.StateChanged -= ChangeState;
        }