/pascal-to-jvm-compiler

portable standard pascal subset compiler target JVM, using Java ASM, Antlr4, Logback etc.

Primary LanguageJava

Pascal to JVM compiler

Java CI with Maven, Docker (build & test & deploy)

A compiler for the classic programming language Pascal (or another language), using Java Virtual Machine code as the target language.

--

submission details see

Active Issues

See

Readme

  • src.main.java - source code
    • ast - compiler components generated by ANTLR
    • grammar - ANTLR grammar
    • driver - driver related class (main entrance inlcuded)
    • tableUtils - Symbol table and Local variable table, etc.
    • runtime - runtime library basic classes
    • type - data type system
    • instruction - refactored ASM API
  • src.test - regression test suites resources and source code of test cases
  • ptj.sh - script which directly calls the project jar file
  • dockerRun.sh - to run the project in container
  • Dockerfile - docker image which allows local building

Build instructions

Building steps (with Maven) are listed below. You may also run this project without building, using Jar or Docker.

Requirements

  • Java/JDK 11 (Minimum)
  • Maven
  • Antlr 4.9.1
  • Docker
  • Test on linux/amd64, win10/amd64

Local Build with Maven

mvn build

Run Without Build - Java Jar

File target/pascal_jvm_compiler-jar-with-dependencies.jar is ready to use which is exported using Maven with (minimum) JDK version of 11

To run the compiler in shell:

  • Remark: run the command below only where jar file exists or create a alias beforehand like alias ptj="java -jar ./target/pascal-to-jvm-compiler-jar-with-dependencies.jar"
# Usage:
# Available command:
#  - parse
#  - check
#  - compile
java -jar pascal-to-jvm-compiler-jar-with-dependencies.jar <command> <path>

If you have already created an alias, then directly run something like:

# Usage: [alias-name] <command> <path>
ptj parse ./testArguments.pas

Run Without Build - Docker Container

DockerHub_url - link

Environment Information:

  • OpenJDK build - eclipse-temurin:17
  • Antlr 4.9.1

Platforms are limited, supported platforms are listed below (full available platforms see):

  • linux/amd64
  • linux/arm64
  • linux/arm/v7
  • ...

Make sure you have Docker installed.

First pull the image from Dockerhub.

docker pull barlinbento/pascal-to-jvm-compiler:latest

Then you may run a new container each time to compile the source:

  • Remark: specify the host dir where your source files exist, the example below will take the current working directory. The volume must be mounted to /usr/local/project/resources (fixed in Dockerfile)
# docker run --rm -v <source-path>/:/usr/local/project/resources \
#  pascal-to-jvm-compiler <command> <source-filename>

docker run --rm -v $(pwd):/usr/local/project/resources \
 pascal-to-jvm-compiler parse testArguments.pas

It is recommended to create an alias, make sure you call the alias under the path where Pascal source programs exist, if choose $(pwd) as host path, but it also possible to directly run the project with scripts (ptj.sh)

# Create an alias
# Then usage: ptj <command> <path>
alias ptj="docker run --rm -v $(pwd):/usr/local/project/resources pascal-to-jvm-compiler"

# Then quick run the compiler
ptj parse <path_to_file>

Or using scripts dockerRun.sh

./dockerRun.sh <command> <path_to_file>

Test steps

  • mvn test

test suites and resources

  • main test suites and test cases can be found under src/test/java
  • basic test suites are designed for testing:
    • driver arguments
    • parse (syntactic analysis)
    • check (semantic analysis)
    • run (code generation)
  • resources of each purpose can be found within corresponding directories under src/test/resources
    • e.g. dir of source testing pascal program resources of semantic analysis - src/test/resources/driver/testPascalCompilerDriver/testCheck