Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

132 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming language

This is test of making a programming language in C with the least amount of help from google as possible. This will be small interpreted language.

NOTE: this is my first C code. I only used C++ (as the most SIMILAR language to C).

Compiling and Running

To compile it run in the root of this repository command:

python3 ./scripts/compile.py

This automatically runs the language with params from ./scripts/CompileRunParams.txt (which is usually examples/ex[num].dio).

Documentation

Dio is procedural, statically typed that's weakly typed programming language. Working directory is generated through "-file" input, if you input "-file example/ex2.dio", DIO uses ./examples/ as it's working directory.

Origins

The name Dio comes from ancient Greek philosopher Diogenes of Sinope and his bowl story. Essentially, Diogenes saw kid drinking water from river with his hands, so he threw away his bowl (one of two things he owned). It's called Dio because it's trying to be minimalistic language (not in line count, but with how much it can do).

Types

(implemented)

  • int - basic number type, it's internally used as float
  • float - basic number type, can be used with +, -, *, /, <, >, <=, >=, ==
  • string - basic text (can only be used as output and be concatenated with "+")
  • bool

Comments

Dio only uses single line comments, >>, these can be used anywhere in the line, however everything after it will not be evaluated in any way.

Variables

>>Declaration
int a = 10;

>>use
int b = a + 1;

Booleans

All normal booleans (true, false) are here, represented by either the word "true" or "false" (this is changed in lexer to 1 and 0 respectively). Dio also has special boolean, maybe, which is either 1 or 0.

NOTE: in loops for some reason it never generates a new number making the loop behave same???

Functions

def name()
    >>code
end

def withParams(type : name, type2 : name2 ...)
    >>they can have any amount of inputs
end

>>call
name()
withParams(a, 10) >> example, use variable and 10

>>NOTE: var types are now not fully used, so function can be parsed any argument 

Control Flow

WHILE Loops

int i = 0;
while(i < 10)
    i = i + 1
    out(i)
end

>>outputs 1 -> 10

FOR Loops

for (int i = 0; i < 10; i = i + 1)
    out(i)
end

>>outputs 0 -> 9

NOTE: walrus operators are not implemented, you have to use "n = n ..."

Branching

if (condition)
>>code
elseif (condition)
>>code
else
>>code
end

Goto

>>this is without any condition

::gotoName::

>>code

goto ::gotoName::


>> goto with condition

::gotoName::

>>code

goto (condition) ::gotoName::

NOTE: if you don't use condition, it will run always

Standard Library

out

int a = 5
out(a)

Out is print function that prints out the variables or what you put into it.

middle-processor

Middle processor is kind of middle ware used to add code or change how lexing works. This is imitating (in a way*) pre-processor from C (or that's the idea behind itq*). All mid processor calls are prefixed with '#'.

get

  • Takes argument of file.
  • Adds the file into the program you're making, this is used to import to other file for multi-file support.

ISSUES (right now)

  • TODO: TEST so I can update this

NEXT

  • loading files (essentially same as I use STD by dynamically in lexer, add like file identifiers, something like "#FILE:NAME" to correctly add file in or start a new lex and add everything to it, whatever is easier)
  • Make variable types work differently and check them + make like "any" as parameter for functions or add overloading (either wold work)

About

Small programing language written in C.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages