From: Simon S. <sim...@gn...> - 2019-02-28 11:13:53
|
Hi and welcome to the world of lexers! Am 27.02.2019 um 14:36 schrieb Wor...@gm...: 5. .|\n { printf("do nothing"); } 6. [_a-zA-Z0-9]+\( { printf("This is a function name %s (steps=%i)", yytext, steps++); } >> Now my problem is that also strings like 12342welcome( are beeing >> "marked" as beeing functions ... what am i doing wrong here ? the >> default route .|\n is said to do nothing, so why does he matches also >> digits with my function catching example ? Actually you've said that anything that consist only of *at least one* ("+") from the following set "[_a-zA-Z0-9]" (directly followed by a "(") is a function. As you did not specify what you want to do you may want to mark only functions if they not start with a number, using a fixed and an optional set (* matches zero to unlimited occurrences): [_a-zA-Z]+[_a-zA-Z0-9]*\( you may also want to add optional spaces before "\(". > I've replaced the lines 5 and 6 because he matches first the lines > with the most matches and that is normaly .|\n but again same problem > =(. If I'm not wrong the *longest* match is the preferred one and as this rule matches only a single character it should normally not be used. Simon |