Last active
April 18, 2016 18:34
-
-
Save vik-y/ddb4c6eac906b7461b35b0dcdaba9302 to your computer and use it in GitHub Desktop.
Modified version of decimal number identifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num (s : char Mystream.mystream) : State.state = | |
let rec one (stream : char Mystream.mystream) : State.state = | |
match stream with | |
Mystream.End -> State.Terminate(true) | |
| Mystream.Cons(c, _) -> | |
let lookahead = (Mystream.tl stream) () in | |
if (c >= '0' && c <= '9') then | |
match lookahead with | |
Mystream.Cons(c', _) -> | |
if (c' >= '0' && c' <= '9') then | |
State.State(one) | |
else if (c' = '.') then | |
State.State(two) | |
else | |
State.Terminate(false) | |
| Mystream.End -> State.Terminate(true) | |
else if c = '.' then | |
match lookahead with | |
Mystream.Cons(c', _) -> | |
if (c' >= '0' && c' <= '9') then | |
State.State(three) | |
else | |
State.Terminate(false) | |
| Mystream.End -> State.Terminate(false) | |
else | |
State.Terminate(false) | |
and two (stream : char Mystream.mystream) : State.state = | |
match stream with | |
Mystream.End -> State.Terminate(true) | |
| Mystream.Cons(c, _) -> | |
let lookahead = (Mystream.tl stream) () in | |
if (c = '.') then | |
match lookahead with | |
Mystream.Cons(c', _) -> | |
if (c' >= '0' && c' <= '9') then | |
State.State(three) | |
else | |
State.Terminate(false) | |
| Mystream.End -> State.Terminate(false) | |
else | |
State.Terminate(false) | |
and three (stream : char Mystream.mystream) : State.state = | |
match stream with | |
Mystream.End -> State.Terminate(true) | |
| Mystream.Cons(c, _) -> | |
let lookahead = (Mystream.tl stream) () in | |
if (c >= '0' && c <= '9') then | |
match lookahead with | |
Mystream.Cons(c', _) -> | |
if (c' >= '0' && c' <= '9') then | |
State.State(three) | |
else | |
State.Terminate(false) | |
| Mystream.End -> State.Terminate(true) | |
else | |
State.Terminate(false) | |
in | |
match s with | |
Mystream.End -> State.Terminate(false) | |
| _ -> one s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment