Sign inSign up

miraz173/hobby_compiler

By miraz173

Updated 8 months ago

A compiler for a simple programming language, built as a learning project for compiler design.

Image
Languages & frameworks
Operating systems
0

358

miraz173/hobby_compiler repository overview

Hobby Language Compiler

A custom compiler for a simple hobby programming language, built primarily as a learning project to explore compiler design, lexical analysis (Flex), parsing (Bison), symbol tables, and basic interpretation and assembly code generation(codeGen, using MASM32).

Focus: Understanding the logic and grammar implementation rather than creating a polished production language.

Source Code

Supported Features

  • Single main block: func_beginfunc_end
  • Variable declaration: design intvar name; / design strvar name;/design intvar x=5;
  • Assignment: calc expression to var;
  • Input: read var;
  • Output: visible expr; or visible nl; (newline)
  • Loops: while condition: … ; (nested supported)
  • Conditional: check condition: … ; default: … ;
  • Operators: + - * < > == != <= >=
  • String literals: "text"
  • Comments: // …

Example Program (Triangle Pattern)

func_begin
design intvar a;
read a;
design strvar s; calc " " to s;
design strvar tr; calc "^" to tr;

while design intvar t = 0; t<a; calc t+1 to t; :
    while design intvar j = 0; j<a-t; calc j+1 to j; : visible s; ;
    while design intvar j = 0; j<2*t-1; calc j+1 to j; : visible tr; ;
    visible nl;
;
func_end

More example programs named input.txt, input2.txt are included in the image.

Run Image

docker pull miraz173/hobby-compiler
docker run --rm -it miraz173/hobby-compiler

Build & Run

# Build compiler
make createCompiler

# Run input program
make compile

Purpose

Educational project to understand:

  • Flex/Bison workflow
  • Grammar design
  • Lexical analysis (Flex)
  • Syntax analysis (Bison)
  • Semantic analysis –(type checking, variable existence)
  • Nested scopes & control flow, string/int operations
  • MASM32 Assembly code generation

Important: Assembly Output & Windows Dependency

TLDR; Note: The docker image does not contain the masm32 as masm32 runs on windows only and running it through wine doesn't work as masm32 installation needs GUI which is not available in docker system. In order to run the output.asm, install masm32 in your windows machine or install it via wine in your local host machine. The image only supports compilerCode(s)->compiler.exe/.out, program.txt->token.txt->intermediate.txt->output.asm, output.asm->output.exe is not available in this image as it would require running masm32 via wine.


The Docker image does not include MASM32 (Microsoft Macro Assembler) or any Windows-specific assembly toolchain, as

  • MASM32 is a Windows-only assembler/linker toolchain.
  • Running MASM32 inside Docker (via Wine) is not supported in linux as:
    • The MASM32 installer requires a graphical interface (GUI).
    • Docker containers typically run headless (no X server / display).
    • Wine + GUI automation in a minimal container is unreliable and complex.
What the Docker image does support

The container contains your compiler and can fully process input programs up to the assembly stage: program.txt ↓ (hobby_compiler) token.txt → intermediate.txt → output.asm text- You get a clean output.asm file (x86 assembly code).

  • All lexical analysis, parsing, semantic checks, and code generation steps work normally.
What the Docker image does NOT do

It cannot assemble or link output.asmoutput.exe because:

  • No MASM32 / ml.exe / link.exe inside the container
  • No reliable headless way to run Windows tools via Wine
To get a working .exe

Option 1 – On Windows host

  1. Install the MASM32 SDK on your Windows machine:
    http://www.masm32.com/ (classic installer, ~10 MB)

  2. Copy output.asm from the Docker container to your Windows host:

    docker cp <container_id>:/app/output.asm ./output.asm
    
  3. Compile the output.asm file using masm32

    C:\masm32\bin\ml /c /coff /Cp output.asm && C:\masm32\bin\link -entry:main /subsystem:console output.obj && output
    

Option 2 - ON Linux host:

  1. Install Wine and MASM32(guide)

  2. Download source code

  3. Use Makefile to run the program

    make main
    

Happy tinkering!
—Miraz, Dhaka 2026

Tag summary

Content type

Image

Digest

sha256:2747f36fb

Size

99.6 MB

Last updated

8 months ago

docker pull miraz173/hobby_compiler