Skip to content

Latest commit

 

History

128 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSL – Ruby to C Compiler

This project is a simple compiler that translates a subset of Ruby into C using Flex and Bison.

Project Structure

.
├── build/              # Generated files (not versioned)
│   └── hello.c         # C code generated from Ruby
│   └── compiler        # The compiler binary
│   └── lexer.c         # Generated by Flex
│   └── parser.tab.c/h  # Generated by Bison
├── lexer/
│   └── lexer.l         # Lexical rules (Flex)
├── parser/
│   └── parser.y        # Syntax rules (Bison)
├── src/
│   └── main.c          # Main compiler logic
├── test/
│   └── hello.rb        # Ruby test input
├── Makefile
└── README.md

Tool Versions Used

This project was built and tested using the following tool versions:

  • Clang: 16.0.0 (clang-1600.0.26.6) or GCC
  • Flex: 2.6.4
  • Bison: 2.3

It's recommended to use the same or compatible versions to avoid unexpected issues during compilation.

On macOS:

brew install flex bison

If using Bison via Homebrew, you may need to adjust your PATH to use the installed version.

How to Run the Hello World

  1. Clone the repository:
git clone https://github.com/gbevi/csl.git
cd csl
  1. Build the compiler:
make
  1. Run the compiler with the Ruby file:
make run

This generates the file build/hello.c containing the translated C code.

  1. Compile and run the generated C code:
clang build/hello.c -o build/hello
./build/hello

Expected output:

Hello, World!

Clean generated files

make clean

License

MIT

About

Ruby to C Compiler

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages