Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

DSLCompiler

Simple DSLCompiler for Lazarus IDE

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

DSLCompiler

Some small adaptations and enhancements to the Primož Gabrijelčič compiler - alias gabr42 - which can now be run from Lazarus IDE and Free Pascal Compiler (FPC).

A must read:

  • Writing a Simple DSL Compiler with Delphi - Introduction and so on. The Delphi Geek, gabr42, 2017
  • SimpleDSLCompiler, A Personal Experiment - Not so simple. Github, gabr42, 2017

Demo output:

pascal
----- Some statements -----

fib(i)
{
  if (i < 3)
  {
    return 1
  }
  else
  {
    return fib(i - 2) + fib(i - 1)
  }
}

mult(a,b)
{
  if (b < 2)
  {
    return a
  }
  else
  {
    return mult(a, b - 1) + a
  }
}

power(a,b)
{
  if (b < 2)
  {
    return a
  }
  else
  {
    return mult(power(a, b - 1), a)
  }
}

----- Syntactic Recognition with Computation -----

mult(5,3) = 15
2^10 = 1024
fib(7) (native) = 13
fib(7) (compiled) = 13

----- Elapsed runtime: fib(30) -----

Native: 832040 in 16 ms
Compiled: 832040 in 344 ms
Interpreted: 832040 in 2312 ms