double quote token "

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

double quote token "

120boxes
Hi! Just a bit confused about double quotes, coming from Chapter 10.

It seems as if the double quote token (") is missing from the Jack symbols listing. I even checked the book's second edition, and it wasn't listed there as well.

Obviously, " has to be a token in the Jack language; otherwise, how can we write 'Let s = "Hello world!";' syntactically inside Jack?

So my confusion is... is it just plain oversight to not have " listed among the Jack symbols specification?

It's even used in specifying stringConstants, so it HAS to be a token!

(I also understand that to actually print a " via a Jack program and to see it on the emulator's screen, we need to use String.doubleQuote() in the Jack code, but I think this is because " is a so-called escape character.)

Thanks for any clarification!


" IS a token, but not explicitly listed as so in the symbols section
Reply | Threaded
Open this post in threaded view
|

Re: double quote token "

120boxes
It seems I was mistaken, after all, over a very subtle matter.
Indeed, I now believe that " is NOT an explicit symbol / token of Jack, after all. Why? Let's see...

1. If " were to be a symbol of Jack, then wouldn't that force stringConstant to be a nonterminal element, instead of a terminal element? Since it's built up by a rule. We probably wouldn't want to have that, since we want stringConstant to be terminal.

2. If we did admit ", then by the same logic, we should also admit the numerals 0, ..., 9 as symbols so we can form things like x = 3, but the authors obviously didn't list the ten numerals as apart of the Jack symbols. So, by the same reason, it seems right to have " be excluded as well.

3. And this explains why the tokenizer is built to drop off the " from stringConstants.

It may sound like I'm rambling, but I hope to have convinced myself and others as to which side we should be treating " symbols in Jack. When implementingbthese things, these questions come up, especially if tiny details can send off flags in your mind!

Hope that helps people out in due time.