Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module randall.Parser
- open System
- type Token = AddT | SubT | MulT | DivT | ExpT | DT | GT | LT | OpT | CpT | NumT of int
- let rec lex s =
- if String.length s = 0 then [] else
- match s.[0] with
- | '+' -> AddT :: lex s.[1..]
- | '-' -> SubT :: lex s.[1..]
- | '*' -> MulT :: lex s.[1..]
- | '/' -> DivT :: lex s.[1..]
- | '^' -> ExpT :: lex s.[1..]
- | 'd' -> DT :: lex s.[1..]
- | 'g' -> GT :: lex s.[1..]
- | 'l' -> LT :: lex s.[1..]
- | '(' -> OpT :: lex s.[1..]
- | ')' -> CpT :: lex s.[1..]
- | d when d > '/' && d < ':' -> tokenize_num s
- | c when c < '!' -> lex s.[1..]
- | c -> failwith ("Illegal character: " + Char.ToString c)
- and tokenize_num s =
- let rec select (s : string) n len =
- if len = 0 then n else
- if s.[0] > '/' && s.[0] < ':' then
- select s.[1..] (n + 1) (len - 1)
- else n
- in
- let fin = select s 0 (String.length s) in
- NumT (int s.[..fin - 1]) :: lex s.[fin..]
- type Rpg0 = Single of Rpg1 * Rpg01
- | Debug
- and Rpg01 = Add of Rpg1 * Rpg01
- | Sub of Rpg1 * Rpg01
- | Nil
- | Debug
- and Rpg1 = Single of Rpg2 * Rpg11
- | Debug
- and Rpg11 = Mul of Rpg2 * Rpg11
- | Div of Rpg2 * Rpg11
- | Nil
- | Debug
- and Rpg2 = Single of All * Rpg21
- | Debug
- and Rpg21 = Exp of All * Rpg21
- | Nil
- | Debug
- and All = A of Loop
- | B of Loop * Loop
- | Next of G_Dice
- | Debug
- and G_Dice = A of Loop
- | B of Loop * Loop
- | C of Loop * Loop
- | D of Loop * Loop * Loop
- | Next of L_Dice
- | Debug
- and L_Dice = A of Loop
- | B of Loop * Loop
- | C of Loop * Loop
- | D of Loop * Loop * Loop
- | Next of Loop
- | Debug
- and Loop = Num of int
- | Closed of Rpg0
- | Debug
- let rpg0 (t : Token list ref) : Rpg0 = Rpg0.Debug
- let rpg01 (t : Token list ref) : Rpg01 = Rpg01.Debug
- let rpg1 (t : Token list ref) : Rpg1 = Rpg1.Debug
- let rpg11 (t : Token list ref) : Rpg11 = Rpg11.Debug
- let rpg2 (t : Token list ref) : Rpg2 = Rpg2.Debug
- let rpg21 (t : Token list ref) : Rpg21 = Rpg21.Debug
- let all (t : Token list ref) : All = All.Debug
- let g_dice (t : Token list ref) : G_Dice = G_Dice.Debug
- let l_dice (t : Token list ref) : L_Dice = L_Dice.Debug
- let loop (t : Token list ref) : Loop = Loop.Debug
Add Comment
Please, Sign In to add comment