CS 342 Lecture -*- Outline -*- * Syntax ** lexical comments start with % no semicolons strings in "", characters with '', escapes (as in C) '\n' is newline, ... operation names have two parts (type, operation) int$from_to ** declarations *** equates introduce abbreviations into environment for types ai = array[int] for constants (wholly immutable) max_addr = 999 ops = sequence[int]$[3,4,5] *** variable declarations y: array[int] are statements in CLU can have initialization x:int := 3 ** statements no goto (but have break, continue, exit, return) *** assignment uses := can have multiple variables on lhs x,y := e1,e2 x,y := foo(c) % foo returns 2 objects may include declaration i: int := 3 *** compound all compound statements are terminated with "end", modules by "end name" if then [elseif then] ... else end while do end for in do end no case statement, can use tagcase instead (no enumeration types, use oneof or variant instead) ** Syntactic sugars (make the syntax "sweeter") *** Arithmetic operations ------------ suppose a,b: int a + b => int$add(a,b) a < b => int$lt(a,b) a = b => int$equal(a,b) -a => int$minus(a) suppose a,b: real a + b => real$add(a,b) a < b => real$lt(a,b) a = b => real$equal(a,b) -a => real$minus(a) ------------ *** Boolean operations ------------ suppose a,b: bool a & b => bool$and(a,b) a | b => bool$or(a,b) a = b => bool$equal(a,b) ~a => bool$not(a) ------------ Special primitives (not sugared operations!) on bools cand - conditional "and", like && in C cor - conditional "or", like || in C these cannot be defined as operations because CLU is call by value *** General comparisons (for most types) ------------ suppose a,b: T a = b => T$equal(a,b) a ~= b => bool$not(T$equal(a,b)) a >= b => T$ge(a,b) a > b => T$gt(a,b) a <= b => T$le(a,b) a < b => T$lt(a,b) ------------