Giter Club home page Giter Club logo

vrjass2's Introduction

Codacy Badge Build Status

vrJASS2

This is the new version of my compiler vrJASS. It aims to have a very high percentage of compatibility with vJASS. In fact, that is the primary goal of this project.

Goals

  1. 100% compatibility with vJASS
  2. LanguageServer (service to provide autocompletes, errors, etc. in editors)

How to manually compile grammar?

ANTLR Version: 4.5.3

cd path/to/vrj
./gradlew buildGrammar

How to compile?

Does not requires the compiled grammar (it will do it automatically).

cd path/to/vrj
./gradlew build

How to use it?

cd path/to/vrj/builds/libs
java -jar vrjc.jar file1.j file2.j ...

For the moment, it will only translate or throw errors in the console (stdout).

Keep in mind that this is a very unstable version and many features are not implemented yet.

Project structure

  • src/main/java/ruke/vrj/antlr: All related to ANTLR (lexer, parser, etc.).
  • src/main/java/ruke/vrj/compiler: Compile, run phases, store results.
  • src/main/java/ruke/vrj/phase: Phases of the compiler. That is definition, typechecking & translation.
  • src/main/java/ruke/vrj/translator: Classes that handle how each expession will be translated.
  • src/main/java/ruke/vrj/util

Code style

Google Java Style

Code style check

./gradlew check

Code style auto fix

java -jar bin/google-java-format.java --relace path/to/vrj/**/*.java

Symbol

It will contain information (for example, where it was declared) about an specific element (meaning variables, functions, structs, libraries, etc.).

SymbolTable

Maps a name (string) to a symbol. It will also provide functionality to fetch these symbols.

Definition phase

It will handle the declaration of symbols (for example variables, functions, etc.) and it will catch already defined errors.

TypeCheck phase

It will handle the checking of the program (for example if a variable is used it will check that it is in fact declared).

Translation phase

It will handle the translation of the program, from vrJASS to raw JASS.

Want to contribute?

Great!, here are a few steps:

  1. Fork the project
  2. Open an issue describing what are you going to be working on (so we don't duplicate efforts)
  3. Create a new branch from master to work on your feature (git checkout -b ISSUE_ID/breaf-feature-description).
  4. Create tests that ensure the code does what it must
  5. Finish the feature
  6. Pull request!

If you're not sure of your code, don't worry, send a pull request and we will check it together ^^

Want to suggest a feature?

Great!, here are a few steps:

  1. Create an issue
  2. Describe the feature
  3. Describe the problem that solves
  4. Write a few usage examples
  5. Describe how could it be translated into raw JASS (optional)

Please keep in mind that not all feature suggestions are going to be implemented or that it could take a while to do so.

Important: your feature cannot change or break the behavior of vJASS code (remember, vrJASS2' primary goal is to achieve full compatibility with vJASS).

Licence

MIT

vrjass2's People

Contributors

codacy-badger avatar ruk33 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

lediegue

vrjass2's Issues

Resolve library member

The compiler must be able to resolve public members of libraries and check for private ones.

Example:
someLibrary_somePublicMember

Private members must only be usable inside of the library where declared. If used from outside, an error must be logged.

Example:

library Foo
  private function bar takes ... returns ...
  endfunction
endlibrary

function baz takes ... returns ...
  call Foo_bar() // <-- Error
endfunction

Debug preprocessor

Each statement must allow a debug keyword in the beginning.

Example:

debug call BJDebugMsg("Foo")

Result:

If debug mode enabled: call BJDebugMsg("Foo")
If debug mode disabled: // call BJDebugMsg("Foo")

Struct initializers

Static methods onInit will be taken as struct initializers.

Struct initializers must not take any parameters and return nothing.

Like libraries initializers, struct initializers must be injected in the main function and be called using ExecuteFunc.

Global block declaration

The compiler must be able to translate several global blocks and merge them into one.

Example:

globals
  int foo
endglobals
globals
  int bar
endglobals

Result:

globals
  int foo
  int bar
endglobals

Check for circular library dependency

The compiler must log an error if a circular dependency between libraries is detected.

Example:

library Foo requires Bar
endlibrary
library Bar requires Baz
endlibrary
library Baz requires Foo
endlibrary

Interface validations

Structs implementing interfaces must:

  • Implement all methods
  • Match arguments
  • Match return type

Library declaration

Example:

library Foo
  globals
    int bar
  endglobals
  public function baz takes ... returns ...
  endfunction
endlibrary

Must be translated to:

globals
  int Foo_bar
endglobals
function Foo_baz takes ... returns ...
endfunction

Library initializers

Library initializers must be injected into the main function using ExecuteFunc.

Example:

library Foo initializer Init
  private function Init takes ... returns ...
  endfunction
endlibrary

Must be translated to:

function Foo_Init takes ... returns ...
endfunction
function main takes ... returns ...
  call ExecuteFunc("Foo_Init")
endfunction

Allocate structs

Structs not extending from array must automatically include the static methods allocate and create. Both methods must return an instance and only ´createcan be overwritten.allocatemust beprivate`.

Example to allocate: someStruct.create()

Given the following example:

struct Foo
  integer bar
endstruct
function baz takes ... returns ...
  local Foo foo = Foo.create()
endfunction

The translation must be:

globals
  integer array Foo_vrj_instances
  integer array Foo_bar
endglobals
function Foo_allocate takes nothing returns integer
  local integer instance = Foo_vrj_instances[0]
  if (Foo_vrj_instances[instance] == 0) then
    set Foo_vrj_instances[0] = instance + 1
  else
    set Foo_vrj_instances[0] = Foo_vrj_instances[instace]
  endif
  return instance
endfunction

More info about the allocating algorithm: https://www.hiveworkshop.com/threads/allocation-with-one-variable.253320/

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.