Skip to content

sky64redstone/pengc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pengc

pengc is a tiny C-to-NASM compiler for the little penguin (x86_64 Linux).

Pipeline

Lexer → Parser → AST → Codegen → NASM

  • Lexer: tokenizes input C subset
  • Parser: recursive descent expression parser
  • AST: structured representation of expressions
  • Codegen: emits NASM x86_64 assembly

Features

Core compiler

  • Integer literals
  • Arithmetic operations (+ - * /)
  • Bitwise operations (>> | & ^ ~)
  • Relational operators (< >=)
  • Logic operations (|| && != ==)
  • Ternary conditional (? :)
  • Unary operations (+ - ! ~)
  • Indirection (*)
  • Address-of (&)
  • Size-of (sizeof)
  • Cast ((type))
  • Prefix increment and decrement (++ --)
  • Sufix increment and decrement (++ --)
  • Parentheses support
  • Correct operator precedence
  • Return statement parsing
  • AST construction

Language support

  • Variables
  • Assignments
  • Control flow (if, while, for)
  • Function calls
  • Types beyond implicit 64-bit int
  • Strings
  • Floats
  • Arrays
  • Structures
  • Unions
  • Enums
  • Multiple source files
  • Libraries

Preprocessor support

  • Including other files
  • Macros (define undef)
  • Conditionals (if ifdef else elif ...)
  • Implementation defined behaviour (pragma)
  • Throw error (error)
  • File name and line information

Debug tools

  • Token dump mode (--dump-tokens)
  • Parser trace mode (--trace-parser)
  • AST dump (--dump-ast)
  • Improved error reporting (line/column + context)
  • Colored diagnostics
  • Source highlighting (caret-based errors)
  • Panic recovery mode

Build & run

mkdir build
cd build
cmake ..
# optional:
ctest

About

Tiny C-to-NASM compiler

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors