Ejemplo n.º 1
0
        private static void InitIdentifierStates()
        {
            KeywordsTbl.Add("OR", SyntaxType.OR);
            KeywordsTbl.Add("AND", SyntaxType.AND);
            KeywordsTbl.Add("NOT", SyntaxType.NOT);

            for (int i = (int)SyntaxType.BEGIN_KEYWORD + 1; i < (int)SyntaxType.END_KEYWORD; i++)
            {
                KeywordsTbl.Add(((SyntaxType)i).ToString(), (SyntaxType)i);
            }

            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);

            //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 ^[_a-zA-Z0-9] s2
            s1.AddElseState(s2.Id);
        }
Ejemplo n.º 2
0
        private static void InitNumericStates()
        {
            DFAState <int, LexicalFunction> s5 = AddState(new LexicalState(5, false));                               //Numeric begin state;
            DFAState <int, LexicalFunction> s6 = AddState(new LexicalState(6, false));                               //Number dot state;
            DFAState <int, LexicalFunction> s7 = AddState(new LexicalState(7, true, LexicalFunction.OutputNumeric)); //Number quit state;

            //s0 [0-9] s5
            s0.AddNextState('0', '9', s5.Id);
            s0.AddNextState('0', '9', s5.Id);

            //s5 [0-9] s5
            s5.AddNextState('0', '9', s5.Id);
            s5.AddNextState('0', '9', s5.Id);

            //s5 [\.] s6
            s5.AddNextState('.', s6.Id);

            //s5 else s7 (integer)
            s5.AddElseState(s7.Id);

            //s6 [0-9] s6
            s6.AddNextState('0', '9', s6.Id);
            s6.AddNextState('0', '9', s6.Id);

            //s6 else s7 (float)
            s6.AddElseState(s7.Id);
        }
Ejemplo n.º 3
0
        private static void InitCommentAndArithmeticStates()
        {
            ArithmeticTbl.Add("+", SyntaxType.Plus);
            ArithmeticTbl.Add("-", SyntaxType.Subtract);
            ArithmeticTbl.Add("*", SyntaxType.Multiply);
            ArithmeticTbl.Add("/", SyntaxType.Divide);

            DFAState <int, LexicalFunction> s8  = AddState(new LexicalState(8, false));                                      //Comment / state;
            DFAState <int, LexicalFunction> s9  = AddState(new LexicalState(9, false));                                      //Comment * start state;
            DFAState <int, LexicalFunction> s10 = AddState(new LexicalState(10, false));                                     //Comment * end state;
            DFAState <int, LexicalFunction> s11 = AddState(new LexicalState(11, false));                                     //Comment - first state;
            DFAState <int, LexicalFunction> s12 = AddState(new LexicalState(12, false));                                     //Comment - second state;
            DFAState <int, LexicalFunction> s13 = AddState(new LexicalState(13, true, LexicalFunction.OutputComment));       //Comment quit state;

            DFAState <int, LexicalFunction> s14 = AddState(new LexicalState(14, false));                                     //Arithmetic begin state;
            DFAState <int, LexicalFunction> s15 = AddState(new LexicalState(15, true, LexicalFunction.OutputArithmeticOpr)); //Arithmetic quit state;

            //s0 [\/] s8
            s0.AddNextState('/', s8.Id);

            //s8 [\*] s9
            s8.AddNextState('*', s9.Id);
            s8.AddElseState(s15.Id);

            //s9 [\*] s10
            s9.AddNextState('*', s10.Id);
            //s9 else s9
            s9.AddElseState(s9.Id);

            //s10 [\/] s13
            s10.AddNextState('/', s13.Id);
            //s10 else s9
            s10.AddElseState(s9.Id);

            //s0 [-] s11
            s0.AddNextState('-', s11.Id);

            //s11 [-] s12
            s11.AddNextState('-', s12.Id); //For comment
            s11.AddNextState('0', '9', 5); //For Negative numeric
            s11.AddElseState(s15.Id);

            //s12 [\n] s13
            s12.AddNextState(new int[] { 0, '\n' }, s13.Id);
            s12.AddElseState(s12.Id);

            //s0 [\+\*] s14
            s0.AddNextState(new int[] { '+', '*' }, s14.Id);
            s14.AddElseState(s15.Id);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private static void InitSpaceStates()
        {
            DFAState <int, LexicalFunction> s3 = AddState(new LexicalState(3, false, LexicalFunction.DoSpace));    //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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private static void InitStringStates()
        {
            DFAState <int, LexicalFunction> s16 = AddState(new LexicalState(16, false));                                  // \' start state;
            DFAState <int, LexicalFunction> s17 = AddState(new LexicalState(17, false));                                  // \' second start state;
            DFAState <int, LexicalFunction> s18 = AddState(new LexicalState(18, false, LexicalFunction.DoubleQuotation)); // \' third state;
            DFAState <int, LexicalFunction> s19 = AddState(new LexicalState(19, true, LexicalFunction.OutputString));     //String quit state;

            //s0 [\'] s16
            s0.AddNextState('\'', s16.Id);

            //s16 [\'] s17
            s16.AddNextState('\'', s17.Id);
            s16.AddElseState(s16.Id);

            //s17 [\'] s18
            s17.AddNextState('\'', s18.Id);
            s17.AddElseState(s19.Id);

            //s18 [\'] s17
            s18.AddNextState('\'', s17.Id);
            s18.AddElseState(s16.Id);
        }
Ejemplo n.º 8
0
        private static void InitComparisonOprStates()
        {
            ComparisonOprTbl.Add("<", SyntaxType.Lessthan);
            ComparisonOprTbl.Add("<=", SyntaxType.LessthanEqual);
            ComparisonOprTbl.Add(">", SyntaxType.Largethan);
            ComparisonOprTbl.Add(">=", SyntaxType.LargethanEqual);
            ComparisonOprTbl.Add("<>", SyntaxType.NotEqual);
            ComparisonOprTbl.Add("!=", SyntaxType.NotEqual);
            ComparisonOprTbl.Add("=", SyntaxType.Equal);

            DFAState <int, LexicalFunction> s20 = AddState(new LexicalState(20, false));                                     // < start state;
            DFAState <int, LexicalFunction> s21 = AddState(new LexicalState(21, false));                                     // <= <> >= != state;
            DFAState <int, LexicalFunction> s22 = AddState(new LexicalState(22, false));                                     // ! state;
            DFAState <int, LexicalFunction> s23 = AddState(new LexicalState(23, false));                                     // > state;
            DFAState <int, LexicalFunction> s24 = AddState(new LexicalState(24, true, LexicalFunction.OutputComparisonOpr)); // quit state;

            //s0 [<] s20
            s0.AddNextState('<', s20.Id);

            //s20 [=<] s21
            s20.AddNextState(new int[] { '=', '>' }, s21.Id);
            s20.AddElseState(s24.Id);

            s21.AddElseState(s24.Id);

            //s0 [!] s22
            s0.AddNextState('!', s22.Id);

            //s22 [=] s21
            s22.AddNextState('=', s21.Id);

            s0.AddNextState('>', s23.Id);

            s23.AddNextState('=', s21.Id);
            s23.AddElseState(s24.Id);

            s0.AddNextState('=', s21.Id);
        }