Skip to content

Commit ce93ce7

Browse files
committed
2 parents d9edf3b + 07799de commit ce93ce7

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# BookPart_3
1+
# BookPart 3
22

3-
This is source code for part III of the book series on building an interpreter using Object Pascal. The major outward change in this version include library support, a range of (currently) small builtin libraries such as math. The biggest internal change is to separate code generation from syntax analysis in the for of an abstract syntax tree. User functions are also now first-class entities which can be passed around like any other variable. Example code:
3+
This repo holds source code for part III of the book series on building an interpreter using Object Pascal (https://www.objectpascalinterpreter.com). the code is now fairly stable but I will continue to tidy up the code and possibly add one or two additional features. The major outward change in this version includes library support, and a range of small builtin libraries such as math (these will be expanded). The biggest internal change is to separate code generation from syntax analysis in the form of an abstract syntax tree. User functions are also now first-class entities which can be passed around like any other variable. A lot of work has been done on ensure that garbage collection doesn't leak memory. Example code:
44

55

66
// Quick sort algorithm, depends on recursion
@@ -76,3 +76,26 @@ Passing functions as arguments:
7676

7777
s = runtest (cube, 5)
7878
println (s)
79+
80+
Use of modules:
81+
82+
First define a new module called lib.rh:
83+
84+
a1 = 1.234
85+
b1 = 5.678
86+
87+
function sqrt (x)
88+
return x^0.5
89+
end;
90+
91+
function input (prompt)
92+
print (prompt + " ");
93+
return readString()
94+
end
95+
96+
Importing and using the module:
97+
98+
import lib
99+
100+
println (lib.sqrt (25))
101+
println (lib.a1)

0 commit comments

Comments
 (0)