LOSP.md
Last active
October 15, 2017 02:44
-
-
Save val314159/822ca4353e5ec9b743ed82fb573f39a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format t "hello!~%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmacro syntax (x) `(function ,x) | |
defun hasfeat (x) | |
car | |
member x *features* | |
if | |
hasfeat :clisp | |
defvar **args** *args* | |
if | |
hasfeat :sbcl | |
defvar **args** | |
cdr *posix-argv* | |
defun xit (code) | |
if | |
hasfeat :sbcl | |
exit :code code | |
exit code | |
defconstant true t | |
defconstant false nil | |
defvar f false | |
defun errout (&rest R) | |
progn | |
apply #'format stderr R | |
xit 1 | |
defun hasfeat (x) | |
car | |
member x *features* | |
if | |
hasfeat :clisp | |
defvar **args** *args* | |
if | |
hasfeat :sbcl | |
defvar **args** | |
cdr *posix-argv* | |
defvar stdin *standard-input* | |
defvar stdout *standard-output* | |
defvar stderr *error-output* | |
defvar inpname "#<stdin_>" | |
defvar outname "#<stdout>" | |
defvar errname "#<stderr>" | |
defvar line nil | |
defvar lineno 0 | |
defvar arr | |
list 0 | |
defvar prev nil | |
defvar prevno 0 | |
defvar prevspc 0 | |
defvar linespc 0 | |
defun last-char (str) | |
elt str (- (length str) 1) | |
defun last-char-is-colon (str) | |
if | |
eq | |
elt ":" 0 | |
last-char str | |
values t | |
defun trim-prev (str) | |
string-right-trim str prev | |
defun spaces (str acc) | |
if (eq (elt str acc) (elt " " 0)) | |
spaces str (+ acc 1) | |
values acc | |
defun %poparr (spc acc) | |
let | |
\\ | |
top | |
car arr | |
when (< top spc) | |
errout "~a:~d:~d: ERRR: Inconsistent indentation1xxx!" | |
values inpname | |
values lineno | |
+ top 1 | |
if (= top spc) acc | |
progn | |
pop arr | |
%poparr spc | |
incf acc | |
defun %countline (prevno prev prevspc linespc) | |
if (< prevspc linespc) | |
push linespc arr | |
if (< prevspc linespc) -1 | |
if (< prevspc linespc) 0 | |
%poparr linespc 0 | |
defun %%procline (prevno prev cnt prefix suffix) | |
format stdout "~a~a" prefix prev | |
loop :for x from 1 to cnt :do | |
format stdout ")" | |
format stdout "~a~%" suffix | |
defun xspecial (prevno prev cnt) | |
push linespc arr | |
let | |
\\ | |
srch (search " " prev :start2 prevspc) | |
let | |
\\ | |
lhs (subseq prev 0 srch) | |
let | |
\\ | |
rhs (subseq prev (incf srch)) | |
let | |
\\ | |
sstr (format nil "~a( ~a)" lhs rhs) | |
%%procline prevno sstr cnt "( " "(block" | |
defun %procline (prevno prev prevspc linespc cnt) | |
if (last-char-is-colon prev) | |
if (< cnt 0) | |
progn | |
push linespc arr | |
xspecial prevno (trim-prev ":") cnt | |
errout "~a:~d:~d: ERRR: Inconsistent indentation2!" inpname lineno (+ linespc 1) | |
%%procline prevno prev cnt | |
if (< cnt 0) "( " "( " | |
if (< cnt 0) "" ")" | |
defun procline (lineno line) | |
let | |
\\ | |
prevspc linespc | |
setf prevspc | |
spaces prev 0 | |
setf linespc | |
spaces line 0 | |
%procline prevno prev prevspc linespc | |
%countline prevno prev prevspc linespc | |
defun empty (x) | |
if (zerop (length x)) t | |
defun usleep (x) | |
sleep (/ x 1000.0) | |
defun main (inpname outname) | |
setf stdin | |
open inpname | |
setf stdout | |
open outname :direction :output :if-exists :supersede | |
loop | |
incf lineno | |
let | |
\\ | |
line | |
read-line stdin nil nil | |
if line | |
unless (empty line) | |
if prev | |
procline lineno line | |
setf prevno lineno | |
rotatef prev line | |
return | |
if prev | |
procline lineno ";;<<<eof>>>;;" | |
usleep 1 | |
apply #'main **args** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys | |
from sys import * | |
Args = argv[1:] | |
Lineno = 0 | |
Line = '\n' | |
def readline(): | |
global Line, Lineno | |
Line = stdin.readline() | |
Lineno += 1 | |
return Line | |
OutPrevno = 0 | |
OutLineno = 0 | |
def writeline(a,s): | |
global OutLineno , OutPrevno | |
if a is not None : OutPrevno = a | |
while OutLineno < OutPrevno: | |
OutPrevno += 1 | |
OutLineno += 1 | |
pass | |
if OutPrevno : print s | |
OutLineno += 1 | |
pass | |
def main(*args): | |
print ">> ll.py v0.0.1", Args | |
writeline(0,"q0") | |
writeline(1,"q1") | |
writeline(2,"") | |
OutLineno = 3 | |
writeline(None,"q3") | |
OutLineno = 5 | |
writeline(None,"q5") | |
return | |
writeline(Lineno, Line) | |
while readline(): | |
if Line != '\n': | |
writeline(Lineno, Line) | |
pass | |
writeline(Lineno, Line) | |
pass | |
if __name__=='__main__': main(*Args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qall: | |
cat DATA | python ll.py | cat -vet | |
call: clean all parse.lsp hello.lsp | |
all: losp.lisp tst | |
tst: ll.lsp zz.lsp ; diff $^ | |
ll.lsp: ll.lisp ll.losp ; clisp ll.lisp ll.losp $@ ; perl -i -npe 's/\\//g;' $@ | |
zz.lsp: ll.lsp ll.losp ; clisp ll.lsp ll.losp $@ ; perl -i -npe 's/\\//g;' $@ | |
parse.lsp: parse.losp losp.lisp ; clisp ll.lsp $< $@ ; perl -i -npe 's/\\//g;' $@ | |
hello.lsp: hello.losp losp.lisp ; clisp ll.lsp $< $@ ; perl -i -npe 's/\\//g;' $@ | |
losp.lisp: zz.lsp ; cp $< $@ | |
%.lisp:%.losp;unsweeten<$*.losp>$@;if [ -s ERR.tmp ];then exit 99;fi | |
clean: ; rm -fr *.{lisp,lsp,tmp} *~ ? ?? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment