{-# LANGUAGE QuasiQuotes #-}
module Examples.Sqrt where
import Text.RawString.QQ

sq :: String
sq = [r|B:
	None P e, R, P 1; NEW

NEW:
    e R; MARKDIGITS
    AnyAndNone L; NEW

MARKDIGITS:
    0 R, P x, R; MARKDIGITS
    1 R, P x, R; MARKDIGITS
    None R, P z, R, R, P r; FINDX

FINDX:
    x E; FIRSTR
    e N; FINDDIGITS
    AnyAndNone L,L; FINDX

FIRSTR:
    r R,R; LASTR
    AnyAndNone R,R; FIRSTR

LASTR:
    r R,R; LASTR
    None P r, R, R, P r; FINDX

FINDDIGITS:
    e R,R; FIND1STDIGIT
    AnyAndNone L,L; FINDDIGITS

FIND1STDIGIT:
    x L; FOUND1STDIGIT
    y L; FOUND1STDIGIT
    z L; FOUND2NDDIGIT
    None R,R; FIND1STDIGIT

FOUND1STDIGIT:
    0 R; ADDZERO
    1 R,R,R; FIND2NDDIGIT

FIND2NDDIGIT:
    x L; FOUND2NDDIGIT
    y L; FOUND2NDDIGIT
    None R,R; FIND2NDDIGIT

FOUND2NDDIGIT:
    0 R; ADDZERO
    1 R; ADDONE
    None R; ADDONE

ADDZERO:
    r P s; ADDFINISHED
    u P v; ADDFINISHED
    AnyAndNone R, R; ADDZERO

ADDONE:
    r P v; ADDFINISHED
    u P s, R, R; CARRY
    AnyAndNone R,R; ADDONE

CARRY:
    r P u; ADDFINISHED
    None P u; NEWDIGITISZERO
    u P r, R, R; CARRY

ADDFINISHED:
    e R,R; ERASEOLDX
    AnyAndNone L,L; ADDFINISHED

ERASEOLDX:
    x E,L,L; PRINTNEWX
    z P y, L, L; PRINTNEWX
    AnyAndNone R,R; ERASEOLDX

PRINTNEWX:
    e R,R; ERASEOLDY
    y P z; FINDDIGITS
    None P x; FINDDIGITS

ERASEOLDY:
    y E, L, L; PRINTNEWY
    AnyAndNone R,R; ERASEOLDY

PRINTNEWY:
    e R; NEWDIGITISONE
    AnyAndNone P y, R; RESETNEWX

RESETNEWX:
    None R, P x; FLAGRESULTDIGITS
    AnyAndNone R,R; RESETNEWX

FLAGRESULTDIGITS:
    s P t, R, R; UNFLAGRESULTDIGITS
    v P w, R, R; UNFLAGRESULTDIGITS
    AnyAndNone R, R; FLAGRESULTDIGITS

UNFLAGRESULTDIGITS:
    s P r, R, R; UNFLAGRESULTDIGITS
    v P u, R, R; UNFLAGRESULTDIGITS
    AnyAndNone N; FINDDIGITS

NEWDIGITISZERO:
    e R; PRINTZERODIGIT
    AnyAndNone L; NEWDIGITISZERO

PRINTZERODIGIT:
    0 R,E,R; PRINTZERODIGIT
    1 R,E,R; PRINTZERODIGIT
    None P 0, R, R, R; CLEANUP

NEWDIGITISONE:
    e R; PRINTONEDIGIT
    AnyAndNone L; NEWDIGITISONE

PRINTONEDIGIT:
    0 R,E,R; PRINTONEDIGIT
    1 R,E,R; PRINTONEDIGIT
    None P 1, R, R, R; CLEANUP

CLEANUP:
    None N; NEW
    AnyAndNone E,R,R; CLEANUP
|]
