Skip to content

Repository files navigation

M2C Compiler

M2C is a modular Morse-flavored compiler that reads .cym2c programs, tokenizes them, parses a small statement-level IR, generates GNU assembly, links against an assembly runtime library, and produces a native executable.

End-To-End Pipeline

CLI input
  -> main.cpp
  -> Lexer
  -> std::vector<Token>
  -> Parser
  -> std::vector<Statement>
  -> CodeGenerator
  -> temp.s
  -> runtime/io.s + runtime/math.s
  -> gcc -no-pie
  -> executable

Main Modules

Root

Lexer

Syntaxer

Generators

Runtime

Core Data Nodes

The current pipeline is built around these concrete data shapes:

CliOptions

Produced in main.cpp from:

m2c <input.cym2c> -o <output_binary>

Token

Produced by the lexer:

struct Token
{
    TokenType type;
    std::string value;
    int line;
};

Operand

Produced by the parser inside statements.

Statement

The current parsed IR node:

  • PrintString
  • PrintValue
  • VariableAssignment
  • ArithmeticAssignment

What Works Today

  • root build and run flow
  • file-based lexing
  • Morse decoding for quoted strings
  • token stream production
  • parser validation for print and assignment statements
  • simple declaration-before-use checks
  • pure assembly output
  • runtime-backed printing and arithmetic
  • automatic assembly/link step

Supported Syntax

Print

<".... . .-.. .-.. ---">;
<x>;
<42>;

Assignment

let x = 5;
let y = x;

Arithmetic

let a = 5 + 3;
let b = a * 2;
let c = b - 4;
let d = c / 2;

Build

bash build.sh

This produces:

./m2c_bin

Run

bash run.sh m2c_files/test_math.cym2c demo_math

Or directly:

./m2c_bin m2c_files/test_math.cym2c -o demo_math

Runtime Assembly Library

The generator links against:

runtime/io.s

  • m2c_print
  • m2c_print_int

runtime/math.s

  • m2c_add
  • m2c_sub
  • m2c_mul
  • m2c_div

This keeps generated assembly smaller and gives the codebase real reusable assembly modules.

Documentation Map

About

No description, website, or topics provided.

Resources

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages