Changeset 3421 for proto


Ignore:
Timestamp:
Aug 2, 2013, 9:16:42 AM (6 years ago)
Author:
cameron
Message:

Convert to non-curried form

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/doc/mre_compiler.hs

    r3412 r3421  
    1010-- characters for the first prototype.
    1111
    12 data MRE = Ch Char | Cat MRE MRE | Alt MRE MRE | Star Char 
     12data MRE = Ch(Char) | Cat(MRE, MRE) | Alt(MRE, MRE) | Star(Char) 
    1313   deriving Show   -- deriving Show just means Haskell can print MREs
    1414
     
    2020-- (Marker 1), (Marker 2) ...
    2121
    22 data PabloE = Marker Int | And PabloE PabloE | Or PabloE PabloE | Not PabloE
    23               | CharClass Char | Advance PabloE | MatchStar PabloE PabloE
     22data PabloE = Marker(Int) | And(PabloE, PabloE) | Or(PabloE, PabloE) | Not(PabloE)
     23              | CharClass(Char) | Advance(PabloE) | MatchStar(PabloE, PabloE)
    2424   deriving Show
    2525
     
    2727-- assigment and a return statement for now.
    2828
    29 data PabloS = SetMarker Int PabloE | ReturnMarker Int     
     29data PabloS = SetMarker(Int, PabloE) | ReturnMarker(Int)     
    3030   deriving Show
    3131
     
    3838compile :: MRE -> [PabloS]
    3939
    40 compile e = stmts ++ [ReturnMarker m]
    41   where (m, stmts) = mre2pablo_helper e 0
     40compile(e) = stmts ++ [ReturnMarker m]
     41  where (m, stmts) = mre2pablo_helper(e, 0)
    4242
    43 mre2pablo_helper :: MRE -> Int -> (Int, [PabloS])
     43mre2pablo_helper :: (MRE, Int) -> (Int, [PabloS])
    4444
    4545-- To match a character class, use bitwise and of the marker and
     
    4747-- is the next one in sequence.
    4848
    49 mre2pablo_helper (Ch c) m =
    50    (m + 1, [SetMarker (m + 1) (Advance (And (Marker m) (CharClass c)))])
     49mre2pablo_helper(Ch(c), m) =
     50   (m + 1, [SetMarker (m + 1, Advance(And(Marker(m), CharClass(c))))])
    5151
    5252-- A concatenation of two regular expressions is compiled by first
     
    5555-- be the output of the first.
    5656
    57 mre2pablo_helper (Cat e1 e2) m = (m2, s1 ++ s2)
     57mre2pablo_helper(Cat(e1, e2), m) = (m2, s1 ++ s2)
    5858  where
    59    (m1, s1) = mre2pablo_helper e1 m 
    60    (m2, s2) = mre2pablo_helper e2 m1
     59   (m1, s1) = mre2pablo_helper(e1, m)
     60   (m2, s2) = mre2pablo_helper(e2, m1)
    6161
    6262-- An alternation of two regular expressions needs a copy of the
    6363-- input to be saved first.   
    6464
    65 mre2pablo_helper (Alt e1 e2) m = (m2 + 1, save ++ s1 ++ s2 ++ final)
     65mre2pablo_helper(Alt(e1, e2), m) = (m2 + 1, save ++ s1 ++ s2 ++ final)
    6666  where
    67    (m1, s1) = mre2pablo_helper e1 m 
    68    (m2, s2) = mre2pablo_helper e2 (m1 + 1)
    69    save = [SetMarker (m1 + 1) (Marker m)]
    70    final = [SetMarker (m2 + 1) (Or (Marker m1) (Marker m2))]
     67   (m1, s1) = mre2pablo_helper(e1, m) 
     68   (m2, s2) = mre2pablo_helper(e2, m1 + 1)
     69   save = [SetMarker(m1 + 1, Marker(m))]
     70   final = [SetMarker(m2 + 1, Or(Marker(m1), Marker(m2)))]
    7171
    7272-- For a repeated character class, just use MatchStar.
    7373
    74 mre2pablo_helper (Star c) m =
    75    (m + 1, [SetMarker (m + 1) (MatchStar (Marker m) (CharClass c))])
     74mre2pablo_helper(Star(c), m) =
     75   (m + 1, [SetMarker(m + 1, MatchStar(Marker(m), CharClass(c)))])
    7676
Note: See TracChangeset for help on using the changeset viewer.