summaryrefslogtreecommitdiff
path: root/spec/variable-declaration.md
blob: daa055eda336ff6e28d2c4e9820e7df1910bedb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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 +
```