Package dev.zemco.codegame.compilation
Class CodeProgramCompiler
java.lang.Object
dev.zemco.codegame.compilation.CodeProgramCompiler
- All Implemented Interfaces:
IProgramCompiler
Implementation of a compiler, which compiles source code into an executable
program using
the CodeGame syntax. Instructions are parsed using provided instruction parser
and the final program is built using provided program builder factory.
CodeGame syntax includes following features:
- every
instructionis exactly one line long - every jump label is exactly one line long
- jump labels are prefixed using '>' and can contain any non-whitespace character
- comments are prefixed using ';' and end at the end of the line
- comments are completely ignored during compilation and may be placed
behind
instructionsor jump labels - black lines / lines containing only whitespace/comments are completely ignored
- duplicate jump labels are not allowed
- Author:
- Erik Zemčík
-
Constructor Summary
ConstructorsConstructorDescriptionCodeProgramCompiler(IInstructionParser instructionParser, IProgramBuilderFactory programBuilderFactory) Creates an instance ofCodeProgramCompiler. -
Method Summary
Modifier and TypeMethodDescriptioncompileProgram(String sourceCode) Compiles given source code into an executableprogram.
-
Constructor Details
-
CodeProgramCompiler
public CodeProgramCompiler(IInstructionParser instructionParser, IProgramBuilderFactory programBuilderFactory) Creates an instance ofCodeProgramCompiler.- Parameters:
instructionParser- instruction parser for parsing instructionprogramBuilderFactory- factory for building outputprogram- Throws:
IllegalArgumentException- ifinstructionParserisnullor ifprogramBuilderFactoryisnull
-
-
Method Details
-
compileProgram
Description copied from interface:IProgramCompilerCompiles given source code into an executableprogram.- Specified by:
compileProgramin interfaceIProgramCompiler- Parameters:
sourceCode- source code of theprogram- Returns:
- executable
program - Throws:
InvalidSyntaxException- ifsourceCodecontains invalid syntax to the implementation
-