A Translator Compiler written in python and SLY which first converts ".grv" extension files into ".py" files then runs it using inbuilt libraries (tetris.py as of now which aims to help in faster development of Customized Tetris Games). Additionally shell to run code and try out syntax. Automated Script will be provided in MAKE file. ( Note: Language is still under construction but this is sample code.) Compiler doesn't just aim to convert ".grv" to ".py" but also tries to handle both language compile errors as well as python conversion errors beforehand. Compiler creates a single output file at a time, therefore, we can not run multiple files together since there will be only one copy of output file. Same goes for shell. Future updates will allow you to specify output file name which will help you manage the output files together yourselves.
$ make install
$ make compile
Choose file to compile: filename.grv
$ make run
A completely new design for abstract tree representation of a language has been bought about. This construction helped in converting code to python code tremendeously. Main Idea is to have a linked list for each statement at a particular nesting level while maintaining the syntax of our langauge and error checks. We create a new linked list for every nesting level introduced in code as an independent Abstract Tree for that subcode within that nesting.
(Note: This will take a line and override a pre-existing file which stores shell code, then run that file to do compile time check. We recommend using this for syntax checking. After running " quit() " in shell, shell will terminate and the latest copy of code will be ran for syntax checking.
$ make shell
$ grv> console('Hello World!'); $ grv> quit()
Language follows a mix of both C and Python. We do not need any variable types and at the same time langauge follows Block structure with curly braces and semicolons. Few example files are written showing how to use loops, function declaration and our inbuilt functions defined as function_name__(..._). Language is ineffective of indentation instead uses semicolons and blocks as it's check points.
- func
- return
- if
- elif
- else
- while
- break
- continue
- console
- '... string'
Operators : +, -, *, /, >, <, >=, <=, ==, !=, &&, ||, !
# Program for finding factorial of a numnber recursively
func factorial(n) {
if(n == 1) {
return 1;
}
return n*factorial(n-1);
}
f = factorial(10);
console('Factorial of 10 is: ', f);