13

A Compiler in Go

An implementation of a compiler written in the Go programming language.

Project Description

Overview

The project, "A Compiler in Go," focuses on creating a compiler for a simple programming language. This compiler translates source code into executable machine code or bytecode. Leveraging LLVM Intermediate Representation (IR), it generates efficient and optimized output.

Features

  • Lexer and Parser: Includes a lexer and parser to tokenize and parse source code, constructing an abstract syntax tree (AST) representing the program's structure.
  • Symbol Table: Manages variables, functions, and scopes during compilation, facilitating identifier resolution and scope management.
  • Type Checking: Ensures compatibility and consistency of expression and statement types throughout the program, catching type-related errors early.
  • AST Traversal and Compilation: Generates LLVM IR corresponding to each AST node, translating high-level constructs into lower-level representations for execution.
  • Built-in Functions: Supports predefined functions for common operations like input/output and math functions.
  • Error Handling: Implements robust error handling to provide informative messages for syntax errors, type mismatches, and other issues.
  • Optimizations: Applies basic optimizations to improve code efficiency, such as constant folding and dead code elimination.

Accomplishments

  • Implemented lexer and parser capable of parsing the language syntax.
  • Developed a symbol table for managing variable and function scopes.
  • Integrated type checking for ensuring program correctness.
  • Achieved AST traversal and LLVM IR code generation.
  • Supported a set of built-in functions for common operations.
  • Implemented robust error handling mechanisms.
  • Applied basic optimizations to enhance code efficiency.

Future Directions

  • Expand language features to support advanced constructs.
  • Enhance optimization techniques for further efficiency.
  • Develop a runtime environment or interpreter for bytecode execution.
  • Extend compiler targeting different platforms or architectures.
  • Implement additional language tools like a debugger or profiler.

The project, "A Compiler in Go," demonstrates proficiency in language design, parsing techniques, code generation, and error handling, providing a foundation for building compilers.