项目作者: jpan127

项目描述 :
C-- Compiler using Antlr4
高级语言: C++
项目地址: git://github.com/jpan127/compiler.git
创建时间: 2018-02-06T22:22:39Z
项目社区:https://github.com/jpan127/compiler

开源协议:

下载


C- - Language

This project aims to design a compiler for a new language: C—. This language is primarily composed of C99 constructs, and hints of C++, Python, Swift, and GNU built ins absorbed into the language. The language is currently in the process of incremental development and is expecting complex data types in the near future.

C- - Compiler

This compiler utilizes Antlr4 to autogenerate the front end parser and scanner. The intermediate and backend of the compiler is written in C++. The target assembly is Jasmin, a JVM assembly language that can be assembled into Java *.class files. From there, the JVM can be invoked to execute the program.

Directory Structure

  1. .
  2. ├── antlr4-runtime # ANLTR runtime header and source files, usually untouched
  3. ├── build # Build files (bin)
  4. ├── generated # Autogenerated ANTLR files
  5. ├── grammars # All the grammar files
  6. └── Cmm.g4 # The only grammar file under development
  7. ├── libs # ANTLR program specific files
  8. ├── antlr-4.7-complete.jar # Java ANTLR program
  9. ├── libantlr-runtime.a # Static library built from ANTLR runtime source files
  10. └── PascalRTL.jar # Java helper runtime libraries
  11. ├── outputs # Where the output *.j and *.class files are created
  12. ├── samples # Sample C-- programs to test ANTLR with
  13. ├── scripts # Bash and python scripts for build automation
  14. ├── assemble.sh # Assembles the *.j file into a *.class file
  15. ├── build.sh # Builds the lexer / parser for C++ target
  16. ├── compile.sh # Compiles the *.c file into a *.j file
  17. └── recompile.sh # Recompiles the ANTLR library into a static library
  18. ├── src # Non-ANTLR source files
  19. ├── tools # Various tools
  20. ├── jasmin-assembler # Used for assembling *.j files
  21. └── Krakatau # Used for disassembling *.class files into *.j
  22. ├─ SConsript # SCons build script
  23. └─ SConstruct # SCons root environment

How To Build

SCons is responsible for the build process and automation.

  1. Install SCons from their website https://scons.org/pages/download.html
  2. Install JAVA JDK from their website http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html
    • Add the JDK bin path to your environment path
  3. Set up the paths in the build scripts : $JAVA_JDK_PATH
  4. Run scons.py from the directory that contains SConstruct

Use scons.py run=SAMPLE_PROGRAM to build and run.
Use bash assemble.sh SAMPLE_ASSEMBLY to assemble a jasmin source file
Use bash compile.sh SAMPLE_PROGRAM_NO_EXTENSIONS_UNDER_SAMPLES_DIR to compile a source file

How To Generate The Parse Tree

  1. Run the build.sh script
  2. Use the optional command line arguments for a different grammar file or a different sample program

ANTLR Runtime

The runtime library has already been compiled into a static library for easy linking, no need to worry about the runtime source files
However, it will not run on all machines. Use the recompile.sh to recompile a static library on your machine which will appear under
antlr4-runtime/temp.

TODO

# Task
1 Strip repository of unneeded files
2 Clean up and rewrite intermediate modules
3 Finish writing JasminEmitter module
4 Integrate JasminEmitter into the visitors
5 Add all the operators into the language
6 Add for loops
7 Add switch case
8 Add tests
9 Add arrays
10 Add structs
11 Add enums