/// <summary> /// Builds an NFA from the specified expression tree. /// </summary> /// <param name="root">The expresion tree to transform into a DFA.</param> /// <param name="defaultAcceptState">A default accept state can be specified. For instance in case the pression does not have one.</param> public IReadOnlyList <NfaState> BuildNfa(RegExNode root, ushort?defaultAcceptState = null) { _root = root; // first build NFA var start = NewNfaState(); var end = NewNfaState(defaultAcceptState); Apply(root, start, end); #if DIAGNOSTICS Console.WriteLine("Created {0} new states.", _nextNfaStateNumber); for (var i = 0; i < _nfaStates.Count; i++) { var state = _nfaStates[i]; Console.Write("{0,3}:\t", i); foreach (var pair in state.Map) { var str = $"{pair.Key}->N{pair.Value.NfaId}"; Console.Write("{0,-15}", str); } Console.WriteLine(); } #endif // add to each NFA state the closure for epsilon moves CalculateEpsilonState(); return(_nfaStates); }
/// <summary> /// Builds a DFA from the specified expression tree. /// </summary> /// <param name="root">The expresion tree to transform into a DFA.</param> /// <param name="defaultAcceptState">A default accept state can be specified. For instance in case the pression does not have one.</param> /// <returns></returns> public RegExEvaluationNode Build(RegExNode root, ushort?defaultAcceptState = null) { _root = root; // first build NFA var start = NewNfaState(); var end = NewNfaState(defaultAcceptState); Apply(root, start, end); #if DIAGNOSTICS Console.WriteLine("Created {0} new states.", _nextNfaStateNumber); for (var i = 0; i < _nfaStates.Count; i++) { var state = _nfaStates[i]; Console.Write("{0,3}:\t", i); foreach (var pair in state.Map) { var str = $"{pair.Key}->N{pair.Value.NfaId}"; Console.Write("{0,-15}", str); } Console.WriteLine(); } #endif // add to each NFA state the closure for epsilon moves CalculateEpsilonState(); CalcuateBestReachableAcceptStates(); // transform NFA to DFA, starting 'start' and what can be reached from there via epsilon steps. var initial = new HashSet <NfaState> { start }; initial.UnionWith(start.EpsilonStates); var acceptState = GetSmallestAcceptState(null, initial); var stateId = DfaState.GetDfaId(acceptState, initial); var dfaBegin = NewDfaState(acceptState, initial); AddKnownState(stateId, dfaBegin); _pendingStates.Enqueue(dfaBegin); while (_pendingStates.Count > 0) { var state = _pendingStates.Dequeue(); ProcessDfaState(state); } return(_dfaStates[0].EvaluationNode); }
private void Apply(RegExNode regExNode, NfaState begin, NfaState end) { switch (regExNode.RegExType) { case RegExType.Blank: Transition(begin, end, RegExInputRange.EPS); break; case RegExType.Union: var union = (RegExNodeUnion)regExNode; foreach (var exp in union.Expressions) { Apply(exp, begin, end); } break; case RegExType.Concat: var concat = (RegExNodeConcat)regExNode; var lastConcat = begin; for (var i = 0; i < concat.Expressions.Count; i++) { var tmp = (i + 1) < concat.Expressions.Count ? NewNfaState() : end; Apply(concat.Expressions[i], lastConcat, tmp); lastConcat = tmp; } break; case RegExType.Ranges: var prim = (RegExNodeRanges)regExNode; foreach (var range in prim.Ranges) { Transition(begin, end, range); } break; case RegExType.Sequence: var seq = (RegExNodeSequence)regExNode; var lastSeq = begin; switch (seq.Casing) { case RegExCasing.Insensitive: for (var i = 0; i < seq.Sequence.Length; i++) { var tmp = (i + 1 < seq.Sequence.Length) ? NewNfaState() : end; var c1 = char.ToLowerInvariant(seq.Sequence[i]); var c2 = char.ToUpperInvariant(c1); Transition(lastSeq, tmp, new RegExInputRange(c1)); if (c2 != c1) { Transition(lastSeq, tmp, new RegExInputRange(c2)); } lastSeq = tmp; } break; case RegExCasing.Sensitive: for (var i = 0; i < seq.Sequence.Length; i++) { var tmp = (i + 1 < seq.Sequence.Length) ? NewNfaState() : end; Transition(lastSeq, tmp, new RegExInputRange(seq.Sequence[i])); lastSeq = tmp; } break; } break; case RegExType.Repeat: var rep = (RegExNodeRepeat)regExNode; switch (rep.RegExRepeatType) { case RegExRepeatType.ZeroOrOne: Apply(rep.Expression, begin, end); Transition(begin, end, RegExInputRange.EPS); break; case RegExRepeatType.ZeroOrMore: { var s1 = NewNfaState(); var s2 = NewNfaState(); Transition(begin, end, RegExInputRange.EPS); Transition(begin, s1, RegExInputRange.EPS); Apply(rep.Expression, s1, s2); Transition(s2, s1, RegExInputRange.EPS); Transition(s2, end, RegExInputRange.EPS); } break; case RegExRepeatType.OneOrMore: { var s1 = NewNfaState(); var s2 = NewNfaState(); Transition(begin, s1, RegExInputRange.EPS); Apply(rep.Expression, s1, s2); Transition(s2, s1, RegExInputRange.EPS); Transition(s2, end, RegExInputRange.EPS); } break; } break; case RegExType.Except: var except = (RegExNodeExcept)regExNode; break; case RegExType.Accept: // Add an accept state. var accept = (RegExNodeAccept)regExNode; var term = NewNfaState(accept.AcceptState); Apply(accept.Expression, begin, term); Transition(term, end, RegExInputRange.EPS); break; } }
public RegExNode Parse() { RegExNode res = default(RegExNode); var targetTokenType = 0; _stateStack.Reset(); _valueStack.Reset(); KeyValuePair <Token, RegExNode> currentToken = NextToken(); _stateStack.Push(0); goto __state_0; __postReduce: /* find on the stack the state where we need to handle post-reduce goto. */ var gotoState = _stateStack.Elements[_stateStack.Top]; /* put information on the stack regarding the reduced type. */ _stateStack.Push(targetTokenType); /* jump to the resulting state. */ switch (gotoState) { case 0: switch (targetTokenType) { case 2: _stateStack.Push(1); goto __state_1; default: goto __syntaxError; } case 1: switch (targetTokenType) { case 2: _stateStack.Push(6); goto __state_6; default: goto __syntaxError; } case 4: switch (targetTokenType) { case 2: _stateStack.Push(13); goto __state_13; default: goto __syntaxError; } case 6: switch (targetTokenType) { case 2: _stateStack.Push(6); goto __state_6; default: goto __syntaxError; } case 10: switch (targetTokenType) { case 2: _stateStack.Push(18); goto __state_18; default: goto __syntaxError; } case 12: switch (targetTokenType) { case 2: _stateStack.Push(19); goto __state_19; default: goto __syntaxError; } case 13: switch (targetTokenType) { case 2: _stateStack.Push(20); goto __state_20; default: goto __syntaxError; } case 16: switch (targetTokenType) { case 2: _stateStack.Push(28); goto __state_28; default: goto __syntaxError; } case 18: switch (targetTokenType) { case 2: _stateStack.Push(6); goto __state_6; default: goto __syntaxError; } case 19: switch (targetTokenType) { case 2: _stateStack.Push(6); goto __state_6; default: goto __syntaxError; } case 20: switch (targetTokenType) { case 2: _stateStack.Push(20); goto __state_20; default: goto __syntaxError; } case 25: switch (targetTokenType) { case 2: _stateStack.Push(29); goto __state_29; default: goto __syntaxError; } case 27: switch (targetTokenType) { case 2: _stateStack.Push(30); goto __state_30; default: goto __syntaxError; } case 28: switch (targetTokenType) { case 2: _stateStack.Push(20); goto __state_20; default: goto __syntaxError; } case 29: switch (targetTokenType) { case 2: _stateStack.Push(20); goto __state_20; default: goto __syntaxError; } case 30: switch (targetTokenType) { case 2: _stateStack.Push(20); goto __state_20; default: goto __syntaxError; } default: goto __syntaxError; } __state_0: switch ((int)currentToken.Key) { case 3: /* perform shift to state 2 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(2); goto __state_2; case 4: /* perform shift to state 3 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(3); goto __state_3; case 8: /* perform shift to state 4 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(4); goto __state_4; case 12: /* perform shift to state 5 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(5); goto __state_5; default: goto __syntaxError; } __state_1: switch ((int)currentToken.Key) { case 1: /* accept value from stack */ return(_valueStack.Elements[_valueStack.Top]); case 3: /* perform shift to state 2 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(2); goto __state_2; case 4: /* perform shift to state 3 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(3); goto __state_3; case 5: /* perform shift to state 7 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(7); goto __state_7; case 6: /* perform shift to state 8 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(8); goto __state_8; case 7: /* perform shift to state 9 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(9); goto __state_9; case 8: /* perform shift to state 4 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(4); goto __state_4; case 10: /* perform shift to state 10 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(10); goto __state_10; case 11: /* perform shift to state 11 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(11); goto __state_11; case 12: /* perform shift to state 5 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(5); goto __state_5; case 13: /* perform shift to state 12 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(12); goto __state_12; default: goto __syntaxError; } __state_2: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 2 */ goto __action_2; default: goto __syntaxError; } __state_3: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 3 */ goto __action_3; default: goto __syntaxError; } __state_4: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; default: goto __syntaxError; } __state_5: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 4 */ goto __action_4; default: goto __syntaxError; } __state_6: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 8: case 10: case 12: /* do reduce using production 5 */ goto __action_5; case 5: /* perform shift to state 7 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(7); goto __state_7; case 6: /* perform shift to state 8 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(8); goto __state_8; case 7: /* perform shift to state 9 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(9); goto __state_9; case 11: /* perform shift to state 11 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(11); goto __state_11; case 13: /* perform shift to state 12 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(12); goto __state_12; default: goto __syntaxError; } __state_7: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 9 */ goto __action_9; default: goto __syntaxError; } __state_8: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 8 */ goto __action_8; default: goto __syntaxError; } __state_9: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 10 */ goto __action_10; default: goto __syntaxError; } __state_10: switch ((int)currentToken.Key) { case 3: /* perform shift to state 2 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(2); goto __state_2; case 4: /* perform shift to state 3 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(3); goto __state_3; case 8: /* perform shift to state 4 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(4); goto __state_4; case 12: /* perform shift to state 5 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(5); goto __state_5; default: goto __syntaxError; } __state_11: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 7 */ goto __action_7; default: goto __syntaxError; } __state_12: switch ((int)currentToken.Key) { case 3: /* perform shift to state 2 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(2); goto __state_2; case 4: /* perform shift to state 3 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(3); goto __state_3; case 8: /* perform shift to state 4 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(4); goto __state_4; case 12: /* perform shift to state 5 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(5); goto __state_5; default: goto __syntaxError; } __state_13: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 5: /* perform shift to state 21 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(21); goto __state_21; case 6: /* perform shift to state 22 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(22); goto __state_22; case 7: /* perform shift to state 23 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(23); goto __state_23; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 9: /* perform shift to state 24 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(24); goto __state_24; case 10: /* perform shift to state 25 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(25); goto __state_25; case 11: /* perform shift to state 26 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(26); goto __state_26; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; case 13: /* perform shift to state 27 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(27); goto __state_27; default: goto __syntaxError; } __state_14: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 2 */ goto __action_2; default: goto __syntaxError; } __state_15: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 3 */ goto __action_3; default: goto __syntaxError; } __state_16: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; default: goto __syntaxError; } __state_17: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 4 */ goto __action_4; default: goto __syntaxError; } __state_18: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 8: case 10: case 12: /* do reduce using production 6 */ goto __action_6; case 5: /* perform shift to state 7 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(7); goto __state_7; case 6: /* perform shift to state 8 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(8); goto __state_8; case 7: /* perform shift to state 9 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(9); goto __state_9; case 11: /* perform shift to state 11 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(11); goto __state_11; case 13: /* perform shift to state 12 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(12); goto __state_12; default: goto __syntaxError; } __state_19: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: /* do reduce using production 11 */ goto __action_11; case 13: /* perform shift to state 12 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(12); goto __state_12; default: goto __syntaxError; } __state_20: switch ((int)currentToken.Key) { case 3: case 4: case 8: case 9: case 10: case 12: /* do reduce using production 5 */ goto __action_5; case 5: /* perform shift to state 21 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(21); goto __state_21; case 6: /* perform shift to state 22 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(22); goto __state_22; case 7: /* perform shift to state 23 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(23); goto __state_23; case 11: /* perform shift to state 26 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(26); goto __state_26; case 13: /* perform shift to state 27 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(27); goto __state_27; default: goto __syntaxError; } __state_21: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 9 */ goto __action_9; default: goto __syntaxError; } __state_22: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 8 */ goto __action_8; default: goto __syntaxError; } __state_23: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 10 */ goto __action_10; default: goto __syntaxError; } __state_24: switch ((int)currentToken.Key) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 10: case 11: case 12: case 13: /* do reduce using production 1 */ goto __action_1; default: goto __syntaxError; } __state_25: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; default: goto __syntaxError; } __state_26: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 7 */ goto __action_7; default: goto __syntaxError; } __state_27: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; default: goto __syntaxError; } __state_28: switch ((int)currentToken.Key) { case 3: /* perform shift to state 14 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(14); goto __state_14; case 4: /* perform shift to state 15 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(15); goto __state_15; case 5: /* perform shift to state 21 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(21); goto __state_21; case 6: /* perform shift to state 22 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(22); goto __state_22; case 7: /* perform shift to state 23 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(23); goto __state_23; case 8: /* perform shift to state 16 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(16); goto __state_16; case 9: /* perform shift to state 31 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(31); goto __state_31; case 10: /* perform shift to state 25 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(25); goto __state_25; case 11: /* perform shift to state 26 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(26); goto __state_26; case 12: /* perform shift to state 17 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(17); goto __state_17; case 13: /* perform shift to state 27 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(27); goto __state_27; default: goto __syntaxError; } __state_29: switch ((int)currentToken.Key) { case 3: case 4: case 8: case 9: case 10: case 12: /* do reduce using production 6 */ goto __action_6; case 5: /* perform shift to state 21 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(21); goto __state_21; case 6: /* perform shift to state 22 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(22); goto __state_22; case 7: /* perform shift to state 23 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(23); goto __state_23; case 11: /* perform shift to state 26 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(26); goto __state_26; case 13: /* perform shift to state 27 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(27); goto __state_27; default: goto __syntaxError; } __state_30: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: /* do reduce using production 11 */ goto __action_11; case 13: /* perform shift to state 27 */ _valueStack.Push(currentToken.Value); _stateStack.Push((int)currentToken.Key); currentToken = NextToken(); _stateStack.Push(27); goto __state_27; default: goto __syntaxError; } __state_31: switch ((int)currentToken.Key) { case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: /* do reduce using production 1 */ goto __action_1; default: goto __syntaxError; } __action_1: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 2]; var arg1 = _valueStack.Elements[_valueStack.Top - 1]; var arg2 = _valueStack.Elements[_valueStack.Top - 0]; res = arg1; } _valueStack.Pop(3); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(6); targetTokenType = 2; goto __postReduce; __action_2: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 0]; res = arg0; } _valueStack.Pop(1); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(2); targetTokenType = 2; goto __postReduce; __action_3: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 0]; res = arg0; } _valueStack.Pop(1); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(2); targetTokenType = 2; goto __postReduce; __action_4: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 0]; res = _namedExpressions[(arg0 as RegExNodeName).Name]; } _valueStack.Pop(1); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(2); targetTokenType = 2; goto __postReduce; __action_5: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 1]; var arg1 = _valueStack.Elements[_valueStack.Top - 0]; res = new RegExNodeConcat(arg0, arg1); } _valueStack.Pop(2); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(4); targetTokenType = 2; goto __postReduce; __action_6: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 2]; var arg1 = _valueStack.Elements[_valueStack.Top - 1]; var arg2 = _valueStack.Elements[_valueStack.Top - 0]; res = RegExNodeUnion.Of(arg0, arg2); } _valueStack.Pop(3); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(6); targetTokenType = 2; goto __postReduce; __action_7: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 1]; var arg1 = _valueStack.Elements[_valueStack.Top - 0]; res = new RegExNodeAccept(arg0, (arg1 as RegExNodeAccept).AcceptState); } _valueStack.Pop(2); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(4); targetTokenType = 2; goto __postReduce; __action_8: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 1]; var arg1 = _valueStack.Elements[_valueStack.Top - 0]; res = new RegExNodeRepeat(arg0, RegExRepeatType.OneOrMore); } _valueStack.Pop(2); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(4); targetTokenType = 2; goto __postReduce; __action_9: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 1]; var arg1 = _valueStack.Elements[_valueStack.Top - 0]; res = new RegExNodeRepeat(arg0, RegExRepeatType.ZeroOrMore); } _valueStack.Pop(2); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(4); targetTokenType = 2; goto __postReduce; __action_10: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 1]; var arg1 = _valueStack.Elements[_valueStack.Top - 0]; res = new RegExNodeRepeat(arg0, RegExRepeatType.ZeroOrOne); } _valueStack.Pop(2); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(4); targetTokenType = 2; goto __postReduce; __action_11: { res = default(RegExNode); var arg0 = _valueStack.Elements[_valueStack.Top - 2]; var arg1 = _valueStack.Elements[_valueStack.Top - 1]; var arg2 = _valueStack.Elements[_valueStack.Top - 0]; res = RegExNodeRanges.Except(arg0, arg2); } _valueStack.Pop(3); _valueStack.Push(res); // find goto state and adjust state stack _stateStack.Pop(6); targetTokenType = 2; goto __postReduce; __syntaxError: throw new Exception("Syntax error"); }