Unable to understand why the given Lex program fails to recognize the given input string.
by ajiten from LinuxQuestions.org on (#6CS69)
The problem is stated below, based on the contents here: https://www.ibm.com/docs/en/zos/2.4....uity-lookahead
It states a Lex program may be ambiguous, if some particular string may match more than one translation expression.
If the input matches more than one expression, Lex uses the following rules to determine which action to take:
1. The rule that matches the longest possible input stream is preferred.
2. If more than one rule matches an input of the same length, the rule that appears first in the translations section is preferred.
It states that the below fragment of lex program, would not be able to recognize the input string: abbb9', due to the second translation expression never being reached.
This is stated to be due to the above rule (not clear which of the two, the author implies):
letter [[:lower:]]
%%
a({letter})* { return('A'); }
ab({letter})* { return('B'); }
It states that by the swapping the sequence of the two translation expressions, the given string would be recognized.
It states a Lex program may be ambiguous, if some particular string may match more than one translation expression.
If the input matches more than one expression, Lex uses the following rules to determine which action to take:
1. The rule that matches the longest possible input stream is preferred.
2. If more than one rule matches an input of the same length, the rule that appears first in the translations section is preferred.
It states that the below fragment of lex program, would not be able to recognize the input string: abbb9', due to the second translation expression never being reached.
This is stated to be due to the above rule (not clear which of the two, the author implies):
letter [[:lower:]]
%%
a({letter})* { return('A'); }
ab({letter})* { return('B'); }
It states that by the swapping the sequence of the two translation expressions, the given string would be recognized.