An extremely simple C compiler for MARIE (Machine Architecture that is Really Intuitive and Easy).
- Only a small subset of C features is supported. It is still far from being able to compile a real-world program without modifications.
- The compiler is still at a very early stage and many bugs can happen during parsing or code generation.
- MARIE architecture supports 4K words of memory, which is a big limitation for the amount of instructions a program can have and how much space can be destined to the stack.
- Data types
int
andchar
- Arithmetic operators
+
,-
,*
,/
,%
,++
and--
- Relational operators
==
,!=
,<
,<=
,>
and>=
- Logical operators
&&
and||
- Pointer operators
*
and&
- Flow control statements
if
,while
andfor
- Function calls working (recursion is supported)
- Initial support for macros and typedef
{ }
syntax to initialize arrays""
syntax to initialize strings
The project uses Yarn for the dependencies, so make sure you have Yarn and Node.js installed on your machine:
- Yarn: https://yarnpkg.com/
- Node.js: https://nodejs.org/
- Clone the repository and navigate to the project folder:
git clone https://github.com/lsmacedo/c-compiler-marie
cd c-compiler-marie
- Install the dependencies:
yarn install
To compile a .c
file, use the yarn compile
command with the file names. Example:
yarn compile hello.c world.c
The following parameters are supported:
-o <file>
: Output file name (default: a.mas)-v
: verbose mode
The generated MARIE code is written by default into the file a.mas
and can be executed in a simulator like this one: https://marie.js.org/