CMS Interpreter: Documentation and Applet

Syntax

<E> ::=
<C>  |
<VAR>  |
`[' <VN> `;' <NE> `;' <VE> `]'  |
<E> `@' <E>  |
reduct `{' <NN> `}'  `|'  <E>  `|'  `{' <NN> `}'  |
freeze `{' <NN> `}'  `('  <E>  `)'  |
<E> `.' <NAME> |
eval `('  <E>  `)' 
<C> ::=
<E>
fn <VAR> `=>' <C>  |
<C>  `(' <C> `)'  |
if <C> then <C> else <C>  |
let <VAR> '=' <C> in <C>  |
<COP>  |
<UNOP> <C>  |
<C> <BINOP> <C>
<VN> ::=
[ <VAR> `->' <NAME> { `,' <VAR> `->' <NAME> } ]
<NE> ::=
[ <NAME> `->' <E> { `,' <NAME> `->' <E> } ]
<VE> ::=
[ <VAR> `->' <E> { `,' <VAR> `->' <E> } ]
<NN> ::=
[ <NAME>  [ `->' <NAME> ] { `,' <NAME>  [ `->' <NAME> ] } ]
<COP> ::=
<NUM>  | false | true
<UOP> ::=
`-'  |  `!'
<BOP> ::=
`+'  |  `-'  |  `*'  |  `/'  |  `||'  |  `&&'  |  `=='  |  `!='  |  `<'  |  `<='  |  `>'  |  `>='

Remarks

  • <VAR> and <NAME> represent non empty sequences of letters and digits starting with a letter;
  • <NUM> represents rational numbers in the usual notation;
  • [ ] means optionality;
  • { } means repetition (>= 0).
  • eval is the call-by-value effect-free version of doall of CMSdo (see Mixin Modules and Computational Effects ).

Semantics

 See A Calculus of Module Systems  (note that the syntax has been slightly changed!).

Examples

  • The factorial function
  • [  ;  Fact -> fact;  fact -> fn x => if x<=0 then 1 else x*fact(x-1)] . Fact (10)

  • A self-referential module
  • let  m=[   ; M->self ;  self -> [  ; X -> 1,  Y -> self.X+1,  Self -> self;  ]  ].M in  m.Self.Y

  • Encoding of the lambda term ((lambda x . lambda y . x 7) 11)
  • freeze

      {Arg -> Arg}
      (
         freeze
           {Arg -> Arg}
           (
               [
                x-> Arg;
                Res -> [
                              y -> Arg;
                              Res -> x;
                             ];
               ]
             @
               [ ;
                 Arg -> 7;
               ]
            ) . Res
        @
        [ ;
         Arg -> 11;
        ]
      ) . Res

  • Encoding a Counter object
  • [
      value -> Val;
      Val -> 0,
      Inc-> reduct {Val -> Val } | self | {Inc -> Inc } @ [ ; Val -> value + 1; ];
      self -> [
                    value -> Val;
                    Val -> 0,
                    Inc -> reduct {Val -> Val } | self | {Inc -> Inc } @ [ ; Val -> value + 1; ];
                   ]
    ]
     

  • Encoding the method invocation Counter.Inc.Val
  • freeze
       {Val->Val}
        (
          freeze

          {Val->Val}
          (
           [
            value -> Val;
            Val -> 0,
             Inc-> reduct {Val -> Val } | self | {Inc -> Inc } @ [ ; Val -> value + 1; ];
             self -> [
                           value -> Val;
                           Val -> 0,
                           Inc -> reduct {Val -> Val } | self | {Inc -> Inc } @ [ ; Val -> value + 1; ];
                         ]
           ]
          ) . Inc
        ) . Val



Applet