ambmcmdmem.lmn: this file is (C) Copyright 2006 Peri Hankey (mpah@users.sourceforge.net). This text is published under the terms of the Gnu General Program License, and comes with absolutely no warranty.
{a^m*b^m*c^m*d^m*e^m, where a,b,c,d,e are terminal & ( m == 0 | m > 0) & (no variables permitted)}
Test harness - _S may be empty, so require terminator
esc out <- eof - ; // H1 .[ \n] <- eof - ; // H2 - _Err <- eof - esc "no\n" ; // H3 - _S ';' <- eof - esc "yes\n"; // H4
- {repeat .[^\n]} <- _Err ; // E1
Accept null case for _S, or recognise _P and use result to control recognition for _Q:
- <- _S ; - _P _G _Q <- _S ;
Each 'a' produces _x to drive iteration in the second half:
- <- _A ; 'a' _A <- _A _x; 'a' _A <- _P _x;
Generate one of each of the driver symbols for each _x - eg _x _x <- _e _e _d _d _c _c _b _b - they emerge in reverse order. The _x symbols are passed from the rules for _B to the rules for _C and so on.
- _B _C _D _E <- _G;
The main rule in each of the following pairs replaces each _x by _x and a driver symbol (except for the first, which only produces the driver symbol). Each main rule goes top down (looks for _x) so as to give the _x propagation rules a chance. The alternative would be to permit the propagation rules in any context.
- _x _E <- _E _e ; - <- _E ;
- _x _D <- _D _x _d ; - <- _D ;
- _x _C <- _C _x _c ; - <- _C ;
- _x _B <- _B _x _b ; - <- _B ;
Propagate interleaved _x symbols back up the chain
_e _x <- _x _e; _d _x <- _x _d; _c _x <- _x _c; _b _x <- _x _b;
Use recursion to match driver symbol sequences against the input - eg _e ( _d ( _c ( _b 'b' ) 'c' ) 'd' ) 'e'
_e _Y 'e' <- _Q ; // 'e' for each _e
_b _Y 'b' <- _Y ; // 'b' for each _b _c _Y 'c' <- _Y ; // 'c' for each _c _d _Y 'd' <- _Y ; // 'd' for each _d _e _Y 'e' <- _Y ; // 'e' for each _e - <- _Y ; // no more