Skip to content

Commit

Permalink
Add doc comment, change while loop to recursion.
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigStuntz committed Jan 31, 2012
1 parent 4f54ffb commit 8614185
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions Lbac.Compiler/Part01-Introduction.fs
Expand Up @@ -20,6 +20,7 @@
error(s + " Expected") error(s + " Expected")


/// <summary> /// <summary>
/// Returns argument c if lookahead equals c, throws otherwise.
/// Crenshaw calls this "Match", but match is reserved in F# /// Crenshaw calls this "Match", but match is reserved in F#
/// </summary> /// </summary>
member x.matchChar(c : char) = member x.matchChar(c : char) =
Expand Down
22 changes: 12 additions & 10 deletions Lbac.Compiler/Part02-ExpressionParsing.fs
Expand Up @@ -114,16 +114,18 @@


member x.expression() = member x.expression() =
// <expression> ::= [<addop>] <term> [<addop> <term>]* // <expression> ::= [<addop>] <term> [<addop> <term>]*
let mutable result = if isAddop x.look then let head = if isAddop x.look then
[IL.Ldc_I4_0] [IL.Ldc_I4_0]
else else
x.term() x.term()
while isAddop x.look do // rest of expression is evaluated recurively for forms like 1+2-3+4...
match x.look with x.expressionTail head
| '+' -> result <- result @ x.add()
| '-' -> result <- result @ x.subtract() member private x.expressionTail head =
| _ -> x.expected("Addop") match x.look with
result | '+' -> x.expressionTail( head @ x.add() )
| '-' -> x.expressionTail( head @ x.subtract() )
| _ -> head


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

0 comments on commit 8614185

Please sign in to comment.