Exemplo n.º 1
0
        static bool ProcessFile(string file)
        {
            FSMFile fsmfile = new FSMFile(file, config);

            fsmfile.ResetImplementation();

            FSM fsm = null;
            try
            {
                fsm = new FSM(fsmfile);
            }
            catch (MalformedFSMException e)
            {
                //MessageBox.Show(e.Message, "FSMGen Failed: " + fullname);
                Console.WriteLine(file + "(" + e.line + ") : error : " + e.Message);
                return false;
            }

            try
            {
                fsm.Export(config);
            }
            catch (MalformedFSMException e)
            {
                //MessageBox.Show(e.Message, "FSMGen Failed:" + fullname);
                Console.WriteLine(file + "(" + e.line + ") : error : " + e.Message);
                return false;
            }

            return true;
        }
Exemplo n.º 2
0
 public InitializationVisitor(Config config, FSMFile file)
     : base(config, file)
 {
 }
Exemplo n.º 3
0
 public TargetVisitor(Config config, FSMFile file)
     : base(config, file)
 {
 }
Exemplo n.º 4
0
 public DefinitionVisitor(Config config, FSMFile file)
     : base(config, file)
 {
 }
Exemplo n.º 5
0
        public FSM(FSMFile _file)
        {
            file = _file;
            InitTokensDictionary( _file.config );

            StreamReader stream = new StreamReader(file.SourceFile);

            try
            {

                while (!stream.EndOfStream)
                {
                    currentLine++;
                    rawtokens = new Queue<string>(stream.ReadLine().Split(null));

                    if (IsComment(rawtokens.Peek()))
                        continue;

                    while (rawtokens.Count > 0)
                    {
                        string token = rawtokens.Dequeue();

                        if (token == "")
                            continue;

                        if (!IsToken(token))
                            throw new MalformedFSMException("Unexpected identifier " + token + ", expected keyword.", currentLine);

                        Type statementtype = Tokens[token];

                        Statement statement = (Statement)Activator.CreateInstance(statementtype);
                        statement.owner = this;
                        statement.line = currentLine;

                        System.Diagnostics.Debug.Assert(statement != null);

                        statement.Consume(rawtokens);
                        if (statement.ShouldPush())
                        {
                            //we need to add it to the current state, if it exists.
                            //it may not exist if this is the first statement (Global)
                            if (statements.Count > 0)
                                statements.Peek().Statements().Add(statement);
                            statements.Push(statement);
                        }
                        else if (statement.ShouldPop())
                        {
                            lastpopped = statements.Pop();

                            if (statements.Count > 0)
                                statements.Peek().Statements().Add(statement);
                        }
                        else //add to current statement
                        {
                            statements.Peek().Statements().Add(statement);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                stream.Close();
            }

            if (statements.Count > 0) //we have terminated without closing the FSM.
            {
                throw new MalformedFSMException("Unexpected EOF: Did you forget an endstate/endfsm?", currentLine);
            }
        }