Ho trovato questa perla in un articolo su come implementare un interprete... in questo momento sta spiegando come funziona un Recursive Descent Parser, e fa vedere questi due metodi che sono a dir poco *GENIALI*.
codice:
typedef const unsigned char* Iterator;
bool MatchesDigits(Iterator& it) //[0-9]Digits?
{
return (*it>='0' && *it<='9'?(++it,true):false)//[0-9]
&& (MatchesDigits(it),true); //Digits?
}
bool MatchesEnclosedDigits(Iterator& it) //Digits | '(' EnclosedDigits ')'
{
Iterator itSave= it;
return
MatchesDigits(it) // Digits
|| // |
( (itSave=it,
(*it=='('?(++it,true):false) // '('
&& MatchesEnclosedDigits(it) // EnclosedDigits
&& (*it==')'?(++it,true):false) // ')'
)
||(it=itSave,false)
);
}
Cioè... che altro dire se non WHAT!?