views:

144

answers:

3

If I have the following in my flex file, what does it do?

[\\[\\];]     { return yytext[0]; }
A: 

if it finds any of the follwing []; it returns yytext[0]

ennuikiller
You sure? In most regex flavors I know, characters inside `[` and `]` are treated as a character class: it matches just a single character defined in them.
Bart Kiers
.. perhaps Flex handles it differently.
Bart Kiers
you're right I thought it may have been the deliniter
ennuikiller
+2  A: 

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.

AAT
+1  A: 

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.

laalto