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
|
### 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
|
#### 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
|
#### Standard library functions
|
||||||
|
|
||||||
@ -109,13 +99,19 @@ Return true if the given strings are the same.
|
|||||||
|
|
||||||
#### lt a b
|
#### lt a b
|
||||||
|
|
||||||
|
`a` and `b` are expected to have length 1.
|
||||||
|
|
||||||
Return true if a would sort before b.
|
Return true if a would sort before b.
|
||||||
|
|
||||||
#### addstringchar a 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
|
#### peek
|
||||||
|
|
||||||
@ -125,6 +121,10 @@ Checks stdin for the next character and returns it.
|
|||||||
|
|
||||||
Advances stdin a single character.
|
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
|
### Typing
|
||||||
|
|
||||||
Every variable is of type string. Every function gets a number of strings as output, and returns another string.
|
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)
|
emit(eol)
|
||||||
skipchar(eol)
|
skipchar(eol)
|
||||||
|
|
||||||
def parsestatemit(indent):
|
|
||||||
skipchar(' ')
|
|
||||||
emit(' ' * indent)
|
|
||||||
emit('emit(')
|
|
||||||
|
|
||||||
if quote == peek():
|
|
||||||
parseconststring()
|
|
||||||
else:
|
|
||||||
parseexprvarref()
|
|
||||||
skipchar(eol)
|
|
||||||
|
|
||||||
emit(')\n')
|
|
||||||
|
|
||||||
def parsestattrace(indent):
|
def parsestattrace(indent):
|
||||||
skipchar(' ')
|
skipchar(' ')
|
||||||
emit(' ' * indent)
|
emit(' ' * indent)
|
||||||
@ -185,17 +172,6 @@ def parsestattrace(indent):
|
|||||||
emit(var_name)
|
emit(var_name)
|
||||||
emit(')\n')
|
emit(')\n')
|
||||||
|
|
||||||
def parsestatskipchar(indent):
|
|
||||||
skipchar(' ')
|
|
||||||
emit(' ' * indent)
|
|
||||||
emit('skipchar(')
|
|
||||||
if quote == peek():
|
|
||||||
parseconststring()
|
|
||||||
else:
|
|
||||||
parseexprvarref()
|
|
||||||
emit(')\n')
|
|
||||||
skipchar(eol)
|
|
||||||
|
|
||||||
def parsestat(indent):
|
def parsestat(indent):
|
||||||
call = lexident()
|
call = lexident()
|
||||||
trace('call', call)
|
trace('call', call)
|
||||||
@ -228,18 +204,10 @@ def parsestat(indent):
|
|||||||
parsestatreturn(indent)
|
parsestatreturn(indent)
|
||||||
return
|
return
|
||||||
|
|
||||||
if call == "emit":
|
|
||||||
parsestatemit(indent)
|
|
||||||
return
|
|
||||||
|
|
||||||
if call == "trace":
|
if call == "trace":
|
||||||
parsestattrace(indent)
|
parsestattrace(indent)
|
||||||
return
|
return
|
||||||
|
|
||||||
if call == "skipchar":
|
|
||||||
parsestatskipchar(indent)
|
|
||||||
return
|
|
||||||
|
|
||||||
emit(' ' * indent)
|
emit(' ' * indent)
|
||||||
emit(call)
|
emit(call)
|
||||||
emit('(')
|
emit('(')
|
||||||
|
|||||||
44
it1-in.lang0
44
it1-in.lang0
@ -152,23 +152,6 @@ parsestatreturn indent:
|
|||||||
skipchar eol
|
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:
|
parsestattrace indent:
|
||||||
emit indent
|
emit indent
|
||||||
emit "trace("
|
emit "trace("
|
||||||
@ -183,23 +166,6 @@ parsestattrace indent:
|
|||||||
skipchar eol
|
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:
|
parsestat indent:
|
||||||
calc call lexident
|
calc call lexident
|
||||||
trace call
|
trace call
|
||||||
@ -238,21 +204,11 @@ parsestat indent:
|
|||||||
parsestatreturn indent
|
parsestatreturn indent
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
calc isemit eq call "emit"
|
|
||||||
if isemit
|
|
||||||
parsestatemit indent
|
|
||||||
return
|
|
||||||
/
|
|
||||||
calc istrace eq call "trace"
|
calc istrace eq call "trace"
|
||||||
if istrace
|
if istrace
|
||||||
parsestattrace indent
|
parsestattrace indent
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
calc isskipchar eq call "skipchar"
|
|
||||||
if isskipchar
|
|
||||||
parsestatskipchar indent
|
|
||||||
return
|
|
||||||
/
|
|
||||||
emit indent
|
emit indent
|
||||||
emit call
|
emit call
|
||||||
emit "("
|
emit "("
|
||||||
|
|||||||
52
it2-in.lang0
52
it2-in.lang0
@ -209,27 +209,6 @@ parsestatreturn indent:
|
|||||||
return
|
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:
|
parsestattrace indent:
|
||||||
declare varname
|
declare varname
|
||||||
emit indent
|
emit indent
|
||||||
@ -246,27 +225,6 @@ parsestattrace indent:
|
|||||||
return
|
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:
|
parsestat indent:
|
||||||
declare call
|
declare call
|
||||||
declare char
|
declare char
|
||||||
@ -315,21 +273,11 @@ parsestat indent:
|
|||||||
parsestatreturn indent
|
parsestatreturn indent
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
calc iscall eq call "emit"
|
|
||||||
if iscall
|
|
||||||
parsestatemit indent
|
|
||||||
return
|
|
||||||
/
|
|
||||||
calc iscall eq call "trace"
|
calc iscall eq call "trace"
|
||||||
if iscall
|
if iscall
|
||||||
parsestattrace indent
|
parsestattrace indent
|
||||||
return
|
return
|
||||||
/
|
/
|
||||||
calc iscall eq call "skipchar"
|
|
||||||
if iscall
|
|
||||||
parsestatskipchar indent
|
|
||||||
return
|
|
||||||
/
|
|
||||||
emit indent
|
emit indent
|
||||||
emit call
|
emit call
|
||||||
emit "("
|
emit "("
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user