Language Expansion: Variables, Statements, Functions
- Separate added string syntax from runtime binding behavior.
- Decode string escapes while retaining source positions.
- Explain which v2 features require parser, analyzer, and VM changes.
1 / 6
For source let text = "a\n";, distinguish two levels of representation. In
the actual language source the quoted characters are a, backslash, n; the
STRING token's value contains a followed by one newline character. The source
cursor remains on its original line because the escape occupies two source
characters. A literal unescaped newline inside quotes is an error.
The escaped input "say: \"hi\"" produces a string value containing quote
characters. Scanning looks for an unescaped closing quote, so stopping at the
first quote byte after a backslash would truncate it. Support exactly the four
listed escapes (\", \\, \n, \t); an unlisted \q must fail.
A scanner increments its source line counter when it decodes the two-character escape backslash-n inside a string. The next token is now reported on the wrong line. Explain which representation was confused.
Make a three-row comparison of let name="x";, let name="x;, and let name="x\q";. Predict tokens or the earliest lexer failure, then separately explain why a valid token sequence does not prove legal assignment.
Carry decoded STRING values and exact token positions into program parsing. Retain the old expression regressions where token contracts agree, and add explicit version-boundary tests where they differ.