Skip to content
/ wmoc Public

WMOC - Writing My Own Compiler, is currently the front end of the compiler for PL/0 language written in C.

Notifications You must be signed in to change notification settings

Gamin8ing/wmoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WMOC - Writing My Own Compiler

WMOC is a learning project about compiler design and construction. It’s based on PL/0, formulated by Niklaus Wirth as a minimal educational language. Followed from the brilliant blog series written by Brian Callahen.

PL/0

PL/0 (or pl0) is an "educational programming language" as stated by Rosetta Code. The syntax rule of the language can be represented in the EBNF form as:

program		= block "." .
block		= [ "const" ident "=" number { "," ident "=" number } ";" ]
                  [ "var" ident { "," ident } ";" ]
                  { "procedure" ident ";" block ";" } statement .
statement	= [ ident ":=" expression
                  | "call" ident
                  | "begin" statement { ";" statement } "end"
                  | "if" condition "then" statement
                  | "while" condition "do" statement ] .
                  | "printInt" ident
                  | "printChar" into ident
                  | "readInt" into ident
condition	= "odd" expression
                | expression ( "=" | "#" | "<" | ">" ) expression .
expression	= [ "+" | "-" ] term { ( "+" | "-" ) term } .
term		= factor { ( "*" | "/" ) factor } .
factor		= ident
                | number
                | "(" expression ")" .
ident		= "A-Za-z_" { "A-Za-z0-9_" } .
number		= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" .

Main Flow

In this first version, WMOC works as a front end. It generates intermediate C code from .pl0 source files. You can then compile the generated C code with any C compiler (like gcc).

Source Code -> Lexer -> Parser -> Semantic Analyser -> C Code Generation

Installation

  1. Download the executable wmoc from releases.
  2. Run:
./wmoc <your-.pl0-file> <output.c-filename
  1. This will generate a .c file. Then compile and run it with:
gcc <output.c> && ./a.out

Build from source

  1. Clone the repository:
git clone https://github.com/Gamin8ing/wmoc.git
cd wmoc
  1. Build using:
make
  1. An executable named wmoc will be created.
  2. To use it:
./wmoc <your-file.pl0> <output.c>
  1. Then compile and run it with:
gcc <output.c> && ./a.out

Example Usage

An example .pl0 file is included in the source code (example.pl0).

Command

./wmoc example.pl0 example.c
gcc example.c -o example && ./example

Issues

To report bugs or request features, please open an issue using our issue template mentioned in CONTRIBUTION.md. We appreciate feedback and contributions!

About

WMOC - Writing My Own Compiler, is currently the front end of the compiler for PL/0 language written in C.

Topics

Resources

Stars

Watchers

Forks