types: void int float char text list array proc var proc, text, list and array<> are handled via pointer LITERAL: +123 -123.45e6 'a' "abc" general instruction: NAME ... ";" NAME ... "{" ... "}" "{" ... "}" NAME: [ letter | "_" ] [ letter | "_" | digit ]? SYMBOL: NAME NAME "." NAME // in scope or class TYPE: void int byte var cstr char bool float int8 int16 int32 int64 uint8 uint16 uint32 uint64 TYPE "[" ["," ...] "]" // array TYPE "[" "*" ["," ...] "]" // range TYPE ( TYPES ) // procedure TYPE & // LVALUE, '&' must be last SYMBOL // user defined name ASSIGNMENT_OPERATOR: = += -= ... -> := // initializer (ignores constness) OPERATOR: ASSIGNMENT_OPERATOR + - * / \ & ^ | << >> == > < >= <= != && || ? : . to is isa PREFIX: + - ~ ! ++ -- POSTFIX: ++ -- LVALUE: SYMBOL // variable VALUE ( VALUES ) // procedure call, must return a lvalue VALUE [ VALUES ] // array VALUE: SYMBOL // var or const VALUE OPERATOR VALUE VALUE ( VALUES ) // procedure call VALUE [ VALUES ] // array element VALUE "[" [VALUE] to [VALUE] ["," VALUES] "]" // range of array elements VALUE "[" "*" ["," VALUES] "]" // range of all array elements PREFIX VALUE VALUE POSTFIX LITERAL ( VALUE ) // brackets { NAMED_VALUES } // list literal [ VALUES ] // array literal ( TYPE ) VALUE // cast LVALUE is LVALUE // test for identity (not equality) VALUE isa TYPE // type test for var, array and object VALUE . NAME // data member or member function or data/proc in named scope SYMBOL ( VALUES ) // procedure call RANGE // only in temporaries RANGE: VALUE "[" [VALUE] to [VALUE] "]" NAMED_VALUES: [ [ NAME "=" ] VALUE ] [ "," ... ] INSTRUCTION: SYMBOL [ "++" | "--" ] ";" NAME : INSTRUCTION // label ASSIGNMENT LVALUE ASSIGNMENT_OPERATOR VALUE ; PROCEDURE_CALL SYMBOL ( VALUES ) ; BLOCK_INSTRUCTION INSTRUCTION { INSTRUCTIONS } scope NAME { INSTRUCTIONS } FLOW_CONTROL if ( VALUE ) BLOCK_INSTR [ elif ( VALUE ) BLOCK_INSTR ] [ ... ] [ else BLOCK_INSTR] if ( TYPE NAME = VALUE ) ... do BLOCK_INSTRUCTION try BLOCK_INSTRUCTION catch ( TYPE NAME ) BLOCK_INSTRUCTION throw VALUE ; for ( VALUE ; VALUE ; VALUE ) BLOCK_INSTRUCTION for ( TYPE NAME = VALUE ; VALUE ; VALUE ) ... for ( NAME in RANGE ) BLOCK_INSTRUCTION switch ( VALUE ) { [ VARDEFS ] VALUE : INSTRUCTIONS [ ... ] default : INSTRUCTIONS } switch ( TYPE NAME = VALUE ) ... return [ value ] ; next [ LABEL ] ; while VALUE ; until VALUE ; break [ LABEL ] ; goto LABEL ; assert VALUE ["," STRING_VALUE ] ; DEFINITION: Alias: alias NAME = SYMBOL // alias for any defined symbol alias NAME = TYPE TYPEDEF enum NAME ; enum NAME = TYPE ; enum NAME { ENUMDEF_ARGS } enum NAME = TYPE { ENUMDEF_ARGS } enum NAME += { ENUMDEF_ARGS } class NAME = { TYPEDEF CONSTDEF VARDEF PROCDEF ... } class NAME = SYMBOL + { TYPEDEF CONSTDEF VARDEF PROCDEF ... } class NAME += { TYPEDEF CONSTDEF VARDEF PROCDEF ... } CONSTDEF const TYPE NAME "=" VALUE [ "," ... ] ";" const NAME "=" VALUE [ "," ... ] ";" VARDEF TYPE NAME [ "=" VALUE ] [ "," ... ] ";" PROCDEF TYPE NAME ( PROCDEF_ARGS ) BLOCK_INSTRUCTION TYPE operator OPERATOR ( PROCDEF_ARGS ) BLOCK_INSTRUCTION ENUMDEF_ARGS: NAME [ "=" VALUE ] [ "," ... ] PROCDEF_ARGS: [ TYPE NAME ] [ "," ... ] Types and Default Types ======================= int8, uint8 if available int16, uint16 int32, uint32 int64, uint64 if available float32 if available float64 if available byte = uint8 on most systems int, uint = pointer size. preferred size. float = float64 if available bool char cstr variadic array enum class proc range (tuple?) mutable Operators and Automatic Type Promotion of Numeric Types ------------------------------------------------------- Built-in arithmetic, logic, comparison and assignment operators for numeric (integer and float) types. Built-in Operators for Numeric Types cannot be overriden. Arithmetic: - Built-in arithmetic operators for INT/UINT, LONG/ULONG (if different) and FLOAT. Automatic operand casting: - Small integer operands are propagated to U/INT before operation. - U/INT is propagated to U/LONG if the other operand is U/LONG. - U/INT/LONG is propagated to FLOAT if the other operand is FLOAT. - If one operand is SIGNED (INT/LONG), then the result is SIGNED. - ENUMs are stripped (cast to their base type), but the program may define overloaded operators. operator + - * / as above % >> << result type = LHS monadic + - result is SIGNED monadic ++ -- operand must be mutable. ENUM preserved. result type = operand type. Logic: - Built-in logic operators for all integer sizes, ENUMs and FLOAT(?). Operand casting: - Small integers are *NOT* propagated to U/INT before operation. - Smaller integer operand is cast to the larger operand if size differs. - TODO(?) U/INT/LONG is propagated to FLOAT if the other operand is FLOAT. - If one operand is SIGNED (INT/LONG), then the result is SIGNED. - ENUMs are not stripped if both operands are of the same ENUM type. Else, unless a matching operator is defined, they are stripped, and mating too different ENUMs is not allowed. operator & | ^ as above monadic ~ as above Assignment: - Assignment operators are all built-in. - Modifying assignment operators are defined for diadic operator where the LHS and result have the same type. Behavior is same as LHS = LHS × RHS. - Default modifying assignment operators are defined that way for all other types, but they may be overrided. - LHS must be mutable - RHS is cast to LHS - Returns no value. (optionally LHS) operator = pure assignment operator += -= *= /= %= operator &= |= ^= operator <<= >>= operator &&= ||= Comparison: - Comparison is done correctly for all type combinations. - Result type is BOOL. operator == != > >= < <= Boolean: - Operands are cast to BOOL. - Return type is BOOL. monadic ! !! operator is isnot RHS is a type operator && || pruning Others: operator :? operator () operator []