Compiler for a Simple Imperative Language to Virtual Machine Code
Budget: $30 – $250 USD
The task is to create a compiler that translates code written in a simple imperative language into virtual machine instructions. The language is characterized by a grammar that includes variable declarations, conditional statements, loops, procedure calls, arithmetic operations, and array operations.
Requirements:
Compilation and error handling: The compiler should detect errors such as:
Duplicate variable declarations,
Usage of undeclared variables,
Errors related to procedures (e.g., unknown procedures).
If there are no errors, the compiler should generate the virtual machine code.
Code optimization: The resulting machine code should be optimized for size and speed. Special attention should be given to arithmetic operations, especially multiplication and division, which should be performed in logarithmic time relative to the argument values.
Grammar handling: The language grammar defines how variables, loops, conditions, array and procedure declarations should be written. Particular attention must be paid to:
Declaring arrays with specific ranges,
Handling loops (FOR, REPEAT-UNTIL),
Procedure calls without recursion.
Virtual machine: The virtual machine executes instructions based on 64-bit integer values. The instructions include operations on variables, input/output, arithmetic, and jump operations. Each instruction has a specific time cost.
Instructions: The source program should be translated into virtual machine instructions. For example:
LOAD i – load a value from memory to the accumulator,
ADD i – add a value from memory to the accumulator,
JUMP i – jump to the specified instruction.
Process:
Step 1: Analyze and parse the source code using tools like BISON and FLEX (or other similar tools). BISON is used for generating parsers, and FLEX is used for lexical analyzers.
Step 2: Generate intermediate code in the form of virtual machine instructions.
Step 3: Perform code optimization (e.g., shortening instructions, eliminating unnecessary operations).
Step 4: Generate the output file with the virtual machine code.
Step 5: Provide the necessary auxiliary files (Makefile, README).
Files to submit:
Makefile: Containing instructions for compiling the project.
README: Describing the project, the tools used, how to compile and run the program, the author's details, and instructions for installing dependencies on Ubuntu (if other languages than C/C++ were used).
Source code: Containing the compiler implementation, which processes the input code and generates the output in the form of virtual machine instructions.
Summary:
The task is to create a compiler that translates code from a simple imperative language into virtual machine code. The compiler should detect errors, optimize the generated code, and ensure the program can be compiled and run efficiently.
Requirements:
Compilation and error handling: The compiler should detect errors such as:
Duplicate variable declarations,
Usage of undeclared variables,
Errors related to procedures (e.g., unknown procedures).
If there are no errors, the compiler should generate the virtual machine code.
Code optimization: The resulting machine code should be optimized for size and speed. Special attention should be given to arithmetic operations, especially multiplication and division, which should be performed in logarithmic time relative to the argument values.
Grammar handling: The language grammar defines how variables, loops, conditions, array and procedure declarations should be written. Particular attention must be paid to:
Declaring arrays with specific ranges,
Handling loops (FOR, REPEAT-UNTIL),
Procedure calls without recursion.
Virtual machine: The virtual machine executes instructions based on 64-bit integer values. The instructions include operations on variables, input/output, arithmetic, and jump operations. Each instruction has a specific time cost.
Instructions: The source program should be translated into virtual machine instructions. For example:
LOAD i – load a value from memory to the accumulator,
ADD i – add a value from memory to the accumulator,
JUMP i – jump to the specified instruction.
Process:
Step 1: Analyze and parse the source code using tools like BISON and FLEX (or other similar tools). BISON is used for generating parsers, and FLEX is used for lexical analyzers.
Step 2: Generate intermediate code in the form of virtual machine instructions.
Step 3: Perform code optimization (e.g., shortening instructions, eliminating unnecessary operations).
Step 4: Generate the output file with the virtual machine code.
Step 5: Provide the necessary auxiliary files (Makefile, README).
Files to submit:
Makefile: Containing instructions for compiling the project.
README: Describing the project, the tools used, how to compile and run the program, the author's details, and instructions for installing dependencies on Ubuntu (if other languages than C/C++ were used).
Source code: Containing the compiler implementation, which processes the input code and generates the output in the form of virtual machine instructions.
Summary:
The task is to create a compiler that translates code from a simple imperative language into virtual machine code. The compiler should detect errors, optimize the generated code, and ensure the program can be compiled and run efficiently.