Format/typo check 1993/vanb + add alt code
The alt code was provided by the author as a kind of spoiler but I fixed it to also work with clang like I did with the original entry. Silenced some warnings (all on macOS are now silenced, at least with default cc which is clang). Format/typo check README.md file. This should complete 1993/vanb.
This commit is contained in:
1 parent
1364ac3e87
commit
959d1559be
5 files changed
+73
-13
No files matched your search
@@ -1,3 +1,4 @@
|
||||
vanb
|
||||
vanb.alt
|
||||
vanb.orig
|
||||
prog.orig
|
||||
+4
-3
@@ -38,7 +38,8 @@ include ../../var.mk
|
||||
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
CSILENCE= -Wno-deprecated-non-prototype -Wno-unused-value
|
||||
CSILENCE= -Wno-deprecated-non-prototype -Wno-unused-value -Wno-unused-parameter \
|
||||
-Wno-implicit-int
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
@@ -112,8 +113,8 @@ OBJ= ${PROG}.o
|
||||
DATA=
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
ALT_OBJ= ${PROG}.alt.o
|
||||
ALT_TARGET= ${PROG}.alt
|
||||
|
||||
|
||||
#################
|
||||
|
||||
+20
-10
@@ -4,6 +4,16 @@
|
||||
make all
|
||||
```
|
||||
|
||||
### Bugs and (Mis)features:
|
||||
|
||||
The current status of this entry is:
|
||||
|
||||
```
|
||||
STATUS: INABIAF - please **DO NOT** fix
|
||||
```
|
||||
|
||||
For more detailed information see [1993 vanb in bugs.md](/bugs.md#1993-vanb).
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
@@ -33,8 +43,8 @@ The octal expression may contain:
|
||||
```
|
||||
unary operators: +, -
|
||||
binary operators +, -, *, /, %
|
||||
hex numbers: x or X follow by hex digits
|
||||
decimal numbers: d or D follow by decimal digits
|
||||
hex numbers: x or X followed by hex digits
|
||||
decimal numbers: d or D followed by decimal digits
|
||||
octal numbers: octal digits
|
||||
grouping: ()
|
||||
```
|
||||
@@ -57,12 +67,12 @@ decimal `-46` would be entered as `-d46` and not `d-46`.
|
||||
0. Of course, the fact that the program takes input and produces output in
|
||||
octal, rather than a more useful system like decimal, makes it "special".
|
||||
|
||||
1. The entire program consists of a single expression, returned from main.
|
||||
1. The entire program consists of a single expression, returned from `main()`.
|
||||
|
||||
2. There are no global or local variables other than the parameters to main.
|
||||
2. There are no global or local variables other than the parameters to `main()`.
|
||||
|
||||
3. All of the constants in the program are expressed in octal - including the
|
||||
printf string.
|
||||
`printf(3)` string.
|
||||
|
||||
4. The variables are given names which cause visual confusion with the octal
|
||||
constants.
|
||||
@@ -77,8 +87,8 @@ time, to make the program harder to understand.
|
||||
|
||||
### How It Works:
|
||||
|
||||
It's a recursive descent parser, calling `main`
|
||||
for all of its recursion. `O2` is a state variable, telling main
|
||||
It's a recursive descent parser, calling `main()`
|
||||
for all of its recursion. `O2` is a state variable, telling `main()`
|
||||
what grammar non-terminal to parse. `**O7` is the next character.
|
||||
`O3` is an intermediate result. Whenever you see a construct like:
|
||||
|
||||
@@ -86,10 +96,10 @@ what grammar non-terminal to parse. `**O7` is the next character.
|
||||
!(expression with O2)?
|
||||
```
|
||||
|
||||
it's decrementing & testing `O2` to see what state it's in. Comparisons
|
||||
it's decrementing and testing `O2` to see what state it's in. Comparisons
|
||||
involving `**O7` and octal constants are looking for certain characters.
|
||||
|
||||
Here's the grammar `('e'` denotes the empty string) :
|
||||
Here's the grammar (`'e'` denotes the empty string) :
|
||||
|
||||
|
||||
```
|
||||
@@ -103,7 +113,7 @@ Here's the grammar `('e'` denotes the empty string) :
|
||||
<X> ::= [0-9]<X> | [A-F]<X> | [a-f]<X> | e
|
||||
<O> ::= [0-7]<O> | e
|
||||
```
|
||||
\
|
||||
|
||||
Here's how the grammar nonterminals map to octal state numbers:
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
O5(O2,O7,O3)char**O7;
|
||||
{
|
||||
return
|
||||
/* N1 */ !(O2+=~01+01) ?\
|
||||
00:
|
||||
/* N2 */ !(O2-=02>01) ?\
|
||||
printf("\045\157\012",O5(012,O7+01,00)):
|
||||
/* O */ !(O2-=02>>01) ?\
|
||||
(**O7<=067 && **O7>057 ? O5(03,O7,*(*O7)++-060+010*O3):O3):
|
||||
/* D */ !(O2-=-O3-~O3) ?\
|
||||
(072>**O7 && 060<=**O7 ? O5(04,O7,012*O3-060+*(*O7)++):O3):
|
||||
/* X */ !(O2-=!O3+!!O3) ?\
|
||||
(**O7>057 && **O7<=071 ? O5(05,O7,*(*O7)+++O3*020-060):
|
||||
**O7<=0106 && 0101<=**O7 ? O5(05,O7,020*O3+*(*O7)++-067):
|
||||
0140<**O7 && **O7<0147 ? O5(05,O7,-0127+*(*O7)+++020*O3):O3):
|
||||
/* F */ !(O2-=02-01) ?\
|
||||
(**O7==050 ? 050**++*O7,O5(013,O7,O5(012,O7,00)):
|
||||
**O7<056 && 054<**O7 ? 055**++*O7,-O5(06,O7,00):
|
||||
054>**O7 && 052<**O7 ? 050**(*O7)++,O5(06,O7,00):
|
||||
!(**O7^0170)||!(0130^**O7) ? *++*O7,O5(05,O7,00):
|
||||
**O7==0144||**O7==0104 ? ++*O7,O5(04,O7,00):O5(03,O7,00)):
|
||||
/* T' */ !--O2 ?\
|
||||
(**O7==052 ? O5(07,O7,O3*(*++*O7,O5(06,O7,00))):
|
||||
!(045-**O7) ? O5(07,O7,O3%(03+(*O7)++,O5(06,O7,00))):
|
||||
!(**O7^057) ? O5(07,O7,O3/(03-*++*O7,O5(06,O7,00))):O3):
|
||||
/* T */ !(O2+=01-02) ?\
|
||||
O5(07,O7,O5(06,O7,00)):
|
||||
/* E' */ !(O2+=-02/02) ?\
|
||||
(!(**O7-053)?O5(011,O7,O3+(++*O7,O5(010,O7,00))):
|
||||
!(055^**O7) ? O5(011,O7,O3-(03+*(*O7)++,O5(010,O7,00))):O3):
|
||||
/* E */ !(O2-=0563&0215) ?\
|
||||
O5(011,O7,O5(010,O7,00)):
|
||||
/* C */ (++*O7,O3);
|
||||
}
|
||||
main(O2,O7,O3)char**O7,**O3;{return O5(O2,O7,0);}
|
||||
Reference in new issue
Block a user