From aa05eb86a75b76e0f82ea5b4a0dcf6de6a3bc180 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 30 Aug 2026 19:10:51 -0700 Subject: add some stuff about string literals to the readme Force-Push: yes Change-Id: I7bda5d1ad0c6b1b44ea283b429b14fd397ef978a --- README.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.txt b/README.txt index 334f3b8..a6690e4 100644 --- a/README.txt +++ b/README.txt @@ -70,6 +70,33 @@ versions as you modify Evocation. Some helpful words to try to get started are list-dictionary and describe. + The syntax for a string literal is s" ...". There's something very subtle +happening: it's the lowercase letter "s", a double quote, and a space. Then +you type the actual contents of the string, then at the end you type another +double quote. The words "Hi, Irenes!", in the example above, are part of a +closely related syntax that uses a period instead of a letter s, and prints +the string out to your terminal instead of returning it. + + Whether you're using s" or .", that space after the quote is mandatory, +which may seem very strange if you're more familiar with pretty much any +language that isn't a Forth, but it's a common Forth idiom. Requiring the +space allows the string literal syntax to be tokenized just like any other +space-delimited word. Unlike most languages, there's no special concept of an +operator or punctuation character that can "interrupt" another word or run up +against the start of one. Everything is separated by spaces. + + Of course, in modern Forth dialects it's also very common to add a special +lexer feature for that sort of thing. Evocation doesn't do that, because +eventually fancy syntax and grammar will be implemented at a higher layer, +using the experimental parsing formalism that doesn't exist yet. If you want +to see where this feature would be if it were implemented in the simpler way, +you can read the definition of the word named "word", in interpret.e. + + If you went to look at that and you're wondering: Yeah, Evocation's lexer +really is that short and simple. Part of why it's able to be that easy is that +words such as s" that introduce special syntaxes do their own lexing for +whatever comes after them. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ Reading Evocation's source code ~~ -- cgit 1.4.1