https://www.reddit.com/r/ProgrammingLanguages/comments/1dxhg74/token_overloading/
id | token | meaning | example | notes |
---|---|---|---|---|
equalityOperator | = | Equality operator | if a = b | |
isOperator | = | 'is' | fun addone(x) = x + 1 | |
compileTimeInit | = | Compile-time init | static int a = 100 | Runtime assignment uses ':=' |
defaultParamValues | = | Default param values | (a, b, c = 0) | |
addition | + | Addition | a + b | Also set union, string concat, but this doesn't affect parsing |
unaryPlus | + | Unary plus | + | Same with most other arithmetic ops |
subtraction | - | Subtraction | a - b | |
negation | - | Negation | -a | |
multiplication | * | Multiply | a * b | |
reflectFunction | * | Reflect function | func F* | F will be added to function tables for app lookup |
partOfFloatConst | . | Part of float const | 12.34 | OK, not really a token by itself |
nameResolution | . | Name resolution | module.func() | |
memberSelection | . | Member selection | p.x | |
extractInfo | . | Extract info | x.len | |
defineLabel | : | Define label | lab: | |
namedArgs | : | Named args | messagebox(message:"hello") | |
printItemFormat | : | Print item format | print x:"H" | |
keywordValue | : | Keyword:value | ["age":23] | |
compactThenElse | | | Compact then/else | (cond | a | b) | First is 'then', second is 'else' |
nWaySelect | | | N-way select | (n | a, b, c, ... | z) | |
lastArrayItem | $ | Last array item | A[$] | Otherwise written A[A.len] or A[A.upb] |
addSpaceInPrint | $ | Add space in print | print $,x,y | Otherwise is a messier print " ",,x or print "",x" |
stringifyLastEnum | $ | Stringify last enum | (red, $, ...) | $ turns into "red" |
addressOf | & | Address-of | &a | |
append | & | Append | a & b | |
byReferenceParam | & | By-reference param | (a, b, &c) | |
variableEquivalence | @ | Variable equivalence | int a @ b | Share same memory |
readPrintChannel | @ | Read/print channel | print @, "hello" | |
minimum | min | Minimum | min(a, b) or a min b | also 'max' |
minimumTypeValue | min | Minimum type value | T.min or X.min | Only for integer types |
forLoopSyntax | in | For-loop syntax | for x in A do | |
testInclusion | in | Test inclusion | if a in b | |
indexingSlicing | [] | Indexing/slicing | A[i] or A[i..j] | |
bitIndexSlice | [] | Bit index/slice | A.[i] or A.[i..j] | |
setConstructor | [] | Set constructor | ['A'..'Z', 'a'..'z'] | These 2 in dynamic lang... |
dictConstructor | [] | Dict constructor | ["one":10, "two":20] | |
declareArrayType | [] | Declare array type | [N]int A | in static lang |
dictLookup | {} | Dict lookup | D{k} or D{K, default} | D[i] does something different |
anonymousFunctions | {} | Anonymous functions | addone := {x: x+1} | |
exprTermGrouping | () | Expr term grouping | (a + b) * c | |
unitGrouping | () | Unit grouping | (s1; s2; s3) | Turns multiple units into one, when only one allowed |
functionArgs | () | Function args | f(x, y, z) | Also args for special ops, eg. swap(a, b) |
typeConversion | () | Type conversion | T(x) | |
typeConstructor | () | Type constructor | Point(x, y, z) | Unless type can be inferred |
listConstructor | () | List constructor | (a, b, c) | |
compactIfThenElse | () | Compact if-then-else | (a | b | c) | |
misc | () | Misc | ... | Define bitfields; compact record definitions; ... |