A compiler for the classic programming language Pascal (or another language), using Java Virtual Machine code as the target language.
submission details see
See
src.main.java
- source codeast
- compiler components generated by ANTLRgrammar
- ANTLR grammardriver
- driver related class (main entrance inlcuded)tableUtils
- Symbol table and Local variable table, etc.runtime
- runtime library basic classestype
- data type systeminstruction
- refactored ASM API
src.test
- regression test suites resources and source code of test casesptj.sh
- script which directly calls the project jar filedockerRun.sh
- to run the project in containerDockerfile
- docker image which allows local building
Building steps (with Maven) are listed below. You may also run this project without building, using Jar or Docker.
- Java/JDK
11
(Minimum) - Maven
- Antlr
4.9.1
- Docker
- Test on linux/amd64, win10/amd64
mvn build
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 likealias 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
- 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 inDockerfile
)
# 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>
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
- e.g. dir of source testing pascal program resources of semantic analysis -