Skip to content

pook27/LavaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌋 LavaScript 🌋

A toy programming language and compiler built on top of the Hack Computer

LavaScript translates .ls files into Hack assembly, assembles them into binary, and runs them on a custom CPU emulator that operates on top of the Hack ALU.

Inspired by the legendary Nand2Tetris course, extended with ✨ new features ✨ such as assignments, conditions, loops, character printing, and even a quirky Maybe random condition.

✨ Features

  • 📝 Variables with automatic memory allocation
  • ➕ Arithmetic operators: +, -, *, /
  • 🔀 Logical operators: &, |
  • 🔎 Comparisons: ==, !=, >, <, >=, <=
  • 🔁 Control flow:
    • while loops (supports True, False, and Maybe for random branching)
    • if conditionals
    • for (init; condition; increment) loops
  • 🖨️ Printing:
    • print(x) → print number
    • printc('A') or printc(x) → print ASCII character
  • 🔡 Character literals automatically converted to ASCII codes
  • ⚙️ Compiler → Hack assembly
  • 🛠️ Assembler → machine code
  • 💻 CPU emulator executes the machine code with extended print opcodes:
    • 01 → print number (decimal)
    • 10 → print ASCII character
    • 11 → no print (default, backward compatible)

🚀 Getting Started

Clone the repository, then run:

./melt examples/example.ls
to compile and execute a LavaScript program.

Development
Add new syntax → parser.py
Implement new operations → compiler.py
Update opcode translation → assembler.py
Extend CPU behavior → cpu.py

Roadmap
<p>Functions and subroutines</p> <p>Strings and arrays</p> <p>Additional operators (like % and logical not)</p> <p>File I/O</p>
License
This project is just for learning and fun. Do whatever you want.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages