This project is a simple compiler that translates a subset of Ruby into C using Flex and Bison.
.
├── 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
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.
- Clone the repository:
git clone https://github.com/gbevi/csl.git
cd csl
- Build the compiler:
make
- Run the compiler with the Ruby file:
make run
This generates the file build/hello.c containing the translated C code.
- Compile and run the generated C code:
clang build/hello.c -o build/hello
./build/hello
Expected output:
Hello, World!
make clean
MIT