当前位置:网站首页>The master programmer "plays" a C program that is not like C
The master programmer "plays" a C program that is not like C
2022-06-12 04:46:00 【Big craft】
author | Brian Robert Callahan
compile | Zhang Jie
Coordinating editor | Du min
To make the challenge interesting ,Brian Robert Callahan( Lecturer in information technology and network science at Rensselaer Institute of technology in northern New York ) Decided to write one that doesn't look like C Of C Program . If you put C Language becomes another language , Then write the program in that language , So use C What happens when the compiler compiles the program ?
Can write the following program ,Brian Robert Callahan I think it's a glorious thing .
#include"cpaint.h"
var a, b, c, h, i, l, v, x, y, q, w, p size 65535 ,
packed n size 13 ꞉integer ;
procedure display(r,s,c) ;
begin
LOOP
call A(Z) ;
call H(y,x) ;
call B(Z)
POOL ;
y ꞉= r;
x ꞉= s;
call A(c) ;
call H(y,x) ;
call B(c) ;
call refresh()
end ;
procedure fill(y,x,c,a) ;
begin
if(y<0 or y>w-1 or x<0 or x>q-1 or c = a or Z <> a)fill꞉= -1 ;
call draw(c) ;
call fill(y+1,x,c,a) ;
call fill(y-1,x,c,a) ;
call fill(y,x-1,c,a) ;
call fill(y,x+1,c,a)
end ;
procedure save(r,s) ;
begin
i ꞉= 0 ;
while(i<13)do
begin
n[i] ꞉= 0 ;
i ꞉= i+1
end ;
call move(w>>1,(q>>1)-6) ;
call printw("Save: ") ;
call echo() ;
call getnstr(n,12) ;
call noecho() ;
call open(n,"w+") ;
call writeChar(83) ;
call writeChar(w) ;
call writeChar(q) ;
LOOP
call writeChar(Z)
POOL ;
y ꞉= r;
x ꞉= s;
call close ;
call move(y,x)
end ;
procedure load(packed ʌ n) ;
begin
call open(n,"r") ;
call check ;
LOOP
readln(c);
call draw(c)
POOL ;
c ꞉= 0;
call close
end ;
procedure m() ;
begin
l ꞉= 0 ;
v ꞉= 1 ;
call A(c) ;
call H(0,0) ;
call B(c) ;
call refresh() ;
while(v)do
begin
read(inp) ;
'/':l ꞉= not l ; if(l)call draw(c) ; OK
'k':y ꞉= y-1 ; if(y<0)y ꞉= 0 ; if(l)call draw(c) ; OK
'j':y ꞉= y+1 ; if(y>w-1)y ꞉= w-1 ; if(l)call draw(c) ; OK
'h':x ꞉= x-1 ; if(x<0)x ꞉= 0 ; if(l)call draw(c) ; OK
'l':x ꞉= x+1 ; if(x>q-1)x ꞉= q-1 ; if(l)call draw(c) ; OK
' ':call draw(c) ; OK
'c':c ꞉= c+1 ; if(c = M)c ꞉= 0 ; OK
'd':call draw(15) ; OK
'f':call fill(y,x,c,Z) ; OK
's':call save(y,x) ; OK
'q':v ꞉= 0 ; OK
'v':c ꞉= c-1 ; if(c = N)c ꞉= M-1 ; CALL display(y,x,c)
end
end ;
procedure main(I c,packed ʌ ʌ v) ;
begin
call start ;
call getmaxyx(stdscr,w,q) ;
if(w>M)w ꞉= M ;if(q>M)q ꞉= M ;
call start_color() ;
while(x<M)do
begin
call init_pair(x,x,x) ;
x ꞉= x+1
end ;
LOOP
call draw(15)
POOL ;
if(c = 2)call load(v[c-1]) ; call display(0,0,0) ; call m() ; call endwin()
end ;
call main.Through this code , Maybe many netizens say frankly , This is not C Code , It contains Pascal All the features of language , Use semicolons as statement separators instead of statement terminators , use “:=” Indicates assignment , Maybe some more Algol( An instruction based programming language ) Of LOOP……POOL grammar . It even has Pascal Return assignment of language , That is, assign a value to the function , Is its return value .
however ,Brian Robert Callahan Explain this , I heard recently that A+、K and Q Language ( They are APL and J Array programming languages like ) The developer of the Arthur Whitney Will use C Preprocessor to create your own language , Then use this self-defined language to realize his language . therefore , He decided to try this interesting experiment .
Brian Robert Callahan be based on PL/0 Custom language for , Write a compiler . The highlight of this exercise is C Compiler will UTF-8 Characters are understood as valid characters of identifiers .Brian Robert Callahan Used a lot to look like ASCII( American standard code for information exchange ) The characters of , Not really ASCII, Eventually accepted as a valid identifier .C The preprocessor can well convert these identifiers into corresponding instructions . Here you can see the hidden header file .
If you want to see C The real look of the code , Please try to run :
$ cc -E cpaint.c | clang-format | lessIf you're interested , You might as well try the above program !
Link to the original text :Brian Robert Callahan
边栏推荐
- Common MySQL date query
- QT compile 45 graphic report of security video monitoring system
- leetcode 205. Isomorphic Strings
- How Windows installs multiple versions of MySQL and starts it at the same time
- How to construct a search string?
- L1-068 harmonic average (10 points)
- QT compiling security video monitoring system 44 video uploading
- Thousand word masterpiece "programming biography"
- Oracle paging query ~~rownum (line number)
- leetcode 263. Ugly number
猜你喜欢

Drive safety coding & troubleshooting guide

Ten trends of Internet Security in 2022 industry released

Gao Xiang slam14 notes on three Lie groups and Lie algebra

Using datetime in MySQL

File contains (regardless of suffix) Apache log remote file contains PHP encapsulated pseudo protocol:

Ubunt 20.04 uses CDROM or ISO as the installation source

Token based authentication

Data processing and data set preparation

How to use union all in LINQ- How to use union all in LINQ?

如何制作数据集并基于yolov5训练成模型并部署
随机推荐
QT compiling security video monitoring system 43- picture playback
Parallelization of accelerated training tf data. Dataset generator
JS function and variable have the same name (function and variable parsing rules)
[backtracking method] backtracking method to solve the problem of Full Permutation
Work report of epidemic data analysis platform [42] codenet
Sword finger offer30 days re brush
PostgreSQL age XID maintenance prevents the database from being read-only
Install/Remove of the Service Denied!
L1-064 AI core code valued at 100 million (20 points)
Simple Tetris
Sustainable service business models
[backtracking method] queen n problem
What is reverse repurchase of treasury bonds? Is the reverse repurchase of treasury bonds safe?
疫情数据分析平台工作报告【4】跨域相关
CCF access control system
leetcode 205. Isomorphic Strings
From science to startup
QT experiment - gold coin flipping games
Zabbix6.0 new feature GEOMAP map marker can you use it?
According to aiqicha, keep went public in Hong Kong and hit the "first share of online fitness"