If I have the following in my flex file, wha开发者_如何学Got does it do?
[\\[\\];] { return yytext[0]; }
If it was in Perl, it would match any of '[', ']', or ';' -- I imagine it's the same in flex. The outer "[...]" defines a character range, i.e. matches any one of the specified characters: the backslashes escape the inner "[]" so that they just mean literal brackets.
It matches a token consisting of one of the characters [
, ]
or ;
. @AAT is is right in his explanation, though terminology wise "character class" is more common than "character range".
return yytext[0];
returns the first character of the matched token. Since the regexp here matches only single character tokens, it returns the matched token itself as a character.
if it finds any of the follwing []; it returns yytext[0]
精彩评论