A Simple programming Language written in Go
- Arithmetic operations (+, -, *, /)
- Variables and assignments
- If statements
- Functions and return values
- REPL (Read-Eval-Print Loop) for interactive coding
go run main.goYou should see the REPL prompt:
>>Type Bat code directly, for example:
>> let a = 5;
>> let b = 10;
>> a + b;
15Bat follows a simple, C-like syntax. Here's the core grammar:
<program> ::= <statement>*
<statement> ::= "let" <identifier> "=" <expression> ";"
| "return" <expression> ";"
| <expression> ";"
<expression> ::= <integer>
| <boolean>
| <identifier>
| <expression> <operator> <expression>
| "(" <expression> ")"
| "if" "(" <expression> ")" "{" <program> "}" ("else" "{" <program> "}")?
| "fn" "(" <parameters> ")" "{" <program> "}"
| <expression> "(" <arguments> ")"
<parameters> ::= <identifier> ("," <identifier>)*
| ε
<arguments> ::= <expression> ("," <expression>)*
| ε
<operator> ::= "+" | "-" | "*" | "/" | "==" | "!=" | "<" | ">"
<identifier> ::= [a-zA-Z_][a-zA-Z0-9_]*
<integer> ::= [0-9]+
<boolean> ::= "true" | "false" _..-'( )'-.._
./'. '||\\. (\_/) .//|' .'\.
./'.|'.'||||\\|.. )O O( ..|//|||'.'|.'\.
./'..|'.|| |||||\'''''' '"'" ''''''/||||| ||'|..'\.
./'.||'.|||| ||||||||||||. .|||||||||||| |||||'||.'\.
/'|||'.|||||| ||||||||||||{ }|||||||||||| ||||||'|||'\
'.|||'.||||||| ||||||||||||{ }|||||||||||| |||||||'|||.'
'.||| ||||||||| |/' ''\||'' ''||/'' '\| ||||||||| |||.'
|/' \./' '\./ \!|\ /|!/ \./' '\./ '\|
V V V }' '\ /' '{ V V V
' ' ' V ' ' 'Ty Thorsten Ball