next up previous contents
Next: The Auxiliary Signatures Up: Signatures Previous: Signatures

The Main Signatures

The COSY signature

The signature corresponding to the Macro COSY grammar is signature COSY. It defines datatypes (concrete syntax tree) according to the Macro COSY grammar.

In order to change from use of regular expressions in the grammar, we modified the Macro COSY grammars as given in [JL92]p.459 as follows(The original Macro COSY grammars are shown in Appendix B with some corrections):

M1.    <mprogram> = "program" <mprogrambody> "endprogram"
M2.    <mprogrambody> = <mpath>
                      | <mprocess>
                      | <bodyreplicator>
                      | <collectivisor> <mprogrambody>
                      | <mprogrambody> <mpath>
                      | <mprogrambody> <mprocess>
                      | <mprogrambody> <bodyreplicator>
M2.1.  <collectivisor> = "array" <arraybody> "endarray"
M2.1.1 <arraybody> = <simpleardecl>
                   | <replardecl>
                   | <arraybody> <simpleardecl>
                   | <arraybody> <replardecl>
M2.2.  <simpleardecl> = <name1> "(" <simpleardeclbody> ")"
M2.2.1 <name1> = <name>
               | <name1> <name>
M2.2.2 <simpleardeclbody> = <iexpr>
                          | <iexpr> ":" <iexpr>
                          | <simpleardeclbody> "," <iexpr>
                          | <simpleardeclbody> "," <iexpr> ":" <iexpr>
M2.3.  <replardecl> = <range_spec> "[" <replardeclbody> "]"
M2.3.1 <replardeclbody> = <replardecl>
                        | <subsevents>
                        | <replardeclbody> <replardecl>
                        | <replardeclbody> <subsevents>
M2.4.  <subsevents> = <name1> "(" <subseventsbody> ")"
                    | <subsevents> <name1> "(" <subseventsbody> ")"

M2.4.1 <subseventsbody> = <iexpr>
                        | <subseventsbody> "," <iexpr>
M2.5.  <range_spec>
            = "#" <indexvariable> ":" <iexpr> "," <iexpr> "," <iexpr>
M2.6.  <iexpr> = <integer>
               | <rangevariable>
               | <indexvariable>
               | <iexpr> "+" <iexpr>
               | <iexpr> "*" <iexpr>
               | <iexpr> "div" <iexpr>
               | <iexpr> "**" <iexpr>
               | "(" <iexpr> ")"
M2.7.  <space> = " " (* ignored *)
M2.8.  <indexvariable> = <name>
M2.9.  <rangevariable> = <name>
M2.10. <bodyreplicator> = <range_spec> "[" <b_bodyreplicator> "]"
M2.10.1 <b_bodyreplicator> = <mpath>
                           | <mprocess>
                           | <bodyreplicator>
                           | <b_bodyreplicator> <mpath>
                           | <b_bodyreplicator> <mprocess>
                           | <b_bodyreplicator> <bodyreplicator>
M3.1.  <mpath> = "path" <msequence> "end"
M3.2.  <mprocess> = "process" <msequence> "end"
M4.    <msequence> = <morelement>
                   | <msequence> ";" <morelement>
M5.    <morelement> = <gelement>
                    | <morelement> "," <gelement>
M5.1.  <gelement> = <mstarelement>
                  | <sreplicator>
                  | <distributor>
                  | <rreplicator> <gelement>
                  | <mstarelement> <gelementL>
                  | <sreplicator> <gelementL>
                  | <distributor> <gelementL>
M5.2.  <gelementL> = <lreplicator>
                   | <lreplicator> <gelementL>
M6.    <mstarelement> = <melement> | <melement> "*"
M7.    <melement> = <mevent> | "(" <msequence> ")"
M8.    <mevent> = <name>
                | <name> "(" ")"
                | <name> "(" <meventbody> ")"
M8.1   <meventbody> = Empty
                    | <iexpr>
                    | <meventbody> ","
                    | <meventbody> "," <iexpr>
M9.    <distributor> = <sep> <dim> <range> "[" <msequence> "]"
                     | <sep> <dim> "[" <msequence> "]"
                     | <sep> <range> "[" <msequence> "]"
                     | <sep> "[" <msequence> "]"
M9.1.  <sep> = "," | ";"
M9.2.  <dim> = <iexpr>
M9.3.  <range> = "#" <iexpr> "," <iexpr> "," <iexpr>
M10.   <sreplicator> = <range_spec> "[" <concseq> "]"
                     | <range_spec> "[" <imbrseq> "]"
M11.   <concseq> = <msequence> <sep> "@"
M12.   imbrseq = <msequence> <sep> "@" <sep> "@" <sep> <msequence>
 | <msequence> <sep> "@" <sep> <msequence> <sep> "@" <sep> <msequence>
 | "(" "@" "@" <sep> <msequence> ")"
 | "(" "@" "@" <sep> <msequence> ")" "*"
 | "(" "@" <msequence> <sep> "@" <sep> <msequence> ")"
 | "(" "@" <msequence> <sep> "@" <sep> <msequence> ")" "*"
 | "(" <msequence> <sep> "@" "@" ")"
 | "(" <msequence> <sep> "@" "@" ")" "*"
 | "(" <msequence> <sep> "@" <sep> <msequence> "@" ")"
 | "(" <msequence> <sep> "@" <sep> <msequence> "@" ")" "*"
 | "(" "@" <msequence> "@" ")"
 | "(" "@" <msequence> "@" ")" "*"
 | "(" <imbrseq> ")"
 | "(" <imbrseq> ")" "*"
 | "(" <msequence> <sep> <imbrseq> ")"
 | "(" <msequence> <sep> <imbrseq> ")" "*"
 | "(" <imbrseq> <sep> <msequence> ")"
 | "(" <imbrseq> <sep> <msequence> ")" "*"
 | "(" <msequence> <sep> <imbrseq> <sep> <msequence> ")"
 | "(" <msequence> <sep> <imbrseq> <sep> <msequence> ")" "*"
 | <msequence> <sep> <imbrseq>
 | <imbrseq> <sep> <msequence>
M13.   <lreplicator> = <range_spec> "[" <sep> "|" <concseq> "]"
                     | <range_spec> "[" <sep> "|" <imbrseq> "]"
M14.   <rreplicator> = <range_spec> "[" <concseq> "|" <sep> "]"
                     | <range_spec> "[" <imbrseq> "|" <sep> "]"
M15.   <integer> = <digit>
                 | "+" <digit>
                 | <integer> <digit>
M16: <name> = <letter>
            | <name> <letter>
            | <name> <digit>
M17: <letter> = "a"|"b"|"c"|"d"|"e"|"f"|"g"|"h"|"i"|"j"|"k"|"l"|"m"
              | "n"|"o"|"p"|"q"|"r"|"s"|"t"|"u"|"v"|"v"|"x"|"y"|"z"
              | "A"|"B"|"C"|"D"|"E"|"F"|"G"|"H"|"I"|"J"|"K"|"L"|"M"
              | "N"|"O"|"P"|"Q"|"R"|"S"|"T"|"U"|"V"|"W"|"X"|"Y"|"Z"
M18: <digit> = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"

According to the grammar as given above, we define a signature COSY which uses a concrete datatype to represent the grammar:

signature COSY =
  sig
    datatype mprogram = Program of mprogrambody
    and      mprogrambody = Programbody1 of mpath
                    | Programbody2 of mprocess
                    | Programbody3 of bodyreplicator
                    | Programbody4 of collectivisor * mprogrambody
                    | Programbody5 of mpath * mprogrambody
                    | Programbody6 of mprocess * mprogrambody
                    | Programbody7 of bodyreplicator * mprogrambody
    and      collectivisor = Array of arraybody
    and      arraybody = Arraybody1 of simpleardecl
                       | Arraybody2 of replardecl
                       | Arraybody3 of simpleardecl * arraybody
                       | Arraybody4 of replardecl * arraybody
    and simpleardecl = Simpleardecl of name1 * simpleardeclbody
    and name1 = Name1 of name
              | Morename of name * name1
    and simpleardeclbody = Simpleardeclbody1 of iexpr
            | Simpleardeclbody2 of iexpr * iexpr
            | Simpleardeclbody3 of iexpr * simpleardeclbody
            | Simpleardeclbody4 of iexpr * iexpr * simpleardeclbody
    and replardecl = Replardecl of range_spec * replardeclbody
    and replardeclbody = Replardeclbody1 of replardecl
                    | Replardeclbody2 of subsevents
                    | Replardeclbody3 of replardecl * replardeclbody
                    | Replardeclbody4 of subsevents * replardeclbody
    and subsevents = Subsevents1 of name1 * subseventsbody
                | Subsevents2 of name1 * subseventsbody * subsevents
    and subseventsbody = Subseventsbody1 of iexpr
                       | Subseventsbody2 of iexpr * subseventsbody
    and range_spec 
           = Range_spec of indexvariable * iexpr * iexpr * iexpr
    and iexpr = Iexpr1 of integer
              | Iexpr2 of rangevariable
              | Iexpr3 of indexvariable
              | Plus of iexpr * iexpr
              | Mult of iexpr * iexpr
              | Div of iexpr * iexpr
              | Pow of iexpr * iexpr
              | Iexpr4 of iexpr
    and indexvariable = Indexvariable of name
    and rangevariable = Rangevariable of name
    and bodyreplicator 
          = Bodyreplicator of range_spec * b_bodyreplicator
    and b_bodyreplicator = BBodyreplicator1 of mpath
           | BBodyreplicator2 of mprocess
           | BBodyreplicator3 of bodyreplicator
           | BBodyreplicator4 of mpath * b_bodyreplicator
           | BBodyreplicator5 of mprocess * b_bodyreplicator
           | BBodyreplicator6 of bodyreplicator * b_bodyreplicator
    and mpath = Path of msequence
    and mprocess = Process of msequence
    and msequence = Sequence1 of morelement
                  | Sequence2 of morelement * msequence
    and morelement = Orelement1 of gelement
                   | Orelement2 of gelement * morelement
    and gelement = Gelement1 of mstarelement
                 | Gelement2 of sreplicator
                 | Gelement3 of distributor
                 | Gelement4 of rreplicator * gelement
                 | Gelement5 of mstarelement * gelementL
                 | Gelement5_1 of sreplicator * gelementL
                 | Gelement5_2 of distributor * gelementL
    and gelementL = GelementL1 of lreplicator
                  | GelementL2 of lreplicator * gelementL
    and mstarelement = Nostar of melement
                     | Star of melement
    and melement = Element of mevent
                 | Group of msequence
    and mevent = Event1 of name
               | Event2 of name
               | Event3 of name * meventbody
    and meventbody = Empty
                   | Meventbody1 of iexpr
                   | Meventbody2 of meventbody
                   | Meventbody3 of iexpr * meventbody
                   | Meventbody4 of iexpr
    and distributor = Distributor1 of sep * dim * range * msequence
                    | Distributor2 of sep * dim * msequence
                    | Distributor3 of sep * range * msequence
                    | Distributor4 of sep * msequence
    and sep = Comma of string
            | Simicol of string
    and dim = Dim of iexpr
    and range = Range of iexpr * iexpr * iexpr
    and sreplicator = Sreplicator1 of range_spec * concseq
                    | Sreplicator2 of range_spec * imbrseq
    and concseq = Concseq of msequence * sep
    and imbrseq 
        = Imbrseq1 of msequence * sep * sep * sep * msequence
        | Imbrseq2 of msequence * sep *
                      sep * msequence * sep * sep * msequence
        | Imbrseq3 of sep * msequence
        | Imbrseq3s of sep * msequence
        | Imbrseq4 of msequence * sep * sep * msequence
        | Imbrseq4s of msequence * sep * sep * msequence
        | Imbrseq5 of msequence * sep
        | Imbrseq5s of msequence * sep
        | Imbrseq6 of msequence * sep * sep * msequence
        | Imbrseq6s of msequence * sep * sep * msequence
        | Imbrseq7 of msequence
        | Imbrseq7s of msequence
        | Imbrseq8 of imbrseq
        | Imbrseq8s of imbrseq
        (*| Imbrseq9 of msequence * sep * imbrseq
        | Imbrseq9s of msequence * sep * imbrseq
        | Imbrseq10 of imbrseq * sep * msequence
        | Imbrseq10s of imbrseq * sep * msequence
        | Imbrseq11 of msequence * sep * imbrseq * sep * msequence
        | Imbrseq11s of msequence * sep * imbrseq * sep * msequence
        | Imbrseq12 of msequence * sep * imbrseq
        | Imbrseq13 of imbrseq * sep * msequence*)
    and lreplicator = Lreplicator1 of range_spec * sep * concseq
                    | Lreplicator2 of range_spec * sep * imbrseq
    and rreplicator = Rreplicator1 of range_spec * concseq * sep
                    | Rreplicator2 of range_spec * imbrseq * sep
    and integer = Integer of int
    and name = Name of string;
  end

Note:
According to a lot of testing we did, we found that the constructors of the datatype imbrseq from Imbrseq9 to Imbrseq13 which are corresponding to the grammar given as above are redundant. So, we commented them out in order to benefit readers to check whether they are really redundant. We also commented the corresponding parts of the programs which deal with these commented of the concrete datatype imbrseq.

The Parser Signature

The second main signature is PARSER:

     signature PARSER =
       sig
         structure CSY: COSY
         structure LX : LEX
         structure PRSR_BLDR: PARSER_BUILDER
         val m_parser : LX.token list
              -> (CSY.mprogram * LX.token list) PRSR_BLDR.possible
       end

From the signature PARSER we can see that the function m_parser reads a token list and produces a datatype possible with mprogram and a token list. Here mprogram is a syntax tree of the Macro COSY program. We will explain the datatype possible later.

The Context-Sensitive Restrictions Signature

The third main signature is CSR:

     signature CSR =
       sig
         structure CSY: COSY
         type Arraytable
         type bound
         type unbound
         val err_cnt : int ref
         val mktbl
           : CSY.mprogram
            -> {dim:int, name:string,
            value:{lower:int,pos:int,step:int,upper:int} list} list
         val crest1 : CSY.mprogram -> bool
         val crest2 : CSY.mprogram -> bool
         val crest3 : CSY.mprogram -> bool
         val irest1 : CSY.mprogram -> bool
         val irest2 : CSY.mprogram -> bool
         val brrest : CSY.mprogram -> bool
         val rrest11 : CSY.mprogram -> bool
         val rrest12 : CSY.mprogram -> bool
         val rrest13 : CSY.mprogram -> bool
         val rrest2 : CSY.mprogram -> bool
         val drest1 : CSY.mprogram -> bool
         val drest21 : CSY.mprogram -> bool
         val drest22 : CSY.mprogram -> bool
         val drest3 : CSY.mprogram -> bool
         val drest4 : CSY.mprogram -> bool
         val drest5152 : CSY.mprogram -> bool
       end

The function mktbl inside the signature body is to make a table for storing all information about arrays. It reads the syntax tree and produces an array table. The rest of the functions crest1, crest2,...,drest4 and drest5152, as their names indicate, check whether the syntax tree satisfies these context-sensitive restrictions. They input a syntax tree and return a boolean value.

The Expander Signature

The last main signature is EXPAND:

     signature EXPAND =
       sig
         structure CSY: COSY
         val expand : CSY.mprogram -> string
       end

In this signature, we define a function called expand. As its name indicates that it expands the Macro COSY program which represents as a syntax tree into a string which is in the form of a Basic COSY program.


next up previous contents
Next: The Auxiliary Signatures Up: Signatures Previous: Signatures

Peter Lauer
Mon Jul 22 17:29:46 EDT 1996