Пример #1
0
        void HandleEndDefinitionToken(Token token)
        {
            if (mode == InterpreterMode.EXECUTING)
            {
                throw new InvalidOperationException("Unmatched end definition");
            }
            EndDefinitionToken edToken = (EndDefinitionToken)token;

            CurModule().AddWord(curDefinition);
            mode = InterpreterMode.EXECUTING;
        }
Пример #2
0
        void HandleStartDefinitionToken(Token token)
        {
            if (mode == InterpreterMode.COMPILING)
            {
                throw new InvalidOperationException("Can't have nested definitions");
            }
            StartDefinitionToken sdToken = (StartDefinitionToken)token;

            curDefinition = new DefinitionWord(sdToken.Name);
            mode          = InterpreterMode.COMPILING;
        }
Пример #3
0
        public void InterpretLine(List <Statement> statement)
        {
            if (InterpreterMode == InterpreterMode.Running)
            {
                return;
            }

            ContinueRunning = true;
            CurrentImmediateModeStatementMarker = new ImmediateModeStatementMarker(statement);

            try
            {
                while (CurrentImmediateModeStatementMarker.Valid && CurrentImmediateModeStatementMarker.StatementIndex < statement.Count)
                {
                    var currentStatement     = CurrentImmediateModeStatementMarker.Statement;
                    var commandToken         = currentStatement.Tokens[0] as Commands.CommandToken;
                    var isVariableAssignment = currentStatement.Tokens[0] is VariableNameToken;

                    if (commandToken == null && !isVariableAssignment)
                    {
                        throw new SyntaxErrorException();
                    }

                    CurrentCommandToken = commandToken;

                    TokenMarker marker = new TokenMarker(currentStatement.Tokens);
                    if (isVariableAssignment)
                    {
                        commandToken = (CommandToken)TokensProvider.GetBuiltinToken("LET");
                    }
                    else
                    {
                        marker.MoveNext();
                    }

                    commandToken.Execute(this, marker);

                    CurrentImmediateModeStatementMarker.MoveToNextStatement();
                }
            }
            catch (RetroBASIC.Exceptions.RetroBASICException basicException)
            {
                ExpressionEvaluator.Clear();
                string outputMessage = $"{ErrorMessages.errorStart} {basicException.Message}{ErrorMessages.error}";
                Console.OutputTextWriter.WriteLine();
                Console.OutputTextWriter.WriteLine(outputMessage);
            }
            finally
            {
                ContinueRunning = false;
                CurrentImmediateModeStatementMarker = null;
                InterpreterMode = InterpreterMode.Immmediate;
            }
        }
Пример #4
0
        protected void FilterSelectedMids(InterpreterMode mode)
        {
            if (mode == InterpreterMode.Both)
            {
                return;
            }

            var type         = mode == InterpreterMode.Controller ? typeof(IIntegrator) : typeof(IController);
            var selectedMids = _templates.Values.Where(x => x.Type.IsAssignableFrom(type));

            FilterSelectedMids(selectedMids);
        }
Пример #5
0
        public CodeRunner(Field field)
        {
            _field = field;
            _ip    = new InstructionPointer();
            _mode  = InterpreterMode.Normal;
            _stack = new Stack <long>();

            _rnd = new Random();
            _run = true;
            //                                 '═'
            _separatorLine = new string((char)0x2550, Field.Width);
            _input         = "";
            _output        = "";
        }
Пример #6
0
        private void Stringmode()
        {
            switch (_mode)
            {
            case InterpreterMode.Normal:
                _mode = InterpreterMode.String;
                break;

            case InterpreterMode.String:
                _mode = InterpreterMode.Normal;
                break;

            default:
                ThrowHelper.ThrowInvalidEnumValueException(
                    nameof(_mode),
                    nameof(InstructionPointerDirection));
                break;
            }
            _ip.Move();
        }
Пример #7
0
        public Interpreter()
        {
            this.stack = new Stack <StackItem>();

            // Set up usingModules.
            usingModules = new List <Module>();

            // Set up moduleStack.
            // The first module is a local module that will always be in place during execution.
            moduleStack = new List <Module>();
            ModuleStackPush(new Module(""));

            registeredModules = new Dictionary <string, Module>();
            mode = InterpreterMode.EXECUTING;


            // The first module (and the last to be searched) is the GlobalModule
            Module globalModule = new GlobalModule();

            UseModule(globalModule);
            runModuleCode(globalModule);
        }
Пример #8
0
        public Interpreter(IConsole console = null)
        {
            TokensProvider = new TokensProvider();
            TokensProvider.RegisterTokens();
            tokenizer            = new Tokenizer(TokensProvider);
            Lines                = new SortedList <int, Line>();
            VariablesEnvironment = new InterpreterVariables(this);
            ExpressionEvaluator  = new ExpressionEvaluator(this);

            CurrentStatementMarker = new StatementMarker(Lines);
            CurrentImmediateModeStatementMarker = null;

            NextStatementMarker = null;
            DataStatementMarker = new StatementMarker(Lines);
            DataTokenMarker     = null;

            GosubMarkers = new Stack <StatementMarker>();
            ForNextLoops = new Stack <ForNextLoopState>();

            ContinueRunning = false;
            InterpreterMode = InterpreterMode.Immmediate;

            Console = console;
        }
Пример #9
0
 public static MidInterpreter UseMultiSpindleMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <MultiSpindle.MultiSpindleMessages>(mode);
     return(midInterpreter);
 }
Пример #10
0
 public static MidInterpreter UseMultipleIdentifiersMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <MultipleIdentifiers.MultipleIdentifierMessages>(mode);
     return(midInterpreter);
 }
 public ModeMessages(InterpreterMode mode) : this()
 {
     FilterSelectedMids(mode);
 }
Пример #12
0
 public static MidInterpreter UseAlarmMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Alarm.AlarmMessages>(mode);
     return(midInterpreter);
 }
Пример #13
0
 public static MidInterpreter UseTighteningMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Tightening.TighteningMessages>(mode);
     return(midInterpreter);
 }
Пример #14
0
 public static MidInterpreter UseResultMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Result.ResultMessages>(mode);
     return(midInterpreter);
 }
Пример #15
0
 public static MidInterpreter UsePLCUserDataMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <PLCUserData.PLCUserDataMessages>(mode);
     return(midInterpreter);
 }
Пример #16
0
 public static MidInterpreter UseOpenProtocolCommandsDisabledMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <OpenProtocolCommandsDisabled.OpenProtocolCommandsDisabledMessages>(mode);
     return(midInterpreter);
 }
 public TighteningMessages(InterpreterMode mode) : this()
 {
     FilterSelectedMids(mode);
 }
 public PLCUserDataMessages(InterpreterMode mode) : this()
 {
     FilterSelectedMids(mode);
 }
Пример #19
0
 public static MidInterpreter UseParameterSetMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <ParameterSet.ParameterSetMessages>(mode);
     return(midInterpreter);
 }
Пример #20
0
 public static MidInterpreter UseApplicationSelectorMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <ApplicationSelector.ApplicationSelectorMessages>(mode);
     return(midInterpreter);
 }
Пример #21
0
 public static MidInterpreter UsePowerMACSMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <PowerMACS.PowerMACSMessages>(mode);
     return(midInterpreter);
 }
Пример #22
0
 public static MidInterpreter UseApplicationToolLocationSystemMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <ApplicationToolLocationSystem.ApplicationToolLocationSystemMessages>(mode);
     return(midInterpreter);
 }
Пример #23
0
 public static MidInterpreter UseStatisticMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Statistic.StatisticMessages>(mode);
     return(midInterpreter);
 }
Пример #24
0
 public static MidInterpreter UseAutomaticManualModeMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <AutomaticManualMode.AutomaticManualModeMessages>(mode);
     return(midInterpreter);
 }
Пример #25
0
 public static MidInterpreter UseUserInterfaceMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <UserInterface.UserInterfaceMessages>(mode);
     return(midInterpreter);
 }
Пример #26
0
 public static MidInterpreter UseCommunicationMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Communication.CommunicationMessages>(mode);
     return(midInterpreter);
 }
 public MultipleIdentifierMessages(InterpreterMode mode) : this()
 {
     FilterSelectedMids(mode);
 }
Пример #28
0
 /// <summary>
 /// Configure MidInterpreter to parse all available Mids of a mode
 /// <para>Select Integrator if you're integrator or Controller if you're a controller</para>
 /// </summary>
 /// <param name="midInterpreter">MidInterpreter instance</param>
 /// <param name="mode">Are you the integrator or controller?</param>
 /// <returns></returns>
 public static MidInterpreter UseAllMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     return(midInterpreter
            .UseAlarmMessages(mode)
            .UseApplicationControllerMessage(mode)
            .UseApplicationSelectorMessages(mode)
            .UseApplicationToolLocationSystemMessages(mode)
            .UseAutomaticManualModeMessages(mode)
            .UseCommunicationMessages(mode)
            .UseIOInterfaceMessages(mode)
            .UseJobMessages(mode)
            .UseAdvancedJobMessages(mode)
            .UseMotorTuningMessages(mode)
            .UseMultipleIdentifiersMessages(mode)
            .UseMultiSpindleMessages(mode)
            .UseOpenProtocolCommandsDisabledMessages(mode)
            .UseParameterSetMessages(mode)
            .UsePLCUserDataMessages(mode)
            .UsePowerMACSMessages(mode)
            .UseResultMessages(mode)
            .UseStatisticMessages(mode)
            .UseTighteningMessages(mode)
            .UseTimeMessages(mode)
            .UseToolMessages(mode)
            .UseUserInterfaceMessages(mode)
            .UseVinMessages(mode));
 }
 public ApplicationToolLocationSystemMessages(InterpreterMode mode) : this()
 {
     FilterSelectedMids(mode);
 }
Пример #30
0
 public static MidInterpreter UseAdvancedJobMessages(this MidInterpreter midInterpreter, InterpreterMode mode = InterpreterMode.Both)
 {
     midInterpreter.UseTemplate <Job.Advanced.AdvancedJobMessages>(mode);
     return(midInterpreter);
 }