LEX/YACC compiler, compiles a subset of Pascal into a subset of C.

Source code and examples

All the source code and examples are online here: https://github.com/pmav/kpascal-compiler.

Example

The following file is an example of a program in kpascal.

program Fibonacci; 

var n, f, max: integer;

function fibonacci(n : integer) : integer;
begin
    if n = 0 or n = 1 then
        begin
        fibonacci := n;
        end;
    else
        begin
        fibonacci := fibonacci(n - 1);
        fibonacci := fibonacci + fibonacci(n - 2);
        end;
end;

begin
    max := 20;

    n := 1;
    while n <= max do
    begin
        f := fibonacci(n);
        writeln('fibonacci(', n,') = ', f);
        n := n + 1;
    end;

end.