Entries for tag "regscript", ordered from most recent. Entry count: 2.
# RegScript - Bidirectional Type Inference
Sun
03
Jan 2010
Coding my RegScript programming language is no longer easy as code grows bigger, but it's still much fun. In the last days I've added support for numeric types of different size. Here is the full list: float, double, uint8, uint16, uint32 (uint), uint64, int8, int16, int32 (int), int64
.
I try to keep the syntax as close to C/C++ as possible, but at the same time I introduce some interesting details like:
object[x,y,z]
void Func(float x = sin(globalVar)) { ... }
switch (val) { case 1, 2, 3: ...
switch (val) { case someVar+1: ...
I've also implemented function overloading and many compiler errors and warnings similar to these from C++ compiler. But most interesting feature so far is what I call "Bidirectional Type Inference" :) I first introduced auto keyword to allow skipping type name and next I've made literal constants like 123 typeless so their type is deduced from the context (because I hate typing this f, u or ll postfixes everywhere in C++ code). For example:
// Left to right - these numbers are int16 int16 myShort = -32000 + 10; // Right to left - newVar is int16 auto newVar = myShort;
Comments | #c++ #compilers #regscript Share
# RegScript - my Scripting Language
Wed
30
Dec 2009
RegScript is my scripting language I've started coding yesterday. I'm not a guru in formal languages theory, but I'm quite fascinated with programming languages, parsers and interpreters. I don't know why but I felt I'd love to write my own programming language so I just started coding it, even if it doesn't make any sense. Maybe that's just because it's like being the creator of something that we, as developers, are usually only users. The language syntax is similar to C++. Here are features I've coded untill now:
-10, 0xFFFF, 0b1010, 1e-6f, false, true, 'A', "foo"
+ - * / % < ?: ! && || ~ & | ^ << >>
= += -= *= /= %= &= |= ^= <<= >>= ++ -- == != < > <= >= ( ) sizeof ,
sin, print
, intrinsic constants: PI
.
The implementation is not optimal yet as I don't generate any bytecode. I just execute statements and evaluate expressions from a tree made of polymorphic nodes dynamically allocated by parser. Sample program:
print("Hello World!\n"); for (auto i = 0; i < 10; i++) print("i = " + i + '\n');