View Code? Open in Web Editor
NEW
a c4-like compiler & vm to run a subset of C
c-minus-minus's Introduction
- source code -> |Lexer| -> token stream -> |Parser| -> VM code
- program: {global_decl}
- global_decl: var_decl | enum_decl | func_decl
- var_decl: type [
*
] Id [,
[*
] Id] ;
- enum_decl:
enum
[Id] {
Id [=
num
] [,
Id [=
num
]] }
;
- func_decl: type [
*
] Id (
param_decl )
{
{var_decl}, {stmt} }
- param_decl: type [
*
] Id [,
type [*
] Id]
- stmt:
{
stmt }
| if_stmt | while_stmt | return_stmt | empty_stmt | normal_stmt
- normal_stmt: expression
;
- type:
char
| int
Minimalist Virtual Machine
- Register
- Memory
- Instruction Set
- Save & Load:
IMM
| LEA
| LC
| SC
| LI
| SI
| PUSH
- Arithmetic & Logical Operations:
ADD
| SUB
| MUL
| DIV
| MOD
| OR
| XOR
| AND
| SHL
| SHR
| EQ
| NE
| LT
| LE
| GT
| GE
- Control:
JMP
| JZ
| JNZ
| CALL
| NVAR
| DARG
| RET
- Native-Call:
OPEN
| CLOS
| READ
| PRTF
| MALC
| FREE
| MSET
| MCMP
| EXIT
c-minus-minus's People
Contributors
Watchers