2003 LMNtal : 2004 2 5 : : 1G00P102-2
LMNtal LMNtal (1) (2) (3) (OS) LMNtal LMNtal LMNtal
i 1 1 1.1 LMNtal....................... 1 1.2 LMNtal................ 1 1.2.1..................... 2 1.2.2.............. 2 1.3............................. 2 2 LMNtal 4 2.1 Atom............................ 4 2.2 -.................... 5 2.3.............................. 6 2.4 LMNtal............................ 7 2.5............................. 8 2.5.1..................... 8 2.5.2........................ 9 2.5.3................... 9 2.6.............................. 10 2.7......................... 10 2.8......................... 11 2.8.1..................... 11 2.8.2..................... 11 3 12 3.1.............................. 12 3.1.1......................... 12 3.1.2......................... 12 3.1.3.................. 13 3.2.............. 13 3.2.1 Java................ 13 3.2.2................... 13 3.2.3............. 14 3.2.4................... 15
ii 3.2.5........... 15 3.2.6 INLINE.................. 17 4 19 4.1.............................. 19 4.1.1......... 19 4.1.2................... 20 4.1.3........... 20 4.2...................... 20 4.2.1............. 20 4.2.2............. 22 4.2.3................... 24 4.2.4........... 31 5 32 5.1 Inline............................. 32 5.1.1........................ 32 5.1.2......................... 32 5.1.3......................... 33 5.2 module............................ 34 5.2.1........................ 34 5.2.2......................... 35 5.2.3......................... 35 6 37 6.1 - I/O....................... 37 6.1.1 I/O.................... 37 6.2 - map....................... 38 6.2.1 map.................... 38 6.3 - semaphore................... 39 6.3.1 semaphore................ 39 6.4 -................... 40 6.4.1 amidakuji.lmn -....... 40 6.4.2.......... 40 6.5.................... 41 6.5.1.................... 41 6.5.2................... 41 6.5.3......... 42 6.5.4.......... 42
iii 43 44 Appendix.A 45 A.1 Inline.java............................... 45 A.2 Module.java.............................. 48 A.3.java.................................. 53 Appendix.B 54 B.1 I/O (io.lmn)....................... 54
iv 2.1............... 4 2.2 Append :........... 5 2.3............ 7 2.4.............. 8 3.1........... 14 3.2............ 16 4.1......................... 23 4.2..................... 27 4.3..................... 28 4.4..................... 29 6.1.............. 43
v 2.1 LMNtal.............................. 7 2.2...................... 9 3.1 INLINE........................ 18 4.1 LOADMODULE................... 24
1 1 1.1 LMNtal LMNtal[1], [2] LMNtal Atom LMNtal LMNtal LMNtal CHR gamma LMNtal LMNtal LMNtal 1.2 LMNtal LMNtal
1.3. 2 1.2.1 1.2.2 LMNtal LMNtal 1.3 2 LMNtal 3 4 5
1.3. 3 6 Appendix Module Inlin 7
4 2 LMNtal LMNtal(Linked Multisets of Nodes transformation language) LMNtal [1][2] TODO cite 2.1 Atom Atom LMNtal Atom 0 Atom 1 1 X a Atom a(x) Atom a(x,y) a(y,x) Atom h(neck). a(neck, Hand1, Body, Hand2). h(hand1). h(hand2). b(body, Foot1, Foot2). f(foot1). f(foot2). h h Hand2 h Neck a Body Hand1 b Foot1 Foot2 f f 2.1: LMNtal 2.4 Atom Atom Atom KL1 CHR
2.2. - 5 X 2.2 - start1 start2 start3 start1 start2 start3 start1 start2 start3 you c c c c c c you c c c c c c c c c c c c you goal1 goal2 goal3 goal1 goal2 goal3 goal1 goal2 goal3 << Rule >> you c c :- c c you 2.2: Append : you LMNtal 2.2
2.3. 6 start1(you). start2(r20). start3(r30). you(you, R10). c(r10, C1, R11). c(r11, C3, R12). c(r20, C1, R21). c(r21, C2, R22). c(r22, C3, R23). c(r30, C2, R31). goal1(r12). goal2(r23). goal3(r31). you(t1,m1), c(m1,c,d1), c(t2,c,d2) :- c(t1,c,d1), c(t2,c,m2), you(m2,d2). 2 1 1 Atom c c you you c 2 a(x), b(x) a(y), b(y) 2.3 Atom { compound Cell 1 Python 2 LMNtal you
2.4. LMNtal 7 { { {a(x), b(x,y), ({a(x) :- {d(x)), c(y) a b c : Cell : Atom a :- d : Rule 2.3: (stable) Atom a b c a,b,c LMNtal 2.4 LMNtal LMNtal P P ::= 0 (null) p( X) (atom) P,P (composition) {P (cell) {P/ (stable cell) (T :- T) (reaction rule) T T ::= 0 (null) p( X) (atom) T,T (composition) {T (cell) {T/ (stable cell) T:-T (rule) @p (rule variable) $p[ X A] (process variable) p(* X) (aggregate) A ::= [ ] (null) *X (bundle) 2.1: LMNtal X X X
2.5. 8 X p p Atom Atom p P P P P P {P P P 2.4: 2.5 2.5.1 Atom Node1 : { kake. ue. { { kashi. { kake. $p. $p ue. { { kashi. kake Node1 { ue { ue Node1 ue
2.5. 9 2.5.2 $p[x 1,...X m A] [X 1,...X m A] $p $p Atom 3 $p[x 1,...X m A] X 1,...X m $p X 1,...X m m A X 1,...X m [ ] 0 *X 0 A [ ] $p[x,y] $p X,Y $p[x *Y] $p X $p[ [ ] ] $p $p[ ] $p[ *X] $p $p 2.2: 2.5.3 1 3 {a(x), {b(x) {$p(x),{b(x) $p b(x) X a(x) X $p
2.6. 10 2.6 1 { order_area, @rule, { lawless_area :- { order_area, @rule, { lawless_area, @rule order lawless area 4 2.7 1 5 6 number(n) :- 7 < N greater_than_seven(n). { number(n) :- greater_than_seven(n) n(n Z n > 7) number( 8) :- greater_than_seven( 8). number( 9) :- greater_than_seven( 9). 4 lawless area :) 5 6
2.8. 11 number(10) :- greater_than_seven(10). number(11) :- greater_than_seven(11). number(12) :- greater_than_seven(12). : : number(5). number(19). number(5). greater_than_seven(19). 2.8 LMNtal Java 2.8.1 LMNtal LMNtal 2.8.2 1 LMNtal
12 3 LMNtal 5 3.1 3.1.1 OS LMNtal LMNtal 3.1.2 OS LMNtal LMNtal LMNtal
3.2. 13 3.1.3 LMNtal 3.2 4 LMNtal 3.2.1 Java Java Java Java 3.2.2 LMNtal
3.2. 14 LMNtal LMNtal LMNtal LMNtal 3.2.3 /*inline*/ System.out.println("test") print_test 3.1:
3.2. 15 3.2.4 2 /*inline*/ (NEWATOM, LINK ) Java runtime.atom me 2 /*inline_define*/ Java Java 3.2.5 Java
3.2. 16 /*inline*/ String s=do_input(); me.nthatom(0).changename(s); me.changename("done"); null (You inputted "ABC") done ABC 3.2: MyInlineCode.java runtime.inlinecode run(atom a, int codeid) interface runtime.inlinecode package runtime; public interface InlineCode { public void run(atom a, int codeid); codeid MyInlineCode.java
3.2. 17 import runtime.*; /*** ***/ public class MyInlineCode implements InlineCode { public void run(atom me, int codeid) { switch(codeid) { case 0: { /*** ID = 0 ***/ break; case 1: { /*** ID = 1 ***/ break; : : case N: { /*** ID = N ***/ break; 3.2.6 INLINE
3.2. 18 INLINE ID 3.1: INLINE LMNtal ( a :- [[/*inline*/system.out.println(123);]] ), a spec [2, 0] findatom [1, 0, a_0] react [( a :- /*inline*/... ), [0], [1]] spec [2, 3] dequeueatom [1] removeatom [1, 0, a_0] newatom [2, 0, /*inline*/...] enqueueatom [2] inline [2, 0] freeatom [1] proceed [] import runtime.*; public class MyInlineCode implements InlineCode { public void run(atom me, int codeid) { switch(codeid) { case 0: { /*inline*/system.out.println(123); break;
19 4 LMNtal 5 4.1 4.1.1 LMNtal
4.2. 20 4.1.2 Java static 4.1.3 2 2 4.2 4.2.1 LMNtal LMNtal
4.2. 21 LMNtal { C Java 2 1 name/1 1 name/1 name/1 1 name/1 1 % io { name(io), ( fprint(stream, String) :-??? ) 2 ::= [ : ] {
4.2. 22 1 2 2 1 % io io : { ( fprint(stream, String) :-??? ) 1 2 foo 2 % foo : { some_atom, foo : { another_atom java 4.2.2 4.1
4.2. 23 << Module m >> m.a m.a :- m.b (rule N) (Copy m s rule to user membrane) << Module m >> m.a :- m.b (rule N) m.a m.a :- m.b (rule N) (Apply m.a :- m.b) << Module m >> m.a :- m.b (rule N) m.b m.a :- m.b (rule N) 4.1:
4.2. 24 1. LOADMODULE LOADMODULE 4.1: LOADMODULE 4.2.3 4
4.2. 25 {{mv($m),$p,@q,$r,@s :- unary($m) {$r,@s,{mv($m),$p,@q. mv 1 {mv($m1),$p,@q,{name($m2),$r,@s :- $m1=$m2 {name($m2),$p,@q,$r,@s. 1 mv LMNtal 1 name(module_name) name {find_and_link($m1,x),ready($m2), $p, @q :- $m1=$m2 {msg(x,$m2), $p, @q. mv call($m,$method,x) :- unary($m),unary($method) {mv($m).find_and_link($method,x).. 4 module : { name(module). static.load. module.static_method(ready). module.static_method(msg(x)) :- some process..., module.static_method(ready). call(module, module.static_method, result)
4.2. 26 4.2 4.3 4.4 call(m, m.incr, X) m io.print(x) {{{ io.print(call(m, m.incr)). m:{ name(m). id(0). m.incr(ready). m.incr(msg(x)), id($o) :- int($o),$n=$o+1 cp($n, C1, C2), id(c1), X=C2, m.incr(ready).. {{{ io.print(x). {mv(m). find_and_link(m.incr,x).. m:{... 1 {{{ io.print(x). {mv(m). find_and_link(m.incr,x).. m:{... 1 {{{ io.print(x). {mv(m). find_and_link(m.incr,x).. m:{... 1 {{{ io.print(x).. {mv(m). find_and_link(m.incr,x).. m:{...
4.2. 27 << Module m >> m.incr ready id 0 io.print call m.incr,..., :- cp($n,... m m.incr Generate agent << Module m >> id 0 io.print m.incr ready m.incr,..., :- cp($n,... find_and_link m.incr mv m Agnet go up << Module m >> id 0 io.print m.incr ready m.incr,..., :- cp($n,... find_and_link m.incr mv m 4.2:
4.2. 28 Agnet go up << Module m >> id 0 io.print m.incr ready find_and_link m.incr,..., :- cp($n,... m.incr mv m Agnet go up << Module m >> id 0 io.print m.incr ready find_and_link m.incr,..., :- cp($n,... m.incr mv m Agnet go down << Module m >> find_and_link m.incr m.incr ready id 0 io.print m.incr,..., :- cp($n,... 4.3:
4.2. 29 Find and link << Module m >> msg m.incr id 0 io.print m.incr,..., :- cp($n,... Apply m s rule << Module m >> 1 cp m.incr ready id io.print m.incr,..., :- cp($n,... Finish << Module m >> 1 m.incr 1 id io.print ready m.incr,..., :- cp($n,... 4.4:
4.2. 30 {{{ io.print(x).. m:{ name(m). find_and_link(m.incr, X). id(0). m.incr(ready). m.incr(msg(x)), id($o) :- int($o),$n=$o+1 cp($n, C1, C2), id(c1), X=C2, m.incr(ready).. find_and_link {{{ io.print(x).. m:{ name(m). id(0). m.incr(msg(x)). m.incr(msg(x)), id($o) :- int($o),$n=$o+1 cp($n, C1, C2), id(c1), X=C2, m.incr(ready).. {{{ io.print(x).. m:{ name(m). cp(1, C1, C2). id(c1). X=C2. m.incr(ready). m.incr(msg(x)), id($o) :- int($o),$n=$o+1 cp($n, C1, C2), id(c1), X=C2, m.incr(ready).. {{{ io.print(x).. m:{ name(m). id(1). 1(X). m.incr(ready). m.incr(msg(x)), id($o) :- int($o),$n=$o+1 cp($n, C1, C2), id(c1), X=C2, m.incr(ready).. io.print 1 id(0) id(1) call(m, m.incr, X) 2(X), id(2)
4.2. 31 4.2.4 system_ruleset
32 5 5.1 Inline 5.1.1 public static InlineCode inlinecode Process cp public static Map code static List defs Map List static int codecount 5.1.2 public static void initinline() MyInline.class public static int getcodeid(string codestr) ID
5.1. Inline 33 public static void add(string funcname) public static void makecode() MyInline.java public static void callinline(atom atom, int codeid) ID 5.1.3 Inline.add /*inline*/ Map code ID /*inline_define*/ List defs runtime.inline.makecode() Java compile.rulecompiler.addinline INLINE
5.2. module 34 compile.rulecompiler.addinline /** */ private void addinline() { Iterator it = rhsatoms.iterator(); while(it.hasnext()) { Atom atom = (Atom)it.next(); int atomid = rhsatomtopath(atom); int codeid = Inline.getCodeID(atom.functor.getName()); if(codeid == -1) continue; body.add( new Instruction (Instruction.INLINE, atomid, codeid)); INLINE MyInlineCode.run INLINE case Instruction.INLINE : //[atom, inlineref] Inline.callInline ( atoms[inst.getintarg1()], inst.getintarg2() ); break; 5.2 module 5.2.1 public static String libpath "../lmntal_lib/" public static Map memnametable
5.2. module 35 5.2.2 public static void regmemname(string name, Membrane m) public static void loadmodule(membrane m, String modname) public static void resolvemodules(membrane m) C Linker static void getneedmodules(membrane m, List need) need 5.2.3 regmemname Module.resolveModules LMNtal
5.2. module 36 LOADMODULE LOADMODULE case Instruction.LOADMODULE: //[dstmem, module_name] // compile.structure.membrane m = (compile.structure.membrane) compile.module.memnametable.get(inst.getarg2()); if(m==null) { Env.e("Undefined module "+inst.getarg2()); else { Iterator i = m.rulesets.iterator(); while (i.hasnext()) { mems[inst.getintarg1()].loadruleset ((Ruleset)i.next() ); break;
37 6 6.1 - I/O 6.1.1 I/O io:{ io.print(string) :- unary(string) [[/*inline*/ System.out.println(me.nth(0)); ]](String). io.input(message) :- [[/*inline*/ String s = javax.swing.joptionpane.showinputdialog(null, me.nth(0)); me.changename(s); me.nthatom(0).changename("done"); ]](Message). io.input(message, X) :- [[/*inline*/ String s = javax.swing.joptionpane.showinputdialog(null, me.nth(0)); me.changename("done"); me.nthatom(0).changename(s); ]](Message, X). io.input :- [[/*inline*/ String s = javax.swing.joptionpane.showinputdialog(null, "Input text."); me.changename(s); ]]. Java io.print io.input 1 done
6.2. - map 38 2 done LMNtal 6.2 - map 6.2.1 map // unary map map : { map.new($self) :- unary($self) {name($self). // override exist key map.put($self, $k, $v), {name($name), assoc($ok, $ov), $p :- unary($k),unary($v),$name=$self,$ok=$k,unary($ov) {name($name), assoc($k, $v), $p. // add new key map.put($self, $k, $v), {name($name), $p :- unary($k),unary($v),$name=$self {name($name), assoc($k, $v), $p. map.get($self, $k, V), {name($name), assoc($mk, $mv), $p :- unary($k),$name=$self,$k=$mk,unary($mv) V=$mv, {name($name), assoc($mk, $mv), $p.. key value (map.put) key value (map.get) map.new map map.get map.put map map.get 1
6.3. - semaphore 39 LMNtal (bless ) 1 Perl5 OOP Perl5 OOP Java C++ OOP 6.3 - semaphore 6.3.1 semaphore // Semaphore sem : { name(sem). static.load. // public static method interface defs. sem.new(ready). sem.up(ready). sem.new(msg($self)) :- unary($self) {sem($self), state(notbusy), sem.new(ready). // up -> state(busy) if state(notbusy) sem.up(msg($self)), {sem($name), state(notbusy) :- $self==$name {sem($name), state(busy), allowed($self), sem.up(ready). // down -> state(notbusy) sem.down(msg($self)), {sem($name), state(busy) :- $self==$name {sem($name), state(notbusy), sem.down(ready)..
6.4. - 40 6.4-6.4.1 amidakuji.lmn - /* SYNOPSIS amidakuji.start_at(start2). ==> amidakuji.done(goal??). */ amidakuji : { amidakuji.start_at($y),c($s,c,d) :- $s=$y you($s,u),c(u,c,d). you(t1,m1), c(m1,c,d1), c(t2,c,d2) :- c(t1,c,d1), c(t2,c,m2), you(m2,d2).. c(u,c,m), you(m,$goal) :- unary($goal) c(u,c,$goal), amidakuji.done($goal). 2.2 amidakuji.start_at( ) you you you amidakuji.done( ) 6.4.2 // Amida data start1(r10). start2(r20). start3(r30). c(r10, C1, R11). c(r20, C1, R21). c(r21, C2, R22). c(r30, C2, R31). c(r11, C3, R12). c(r22, C3, R23). goal1(r12). goal2(r23). goal3(r31).
6.5. 41 // Main program io.input([[this is amidakuji. Where to start today? Input start1, start2 or start3.]], input_str). input_str(done(you)) :- amidakuji.start_at(you). amidakuji.done($goal) :- unary($goal) io.print([[you got to ]]), io.print($goal). start1 3 amidakuji.start_at you 6.5 6.5.1 module : {... { name(module) 6.5.2 system_ruleset name(module) module:{ property:{ atom.... module.property.atom
6.5.3. Objective Caml LMNtal 6.5.4
43 6.1: 2004 2
44 [1], : Programming with Logical Links, 19, 2002. [2] Kazunori Ueda and Norio Kato : Programming with Logical Links, Design of the LMNtal language, In Proc. 3rd Asian Workshop on Programming Languages and Systems (APLAS 2002), pp.115-126, 2002. [3] : Inside KLIC Version 1.0, KLIC Task Group/AITEC/JIPDEC, 1998. http://www.klic.org/software/klic/inside/master.html [4] : DKLIC,,, 2002.
45 Appendix.A A.1 Inline.java package runtime; import java.io.*; import java.util.*; /** * <BR> * * <UL> * <LI>"/ inline /" * * <LI>"/ inline_define /" * * <LI> * * <LI> * * * <LI> INLINE * * <LI> NEWATOM, LINK * INLINE * * <LI> * </UL> * <PRE> * NEWATOM [1, 0, abc_0] *... * INLINE [1, 0] * </PRE> * * @author hara */ public class Inline { /** */ public static InlineCode inlinecode; /** */
A.1. Inline.java 46 static Process cp; /** Hash { -> */ public static Map code = new HashMap(); /** List */ public static List defs = new ArrayList(); /** */ static int codecount = 0; /** * * */ public static void initinline() { try { if(cp!=null) { // // BufferedReader br = new BufferedReader(new InputStreamReader(cp.getErrorStream() String el; while( (el=br.readline())!=null ) { System.err.println(el); cp.waitfor(); Env.d("Compile result : "+cp.exitvalue()); cp = null; // jar ClassLoader cl = new FileClassLoader(); Object o = cl.loadclass("myinlinecode").newinstance(); if (o instanceof InlineCode) { inlinecode = (InlineCode)o; //inlinecode = (InlineCode)Class.forName("MyInlineCode").newInstance(); //Env.d(Class.forName("MyInlineCode").getField("version")); catch (Exception e) { //Env.e("!! catch!! "+e.getmessage()+"\n"+env.parray(arrays.aslist(e.getstacktrace( if (inlinecode!= null) { Env.d("MyInlineCode Loaded"); else if (inlinecode == null) { Env.d("Failed in loading MyInlineCode"); /** * ID * @param name * @return codeid */ public static int getcodeid(string name) { try {
A.1. Inline.java 47 return ((Integer)code.get(name)).intValue(); catch (Exception e) { return -1; /** * * * @param atom */ public static void add(string src) { if(src.startswith("/*inline*/")) { //if(src.startswith("a")) { // Env.d("Register inlinecode : "+src); code.put(src, new Integer(codeCount++)); else if(src.startswith("/*inline_define*/")) { // Env.d("Register inlinedefinecode : "+src); defs.add(src); /** * * TODO java oneliner REPL "-" * TODO */ public static void makecode() { try { if(code.isempty() && defs.isempty()) return; Iterator i; PrintWriter p = new PrintWriter(new FileOutputStream("MyInlineCode.java")); Env.d("make inline code "+code); //p.println("package runtime;"); p.println("import runtime.*;"); i = defs.iterator(); while(i.hasnext()) { String s = (String)i.next(); p.println(s); p.println("public class MyInlineCode implements InlineCode {"); p.println("\tpublic static String version=\"static string.\";"); p.println("\tpublic void run(atom me, int codeid) {"); //p.println("\t\tenv.p(\"-------------------------- \");"); //p.println("\t\tenv.d(\"exec Inline \"+me+codeid);"); p.println("\t\tswitch(codeid) {"); i = code.keyset().iterator(); while(i.hasnext()) {
A.2. Module.java 48 String s = (String)i.next(); int codeid = ((Integer)(code.get(s))).intValue(); p.println("\t\tcase "+codeid+": "); //p.println("\t\t\t/*"+s.replaceall("\\*\\/", "* /").replaceall("\\/\\*", "/ *") p.println("\t\t\t"+s); p.println("\t\t\tbreak;"); p.println("\t\t"); p.println("\t"); p.println(""); p.close(); // cp = Runtime.getRuntime().exec("javac -classpath.;lmntal.jar MyInlineCode.java"); catch (Exception e) { Env.d("!!! "+e.getmessage()+arrays.aslist(e.getstacktrace())); /** * * @param atom */ public static void callinline(atom atom, int codeid) { //Env.d(atom+" "+codeid); if(inlinecode==null) return; //Env.d("=> call Inline "+atom.getname()); inlinecode.run(atom, codeid); A.2 Module.java package compile; import java.io.bufferedreader; import java.io.fileinputstream; import java.io.inputstreamreader; import java.util.*; //import runtime.functor; import runtime.env; import compile.parser.lmnparser; import compile.structure.*; /** * <br><br> * *
A.2. Module.java 49 * <li> * <li> module_name : {... * <li> * <li> * <li> LOADMODULE * * <ul> * <li> module_name : {... * <li> [1] module_name.name * <li> [2] use(module_name), name<br> * <br> * * <li> * * </ul><br> * * * * <ul> * <li> [.] * <dl> * <dt>string Functor.path</dt> * <dd> * * * (n-kato)</dd> * <dt>boolean Functor.pathFree</dt> * <dd> </dd> * ModuleName$AtomName (n-kato) * </dl> * <li>. LOADMODULE *.lmn * <li> FINDATOM AtomSet * func * <ul> * <li>!func.pathfree name, arity, path * <li> func.pathfree name, arity * </ul> * (n-kato) * </ul> * * * * m.p
A.2. Module.java 50 * * runtime.functor p * runtime.atom * * [1] m.p m.p m.p m,p * findatom dstatom,srcmem,p * path dstatom,m * [2] p p (*A) * findatom dstatom,srcmem,p * [3] m.p m.p * newatom dstmem,p,m * [4] p m.p * newatom dstmem,p,m * [5] m.p m.p * [6] p m.p * * m.p * * m.p m,p * * [1] m.p m.p m.p * findatom dstatom,srcmem, m,p * [2] p p * findatom dstatom,srcmem,p * [3] m.p m.p * newatom dstmem,mem, m,p * [4] p p * newatom dstmem,mem,p * [5] m.p m.p * [6] p p * * m.p p (*A) * * * * m.p * * * * * * inline * >>>1
A.2. Module.java 51 ({{up,$p,@q,$s,@t:-{$s,@t,{up,$p,@q) #, {{up,1,2,3 down {down ({down,$p,@q,{$r,@s:-! ($r match {down, $t) {down,$p,@q, {{down,$p,@q,$r,@s) #, {down,1,{2,3,{4,5 >>>2 ( { find_and_link($name1, X), $Name2, decl :- $Name1 eq $Name2 $name2(x), decl ) ## { find_and_link(m, X), m, decl :- m(x), decl for all {m String(m) ## decl >>>3 ( $a(x) :- static($a) { up, down, find_and_link($a, X) ) 1, 2, 3 {{{ io.print(m.incr), m:{ decl, m.incr, id(0), ( m.incr(x), id(n) :- cp(s(n), Cp1, Cp2), id( -> {{{ io.print(x), { up, down, find_and_link(m.incr, X), m.incr(x), m:{... -> {{{ io.print(x), { up, down, find_and_link(m.incr, X), m:{... -> {{{ io.print(x), { up, down, find_and_link(m.incr, X), m:{... -> {{{ io.print(x), { up, down, find_and_link(m.incr, X), m:{... -> {{{ io.print(x), m:{ decl, m.incr, id, { up, down, find_and_link(m.incr, X), (... :-.. -> {{{ io.print(x), m:{ decl, id, m.incr(x), (... :-...) -> {{{ io.print(x), m:{ decl, id(1), 1(X), m.incr, (... :-...) * @author hara * */ public class Module { public static String libpath = "../lmntal_lib/"; public static Map memnametable = new HashMap(); /** * * @param m */ public static void regmemname(string name, Membrane m) { memnametable.put(name, m); /** * * @param m * @param mod_name */ public static void loadmodule(membrane m, String mod_name) {
A.2. Module.java 52 String filename = libpath+mod_name+".lmn"; StringBuffer sb = new StringBuffer("Loading Module "+mod_name+"..."); try { LMNParser lp = new LMNParser(new BufferedReader(new InputStreamReader(new FileInputS Membrane nm = RulesetCompiler.runStartWithNull(lp.parse()); // Env.p("MOD compiled "+nm); //memnametable GC //m.add(nm); sb.append(" [ OK ] "); catch (Exception e) { Env.e("!! catch!! "+e.getmessage()+"\n"+env.parray(arrays.aslist(e.getstacktrace()) sb.append(" [ FAILED ] "); Env.d(sb.toString()); /** * * @param m */ public static void resolvemodules(membrane m) { List need = new ArrayList(); getneedmodules(m, need); Iterator i = need.iterator(); while(i.hasnext()) { loadmodule(m, (String)i.next()); /** * * @param m * @param need */ static void getneedmodules(membrane m, List need) { Iterator i; i = m.atoms.listiterator(); while(i.hasnext()) { Atom a = (Atom)i.next(); String path = a.getpath(); if(path == null) continue; if(path.equals(m.name)) continue; // Env.p("Check module existence "+path); if(!memnametable.containskey(path)) { // Env.p("TODO: search lib file : " + path); need.add(path); i = m.rules.listiterator(); while(i.hasnext()) { RuleStructure rs = (RuleStructure)i.next(); getneedmodules(rs.leftmem, need); getneedmodules(rs.rightmem, need);
A.3..java 53 i = m.mems.listiterator(); while(i.hasnext()) { getneedmodules((membrane)i.next(), need); A.3.java
54 Appendix.B B.1 I/O (io.lmn) io:{ ( io.print(string) :- [[/*inline*/ System.out.println(me.nth(0)); ]](String) )