More docs. Made two builtins be stdlib functions.
This commit is contained in:
parent
97c3e05856
commit
b682ee964b
26
README.md
26
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.
|
||||
|
||||
32
it0-out.py
32
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('(')
|
||||
|
||||
44
it1-in.lang0
44
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 "("
|
||||
|
||||
52
it2-in.lang0
52
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 "("
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user