Midren / MicroJavapp

MicroJava++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MicroJava++ 🐧

Implementation of the programming language compiler. Based on the Truffle framework. MicroJava as the base grammar for MicroJava++

forthebadge forthebadge forthebadge

forthebadge forthebadge

Table of contents

Language description

Grammar

Also known as MicroJava - Grammatik 👽

Program = "​program​" ​ident​ ​{ ​ConstDecl ​| ​VarDecl ​| ​ClassDecl ​} "​{​" ​{​MethodDecl​}​ "​}​". 

ConstDecl = "​final​" ​Type​ ​ident​ "​=​" ​( ​number ​| ​charConst ​)​ "​;​". 

VarDecl = Type​ ​ident​ ​{ ​"​,​" ​ident ​}​ "​;​". 

ClassDecl = "​class​" ​ident​ "​{​" ​{ ​VarDecl ​} ​"​}​". 

MethodDecl = ( T ​ ype ​| ​"​void​" ​)​ ​ident​ "​(​" ​[ ​FormPars ​]​ "​)​" { V ​ arDecl ​}​ ​Block​. 

FormPars = Type​ ​ident​ ​{ ​"​,​" ​Type​ ​ident ​}​. Type = ident​ ​[ ​"​[​" "​]​" ​]​. 

Block = "​{​" ​{ ​Statement ​}​ "​}​". 

Statement = Designator​ ​( ​Assignop​ ​Expr ​|​ ​ActPars​ ​| ​"​++​" ​| ​"​--​" ​)​ "​;​" 
            | "​if​" "​(​" ​Condition​ "​)​" ​Statement​ ​[ ​"​else​" ​Statement ​] 
            | "​while​" "​(​" ​Condition​ "​)​" ​Statement 
            | "​break​" "​;​" | "​continue​" "​;​" 
            | "​return​" ​[ ​Expr ​]​ "​;​" 
            | "​read​" "​(​" ​Designator​ "​)​" "​;​" 
            | "​print​" "​(​" ​Expr​ ​[ ​"​,​" ​number ​]​ "​)​" "​;​" 
            | Block 
            | "​;​". 

Assignop = "​=​" ​| ​"​+=​" ​| ​"​-=​" ​| ​"​*=​" ​| ​"​/=​" ​| ​"​%=​". 

ActPars = "​(​" ​[ ​Expr ​{ ​"​,​" ​Expr ​} ] ​"​)​". 

Condition = CondTerm​ ​{ ​"​||​" ​CondTerm ​}​. 

CondTerm = CondFact​ ​{ ​"​&&​" ​CondFact ​}​. 

CondFact = Expr​ ​Relop​ ​Expr​. Relop = "​==​" ​| ​"​!=​" ​| ​"​>​" ​| ​"​>=​" ​| ​"​<​" ​| ​"​<=​". 

Expr = [ ​"​–​" ​]​ ​Term​ ​{ ​Addop​ ​Term ​}​. Term = Factor​ ​{ ​Mulop​ ​Factor ​}​. 

Factor = Designator​ ​[ ​ActPars ​] 
         | number 
         | charConst 
         | "​new​" ​ident​ ​[ ​"​[​" ​Expr​ "​]​" ​]
         | "​(​" ​Expr​ "​)​". 
         
Designator = ident​ ​{ ​"​.​" ​ident ​| ​"​[​" ​Expr​ "​]​" ​}​.

Addop = "​+​" ​| ​"​–​". 

Mulop = "​*​" ​| ​"​/​" ​| ​"​%​". 

Extensions 💰

MicroJava++ supports additional features, not sated in the grammar:

  • Scoping (Functions` and blocks` scopes, we are very proud of this! 🙌);
  • Declaring variables inside of funtions/blocks;
  • Declaring constant variables inside the functions/blocks;
  • Constant variables can be initialized with expression, not only literal (inside of the block, global variables suport only literal initilization);
  • Supported types: Integer, Boolean, Character, Double;

Not implemented yet ⏩

  • Arrays - Nodes for arrays were implemented, but to work corectly with scoping system, there is still work to be done;
  • Classes - TBD;
  • For/Foreach - After adding arrays, to make work with them more convinient;
  • auto keyword - For type deduction;
  • Ternary operator - The functional way, is the righ way;

Team 💡

Roman Milishchuck Hermann Yavorskyi
"I am starting to like Java... LoL, I fooled you." 💥💀

About

MicroJava++


Languages

Language:Java 99.1%Language:Python 0.9%