========================================= Juliet Programming Language Specification Author....... Kevin P. Albrecht Version...... 0.20 Date......... 15 Jan 2003 ========================================= ----------- IDENTIFIERS ----------- Identifiers (variables, labels, etc.) must begin with one of the follwing characters: abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ_ The rest of the identifier can be any of the characters below: 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ_ -------- ROUTINES -------- there must be a main routine routines are not recursive rout NAME { :TYPE } CODE { return { EXP } } ------- EXITING ------- to immediately terminate the program, use the following statement exit ----- SCOPE ----- scope is defined by indentation, as in python indent example ------ ------- 0 printn "Hello, World!" 5 {hi} printn "Hello!" 5 c <- x variable names can be redefined in a deeper scope, which will hide the original definition of that variable. ----- STACK ----- push EXP pop VARIABLE --------------- FLOW OF CONTROL --------------- #(identifier) line label goto (identifier) goto the line labeled with (identifier) loop BOOLEAN_EXP BLOCK cond _boolean_exp_ _block_ -------------- FILE INCLUSION -------------- $filename.jul inserts the Juliet file immediately filename can be omitted ----------- CONSOLE I/O ----------- (items in {} are optional): print { EXP } printn { EXP } cinput a special string identifier that grabs a string out of the console -------------------- VARIABLE DEFINITIONS -------------------- Variables are automatically initialized as follows: int: 0 rat: 0.0 str: "" Variables cannot be used in the same statement they are defined in. Variables are defined as follows (items in {} are optional): def ID:TYPE { <- EXP } { , ID:TYPE { <- EXP } } { , ... } where TYPE = int, rat, or str Constants are defined as follows: const ID:TYPE <- EXP { , ID:TYPE <- EXP } ------------ TYPE CASTING ------------ int EXP rat EXP str EXP -------- COMMENTS -------- {{ single line { multiple line } -------- LITERALS -------- String: "Hello", "23.4" Integer: 23, -1000 Rational: 23.0 'nl' is a special string variable that contains the newline value Rationals can store up to 6 digits in the mantissa (to the right of the decimal point). ------------------- ASSIGNMENT OPERATOR ------------------- a <- b where a = variable b = expression --------------- LOGIC OPERATORS --------------- a = b a <> b (a=num & b=num) | (a=str & b=str) yields: rat a < b a > b a <= b a >= b a or b a and b a=num & b=num yields: rat -------------------- ARITHMETIC OPERATORS -------------------- a + b a - b a * b a / b a=num & b=num yields: if (a|b = rat) then rat else int a mod b a=int & b=int yields: int a ^ b a=num & b=int yeilds: if a=rat, then rat if a=int, then int --------------- STRING OPERATOR --------------- a & b a=str & b=str yields: str