예제 #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];
        }
예제 #2
0
 public void ChartEnqueShouldAvoidDuplication()
 {
     ProductionExpression L = "L";
     var aToZ = new RangeTerminal('a', 'z');
     L.Rule = L + aToZ | aToZ;
     var grammar = new GrammarExpression(L, new[] { L }).ToGrammar();
     var chart = new Chart();
     var firstState = new NormalState(grammar.Productions[0], 0, 1);
     var secondState = new NormalState(grammar.Productions[0], 0, 1);
     chart.Enqueue(0, firstState);
     chart.Enqueue(0, secondState);
     Assert.AreEqual(1, chart.EarleySets[0].Predictions.Count);
 }
예제 #3
0
        public void ProductionExpressionShouldSupportAlterationOfStringAndTerminal()
        {
            ProductionExpression
                S = "S";
            BaseTerminal
                a = new RangeTerminal('a', 'b');
            S.Rule = (Expr)"b" | a;

            Assert.IsNotNull(S.ProductionModel);
            Assert.AreEqual(2, S.ProductionModel.Alterations.Count);
            Assert.AreEqual(1, S.ProductionModel.Alterations[0].Symbols.Count);
            Assert.AreEqual(1, S.ProductionModel.Alterations[1].Symbols.Count);
        }
예제 #4
0
 public void RangeTerminalWhenInputIsLessThanLowerBoundShouldFail()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsFalse(rangeTerminal.IsMatch('0'));
 }
예제 #5
0
 public void RangeTerminalWhenInputGreaterThanUpperBoundShouldFail()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsFalse(rangeTerminal.IsMatch('A'));
 }
예제 #6
0
 public void RangeTerminalWhenInputBetweenBoundsShouldMatch()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsTrue(rangeTerminal.IsMatch('l'));
 }
예제 #7
0
 public void Test_RangeTerminal_That_When_Start_Less_Than_Lower_Bound_IsMatch_Returns_False()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsFalse(rangeTerminal.IsMatch('0'));
 }
예제 #8
0
 public void Test_RangeTerminal_That_When_End_Greater_Than_Upper_Bound_IsMatch_Returns_False()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsFalse(rangeTerminal.IsMatch('A'));
 }
예제 #9
0
 public void Test_RangeTerminal_That_When_Character_Between_Bounds_IsMatch_Returns_True()
 {
     var rangeTerminal = new RangeTerminal('a', 'z');
     Assert.IsTrue(rangeTerminal.IsMatch('l'));
 }
예제 #10
0
 public ITerminalBuilder Range(char start, char end)
 {
     var rangeTerminal = new RangeTerminal(start, end);
     _terminals.Add(rangeTerminal);
     return this;
 }
 private static INfa Range(RegexCharacterRange range, bool negate)
 {
     // combine characters into a character range terminal
     var start = range.StartCharacter.Value;
     var end = range.EndCharacter.Value;
     ITerminal terminal = new RangeTerminal(start, end);
     var nfaStartState = new NfaState();
     var nfaEndState = new NfaState();
     if (negate)
         terminal = new NegationTerminal(terminal);
     nfaStartState.AddTransistion(
         new TerminalNfaTransition(terminal, nfaEndState));
     return new Nfa(nfaStartState, nfaEndState);
 }