Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nimaposhtiban/cminus
minimal interpreter for (C-)
https://github.com/nimaposhtiban/cminus
go golang interpreter
Last synced: 9 days ago
JSON representation
minimal interpreter for (C-)
- Host: GitHub
- URL: https://github.com/nimaposhtiban/cminus
- Owner: NimaPoshtiban
- License: wtfpl
- Created: 2022-10-23T14:34:12.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T06:35:01.000Z (9 months ago)
- Last Synced: 2024-04-02T07:39:53.965Z (9 months ago)
- Topics: go, golang, interpreter
- Language: Go
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cminus
This is an interpreter for a minimal dynamically typed programming language. It currently supports the following data types:
Integers (no floats)
Boolean (true, false)
Strings (enclosed with double quotes)
All C defined Operators except ++ & --## Built-in Functions :
The following built-in functions are currently available to use:
- len() -> returns the length of the string or the array.
- push() -> adds the element to the end of the array.
- join() -> join two arrays into a single array.
- delete() -> returns the array without the deleted item.
- print() -> prints the data to the console.
- exit() -> exits the program by causing it to panic.
- exec() -> execute system command
- info() -> returns system info
- flush() -> clears the console
- str() -> converts types to string
- int() -> converts string to integer
- sizeof() -> returns the size of the object
- alert(message)-> shows the entered message in a GUI windows (only for Windows)## Operators:
- "=" -> assignment operator
- "%" -> modulo operator
- "-" -> minus operator
- "/" -> division operator
- "*" -> multiplaction operator
- "+" -> sum operator
- ">>" -> right shift operator
- "<<" -> left shift operator
- "!" -> not operator
- "and" -> logical and operator (&&)
- "or" -> logical or operator (||)
- All LT GT Operators (<= => > < == != )## Built-in Macro Functions:
- quote(expression) -> returns the unevaluated expression
- unquote(expression) -> evaluate the expression inside quote### Syntax
- Defining a variable:
```
let foo = 20;
```
- Defining a function:
```
let sum = func(x,y) { x + y };
let sum = func(x,y) {
return x + y
};
```
- Using recursion:
```
let factorial = func(n) { if (n == 0) { 1 } else { n * factorial(n - 1) } };
```
- Using while loop:
```
let j = 10
while(j > 0){
print(j)
let j = j - 1
}
```
- Using Arrays:
```
let numbers = [1,3,7,9];
```
- Using Hashes:
```
let people = [{"name": "Alice", "age": 24}, {"name": "Anna", "age": 28}];
```
- Defining a macro:
```
let unless = macro(condition, consequence, alternative){ quote(if (!(unquote(condition))) { unquote(consequence); }else { unquote(alternative); }); };
```
#### Interpret a file```
cminus --interpret
```#### Generate JSON ast and save it to a file
```
cminus --interpret --ast
```