fineLang
- 9 Devlogs
- 10 Total hours
painful top use prrogramming language witch has transpiler made in python and transpiles to C from c tomashine code
painful top use prrogramming language witch has transpiler made in python and transpiles to C from c tomashine code
Finished : automatic “INDENT” and “DEDENT”
: “IF” statement
: MAIN() function search
: Math OPERATORS
Since in suffer levels 1 and 2 are used basic symbol types “<,>” etc, i didnt bother much checking the correctnbes of the implementation.
CODE EXAMPLE (with the new stuff):
-fineLang ->
SUFFER: two
;
FUNCTION main():
let x = 5
if x > 3:
print(x)
if x > 4:
print(x)
let y = 6
if (x add y > 10):
print(“hi”)
#include <stdio.h>
int main() {
int x = 5;
if (x > 3) {
printf(“%d\n”, x);
if (x > 4) {
printf(“%d\n”, x);
int y = 6;
if (x + y > 10) {
printf(“hi\n”);
}
}
}
}
INTO THE ULTIMATE COMPILED STATE ->
5
5
hi
this was a very complicated test case, and i wouldnt lie if i said that If this fails i wouldnt be surprised
THATS IT FOR TODAY!! thanks you for your time and have a nice day :>)
Heres what majestic stuff have we done
Finelang now accepts CALCULATING OPERATORS
and CHAINED calculated operation.
lets give ourselves a representation
let x = 5 add 7 multiuply 9
let y = x subtract 67
this adequetly transforms the code to the correct math operators, and let our big dawg figure out the operations.
’
lets see for ourselves.
fineLang ->
´´´
SUFFER: two
;
FUNCTION main():
let x = 5.5 times 2
let y = x divide 6
print(x)
print(y)
return 0
´´´
into correct C
´´´
#include <stdio.h>
int main() {
float x = 5.5 * 2;
float y = x / 6;
printf(“%f\n”, x);
printf(“%f\n”, y);
return 0;
}
´´´
this was amazingly painfull to do and im glad it works :)
tomorows work is automationg codegen tabs / spaces, and being able for new code blocks
i modified our regex in tokeniser to accept numbers 0-9 with a dot inbetween and number(s) after
this gets by tokeniser recognised as pices and codegen now correctly outputs it with F in the C printf command.
The biggest problem C standartly takes 6 nuámbers after the dot so from x=5.6 you get
5.600000.
That aint a big of a deal.
Todo:
This also allows for automatic tabs in codegen instead of manual and allows implementation of someting like if/else
We got wokring avriables?
so for levels 1 and 2 you dont need to define the type of variables, we right now have
Incoming 3. ‘pieces’ for float
in the codegen i designed a list lookup where if you create a vaiable with let its type, datatype name and value can be looked up for easyprint.
parser had MAJOR fallback flaws witch i also patched.
There was one teeny beeny mess up where i had if statement that basically said if (string) “IDENTIFIER” is equal to the equal sign. :(
BUT WE KNOW FINELANG WORKS. tomorrow there comes maybe piees data type and “if” “else” statements ?
so i completed the codegen to actualy buuild the C code, and made in main.py to open a new file called output.c
Next output.c is compiled with gcc trough subprocess. if compilation succeeds we also call the binary itself, and THTS IT.
next steps are to recognise and properly save variables and then be able to print them
belive it or not, i made a working parser that works with all out keyword comands function, return,print, and let.
Function- sadly right now couts as a non ending function so it ondly recursivly calls parse fro rest of the file, but thats easy solvable issue.,
Parser now generates correct AST, witch after building Codegen can be correctly transpiled into C
heres a comparison code w/ AST
code:
SUFFER: two
;
FUNCTION main():
let x = 5
print(“hello world”)
return 0
AST:
[{‘type’: ‘function’, ‘name’: ‘main’, ‘body’: [{‘type’: ‘let’, ‘name’: ‘x’, ‘value’: 5}, {‘type’: ‘print’, ‘value’: ‘hello world’}, {‘type’: ‘return’, ‘value’: 0}]}]
as we can see theres a list (body) inside the whole list as a part od the main function. This is enough to generate correct C and run it !
since last time i also implemented errors.py witch is only a library of custom errors dataclas. the point of that is that with mopre complexity in our programming language the more feedback we need to guive to the coder to tell him “hey you did this wrong!” instead of “you fricked up” because that wouldnt be fun
in the picture we can see my terminal as a proof of the working error and parser.
someone told me theres no need for a wirtual enviroment, but its better to keep track of stuff even tho we wont be needing any more packages. BUT if we did then its good practice after compiling the compiler to have all the necesary packages already installed.
so, i implemented a error checking if string is open, and updated my tokenizer to recognise a group of words in “” aqs one big string. implemented error witch is called on unclosed strings
I have “completed” our tokenizer and validator that ensures correct “SUFFER” declaration. if we tokenize the code from our first devlog we get this
today i started to make basic “compiler|” for level 1 and 2. if you want to see how finelangs going to work there is a attached snippet and you can see for yourself the whole idea in readme of the project