blob: f8dff10821a3af373254d866a7c872ae98269833 (
plain) (
blame)
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
|
# Sil
A compiler for the simple imperative language sil.
This compiler is written in [Clean][clean] and compiles to [ABC-assembly][abc],
which can be used to generate actual machine code using Clean's code generator
or can be interpreted with the [ABCMachine][abc-github] project.
## Grammar
```
<Program> ::= <Function>-list
<Function> ::= <Type> <Name> '(' <Arg>-clist ')' '{' <CodeBlock> '}'
<CodeBlock> ::= <Initialisation>-list <Statement>-list
<Initialisation> ::= <Type> <InitName>-clist ';'
<InitName> ::= <Name> [':=' <Expression>]
<Statement> ::= [<Name> ':='] <Expression> ';'
| 'return' [<Expression>] ';'
| 'if' '(' <Expression> ')' '{' <CodeBlock> '}'
['else' 'if' '(' <Expression> ')' '{' <CodeBlock> '}']-list
['else' '{' <CodeBlock> '}']
| 'while' '(' <Expression> ')' '{' <CodeBlock> '}'
| '|~' <MachineCode>
<Expression> ::= <Name>
| <Literal>
| <Name> '(' <Expression>-clist ')'
| <Op1> <Expression>
| <Expression> <Op2> <Expression>
| '(' <Expression>-clist ')'
| '(' <Expression> ')'
| <Expression> '.' <Name>
<Op1> ::= '~' | '!'
<Op2> ::= '+' | '-' | '*' | '/' | '%' | '==' | '||' | '&&'
<Type> ::= 'Bool' | 'Int' | 'Void'
<Literal> ::= <Bool> | <Int>
<Bool> ::= 'True' | 'False'
<Int> ::= <Digit>-list
```
Comments (single-line `//`, multi-line `/* ... */`) are not included in the
grammar above.
## Dependencies
You need a working Clean installation to build the compiler and at least `clm`
and the code generator to use it.
## Vim highlighting
In the `vim` directory.
## Author & License
Copyright © 2017 [Camil Staps][cs].
Licensed under MIT, see the `LICENSE` file.
[abc]: https://en.wikipedia.org/wiki/Clean_%28programming_language%29#The_ABC-Machine
[abc-github]: https://github.com/camilstaps/ABCMachine
[clean]: http://clean.cs.ru.nl
[cs]: https://camilstaps.nl
|