diff options
| author | Julian Hurst <ark@mansus.space> | 2026-03-11 23:48:12 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2026-03-12 00:17:40 +0100 |
| commit | 7bbdffafdbf016c3a8aecaeb4b7d29b0f10217d3 (patch) | |
| tree | ed3c81b0045295082abf1bb6bd879430a53adf05 /spec/variable-declaration.md | |
| download | rabbitscript-7bbdffafdbf016c3a8aecaeb4b7d29b0f10217d3.tar.gz | |
spec: Add variable declaration
Diffstat (limited to 'spec/variable-declaration.md')
| -rw-r--r-- | spec/variable-declaration.md | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/variable-declaration.md b/spec/variable-declaration.md new file mode 100644 index 0000000..2959f29 --- /dev/null +++ b/spec/variable-declaration.md @@ -0,0 +1,87 @@ +--- +title: Variable declaration +version: 1.0.0 +state: draft +--- + +# Variable declaration + +## Terms + +list: multiple tokens seperated by spaces +token: a particular fully formed symbol or set of symbols representing a specific meaning in rabbitscript and that has no more specific underlying meaning. (i.e. a VARNAME is a token but not an EXPRESSION, however a LITERAL or an OPERAND are tokens) +meaning: something that a parser of the grammar could act on to verify syntaxic validity (is a token valid in relation to the token that follows or precedes it) +representation: something that defines meaning and that a parser of the grammar could act on to verify a token's validity (is a token properly represented or does it contain a symbol that breaks the validity of its representation) + +## Grammar + +### Declaration + +``` +VARNAME = EXPRESSION +``` + +### VARNAME + +A VARNAME is represented by a series of alphanumeric characters: + +``` +alphanum+ +``` + +### EXPRESSION + +``` +(OPERATION | LITERAL) +``` + +### LITERAL + +A literal is represented by a set of alphanumeric symbols. If the symbols can be parsed as a number then the type is a number, otherwise it is a a string. + +``` +(number|string) +``` + +### OPERATION + +Operations are calculations on numbers using reverse polish notation. + +An operation is defined as a list of n operands (where n>1) followed by a a list of n-1 operators, or otherwise said an operand followed by n>=1 operands followed by n operators: + +``` +OPERAND (OPERAND ){N} OPERATOR{N} +``` + +An operand is defined strictly as a number (integer or floating). An operator is defined by the addition, subtraction, multiplication and division symbols as follows: + +``` +(+|-|\*|/) +``` + + +## Example + +Declares a variable `a` with the number value 15. + +``` +a=15 +``` + +Declares a variable `b` with the string value "a string". + +``` +s=a string +``` + +Declares the variable `o` that is an operation resulting in the number value 6. + +``` +o=1 5 + +``` + +The same as above can be specified with an arbitrary number of spaces around the tokens. They should be trimmed by parsers: + +``` +o = 1 5 + +``` |
