Skip to content

mohit-bhandari45/Compiler-GO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ Go Compiler

A simple compiler written in Go, designed for educational and experimental purposes. It features a hand-written lexer, parser, and evaluator for a basic scripting language.

✨ Features to be added.

  • Tokenizer (lexer) for source code
  • Recursive descent parser
  • AST (Abstract Syntax Tree) generation
  • REPL for live testing
  • Interpreter/evaluator for expressions and statements
  • Written 100% in Go with no external dependencies

πŸ“‚ Project Structure

/compiler
β”‚
β”œβ”€β”€ lexer/         # Tokenizing logic
β”œβ”€β”€ parser/        # Parsing expressions/statements into AST
β”œβ”€β”€ ast/           # AST node definitions
β”œβ”€β”€ token/         # Token type definitions
β”œβ”€β”€ evaluator/     # Executes parsed AST
β”œβ”€β”€ repl/          # REPL interface
└── main.go        # Entry point

πŸš€ Getting Started

Prerequisites

  • Go 1.18 or higher

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/go-compiler.git
cd go-compiler
  1. Run the REPL:
go run main.go

You should see:

>> let five = 5;
>> five + 10;
15

πŸ’‘ Example Code

let name = "Mohit";
let age = 25;
age + 5;

πŸ§ͺ Running Tests

Each component (lexer, parser, etc.) has its own _test.go files.

To run all tests:

go test ./...

πŸ“Œ TODO

  • Add support for functions
  • Support conditionals (if/else)
  • Handle escape characters in strings
  • Add error recovery in parser
  • Add support for arrays and hash maps

πŸ“„ License

MIT License


Built as a learning project inspired by the Monkey Programming Language by Thorsten Ball.

About

Go Compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages