Skip to content

Instantly share code, notes, and snippets.

@LukaHorvat
Created December 24, 2014 16:52
Show Gist options
  • Save LukaHorvat/dfc33a97b4f9578f7e09 to your computer and use it in GitHub Desktop.
Save LukaHorvat/dfc33a97b4f9578f7e09 to your computer and use it in GitHub Desktop.
connectStatement :: String -> State -> Statement -> State
connectStatement name state stmt = case stmt of
AST.Line expr -> connectExpression name expr state
AST.If cond th el -> let s = connectStatement name (connectExpression name state cond) th in case el of
Just ex -> connectExpression name s ex
Nothing -> s
AST.While cond s -> connectStatement name (connectEpxression name state cond) s
AST.Routine ss -> foldl (connectStatement name) state ss
_ ->
let (this, expr) = case stmt of
AST.Assignment s e -> (Variable name s, e)
AST.Return e -> (Return name, e)
in case expr of
AST.Number _ -> addType this Number state
AST.String _ -> addType this String state
AST.Boolean _ -> addType this Boolean state
AST.Variable v -> addConnection this (Variable name v) state
AST.Application f es -> addConnection this (Return f) $ foldl (connectExpression name) state es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment