All Projects → DrkSephy → pascal-compiler

DrkSephy / pascal-compiler

Licence: MIT license
Repository for a pascal compiler built using Python

Programming Languages

python
139335 projects - #7 most used programming language
pascal
1382 projects

pascal-compiler

A Pascal compiler built using Python.

Restrictions

As a means to learn, no libraries will be used for heavy lifting of the implementation of the scanner, parser or abstract syntax tree. The only libraries being used within this project are:

  • Pretty Tables : Library for printing ascii tables, useful for formatting debug statements and generated tokens to console.

Progress

The following is a list of features that have been implemented.

  • <program> -->

  •     <header>

  •     <declarations>

  •     <begin-statement>

  •     <halt>

  • <declarations> -->

  •     <var decl>;<declarations>

  •     <label decl>;<declarations>

  •     <procedure decl>;<declarations>

  •     <function decl>;<declarations>

  • <begin-statement> -->

  •     begin<statements>end

  • <statements> -->

  •     <while statement>;<statement>

  •     <goto statement>;<statement>

  •     <repeat statement>;<statement>

  •     <for statement>;<statement>

  •     <if statement>;<statement>

  •     <case statement>;<statement>

  •     <assignment>

  •     <proc call>

  • <var decl> -->

  •     var[<namelist>:<type>]*

  • <assignment> -->

  •     <LHS> := <RHS>

  • L -> E | < E [<] E | > E [>] E | <= E [<=] E | >= E [>=] E | = E [=] E | != E [!=] E

  • E -> TE'

  • E' -> + T [+] E' | - T [-] E' | e | OR T [OR] E' | XOR T [XOR] E'

  • T -> FT'

  • T' -> x F [x] T' | /F [/] T' | e | DIV F [DIV] T' | MOD F [MOD] T'

  • F -> id | lit | (E) | -F | + F | not F

  • Need to implement (E)

  • Need to implement -F and +F

###Compiler Research Links

######General

######Compiler Theory

######Parsing Methods and Grammar theory

######Bytecode

Compiling Pascal on Mac OS X

If you do not want to use an IDE to write and compile Pascal code, it is highly recommended to simply compile pascal programs through the command line. To do so, follow these steps.

  • Download 'fpc' (Free Pascal Compiler) here. If running on an intel-based Mac, download and installfpc-2.6.0.intel-macosx.dmg, and if you are on a PowerPC Macbook, download and install fpc-2.6.0.powerpc-macosx.dmg.

This should be all you need. Given the following sample program, hello.pas:

program HelloWorld;
uses crt; 

(* Here the main program block starts *)
begin
    writeln('Hello World!');
end.

You can compile hello.pas using fpc hello.pas on the command line, producing hello.o and hello. You can now execute the executable using ./hello, printing 'Hello World!'.

LICENSE

The MIT License (MIT)

Copyright (c) 2014 David Leonard

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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].