cyang / pascal-compiler

Pascal compiler written in Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pascal-compiler

This is a one-pass Pascal compiler using a stack-based representation of intermediate code written in Java.

TokenScanner.java - reads each character and creates a list of tokens

Token.java - class for the Token objects

Parser.java - proccesses/analyzes the list of tokens and and generates a byte array of instructions containing P-codes and addresses

Simulator.java - reads the instructions returned by the Parser and runs it on a stack data type

Emulator.java - main program that passes the token list returned from the TokenScanner to the Parser. Then the instruction array is passed to the Simulator to run the Pascal program and generate output.

SymbolTable.java - hash table to store symbols

Symbol.java - class for the objects stored in SymbolTable

keywords.txt - list of Pascal keywords

How to run:

  1. Change directory to src/
  2. Compile Emulator.java
  3. Provide a Pascal file as input to the Emulator program`

For example:

  1. cd src/
  2. javac Emulator.java
  3. java Emulator ../examples/array.pas

About

Pascal compiler written in Java

License:MIT License


Languages

Language:Java 100.0%