0 people like it.

Nontrivial Gotos

 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: 
type Token = END
type Status = ACCEPT | ERROR

type ParseState = Shifting | Reducing

let parse gettoken shift reduce () =
    let rec read() =
        let tok = gettoken()

        if tok = END then
            ACCEPT
        else
            update tok Shifting

    and update tok state = 
        match state with
        | Shifting ->
            if shift tok then
                read()
            else
                update tok Reducing

        | Reducing ->
            if reduce tok then
                update tok Shifting
            else
                ERROR
    
    read()
union case Token.END: Token
type Status =
  | ACCEPT
  | ERROR

Full name: Script.Status
union case Status.ACCEPT: Status
union case Status.ERROR: Status
type ParseState =
  | Shifting
  | Reducing

Full name: Script.ParseState
union case ParseState.Shifting: ParseState
union case ParseState.Reducing: ParseState
val parse : gettoken:(unit -> Token) -> shift:(Token -> bool) -> reduce:(Token -> bool) -> unit -> Status

Full name: Script.parse
val gettoken : (unit -> Token)
val shift : (Token -> bool)
val reduce : (Token -> bool)
val read : (unit -> Status)
val tok : Token
val update : (Token -> ParseState -> Status)
val state : ParseState
Raw view Test code New version

More information

Link:http://fssnip.net/6Z
Posted:12 years ago
Author:
Tags: