Skip to content

Grace is a language with an academic purpose, elaborated on course of Compilers (Computer Science) from State University of Maringa

License

Notifications You must be signed in to change notification settings

rafaelbaiolim/language-grace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grace Language

Grace is a language with an academic purpose, elaborated on course of Compilers (Computer Science) from State University of Maringa. The version of this repository was developed using Antlr4, Java 9, Gradle, LLVM 8.0 and JavaCPP for generate the intermediate code.

The grammar of the language as well lexical, semantic and syntactic specifications can be consulted in:

https://din-ilp2018.readthedocs.io/en/latest

Execution

Parameters

Arg Description
0 Absolute path of .grc file
-o Enable LLVM optimizations
-a Abort IR generation for modules with warnings/errors
-nd Do not show the IR dump on terminal

The IR output file is generated on: tests/assets/llvm/out.bc

Console

Only execute this step if package uem.antlr was empty.This repository already have one compiled version of this step

  1. Execute ANTLR4 with Gradle as follow, for generate lex and parser files
$ gradle generateGrammarSource && gradle copyTokenFile

InteliJ

The build of this project as well as the unit tests were running on the InteliJ Community IDE. This is how execute:

  1. Create a test .grc file on tests/assets/parser/, and use this file as first argument on IDE execution.

  2. F6 key, for execute and generate the assembly of language

  3. On terminal (you could use IDE terminal), execute: $lli unit/assets/llvm/out.bc (This should output the result of your code)

Antrl4

The .G4 files src/main/antlr can be executed or tested with the antrl4 tool:

$ antlr4 *.g4
$ javac *.java
$ grun Grace command -tree 

I strongly recommend you to install ANTLR4 plugin for InteliJ. This way you can debug and validate your grammar much faster.

Unit Tests

All tests was written in XML structure, if you want create one you could do as follow:

  1. Set the tests folder as test resource on project structure of your IDE.
  2. Because JavaCPP has the most methods and builders on static way, you must write each test in a separated XML.
  3. Add a new entry with XML name on array of tests files and create a new static final String of the line that references this entry on CompillerTest.java .

This is how your XML test should like:

<tests>
    <test>
        <wanted>0 1 1 2 3</wanted>
        <type>EQUALS</type>
        <optimize>true</optimize>
        <file>CAMINHO_ABSOLUTO/test-fib.grc</file>
    </test>
</tests>
Tag Description
wanted Expected value of llvm output
type EQUALS or NOT_EQUALS
optimize Use llvm optimizations ( true or false)
file Absoule path of your .grc code

I really hope this implementation helps someone who needs help with compiler development.