Skip to content

williamalexakis/phase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

119 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phase

A statically-typed bytecode-interpreted programming language in C with zero dependencies.

Bytecode Interpretation From Scratch in C

Building

git clone https://github.com/williamalexakis/phase.git
cd phase
mkdir build
cd build
cmake ..
cmake --build .

Syntax

Hello World

entry {
    out("Hello world!")
}

Functions

func add(num1: int, num2: int): void {
    out(num1 + num2)
}

entry {
    add(5, 5)
}

Loops

entry {
    let num: int = 0
    
    while num < 11 {
        out(num)
        num += 1
    }
}

More examples

Architecture

INPUT → Lexer → Parser → Type Checker → Bytecode Generator → Virtual Machine → OUTPUT

Programs are compiled into hexadecimal bytecode and executed by a stack-based VM supporting 25 opcodes. For example, Hello World translates to:

0x0000  →  00 00 00  →  OP_PUSH_CONST 0
0x0003  →  01        →  OP_PRINT
0x0004  →  18        →  OP_HALT

Usage

  • phase --help — list commands and flags
  • phase <file.phase> --tokens — print the token stream
  • phase <file.phase> --ast — print the AST
  • phase <file.phase> --loud — print a success message on exit

MIT

About

A statically-typed bytecode-interpreted programming language in C with zero dependencies.

Resources

License

Stars

Watchers

Forks