Compare commits
2 commits
a66fcd3dab
...
8fe329c620
Author | SHA1 | Date | |
---|---|---|---|
8fe329c620 | |||
bd13458eab |
5 changed files with 108 additions and 22 deletions
60
README.md
60
README.md
|
@ -1,34 +1,50 @@
|
|||
# q-lang
|
||||
# Q-LANG
|
||||
|
||||
Idea by [@thea@eldritch.cafe](https://eldritch.cafe/@thea).
|
||||
You can code only using the letter `q`.
|
||||
|
||||
`q-pilator` (WIP) is the interpreter/compiler
|
||||
|
||||
## Project structure
|
||||
|
||||
The project is entirely made of `q` directories and files, each `q` file contain a number of `q` that determine instructions.
|
||||
instruction are executed in order `q -> qq -> ..`
|
||||
- `q-pilator` (WIP) is the interpreter/compiler
|
||||
- `q-pidon` (WIP) is the code generator
|
||||
|
||||
## Glossary
|
||||
## Language spec
|
||||
|
||||
| symbol | interpretation |
|
||||
| ------ | -------------- |
|
||||
| `q` | read registry |
|
||||
| `qq` | declare registry |
|
||||
| `qqq` | call function |
|
||||
| `qqqq` | declare function |
|
||||
| `qqqqq` | operator |
|
||||
Q-lang is a single threaded language, code is written on using `q-dir` and `q-file` sequentially (`q -> qq -> qqq`).
|
||||
|
||||
### Type declaration
|
||||
A `q-dir` contain at least a `q-file` named `q` and can contain an arbitrairy number of `q-dir` and `q-file`
|
||||
|
||||
when encountering thoose symbol `qpilator` will check a directory with the same name + `q` to find the value
|
||||
A `q-file`can contain either an data or instruction.
|
||||
|
||||
| symbol | interpretation | range | method |
|
||||
| ------- | -------------- | ----- | ---- |
|
||||
| `q` | bool | true - false | single file
|
||||
| `qq` | uint | 0 .. 255 | single file
|
||||
| `qqq` | int | -127 .. 128 | single file
|
||||
| `qqqq` | string | [a-zA-Z] | one file per char* |
|
||||
Instruction is always implied.
|
||||
|
||||
*qqqq -string : `empty = a, ..., 25q = z, 26q = A, ..., 51q = Z`
|
||||
### Glossary
|
||||
|
||||
- $f$ is a file
|
||||
- $dir$ a directory
|
||||
- $...$ meaning repeating
|
||||
|
||||
A scope refference the curent execution calling a function make the scope local to this function meaning once the call end memory is cleared.
|
||||
|
||||
#### Instruction
|
||||
|
||||
| number of $q$ | INSTRUCT | ARGs | Structure | Details
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 0 | STDOUT | DATA |
|
||||
| 1 | WRITE VAR | name - scope - DATA | $f,f,dir$
|
||||
| 2 | READ VAR | name | $f$ |
|
||||
| 3 | FUNCTION | name | $dir$ | function are always using the smalest scope possible
|
||||
| 4 | CALL | name - DATA | $f, dir$ |
|
||||
|
||||
#### DATA
|
||||
|
||||
Data type are always prefixed by a `q-file` containing type info (number of $q$).
|
||||
|
||||
| number of $q$ | Type | Structure | Details
|
||||
| --- | --- | --- | --- |
|
||||
| 0 | boolean | $f$ | bool
|
||||
| 1 | unsigned int | $f$ | u32
|
||||
| 2 | signed int | $f,f$ | i16
|
||||
| 3 | char | $f$ | [ASCII](https://www.ascii-code.com/)
|
||||
| 4 | array | $dir \rightarrow (f,data...)$ | u16
|
||||
| 5 | exec | $dir \rightarrow$ `INSTRUCTs` | `exec` return the data contain in the first cell of the local registry |
|
1
q-pidon/.gitignore
vendored
Normal file
1
q-pidon/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target/
|
25
q-pidon/Cargo.lock
generated
Normal file
25
q-pidon/Cargo.lock
generated
Normal file
|
@ -0,0 +1,25 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "q-pidon"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"getopts",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
7
q-pidon/Cargo.toml
Normal file
7
q-pidon/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "q-pidon"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2"
|
37
q-pidon/src/main.rs
Normal file
37
q-pidon/src/main.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
extern crate getopts;
|
||||
use getopts::Options;
|
||||
use std::env;
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
// Define flags
|
||||
let mut opts = Options::new();
|
||||
opts.optflag("h", "help", "print this help menu");
|
||||
opts.optflag("v", "version", "print version");
|
||||
opts.reqopt("t", "type", "type of data/instruction to write", "TYPE");
|
||||
opts.reqopt("v", "value", "value to write", "VALUE");
|
||||
opts.reqopt("o", "output", "output folder", "FOLDER");
|
||||
|
||||
// Print help and exit (see https://github.com/rust-lang/getopts/pull/109)
|
||||
if args.contains(&String::from("-h")) || args.contains(&String::from("--help")) {
|
||||
print!("{}", opts.usage(&format!("Usage: {} FILE [options]", &args[0])));
|
||||
return ExitCode::SUCCESS;
|
||||
}
|
||||
|
||||
if args.contains(&String::from("-v")) || args.contains(&String::from("--version")) {
|
||||
print!("{} {}", &args[0], env!("CARGO_PKG_VERSION"));
|
||||
return ExitCode::SUCCESS;
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => { m }
|
||||
Err(f) => { panic!("{}",f.to_string()) }
|
||||
};
|
||||
|
||||
|
||||
|
||||
ExitCode::SUCCESS
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue