KSM Language is a simple, interpreted language implemented in Go. The project includes a lexer, parser, and interpreter that work together to read, understand, and execute code written in the KSM language. It is a great starting point for understanding the components of a programming language.
The KSM language project is composed of three main components:
- Lexer: Responsible for breaking the source code into tokens.
- Parser: Organizes the tokens into a meaningful structure (Abstract Syntax Tree - AST).
- Interpreter: Executes the parsed instructions.
lexer.go
: Contains the lexical analyzer (lexer) that converts the input code into tokens.parser.go
: Contains the parser that processes the tokens to build an abstract syntax tree (AST).interpreter.go
: Contains the interpreter that executes the AST.main.go
: The entry point for running KSM either in REPL mode or by executing a .ksm file.
- Basic Syntax: Supports variable declarations, control structures (like
if
andcase
), basic arithmetic operations, and more. - Tokenization: Tokenizes keywords, identifiers, numbers, strings, and operators.
- Parsing: Builds a syntax tree from the tokens.
- Interpreting: Executes the parsed code.
git clone https://github.com/yourusername/ksm-language.git
cd ksm-language
-
You can run KSM in two ways:
- Interactive REPL: Starts an interactive session where you can type KSM code line by line.
go run .
2. Run a File: Executes a .ksm file.
go run . core.ksm
declare x = "Hello World" displayln(x)
- Output will be . Hello World
The project supports the following data structures:
Number: Supports both integers.
String: A sequence of characters.
Boolean: Represents true and false values.
int -> digit
string -> sent
rune -> char
float64 -> deci64
float32 -> deci32
bool -> booly
byte -> bite
main -> core
if -> if case
else -> otherwise
switch -> option
case -> option case
default -> default case
return -> return
break -> exit
func -> method
print -> display
println -> displayln
printf -> displayf
var -> declare
const -> constant
type -> define