Skip to content

Commit

Permalink
Tidy Chapter 2 by moving recursive functions inline with callers.
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigStuntz committed Feb 2, 2012
1 parent 03d99c4 commit b7cabf0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Lbac.Compiler/Part02-ExpressionParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
/// </summary>
member x.term() =
let head = x.factor()
x.termTail head

member private x.termTail head =
match x.look with
| '*' -> x.termTail ( head @ x.multiply() )
| '/' -> x.termTail ( head @ x.divide() )
| _ -> head
let rec termTail head =
match x.look with
| '*' -> termTail ( head @ x.multiply() )
| '/' -> termTail ( head @ x.divide() )
| _ -> head
termTail head

/// <summary>
/// <factor> ::= (<expression>) | <number>
Expand All @@ -58,13 +57,12 @@
else
x.term()
// rest of expression is evaluated recurively for forms like 1+2-3+4...
x.expressionTail head

member private x.expressionTail head =
match x.look with
| '+' -> x.expressionTail( head @ x.add() )
| '-' -> x.expressionTail( head @ x.subtract() )
| _ -> head
let rec expressionTail head =
match x.look with
| '+' -> expressionTail( head @ x.add() )
| '-' -> expressionTail( head @ x.subtract() )
| _ -> head
expressionTail head

override x.compile() =
x.expression()

0 comments on commit b7cabf0

Please sign in to comment.