1

I used a backslash to continue a Ruby statement on the next line.

print abc \
+ def

I added a space after the backslash, because I like to blow things up, and, sure enough, I got an error:

unexpected $undefined, expecting $end

I assume $undefined is a global variable that means anything the compiler sees that it doesn't recognize - in this case the space after the backslash.

Is $end a global variable that refers to the "end of line" character?

Are these globals just global in my program or are they more global than that? Just how global are they?

4

3 回答 3

7

Those are not global variables. That is just notation used by the parser. $undefined appears to mean a blank space or token of no meaning. $end is the end of a line or statement.

于 2009-02-25T00:42:22.723 回答
2

I'd bet the $ is just a shorthand that the parser/lexer uses to symbolise a token, and not an actual usable variable.

于 2009-02-25T00:38:59.283 回答
1

$undefined is referring to the lexer token created by "\ " -- it isn't syntactically valid ruby.

$end lexer token for the end of the file.

-- MarkusQ

于 2009-02-25T06:56:23.150 回答