plc_script - tiny programming language written from scratch

Author: Goran Trlin

Here is a short overview of plc_script - a super tiny programming language intended for learning about parsers, compilers and virtual machines.

The full source code of plc_script is located here. It includes:

  • regular expression based tokenizer
  • LL(1) top-down parser
  • Abstract Syntax Tree (AST) interpreter

Supported language features:

  • variable declaration and assignment
  • numbers and strings as builtin types
  • binary operators (==,<,>)
  • addition, subtraction, multiplication, division operators
  • user defined function definitions and calls
  • builtin functions (only one at the moment - printIt())
  • if else statement
  • while loop statement
  • comments (//)

Sample plc_script program:

// variable declaration: someVar = 10; a = 2; b = 3; // user-defined function: function multiply(a,b){ return a*b; } function sum(a,b) { return a+b; } // sample function calls printIt("Hello world!"); c = someVar + (multiply(a,b) + sum(a,b)); printIt(c);

Feel to play with the language to modify or expand its features. I hope you find it useful while learning about compilers, languages and virtual machines.