All Projects → cwalk → Pl0 Compiler

cwalk / Pl0 Compiler

Compiler written for PL0 programming Language. Written in C, for COP3402 class from UCF.

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to Pl0 Compiler

Ldpl
Compiled programming language for Unix systems, inspired by COBOL and designed to be expressive, fast, readable and easy to learn.
Stars: ✭ 115 (-10.16%)
Mutual labels:  compiler
Serverless Layers
Serverless.js plugin that implements AWS Lambda Layers which reduces drastically lambda size, warm-up and deployment time.
Stars: ✭ 119 (-7.03%)
Mutual labels:  compiler
Cperl
A perl5 with classes, types, compilable, company friendly, security
Stars: ✭ 125 (-2.34%)
Mutual labels:  compiler
Chirp
A modern low-level programming language
Stars: ✭ 116 (-9.37%)
Mutual labels:  compiler
Peachpy
x86-64 assembler embedded in Python
Stars: ✭ 1,592 (+1143.75%)
Mutual labels:  compiler
One
OneLang: The One System Programming Language. (release as soon)
Stars: ✭ 120 (-6.25%)
Mutual labels:  compiler
Elixirscript
Converts Elixir to JavaScript
Stars: ✭ 1,504 (+1075%)
Mutual labels:  compiler
Grain
The Grain compiler toolchain and CLI. Home of the modern web staple. 🌾
Stars: ✭ 2,199 (+1617.97%)
Mutual labels:  compiler
Coq Of Ocaml
Import OCaml programs to Coq 🐓 🐫
Stars: ✭ 117 (-8.59%)
Mutual labels:  compiler
Mcscript
A programming language for Minecraft Vanilla
Stars: ✭ 124 (-3.12%)
Mutual labels:  compiler
Gopherjs
A compiler from Go to JavaScript for running Go code in a browser
Stars: ✭ 10,721 (+8275.78%)
Mutual labels:  compiler
Shadow Rs
A build-time information stored in your rust project.(binary,lib,cdylib,dylib)
Stars: ✭ 117 (-8.59%)
Mutual labels:  compiler
Reading
A list of computer-science readings I recommend
Stars: ✭ 1,919 (+1399.22%)
Mutual labels:  compiler
Rucc
rucc is a tiny toy C compiler in Rust.
Stars: ✭ 115 (-10.16%)
Mutual labels:  compiler
Asterius
A Haskell to WebAssembly compiler
Stars: ✭ 1,799 (+1305.47%)
Mutual labels:  compiler
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-11.72%)
Mutual labels:  compiler
Impala
An imperative and functional programming language
Stars: ✭ 118 (-7.81%)
Mutual labels:  compiler
Md
A markdown parser and compiler. Built for speed.
Stars: ✭ 128 (+0%)
Mutual labels:  compiler
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-0.78%)
Mutual labels:  compiler
Ghc Grin
GRIN backend for GHC
Stars: ✭ 123 (-3.91%)
Mutual labels:  compiler

Introduction

This project simulates a full compiler for the PL/0 programming language, written entirely in C.

The code is based on a class project from my Systems Software class when I was in college.

See HW1-VirtualMachine.doc, HW2-LexScanner.doc, and HW3-ParserandCodeGenerator.doc for more information.

PL-0-Compiler

A PL/0 compiler with lexical analyzer, syntax analyzer and machine code generator with a PM/0 virtual machine containing features designed to support function and procedure calls with parameter passing in C.

Usage

Copy the project using git clone https://github.com/cwalk/PL0-Compiler

Navigate to the directory containing the source code and the test files: cd compiler

  • Run the following command to compile:

$ gcc -o [Executable File Name] *.c

Then to run the executable file:

$ ./[Executable File Name] [Command line switches]

The following command line switches print its corresponding type of output to the screen:

  -l  	The lexeme list created
  -a 	The disassembled code from the code generator
  -v 	The virtual machine execution stack trace

Make sure the test files are in the same directory as the source files (or in the home directory for OSX).

YouTube

YouTube: https://www.youtube.com/watch?v=hF43WUd8jrg&list=PLgAD2y-6wgwoTnPfZWhMuXID14xnzkz2x

##README

The project folder should be named "compiler" Inside you should find the following:

-data.h (a header file that contains defines, variables, and functions used across all .c files. All c files include this header file in their respective source codes)
-main.c (a C program that has a main function. This will run all the other C files: lex, parser, and vm, in that order. It will also take care of the -l -a -v commands)
-lex.c (the lex/scanner)
-parser.c (the parser/intermediate code generator)
-vm.c (the virtual machine)
-a folder called "test files"

Inside the "test files" folder, there will be 5 more folders:

-The first is called "input test files" and holds 12 different input test cases.

-The next folder "lex output files" contains the output files from lex, which uses the 12 input test cases as its input files. These files will have the lexeme list after lex runs with the input files.

-The next folder "parser output files" contains the output files from the parser, which uses the 12 lex output files as its input files. These files have the intermediate generated code after parser runs with the lex output file as its input.

-The next folder "vm output files" contains the output files from the vm, which uses the 12 parser output files as its input files. These files have the instructions printed in order, and then the stack frame of the instructions being executed, after the vm runs with the parser output file as its input.

-The last folder "all errors output" contains a single file called "errors" which holds all the errors that the program might produce. Note: Not all of these error messages may be used.

When you use the ./compile command, the program will print "What is the name of your test file?" to the screen, and if you type "input.txt" it will run fine.

The program works like this: After you compile and run, main.c runs first. Inside main.c, it will take care of the "-l -a -v" commands. It will then run lex.c.

lex.c will use the "input.txt" passed in from the user as its input file, and will generate an output file called "lexoutput.txt" which holds the lexeme list. Then, parser.c will be run.

parser.c will use the "lexoutput.txt" generated from the lex.c as its input file, and will generate an output file called "parseroutput.txt" which holds the generated code. Then, vm.c will be run.

vm.c will use the "parseroutput.txt" generated from the parser.c as its input file, and will generate 3 output files called "vmout.txt" which holds both the instructions and stack frame, "vmout2.txt" which holds just the instructions, and "vmout3.txt" which holds just the stack frame.

Then, main.c will print the lexeme list, generated code, and stack frame, depending on the "-l -a -v" commands called from the user during initial execution. main.c will also print out if there were no errors.

An example of compiling would look like this:

./compile -l -a -v

This would print out all 3: lexeme list, generated code, and stack frame, to the console.


You can compile and run your program, using the commands below:

To compile:

$ gcc –o [Executable File Name] *.c

To Run:

$ ./[Executable File Name]

Then, the program will prompt you with what input.txt you wish to run. Examples would be "input.txt" or "input1.txt" etc.

A full example would be to name the runfile "compile" as this would make the command something similar to this:

To compile: gcc –o compile main.c lex.c parser.c vm.c To Run: ./compile

To print out different things: ./compile -l -a -v

You will then be prompted for the input file name. The input file must be in the same directory as the source files (or the home directory in OSX).

Be sure to check if your input file does a read or a write. If the program is stopped but not crashed, it might be waiting for a scanf, meaning you called read in the test input file. If a single number is printed to screen then it is the result of the write function.

write will write things to screen right after the program prompts the user for the input file name. If "-l -a -v" commands were used, they would be printed after the write functions printed their variables.


This compiler project follows the specifications and EBNF tree specified in the HW3 doc from COP 3402 Summer 2013. PL/0 is a simpler programming language than Pascal. It serves as an example of how to construct a compiler. This compiler is a recursive descent parser with a simple syntax. The grammar can be viewed in the EBNF tree in the HW3 doc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].