From b682ee964b87508fd3daa77620ba9720af82b6d2 Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Sun, 26 Jan 2025 13:52:39 +0100 Subject: [PATCH] More docs. Made two builtins be stdlib functions. --- README.md | 26 +++++++++++++------------- it0-out.py | 32 -------------------------------- it1-in.lang0 | 44 -------------------------------------------- it2-in.lang0 | 52 ---------------------------------------------------- 4 files changed, 13 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index 68b9637..789fb9a 100644 --- a/README.md +++ b/README.md @@ -87,19 +87,9 @@ Calls the given function with the given arguments. The result, if any, is ignore ### Builtins -#### emit arg - -Writes the given string to standard output. - -? Does this need to be a builtin ? - -#### skipchar - -? Does this need to be a builtin ? - #### trace -? Does this need to be a builtin ? +Writes the name and value of the variable passed to stderr if the TRACE environment variable is set. #### Standard library functions @@ -109,13 +99,19 @@ Return true if the given strings are the same. #### lt a b +`a` and `b` are expected to have length 1. + Return true if a would sort before b. #### addstringchar a b -b is expected to have length 1. +`b` is expected to have length 1. -Creates a new string with b appended to a. +Creates a new string with `b` appended to `a`. + +#### emit arg + +Writes the given string to standard output. #### peek @@ -125,6 +121,10 @@ Checks stdin for the next character and returns it. Advances stdin a single character. +#### skipchar a + +Advances stdin a single character, if it matches the first character of `a`. Otherwise, exits the program. + ### Typing Every variable is of type string. Every function gets a number of strings as output, and returns another string. diff --git a/it0-out.py b/it0-out.py index 0e86033..a169ddc 100644 --- a/it0-out.py +++ b/it0-out.py @@ -159,19 +159,6 @@ def parsestatreturn(indent): emit(eol) skipchar(eol) -def parsestatemit(indent): - skipchar(' ') - emit(' ' * indent) - emit('emit(') - - if quote == peek(): - parseconststring() - else: - parseexprvarref() - skipchar(eol) - - emit(')\n') - def parsestattrace(indent): skipchar(' ') emit(' ' * indent) @@ -185,17 +172,6 @@ def parsestattrace(indent): emit(var_name) emit(')\n') -def parsestatskipchar(indent): - skipchar(' ') - emit(' ' * indent) - emit('skipchar(') - if quote == peek(): - parseconststring() - else: - parseexprvarref() - emit(')\n') - skipchar(eol) - def parsestat(indent): call = lexident() trace('call', call) @@ -228,18 +204,10 @@ def parsestat(indent): parsestatreturn(indent) return - if call == "emit": - parsestatemit(indent) - return - if call == "trace": parsestattrace(indent) return - if call == "skipchar": - parsestatskipchar(indent) - return - emit(' ' * indent) emit(call) emit('(') diff --git a/it1-in.lang0 b/it1-in.lang0 index a2addaf..bc61e62 100644 --- a/it1-in.lang0 +++ b/it1-in.lang0 @@ -152,23 +152,6 @@ parsestatreturn indent: skipchar eol / -parsestatemit indent: - emit indent - emit "emit(" - skipchar " " - calc char peek - calc isquote eq char quote - calc isnotquote not isquote - if isquote - parseconststring - / - if isnotquote - parseexprvarref - / - emit ")\n" - skipchar eol -/ - parsestattrace indent: emit indent emit "trace(" @@ -183,23 +166,6 @@ parsestattrace indent: skipchar eol / -parsestatskipchar indent: - skipchar " " - emit indent - emit "skipchar(" - calc char peek - calc isquote eq char quote - calc isnotquote not isquote - if isquote - parseconststring - / - if isnotquote - parseexprvarref - / - emit ")\n" - skipchar eol -/ - parsestat indent: calc call lexident trace call @@ -238,21 +204,11 @@ parsestat indent: parsestatreturn indent return / - calc isemit eq call "emit" - if isemit - parsestatemit indent - return - / calc istrace eq call "trace" if istrace parsestattrace indent return / - calc isskipchar eq call "skipchar" - if isskipchar - parsestatskipchar indent - return - / emit indent emit call emit "(" diff --git a/it2-in.lang0 b/it2-in.lang0 index 12fdb6d..3809d16 100644 --- a/it2-in.lang0 +++ b/it2-in.lang0 @@ -209,27 +209,6 @@ parsestatreturn indent: return / -parsestatemit indent: - declare char - declare isquote - declare isnotquote - emit indent - emit "emit(" - skipchar " " - calc char peek - calc isquote eq char quote - calc isnotquote not isquote - if isquote - parseconststring - / - if isnotquote - parseexprvarref - / - emit ");\n" - skipchar eol - return -/ - parsestattrace indent: declare varname emit indent @@ -246,27 +225,6 @@ parsestattrace indent: return / -parsestatskipchar indent: - declare char - declare isquote - declare isnotquote - skipchar " " - emit indent - emit "skipchar(" - calc char peek - calc isquote eq char quote - calc isnotquote not isquote - if isquote - parseconststring - / - if isnotquote - parseexprvarref - / - emit ");\n" - skipchar eol - return -/ - parsestat indent: declare call declare char @@ -315,21 +273,11 @@ parsestat indent: parsestatreturn indent return / - calc iscall eq call "emit" - if iscall - parsestatemit indent - return - / calc iscall eq call "trace" if iscall parsestattrace indent return / - calc iscall eq call "skipchar" - if iscall - parsestatskipchar indent - return - / emit indent emit call emit "("