a single rule with for loops
.onerule()
- var I = 0; <- postlude "extern (C) mode lmdInit(inout stream s){" indent nl table :"mt" :Mi {for(I = 0; I < Mi; I++) { defq :mt :I :(Mn[I]) eoc }} nl {for(I = 0; I < Ir; I++) { defr :ru :I :I eoc }} nl "return " pt "sm(s)" eoc "}" lmn nl2 lmn ;
internal format wrapped a as a shell script
#! /usr/bin/lm -r # Language Machine (C) 2005 Peri Hankey (mpah@users.sourceforge.net). Redistribution permitted subject to GNU GPLv2. # The Language Machine is free software as defined by the Gnu GPL and comes with ABSOLUTELY NO WARRANTY. m:onerule L:0 n:0 ( z v:I G n:0 G w . ) ( m:postlude m:extern%20(C)%20mode%20lmdInit(inout%20stream%20s)%7B m:indent m:nl m:table m:mt p v:Mi p ( v:I V n:0 G f:= . ( v:I V v:Mi V f:%3C f:test m:defq m:mt p v:I p v:Mn V v:I V f:idx b m:eoc v:I V f:postinc ) G f:loop ) m:nl ( v:I V n:0 G f:= . ( v:I V v:Ir V f:%3C f:test m:defr m:ru p v:I p v:I p m:eoc v:I V f:postinc ) G f:loop ) m:nl m:return%20 m:pt m:sm(s) m:eoc m:%7D m:lmn m:nl2 m:lmn ) r
internal format wrapped as a D program
import lm.lmd; import lm.licenseGnuGPLv2;
extern (C) mode lmdInit(inout stream s);
int main(char[][]args) { application a = new application(args, &lmdInit); int result = a.start(); return result; }
import lm.lmd; import lm.licenseGnuGPLv2;
static char[] rul0 = "m:onerule L:0 n:0 ( z v:I G n:0 G w . ) ( m:postlude m:extern%20(C)%20mode%20lmdInit(inout%20stream%20s)%7B m:indent m:nl m:table m:mt p v:Mi p ( v:I V n:0 G f:= . ( v:I V v:Mi V f:%3C f:test m:defq m:mt p v:I p v:Mn V v:I V f:idx b m:eoc v:I V f:postinc ) G f:loop ) m:nl ( v:I V n:0 G f:= . ( v:I V v:Ir V f:%3C f:test m:defr m:ru p v:I p v:I p m:eoc v:I V f:postinc ) G f:loop ) m:nl m:return%20 m:pt m:sm(s) m:eoc m:%7D m:lmn m:nl2 m:lmn ) r "; extern (C) mode lmdInit(inout stream s){ needft(s, 0); define(s, rul0); return null; }
compiled and wrapped as D code
Note: the tracing code is normally compiled as null procedures and so with inlining should vanish entirely. In the equivalent C code #defines are used to null out tracing code unless specifically required by a compile-time switch.
import lm.lmd; import lm.licenseGnuGPLv2;
extern (C) mode lmdInit(inout stream s);
int main(char[][]args) { application a = new application(args, &lmdInit); int result = a.start(); return result; }
import lm.lmd; import lm.licenseGnuGPLv2;
mode lhs0(inout stream s){ goto Lz; L0: zVtr(s, "lhs", 0, 3); return zV(s, 1, smt(s, 0)); // [mi:null] L1: newvar(s, svt(s, 0), gn(s, cast(lmNumber) 0)); L2: rTtr(s, "lhs", 0, 3); return rT(s, 3, null); Lz: switch(sci(s)){ case 0: goto L0; case 1: goto L1; case 2: goto L2; default: return zZ(s, 0, null); } }
mode rhs0(inout stream s){ goto Lz; L0: mVtr(s, "rhs", 0, 3); return mV(s, 1, smt(s, 1)); // [mi:postlude] L1: mVtr(s, "rhs", 0, 3); return mV(s, 2, sdt(s, 0)); // [di:extern (C) mode lmdInit(inout stream s){] L2: mVtr(s, "rhs", 0, 3); return mV(s, 3, smt(s, 2)); // [mi:indent] L3: mVtr(s, "rhs", 0, 3); return mV(s, 4, smt(s, 3)); // [mi:nl] L4: mVtr(s, "rhs", 0, 3); return mV(s, 5, smt(s, 4)); // [mi:table] L5: bVtr(s, "rhs", 0, 3); return bV(s, 6, sdt(s, 1)); L6: bVtr(s, "rhs", 0, 3); return bV(s, 7, svt(s, 1)); L7: assign(s, gv(s, svt(s, 2)), gn(s, cast(lmNumber) 0)); ra0:; if(!(tf(lt(s, gv(s, svt(s, 2)), gv(s, svt(s, 1)))))) goto rz0; L8: mVtr(s, "rhs", 0, 3); return mV(s, 9, smt(s, 5)); // [mi:defq] L9: bVtr(s, "rhs", 0, 3); return bV(s, 10, smt(s, 6)); L10: bVtr(s, "rhs", 0, 3); return bV(s, 11, svt(s, 2)); L11: bVtr(s, "rhs", 0, 3); return bV(s, 12, idx(s, gv(s, svt(s, 3)), gv(s, svt(s, 2)))); L12: mVtr(s, "rhs", 0, 3); return mV(s, 13, smt(s, 7)); // [mi:eoc] L13: postinc(s, gv(s, svt(s, 2))); goto ra0; rz0:; L14: mVtr(s, "rhs", 0, 3); return mV(s, 15, smt(s, 3)); // [mi:nl] L15: assign(s, gv(s, svt(s, 2)), gn(s, cast(lmNumber) 0)); ra1:; if(!(tf(lt(s, gv(s, svt(s, 2)), gv(s, svt(s, 4)))))) goto rz1; L16: mVtr(s, "rhs", 0, 3); return mV(s, 17, smt(s, 8)); // [mi:defr] L17: bVtr(s, "rhs", 0, 3); return bV(s, 18, smt(s, 9)); L18: bVtr(s, "rhs", 0, 3); return bV(s, 19, svt(s, 2)); L19: bVtr(s, "rhs", 0, 3); return bV(s, 20, svt(s, 2)); L20: mVtr(s, "rhs", 0, 3); return mV(s, 21, smt(s, 7)); // [mi:eoc] L21: postinc(s, gv(s, svt(s, 2))); goto ra1; rz1:; L22: mVtr(s, "rhs", 0, 3); return mV(s, 23, smt(s, 3)); // [mi:nl] L23: mVtr(s, "rhs", 0, 3); return mV(s, 24, sdt(s, 2)); // [di:return ] L24: mVtr(s, "rhs", 0, 3); return mV(s, 25, smt(s, 10)); // [mi:pt] L25: mVtr(s, "rhs", 0, 3); return mV(s, 26, sdt(s, 3)); // [di:sm(s)] L26: mVtr(s, "rhs", 0, 3); return mV(s, 27, smt(s, 7)); // [mi:eoc] L27: mVtr(s, "rhs", 0, 3); return mV(s, 28, sdt(s, 4)); // [di:}] L28: mVtr(s, "rhs", 0, 3); return mV(s, 29, smt(s, 11)); // [mi:lmn] L29: mVtr(s, "rhs", 0, 3); return mV(s, 30, smt(s, 12)); // [mi:nl2] L30: mVtr(s, "rhs", 0, 3); return mV(s, 31, smt(s, 11)); // [mi:lmn] L31: rTtr(s, "rhs", 0, 3); return rT(s, 32, null); Lz: switch(sci(s)){ case 0: goto L0; case 1: goto L1; case 2: goto L2; case 3: goto L3; case 4: goto L4; case 5: goto L5; case 6: goto L6; case 7: goto L7; case 8: goto L8; case 9: goto L9; case 10: goto L10; case 11: goto L11; case 12: goto L12; case 13: goto L13; case 14: goto L14; case 15: goto L15; case 16: goto L16; case 17: goto L17; case 18: goto L18; case 19: goto L19; case 20: goto L20; case 21: goto L21; case 22: goto L22; case 23: goto L23; case 24: goto L24; case 25: goto L25; case 26: goto L26; case 27: goto L27; case 28: goto L28; case 29: goto L29; case 30: goto L30; case 31: goto L31; default: return zZ(s, 0, null); } }
mode rul0(inout stream s){ def(s, gm(s, smt(s, 13)), L(0), 1, 0, 3, 32, smt(s, 14), smt(s, 1), &lhs0, &rhs0, "rules", 3); return ssm(s); }
extern (C) mode lmdInit(inout stream s){ needmt(s, 15); makemt(s, 0, "null"); makemt(s, 1, "postlude"); makemt(s, 2, "indent"); makemt(s, 3, "nl"); makemt(s, 4, "table"); makemt(s, 5, "defq"); makemt(s, 6, "mt"); makemt(s, 7, "eoc"); makemt(s, 8, "defr"); makemt(s, 9, "ru"); makemt(s, 10, "pt"); makemt(s, 11, "lmn"); makemt(s, 12, "nl2"); makemt(s, 13, "onerule"); makemt(s, 14, "null");
needdt(s, 5); makedt(s, 0, "extern (C) mode lmdInit(inout stream s){"); makedt(s, 1, "mt"); makedt(s, 2, "return "); makedt(s, 3, "sm(s)"); makedt(s, 4, "}");
needtt(s, 0);
needxt(s, 0);
needvt(s, 5); makevt(s, 0, "I"); makevt(s, 1, "Mi"); makevt(s, 2, "I"); makevt(s, 3, "Mn"); makevt(s, 4, "Ir");
neednt(s, 0);
needst(s, 0);
rul0(s);
return ssm(s); }