-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack-cli.lala
41 lines (34 loc) · 1010 Bytes
/
stack-cli.lala
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
include example.stack
function main(): void {
print 'Stack CLI'
print 'Available commands:'
print ' print'
print ' push'
print ' pop'
print ' clear'
print ' exit / quit'
var stack: IntStack = create-int-stack()
while true {
print ''
var command: string = read string
if command == 'print' {
print int-stack-to-string(stack)
} else if command == 'push' {
print 'Enter value:'
push-onto-int-stack(stack, read int)
} else if command == 'pop' {
if stack.size == 0
print 'Cant pop: the stack is empty!'
else
print pop-from-int-stack(stack)
} else if command == 'clear' {
clear-int-stack(stack)
} else if command == 'exit' or command == 'quit' {
print 'Goodbye!'
return
} else {
print 'Invalid command "' + command + '"!'
}
}
}
main()