ambnambn.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^n*a^m*b^n, where a and b are terminal & ((m = 0 & n = 0) | n > 0 & m > 0) & (no variables permitted)}
Test harness - S may be empty, so require terminator
esc out <- eof - ; // H1 .[ \n] <- eof - ; // H2 - _E <- eof - esc "no\n" ; // H3 - _S ';' <- eof - esc "yes\n"; // H4
- {repeat .[^\n]} <- _E ; // E1
The null case, and a game of two halves
- <- _S ; // S01 - _P _Q <- _S ; // S02
Recognise 'a'^m*'b'^n (n > 0, m > 0), transform to _a^m*_b*n
'a' _A _B <- _P _a; // S03
- <- _A ; // S04 'a' _A _B <- _A _a; // S05
- <- _B ; // S06 'b' _B <- _B _b; // S07
Recognise one 'b' for each _b:
NB will only see actual input at end of recursion for _Y after matching all _b and all _a.
Effective input eg _a _a _b 'aab' is to be transformed and analysed as _b _a _a 'aab'.
So we need to go top down to look for _b
- _b _Y 'b' <- _Q ; // S08
- _b _Y 'b' <- _Y ; // S10 _a _Z 'a' <- _Y ; // S11
- <- _Z ; // S12 _a _Z 'a' <- _Z ; // S13
Treat _a _b as _b _a when looking for _b
_a _b <- _b _a ; // S14