A compiler for the REC language implemented in Java.
REC is based on the ADA language.
global num : Integer := 8;
function fibonacci(pos : Integer) return Integer is
begin
if pos <= 0 then
return 0;
end if;
if pos < 3 then
return 1;
end if;
return fibonacci(pos-1) + fibonacci(pos-2);
end fibonacci;
procedure Main () is
begin
show fibonacci(num);
return;
end Main;
You can find REC's context-free grammars written in an EBNF variant on /docs
Right now lexical, syntatic, and semantic analysis are performed. Code generation will be added on the next release.
- Implementation
- The Scanner simulates a Deterministic Finite Automaton (DFA) to create Tokens
- The Parser builds an Abstract Syntax Tree (AST) using the Recursive-descent parsing algorithm
- The Checker decorates the AST with information from indentification and type checking using the Visitor pattern
While an executable is not available, build the project
$> cd /Path/To/Project/root/
$> javac -d Compilador/bin -cp Compilador/src Compilador/src/compiler/Compiler.java
Then create an alias for the compiler with
$> alias compile="java -cp Compilador/bin compiler.Compiler"
Now you can compile your REC programs from the command line using
$> compile /some/path/program.rec