Skip to content

tejus3131/bhasha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bhasha

Rust License: MIT

Bhasha is a small interpreter for a toy language whose keywords and operators read like Hindi / Hinglish. Programs are plain text files with the .bhasha extension.

The implementation is a classic three-stage pipeline in Rust: lexer (Logos) → recursive-descent parsertree-walking interpreter.

Features

Area What works
Variables mano + barabar for declarations
Arithmetic ka yog, ka antar, ka guna, ka bhaag, %
Types in runtime Integers, floats, strings, booleans (satya / asatya)
Control flow agar / warna / aage, jabtak loops
I/O likho (print), padho with type names
Functions banaojo lefirwapas karo, chalaoparme
Comments Lines starting with faltu
Program end samapt (CLI also appends this if omitted)

Requirements

  • Rust (stable), 2021 edition

Quick start

git clone https://github.com/<your-username>/bhasha.git
cd bhasha
cargo build --release

Run a program:

cargo run --release -- examples/hello.bhasha
# or
./target/release/bhasha examples/hello.bhasha

The CLI accepts exactly one argument: path to a .bhasha file.

Project layout

Path Role
src/tokens.rs Logos-derived lexer; all keyword / operator spellings
src/ast.rs AST: Expression, Statement, Program
src/parser.rs Builds Program from token stream
src/interpreter.rs Evaluates AST; global env + function table
src/main.rs Reads file, tokenizes, parses, runs
src/lib.rs Re-exports Token, Parser, Interpreter for tests / embedders
examples/ Sample .bhasha programs

Language sketch

Binary expressions use operand–operand–operator token order (see parser), e.g. 10 5 ka yog → 10 + 5.

Declaration

mano naam barabar "Ram"
mano x barabar 20 5 ka bhaag

Conditionals and loops

Blocks close with aage. Optional warna branch after the first block.

agar x 5 se bada hai
likho "bada"
warna
likho "chhota ya barabar"
aage

jabtak x 0 nhi hai
likho x
mano x barabar x 1 ka antar
aage

Input (padho then variable name then type keyword)

Type keyword Meaning
sankhya Integer
dasamlav Float
paath String (line)
tark Boolean
padho sankhya n
likho n

Functions (minimal surface syntax)

banao greet jo le naam fir
likho naam
wapas karo 0

chalao greet "Bhasha" par result me

Comments

faltu yeh line ignore hoti hai

End of program

Use samapt at end of source, or rely on the CLI inserting it when missing.

Full token list lives in src/tokens.rs.

Using as a library

use bhasha::{Interpreter, Parser, Token};

let source = "mano x barabar 1 2 ka yog samapt";
let mut tokens = Token::tokenize(source);
let mut parser = Parser::new(&mut tokens);
let program = parser.parse();
Interpreter::new().run(program);

Contributing

See CONTRIBUTING.md and CODE_OF_CONDUCT.md. PRs welcome: docs, examples, tests, lexer/parser fixes, better errors.

Security

See SECURITY.md.

License

MIT.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages