1 DiGen: A Genertor for Digrm Eitors Bse on Hypergrph Moel G. Viehstet M. Mins Lehrstuhl für Progrmmiersprhen Universität Erlngen-Nürnerg Mrtensstr. 3, Erlngen, Germny Emil: Astrt Digrms (e.g., trees for hierrhil strutures, or grphs for finite stte mhines) re often neee s prt of vne user interfes, n re frequently speifi to user s pplition. The implementtion of eitors for igrms shoul e supporte y tool n se on forml moel. This pper gives n overview of DiGen, our genertor for igrm eitors. An eitor for ertin kin of igrms is generte from speifition, whih inlues hypergrph grmmr to esrie the struture of igrms. The user of igrm eitor oes not hve to e onerne with the grmmr, ut n mnipulte igrms very onveniently y iret mnipultion. 1 Introution An esily omprehensile representtion of omplex strutures is gining importne for the users of informtion systems or CASE tools. A signifint n inresing shre of the effort for implementing these systems goes into the user interfe. Common interfe uilers for Grphil User Interfes (GUIs) minly fous on wigets like uttons, menus, et., whih oes not mke interfes very grphil. This ssessment ws lso me in reent CACM issue on GUIs : Wht the mrket onsiers GUI is little more thn glorifie menu system, hving no grphis. This leves the grphil representtion of the pplition omin s n exerise for the eveloper ::: More omplex strutures in the pplition n often e grphilly represente y some kin of igrm. It is esirle to mke igrms prt of the user interfe n let user intertively eit them. Digrms usully hve semntil mening for the pplition. Thus, hnges to igrm hve to e trnsformtions from one onsistent stte into nother. The set of vli igrms, e.g., the set of Nssi-Shneiermn igrms (NSDs) [2, 3], is terme igrm lss n shoul e esrie y forml moel. A syntx-irete eitor tilore to some igrm lss is lle igrm eitor. A igrm eitor ensures tht igrm onstrute y the user lwys hs vli struture, n n support omplex eiting opertions n lyout. Some tools, e.g., Grnet , support simple kins of igrms. The struture of vli igrms, however, hs to e mintine y the progrmmer using Grnet n is more or less hien in the oe. There re only very few systems for generting igrm eitor tht re se on forml moel. A onept is presente in , ut not genertor. In the PAGG system  lyout of igrms is troulesome n eiting inonvenient. The Constrint system  uses grmmr moel se on on-free grmmrs n onstrints for utomti lyout of igrms. Con-free grmmrs, however, o not permit iret representtion of multiimensionl reltionships, s neee for the lyout of igrms. Furthermore, the eiting pilities re very restrite. Hypereges n hypergrphs , whih hve, e.g., een use y Hrel for tehrts , re n intuitive n vntgeous moel for representtion of igrms. DiGen, our genertor for igrm eitors, is se on hypergrph grmmr moel for speifying igrm lss. Setion 2 gives rief overview of the system. The grmmr moel is the topi of Setion 3. Setion 4 resses user intertion y iret mnipultion. Trnsformtions triggere y user intertions re esrie in Setion 5. In Setion 6 results from se stuies re presente. 2 The Genertor DiGen DiGen genertes igrm eitor, e.g., n NSD eitor s epite in Fig. 1, from speifition, whih onsists of the prts shown in Fig. 3. A mjor prt is the grmmr for the igrm lss. Some prtiulr igrm shown on the sreen is internlly represente in the igrm eitor y hypergrph, whih is erivle in the grmmr. This hy-
2 y on on n Figure 2: Hypergrph orresponing to the upper NSD in Fig. 1. Noes re shown s lk irles, n ft lines s well s the she res lele with, on, y, n n re terminl hypereges. Figure 1: Snpshot of session with n NSD eitor generte y DiGen. An eiting stte with two NSDs is shown. A group of two susequent sttements (onsisting of simple sttement n n if) is selete in the lower NSD, s inite y the hnles. pergrph is referre to s erivtion grph in Fig. 3 n is the min t struture. Lyout onitions re tthe to grmmr proutions in the speifition. Terminl symols in erivtion grph re mppe on the sreen. Their imge is ompose of primitive elements (lines,, et.) n lso prt of the speifition. The remining prts in Fig. 3 re for user intertion. 3 Digrm struture n lyout Beuse of their one-imensionl struture strings s use in  nnot represent multiimensionl reltionships iretly. We use hypergrphs inste s internl moels of igrms eing eite. A hypergrph is generliztion of grph, in whih eges re hypereges, i.e., they n e onnete to ny (fixe) numer of noes. Eh hyperege hs type n numer of onnetion points tht etermine how mny noes the hyperege is onnete to. We sy the hyperege visits these noes. 1 The fmilir irete grph n e seen s hypergrph in whih ll hypereges visit extly two noes. Noes in hypergrph moeling igrm stn for points (e.g., in the plne), hypereges re igrm elements whose position is given y the noes eing visite 1 Atully, we onsier irete hypergrphs. A irete hypergrph is triple (N;E; ) where N is finite set of noes, E finite set of hypereges, n funtion : E! N +, whih ssigns sorte sequene (e) =(n 1 ;n 2 ;:::;n k )of visite noes to eh hyperege e 2 E. The length of (e) is the rity of e. y the hyperege. This very intuitive representtion is illustrte in Fig. 2. A representtion in systems whih o not use hypergrphs [6, 7] woul e signifintly more omplite. A igrm lss, i.e., the syntti struture of igrms, is speifie in terms of its hypergrph moels using hypergrph grmmr. Con-free hypergrph grmmrs re nlogously efine to on-free (string) grmmrs n hve similr properties . Terminl n nonterminl hypereges re use in hypergrph grmmrs inste of lphet symols in string grmmrs. Eh proution in on-free hypergrph grmmr onsists on its left hn sie (lhs) of single nonterminl hyperege n the noes visite, see Fig. 4. The lhs of proution P 1 is the strting grph of the grmmr. A proution s rhs is n ritrry hypergrph, whih my ontin terminl s well s nonterminl hypereges. Applition of proution to hypergrph is similr to string grmmrs, too: if the lhs is sugrph of the hypergrph, this sugrph is remove n reple y the rhs. The resulting hypergrph is si to e erive from the first. In orer to speify whih rhs noe reples whih lhs noe, orresponing noes of the lhs n rhs re lele with the sme letters. A smple erivtion sequene is shown in Fig. 5. The igrm lss given y (on-free) hypergrph grmmr is the set of erivtion grphs tht re erivle from the strting grph n onsist of terminl hypereges only. 2 The erivtion grph is the igrm s internl hypergrph moel, whih is mppe on the sreen. Sine the hypergrph grmmr esries the set of vli hypergrph moels, the user of igrm eitor only sees vli 2 There re igrm lsses tht on-free hypergrph grmmrs nnot esrie, e.g., finite stte mhines, see Figures For these lsses, DiGen uses on-sensitive trnsformtions whih generte the itionl grph omponents tht nnot e expresse y onfree hypergrph grmmrs; see Setion 5.
3 Digrm Eitor Groups Derivtion grph Lyout ttriutes Grphil interfe Grphil ojets Group efinition Digrm representtion n trnsformtion Constrint stisftion moules Intertion t ll t flow Group types Speifition Event utomt Grmmr n trnsformtions Lyout onitions Imge of terminl symols trget of speifition Figure3: Overview of igrm eitor generte with DiGen n its speifition. P 1 P 2 NSD P 5.x = f.x.x = i.x.y = e.y =.y f.y = g.y f.x+0.5 = g.x h.x+0.5 = i.x f y e g Con h n i P 3 P 6 P 7 retngle(,,,).x+0.25 = e.x e Con e P 4 retngle(,,,).y-.y.h.x-.x.w retngle(,,,) stns for.x =.x.x =.x.y =.y.y =.y P 8 retngle(,,,).x+0.25 = e.x Con on retngle(,,,).y-.y on.h.x-.x on.w Con Figure 4: Con-free hypergrph grmmr for NSDs. Noes re shown s lk irles. Ft lines n rk she res lele with, on, y, n n re terminl hypereges, light she res re nonterminl hypereges. Nonterminls n stn for sttement sequene resp. sttement, Con for onition. The formuls re onstrints for lyout.
4 igrms. The hypergrph in Fig. 2 is suh erivtion grph onsisting of terminl eges only. These eges epite s ft lines n rk she res in Fig. 2 re mppe on the sreen s esrie in the speifition, see Fig. 3. As result of this mpping the grphil representtion (see the upper NSD in Fig. 1) onsists of set of grphil ojets. E.g., hyperege is mppe to n re ontining ritrry s, i.e., the sttements in Fig. 1. The sttement s re not prt of the hypergrph moel, ut property of this grphil ojet. Hypergrph grmmrs n esrie the syntti struture of igrms, ut lyout requirements re not inlue euse hypergrphs o not hve ny lyout. For onfree (string) grmmrs lyout n e esrie using ttriute grmmrs . Constrints were me populr y Borning  for lyout in intertive environments. Their vntge is the multiiretionl nture, wheres in ttriute grmmrs hnges re propgte only into one iretion. Vner Znen  omine onstrints with on-free (string) grmmrs. Hypergrph grmmrs re ttriute in similr wy. However, not only hypereges, whih orrespon to lphet symols in string grmmrs, rry ttriutes, ut lso noes. Sine ny numer of hypereges n e onnete to noe, noe ttriutes re ommon ttriutes for ll hypereges visiting this noe. With using hypergrphs only few onstrints re neee ompre to . Furthermore, onstrints n e liner inequlities in DiGen. Equtions etermine reltions etween ttriute vlues in efinite wy, wheres inequlity onstrints permit whole rnge of vlues s solutions. This is onvenient wy to omine utomti lyout of igrms provie y the system with user-efine moifitions. Detils on lyout n the inrementl lgorithm for onstrint stisftion uilt into our genertor n e foun in . The onstrints for lyout of NSDs re shown in Fig. 4. Every noe n hs ttriutes x n y for the noe s position. They re referre to y n:x n n:y. The only ege ttriutes re.h,.w, on.h, non.w for the miniml height n with of loks resp. onitions. The smll numer of onstrints shown in Fig. 4 is suffiient for lyout ue to noe ttriutes, whih re shre mong ll visiting hypereges. 4 Diret Mnipultion The min feture onerning user intertion is tht igrm n e moifie very onveniently in iret mnipultion style y just moving igrm elements roun on the sreen. This is not the se for other systems like PAGG or Constrints [6, 7], in whih eiting opertions hve to e hosen from menu. In igrm eitor generte with DiGen the intertion moule (see Fig. 3) is responsile for the retion on user s tions with mouse NSD P 1 P 3 P 6 Con P 3 Figure 5: Prt of the erivtion for the hypergrph in Fig. 2 using the proutions from Fig. 4. n keyor. They n, e.g., use lyout hnges, seletion of igrm elements, or trnsformtions of the igrm s struture. Lyout hnges hve een isusse in . Seletion of igrm elements is possile in ifferent wys n prt of the speifition. In our NSD eitor, e.g., susequent selete sttements (whih my e omplex) re utomtilly omine into single entity lle group, see Fig. 1 n . Trnsformtions will e presente in setion 5. Our NSD eitor serves for emonstrting iret mnipultion. As n exmple, we wnt to remove the group in Fig. 1 from its position n insert it into the upper NSD s the first sttements of the while. Fig. 6 shows the result. The only wy to hieve this in other systems like [6, 7] is solely se on seletion n pressing uttons or hoosing menu items in the following style: 1. Press the Cut-utton 2. Selet the line immeitely elow the while sonition to inite the estintion 3. Press the Insert-utton The onept is the sme s in the Synthesizer Genertor  for syntx-irete eiting. It is suffiient there, ut for igrms more nturl wy of eiting is esirle. With DiGen igrm eitors offering true iret mnipultion n e speifie using event utomt, see Fig. 3 n . E.g., the moifition from Fig. 1 to Fig. 6 n e me y simply pressing the mouse utton while the mouse pointer is lote over the selete group, rgging this group to its estintion,
5 s: t: l:line l:line s: t: line Figure 7: Smple trnsformtion rule in the NSD eitor for inserting t t line l. For pplying this rule the lhs hs to mth the igrm s urrent struture. The rhs esries the moifition. Corresponing sutrees of the lhs n rhs re emphsize the sme wy. This enles more powerful trnsformtions n reusge of primitives. E.g., mny trnsformtions in the NSD eitor re se on primitives for eleting or inserting sequene of (ompoun) sttements. Figure 6: Sitution fter moving the group selete in Fig. 1 to the eginning of the while. n relesing the mouse utton over the line elow the while s onition. In the sme wy ny prt of igrm n e remove n inserte t ny other spot. A igrm prt n lso e me new NSD of its own, or n entire NSD n e inserte into nother igrm in similr fshion. A numer of other eiting opertions y iret mnipultion hve een speifie for the NSD eitor: The then-nelse-rnh ofn if n eswithey pressing the mouse utton over the if s tringle with y insie, rgging it to the right, n relesing it over the orresponing n (or the other wy roun). A while n e hnge into n until y moving the while s onition own to the en of the while n relesing the mouse utton there. Similrly, n until n e moifie into while. 5 Trnsformtions Digrm moifitions initite y iret mnipultion re esrie y trnsformtions: trnsformtion is trnsition from set of igrms to nother set of igrms. The struture of one or more igrms n e hnge, ut the user of igrm eitor only sees vli igrms, i.e., igrms elonging to the speifie igrm lss. In ontrst to , trnsformtions in DiGen n e omplex n onsist of severl primitive steps. An exmple of simple trnsformtion rule in the NSD eitor is given in Fig. 7. Trnsformtion rules esrie the moifition of the erivtion whih stns ehin eh igrm eing isplye on the sreen. In these rules erivtion (like tht in Fig. 5) is written s tree. A trnsformtion onsists of sequene of rules. The user of igrm eitor inites the trnsformtion n its lotion y iret mnipultion using mouse n keyor. The user woul inite t n line l where t hs to e inserte in the ove exmple. The system tries to pply the trnsformtion y mthing the left hn sies of the trnsformtion s rules in the sequene given. The first mthing lhs etermines the moifition to e me. Different rules in trnsformtion tke re of ifferent ons of the positions inite y the user (here t n line l). In the urrent implementtion the progrmmer of igrm eitor, i.e., the user of our genertor, hs to mke sure tht trnsformtions, whih re prt of n eitor speifition, ontin ll relevnt rules. If the progrmmer fils to provie omplete set of rules, this only mens tht for ertin ons trnsformtion oes not use ny hnge. An nlysis uring prsing the speifition woul e helpful to prevent suh pitflls. Trnsformtion rules s illustrte in Fig. 7 re suffiient for tree struture igrms like NSDs. For other igrm lsses, e.g., finite stte mhines, onfree hypergrph grmmr (see Fig. 4) is too wek. In suh ses on-sensitive proutions resp. trnsformtions re neee. They ritrry grph omponents to the hypergrph erive from the grmmr s strting grph. The on-sensitive trnsformtions re not llowe to elete sugrphs n therefore nnot istur the erivtion of hypergrphs in the hypergrph grmmr. Their priniple is out the sme s for the trnsformtions esrie ove. In igrm eitors generte with DiGen trnsformtions n lso e use to speify exeution of igrms. This is possile if
6 Figure 8: Snpshot of n FSM eitor session. te 1 is the initil n lso finl stte. The initil stte is mrke y thik orer line, finl sttes y oule orer line. Figure 10: Sitution rising from Fig. 9 fter pressing utton ep one. Figure 9: The FSM eitor session of Fig. 8 fter pressing utton rt. The urrent stte is set to the initil stte, whih is inite y the ft orer line. exeuting igrm, i.e., semntilly evluting igrm, n e synttilly represente, n ll the igrms rete uring the exeution re memers of the igrm lss. For n intuitive illustrtion we use our smple eitor for finite stte mhines (FSMs), see Figures Using the eitor, the user n rete n moify n FSM onsisting of sttes (irles) n trnsitions (rrows). A single stte hs to e mrke s initil stte, t lest one s terminl. But moreover, the user n exeute the eite FSM: n input string n e type in, n trnsitions n e rrie out step y step, eh onsuming one hrter of the input string. When the lst hrter is proesse n the FSM is in terminl stte, the string is onsiere epte. Exeution etils re represente n rrie out Figure 11: Termintion sitution fter proessing the lst igit of the string from Fig. 9. using trnsformtions on the erivtion grph of the urrent FSM: The remining string is represente s ontents of hyperege. Consuming the string hrter y hrter shortens the ontents. The urrent stte is inite y n itionl terminl ege ( ursor ) whih is mppe s fille irle or thik orer line on the sreen just ove the irle representing the urrent stte. epping initites trnsformtion on the erivtion grph tht looks up the first remining hrter n serhes for suitle trnsition. If more thn one trnsition fits, n ritrry one is hosen. Then the ursor is move to the new stte, n the string s first hrter is remove. opping the FSM y either rejeting or epting
7 the string is inite y n itionl hyperege with Ok or Error. Sine eh exeution step is rrie out s trnsformtion on the erivtion grph, the user my hnge the igrm uring exeution. Lter exeution steps follow the new igrm struture. Fig. 8 shows the sitution fter onstruting n FSM n Fig. 9 the sitution fter pressing utton rt. The user ws ske to provie n input string for the FSM, n the urrent stte ws set to the initil stte. If there is suitle trnsition for the urrently first hrter in the input string, eh press on utton ep uses trnsition n removes the first hrter from the input, see Fig. 10. After repetely pressing on utton ep the FSM rehes its finl stte s in Fig. 11. Ok visulizes the FSM to hve epte the initilstring. 6 Cse uies A prototype of DiGen hs een implemente on Spr-Worksttions using C++ n X-Winows with OSF/Motif. Currently, DiGen onsists of pproximtely 100,000 lines of oe. Three smple igrm eitors hve een speifie n generte y DiGen: n NSD eitor s shown in Figures 1 n 6, n eitor for flowhrts, Fig. 12, n n FSM eitor, see Figures From these se stuies we got the following results: Con-free hypergrph grmmrs s introue in Setion 3 n esily n ompletely esrie NSDs n flowhrts. However, FSMs nnot e expresse y pure on-free hypergrph grmmr euse of their generl grph struture . We use hypergrph grmmr to speify the igrm s skeleton n, itionlly, on-sensitive trnsformtion rules to esrie the FSMs grph prts. This exmple emonstrtes tht DiGen is useful even for igrm lsses tht on-free hypergrph grmmrs nnot ompletely esrie. Of ourse, utomti lyout oes not work for those igrm prts efine y on-sensitive trnsformtion rules. But sine DiGen provies user-justle lyout, the user n rrnge the igrm mnully. Speifitions in the urrent implementtion of DiGen re files. The speifition effort n thus e mesure in lines of. Tle 1 shows the totl numers of lines neee to speify the three smple eitors n for eh of the speifition prts. Oviously, the prt onsisting of grmmr n mpping terminl eges on the sreen is the shortest one in eh speifition. The longest prt is theesription of user intertion, whih onsists of ul Figure 12: Smple session with flowhrt eitor # lines for NSD FC FSM grmmr & lyout & groups mpping on sreen grph omponents 191 trnsformtions user intertion totl Tle 1: Numer of lines neee to speify the eitors for Nssi-Shneiermnn igrms (NSD), flowhrts (FC), n finite stte mhines (FSM). representtion of event utomt, speil kin of finite stte mhines. Using grphil speifition woul reue the speifition effort y gret extent. Speifying grph omponents is short: for FSMs 191 lines re neee to esrie rrows, i.e., trnsitions, etween ritrry sttes. A grphil speifition will further reue this speifition effort. The speifitions for the NSD n flowhrt eitors re pretty muh the sme. Atully, we hve uilt the flowhrt speifition y opying the NSD speifition n minly hnging the mpping of terminl hypereges on the sreen. We oul thus emonstrte tht generting igrm eitor is simple tsk if n eitor for similr igrm lss lrey
8 exists. 7 Conlusions DiGen genertes igrm eitors with iret mnipultion opertions from speifition. A igrm lss is speifie y hypergrph grmmr, whih is esp. useful for esriing multiimensionl reltionships etween igrm elements. Lyout is efine on high level y onstrints. Complex eiting opertions n even exeution of igrm n e speifie. A igrm eite y the user is lwys in onsistent stte, whih is hypergrph in the forml moel. This hypergrph n e use y other prts of the pplition; however, this ws not one yet. Three se stuies showe tht even using forml moel for esriing the igrm lss n utomtilly generting the eitor oes not leve the progrmmer without work: in our exmples, eh speifition onsists of some 2,000 lines of % of the speifition is neee to esrie trnsformtions n user intertion. Future work will reue this perentge: A file s use so fr is not the est hoie for esriing user intertion n trnsformtions. A grphil representtion will mke speifitions shorter n lerer. We wnt to hypergrph prsing lgorithm to DiGen, i.e., n lgorithm tht reonstruts the erivtion struture from hypergrph. Furthermore, DiGen will hve rwing progrm omponent. Then, the user n simply rw igrms y ritrrily omining igrm prts extrte from the speifition. Drwing will e n eitor s efult ehvior when trnsformtions n intertions hve not een speifie, n it will e the prsing lgorithm s tsk to fin the igrms erivtion struture in orer to ientify orret igrms resp. igrm prts. As onsequene, trnsformtions n intertion esriptions my e omitte for rpi prototyping purposes. Speifitions will shrink to 5 20% of the urrent length (see Tle 1), n very rpi prototyping will thus e possile. Of ourse, the user my rw inorret igrms n hs thus less eiting support thn esrie in Setion 4. But sine the prsing lgorithm will point out inorret igrms n igrm prts, this my e permissile for rpi prototyping. Referenes  A. Morse n G. Reynols, Overoming urrent growth limits in UI evelopment, Communitions of the ACM, vol. 36, pp , Apr  I. Nssi n B. Shneiermn, Flowhrt tehniques for struture progrmming, ACM SIGPLAN Noties, vol. 8, pp , Aug  A.A. Khwj n J.E. Urn, Apttion n moifition of Nssi-Shneiermn hrts to represent Desrtes speifitions visully, in 1992 Interntionl Workshop on Rpi Prototyping, Reserh Tringle Prk, NC, June 1992, pp IEEE Computer Soiety Press,  B.A. Myers, D.A. Giuse, R.B. Dnnenerg, et l., Grnet - Comprehensive support for grphil, highly intertive user interfes, Computer, vol. 23, pp , Nov  F. Arefi, C.E. Hughes, n D.A. Workmn, Automtilly generting visul syntx-irete eitors, Communitions of the ACM, vol. 33, pp , Mr  H. Göttler, Grph grmmrs, new prigm for implementing visul lnguges, in N. Dershowitz, eitor, Rewriting Tehniques n Applitions, vol. 355 of Leture Notes in Computer Siene, pp Springer,  B.T. Vner Znen, Constrint grmmrs - new moel for speifying grphil pplitions, in K. Bie n C. Lewis, eitors, Pro. CHI 89,vol.20 of SIGCHI Bulletin, pp , Mr  C. Berge, Hypergrphs, North-Holln, Amsterm,  D. Hrel, tehrts: A visul formlism for omplex systems, Siene of Computer Progrmming, vol. 8, pp ,  F. Drewes n H.-J. Kreowski, A note on hyperege replement, in H. Ehrig, H.-J. Kreowski, n G. Rozenerg, eitors, Leture Notes in Computer Siene, vol. 532, pp Springer,  D.E. Knuth, Semntis of on-free lnguges, Mthemtil Systems Theory, vol. 2, pp ,  A. Borning, The progrmming lnguge spets of ThingL, onstrint-oriente simultion lortory, ACM Trnstions on Progrmming Lnguges n Systems, vol. 3, pp , Ot  M. Mins n G. Viehstet, Speifition of igrm eitors proviing lyout justment with miniml hnge, in Pro IEEE Symposium on Visul Lnguges, pp IEEE Computer Soiety Press,  Gerhr Viehstet n Mrk Mins, Intertion in relly grphil user interfes, in Pro IEEE Symposium on Visul Lnguges, pp , Los Almitos, CA, USA, Ot IEEE Computer Soiety Press.  T.W. Reps n T. Teitelum, The Synthesizer Genertor, Springer, New York, 1989.