bool Match(ref TOKEN tok,Dfa dfa)
{
char ch=PeekChar();
int op=m_pch, mark=0;
Dfa next;
if (m_debug)
{
Console.Write("state {0} with ",dfa.m_state);
if (char.IsLetterOrDigit(ch)||char.IsPunctuation(ch))
Console.WriteLine(ch);
else
Console.WriteLine("#"+(int)ch);
}
if (dfa.m_actions!=null)
{
mark = Mark();
}
if (// ch==0 ||
(next=((Dfa)dfa.m_map[m_tokens.Filter(ch)]))==null)
{
if (m_debug)
Console.Write("{0} no arc",dfa.m_state);
if (dfa.m_actions!=null)
{
if (m_debug)
Console.WriteLine(" terminal");
return TryActions(dfa,ref tok); // fails on REJECT
}
if (m_debug)
Console.WriteLine(" fails");
return false;
}
Advance();
if (!Match(ref tok, next))
{ // rest of string fails
if (m_debug)
Console.WriteLine("back to {0} with {1}",dfa.m_state,ch);
if (dfa.m_actions!=null)
{ // this is still okay at a terminal
if (m_debug)
Console.WriteLine("{0} succeeds",dfa.m_state);
Restore(mark);
return TryActions(dfa,ref tok);
}
if (m_debug)
Console.WriteLine("{0} fails",dfa.m_state);
return false;
}
if (dfa.m_reswds>=0)
{
((ResWds)m_tokens.reswds[dfa.m_reswds]).Check(this,ref tok);
}
if (m_debug)
{
Console.Write("{0} matched ",dfa.m_state);
if (m_pch<=m_buf.Length)
Console.WriteLine(m_buf.Substring(op,m_pch-op));
else
Console.WriteLine(m_buf.Substring(op));
}
return true;
}