visits
318
votes
24
votes++Vote positively this post :)
+34
votes--Vote negatively this post :(
-10
The rebel emoticons of messenger

Messenger have a functionality that consist in add images ass emoticons and associate a text string to it for make appear the emoticons every time that you write that string. Until here all is correct, but suppose that we have stored the two following emoticons with the text assigned that appears adjacently:
^^
^^ U
Now if we want to write the emoticon without having to search it in the panel of emoticons, will have to write "^^U", but oh! Surprise!, instead will get "
U". In other words, shows "^^" as
and the "U" is ignore, making imposible write directly emoticons with an associated text string with a prefix that contains the string assigned to any other emoticon.
What the program does, it's transform the text in an emoticon as soon as it find an associated emoticon. This behaviour is, obviously, a fatal error for anyone that has programmed sometime a lexical analyzer.
All compilers, interprets, translators or any other program that have to work with a language, either computer or human language, have a lexical analyzer that implements the principle of take always the longest substring. All except the lexical analyzer of the Messenger.
This principle consists in doesn’t return the text string as a word of the language (at the Messenger case are emoticons), until haven't read a string sufficiently larger, as to know that we are not reading a word of the language more long than we thought. But see it with an example:
Suppose that we have a language in that "emoticons" is a word and "emoticonsMSN" is another. Our lexical analyzer have to say us the words of the language that appears in the next text:
emoticonYahooemoticonosMSN
To make this task will read the text, character by character and will return the words found.
Now let's see step by step how works a lexical analyzer (the bold character is the character that we are reading).
Read the first character:
emoticonsYahoosemoticonsMSN
We continue reading until we find the word "emoticons" that belongs to the language, but we don't return it, simply we store it temporaly:
emoticonosYahooemoticonsMSN
Read the next character and as "emoticonsY" isn't a word of the language, we return the word that we have stored temporally, that was "emoticons".
emoticonsYahooemoticonsMSN
The analyzer goes rejecting the next characters that go reading until it find a character that is the beginning of another word of the language.
emoticonsYahooemoticonosMSN
Several characters more, we find again the word "emoticons". Again the analyzer don't return the word (the analyzer of the Messenger would do), only we store it temporaly.
emoticonsYahooemoticonsMSN
We reach the final of the text and the analyzer have found the word "emoticonsMSN", therefore rejects the word "emoticons" that had stored and returns "emoticonsMSN".
Finally the result get by any lexical analyzer was "emoticons" and "emoticonsMSN", while the irrational lexical analyzer of the Messenger will return the word "emoticons" two times.
I hope that do you have understand this example, but have in account that it's a superficial and slant explanation of the algorithm. If someone want implement it, they would learn programming, finite automats and read part of the book "Compilers. Principles, techniques and Tools", also know popularly as "The book of the dragon".