Пример #1
0
        public static DFAState <Token, Function> AddState(DFAState <Token, Function> state)
        {
            if (state.Id >= States.Length)
            {
                int newLength;

                if (state.Id < 2 * States.Length)
                {
                    newLength = 2 * States.Length;
                }
                else
                {
                    newLength = state.Id + 1;
                }

                DFAState <Token, Function>[] oldStates = States;

                States = new DFAState <Token, Function> [newLength];

                oldStates.CopyTo(States, 0);
            }

            if (States[state.Id] != null)
            {
                throw new DFAException("state.Id must be equal to States index!", 0, state.Id);
            }

            States[state.Id] = state;

            return(state);
        }
Пример #2
0
        private static void InitChineseStates()
        {
            DFAState <int, LexicalFunction> s8 = AddState(new LexicalState(8, false));                               //Numeric begin state;
            DFAState <int, LexicalFunction> s9 = AddState(new LexicalState(9, true, LexicalFunction.OutputChinese)); //Number quit state;

            //s0 [4e00-9fa5] s5
            s0.AddNextState(0x4e00, 0x9fa5, s8.Id);

            s8.AddNextState(0x4e00, 0x9fa5, s8.Id);

            s8.AddElseState(s9.Id);
        }
Пример #3
0
        private static void InitSpaceStates()
        {
            DFAState <int, LexicalFunction> s3 = AddState(new LexicalState(3, false));                             //Space begin state;
            DFAState <int, LexicalFunction> s4 = AddState(new LexicalState(4, true, LexicalFunction.OutputSpace)); //Space quit state;

            //s0 [ \t\r\n] s3
            s0.AddNextState(new int[] { ' ', '\t', '\r', '\n' }, s3.Id);

            //s3 [ \t\r\n] s3
            s3.AddNextState(new int[] { ' ', '\t', '\r', '\n' }, s3.Id);

            //s3 ^[ \t\r\n] s4
            s3.AddElseState(s4.Id);
        }
Пример #4
0
        private static DFAState <int, LexicalFunction> sother = AddState(new LexicalState(255, true, LexicalFunction.Other)); //Start state;

        private static void InitIdentifierStates()
        {
            DFAState <int, LexicalFunction> s1 = AddState(new LexicalState(1));                                         //Identifier begin state;
            DFAState <int, LexicalFunction> s2 = AddState(new LexicalState(2, true, LexicalFunction.OutputIdentifier)); //Identifier quit state;

            //s0 [_a-zA-Z] s1
            s0.AddNextState('_', s1.Id);
            s0.AddNextState('a', 'z', s1.Id);
            s0.AddNextState('A', 'Z', s1.Id);
            s0.AddNextState('a', 'z', s1.Id);
            s0.AddNextState('A', 'Z', s1.Id);

            //s1 [_a-zA-Z0-9] s1
            s1.AddNextState('_', s1.Id);
            s1.AddNextState('a', 'z', s1.Id);
            s1.AddNextState('A', 'Z', s1.Id);
            s1.AddNextState('0', '9', s1.Id);
            s1.AddNextState('a', 'z', s1.Id);
            s1.AddNextState('A', 'Z', s1.Id);
            s1.AddNextState('0', '9', s1.Id);

            //s1 ^[_a-zA-Z0-9] s2
            s1.AddElseState(s2.Id);
        }