Hasty Briefsbeta

Bilingual

I Wrote a Compiler

a year ago
  • #compiler
  • #Go
  • #BASIC
  • The author wrote a compiler for a simplified BASIC variant called toybasic over a weekend.
  • The compiler is written in Go and translates BASIC into Go code.
  • The compiler has three stages: Lexer, Parser, and Compiler.
  • The Lexer uses nex to tokenize the source code.
  • The Parser uses goyacc to build a syntax tree from tokens.
  • The Compiler generates Go code by traversing the syntax tree.
  • The project was inspired by TinyBASIC and modified to exclude the INPUT statement.
  • The full code is available on GitHub.
  • The author tested the compiler with a BASIC program using all language constructs.
  • The project was a fun and educational experience for the author.