Shen YACC
Shen contains a YACC, just as Qi II, but the syntax was modified in 9.0 to bring it closer to Shen. This
section briefly describes the differences.
The -*- (ditto -s- and -o-) indicating the head of the input stream is gone from YACC II and just as in Shen
variables mark the position of isolated elements. This makes for a more powerful and flexible notation. The
use of (fail) in a semantic action to trigger backtracking is dropped in favour of a guard. Thus the following
tests a list of numbers to determine if the list is binary.
(defcc <binary?>
X <binary?> := true where (element? X [0 1]);
X := true where (element? X [0 1]);
<e> := false;)
<!> consumes the remaining input.
(defcc <tl>
_ <!> := <!>;)
returns the tail of a list. Shen-YACC recognises lists in the input.
(defcc <asbs>
[a b] <asbs>;
[a b];)
recognises lists of the form [[a b]], [[a b] [a b]], ....
The S series of kernels introduced types for Shen YACC functions.
(2+) (defcc <total>
{(list number) ==> number}
X <total> := (+ X <total>);
X := X;)
(fn <total>) : ((list number) ==> number)
(3+) (compile (fn <total>) [1 2 3 4])
10 : number
TBoS is the source for the technology of Shen YACC. |