Skip to content

Instantly share code, notes, and snippets.

View ytaki0801's full-sized avatar

TAKIZAWA Yozo ytaki0801

View GitHub Profile
@ytaki0801
ytaki0801 / w23tm-ds.py
Created December 10, 2022 11:41
Wolfram's 2-state 3-symbol Turing Machine
# Wolfram's 2-state 3-symbol Turing Machine
from time import sleep
delta = {1: {0: (1, 1, 2), 1: (2, -1, 1), 2: (1, -1, 1)},
2: {0: (2, -1, 1), 1: (2, 1, 2), 2: (0, 1, 1)}}
ds = {0: ' ', 1: '.', 2: '*'}
tlen = 80
tape, head, state = [0] * tlen, int(tlen / 2) - 9, 1
@ytaki0801
ytaki0801 / w23tm-turtle.py
Last active December 10, 2022 14:44
Wolfram's 2-state 3-symbol Turing Machine as an Universal TM with Turtle Graphics
# Wolfram's 2-state 3-symbol Turing Machine as an Universal TM
# with Turtle Graphics
from time import sleep
from turtle import fd, rt, lt, setpos, pu, pd
pu(); setpos(-300, 300); pd(); sleep(5)
delta = {1: {0: (1, 1, 2), 1: (2, -1, 1), 2: (1, -1, 1)},
2: {0: (2, -1, 1), 1: (2, 1, 2), 2: (0, 1, 1)}}
@ytaki0801
ytaki0801 / letLISP-REPL.py
Last active April 6, 2024 12:42
A Pure LISP Interpreter with dynamic-scope named-let in pseudocode-style Python 3
####
#### letLISP-REPL.py:
#### A Pure LISP Interpreter
#### with dynamic-scope named-let
#### in pseudocode-style Python 3
####
#### (C) 2022 TAKIZAWA Yozo
#### This code is licensed under CC0,
#### Creative Commons 0 as Public Domain
####
@ytaki0801
ytaki0801 / letLISP.py
Last active April 6, 2024 12:42
A Pure LISP Interpreter with dynamic-scope named-let in pseudocode-style Python 3
####
#### letLISP.py:
#### A Pure LISP Interpreter
#### with dynamic-scope named-let
#### in pseudocode-style Python 3
####
#### (C) 2022 TAKIZAWA Yozo
#### This code is licensed under CC0.
#### https://creativecommons.org/publicdomain/zero/1.0/
####
@ytaki0801
ytaki0801 / ev.py
Last active February 22, 2022 10:40
A Pure LISP Interpreter in Pseudocode-style Python 3
####
#### ev.py: A Pure LISP Interpreter
#### in Pseudocode-style Python 3
####
#### (C) 2022 TAKIZAWA Yozo
#### This code is licensed under CC0.
#### https://creativecommons.org/publicdomain/zero/1.0/
####
#### <examples>
@ytaki0801
ytaki0801 / swrap.sh
Last active February 10, 2022 16:47
Parser for simplest S-expression or array-expression of parentheses by using noncanonical 1-character input in POSIX Shell
#!/bin/sh
# One token input function with look-ahead caching
stty -icanon
LF="$(printf \\012)"
get_c1 () {
case "$LH" in ("") GC1R=$(dd bs=1 count=1 2>/dev/null)
;;(*) GC1R="$LH"; LH="" ;;esac
}
skip_spaces () {
@ytaki0801
ytaki0801 / sread-c1.py
Created February 8, 2022 14:20
Parser for simplest S-expression or array-expression of parentheses by using 1-character input in Python
from sys import stdin
LH = False
def get_token():
def put_c1(x): global LH; LH = x
def null_c1(): global LH; LH = False
def get_c1():
if not LH:
try: return stdin.read(1)
except EOFError: pass
@ytaki0801
ytaki0801 / sread-c1-dot.scm
Created February 8, 2022 02:48
Parser for simplest S-expression with dot notation by using 1-character input in Scheme
(define *lh* #f)
(define (get-token)
(define (put-c1 x) (set! *lh* x))
(define (null-c1) (set! *lh* #f))
(define (get-c1) (if *lh* (let ((lh *lh*)) (null-c1) lh) (read-char)))
(define (tstring t) (list->string (reverse t)))
(define (skip-spaces)
(do ((c (get-c1) (get-c1)))
((not (member c (string->list " \n\r"))) (put-c1 c))))
(let loop ((c (get-c1)) (t '()))
@ytaki0801
ytaki0801 / sread-c1.scm
Last active February 21, 2022 17:41
Parser for simplest S-expression by using 1-character input in Scheme
(define *lh* #f)
(define (get-token)
(define (put-c1 x) (set! *lh* x))
(define (null-c1) (set! *lh* #f))
(define (get-c1) (if *lh* (let ((lh *lh*)) (null-c1) lh) (read-char)))
(define (tstring t) (list->string (reverse t)))
(define (skip-spaces)
(do ((c (get-c1) (get-c1)))
((not (member c (string->list " \n\r"))) (put-c1 c))))
(let loop ((c (get-c1)) (t '()))
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
extern int yylex(void);
int yyerror(const char *s) { printf("%s\n", s); return 0; }
int node[4096]; int nnum = 1;