Skip to content

reynoldsbrent/KnightCodeCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KnightCode Compiler

Overview

The KnightCode Compiler compiles programs written in KnightCode into Java bytecode. This bytecode is executable on any Java Virtual Machine (JVM). The compiler is built using Java and utilizes the ANTLR tool for parsing the KnightCode syntax, transforming it into a format that can be converted into bytecode.

Key Components

  • Lexer and Parser: Automatically generated by ANTLR based on the grammar definitions provided for KnightCode. These components break down the input code into tokens and construct a parse tree.
  • SymbolTable: Manages variable declarations and scope to ensure correct bytecode generation concerning variable usage.
  • BytecodeGenerator: Utilizes the ASM library to generate Java bytecode directly from the parsed KnightCode.
  • KccVisitor: Traverses the parse tree, utilizing the SymbolTable and BytecodeGenerator to produce the final bytecode output based on the logic of the KnightCode program.

Using the Compiler

Prerequisites

  • Java Development Kit (JDK) must be installed.
  • Clone the repository to you local machine.
  • ANTLR and ASM libraries need to be included in your project or build path.
  • Run the build-grammar and compile-grammar ANT commands to generate and compile the Java files produced by ANTLR. These commands can be found in the build.xml file.

Compilation Steps

  1. Write Your KnightCode File: Write your program in a file with the .kc extension.
  2. Compile Your Program:
    • Open your command line interface (CLI).
    • Navigate to the directory containing your .kc file and the kcc compiler.
    • Run the following command:
    java compiler/kcc tests/yourKnightCodeFile.kc output/yourKnightCodeFile
    • Replace "yourKnightCodeFile" with the name of the KnightCode file that you wrote.
    • Run your KnightCode class file using this command:
    java output/yourKnightCodeFile

About

KnightCode to Java bytecode compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published