tumcms / BlueCompiler

This is a barebones compiler written with the project IFC Allignment in mind.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enter image description here Welcome to BlueCompiler!

enter image description here

This is a barebones compiler written with the project IFC Allignment in mind. The interpreter was written in C++ for the project but it has scope to be plugged in with an LLVM implementation (refer developer documentation for details). A complete list of supported tokens and the supported inbuilt functions are provided below. A example program is also included to showcase what this language can do.

Feel free to extend and modify the source code as you please but please remember to provide references to this repo.

Note: This work was done within an IDP project (http://www.cms.bgu.tum.de/publications/reports/2015_Sengupta_Amann.pdf) at the Technische Universität München at the Chair of Computational Modeling and Simulation.

Logical components

enter image description here

Language Layout

The basic programming language that the compiler understands is organised in blocks. An overview of the language that the compiler understands:

enter image description here

Programming with the Language

The compiler reads a program from the file. It currenly only understands the txt files with .txt extension. To get a better flavour of what BlueCompiler can actually do, please refer the example program for Ifc Allignment: ClothoidIFCPL.txt.

Here is a simple example program:

{

func computeX(double L,double A)
{
	x = L;
	iterations = 5;
	i = 1;
	while(i < 6) do
	{
		sign = sgnEven(i);
	
		L_exponent = 5 + (i - 1) * 4.0;

		A_exponent = i*4.0;
		Atemp = factorial(2.0*i);
		B = pow(2.0, 2.0*i);
		C = 5.0 + (i - 1) * 4;
		factor = Atemp * B * C;
	

    	D = pow(L, L_exponent);
		E = factor * pow(A, A_exponent);
		x = x + (sign * (D / E));
		i = i + 1;
	}; # while ends here

	return x;

}; # func computeX() ends here	

}; # program block ends here

Railroad Diagrams for the Grammar

The grammar is the star of the show here, so if things start getting confusing please revert to the full blown html which can be found in the repo as Grammar.html

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

List of supported tokens and inbuilt functions

Token(in Program) Internal Representation
while TOKEN_WHILE
!= , <= , >= , && , == TOKEN_OPERATOR
{ TOKEN_BEGIN
} TOKEN_END
[ BOX_OPEN
] BOX_CLOSE
func BEGIN_FUNC
do TOKEN_DO
if TOKEN_IF
else TOKEN_ELSE
vector TOKEN_VECTOR
vector2d TOKEN_VECTOR2d
return TOKEN_RETURN
pow TOKEN_POW
acos TOKEN_ACOS
sqrt TOKEN_SQRT
rotatez TOKEN_ROTATEZ
magnitude_squared TOKEN_MAGNITUDESQR
transform TOKEN_TRANSFORM
min TOKEN_MIN
dot TOKEN_DOT
cross TOKEN_CROSS
[a-zA-Z_][a-zA-Z0-9_]* TOKEN_ID
[-]?[0-9]*[.]?[0-9]+ TOKEN_NUMBER
* , /, +, -, <, >, % TOKEN_OPERATOR

The grammar in BNF form can be found in the developer documentation.

LICENSE

MIT LICENSE

About

This is a barebones compiler written with the project IFC Allignment in mind.

License:Other


Languages

Language:C++ 79.8%Language:HTML 16.0%Language:Yacc 2.2%Language:C 1.4%Language:Lex 0.6%