Coder Social home page Coder Social logo

minijavac's Introduction

minijavac

A compiler for a subset of Java on ARM 32-bit. This Java subset has been around for a long time, and I've seen at least 5 different universities using this grammar (with some very small variations) for their compilers class. This compiler can compile any Java program that can be parsed by the grammar below, with the exception of programs with arrays with more than 2 dimensions. It would not be a terribly difficult upgrade to support arrays with arbitrary number of dimensions, but I have no incentive to do so.

Grammar:

 Program  : MainClass ClassDecl*
 MainClass : class id { public static void main "(" String [] id ")"
               { Statement* }}
 ClassDecl : class id (extends id)? { VarDecl* MethodDecl* }
           
   VarDecl : Type id (= Exp)? (, id (= Exp)? )* ;

MethodDecl : public? Type id "(" FormalList? ")"
               {Statement*}

FormalList : Type id (, Type id)*

 PrimeType : int
           : boolean
           : id
	   : String

      Type : PrimeType
           : Type [ ]

 Statement : VarDecl
	   : { Statement* }
           : if "(" Exp ")" Statement else Statement
           : while "(" Exp ")" Statement
           : System.out.println "(" Exp ")" ;
           : System.out.print "(" Exp ")" ;
           : LeftValue = Exp ;
	   : return Exp ;
	   : MethodCall ;

MethodCall : LeftValue "(" ExpList? ")" 

       Exp : Exp op Exp
           : ! Exp
           : + Exp       
           : - Exp
           : "(" Exp ")"
	   : LeftValue
           : LeftValue . length
           : INTEGER_LITERAL
	   : STRING_LITERAL
           : true
           : false
           : MethodCall
	   : new id "(" ")"
	   : new PrimeType Index


     Index :  [ Exp ]
           : Index [Exp]

   ExpList : Exp (, Exp)*

LeftValue  : id
	   : LeftValue Index
	   : LeftValue . id
	   : new id "(" ")" . id
	   : this . id

minijavac's People

Watchers

James Cloos avatar Luong-Minh Nguyen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.