-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.fortob
60 lines (50 loc) · 1.1 KB
/
test.fortob
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
# strings
$name = "Nimi"\;
$name.println;
$name+_+"Sukunimi"\\.println;
# loop
$i = '0\;
[$i < '1 0].while: [
$i = $i + '1\\;
$i p;
]\;
# functions
$printTwo=[
# args
$a=\;
$b=\;
($a+_+$b).println;
'
]\;
$printTwo.apply: "koe", "koe2"\;
# parsing functions
# $? is the token list of the **current scope**
$printName=[
$tl=\;
$firstName = $tl.nextString\;
$lastName = $tl.nextString\;
$originalName = $tl.seekString="os"\.if: [
$tl.accept:"os"\;
$tl.accept:"."\;
$tl.nextString
], [$lastName]\\;
($firstName+_+$lastName+_+"os."+_+$originalName).println;
'
]\;
$? $printName.apply:\ Pekka Meikäläinen;
$? $printName.apply:\ Maija Meikäläinen os. Suomalainen;
# another way to do the same thing
@printName[
$firstName = $!.nextString\;
$lastName = $!.nextString\;
$originalName = $!.seekString="os"\.if: [
$!.accept:"os"\;
$!.accept:"."\;
$!.nextString
], [$lastName]\\;
($firstName+_+$lastName+_+"os"+_+$originalName).println;
$\.push:'\;
]\;
printName Anna Virtanen;
@print[$!.readcom.println;$\.push:'\;]\;
print "Hello world!"\;