Glocal - an interpreter I am making
by dweller - 2015-04-07
Hello, I just decided to share that I am currently developing my own little interpreter. I am coding it in C#, because I am most familiar with it, and feel comfortable in it.
The language itself is pretty limited at the moment. it is called Glocal, an abbreviation of “Glorified Calculator”. Since that is what it basically is at the moment.
I am coding it from scratch, with no prior experience. So everything from Lexer to Evaluation is made with no external library. Reason? Just for fun! :D
Here are the list of features it has right now:
Math Expressions
- Variables
- If-Then-Else Statement
- Times Loop
- Basic I/O with keywords (print and scan)
- Basic Types (Int, Real, Bool, String)
So I plan to also add:
- Lists/Tables
- Scopes (Currently everything is global)
- Structures
- Functions/Procedures
- Module loading (includes/using)
- DLL support
Here’s a code snippet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
; Has one line comments
; variables and basic I/O
print "Echo: "
a = scan
print a
; Just added types, so no bool operations yet :(
; Has flow control
if true then
{
; Has power operator
b = 2 ^ 10
print b
}
else
{
; And other basic math
c = 213.2 % 3.1 + (16 - 3)
print c
}
print "Enter a number: "
num = scan
i = 0
; Has a loop
times num do
{
i = i + 1
print i
}
print "What is your name?"
name = scan
print "Hello, " + name + "!"
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
D:\C#\Interpreter\Interpreter\Debug>glocal test5.gc
Echo:
echo?
echo?
1024
Enter a number:
5
1
2
3
4
5
What is your name?
Dweller
Hello, Dweller!
D:\C#\Interpreter\Interpreter\Debug>
Thanks for reading! :D