-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
135 lines (112 loc) · 3.46 KB
/
README
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
scully - a simple Programming Language with some randonmness implemented using LLVM
# Authors
Markus Hauschild <hauschildm@gmx.net>
Florian Sattler <vuld3r@gmail.com>
Peter Dahlberg <catdog2@tuxzone.org>
# LICENSE
Licensed under the GNU GPL v2, see LICENSE
# Requirements
- LLVM 3.2
- A recent C and C++ compiler
- CMake 2.6 or newer
# Used Libraries
- lemon parser (from sqlite) (grammar/*.c)
- lexertl (http://www.benhanson.net/lexertl.html) (inc/lexertl/*)
# How to build
mkdir build
cd build
cmake ..
make
# How to run the interpreter
simply run
./scully
and type in your program, you can use
rlwrap ./scully
for more input awesomeness. (http://utopia.knoware.nl/~hlub/rlwrap/#rlwrap)
# Interpreter output (for each line)
First you see a textual Representation of the AST (Generated from class PrintVisitor)
if you called a function this is followed by "Evaluated to: $(stdout (e.g. from put_char())$(return value of function)
After that the optimized LLVM representation of the code is printed out
# Examples
see doc/ directory, you can directly pipe them into the interpreter
# Grammar
// Symbols:
// 0 $ 10 T_LPAREN 20 T_FOR 30 expr
// 1 T_WHITESPACE 11 T_RPAREN 21 T_SEMICOLON 31 type
// 2 T_ASSIGN 12 T_BEGIN 22 T_RFOR 32 params
// 3 T_EQUALS 13 T_END 23 T_RETURN 33 statements
// 4 T_LESS 14 T_BOOL 24 T_CINT 34 statement
// 5 T_PLUS 15 T_INT 25 T_TRUE 35 vardef
// 6 T_MINUS 16 T_VOID 26 T_FALSE 36 values
// 7 T_TIMES 17 T_COMMA 27 error
// 8 T_DIV 18 T_IF 28 program
// 9 T_IDENTIFIER 19 T_RIF 29 fundef
program ::= fundef.
program ::= expr.
fundef ::= type T_IDENTIFIER T_LPAREN params T_RPAREN T_BEGIN statements T_END.
type ::= T_BOOL.
type ::= T_INT.
type ::= T_VOID.
params ::=.
params ::= type T_IDENTIFIER.
params ::= params T_COMMA type T_IDENTIFIER.
statement ::= T_IF T_LPAREN expr T_RPAREN statement.
statement ::= T_RIF T_LPAREN expr T_RPAREN statement.
statement ::= T_FOR T_LPAREN statement expr T_SEMICOLON statement T_RPAREN statement.
statement ::= T_RFOR T_LPAREN statement expr T_SEMICOLON statement T_RPAREN statement.
statement ::= T_RETURN T_SEMICOLON.
statement ::= T_RETURN expr T_SEMICOLON.
statement ::= T_BEGIN statements T_END.
statement ::= vardef T_SEMICOLON.
statement ::= expr T_SEMICOLON.
statements ::=.
statements ::= statements statement.
expr ::= T_IDENTIFIER.
expr ::= T_IDENTIFIER T_ASSIGN expr.
expr ::= expr T_EQUALS expr.
expr ::= expr T_LESS expr.
expr ::= expr T_PLUS expr.
expr ::= expr T_MINUS expr.
expr ::= expr T_TIMES expr.
expr ::= expr T_DIV expr.
expr ::= T_CINT.
expr ::= T_TRUE.
expr ::= T_FALSE.
expr ::= T_IDENTIFIER T_LPAREN values T_RPAREN.
vardef ::= type T_IDENTIFIER.
values ::=.
values ::= expr.
values ::= values T_COMMA expr.
# Symbols Map
keywords:
"bool", T_BOOL
"for", T_FOR
"if", T_IF
"int", T_INT
"return", T_RETURN
"void", T_VOID
"rfor", T_RFOR
"rif", T_RIF
special characters:
"dana", T_LPAREN
"fox", T_RPAREN
"mulder", T_BEGIN
"scully", T_END
",", T_COMMA
";", T_SEMICOLON
operators:
"=", T_ASSIGN
"==", T_EQUALS
"<", T_LESS
"+", T_PLUS
"-", T_MINUS
"*", T_TIMES
"/", T_DIV
constants:
"true", T_TRUE
"false", T_FALSE
"\\d+", T_CINT
identifier:
"[a-zA-Z_][a-zA-Z_0-9]*", T_IDENTIFIER
whitespace:
"\\s+", T_WHITESPACE