blob: bacfd06446527674d4a555ee897a1a4310876943 (
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
|
# 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> <Name>-clist ';'
<Statement> ::= <Name> ':=' <Expression> ';'
| <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>
| <Op2> <Expression>
<Op1> ::= '~'
<Op2> ::= '+' | '-' | '*' | '/' | '%' | '==' | '||' | '&&'
<Type> ::= 'Bool' | 'Int' | 'Void'
<Literal> ::= <Bool> | <Int>
```
## 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
|