当前位置:网站首页>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
边栏推荐
- SQL injection upload one sentence Trojan horse (turn)
- 千字巨著《编程后传》
- eBPF系列学习(4)了解libbpf、CO-RE (Compile Once – Run Everywhe) | 使用go开发ebpf程序(云原生利器cilium ebpf )
- leetcode 205. Isomorphic Strings
- Gavin teacher's perception of transformer live class - rasa dialogue robot project practice in the field of education agency mode and core component source code analysis under the microservice of educ
- leetcode797. 所有可能的路径(中等)
- [backtracking method] queen n problem
- Asp. Net core EF value conversion
- Thousand word masterpiece "programming biography"
- PostgreSQL age XID maintenance prevents the database from being read-only
猜你喜欢

Install pycharm under Kali and create a shortcut access

疫情数据分析平台工作报告【1】数据采集
![[wechat applet] the mobile terminal selects and publishes pictures](/img/9a/46bc4a7bf9b70d26b0e24fe02f747d.jpg)
[wechat applet] the mobile terminal selects and publishes pictures

MySQL master-slave construction and Django implementation of read-write separation

1008 color classification

Summary of common interview questions in redis

Day17 array features array boundary array application traversal array multidimensional array creation and traversal arrays operation array bubble sort

Based on Visual Studio code Net Maui cross platform mobile application development

Bearpi IOT serial port transceiver 1- normal mode

MFC General dialog color dialog
随机推荐
Work report of epidemic data analysis platform [1] data collection
[automation] generate xlsx report based on openstack automated patrol deployed by kolla
eBPF系列学习(4)了解libbpf、CO-RE (Compile Once – Run Everywhe) | 使用go开发ebpf程序(云原生利器cilium ebpf )
In the era of smart retail, Weimeng reshapes the value of "shopping guide"
Work report of epidemic data analysis platform [6] visual drawing
MFC General dialog color dialog
@What happens if bean and @component are used on the same class?
leetcode797. All possible paths (medium)
L1-068 harmonic average (10 points)
Ubunt 20.04 uses CDROM or ISO as the installation source
[backtracking based on bit operation] queen n problem 2
Work report of epidemic data analysis platform [4] cross domain correlation
How to make datasets, train them into models and deploy them based on yolov5
Epidemic data analysis platform work report [2] interface API
1007- stair climbing
Common MySQL date query
Sword finger offer30 days re brush
Memory protection
Redis learning notes (continuously updating)
Musk promotes the development of fascinating new products partners remind important questions