diff --git a/AlgebraicDataflowArchitectureModel/models/Accounts.model b/AlgebraicDataflowArchitectureModel/models/Accounts.model index e1d32b1..dba68ba 100644 --- a/AlgebraicDataflowArchitectureModel/models/Accounts.model +++ b/AlgebraicDataflowArchitectureModel/models/Accounts.model @@ -1,7 +1,7 @@ channel CIO1 { - out accounts(l:Map, signup(id:Int, name:Str)) == append(l, {"name": name}) + out accounts(l:Map, signup(id:Int, name:Str)) = append(l, {"name": name}) } channel CIO2(uid:Int) { - out accounts.{uid}.name(n:Str, changeName(name)) == name + out accounts.{uid}.name(n:Str, changeName(name)) = name } diff --git a/AlgebraicDataflowArchitectureModel/models/Algo.model b/AlgebraicDataflowArchitectureModel/models/Algo.model index 6228431..328f11a 100644 --- a/AlgebraicDataflowArchitectureModel/models/Algo.model +++ b/AlgebraicDataflowArchitectureModel/models/Algo.model @@ -1,12 +1,12 @@ channel turnA{ ref handsB(b:List, drawA(target:Int, guess:Int, b, d)) ref deck(d:List, drawA(target, guess, b, d)) - out handsA(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), cons(tuple(fst(head(d)), false), a), cons(tuple(fst(head(d)), true), a)) - out handsB(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) - out deck(t:List, drawA(target, guess, b, d)) == tail(d) + out handsA(a:List, drawA(target, guess, b, d)) = if(eq(get(b, target), guess), cons(tuple(fst(head(d)), false), a), cons(tuple(fst(head(d)), true), a)) + out handsB(a:List, drawA(target, guess, b, d)) = if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) + out deck(t:List, drawA(target, guess, b, d)) = tail(d) } channel turnAA{ ref handsB(b:List, selectA(target:Int, guess:Int, attacker:Int, b)) - out handsA(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), a, set(a, attacker, tuple(fst(get(a, attacker)), true))) - out handsB(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) + out handsA(a:List, selectA(target, guess, attacker, b)) = if(get(b, target) == guess, a, set(a, attacker, tuple(fst(get(a, attacker)), true))) + out handsB(a:List, selectA(target, guess, attacker, b)) = if(get(b, target) == guess, set(a, target, tuple(fst(get(a, target)), true)), a) } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Algolike.model b/AlgebraicDataflowArchitectureModel/models/Algolike.model index 97aef04..8ea8dc2 100644 --- a/AlgebraicDataflowArchitectureModel/models/Algolike.model +++ b/AlgebraicDataflowArchitectureModel/models/Algolike.model @@ -6,25 +6,25 @@ guessB := 0 } channel targetAInput{ - out targetA(t:Int, setTargetA(a:Int)) == a + out targetA(t:Int, setTargetA(a:Int)) = a } channel targetBInput{ - out targetB(t:Int, setTargetB(b:Int)) == b + out targetB(t:Int, setTargetB(b:Int)) = b } channel attackerAInput{ - out attackerA(t:Int, setAttackerA(a:Int)) == a + out attackerA(t:Int, setAttackerA(a:Int)) = a } channel attackerBInput{ - out attackerB(t:Int, setAttackerB(b:Int)) == b + out attackerB(t:Int, setAttackerB(b:Int)) = b } channel guessAInput{ - out guessA(t:Int, setGuessA(a:Int)) == a + out guessA(t:Int, setGuessA(a:Int)) = a } channel guessBInput{ - out guessB(t:Int, setGuessB(b:Int)) == b + out guessB(t:Int, setGuessB(b:Int)) = b } channel addDeck{ - out deck(d:List, addCard(num:Integer)) == cons(tuple(num, false), d) + out deck(d:List, addCard(num:Integer)) = cons(tuple(num, false), d) } channel drawAInput{ @@ -32,21 +32,21 @@ ref targetA(t:Int, drawAndAttackA(t, g, b)) ref guessA(g:Int, drawAndAttackA(t, g, b)) ref handsB(b:List, drawAndAttackA(t, g, b)) - out resultByDrawingA(sda:Tuple, drawAndAttackA(t, g, b)) == tuple(eq(fst(get(b, t)), g), t) + out resultByDrawingA(sda:Tuple, drawAndAttackA(t, g, b)) = tuple(fst(get(b, t)) == g, t) } channel inputDrawArgsA{ - in resultByDrawingA(sda:Tuple, drawA(sucTrg, d)) == sucTrg + in resultByDrawingA(sda:Tuple, drawA(sucTrg, d)) = sucTrg ref deck(d:List, drawA(sucTrg, d)) - out handsA(outA:List, drawA(sucTrg, d)) == if(fst(sucTrg), - sortByKey(cons(tuple(fst(head(d)),false), outA)), + out handsA(outA:List, drawA(sucTrg, d)) = if(fst(sucTrg), + sortByKey(cons(tuple(fst(head(d)), false), outA)), sortByKey(cons(tuple(fst(head(d)), true), outA))) - out handsB(outB:List, drawA(sucTrg, d)) == if(fst(sucTrg), + out handsB(outB:List, drawA(sucTrg, d)) = if(fst(sucTrg), set(outB, snd(sucTrg), tuple(fst(get(outB, snd(sucTrg))), true)), outB) - out deck(t:List, drawA(sucTrg, d)) == tail(t) + out deck(t:List, drawA(sucTrg, d)) = tail(t) } channel selectAInput{ @@ -54,14 +54,14 @@ ref targetA(t:Int, selectAndAttackA(a, t, g, b)) ref guessA(g:Int, selectAndAttackA(a, t, g, b)) ref handsB(b:List, selectAndAttackA(a, t, g, b)) - out resultBySelectingA(ssa:Tuple, selectAndAttackA(a, t, g, b)) == tuple(eq(fst(get(b, t)), g), t, a) + out resultBySelectingA(ssa:Tuple, selectAndAttackA(a, t, g, b)) = tuple(fst(get(b, t)) == g, t, a) } channel inputSelectArgA{ - in resultBySelectingA(ssa, selectA(sucTrgAtk)) == sucTrgAtk - out handsA(outA, selectA(sucTrgAtk)) == if(fst(sucTrgAtk), + in resultBySelectingA(ssa, selectA(sucTrgAtk)) = sucTrgAtk + out handsA(outA, selectA(sucTrgAtk)) = if(fst(sucTrgAtk), outA, set(outA, snd(snd(sucTrgAtk)), tuple(fst(get(outA, snd(snd(sucTrgAtk)))), true))) - out handsB(outB, selectA(sucTrgAtk)) == if(fst(sucTrgAtk), + out handsB(outB, selectA(sucTrgAtk)) = if(fst(sucTrgAtk), set(outB, fst(snd(sucTrgAtk)), tuple(fst(get(outB, fst(snd(sucTrgAtk)))), true)), outB) } @@ -69,21 +69,21 @@ ref targetB(t:Int, drawAndAttackB(t, g, a)) ref guessB(g:Int, drawAndAttackB(t, g, a)) ref handsA(a:List, drawAndAttackB(t, g, a)) - out resultByDrawingB(sdb:Tuple, drawAndAttackB(t, g, a)) == tuple(eq(fst(get(a, t)), g), t) + out resultByDrawingB(sdb:Tuple, drawAndAttackB(t, g, a)) = tuple(fst(get(a, t)) == g, t) } channel inputDrawArgsB{ - in resultByDrawingB(sdb:Tuple, drawB(sucTrg, d)) == sucTrg + in resultByDrawingB(sdb:Tuple, drawB(sucTrg, d)) = sucTrg ref deck(d:List, drawB(sucTrg, d)) - out handsB(outB:List, drawB(sucTrg, d)) == if(fst(sucTrg), + out handsB(outB:List, drawB(sucTrg, d)) = if(fst(sucTrg), sortByKey(cons(tuple(fst(head(d)),false), outB)), sortByKey(cons(tuple(fst(head(d)), true), outB))) - out handsA(outA:List, drawB(sucTrg, d)) == if(fst(sucTrg), + out handsA(outA:List, drawB(sucTrg, d)) = if(fst(sucTrg), set(outA, snd(sucTrg), tuple(fst(get(outA, snd(sucTrg))), true)), outA) - out deck(t:List, drawB(sucTrg, d)) == tail(t) + out deck(t:List, drawB(sucTrg, d)) = tail(t) } channel selectBInput{ @@ -91,23 +91,23 @@ ref targetB(t:Int, selectAndAttackB(atk, t, g, a)) ref guessB(g:Int, selectAndAttackB(atk, t, g, a)) ref handsA(a:List, selectAndAttackB(atk, t, g, a)) - out resultBySelectingB(ssb:Tuple, selectAndAttackB(atk, t, g, a)) == tuple(eq(fst(get(a, t)), g), t, atk) + out resultBySelectingB(ssb:Tuple, selectAndAttackB(atk, t, g, a)) = tuple(fst(get(a, t)) == g, t, atk) } channel inputSelectArgB{ - in resultBySelectingB(ssb, selectB(sucTrgAtk)) == sucTrgAtk - out handsB(outB, selectB(sucTrgAtk)) == if(fst(sucTrgAtk), + in resultBySelectingB(ssb, selectB(sucTrgAtk)) = sucTrgAtk + out handsB(outB, selectB(sucTrgAtk)) = if(fst(sucTrgAtk), outB, set(outB, snd(snd(sucTrgAtk)), tuple(fst(get(outB, snd(snd(sucTrgAtk)))), true))) - out handsA(outA, selectB(sucTrgAtk)) == if(fst(sucTrgAtk), + out handsA(outA, selectB(sucTrgAtk)) = if(fst(sucTrgAtk), set(outA, fst(snd(sucTrgAtk)), tuple(fst(get(outA, fst(snd(sucTrgAtk)))), true)), outA) } channel judgeA{ - in handsA(a:List, judge(j)) == j - out loseA(la:Bool, judge(j)) == eq(length(extractFaceDown(j)), 0) + in handsA(a:List, judge(j)) = j + out loseA(la:Bool, judge(j)) = length(extractFaceDown(j)) == 0 } channel judgeB{ - in handsB(b:List, judge(j)) == j - out loseB(lb:Bool, judge(j)) == eq(length(extractFaceDown(j)), 0) + in handsB(b:List, judge(j)) = j + out loseB(lb:Bool, judge(j)) = length(extractFaceDown(j)) == 0 } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Base.model b/AlgebraicDataflowArchitectureModel/models/Base.model index ac44843..bb460e4 100644 --- a/AlgebraicDataflowArchitectureModel/models/Base.model +++ b/AlgebraicDataflowArchitectureModel/models/Base.model @@ -1,13 +1,13 @@ channel CIO{ - out r1(x1:Int, set1(y1:Int)) == y1 - out r1(x1, e) == x1 + out r1(x1:Int, set1(y1:Int)) = y1 + out r1(x1, e) = x1 } channel CIO2{ - out r2(x2:Int, set2(y2:Int)) == y2 - out r2(x2, e) == x2 + out r2(x2:Int, set2(y2:Int)) = y2 + out r2(x2, e) = x2 } channel C1{ - in r1(x1, update(x1:Int, y1:Int, x2:Int, y2:Int)) == y1 - in r2(x2, update(x1, y1, x2, y2)) == y2 - out r3(x3:Int, update(x1, y1, x2, y2)) == x1 + y1 + x2 + y2 + in r1(x1, update(x1:Int, y1:Int, x2:Int, y2:Int)) = y1 + in r2(x2, update(x1, y1, x2, y2)) = y2 + out r3(x3:Int, update(x1, y1, x2, y2)) = x1 + y1 + x2 + y2 } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Bug.model b/AlgebraicDataflowArchitectureModel/models/Bug.model index f31727b..1ba4f5e 100644 --- a/AlgebraicDataflowArchitectureModel/models/Bug.model +++ b/AlgebraicDataflowArchitectureModel/models/Bug.model @@ -1,7 +1,7 @@ channel CIO{ - out aUa(a, input(x:Int)) == x + out aUa(a, input(x:Int)) = x } channel C1{ - in aUa(a, update(x)) == x - out aUb(b, update(x)) == x + 3 + in aUa(a, update(x)) = x + out aUb(b, update(x)) = x + 3 } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Clock.dtram b/AlgebraicDataflowArchitectureModel/models/Clock.dtram index 939c325..bbeb6dc 100644 --- a/AlgebraicDataflowArchitectureModel/models/Clock.dtram +++ b/AlgebraicDataflowArchitectureModel/models/Clock.dtram @@ -1,18 +1,18 @@ model { channel CIO1 { - out min(m: Int, tick) == mod(m + 1, 60) + out min(m: Int, tick) = (m + 1) % 60 } channel HourUpdate { - in hour(h: Int, update(h2)) == h2 - out hour_ang(h_ang: Double, update(h2)) == h2 / 6 * PI + in hour(h: Int, update(h2)) = h2 + out hour_ang(h_ang: Double, update(h2)) = h2 / 6 * PI } channel MinUpdate { - in min(m, update(m2)) == m2 - out min_ang(m_ang: Double, update(m2)) == m2 / 30 * PI + in min(m, update(m2)) = m2 + out min_ang(m_ang: Double, update(m2)) = m2 / 30 * PI } channel Clock { - in min(m, update(m2)) == m2 - out hour(h, update(m2)) == if(eq(m2, 0), mod(h + 1, 24), h) + in min(m, update(m2)) = m2 + out hour(h, update(m2)) = if(m2 == 0, (h + 1) % 24, h) } } geometry { diff --git a/AlgebraicDataflowArchitectureModel/models/Clock.model b/AlgebraicDataflowArchitectureModel/models/Clock.model index 0cabf0e..0ecb11b 100644 --- a/AlgebraicDataflowArchitectureModel/models/Clock.model +++ b/AlgebraicDataflowArchitectureModel/models/Clock.model @@ -1,15 +1,15 @@ channel CIO1 { - out min(m: Int, tick) == mod(m + 1, 60) + out min(m: Int, tick) = (m + 1) % 60 } channel HourUpdate { - in hour(h: Int, update(h2)) == h2 - out hour_ang(h_ang: Double, update(h2)) == h2 / 6 * PI + in hour(h: Int, update(h2)) = h2 + out hour_ang(h_ang: Double, update(h2)) = h2 / 6 * PI } channel MinUpdate { - in min(m, update(m2)) == m2 - out min_ang(m_ang: Double, update(m2)) == m2 / 30 * PI + in min(m, update(m2)) = m2 + out min_ang(m_ang: Double, update(m2)) = m2 / 30 * PI } channel Clock { - in min(m, update(m2)) == m2 - out hour(h, update(m2)) == if(eq(m2, 0), mod(h + 1, 24), h) + in min(m, update(m2)) = m2 + out hour(h, update(m2)) = if(m2 == 0, (h + 1) % 24, h) } diff --git a/AlgebraicDataflowArchitectureModel/models/CustomerOffice.model b/AlgebraicDataflowArchitectureModel/models/CustomerOffice.model index b3ddeb5..42cdf13 100644 --- a/AlgebraicDataflowArchitectureModel/models/CustomerOffice.model +++ b/AlgebraicDataflowArchitectureModel/models/CustomerOffice.model @@ -1,21 +1,21 @@ channel CIO_AddCustomer { - out customers(db:Map, addCustomer(uid:Str, off:Str)) == insert(db, uid, {"off": off}) + out customers(db:Map, addCustomer(uid:Str, off:Str)) = insert(db, uid, {"off": off}) } channel CIO_AddCampany { - out companies(db:Map, addCampany(cid:Str, add:Str)) == insert(db, cid, {"add": add}) + out companies(db:Map, addCampany(cid:Str, add:Str)) = insert(db, cid, {"add": add}) } channel CIO_SetCustomerOff(uid:Str) { - out customers.{uid}.off(cid:Str, setOff(cid2)) == cid2 + out customers.{uid}.off(cid:Str, setOff(cid2)) = cid2 } channel CIO_SetCompanyAdd(cid:Str) { - out companies.{cid}.add(a1:Str, setAdd(a2)) == a2 + out companies.{cid}.add(a1:Str, setAdd(a2)) = a2 } channel C(uid:Str) { - in customers.{uid}.off(cid, sync(cid2, add2)) == cid2 - in companies.{cid2}.add(a1, sync(cid2, add2)) == add2 - out customers.{uid}.add(a3:Str, sync(cid2, add2)) == add2 + in customers.{uid}.off(cid, sync(cid2, add2)) = cid2 + in companies.{cid2}.add(a1, sync(cid2, add2)) = add2 + out customers.{uid}.add(a3:Str, sync(cid2, add2)) = add2 } diff --git a/AlgebraicDataflowArchitectureModel/models/Game.model b/AlgebraicDataflowArchitectureModel/models/Game.model index bc90ba4..1952ff0 100644 --- a/AlgebraicDataflowArchitectureModel/models/Game.model +++ b/AlgebraicDataflowArchitectureModel/models/Game.model @@ -1,32 +1,32 @@ channel CIO { - out force(f:Double, action(x:Double)) == x - out time(t:Double, action(x)) == t + 0.01 - out force(f, e) == x - out time(t, e) == t + 0.01 + out force(f:Double, action(x:Double)) = x + out time(t:Double, action(x)) = t + 0.01 + out force(f, e) = x + out time(t, e) = t + 0.01 } channel CIO2 { - out velocity(v:Double, setVel(x:Double)) == x - out velocity(v, e) == x + out velocity(v:Double, setVel(x:Double)) = x + out velocity(v, e) = x } channel CIO3 { - out mass(m:Double, setMass(x:Double)) == x - out mass(m, e) == m + out mass(m:Double, setMass(x:Double)) = x + out mass(m, e) = m } channel C1 { - in force(f, update1(y, z)) == y - in mass(m, update1(y, z)) == z - out acceleration(a: Double, update1(y, z)) == y / z + in force(f, update1(y, z)) = y + in mass(m, update1(y, z)) = z + out acceleration(a: Double, update1(y, z)) = y / z } channel C2 { - in acceleration(a, update2(z)) == z - out velocity(v:Double, update2(z)) == v + 0.01 * z + in acceleration(a, update2(z)) = z + out velocity(v:Double, update2(z)) = v + 0.01 * z } channel C3 { - in velocity(v, update3(u)) == u - out position(p:Double, update3(u)) == p + 0.01 * u + in velocity(v, update3(u)) = u + out position(p:Double, update3(u)) = p + 0.01 * u } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Hello.model b/AlgebraicDataflowArchitectureModel/models/Hello.model index 46bb932..38759d7 100644 --- a/AlgebraicDataflowArchitectureModel/models/Hello.model +++ b/AlgebraicDataflowArchitectureModel/models/Hello.model @@ -1,3 +1,3 @@ channel cio { - out r1(x1:Int,set(x2)) == x2 + out r1(x1:Int,set(x2)) = x2 } diff --git a/AlgebraicDataflowArchitectureModel/models/Hello2.model b/AlgebraicDataflowArchitectureModel/models/Hello2.model index 4815cf6..67eb1c0 100644 --- a/AlgebraicDataflowArchitectureModel/models/Hello2.model +++ b/AlgebraicDataflowArchitectureModel/models/Hello2.model @@ -1,3 +1,3 @@ channel cio { - out r1(x1:Int,set(x2:Int)) == x2:Int + out r1(x1:Int,set(x2:Int)) = x2:Int } diff --git a/AlgebraicDataflowArchitectureModel/models/HelloWorld.model b/AlgebraicDataflowArchitectureModel/models/HelloWorld.model index 44aa310..2a5fa1e 100644 --- a/AlgebraicDataflowArchitectureModel/models/HelloWorld.model +++ b/AlgebraicDataflowArchitectureModel/models/HelloWorld.model @@ -1,7 +1,7 @@ channel cio { - out r1(x1:Int,set(x2:Int)) == x2:Int + out r1(x1:Int,set(x2:Int)) = x2:Int } channel c2 { - in r1(x1:Int,update(x2:Int)) == x2:Int - out r2(y1:Int,update(x2:Int)) == (x2:Int+1) + in r1(x1:Int,update(x2:Int)) = x2:Int + out r2(y1:Int,update(x2:Int)) = (x2:Int+1) } diff --git a/AlgebraicDataflowArchitectureModel/models/InventoryManagement.model b/AlgebraicDataflowArchitectureModel/models/InventoryManagement.model index e69f8f7..c41ed3c 100644 --- a/AlgebraicDataflowArchitectureModel/models/InventoryManagement.model +++ b/AlgebraicDataflowArchitectureModel/models/InventoryManagement.model @@ -1,7 +1,7 @@ channel ItemRegistration { - out inventory(items:Map, registerItem(itemId:Str, quantity:Int)) == insert(items, itemId, {"count": quantity}) + out inventory(items:Map, registerItem(itemId:Str, quantity:Int)) = insert(items, itemId, {"count": quantity}) } channel ReceivingOrShipping(itemId:Str) { - out inventory.{itemId}.count(prev_quantity:Int, receiveOrship(quantity:Int)) == prev_quantity + quantity + out inventory.{itemId}.count(prev_quantity:Int, receiveOrship(quantity:Int)) = prev_quantity + quantity } diff --git a/AlgebraicDataflowArchitectureModel/models/JumpGame.model b/AlgebraicDataflowArchitectureModel/models/JumpGame.model index 1981df9..e1b9250 100644 --- a/AlgebraicDataflowArchitectureModel/models/JumpGame.model +++ b/AlgebraicDataflowArchitectureModel/models/JumpGame.model @@ -12,59 +12,59 @@ gameover := false } channel CIO { - out force(f:Pair, gravity(y:Double)) == pair(0.0, y) - out time(t:Double, gravity(y)) == t + 0.01 + out force(f:Pair, gravity(y:Double)) = pair(0.0, y) + out time(t:Double, gravity(y)) = t + 0.01 } channel CIO2 { - out movex(x:Double, run(x2:Double)) == x2 + out movex(x:Double, run(x2:Double)) = x2 } channel CIO3 { - out movey(y:Double, jump(y2:Double)) == y2 + out movey(y:Double, jump(y2:Double)) = y2 } channel CIO4 { - out mass(m:Double, setMass(x:Double)) == x + out mass(m:Double, setMass(x:Double)) = x } channel CIO5 { - out ground(g:Bool, openHole) == false - out ground(g, closeHole) == true + out ground(g:Bool, openHole) = false + out ground(g, closeHole) = true } channel C1 { ref onground(o, update1(f2, m2, o)) - in force(f, update1(f2, m2, o)) == f2 - in mass(m, update1(f2, m2, o)) == m2 - out acceleration(a:Pair, update1(f2, m2, o)) == if(o, pair(left(f2) / m2, 0.0), pair(left(f2) / m2, right(f2) / m2)) + in force(f, update1(f2, m2, o)) = f2 + in mass(m, update1(f2, m2, o)) = m2 + out acceleration(a:Pair, update1(f2, m2, o)) = if(o, pair(left(f2) / m2, 0.0), pair(left(f2) / m2, right(f2) / m2)) } channel C2 { ref onground(o, update3(a2, o)) - in acceleration(a, update3(a2, o)) == a2 - out velocity(v:Pair, update3(a2, o)) == if(and(o, lt(right(v), 0.0)), + in acceleration(a, update3(a2, o)) = a2 + out velocity(v:Pair, update3(a2, o)) = if(o && right(v) < 0.0, pair(left(v) + 0.01 * left(a2), 0.0), pair(left(v) + 0.01 * left(a2), right(v) + 0.01 * right(a2))) } channel C3 { ref onground(o, update4(x2, o)) - in movex(x, update4(x2, o)) == x2 - out velocity(v:Pair, update4(x2, o)) == if(o, pair(x2, right(v)), v) + in movex(x, update4(x2, o)) = x2 + out velocity(v:Pair, update4(x2, o)) = if(o, pair(x2, right(v)), v) } channel C4 { ref onground(o, update5(x2, o)) - in movey(y, update5(y2, o)) == y2 - out velocity(v:Pair, update5(y2, o)) == if(o, pair(left(v), y2), v) + in movey(y, update5(y2, o)) = y2 + out velocity(v:Pair, update5(y2, o)) = if(o, pair(left(v), y2), v) } channel C5 { - in velocity(v, update6(v2, g)) == v2 + in velocity(v, update6(v2, g)) = v2 ref ground(g, update6(v2, g)) - out position(p:Pair, update6(v2, g)) == if(and(eq(g, true), lt(right(p) + 0.01 * right(v2), 0.0)), + out position(p:Pair, update6(v2, g)) = if(g == true && right(p) + 0.01 * right(v2) > 0.0, pair(left(p) + 0.01 * left(v2), 0.0), pair(left(p) + 0.01 * left(v2), right(p) + 0.01 * right(v2))) } channel C6 { - in position(p, update2(p2, g2)) == p2 - in ground(g, update2(p2, g2)) == g2 - out onground(o:Bool, update2(p2, g2)) == and(eq(g2, true), le(right(p2), 0.0)) + in position(p, update2(p2, g2)) = p2 + in ground(g, update2(p2, g2)) = g2 + out onground(o:Bool, update2(p2, g2)) = (g2 == true) && (right(p2) <= 0.0) } channel C7 { in position(p, update7(p2)) == p2 - out clear(c:Bool, update7(p2)) == if(gt(left(p2), 100.0), true, false) - out gameover(go:Bool, update7(p2)) == if(lt(right(p2), -1.0), true, false) + out clear(c:Bool, update7(p2)) == (left(p2) > 100.0) + out gameover(go:Bool, update7(p2)) == (right(p2) < -1.0) } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/POS.model b/AlgebraicDataflowArchitectureModel/models/POS.model index 150c106..c15c931 100644 --- a/AlgebraicDataflowArchitectureModel/models/POS.model +++ b/AlgebraicDataflowArchitectureModel/models/POS.model @@ -1,15 +1,15 @@ channel CIO { - out payment(p:Int, purchase(x:Int)) == x + out payment(p:Int, purchase(x:Int)) = x } channel C3 { - in history(h, update3(u)) == u - out total(t:Int, update3(u)) == sum(u) + in history(h, update3(u)) = u + out total(t:Int, update3(u)) = sum(u) } channel C1 { - in payment(p, update1(y)) == y - out points(l:Int, update1(y)) == floor(y * 0.05) + in payment(p, update1(y)) = y + out points(l:Int, update1(y)) = floor(y * 0.05) } channel C2 { - in payment(p, update2(z)) == z - out history(h:List, update2(z)) == cons(z, h) + in payment(p, update2(z)) = z + out history(h:List, update2(z)) = cons(z, h) } diff --git a/AlgebraicDataflowArchitectureModel/models/POS2.model b/AlgebraicDataflowArchitectureModel/models/POS2.model index 6ae676d..0ee31d2 100644 --- a/AlgebraicDataflowArchitectureModel/models/POS2.model +++ b/AlgebraicDataflowArchitectureModel/models/POS2.model @@ -1,14 +1,14 @@ channel CIO { - out payment(p:Int, purchase(x:Int)) == x + out payment(p:Int, purchase(x:Int)) = x } channel C1 { - in payment(p1, update1(y)) == y - out points(l:Int, update1(y)) == floor(y * 0.05) + in payment(p1, update1(y)) = y + out points(l:Int, update1(y)) = floor(y * 0.05) } channel C2 { - in payment(p1, update2(z)) == z - out history(h:List, update2(z)) == cons(z, h) - out total(t:Int, update2(z)) == z + t + in payment(p1, update2(z)) = z + out history(h:List, update2(z)) = cons(z, h) + out total(t:Int, update2(z)) = z + t } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java index b8bb8fe..9cf0280 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java @@ -48,6 +48,6 @@ return resourcePath.getLeafResourceName() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")" - + " == " + stateTransition.getNextStateExpression(); + + " = " + stateTransition.getNextStateExpression(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 3f8a50e..7d21e0c 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -105,6 +105,19 @@ return new Constant(Integer.toString(Integer.parseInt(arg0) / Integer.parseInt(arg1))); } }); + public static final Symbol mod = new Symbol(Parser.MOD, 2, Symbol.Type.INFIX, "%", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(arg0) % Long.parseLong(arg1)), typeLong); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(arg0) % Integer.parseInt(arg1)), typeInt); + } + return new Constant(Integer.toString(Integer.parseInt(arg0) % Integer.parseInt(arg1))); + } + }); public static final Symbol minus = new Symbol(Parser.MINUS, 1, new Symbol.ICalculator() { @Override public Constant calculate(List args) { @@ -121,6 +134,185 @@ return new Constant(Integer.toString(-Integer.parseInt(arg))); } }); + public static final Symbol eq = new Symbol(Parser.EQ, 2, Symbol.Type.INFIX, "==", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) == Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) == Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) == Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) == Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol neq = new Symbol(Parser.NEQ, 2, Symbol.Type.INFIX, "!=", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) != Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) != Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) != Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) != Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol gt = new Symbol(Parser.GT, 2, Symbol.Type.INFIX, ">", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) > Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) > Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) > Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) > Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol lt = new Symbol(Parser.LT, 2, Symbol.Type.INFIX, "<", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) < Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) < Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) < Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) < Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol ge = new Symbol(Parser.GE, 2, Symbol.Type.INFIX, ">=", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) >= Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) >= Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) >= Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) >= Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol le = new Symbol(Parser.LE, 2, Symbol.Type.INFIX, "<=", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeDouble) || args.get(1).getType().equals(typeDouble)) { + result = (Double.parseDouble(arg0) <= Double.parseDouble(arg1)); + } else if (args.get(0).getType().equals(typeFloat) || args.get(1).getType().equals(typeFloat)) { + result = (Float.parseFloat(arg0) <= Float.parseFloat(arg1)); + } else if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { + result = (Long.parseLong(arg0) <= Long.parseLong(arg1)); + } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { + result = (Integer.parseInt(arg0) <= Integer.parseInt(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol and = new Symbol(Parser.AND, 2, Symbol.Type.INFIX, "&&", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeBoolean) || args.get(1).getType().equals(typeBoolean)) { + result = (Boolean.parseBoolean(arg0) && Boolean.parseBoolean(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol or = new Symbol(Parser.OR, 2, Symbol.Type.INFIX, "||", Symbol.Type.INFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + String arg1 = args.get(1).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeBoolean) || args.get(1).getType().equals(typeBoolean)) { + result = (Boolean.parseBoolean(arg0) || Boolean.parseBoolean(arg1)); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); + public static final Symbol neg = new Symbol(Parser.NEG, 1, Symbol.Type.PREFIX, "!", Symbol.Type.PREFIX, new Symbol.ICalculator() { + @Override + public Constant calculate(List args) { + String arg0 = args.get(0).getSymbol().toString(); + boolean result = false; + if (args.get(0).getType().equals(typeBoolean)) { + result = !Boolean.parseBoolean(arg0); + } + if (result) { + return new Constant(true_); + } else { + return new Constant(false_); + } + } + }); public static final Symbol cons = new Symbol("cons", 2, Symbol.Type.PREFIX, "($x,$y)->$x.add(0, $y)", Symbol.Type.LAMBDA_WITH_SIDE_EFFECT, new int[] {1, 0}); public static final Symbol append = new Symbol("append", 2, Symbol.Type.PREFIX, "add", Symbol.Type.METHOD_WITH_SIDE_EFFECT); public static final Symbol remove = new Symbol("remove", 2, Symbol.Type.PREFIX, "remove", Symbol.Type.METHOD_WITH_SIDE_EFFECT); @@ -166,6 +358,8 @@ } }); public static final Symbol null_ = new Symbol("null", 0, Symbol.Type.PREFIX, "null", Symbol.Type.PREFIX); + public static final Symbol true_ = new Symbol("true", 0, Symbol.Type.PREFIX, "true", Symbol.Type.PREFIX); + public static final Symbol false_ = new Symbol("false", 0, Symbol.Type.PREFIX, "false", Symbol.Type.PREFIX); public static final Symbol cond = new Symbol("if", 3, Symbol.Type.PREFIX, new Symbol.IImplGenerator() { final int count[] = {0}; @Override @@ -199,32 +393,6 @@ return null; } }); - - - public static final Symbol mod = new Symbol("mod", 2, Symbol.Type.PREFIX, "%", Symbol.Type.INFIX, new Symbol.ICalculator() { - @Override - public Constant calculate(List args) { - String arg0 = args.get(0).getSymbol().toString(); - String arg1 = args.get(1).getSymbol().toString(); - if (args.get(0).getType().equals(typeLong) || args.get(1).getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(arg0) % Long.parseLong(arg1)), typeLong); - } else if (args.get(0).getType().equals(typeInt) || args.get(1).getType().equals(typeInt)) { - return new Constant(Integer.toString(Integer.parseInt(arg0) % Integer.parseInt(arg1)), typeInt); - } - return new Constant(Integer.toString(Integer.parseInt(arg0) % Integer.parseInt(arg1))); - } - }); - public static final Symbol eq = new Symbol("eq", 2, Symbol.Type.PREFIX, "==", Symbol.Type.INFIX); - public static final Symbol neq = new Symbol("neq", 2, Symbol.Type.PREFIX, "!=", Symbol.Type.INFIX); - public static final Symbol gt = new Symbol("gt", 2, Symbol.Type.PREFIX, ">", Symbol.Type.INFIX); - public static final Symbol lt = new Symbol("lt", 2, Symbol.Type.PREFIX, "<", Symbol.Type.INFIX); - public static final Symbol ge = new Symbol("ge", 2, Symbol.Type.PREFIX, ">=", Symbol.Type.INFIX); - public static final Symbol le = new Symbol("le", 2, Symbol.Type.PREFIX, "<=", Symbol.Type.INFIX); - public static final Symbol and = new Symbol("and", 2, Symbol.Type.PREFIX, "&&", Symbol.Type.INFIX); - public static final Symbol or = new Symbol("or", 2, Symbol.Type.PREFIX, "||", Symbol.Type.INFIX); - public static final Symbol neg = new Symbol("neg", 1, Symbol.Type.PREFIX, "!", Symbol.Type.PREFIX); - public static final Symbol true_ = new Symbol("true", 0, Symbol.Type.PREFIX, "true", Symbol.Type.PREFIX); - public static final Symbol false_ = new Symbol("false", 0, Symbol.Type.PREFIX, "false", Symbol.Type.PREFIX); public static final Symbol pair = new Symbol("pair", -1, Symbol.Type.PREFIX, new Symbol.IImplGenerator() { @Override public String generate(Type type, Type[] childrenTypes, String[] childrenImpl, String[] childrenSideEffects, String[] sideEffect) { @@ -297,6 +465,15 @@ div.setInverses(new Symbol[] {mul}); minus.setInverses(new Symbol[] {minus}); mod.setSignature(new Type[] {typeInt, null, null}); + eq.setSignature(new Type[] {typeBoolean, null, null}); + neq.setSignature(new Type[] {typeBoolean, null, null}); + gt.setSignature(new Type[] {typeBoolean, null, null}); + lt.setSignature(new Type[] {typeBoolean, null, null}); + ge.setSignature(new Type[] {typeBoolean, null, null}); + le.setSignature(new Type[] {typeBoolean, null, null}); + and.setSignature(new Type[] {typeBoolean, typeBoolean, typeBoolean}); + or.setSignature(new Type[] {typeBoolean, typeBoolean, typeBoolean}); + neg.setSignature(new Type[] {typeBoolean, typeBoolean}); cons.setInverses(new Symbol[] {head, tail}); cons.setSignature(new Type[] {typeList, null, typeList}); append.setSignature(new Type[] {typeList, typeList, null}); @@ -307,18 +484,9 @@ length.setSignature(new Type[] {typeInt, null}); get.setSignature(new Type[] {null, typeList, typeInt}); set.setSignature(new Type[] {typeList, typeList, typeInt, null}); - eq.setSignature(new Type[] {typeBoolean, null, null}); - neq.setSignature(new Type[] {typeBoolean, null, null}); - gt.setSignature(new Type[] {typeBoolean, null, null}); - lt.setSignature(new Type[] {typeBoolean, null, null}); - ge.setSignature(new Type[] {typeBoolean, null, null}); - le.setSignature(new Type[] {typeBoolean, null, null}); - and.setSignature(new Type[] {typeBoolean, typeBoolean, typeBoolean}); - or.setSignature(new Type[] {typeBoolean, typeBoolean, typeBoolean}); - neg.setSignature(new Type[] {typeBoolean, typeBoolean}); + null_.setSignature(new Type[] {null}); true_.setSignature(new Type[] {typeBoolean}); false_.setSignature(new Type[] {typeBoolean}); - null_.setSignature(new Type[] {null}); pair.setSignature(new Type[] {typePair,null,null}); pair.setInverses(new Symbol[] {left, right}); left.setSignature(new Type[] {null, typePair}); @@ -379,17 +547,6 @@ addSymbol(div); addSymbol(minus); addSymbol(mod); - addSymbol(cons); - addSymbol(append); - addSymbol(remove); - addSymbol(head); - addSymbol(tail); - addSymbol(length); - addSymbol(contains); - addSymbol(get); - addSymbol(set); - addSymbol(nil); - addSymbol(cond); addSymbol(eq); addSymbol(neq); addSymbol(gt); @@ -399,9 +556,20 @@ addSymbol(and); addSymbol(or); addSymbol(neg); + addSymbol(cons); + addSymbol(append); + addSymbol(remove); + addSymbol(head); + addSymbol(tail); + addSymbol(length); + addSymbol(contains); + addSymbol(get); + addSymbol(set); + addSymbol(cond); + addSymbol(nil); + addSymbol(null_); addSymbol(true_); addSymbol(false_); - addSymbol(null_); addSymbol(pair); addSymbol(left); addSymbol(right); diff --git a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java index c6790e5..2fb57ee 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java @@ -63,8 +63,8 @@ super.addChannelMemberAsOutput(channelMember); if (getOutputChannelMembers().size() == 1) { if (formula == null) formula = ""; - if (!formula.contains("==")) { - formula = channelMember.getResource().getLeafResourceName() + " == " + formula; + if (!formula.contains("=")) { + formula = channelMember.getResource().getLeafResourceName() + " = " + formula; } } if (formulaRhs != null) { diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index c1f3d2e..472bb81 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -62,12 +62,23 @@ public static final String MUL = "*"; public static final String SUB = "-"; public static final String DIV = "/"; + public static final String MOD = "%"; public static final String MINUS = "-"; + public static final String EQ = "=="; + public static final String NEQ = "!="; + public static final String GT = ">"; + public static final String LT = "<"; + public static final String GE = ">="; + public static final String LE = "<="; + public static final String AND = "&&"; + public static final String OR = "||"; + public static final String NEG = "!"; public static final String ADD_REGX = "\\+"; public static final String MUL_REGX = "\\*"; public static final String SUB_REGX = "\\-"; public static final String DIV_REGX = "/"; - public static final String EQUALS = "=="; + public static final String OR_REGX = "\\|\\|"; + public static final String EQUALS = "="; public static final String ASSIGNMENT = "="; public static final String COMMA = ","; public static final String COLON = ":"; @@ -265,30 +276,33 @@ ArrayList operators = new ArrayList<>(); String operator = null; for (;;) { - String leftBracketOrMinus = stream.next(); - if (leftBracketOrMinus.equals(LEFT_BRACKET)) { + String leftBracketOrMinusOrNeg = stream.next(); + if (leftBracketOrMinusOrNeg.equals(LEFT_BRACKET)) { Expression exp = parseTerm(stream, model); String rightBracket = stream.next(); if (!rightBracket.equals(RIGHT_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); expressions.add(exp); - } else if (leftBracketOrMinus.equals(LEFT_CURLY_BRACKET)) { + } else if (leftBracketOrMinusOrNeg.equals(LEFT_CURLY_BRACKET)) { Expression exp = parseJsonTerm(stream, model); String rightBracket = stream.next(); if (!rightBracket.equals(RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); expressions.add(exp); - } else if (leftBracketOrMinus.equals(LEFT_SQUARE_BRACKET)) { + } else if (leftBracketOrMinusOrNeg.equals(LEFT_SQUARE_BRACKET)) { Expression exp = parseListTerm(stream, model); String rightBracket = stream.next(); if (!rightBracket.equals(RIGHT_SQUARE_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); expressions.add(exp); } else { - Symbol minus = null; + Symbol minusOrNeg = null; String symbolName = null; - if (leftBracketOrMinus.equals(MINUS)) { - minus = DataTransferModel.minus; // not sub + if (leftBracketOrMinusOrNeg.equals(MINUS)) { + minusOrNeg = DataTransferModel.minus; // not sub + symbolName = stream.next(); + } else if (leftBracketOrMinusOrNeg.equals(NEG)) { + minusOrNeg = DataTransferModel.neg; symbolName = stream.next(); } else { - symbolName = leftBracketOrMinus; + symbolName = leftBracketOrMinusOrNeg; } Expression exp = null; if (stream.checkNext() != null && stream.checkNext().equals(LEFT_BRACKET)) { @@ -341,10 +355,10 @@ } } } - if (minus != null) { - Term minusTerm = new Term(minus); - minusTerm.addChild(exp); - expressions.add(minusTerm); + if (minusOrNeg != null) { + Term minusOrNegTerm = new Term(minusOrNeg); + minusOrNegTerm.addChild(exp); + expressions.add(minusOrNegTerm); } else { expressions.add(exp); } @@ -364,6 +378,36 @@ } else if (operator.equals(DIV)) { operators.add(DataTransferModel.div); stream.next(); + } else if (operator.equals(MOD)) { + operators.add(DataTransferModel.mod); + stream.next(); + } else if (operator.equals(EQ)) { + operators.add(DataTransferModel.eq); + stream.next(); + } else if (operator.equals(NEQ)) { + operators.add(DataTransferModel.neq); + stream.next(); + } else if (operator.equals(GT)) { + operators.add(DataTransferModel.gt); + stream.next(); + } else if (operator.equals(LT)) { + operators.add(DataTransferModel.lt); + stream.next(); + } else if (operator.equals(GE)) { + operators.add(DataTransferModel.ge); + stream.next(); + } else if (operator.equals(LE)) { + operators.add(DataTransferModel.le); + stream.next(); + } else if (operator.equals(AND)) { + operators.add(DataTransferModel.and); + stream.next(); + } else if (operator.equals(OR)) { + operators.add(DataTransferModel.or); + stream.next(); + } else if (operator.equals(NEG)) { + operators.add(DataTransferModel.neg); + stream.next(); } else if (operator.equals(DOT)) { // json accessor Expression exp = expressions.remove(0); @@ -411,7 +455,9 @@ int i = 1; for (Symbol op: operators) { Expression second = expressions.get(i); - if (op.getName().equals(MUL) || op.getName().equals(DIV)) { + if (op.getName().equals(MUL) || op.getName().equals(DIV) || op.getName().equals(MOD) + || op.getName().equals(EQ) || op.getName().equals(NEQ) || op.getName().equals(GT) || op.getName().equals(LT) + || op.getName().equals(GE) || op.getName().equals(LE) || op.getName().equals(AND) || op.getName().equals(OR)) { Term term = new Term(op); term.addChild(first); term.addChild(second); @@ -563,7 +609,7 @@ } public static class TokenStream { - private ArrayList> tokens = new ArrayList<>(); + private ArrayList> tokens = new ArrayList<>(); private ArrayList lines = new ArrayList<>(); private int line = 0; private int n = 0; @@ -591,15 +637,45 @@ splitBy( splitBy( splitBy( - Arrays.asList(line.split("[ \t]")), - ADD, - ADD_REGX), - MUL, - MUL_REGX), - SUB, - SUB_REGX), - DIV, - DIV_REGX), + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + splitBy( + line.split("[ \t]"), + ADD, + ADD_REGX), + MUL, + MUL_REGX), + SUB, + SUB_REGX), + DIV, + DIV_REGX), + MOD, + MOD), + EQ, + EQ), + NEQ, + NEQ), + GT, + GT), + LT, + LT), + GE, + GE), + LE, + LE), + AND, + AND), + OR, + OR_REGX), + NEG, + NEG), DOT, DOT_REGX), COMMA, @@ -621,24 +697,36 @@ RIGHT_SQUARE_BRACKET, RIGHT_SQUARE_BRACKET_REGX)); } - - private ArrayList splitBy(final List tokens, final String delimiter, final String delimiterRegx) { - ArrayList newTokens = new ArrayList<>(); + + private ArrayList splitBy(String[] tokens, final String delimiter, final String delimiterRegx) { + ArrayList newTokens = new ArrayList<>(); for (String token: tokens) { - String[] splitTokens = token.split(delimiterRegx); - boolean fFirstToken = true; - for (String t: splitTokens) { - if (!fFirstToken) { - newTokens.add(delimiter); + newTokens.add(new Token(token)); + } + return splitBy(newTokens, delimiter, delimiterRegx); + } + + private ArrayList splitBy(final List tokens, final String delimiter, final String delimiterRegx) { + ArrayList newTokens = new ArrayList<>(); + for (Token token: tokens) { + if (token.isAtomic()) { + newTokens.add(token); + } else { + String[] splitTokens = token.split(delimiterRegx); + boolean fFirstToken = true; + for (String t: splitTokens) { + if (!fFirstToken) { + newTokens.add(new Token(delimiter, true)); + } + if (t.length() > 0) { + newTokens.add(new Token(t)); + } + fFirstToken = false; } - if (t.length() > 0) { - newTokens.add(t); + while (token.endsWith(delimiter)) { + newTokens.add(new Token(delimiter, true)); + token = token.substring(0, token.length() - 1); } - fFirstToken = false; - } - while (token.endsWith(delimiter)) { - newTokens.add(delimiter); - token = token.substring(0, token.length() - 1); } } return newTokens; @@ -651,7 +739,7 @@ n = 0; if (line >= tokens.size()) return null; } - String token = tokens.get(line).get(n); + String token = tokens.get(line).get(n).getTokenStr(); n++; return token; } @@ -663,7 +751,7 @@ n = 0; if (line >= tokens.size()) return null; } - return tokens.get(line).get(n); + return tokens.get(line).get(n).getTokenStr(); } public boolean hasNext() { @@ -688,4 +776,42 @@ return text; } } + + public static class Token { + String token; + boolean isAtomic = false; + + public Token(String token) { + this.token = token; + } + + public Token(String token, boolean isAtomic) { + this.token = token; + this.isAtomic = isAtomic; + } + + public String getTokenStr() { + return token; + } + + public boolean isAtomic() { + return isAtomic; + } + + public String[] split(String delimiterRegx) { + return token.split(delimiterRegx); + } + + public boolean endsWith(String delimiter) { + return token.endsWith(delimiter); + } + + public int length() { + return token.length(); + } + + public Token substring(int beginIdx, int endIdx) { + return new Token(token.substring(beginIdx, endIdx)); + } + } } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataTransferModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataTransferModelTest.java index c0f38af..5f1b3c3 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataTransferModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataTransferModelTest.java @@ -29,7 +29,7 @@ // === cio_setCustomerOff(uid) === // - // out customers.{uid}.off(c, set(x)) == x + // out customers.{uid}.off(c, set(x)) = x // DataTransferChannel cio_setCustomerOff = new DataTransferChannel("CIO_SetCustomerOff", new Variable("uid")); // set customer's office (an input channel) ChannelMember customer_off_1 = new ChannelMember(customer_off); @@ -38,7 +38,7 @@ // === cio_setCompanyAdd(cid) === // - // out companies.{cid}.add(a, set(y)) == y + // out companies.{cid}.add(a, set(y)) = y // DataTransferChannel cio_setCompanyAdd = new DataTransferChannel("CIO_SetCompanyAdd", new Variable("cid")); // set companie's address (an input channel) ChannelMember company_add_1 = new ChannelMember(company_add); @@ -47,9 +47,9 @@ // === c === // - // in customers.{uid}.off( c, update(cid, a2)) == cid - // in companies.{cid}.add( a, update(cid, a2)) == a2 - // out customers.{uid}.add(b, update(cid, a2)) == a2 + // in customers.{uid}.off( c, update(cid, a2)) = cid + // in companies.{cid}.add( a, update(cid, a2)) = a2 + // out customers.{uid}.add(b, update(cid, a2)) = a2 // DataTransferChannel c = new DataTransferChannel("c", new Variable("uid")); // update customer's address ChannelMember customer_off_2 = new ChannelMember(customer_off); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java index efb7b31..bc1db89 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java @@ -123,8 +123,8 @@ // === c1 === // - // payment(p1, update1(y)) == y - // points(l, update1(y)) == floor(y * 0.05) + // payment(p1, update1(y)) = y + // points(l, update1(y)) = floor(y * 0.05) // DataTransferChannel c1 = new DataTransferChannel("c1"); ChannelMember c1_payment = new ChannelMember(payment); @@ -190,8 +190,8 @@ // === c2 === // - // payment(p1, update2(z)) == z - // history(h, update2(z)) == cons(z, h) + // payment(p1, update2(z)) = z + // history(h, update2(z)) = cons(z, h) // DataTransferChannel c2 = new DataTransferChannel("c2"); ChannelMember c2_payment = new ChannelMember(payment);