Esempio n. 1
0
        static NumberLexerRule()
        {
            var states = new DfaState[5];
            for (int i = 0; i < states.Length; i++)
                states[i] = new DfaState(i==4 || i== 2);

            var zeroThroughNine = new RangeTerminal('0', '9');

            var plusOrMinusTo1 = new DfaTransition(new SetTerminal('+', '-'), states[1]);
            var dotTo3 = new DfaTransition(new CharacterTerminal('.'), states[3]);
            var zeroThroughNineTo2 = new DfaTransition(zeroThroughNine, states[2]);
            var zeroThroughNineTo4 = new DfaTransition(zeroThroughNine, states[4]);

            states[0].AddTransition(dotTo3);
            states[0].AddTransition(plusOrMinusTo1);
            states[0].AddTransition(zeroThroughNineTo2);

            states[1].AddTransition(dotTo3);
            states[1].AddTransition(zeroThroughNineTo2);

            states[2].AddTransition(zeroThroughNineTo2);
            states[2].AddTransition(dotTo3);

            states[3].AddTransition(zeroThroughNineTo4);

            states[4].AddTransition(zeroThroughNineTo4);

            _start = states[0];
        }
Esempio n. 2
0
 static WhitespaceLexerRule()
 {
     _start = new DfaState();
     var end = new DfaState(isFinal: true);
     var transition = new DfaTransition(
         new WhitespaceTerminal(),
         end);
     _start.AddTransition(transition);
     end.AddTransition(transition);
 }
Esempio n. 3
0
 private static ILexerRule Whitespace()
 {
     var start = new DfaState();
     var end = new DfaState(isFinal: true);
     var transition = new DfaTransition(
         new WhitespaceTerminal(),
         end);
     start.AddTransition(transition);
     end.AddTransition(transition);
     return new DfaLexerRule(start, "\\w+");
 }
Esempio n. 4
0
 private static BaseLexerRule CreateNotSingleQuoteLexerRule()
 {
     var start = new DfaState();
     var final = new DfaState(true);
     var terminal = new NegationTerminal(new CharacterTerminal('\''));
     var edge = new DfaTransition(terminal, final);
     start.AddTransition(edge);
     final.AddTransition(edge);
     return new DfaLexerRule(start, new TokenType(@"([^']|(\\.))+"));
 }
Esempio n. 5
0
        private static BaseLexerRule CreateNotDoubleQuoteLexerRule()
        {
            // ([^"]|(\\.))*
            var start = new DfaState();
            var escape = new DfaState();
            var final = new DfaState(true);

            var notDoubleQuoteTerminal = new NegationTerminal(
                new CharacterTerminal('"'));
            var escapeTerminal = new CharacterTerminal('\\');
            var anyTerminal = new AnyTerminal();

            var notDoubleQuoteEdge = new DfaTransition(notDoubleQuoteTerminal, final);
            start.AddTransition(notDoubleQuoteEdge);
            final.AddTransition(notDoubleQuoteEdge);

            var escapeEdge = new DfaTransition(escapeTerminal, escape);
            start.AddTransition(escapeEdge);
            final.AddTransition(escapeEdge);

            var anyEdge = new DfaTransition(anyTerminal, final);
            escape.AddTransition(anyEdge);

            return new DfaLexerRule(start, new TokenType(@"([^""]|(\\.))+"));
        }
Esempio n. 6
0
        private static BaseLexerRule CreateMultiLineCommentLexerRule()
        {
            var pattern = @"\/[*]([*][^\/]|[^*])*[*][\/]";

            var states = new DfaState[5];
            for (int i = 0; i < states.Length; i++)
                states[i] = new DfaState();

            var slash = new CharacterTerminal('/');
            var star = new CharacterTerminal('*');
            var notStar = new NegationTerminal(star);
            var notSlash = new NegationTerminal(slash);

            var firstSlash = new DfaTransition(slash, states[1]);
            var firstStar = new DfaTransition(star, states[2]);
            var repeatNotStar = new DfaTransition(notStar, states[2]);
            var lastStar = new DfaTransition(star, states[3]);
            var goBackNotSlash = new DfaTransition(notSlash, states[2]);
            var lastSlash = new DfaTransition(slash, states[4]);

            states[0].AddTransition(firstSlash);
            states[1].AddTransition(firstStar);
            states[2].AddTransition(repeatNotStar);
            states[2].AddTransition(lastStar);
            states[3].AddTransition(goBackNotSlash);
            states[3].AddTransition(lastSlash);

            return new DfaLexerRule(states[0], pattern);
        }
Esempio n. 7
0
 private static BaseLexerRule CreateWhitespaceLexerRule()
 {
     var whitespaceTerminal = new WhitespaceTerminal();
     var startState = new DfaState();
     var finalState = new DfaState(true);
     var whitespaceTransition = new DfaTransition(whitespaceTerminal, finalState);
     startState.AddTransition(whitespaceTransition);
     finalState.AddTransition(whitespaceTransition);
     return new DfaLexerRule(startState, new TokenType("[\\s]+"));
 }