|
Decaf—Java without the jitters™ | © 2008, Martin Rinehart |
|
| Why Decaf? Because beginners need a language, too. |
|
|
Decaf is strictly left-to-right except as modified by parentheses. 1 + 2 * 3 is 9, because (1 + 2) * 3 is 9. For 7, use 1 + (2 * 3). |
43 Reserved words: AND BIT BREAK BYTE CANDO CAPABILITY CHAR CLASS DEC DO E EACH ELSE EQ EXTENDS FALSE FOR GE GLOBAL GROUP GT IF IN INCLUDE INT LE LOCAL LOOP LT ME NAMELIST NE NOT OR PI RETURN RO RW SUB THEN TRUE TYPE WHILE |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Decaf is strongly typed, but types may be declared implicitly.
3 => x; "Nancy" => y . (Same as 3 => INT x; "Nancy" => [5]CHAR y).
Compile-time error: IF cond 3 => x ELSE "three" => x .
|
Arithmetic: + - * / ^ (exponentiate) % (modulo) |
Assignment: => Comparison: GE GT EQ
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data types: Every class name plus BIT, BYTE, CHAR, INT, DEC, GROUP, NAMELIST, TYPE, SUB | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Decaf is case sensitive. All decaf words are UPPERCASE. Recommend mixed case and lowercase for other words. Decaf's editor will capitalize reserved words. |
Logical: AND OR NOT IN uses short-circuit eval Bitwise: handled by BITARRAYs |
[] subscript . lib,object access , group/list separator () order specifier : integer array creator |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Numbers—BIT, BYTE, CHAR, INT, DEC, TYPE—are passed by value. All others are passed by reference. |
[100]INT x //error specify explicit start [1:100]INT x
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Decaf names are one alpha followed by zero or more alphanumeric and underscore characters. | Predefined constants: TRUE, FALSE, E, PI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Variables are single (scalar), a value or a reference to a list (1D array), to an array (2+D) or to other data structures. |
Comments "here to EOL" start "//"Block comments use multiple EOL comments Multi-line strings ''' (multiple lines) '''
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| In arrays, the rightmost subscript varies most often. A 4x3 array may be used as a 12-item list. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Each compilation unit is a block statement. LOCAL variables (default) are visible within the block in which they are declared. GLOBAL variables are visible until they go out of scope. Declaration of a second variable with an already visible name is an error. All variables go out of scope at the close of the block within which they are declared. |
INT:0 1 -4 -3E6 0xd[d]... DEC:.5 -3.E6 3E-6 50% BYTE:"x" 'x' "\xnn" []CHAR:"Don't" 'Don''t' GROUP: (1, "Fred", 0.5) NAMELIST: Sunday, Monday, ... TYPE: INT, ANGLE, ... SUB: ()ABS |
\r=return \t=tab \', \", \\ = themselves \xnn=hex nn, \xnnnn=hex char |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions (subs that return a value) may not modify global variables. Sub's signature is argument types, name and return type(s). LOCAL subs and classes are visible within their own compilation units. GLOBAL subs and classes are visible to any unit that INCLUDES the sub's compilation unit. | Decaf console (like unix shell) provides simple I/O. Learners test expressions. Ask "2+2?" and it prints "4". With program at break point, ask "foo?" and it prints "DEC = 14.7" or whatever. |
1:6 => ;
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A class's name is its type. OBJECT is the (in)direct parent of all classes. Classes have an implicit constructor of one statement: RETURN ME. Explicit constructor for class Foo: ([args]) [scope] Foo action_statement. Within the constructor, ME is a reference to the object being created. Destruction is handled automatically. Objects are created by assignment: ([args])ClassName => object_ref_name. Object data may be GLOBAL (read/write) or LOCAL (read-only). Assignment to LOCAL from outside class is a compile-time error. Use of xxx.object is a call to get_xxx.object, if coded. Assignment to xxx.object is a call to set_xxx.object, if coded.
|
"ERRORS" is a GLOBAL STACK of ERROR objects. At a programmable size (default is 2), ERRORS is written to console and program terminates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Qualified names: 'foo.bar' searched only in given class (back up inheritance chain, if needed) or module Unqualified names: 'bar' in local routine, class (if any), current module, then through includes in order included Note: this is compile time, not run time. | Everything in Decaf, including names, is a first-class object. | GUI event handling: shamelessly steal from Javascript. It's wonderfully simple. (Can a robust widget set, like wx, be covered within Javascript-equivalent syntax?) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Decaf Object Library
Partial list follows. More to do.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Decaf—Java without the jitters™ |
|