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:
Cody Boone Ferguson committed 2023-11-09 08:38:28 -08:00
1 parent 1364ac3e87
commit 959d1559be
5 files changed
+73 -13

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
vanb vanb
vanb.alt
vanb.orig vanb.orig
prog.orig prog.orig
+4 -3
View File
@@ -38,7 +38,8 @@ include ../../var.mk
# Common C compiler warnings to silence # 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 # Common C compiler warning flags
# #
@@ -112,8 +113,8 @@ OBJ= ${PROG}.o
DATA= DATA=
TARGET= ${PROG} TARGET= ${PROG}
# #
ALT_OBJ= ALT_OBJ= ${PROG}.alt.o
ALT_TARGET= ALT_TARGET= ${PROG}.alt
################# #################
+20 -10
View File
@@ -4,6 +4,16 @@
make all 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: ## To use:
@@ -33,8 +43,8 @@ The octal expression may contain:
``` ```
unary operators: +, - unary operators: +, -
binary operators +, -, *, /, % binary operators +, -, *, /, %
hex numbers: x or X follow by hex digits hex numbers: x or X followed by hex digits
decimal numbers: d or D follow by decimal digits decimal numbers: d or D followed by decimal digits
octal numbers: octal digits octal numbers: octal digits
grouping: () 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 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". 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 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 4. The variables are given names which cause visual confusion with the octal
constants. constants.
@@ -77,8 +87,8 @@ time, to make the program harder to understand.
### How It Works: ### How It Works:
It's a recursive descent parser, calling `main` It's a recursive descent parser, calling `main()`
for all of its recursion. `O2` is a state variable, telling main for all of its recursion. `O2` is a state variable, telling `main()`
what grammar non-terminal to parse. `**O7` is the next character. what grammar non-terminal to parse. `**O7` is the next character.
`O3` is an intermediate result. Whenever you see a construct like: `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)? !(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. 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 <X> ::= [0-9]<X> | [A-F]<X> | [a-f]<X> | e
<O> ::= [0-7]<O> | e <O> ::= [0-7]<O> | e
``` ```
\
Here's how the grammar nonterminals map to octal state numbers: Here's how the grammar nonterminals map to octal state numbers:
``` ```
+35
View File
@@ -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);}
+13
View File
@@ -1642,6 +1642,19 @@ arg (as it was 0 at file scope already this is perfectly fine and it means
there's no need to cast it to an int in the function call though that would also there's no need to cast it to an int in the function call though that would also
work). work).
Cody also added the alt code, provided by the author, which is:
```
... a version of the program before it got formatted into the VIII,
augmented with comments showing where each state begins. N1 and N2 are
notes.
```
but fixed to work with clang as well.
NOTE: the `N1` and `N2` are provided as notes in the README.md file describing
this code. Other code is also described there.
## [1994/horton](1994/horton/horton.c) ([README.md](1994/horton/README.md)) ## [1994/horton](1994/horton/horton.c) ([README.md](1994/horton/README.md))