Parser Combinators
in Smalltalk
1
Parser Combinators in Smalltalk 1 Tims Trick Whats so cool about - - PowerPoint PPT Presentation
Parser Combinators in Smalltalk 1 Tims Trick Whats so cool about functional programming? referential transparency if x = foo stuff , then x + x = foo stuff + foo stuff = is mathematical equality, and you can replace equal
in Smalltalk
1
x + x = foo stuff + foo stuff
equal by equal
2
if x = nextInt input, then x + x ≠ nextInt input + nextInt input
3
4
4
4
4
4
Haskell
5
ifStmnt ::= if boolean then stmts* else stmts* fi
parseIfStmnt parseKeyword: #if. parseBoolean. parseKeyword: #then. parseStatements. parseKeyword: #else. parseStatements. parse: #fi
6
stmts* ::= ε | stmt stmt*
parseStatements ??
7
8
9
9
9
10
c := 'abcde'.
c do: [ : each | Transcript show: each ]. Transcript cr.
s := ReadStream on: c. [ s atEnd ] whileFalse: [ Transcript show: s next ]. Transcript cr.
11
parsed items
and
compound parsers.
12