views:

195

answers:

3

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?

+2  A: 

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

Luke
That sounds like a good guess.
Bryan Locke
Yes, that's what it is. Parsing errors in Ruby always refer to parser variables and constants.
Chuck
+4  A: 

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.

Squeegy
Cool. Thanks again.
Bryan Locke
+1  A: 

$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

MarkusQ
Not valid because nothing is allowed after the backslash?
Bryan Locke
In this case yes; characters are allowed after the \ on some paths through the lexer (e.g. "\n"). The best answer would be to say that it doesn't mean anything, so asking what specifically it doesn't mean isn't meaningful.If you want some fun, look through ruby's parser/lexer source. Bring beer.
MarkusQ