string TransitionFunction(char c) { string ret = STATE_INIT; if (mode_stream) { AccumulateStream(c); } PdfStateTransition transition = FindTransition(c); if (transition != null) { if (transition.back == 0) { Accumulate(c); this.current_token.type = transition.state_out; } this.current_state = transition.state_out; this.read_offset -= transition.back; if (transition.acceptance) { if (this.current_token.lexeme == "stream") { mode_stream = true; stream_token = new PdfToken(); stream_token.type = "STREAM"; } if (this.current_token.lexeme == "endstream") { mode_stream = false; this.tokens.Add(this.stream_token); } this.tokens.Add(this.current_token); this.current_token = new PdfToken(); this.current_state = STATE_INIT; } } return(ret); }
void AddStateTransition( string state_in, string pattern, string state_out, bool acceptance = false, int back = 0 ) { PdfStateTransition transition = new PdfStateTransition() { state_in = state_in, pattern = pattern, state_out = state_out, acceptance = acceptance, back = back }; this.transition_table.Add(transition); }
PdfStateTransition FindTransition(char c) { PdfStateTransition ret = null; bool found = false; int current = 0; while (transition_table.Count > current && !found) { if (transition_table[current].state_in == this.current_state) { if (Regex.IsMatch(c.ToString(), transition_table[current].pattern)) { ret = transition_table[current]; found = true; } } current++; } return(ret); }