Wiki

Clone wiki

inf225public / Aleksander's Project

My very own yet to be named imperative programming language

For my term project I will design and implement an imperative programming language using Visual C++.

The implementation will consist of a tokenizer, a parser and an interpreter.

Some ideas of what the language will contain/be like:

  • Syntax will be similar to that of Java/C++.
  • All variables and methods must be defined within an "object". All types are objects, including native types. This means native types may contain methods, allowing expressions such as "string s = (123).toString();"
  • Objects may be defined in any order (like Java, unlike C++).
  • Objects may overload operators and methods.
  • Native types are: int, float, char, string.
  • Lists of objects are allowed, and will be dynamic. I also want to implement a list constructor, probably C++ style.
  • A predefined "system" object will contain methods for various IO operations.
  • Pointers and references should be allowed.
  • Dynamic memory allocation, with 'new' and 'delete'.
  • No static member variables, but methods are considered static if it doesn't include any calls to member variables.
  • No public/protected/private keywords - everything is public.
  • No defined main method, instead a "program" is defined in the global scope.
  • A source file contains zero or more include statements, object definitions and/or program definitions.
  • Will support most C++ operators

An example of how the syntax will be like:

#!C++

object AnObject {
    int MemberA; // no modifiers
    int MemberB;

    // may be called staticly from AnObject 
    int StaticAddition(int a, int b) {
        return a + b;
    }

    // must be called from instance of AnObject 
    int MemberAddition() {
       return MemberA + MemberB;
    }
}

program Hello {
    if(system.args.size() == 0) { // system.args is list of string
        system.println("Must specify name!");
        exit; // terminate program
    }
    string name = system.args[0];
    system.println("Hello, " ++ name ++ "!");
}

If I should have plenty of leftover time (and motivation), I may want to work on a garbage collector, add static member variables and/or other modifiers, implementing tuples or something else.

Updated