Skip to content

vidstige/pascaljs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pascaljs

CircleCI

first-timers-friendly

Pascal parser in js. The goal is to be able to run simple Turbo Pascal demos made in the 90s that depend on asm, but otherwise very simple pascal.

The generated js output is very sensible and lean. For example the following pascal program:

program HelloWorld;
var
    x: String;
begin
    x := 'y';
    WriteLn('x is ', x);
end.

Is compiled to just

// Genrated by pascaljs. https://github.com/vidstige/pascaljs
function WriteLn() { var args = Array.prototype.slice.call(arguments); console.log(args.join('')); }
var x = null; // integer
x = 'y';
WriteLn('x is ', x);

Example

https://vidstige.github.io/pascaljs/

Features

  • Programs
  • Units

Statements

  • Comments
  • Invoke Procedures
  • var parameters
  • Compound
  • for
  • if
  • assignment
  • while
  • repeat
  • with
  • case
  • Recursive calls

Expressions

  • Integer literals
  • String literals
  • Variables
  • Parenthesis
  • Boolean operators
  • Arithmetic operators
  • Comparisions
  • Function calls
  • Pointers

Declarations

  • Procedures
  • Functions
  • Variabes
  • Constants
  • Type aliases
  • Records
  • Arrays
  • Mix declaration order
  • Real
  • Type checking
  • Nested arrays/records
  • Export types from units

Assembler

  • Parse keywords
  • Construct structured JavaScript flow control (if-then-else, do-while) from assembler
  • Adress variables and pointers
  • Basic instruction set
  • Low/High/Full 16-bit register semantics (ah, al, ax, etc)
  • int for graphics, sleeps, and more
  • Full instruction set

Stanard unit

  • `WriteLn´
  • Arithmetic
  • File I/O
  • Strings
  • In separate file

Demo

  • Separate _system.js for web

Graphics subsystem

  • VGA emulation
  • Palette

Author

Samuel Carlsson [email protected]