Skip to content

PedroBittarBarao/Custom_Language

Repository files navigation

Custom_Language

Usage

python3 Compilador/main.py Compilador/Arquivos_de_teste/teste1.bar

teste2 and teste3 have wrong type attributions and should raise errors

Example:

int x = 21
string y 
y="fish"

if x == 21 
{
	print("x=21")
} else {
	print("no")
}

while x<30 
{
	x=x+1
}

switch x (
	case 10
	{
	print("Case 1")
	}
	case 20

	{

	print("Case 2")

	}

	default 
	{
		print(y)
	}
)

EBNF

BLOCK = { STATEMENT };
STATEMENT = [ ASSIGNMENT| ("int"|"string"), IDENTIFIER, ["=",BOOL_EXP] | PRINT | WHILE | IF | SWITCH ], "\n" ;
ASSIGNMENT = IDENTIFIER, "=", BOOL_EXP;
PRINT = "print", "(", BOOL_EXP, ")" ;
WHILE = "while", BOOL_EXP,{"\n"}, "{", {"\n"}, { ( STATEMENT )}, "}";
IF = "if", BOOL_EXP,{"\n"},"{", { ( STATEMENT ) },"}", [ "else", "{" , { ( STATEMENT )},"}"] ;
SWITCH = "switch", IDENTIFIER,{"\n"},"(",{{"\n"},("case" | "default"), (NUMBER|STRING),{"\n"},"{",{"\n"},{STATEMENT},"}"}, ")";
BOOL_EXP = BOOL_TERM, { ("or"), BOOL_TERM } ;
BOOL_TERM = REL_EXP, { ("and"), REL_EXP } ;
REL_EXP = EXPRESSION, { ("==" | ">" | "<"), EXPRESSION } ;
EXPRESSION = TERM, { ("+" | "-" ), TERM } ;
TERM = FACTOR, { ("*" | "/"), FACTOR } ;
FACTOR = NUMBER | STRING |IDENTIFIER | (("+" | "-" | "not"), FACTOR ) | "(", BOOL_EXP, ")" | "read", "(", ")" ;

Syntax Diagram

DS

Generated by :https://jacquev6.github.io/DrawGrammar/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 5