开发者

Using the regular expression [\[\];] in flex

开发者 https://www.devze.com 2022-12-11 21:31 出处:网络
If I have the following in my flex file, wha开发者_如何学Got does it do? [\\\\[\\\\];]{ return yytext[0]; }

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]

0

精彩评论

暂无评论...
验证码 换一张
取 消