The Friday Programming Language 1. Simple data types: num: represents whole numbers; floating-point numbers are not supported str: represents non-numeric data 2. Structured types: static (fixed-size) arrays of type num or str can be declared Friday has no other aggregate type Pointers and Files are not supported 3. Literal values: any whole number (positive or negative) is a literal value of type num; the range of values is –32768 .. 32767 a str literal value is represented by 0 or more characters enclosed between # characters; for example, the string "hello" is represented as #hello# 4. Identifiers Friday identifiers consist of from one to ten alphabetic characters; no other characters are allowed. Friday is not case-sensitive. Keywords (such as PUSH, PULL, AND, OR, NOT, MOD, RET and mixed or lowercase versions of these) may not be used as identifiers. Friday identifiers within the same program must be unique; the scope of an identifier extends from declaration until the end of the program. 5. General syntax All statements end with a period(.) Program blocks begin and end with a backslash character (\) All statements must appear within program blocks. 6. Statement types: Data declaration: there are only variables, no constants o Syntax: identifier : data type. o Examples: xyz : num. abc : str. o Arrays are declared as follows: identifier : data type (n). where: n is a literal value of type num, indicating the array size an array is indexed from 0 to n-1 Example: strings : str(5). Assignment o Syntax: identifier << expression. o Examples: xyz << 92. abc << #wish you were here#. Computer Organization & Assembly Language Programming Sheller Friday - flash Spring 2007 Page 1 Array access o Syntax: identifier(n) where n is an expression of type num o Example: str(0) << #wubba wubba#. Comments begin with the @ symbol; comments cannot exceed a single line (80 characters) in length, including the symbol, and must appear on lines by themselves; example: @ This program brought to you by Friday Output o Syntax: PUSH arg1, arg2, … , argN; o The keyword CRLF indicates an end of line character o Examples: PUSH #The number is #, xyz, CRLF. PUSH #Enter a new value: # PUSH str(0), CRLF. Input o Syntax: PULL variable. o Only one value can be read at a time; the variable must be declared prior to its use o Examples: PULL xyz. PULL abc. Arithmetic expressions o Friday uses infix (traditional) notation for binary arithmetic operators; all arithmetic operations use num operands and produce num results o The following operators are supported (in order of precedence): unary negation: exponentiation: ^ multiplication: * division: / modulus: MOD addition: + o Subtraction is not directly supported; however, addition of negative num values accomplishes this task o Arithmetic expressions may be grouped using square brackets ([]), which may be nested. Where brackets are used, the innermost, leftmost expression is evaluated first. o Examples: 4 ^ 2 MOD [5 + 1] evaluates to 4 4 ^ [2 MOD 5 + 1] evaluates to 64 4 ^ [2 MOD 5] + 1 evaluates to 17 4 ^ 2 MOD 5 + 1 evaluates to 2 4 ^ [2 MOD [5 + 1]] evaluates to 16 [4 ^ 2] MOD [5 + 1] evaluates to 4 Computer Organization & Assembly Language Programming Sheller Friday - flash Spring 2007 Page 2 Relational and logical expressions evaluate to 0 (false) or 1 (true) o Friday uses the following relational operations: equals: = greater than: > less than: < o For other relational operations (not equal, greater than or equal, less than or equal), use the operators above in combination with logical operators (listed in order of precedence): NOT: logical not (unary) AND: logical and OR: logical or o Binary relational expressions are formed in a manner similar to binary arithmetic expressions, with the same grouping notation and rules o Examples: NOT 0 (evaluates to 1) NOT 1 (evaluates to 0) [5 > 2] AND NOT 0 (evaluates to 1) Function calls o A previously-declared function (see section 8, below) may be called from within any program block following its definition. o Syntax: Identifier arg1, arg2, … argN. 7. Control structures: Friday supports only one type of control structure, the if / else structure. The syntax is: if expression \ statement(s). \ else \ statement(s). \ where: expression is any kind of expression (relational or arithmetic) that evaluates to 1 or 0; statement(s) can be 0 or more statements of any type, including nested structures; both if and else clauses must always be present, as must the block markers, but either or both blocks may be empty There is no looping construct in Friday. Program repetition is accomplished via recursion 8. Program modules: All Friday subprograms are functions; that is, they are value-returning methods. Each subprogram must be defined before it can be called; mutual recursion is not allowed. Each function begins with a heading, immediately followed by a block of statements representing the body of the function. Computer Organization & Assembly Language Programming Sheller Friday - flash Spring 2007 Page 3 9. Function heading syntax: type identifier | parameters | where: “type” is either num or str “identifier is a valid Friday identifier not previously used parameters are listed in the same manner as variable declarations, separated by commas as necessary the list markers: || must be present even if the function takes no arguments The body of a function consists of a set of statements enclosed within begin and end markers (\\). A function must contain at least one statement that explicitly returns the function’s value. As soon as this statement executes, program control leaves the function and returns to the calling function. Return statement syntax: RET value. where “value” is an expression of the data type specified as the return type in the function’s heading Friday program structure: A Friday program consists of one or more functions (see section 8, above). There must be a function named driver, which must be the last function in the program. Program execution begins with the first instruction in the driver function Computer Organization & Assembly Language Programming Sheller Friday - flash Spring 2007 Page 4