Fix 1993/vanb/README.md
This commit is contained in:
1 parent
a411e62815
commit
1b276f4416
1 file changed
+46
-45
+46
-45
@@ -20,8 +20,7 @@ right parameters. Thank you Cody for your assistance!
|
|||||||
|
|
||||||
./vanb 'exp'
|
./vanb 'exp'
|
||||||
|
|
||||||
where:
|
where 'exp' is an octal expression
|
||||||
'exp' an octal expression
|
|
||||||
|
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
@@ -50,49 +49,47 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
|
|
||||||
## Author's comments
|
## Author's comments
|
||||||
|
|
||||||
The program does no error checking - erroneous expressions will
|
The program does no error checking - erroneous expressions will
|
||||||
produce spurious results. Note that unary '-' is an operator. Thus,
|
produce spurious results. Note that unary '-' is an operator. Thus,
|
||||||
decimal -46 would be entered as -d46 and not d-46.
|
decimal -46 would be entered as -d46 and not d-46.
|
||||||
|
|
||||||
What Makes This Program Special:
|
What Makes This Program Special:
|
||||||
|
|
||||||
0) Of course, the fact that the program takes input and produces output
|
0. Of course, the fact that the program takes input and produces output in
|
||||||
in octal, rather than a more useful system like decimal, makes
|
octal, rather than a more useful system like decimal, makes it "special".
|
||||||
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
|
2. There are no global or local variables other than the parameters to main.
|
||||||
to main
|
|
||||||
|
|
||||||
3) All of the constants in the program are expressed in octal - including
|
3. All of the constants in the program are expressed in octal - including the
|
||||||
the printf string.
|
printf string.
|
||||||
|
|
||||||
4) The variables are given names which cause visual confusion with the
|
4. The variables are given names which cause visual confusion with the octal
|
||||||
octal constants.
|
constants.
|
||||||
|
|
||||||
5) The program is formatted like a roman numeral 8. The significance of
|
5. The program is formatted like a roman numeral 8. The significance of 8 is
|
||||||
8 is obvious. I chose roman numerals because it is a numbering
|
obvious. I chose roman numerals because it is a numbering system even more
|
||||||
system even more arcane than octal. It's not very 'deceptive',
|
arcane than octal. It's not very 'deceptive', but it's difficult to deceptively
|
||||||
but it's difficult to deceptively format a program which has no
|
format a program which has no explicit control structures (other than ?:'s).
|
||||||
explicit control structures (other than ?:'s).
|
|
||||||
|
|
||||||
6) Many simple tasks are done many times. I tried to do these differently
|
6. Many simple tasks are done many times. I tried to do these differently each
|
||||||
each time, to make the program harder to understand.
|
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:
|
||||||
|
|
||||||
!(expression with O2)?
|
!(expression with O2)?
|
||||||
|
|
||||||
it's decrementing & testing O2 to see what state it's in. Comparisons
|
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) :
|
||||||
|
|
||||||
Here's the grammar ('e' denotes the empty string) :
|
|
||||||
|
|
||||||
<E> ::= <T><E'>
|
<E> ::= <T><E'>
|
||||||
<E'> ::= +<T><E'> | -<T><E'> | e
|
<E'> ::= +<T><E'> | -<T><E'> | e
|
||||||
@@ -104,7 +101,8 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
<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:
|
||||||
|
|
||||||
<E> is 012
|
<E> is 012
|
||||||
<E'> is 011
|
<E'> is 011
|
||||||
@@ -116,9 +114,10 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
<X> is 05
|
<X> is 05
|
||||||
<O> is 03
|
<O> is 03
|
||||||
|
|
||||||
Here's a version of the program before it got formatted into the VIII,
|
Here's a version of the program before it got formatted into the VIII,
|
||||||
augmented with comments showing where each state begins. N1 and N2 are
|
augmented with comments showing where each state begins. N1 and N2 are
|
||||||
notes:
|
notes:
|
||||||
|
|
||||||
|
|
||||||
#define O5 main
|
#define O5 main
|
||||||
O5(O2,O7,O3)char**O7;
|
O5(O2,O7,O3)char**O7;
|
||||||
@@ -156,18 +155,20 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
/* C */ (++*O7,O3);
|
/* C */ (++*O7,O3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Note N1: It should never enter this state, unless the user invokes the
|
Note N1: It should never enter this state, unless the user invokes the
|
||||||
program with no parameters, in which case it just returns 0.
|
program with no parameters, in which case it just returns 0.
|
||||||
|
|
||||||
Note N2: Since the program is properly invoked with 1 parameter, this is
|
Note N2: Since the program is properly invoked with 1 parameter, this is
|
||||||
the first state it will go into. This state just invokes
|
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:
|
The E and T states work like this:
|
||||||
|
|
||||||
int e(){ return eprime( t() ); }
|
int e(){ return eprime( t() ); }
|
||||||
|
|
||||||
The E' and T' states work like this:
|
|
||||||
|
The E' and T' states work like this:
|
||||||
|
|
||||||
|
|
||||||
int eprime( int intermediate )
|
int eprime( int intermediate )
|
||||||
{
|
{
|
||||||
@@ -179,8 +180,8 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
else return intermediate;
|
else return intermediate;
|
||||||
}
|
}
|
||||||
|
|
||||||
The D, X and O states work like this (they assume that they're initially
|
The D, X and O states work like this (they assume that they're initially
|
||||||
called with 0):
|
called with 0):
|
||||||
|
|
||||||
int octal( int intermediate )
|
int octal( int intermediate )
|
||||||
{
|
{
|
||||||
@@ -193,7 +194,7 @@ expression, otherwise it might become hard to understand. :-)
|
|||||||
else return intermediate;
|
else return intermediate;
|
||||||
}
|
}
|
||||||
|
|
||||||
F and C work similarly.
|
F and C work similarly.
|
||||||
|
|
||||||
## Copyright and CC BY-SA 4.0 License:
|
## Copyright and CC BY-SA 4.0 License:
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user