The Structure of Programming Languages---I

Programming Languages---Course 66.443

Reading

  • Sebesta's Chapter 3.

    Syntactic Structure

    Context Free Grammars

    Parsing

    Syntactic Ambiguity

    Resolving the Syntactic Ambiguity

    Syntax Diagrams

    Handling an Exception in ML

    raju.cs.rpi.edu% sml
    Standard ML of New Jersey, Version 75, November 11, 1991
    Arrays have changed; see Release Notes
    val it = () : unit
    - exception EmptyList;
    exception EmptyList
    -  fun reduce(F,nil) = raise EmptyList
    =  | reduce(F,[a]) = a
    =  | reduce(F,x::xs) = F(x,reduce(F,xs));
    val reduce = fn : ('a * 'a -> 'a) * 'a list -> 'a
    - reduce(op +, [1,3,5]);
    val it = 9 : int
    - reduce(op +, nil);
    std_in:6.8-6.11 Error: overloaded variable "+" cannot be resolved
    - fun foo(x,y) = (x:int)+y;
    val foo = fn : int * int -> int
    - reduce(foo,[1,3,5]);
    val it = 9 : int
    - reduce(foo,nil);
    
    uncaught exception EmptyList
    - fun reduce1(F,m) = reduce(F,m) handle EmptyList => 0;
    val reduce1 = fn : (int * int -> int) * int list -> int
    - reduce1(foo,[1,3,5]);
    val it = 9 : int
    - reduce1(foo,nil);
    val it = 0 : int
    -