Compare commits

...

2 Commits

Author SHA1 Message Date
Johan B.W. de Vries
68e3c12d80 Feat: Adds mapclear, mapgetkey, mapsetkey
Feat: Error on undefined function

Fix: All ids are now prefix to prevent native var clashes.

Chore: __check helper function for ease of use
2025-05-04 15:09:57 +02:00
Johan B.W. de Vries
6055cddab2 Extends the test framework to prepare for compilation tests
Feat: add now can add two full strings

Fix: it2 would have different working for emit eof

Fix: eq and lt would return bools on it0 and it1

Fix: Functions always return something (there is no such
thing as an empty type).

Fix: Return value from main is now always ignored.

Fix: Output from check is same on all iterations
2025-05-04 14:33:10 +02:00
76 changed files with 941 additions and 355 deletions

View File

@ -2,14 +2,14 @@ import os
import sys import sys
def emit(string): def emit(string):
sys.stdout.write(string) sys.stdout.buffer.write(string.encode('latin_1'))
sys.stdout.flush() sys.stdout.flush()
def trace(header, value): def trace(header, value):
if os.environ.get('TRACE'): if os.environ.get('TRACE'):
sys.stderr.write(f'{header}={value!r}\n') sys.stderr.write(f'{header}={value!r}\n')
eof = chr(0) eof = chr(0xFF)
eol = chr(10) eol = chr(10)
quote = chr(34) quote = chr(34)
PEEK = None PEEK = None
@ -39,6 +39,36 @@ def skip():
PEEK = None PEEK = None
def __check(func, args: list[str], msg: list[str]) -> None:
result = func(*args)
if result:
return
sys.stderr.write('ERROR: ' + ' '.join(msg) + '\n')
sys.stderr.flush()
exit(1)
MAPSTORE = {}
def mapclear(mapname: str) -> str:
MAPSTORE.pop(mapname)
return ""
def mapgetkey(mapname: str, key: str, default: str) -> str:
return MAPSTORE.get(mapname, {}).get(key, default)
def mapsetkey(mapname: str, key: str, value: str) -> str:
MAPSTORE.setdefault(mapname, {})
MAPSTORE[mapname][key] = value
return ""
def registerid(id: str) -> str:
idname = mapgetkey("REGISTERID", id, "")
if idname:
return idname
idname = "id_" + id
return idname
def emitln(data): def emitln(data):
emit(data) emit(data)
emit(eol) emit(eol)
@ -81,12 +111,15 @@ def parseconststring():
emit(quote) emit(quote)
def parseexprvarref(): def parseexprvarref():
var = lexident() varname = lexident()
emit(var) varid = registerid(varname)
emit(varid)
def parseexprcall(): def parseexprcall():
funcname = lexident() funcname = lexident()
emit(funcname) __check(mapgetkey, ["FUNCREG", funcname, ""], ["Function", funcname, "does not exist"])
funcid = registerid(funcname)
emit(funcid)
emit('(') emit('(')
first = True first = True
@ -109,11 +142,12 @@ def parsestatdeclare(indent):
def parsestatset(indent): def parsestatset(indent):
skipchar(' ') skipchar(' ')
var = lexident() varname = lexident()
varid = registerid(varname)
skipchar(' ') skipchar(' ')
emit(' ' * indent) emit(' ' * indent)
emit(var) emit(varid)
emit(' = ') emit(' = ')
parseconststring() parseconststring()
@ -123,11 +157,12 @@ def parsestatset(indent):
def parsestatcalc(indent): def parsestatcalc(indent):
skipchar(' ') skipchar(' ')
var = lexident() varname = lexident()
varid = registerid(varname)
skipchar(' ') skipchar(' ')
emit(' ' * indent) emit(' ' * indent)
emit(var) emit(varid)
emit(' = ') emit(' = ')
parseexprcall() parseexprcall()
@ -166,17 +201,21 @@ def parsestatreturn(indent):
parseconststring() parseconststring()
else: else:
parseexprvarref() parseexprvarref()
else:
emit('""')
emit(eol) emit(eol)
skipchar(eol) skipchar(eol)
def parsestatcheck(indent): def parsestatcheck(indent):
skipchar(' ') skipchar(' ')
emit(' ' * indent) emit(' ' * indent)
emit('assert ') emit('__check(')
func_name = lexident() funcname = lexident()
emit(func_name) funcid = registerid(funcname)
emit('(') trace("funcid", funcid)
emit(funcid)
emit(', [')
notfirst = False notfirst = False
while True: while True:
@ -197,7 +236,7 @@ def parsestatcheck(indent):
skipchar(':') skipchar(':')
emit('), (') emit('], [')
notfirst = False notfirst = False
while True: while True:
@ -214,19 +253,21 @@ def parsestatcheck(indent):
if eol == peek(): if eol == peek():
break break
notfirst = True notfirst = True
emitln(')')
emitln('])')
def parsestattrace(indent): def parsestattrace(indent):
skipchar(' ') skipchar(' ')
emit(' ' * indent) emit(' ' * indent)
emit('trace("') emit('__trace("')
var_name = lexident() varname = lexident()
varid = registerid(varname)
skipchar(eol) skipchar(eol)
emit(var_name) emit(varname)
emit('", ') emit('", ')
emit(var_name) emit(varid)
emitln(')') emitln(')')
def parsestat(indent): def parsestat(indent):
@ -269,8 +310,10 @@ def parsestat(indent):
parsestattrace(indent) parsestattrace(indent)
return return
funcid = registerid(call)
emit(' ' * indent) emit(' ' * indent)
emit(call) emit(funcid)
emit('(') emit('(')
first = True first = True
@ -307,19 +350,22 @@ def parseblock(indent):
def parsefunc(): def parsefunc():
funcname = lexident() funcname = lexident()
funcid = registerid(funcname)
mapsetkey("FUNCREG", funcname, "1")
trace('funcname', funcname) trace('funcname', funcname)
emit('def ') emit('def ')
emit(funcname) emit(funcid)
emit('(') emit('(')
first = True first = True
while ' ' == peek(): while ' ' == peek():
skip() skip()
var = lexident() varname = lexident()
varid = registerid(varname)
if not first: if not first:
emit(", ") emit(", ")
emit(var) emit(varid)
first = False first = False
if '/' == peek(): if '/' == peek():
@ -344,26 +390,26 @@ def emitheader():
emitln("import os") emitln("import os")
emitln("import sys") emitln("import sys")
emitln("") emitln("")
emitln("def eq(a, b):") emitln("def __eq(a: str, b: str) -> str:")
emitln(" return a == b") emitln(" return '1' if a == b else ''")
emitln("") emitln("")
emitln("def lt(a, b):") emitln("def __lt(a: str, b: str) -> str:")
emitln(" return a[0] < b[0]") emitln(" return '1' if a < b else ''")
emitln("") emitln("")
emitln("def addstringchar(a, b):") emitln("def __add(a: str, b: str) -> str:")
emitln(" return a + b[0]") emitln(" return a + b")
emitln("") emitln("")
emitln("def emit(string):") emitln("def __emit(string):")
emitln(" sys.stdout.write(string)") emitln(" sys.stdout.buffer.write(string.encode('latin_1'))")
emitln(" sys.stdout.flush()") emitln(" sys.stdout.flush()")
emitln("") emitln("")
emitln("def trace(header, value):") emitln("def __trace(header, value):")
emitln(" if os.environ.get('TRACE'):") emitln(" if os.environ.get('TRACE'):")
emitln(" sys.stderr.write(f'{header}={value!r}\\n')") emitln(" sys.stderr.write(f'{header}={value!r}\\n')")
emitln("") emitln("")
emitln("eof = chr(0)") emitln("__EOF = chr(0xFF)")
emitln("eol = chr(10)") emitln("__EOL = chr(10)")
emitln("quote = chr(34)") emitln("__QUOTE = chr(34)")
emitln("") emitln("")
emitln("STDINCOLNO = 0") emitln("STDINCOLNO = 0")
emitln("STDINLINENO = 1") emitln("STDINLINENO = 1")
@ -371,41 +417,103 @@ def emitheader():
emitln("") emitln("")
emitln("def _readchar():") emitln("def _readchar():")
emitln(" char = sys.stdin.read(1)") emitln(" char = sys.stdin.read(1)")
emitln(" trace('char', char)") emitln(" __trace('char', char)")
emitln(" if not char:") emitln(" if not char:")
emitln(" return eof") emitln(" return __EOF")
emitln(" return char") emitln(" return char")
emitln("") emitln("")
emitln("def peek():") emitln("def __peek():")
emitln(" return STDINPEEK") emitln(" return STDINPEEK")
emitln("") emitln("")
emitln("def skip():") emitln("def __skip():")
emitln(" global STDINCOLNO") emitln(" global STDINCOLNO")
emitln(" global STDINLINENO") emitln(" global STDINLINENO")
emitln(" global STDINPEEK") emitln(" global STDINPEEK")
emitln(" if eol == STDINPEEK:") emitln(" if __EOL == STDINPEEK:")
emitln(" STDINLINENO += 1") emitln(" STDINLINENO += 1")
emitln(" STDINCOLNO = 0") emitln(" STDINCOLNO = 0")
emitln(" STDINCOLNO += 1") emitln(" STDINCOLNO += 1")
emitln(" STDINPEEK = _readchar()") emitln(" STDINPEEK = _readchar()")
emitln("") emitln("")
emitln("def stdinlineno():") emitln("def __stdinlineno():")
emitln(" global STDINLINENO") emitln(" global STDINLINENO")
emitln(" return str(STDINLINENO)") emitln(" return str(STDINLINENO)")
emitln("") emitln("")
emitln("def stdincolno():") emitln("def __stdincolno():")
emitln(" global STDINCOLNO") emitln(" global STDINCOLNO")
emitln(" return str(STDINCOLNO)") emitln(" return str(STDINCOLNO)")
emitln("") emitln("")
emitln("skip()") emitln("__skip()")
emitln("") emitln("")
emitln("MAPSTORE = {}")
emitln("")
emitln("def __mapclear(mapname: str) -> str:")
emitln(" MAPSTORE.pop(mapname)")
emitln(" return ''")
emitln("")
emitln("def __mapgetkey(mapname: str, key: str, default: str) -> str:")
emitln(" return MAPSTORE.get(mapname, {}).get(key, default)")
emitln("")
emitln("def __mapsetkey(mapname: str, key: str, value: str) -> str:")
emitln(" MAPSTORE.setdefault(mapname, {})")
emitln(" MAPSTORE[mapname][key] = value")
emitln(" return ''")
emitln("")
emitln("def __not(a: str) -> str:")
emitln(" if a:")
emitln(" return ''")
emitln(" return '1'")
emitln("")
emitln("def __check(func, args: list[str], msg: list[str]) -> None:")
emitln(" result = func(*args)")
emitln(" if result:")
emitln(" return")
emitln("")
emitln(" sys.stderr.write('ERROR: ' + ' '.join(msg) + '\\n')")
emitln(" sys.stderr.flush()")
emitln(" exit(1)")
def emitfooter(): def emitfooter():
emit("if __name__ == '__main__':\n") mainname = registerid("main")
emit(" main()\n") emitln("if __name__ == '__main__':")
emit(" ")
emit(mainname)
emitln("()")
def main(): def main():
emitheader() emitheader()
# Standard library constants
mapsetkey("REGISTERID", "eof", "__EOF")
mapsetkey("REGISTERID", "eol", "__EOL")
mapsetkey("REGISTERID", "quote", "__QUOTE")
# Standard library functions
mapsetkey("FUNCREG", "add", "1")
mapsetkey("REGISTERID", "add", "__add")
mapsetkey("FUNCREG", "emit", "1")
mapsetkey("REGISTERID", "emit", "__emit")
mapsetkey("FUNCREG", "eq", "1")
mapsetkey("REGISTERID", "eq", "__eq")
mapsetkey("FUNCREG", "lt", "1")
mapsetkey("REGISTERID", "lt", "__lt")
mapsetkey("FUNCREG", "not", "1")
mapsetkey("REGISTERID", "not", "__not")
mapsetkey("FUNCREG", "mapclear", "1")
mapsetkey("REGISTERID", "mapclear", "__mapclear")
mapsetkey("FUNCREG", "mapgetkey", "1")
mapsetkey("REGISTERID", "mapgetkey", "__mapgetkey")
mapsetkey("FUNCREG", "mapsetkey", "1")
mapsetkey("REGISTERID", "mapsetkey", "__mapsetkey")
mapsetkey("FUNCREG", "peek", "1")
mapsetkey("REGISTERID", "peek", "__peek")
mapsetkey("FUNCREG", "skip", "1")
mapsetkey("REGISTERID", "skip", "__skip")
mapsetkey("FUNCREG", "stdincolno", "1")
mapsetkey("REGISTERID", "stdincolno", "__stdincolno")
mapsetkey("FUNCREG", "stdinlineno", "1")
mapsetkey("REGISTERID", "stdinlineno", "__stdinlineno")
while True: while True:
if eof == peek(): if eof == peek():
break break

View File

@ -36,5 +36,8 @@ lang0py.py: lang0py.lang0 lang0py2.exe
mv $@.tmp $@ mv $@.tmp $@
-diff lang0py2.py lang0py.py -diff lang0py2.py lang0py.py
$(LANG0PY): $(CURDIR)/../0-lang0py/lang0py.py $(CURDIR)/../0-lang0py/lang0py.lang0
cd ../0-lang0py && make lang0py.exe
clean: clean:
rm -f lang0py*.py lang0py*.c lang0py*.o lang0py*.exe rm -f lang0py*.py lang0py*.c lang0py*.o lang0py*.exe

View File

@ -1,12 +1,14 @@
skipchar exp: registerid id:
declare act declare idname
declare lineno declare newidx
declare colno
calc act peek calc idname mapgetkey "REGISTERID" id ""
calc lineno stdinlineno if idname
calc colno stdincolno return idname
check eq exp act : "Unexpected character" act "expected" exp "at" lineno colno /
skip
calc idname add "id_" id
return idname
/ /
emitln data: emitln data:
@ -14,14 +16,6 @@ emitln data:
emit eol emit eol
/ /
increaseindent indent:
calc indent addstringchar indent " "
calc indent addstringchar indent " "
calc indent addstringchar indent " "
calc indent addstringchar indent " "
return indent
/
lexident: lexident:
declare word declare word
set word "" set word ""
@ -35,12 +29,28 @@ lexident:
if isafterz if isafterz
break break
/ /
calc word addstringchar word char calc word add word char
skip skip
/ /
return word return word
/ /
skipchar exp:
declare act
declare lineno
declare colno
calc act peek
calc lineno stdinlineno
calc colno stdincolno
check eq exp act : "Unexpected character" act "expected" exp "at" lineno colno
skip
/
increaseindent indent:
calc indent add indent " "
return indent
/
parseconststring: parseconststring:
skipchar quote skipchar quote
emit quote emit quote
@ -63,12 +73,15 @@ parseconststring:
parseexprvarref: parseexprvarref:
calc varname lexident calc varname lexident
emit varname calc varid registerid varname
emit varid
/ /
parseexprcall: parseexprcall:
calc funcname lexident calc funcname lexident
emit funcname calc funcid registerid funcname
check mapgetkey "FUNCREG" funcname "" : "Function" funcname "does not exist"
emit funcid
emit "(" emit "("
set first "1" set first "1"
forever forever
@ -100,16 +113,18 @@ parseexprcall:
parsestatdeclare indent: parsestatdeclare indent:
skipchar " " skipchar " "
calc var lexident calc varname lexident
calc varid registerid varname
skipchar eol skipchar eol
/ /
parsestatset indent: parsestatset indent:
skipchar " " skipchar " "
calc var lexident calc varname lexident
calc varid registerid varname
skipchar " " skipchar " "
emit indent emit indent
emit var emit varid
emit " = " emit " = "
parseconststring parseconststring
emit eol emit eol
@ -118,10 +133,11 @@ parsestatset indent:
parsestatcalc indent: parsestatcalc indent:
skipchar " " skipchar " "
calc var lexident calc varname lexident
calc varid registerid varname
skipchar " " skipchar " "
emit indent emit indent
emit var emit varid
emit " = " emit " = "
parseexprcall parseexprcall
emit eol emit eol
@ -160,6 +176,7 @@ parsestatreturn indent:
emit "return " emit "return "
calc char peek calc char peek
calc isspace eq char " " calc isspace eq char " "
calc isnotspace not isspace
if isspace if isspace
skip skip
calc char peek calc char peek
@ -172,6 +189,10 @@ parsestatreturn indent:
parseexprvarref parseexprvarref
/ /
/ /
if isnotspace
emit quote
emit quote
/
emit eol emit eol
skipchar eol skipchar eol
/ /
@ -186,11 +207,12 @@ parsestatcheck indent:
skipchar " " skipchar " "
emit indent emit indent
emit "assert " emit "__check("
calc funcname lexident calc funcname lexident
emit funcname calc funcid registerid funcname
emit "(" emit funcid
emit ", ["
set notfirst "" set notfirst ""
forever forever
@ -220,7 +242,8 @@ parsestatcheck indent:
skipchar ":" skipchar ":"
emit "), (" emit "], ["
set notfirst "" set notfirst ""
forever forever
@ -249,19 +272,20 @@ parsestatcheck indent:
set notfirst "1" set notfirst "1"
/ /
emitln ")" emitln "])"
/ /
parsestattrace indent: parsestattrace indent:
emit indent emit indent
emit "trace(" emit "__trace("
emit quote emit quote
skipchar " " skipchar " "
calc varname lexident calc varname lexident
calc varid registerid varname
emit varname emit varname
emit quote emit quote
emit ", " emit ", "
emit varname emit varid
emitln ")" emitln ")"
skipchar eol skipchar eol
/ /
@ -314,8 +338,9 @@ parsestat indent:
parsestatcheck indent parsestatcheck indent
return return
/ /
calc callid registerid call
emit indent emit indent
emit call emit callid
emit "(" emit "("
set first "1" set first "1"
forever forever
@ -380,9 +405,11 @@ parseblock indent:
parsefunc: parsefunc:
calc funcname lexident calc funcname lexident
calc funcid registerid funcname
trace funcname trace funcname
mapsetkey "FUNCREG" funcname "1"
emit "def " emit "def "
emit funcname emit funcid
emit "(" emit "("
set isnotfirst "" set isnotfirst ""
forever forever
@ -393,11 +420,12 @@ parsefunc:
break break
/ /
skip skip
calc var lexident calc varname lexident
calc varid registerid varname
if isnotfirst if isnotfirst
emit ", " emit ", "
/ /
emit var emit varid
set isnotfirst "1" set isnotfirst "1"
/ /
calc char peek calc char peek
@ -421,26 +449,31 @@ emitheader:
emitln "import os" emitln "import os"
emitln "import sys" emitln "import sys"
emitln "" emitln ""
emitln "def eq(a, b):" emitln "def __eq(a: str, b: str) -> str:"
emitln " return a == b" emitln " return '1' if a == b else ''"
emitln "" emitln ""
emitln "def lt(a, b):" emitln "def __lt(a: str, b: str) -> str:"
emitln " return a[0] < b[0]" emitln " return '1' if a < b else ''"
emitln "" emitln ""
emitln "def addstringchar(a, b):" emitln "def __not(a: str) -> str:"
emitln " return a + b[0]" emitln " if a:"
emitln " return ''"
emitln " return '1'"
emitln "" emitln ""
emitln "def emit(string):" emitln "def __add(a: str, b :str) -> str:"
emitln " sys.stdout.write(string)" emitln " return a + b"
emitln ""
emitln "def __emit(string):"
emitln " sys.stdout.buffer.write(string.encode('latin_1'))"
emitln " sys.stdout.flush()" emitln " sys.stdout.flush()"
emitln "" emitln ""
emitln "def trace(header, value):" emitln "def __trace(header, value):"
emitln " if os.environ.get('TRACE'):" emitln " if os.environ.get('TRACE'):"
emitln " sys.stderr.write(f'{header}={value!r}\\n')" emitln " sys.stderr.write(f'{header}={value!r}\\n')"
emitln "" emitln ""
emitln "eof = chr(0)" emitln "__EOF = chr(0xFF)"
emitln "eol = chr(10)" emitln "__EOL = chr(10)"
emitln "quote = chr(34)" emitln "__QUOTE = chr(34)"
emitln "" emitln ""
emitln "STDINCOLNO = 0" emitln "STDINCOLNO = 0"
emitln "STDINLINENO = 1" emitln "STDINLINENO = 1"
@ -448,43 +481,102 @@ emitheader:
emitln "" emitln ""
emitln "def _readchar():" emitln "def _readchar():"
emitln " char = sys.stdin.read(1)" emitln " char = sys.stdin.read(1)"
emitln " trace('char', char)" emitln " __trace('char', char)"
emitln " if not char:" emitln " if not char:"
emitln " return eof" emitln " return __EOF"
emitln " return char" emitln " return char"
emitln "" emitln ""
emitln "def peek():" emitln "def __peek():"
emitln " return STDINPEEK" emitln " return STDINPEEK"
emitln "" emitln ""
emitln "def skip():" emitln "def __skip():"
emitln " global STDINCOLNO" emitln " global STDINCOLNO"
emitln " global STDINLINENO" emitln " global STDINLINENO"
emitln " global STDINPEEK" emitln " global STDINPEEK"
emitln " if eol == STDINPEEK:" emitln " if __EOL == STDINPEEK:"
emitln " STDINLINENO += 1" emitln " STDINLINENO += 1"
emitln " STDINCOLNO = 0" emitln " STDINCOLNO = 0"
emitln " STDINCOLNO += 1" emitln " STDINCOLNO += 1"
emitln " STDINPEEK = _readchar()" emitln " STDINPEEK = _readchar()"
emitln "" emitln ""
emitln "def stdinlineno():" emitln "def __stdinlineno():"
emitln " global STDINLINENO" emitln " global STDINLINENO"
emitln " return str(STDINLINENO)" emitln " return str(STDINLINENO)"
emitln "" emitln ""
emitln "def stdincolno():" emitln "def __stdincolno():"
emitln " global STDINCOLNO" emitln " global STDINCOLNO"
emitln " return str(STDINCOLNO)" emitln " return str(STDINCOLNO)"
emitln "" emitln ""
emitln "skip()" emitln "__skip()"
emitln "" emitln ""
emitln ""
emitln "MAPSTORE = {}"
emitln ""
emitln "def __mapclear(mapname: str) -> str:"
emitln " MAPSTORE.pop(mapname)"
emitln " return ''"
emitln ""
emitln "def __mapgetkey(mapname: str, key: str, default: str) -> str:"
emitln " return MAPSTORE.get(mapname, {}).get(key, default)"
emitln ""
emitln "def __mapsetkey(mapname: str, key: str, value: str) -> str:"
emitln " MAPSTORE.setdefault(mapname, {})"
emitln " MAPSTORE[mapname][key] = value"
emitln " return ''"
emitln ""
emitln "def __check(func, args: list[str], msg: list[str]) -> None:"
emitln " result = func(*args)"
emitln " if result:"
emitln " return"
emitln ""
emitln " sys.stderr.write('ERROR: ' + ' '.join(msg) + '\\n')"
emitln " sys.stderr.flush()"
emitln " exit(1)"
/ /
emitfooter: emitfooter:
declare mainname
calc mainname registerid "main"
emitln "if __name__ == '__main__':" emitln "if __name__ == '__main__':"
emitln " main()" emit " "
emit mainname
emitln "()"
/ /
main: main:
emitheader emitheader
mapsetkey "REGISTERID" "eof" "__EOF"
mapsetkey "REGISTERID" "eol" "__EOL"
mapsetkey "REGISTERID" "quote" "__QUOTE"
mapsetkey "FUNCREG" "add" "1"
mapsetkey "REGISTERID" "add" "__add"
mapsetkey "FUNCREG" "emit" "1"
mapsetkey "REGISTERID" "emit" "__emit"
mapsetkey "FUNCREG" "eq" "1"
mapsetkey "REGISTERID" "eq" "__eq"
mapsetkey "FUNCREG" "lt" "1"
mapsetkey "REGISTERID" "lt" "__lt"
mapsetkey "FUNCREG" "not" "1"
mapsetkey "REGISTERID" "not" "__not"
mapsetkey "FUNCREG" "mapclear" "1"
mapsetkey "REGISTERID" "mapclear" "__mapclear"
mapsetkey "FUNCREG" "mapgetkey" "1"
mapsetkey "REGISTERID" "mapgetkey" "__mapgetkey"
mapsetkey "FUNCREG" "mapsetkey" "1"
mapsetkey "REGISTERID" "mapsetkey" "__mapsetkey"
mapsetkey "FUNCREG" "peek" "1"
mapsetkey "REGISTERID" "peek" "__peek"
mapsetkey "FUNCREG" "skip" "1"
mapsetkey "REGISTERID" "skip" "__skip"
mapsetkey "FUNCREG" "stdincolno" "1"
mapsetkey "REGISTERID" "stdincolno" "__stdincolno"
mapsetkey "FUNCREG" "stdinlineno" "1"
mapsetkey "REGISTERID" "stdinlineno" "__stdinlineno"
forever forever
calc char peek calc char peek
calc iseof eq char eof calc iseof eq char eof

View File

@ -15,10 +15,7 @@ emitln data:
/ /
increaseindent indent: increaseindent indent:
calc indent addstringchar indent " " calc indent add indent " "
calc indent addstringchar indent " "
calc indent addstringchar indent " "
calc indent addstringchar indent " "
return indent return indent
/ /
@ -38,7 +35,7 @@ lexident:
if isafterz if isafterz
break break
/ /
calc word addstringchar word char calc word add word char
skip skip
/ /
return word return word
@ -227,7 +224,8 @@ parsestatreturn indent:
/ /
/ /
if isnotspace if isnotspace
emit "0" emit quote
emit quote
/ /
emit ";" emit ";"
emit eol emit eol
@ -284,6 +282,7 @@ parsestatcheck indent:
emit indent emit indent
emitln "{" emitln "{"
emit indent
emit " fprintf(stderr, " emit " fprintf(stderr, "
emit quote emit quote
emit "%s" emit "%s"
@ -321,6 +320,14 @@ parsestatcheck indent:
/ /
/ /
emit indent
emit " fprintf(stderr, "
emit quote
emit "%s"
emit quote
emit ", var_eol"
emitln ");"
emit indent emit indent
emitln " exit(1);" emitln " exit(1);"
emit indent emit indent
@ -479,14 +486,23 @@ parsefunc:
declare funcname declare funcname
declare iseoblock declare iseoblock
declare isfirst declare isfirst
declare ismain
declare isnotmain
declare isspace declare isspace
declare isnotfirst declare isnotfirst
declare isnotspace declare isnotspace
declare var declare var
calc funcname lexident calc funcname lexident
calc ismain eq funcname "main"
calc isnotmain not ismain
trace funcname trace funcname
emit "char * " emit "char * "
emit funcname if ismain
emit "__main"
/
if isnotmain
emit funcname
/
emit "(" emit "("
set first "1" set first "1"
forever forever
@ -532,7 +548,7 @@ emitheader:
emitln "#include <string.h>" emitln "#include <string.h>"
emitln "" emitln ""
emitln "" emitln ""
emitln "char var_eof[2] = {-1, 0};" emitln "char var_eof[2] = {0xFF, 0};"
emitln "char var_eol[2] = {10, 0};" emitln "char var_eol[2] = {10, 0};"
emitln "char var_quote[2] = {34, 0};" emitln "char var_quote[2] = {34, 0};"
emitln "char var_false[1] = {0};" emitln "char var_false[1] = {0};"
@ -553,14 +569,14 @@ emitheader:
emitln " return (strcmp(a, var_true) != 0) ? var_true : var_false;" emitln " return (strcmp(a, var_true) != 0) ? var_true : var_false;"
emitln "}" emitln "}"
emitln "" emitln ""
emitln "char * addstringchar(char * str, char * chr)" emitln "char * add(char * lft, char * rgt)"
emitln "{" emitln "{"
emitln " int str_len = strlen(str);" emitln " int lft_len = strlen(lft);"
emitln " assert(strlen(chr) == 1);" emitln " int rgt_len = strlen(rgt);"
emitln " char * res = malloc((str_len + 2) * sizeof(char));" emitln " char * res = malloc((lft_len + rgt_len + 1) * sizeof(char));"
emitln " strcpy(res, str);" emitln " strcpy(res, lft);"
emitln " res[str_len + 0] = chr[0];" emitln " strcpy(res + lft_len, rgt);"
emitln " res[str_len + 1] = 0;" emitln " res[lft_len + rgt_len] = 0;"
emitln " return res;" emitln " return res;"
emitln "}" emitln "}"
emitln "" emitln ""
@ -644,7 +660,10 @@ emitheader:
/ /
emitfooter: emitfooter:
emit "" emitln "int main() {"
emitln " __main();"
emitln " return 0;"
emitln "}"
return return
/ /

View File

@ -97,7 +97,7 @@ Exits the deepest `forever` loop.
#### func args* #### func args*
Calls the function name `func` with the given arguments. The result, if any, is ignored. Calls the function name `func` with the given arguments. The return value is ignored.
#### if arg #### if arg
@ -109,7 +109,7 @@ Repeats the block until `break` or `return` is called.
#### return var? #### return var?
Returns the given value. You can not give an argument if your function is never used in `call`. Returns the given value. If you don't give something to return, the function will return the empty string.
### Builtins ### Builtins
@ -121,11 +121,23 @@ Calls the given function with the given arguments. If the function's return valu
Writes the name and value of the variable passed to stderr if the TRACE environment variable is set. Writes the name and value of the variable passed to stderr if the TRACE environment variable is set.
### Standard library constants
#### eof
End of file character, zero byte.
#### eol
End of line character.
#### quote
Double quote character.
### Standard library functions ### Standard library functions
#### addstringchar a b #### add a b
`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`.
@ -143,6 +155,29 @@ Return true if the given strings are the same.
Return true if a would sort before b. Return true if a would sort before b.
#### mapclear mapname
Maps are global and can be used from any function.
Clears all values set in the map named `mapname`.
#### mapgetkey mapname key
Maps are global and can be used from any function.
Looks up `key` in the map named `mapname` and returns it.
If not found, returns an empty string.
#### mapsetkey mapname key value
Maps are global and can be used from any function.
Adds a mapping from `key` to `value` to the map named `mapname`.
#### not a
Returns "1" if a is empty; otherwise, returns "".
#### peek #### peek
Checks stdin for the next character and returns it. Checks stdin for the next character and returns it.

2
tests/.gitignore vendored
View File

@ -1 +1 @@
/*.results /Makefile.mk

View File

@ -1,6 +1,5 @@
.SUFFIXES: .SUFFIXES:
.PHONY: all clean .PHONY: all clean
.PRECIOUS: build/%.it0.py build/%.it0.c
.DELETE_ON_ERROR: .DELETE_ON_ERROR:
PYVERSION=3.12 PYVERSION=3.12
@ -8,31 +7,29 @@ PYPREFIX=/usr
CYTHON=cython3 CYTHON=cython3
CC=gcc CC=gcc
# builtincheckfalse is separate since it's supposed to crash. It's a test for the test 'framework', if you will. all: verify-results
TESTLIST=$(shell ls *.lang0 | grep -v 'builtincheckfalse' | sed 's/.lang0//')
all: check Makefile.mk: generate-recipes.py $(wildcard test_*/test_*)
python3 generate-recipes.py Makefile.mk it0 it1 it2
check: all-it0.results all-it1.results all-it2.results include Makefile.mk
! grep -v 'Success' $^
all-it0.results: $(addprefix build/,$(addsuffix .it0, $(TESTLIST))) build/builtincheckfalse.it0
-rm -f $@
cat test-input.txt | build/builtincheckfalse.it0 2> /dev/null 2>&1 | grep 'Success'
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it0 >> $@ ; echo "" >> $@ ;)
all-it1.results: $(addprefix build/,$(addsuffix .it1, $(TESTLIST))) build/builtincheckfalse.it1
-rm -f $@
cat test-input.txt | build/builtincheckfalse.it1 2> /dev/null 2>&1 | grep 'Success'
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it1 >> $@ ; echo "" >> $@ ;)
all-it2.results: $(addprefix build/,$(addsuffix .it2, $(TESTLIST))) build/builtincheckfalse.it2
-rm -f $@
cat test-input.txt | build/builtincheckfalse.it2 2> /dev/null 2>&1 | grep 'Success'
$(foreach test,$(TESTLIST), echo -n "$(test) " >> $@; cat test-input.txt | ./build/$(test).it2 >> $@ ; echo "" >> $@ ;)
clean: clean:
-rm -f *.results build/*.it0* build/*.it1* build/*.it2* find build -name '*.c' -delete
find build -name '*.it0' -delete
find build -name '*.it0.result' -delete
find build -name '*.it0.stderr' -delete
find build -name '*.it0.stdout' -delete
find build -name '*.it1' -delete
find build -name '*.it1.result' -delete
find build -name '*.it1.stderr' -delete
find build -name '*.it1.stdout' -delete
find build -name '*.it2' -delete
find build -name '*.it2.result' -delete
find build -name '*.it2.stderr' -delete
find build -name '*.it2.stdout' -delete
find build -name '*.py' -delete
find build -name '*.tmp' -delete
### ###
# it0 # it0

View File

@ -3,12 +3,21 @@
/*.it0.o /*.it0.o
/*.it0.py /*.it0.py
/*.it0.py.tmp /*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1 /*.it1
/*.it1.c /*.it1.c
/*.it1.o /*.it1.o
/*.it1.py /*.it1.py
/*.it1.py.tmp /*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2 /*.it2
/*.it2.c /*.it2.c
/*.it2.c.tmp /*.it2.c.tmp
/*.it2.o /*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

View File

@ -0,0 +1,23 @@
/*.it0
/*.it0.c
/*.it0.o
/*.it0.py
/*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1
/*.it1.c
/*.it1.o
/*.it1.py
/*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2
/*.it2.c
/*.it2.c.tmp
/*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

23
tests/build/test_parsing/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
/*.it0
/*.it0.c
/*.it0.o
/*.it0.py
/*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1
/*.it1.c
/*.it1.o
/*.it1.py
/*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2
/*.it2.c
/*.it2.c.tmp
/*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

View File

@ -0,0 +1,23 @@
/*.it0
/*.it0.c
/*.it0.o
/*.it0.py
/*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1
/*.it1.c
/*.it1.o
/*.it1.py
/*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2
/*.it2.c
/*.it2.c.tmp
/*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

View File

@ -0,0 +1,23 @@
/*.it0
/*.it0.c
/*.it0.o
/*.it0.py
/*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1
/*.it1.c
/*.it1.o
/*.it1.py
/*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2
/*.it2.c
/*.it2.c.tmp
/*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

23
tests/build/test_variables/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
/*.it0
/*.it0.c
/*.it0.o
/*.it0.py
/*.it0.py.tmp
/*.it0.result
/*.it0.stderr
/*.it0.stdout
/*.it1
/*.it1.c
/*.it1.o
/*.it1.py
/*.it1.py.tmp
/*.it1.result
/*.it1.stderr
/*.it1.stdout
/*.it2
/*.it2.c
/*.it2.c.tmp
/*.it2.o
/*.it2.result
/*.it2.stderr
/*.it2.stdout

View File

@ -1,3 +0,0 @@
main:
check not "1" : "Success"
/

View File

@ -1,4 +0,0 @@
main:
check not "" : "Failure"
emit "Success"
/

View File

@ -1,8 +0,0 @@
main:
declare bool
set bool ""
if bool
return
/
emit "Success"
/

View File

@ -1,7 +0,0 @@
main:
declare bool
set bool "1"
if bool
emit "Success"
/
/

View File

@ -1,8 +0,0 @@
func:
return
/
main:
func
emit "Success"
/

View File

@ -1,11 +0,0 @@
func:
declare result
set result "Success"
return result
/
main:
declare result
calc result func
emit result
/

View File

@ -1,9 +0,0 @@
func:
return "Success"
/
main:
declare result
calc result func
emit result
/

106
tests/generate-recipes.py Normal file
View File

@ -0,0 +1,106 @@
import glob
import os
import sys
class Rule:
def __init__(self, target: str, prerequisites: list[str], recipe: list[str]) -> None:
self.target = target
self.prerequisites = prerequisites
self.recipe = recipe
def make_lines(self):
return [
self.target + ': ' + ' '.join(self.prerequisites),
] + [
'\t' + line
for line in self.recipe
] + ['']
def get_file_list():
return sorted(glob.glob('test_*/*.lang0'))
def make_rules(file_path, lang0it):
result: list[Rule] = []
stdin = file_path.replace('.lang0', '.stdin')
exp_stdout = file_path.replace('.lang0', '.exp.stdout')
exp_stderr = file_path.replace('.lang0', '.exp.stderr')
act_result = 'build/' + file_path.replace('.lang0', f'.{lang0it}.result')
act_stderr = 'build/' + file_path.replace('.lang0', f'.{lang0it}.stderr')
act_stdout = 'build/' + file_path.replace('.lang0', f'.{lang0it}.stdout')
program = 'build/' + file_path.replace('.lang0', f'.{lang0it}')
if os.path.isfile(exp_stdout) or os.path.isfile(exp_stderr):
result.append(Rule(
act_stdout,
[program] + ([stdin] if os.path.isfile(stdin) else []),
[
'-' + (f'cat {stdin} | ' if os.path.isfile(stdin) else 'echo x | ')
+ f'{program} 1> {act_stdout} 2> {act_stderr}',
]
))
exp_list = [exp_stdout, exp_stderr]
act_list = [act_stdout, act_stderr]
result.append(Rule(
act_result,
[act_stdout] + [
x
for x in exp_list
if os.path.isfile(x)
],
[
'rm -f $@',
] + [
f'-diff {exp_file} {act_file} >> $@'
for exp_file, act_file in zip(exp_list, act_list, strict=True)
if os.path.isfile(exp_file)
] + [
f'-diff /dev/null {act_file} >> $@'
for exp_file, act_file in zip(exp_list, act_list, strict=True)
if not os.path.isfile(exp_file)
]
))
assert result[-1].prerequisites, f'Missing expectations for {file_path}'
return result
def main(program, write_to, *lang0it):
rule_list_list = [
make_rules(file_path, it)
for file_path in get_file_list()
for it in lang0it
]
result_targets = [
rule.target
for rule_list in rule_list_list
for rule in rule_list
if rule.target.endswith('.result')
]
rule_list_list.append([Rule(
'verify-results',
result_targets,
[
'@echo Finding failed test results...',
'@find $^ -not -empty -print -exec false {} +',
'@echo All tests passed.'
]
)])
data = '\n'.join(
line
for rule_list in rule_list_list
for rule in rule_list
for line in rule.make_lines()
)
with open(write_to, 'wt', encoding='ASCII') as fil:
fil.write(data)
if __name__ == '__main__':
main(*sys.argv)

View File

@ -1,10 +0,0 @@
func/
main:
check func : "The function should return 1, even though it is not defined yet"
emit "Success"
/
func:
return "1"
/

View File

@ -1,10 +0,0 @@
func arg/
main:
check func "1" : "The function should return 1, even though it is not defined yet"
emit "Success"
/
func arg:
return arg
/

View File

@ -1,86 +0,0 @@
main:
declare char
declare colno
declare lineno
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "H" : "Read: H" char
check eq colno "1" : "The column number should not have advanced yet" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "e" : "Read: e" char
check eq colno "2" : "The column number should have been advanced by 1" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "l" : "Read: l" char
check eq colno "3" : "The column number should have been advanced by 2" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "l" : "Read: l" char
check eq colno "4" : "The column number should have been advanced by 3" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "o" : "Read: o" char
check eq colno "5" : "The column number should have been advanced by 4" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "!" : "Read: !" char
check eq colno "6" : "The column number should have been advanced by 5" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char eol : "Read: eol" char
check eq colno "7" : "The column number should have been advanced by 6" colno
check eq lineno "1" : "The line number should not have advanced yet" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char eol : "Read: eol" char
check eq colno "1" : "The column number should have been reset" colno
check eq lineno "2" : "The line number should have advanced by 1" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "T" : "Read: T" char
check eq colno "1" : "The column number should have been reset again" colno
check eq lineno "3" : "The line number should have advanced by 2" lineno
skip
calc char peek
calc colno stdincolno
calc lineno stdinlineno
check eq char "h" : "Read: h" char
check eq colno "2" : "The line number should not have been advanced by 1" colno
check eq lineno "3" : "The line number should not have advanced further" lineno
emit "Success"
/

View File

@ -1,6 +0,0 @@
main:
declare result
calc result addstringchar "abc" "d"
check eq result "abcd" : "Adding abc and d should be abcd"
emit "Success"
/

View File

@ -1,3 +0,0 @@
main:
emit "Success"
/

View File

@ -1,6 +0,0 @@
main:
declare bool
calc bool eq "1" "2"
check not bool : "1 should not equal 2"
emit "Success"
/

View File

@ -1,5 +0,0 @@
main:
declare bool
check eq "1" "1" : "1 should equal 1"
emit "Success"
/

View File

@ -1,6 +0,0 @@
main:
declare bool
calc bool lt "b" "a"
check not bool : "a should should sort before b"
emit "Success"
/

View File

@ -1,5 +0,0 @@
main:
declare bool
check lt "a" "b" : "a should should sort before b"
emit "Success"
/

View File

@ -1,6 +0,0 @@
main:
declare char
calc char peek
check eq char "H" : "The first byte we're passed is expected to be an 'H'"
emit "Success"
/

View File

@ -1,12 +0,0 @@
main:
declare char
skip
calc char peek
check eq char "e" : "The second byte we're passed is expected to be an 'e'"
skip
skip
skip
calc char peek
check eq char "o" : "The fifth byte we're passed is expected to be an 'o'"
emit "Success"
/

View File

@ -1,3 +0,0 @@
Hello!
This is an example of standard input.

View File

@ -0,0 +1 @@
ERROR: Check failed successfully

View File

@ -0,0 +1 @@
Still alive

View File

@ -0,0 +1,8 @@
main:
check not "" : "This should not trigger"
emit "Still alive"
emit eol
check not "1" : "Check failed successfully"
emit "This should not be output"
emit eol
/

View File

@ -0,0 +1 @@
Success

View File

@ -1,6 +1,7 @@
main: main:
forever forever
emit "Suc"
break break
/ /
emit "Success" emit "cess"
/ /

View File

@ -0,0 +1 @@
Success

View File

@ -0,0 +1,2 @@
1 is true
A is true

View File

@ -0,0 +1,18 @@
main:
declare bool
set bool ""
if bool
emit "empty string is true"
emit eol
/
set bool "1"
if bool
emit "1 is true"
emit eol
/
set bool "A"
if bool
emit "A is true"
emit eol
/
/

View File

@ -0,0 +1,3 @@
funca Constant
funcb Variable
funcc

View File

@ -0,0 +1,32 @@
funca:
return "Constant"
/
funcb:
declare var
set var "Variable"
return var
/
funcc:
return
/
main:
declare var
calc var funca
emit "funca "
emit var
emit eol
calc var funcb
emit "funcb "
emit var
emit eol
calc var funcc
emit "funcc "
emit var
emit eol
/

View File

@ -0,0 +1,2 @@
Predeclared without argument: 1
Predeclared with argument: 2

View File

@ -0,0 +1,24 @@
funca/
funcb arg/
main:
declare var
calc var funca
emit "Predeclared without argument: "
emit var
emit eol
calc var funcb "2"
emit "Predeclared with argument: "
emit var
emit eol
/
funca:
return "1"
/
funcb arg:
return arg
/

View File

@ -0,0 +1 @@
<EFBFBD>

View File

@ -0,0 +1,3 @@
main:
emit eof
/

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
main:
emit eol
/

View File

@ -0,0 +1 @@
"

View File

@ -0,0 +1,3 @@
main:
emit quote
/

View File

@ -0,0 +1,3 @@
1 + 2 = 12
10 + 20 = 1020
101 + 202 = 101202

View File

@ -0,0 +1,29 @@
func tst a b:
declare var
calc var add a b
emit a
emit " + "
emit b
emit " = "
emit var
emit eol
/
main:
declare var
calc var add "1" "2"
emit "1 + 2 = "
emit var
emit eol
calc var add "10" "20"
emit "10 + 20 = "
emit var
emit eol
calc var add "101" "202"
emit "101 + 202 = "
emit var
emit eol
/

View File

@ -0,0 +1 @@
Hello, world!

View File

@ -0,0 +1,4 @@
main:
emit "Hello"
emit ", world!"
/

View File

@ -0,0 +1,4 @@
eq A A: 1
eq A B:
eq AA AA: 1
eq AA AB:

View File

@ -0,0 +1,19 @@
main:
declare result
emit "eq A A: "
calc result eq "A" "A"
emit result
emit eol
emit "eq A B: "
calc result eq "A" "B"
emit result
emit eol
emit "eq AA AA: "
calc result eq "AA" "AA"
emit result
emit eol
emit "eq AA AB: "
calc result eq "AA" "AB"
emit result
emit eol
/

View File

@ -0,0 +1,6 @@
lt A A:
lt A B: 1
lt B A:
lt AA AA:
lt AA AB: 1
lt AB AA:

View File

@ -0,0 +1,27 @@
main:
declare result
emit "lt A A: "
calc result lt "A" "A"
emit result
emit eol
emit "lt A B: "
calc result lt "A" "B"
emit result
emit eol
emit "lt B A: "
calc result lt "B" "A"
emit result
emit eol
emit "lt AA AA: "
calc result lt "AA" "AA"
emit result
emit eol
emit "lt AA AB: "
calc result lt "AA" "AB"
emit result
emit eol
emit "lt AB AA: "
calc result lt "AB" "AA"
emit result
emit eol
/

View File

@ -0,0 +1 @@
AAA

View File

@ -0,0 +1,9 @@
main:
declare char
calc char peek
emit char
calc char peek
emit char
calc char peek
emit char
/

View File

@ -0,0 +1 @@
ABC

View File

@ -0,0 +1 @@
ABD

View File

@ -0,0 +1,12 @@
main:
declare char
calc char peek
emit char
skip
calc char peek
emit char
skip
skip
calc char peek
emit char
/

View File

@ -0,0 +1 @@
ABCD

View File

@ -0,0 +1,4 @@
"A" 1
"
" 2
"B" 1

View File

@ -0,0 +1,35 @@
main:
declare char
declare colno
calc char peek
calc colno stdincolno
emit quote
emit char
emit quote
emit " "
emit colno
emit eol
skip
calc char peek
calc colno stdincolno
emit quote
emit char
emit quote
emit " "
emit colno
emit eol
skip
calc char peek
calc colno stdincolno
emit quote
emit char
emit quote
emit " "
emit colno
emit eol
/

View File

@ -0,0 +1,3 @@
A
B
C

View File

@ -0,0 +1,4 @@
"A" 1
"
" 1
"B" 2

View File

@ -0,0 +1,35 @@
main:
declare char
declare lineno
calc char peek
calc lineno stdinlineno
emit quote
emit char
emit quote
emit " "
emit lineno
emit eol
skip
calc char peek
calc lineno stdinlineno
emit quote
emit char
emit quote
emit " "
emit lineno
emit eol
skip
calc char peek
calc lineno stdinlineno
emit quote
emit char
emit quote
emit " "
emit lineno
emit eol
/

View File

@ -0,0 +1,3 @@
A
B
C

View File

@ -0,0 +1 @@
Success

View File

@ -0,0 +1 @@
Success