+17
-43
CFG.md
+17
-43
CFG.md
···
1
1
The following is a context-free grammar for the `iupi` language.
2
2
3
3
```txt
4
-
<epsilon> ::= ''
5
-
<expr> ::= <operation> | <color>
4
+
<language> ::= <unary operation> | <binary operation> | <color>
5
+
6
+
<expr> ::= <binary operation> | <color>
7
+
8
+
<unary operation> ::= <linear invert> | <value invert>
9
+
10
+
<binary operation> ::= <add> | <multiply> | <subtract> | <divide>
11
+
<interpolate> | <max> | <min>
6
12
7
-
<operation> ::= <add> | <multiply> | <subtract> | <divide> | <value invert> | <linear invert> | <interpolate> | <contrast> | <max> | <min>
8
13
<add> ::= <color> + <expr>
9
14
<multiply> ::= <color> * <expr>
10
15
<subtract> ::= <color> - <expr>
11
16
<divide> ::= <color> / <expr>
12
-
<value invert> ::= <expr> <^>
13
-
<linear invert> ::= <expr> <|>
14
17
<interpolate> ::= <color> <float> <expr>
15
-
<hue shift> ::= <expr> & <integer>
16
18
<max> ::= <color> ^ <expr>
17
19
<min> ::= <color> ! <expr>
18
20
19
-
<float> ::= .<digits> | <digits>.<digits>
20
-
<integer> ::= <digits>
21
-
<digits> ::= <digit><digits> | <epsilon>
22
-
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
23
-
<hex> ::= A | B | C | D | E | F | <digit>
21
+
<value invert> ::= <expr> <^>
22
+
<linear invert> ::= <expr> <|>
24
23
25
-
<color> ::= <RGB color> | <grayscale color>
26
-
<RGB color> ::= (<integer>,<integer>,<integer>)
27
-
<grayscale color> ::= (<integer>)
24
+
<float> ::= .<decimals>
28
25
29
-
<if> ::= <color> = <color> {<expr>} {<expr>}
30
-
```
26
+
<decimals> ::= <digit><decimals> | <epsilon>
31
27
32
-
## Attributes
33
-
Interesting lexeme attributes:
28
+
<digits> ::= <digits><digit> | <epsilon>
29
+
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
34
30
35
-
### Synthesization
36
-
| Non-terminals | Synthesized attributes| Inherited attributes |
37
-
|---------------|-----------------------|-----------------------|
38
-
| `<colorHex>` | | `--` |
39
-
| `<hex>` | Val | `--` |
40
-
| `<+,>` | | `--` |
31
+
<color> ::= (<digits>,<digits>,<digits>)
41
32
42
-
### Base Attributes
43
-
| Terminals | Attribute | Value |
44
-
|-----------|-----------|-------|
45
-
| `<digit> ::= 0` | Val | 0 |
46
-
| `<digit> ::= 1` | Val | 1 |
47
-
| `<digit> ::= 2` | Val | 2 |
48
-
| `<digit> ::= 3` | Val | 3 |
49
-
| `<digit> ::= 4` | Val | 4 |
50
-
| `<digit> ::= 5` | Val | 5 |
51
-
| `<digit> ::= 6` | Val | 6 |
52
-
| `<digit> ::= 7` | Val | 7 |
53
-
| `<digit> ::= 8` | Val | 8 |
54
-
| `<digit> ::= 9` | Val | 9 |
55
-
| `<hex> ::= A` | Val | 10 |
56
-
| `<hex> ::= B` | Val | 11 |
57
-
| `<hex> ::= C` | Val | 12 |
58
-
| `<hex> ::= D` | Val | 13 |
59
-
| `<hex> ::= E` | Val | 14 |
60
-
| `<hex> ::= F` | Val | 15 |
33
+
<epsilon> ::= ''
34
+
```