Simple interpreted programming language. More of a learning project.
C++ Prolog C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
plugins
qtc-gdbmacros
src
.gitignore
Colbert
Colbert.pro
Colbert.pro.user
Colbert.pro.user.1.3
Makefile
README

README

***BEST READ WITH A MONOSPACE FONT***

To use:
If you have a 64-bit openSuSE operating system (11.2 or later) you may be able to skip to step 5
  1) Open a terminal
  2) Go to this folder
  3) Run these commands:
     > make clean
     > rm ./Colbert
     > qmake
     > make
  4) Wait a few seconds and you should be set.
  5) To run the test program run:
     > ./Colbert test.clb

---

Notes about the ALPHA-STAGE interpretor:
  There is no code to handle errors, bad input will often crash or hang the program.
     My goal, so far has been ONLY to get simple programs to run. Once the language is complete
     and bug free on my test programs, I will add error handling.
     so that you can actually run the example program.
  Turing completeness has been proven via the sucessful creation of a BrainFuck interpreter. The program can be found in bf.clb.

---

The built-in functions work as follows:
+------------------+--------------------------------------+----------------------------------------------------------------------+
|     FUNCTION     |             ARGUMENTS                |                                 EFFECT                               |
+------------------+--------------------------------------+----------------------------------------------------------------------+
| func cos(r)      | r: degree in radians                 | Returns cosine of r                                                  |
| func sin(r)      | r: degree in radians                 | Returns sine of r                                                    |
| func tan(r)      | r: degree in radians                 | Returns tangent of f                                                 |
| func print(str)  | str: string to print                 | Prints str to stdout                                                 |
| func prompt(str) | str: string to prompt with           | Prints str to stdout, returns first "word" from stdin                |
| func split(@str) | str: string to split into char array | Splits str into an array of single characters. Returns an error code |
| func join(@str)  | str: char array to merge into string | Joins character array str into a single string. Returns that string  |
| func strlen(str) | str: single string to find length of | Returns the length of the single string str                          |
+------------------+--------------------------------------+----------------------------------------------------------------------+

---

Here is a detailed explanation as to how Colbert works:

1) A stream of characters, part of the program is fed into the program:
"func main()" ...

2) This stream gets converted into logical units, known as tokens:
func : FUNCTION_KEYWORD
main : IDENTIFIER
(    : OPEN_PARENTHESIS
)    : CLOSE_PARENTHESIS

3) Based off of the organization of these tokens, a tree is generated, this tree stores commands, in order,
   which are to be executed.

FUNCTION_KEYWORD IDENTIFIER OPEN_PARENTHESIS CLOSE_PARENTHESIS
...turns into...
Function IDENTIFIER
Arguments:
|--- Children ---|
    ....
|---    End   ---|

The interpretor prints out the tree, as I mentioned earlier.

4) Then, any code not inside a function is removed, save for variable declarations, and the functions themselves.

5) A scope is created, a scope is simply a list of variables, functions, and their values. The variables outside of functions that were
   not removed are added to this, the Global(all functions can "see" the variables here) Scope. You can define functions inside of other functions in Colbert.
   Additionally, all variables are arrays. The array symbols are pure syntactic sugar.

Here is a simple diagram of a scope:

-------------------------------------
| Parent: NONE (Global Scope)       |
-------------------------------------
|         Variable List             |
-------------------------------------
| VAR  | num      | 3               |
-------------------------------------
| VAR  | num2     | 5               |
-------------------------------------
|           Function List           |
-------------------------------------
| FUNC | main     | <Command List>  |
-------------------------------------

If a variable is not in the current scope or one of the parent scopes, it will be created in the most deeply nested scope. (A command line option will eventually disable this)

6) The main function is looked up, and execution begins. All functions get their own scope every time they are called,
   functions are able to modify variables of their callers, but this action can be undefined. Instead precede a function argument with '@' -- this turns the varaible into a reference.

7) If there are no errors, the interpretor runs the whole program and exits cleanly. Otherwise, since I haven't written any
   error handling code, it will crash.

Hope you can still appreciate some ALPHA software. :)

Here's the sloccount output:

Total Physical Source Lines of Code (SLOC)                = 2,491
Development Effort Estimate, Person-Years (Person-Months) = 0.52 (6.26)
 (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
Schedule Estimate, Years (Months)                         = 0.42 (5.02)
 (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
Estimated Average Number of Developers (Effort/Schedule)  = 1.25
Total Estimated Cost to Develop                           = $ 70,442
 (average salary = $56,286/year, overhead = 2.40).

(C) 2010 Alex Reinking