JNC is a minimal compiler that supports a language inspired by James Newton.
It generates assembly code for the FASM assembler.
There are 26 built-in "registers", A-Z.
Each "register" has a stack associated with it.
NOTE: this is a work in progress!
The grammar of language in EBNF is below.
NOTE: I am not very familiar with EBNF, so this may not be 100% accurate.
<program> ::= <defs>
<defs> ::= <defs> <def> | <def>
<def> ::= <func_def> | <int-def> | <char-def>
<func-def> ::= "def" <id> <statements> "end" |
<int-def> ::= "int" <id> ";" | "int" <id> "[" <num> "]" ";"
<char-def> ::= "char" <id> ";" | "char" <id> "[" <num> "]" ";"
<statements> ::= <statements> <statement> | <statement> | <nothing>
<statement> ::= "if" <paren_expr> "then" <statements> "end" |
"if" <paren_expr> "then" <statements> "else" <statements> "end" |
"while" <paren_expr> <statements> "end" |
<func-call> ";" |
"return" <expr> ";" | "return" ";" |
<id-reg> "=" <expr> ";" |
<id-reg> "[" <expr> "]" "=" <expr> ";"
<id-reg> "++" ";" |
<id-reg> "--" ";" |
<id-reg> "+=" <expr> ";" |
<reg> ""
"//" |
<nothing>
<func-call> ::= <id> "(" ")"
<expr> ::= <term> | <term> <op> <term>
<term> ::= <id> | <num> | <string> | <reg> <reg-op>
<id-reg> ::= <id> | <reg>*
<id> ::= <alpha><alpha-numeric>*
<reg> ::= [A-Z]
<num> ::= [0-9]*
<string> ::= '"' <chars> '"'
<op> ::= <math-op> | <test-op> | <bin-op>
<reg-op> ::= one of (++ -- << >>)
<math-op> ::= one of (+ - * /)
<test-op> ::= one of (< == > !=)
<bin-op> ::= one of (& | ^)
<paren_expr> ::= "(" <expr> ")"
<nothing> ::=
The main program is jn.c. An example source file is test.jn, and it's result is test.asm.
Running:
make jnc
make test
TODO:
- Update tc to generate FASM code that generates an executable.
- Create a simple emulator (vm) that can run a useful subset of Linux.
- Optimize the code generated by jnc.c.
- Enhance jnc to the point where it can build itself.
- [ ]