aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 831f633543031fe0c461e8ab0e8ad0caa3d912d2 (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
69
70
71
72
73
74
75
# 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-repo] project.

## Grammar

```
<Program>        ::= <Initialisation>-list <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 ')'  // Function application
                  |  <Op1> <Expression>                 // Unary operator
                  |  <Expression> <Op2> <Expression>    // Binary operator
                  |  '(' <Expression>-clist ')'         // Tuple
                  |  '[' <Type> ']'                     // Empty list
                  |  '[' <Expression>-clist ']'         // List shortcut
                  |  <Expression> '.' <Name>            // Field application
                  |  '(' <Expression> ')'               // Parenthised expression

<Op1>            ::= '~' | '!'
<Op2>            ::= '+' | '-' | '*' | '/' | '%'           // Int Int -> Int
                  | '==' | '<>' | '<' | '>' | '<=' | '>='  // Int Int -> Bool
                  | '||' | '&&'                            // Bool Bool -> Bool
                  | ':'                                    // a [a] -> [a]

<Type>           ::= 'Bool' | 'Int' | 'Void'
                  |  '(' <Type>-clist ')'     // Tuple
                  |  '[' <Type> ']'           // List

<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 &amp; License

Copyright &copy; 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-repo]: https://git.camilstaps.nl/archived/clean/abc-machine.git/
[clean]: http://clean.cs.ru.nl
[cs]: https://camilstaps.nl