Fix 1993/vanb/README.md

This commit is contained in:
Cody Boone Ferguson committed 2023-03-30 12:11:08 -07:00
1 parent a411e62815
commit 1b276f4416
1 file changed
+24 -23
+24 -23
View File
@@ -20,8 +20,7 @@ right parameters. Thank you Cody for your assistance!
./vanb 'exp'
where:
'exp' an octal expression
where 'exp' is an octal expression
## Try:
@@ -56,44 +55,42 @@ expression, otherwise it might become hard to understand. :-)
What Makes This Program Special:
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".
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.
3. All of the constants in the program are expressed in octal - including the
printf string.
4) The variables are given names which cause visual confusion with the
octal constants.
4. The variables are given names which cause visual confusion with the octal
constants.
5) The program is formatted like a roman numeral 8. The significance of
8 is obvious. I chose roman numerals because it is a numbering
system even more arcane than octal. It's not very 'deceptive',
but it's difficult to deceptively format a program which has no
explicit control structures (other than ?:'s).
5. The program is formatted like a roman numeral 8. The significance of 8 is
obvious. I chose roman numerals because it is a numbering system even more
arcane than octal. It's not very 'deceptive', but it's difficult to deceptively
format a program which has no explicit control structures (other than ?:'s).
6) Many simple tasks are done many times. I tried to do these differently
each time, to make the program harder to understand.
6. Many simple tasks are done many times. I tried to do these differently each
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
what grammar non-terminal to parse. **O7 is the next character.
O3 is an intermediate result. Whenever you see a construct like:
what grammar non-terminal to parse. `**O7` is the next character.
`O3` is an intermediate result. Whenever you see a construct like:
!(expression with O2)?
it's decrementing & 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) :
<E> ::= <T><E'>
<E'> ::= +<T><E'> | -<T><E'> | e
<T> ::= <F><T'>
@@ -104,6 +101,7 @@ expression, otherwise it might become hard to understand. :-)
<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:
<E> is 012
@@ -120,6 +118,7 @@ expression, otherwise it might become hard to understand. :-)
augmented with comments showing where each state begins. N1 and N2 are
notes:
#define O5 main
O5(O2,O7,O3)char**O7;
{
@@ -161,14 +160,16 @@ expression, otherwise it might become hard to understand. :-)
Note N2: Since the program is properly invoked with 1 parameter, this is
the first state it will go into. This state just invokes
printf, and sends the parser to state 012 (which is <E>).
printf, and sends the parser to state 012 (which is `<E>`).
The E and T states work like this:
int e(){ return eprime( t() ); }
The E' and T' states work like this:
int eprime( int intermediate )
{
if( ch == '+' )