From 2788df88e6261ac641adf9f39bbfe517a7d77d9c Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 19 Jul 2017 12:25:45 +0000 Subject: Add else if --- Sil/Parse.icl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'Sil/Parse.icl') diff --git a/Sil/Parse.icl b/Sil/Parse.icl index 3a11622..2e21d08 100644 --- a/Sil/Parse.icl +++ b/Sil/Parse.icl @@ -138,17 +138,18 @@ initialisation = pure [{init_type=t, init_name=n} \\ n <- ns] statement :: Parser Token Statement -statement = ((declaration - <|> liftM Application application +statement = declaration + <|> liftM Application (application <* item TSemicolon) <|> return <|> if` - /*<|> while*/) <* item TSemicolon) <|> machinecode + //<|> while + <|> machinecode where declaration :: Parser Token Statement - declaration = liftM2 Declaration name (item TAssign *> application) + declaration = liftM2 Declaration name (item TAssign *> application <* item TSemicolon) return :: Parser Token Statement - return = liftM Return (item TReturn *> optional application) + return = liftM Return (item TReturn *> optional application <* item TSemicolon) machinecode :: Parser Token Statement machinecode = (\(TMachineCode s) -> MachineStm s) <$> satisfy isMachineCode @@ -158,8 +159,14 @@ where if` = item TIf *> parenthised application >>= \cond -> braced codeblock >>= \iftrue -> + many elseif >>= \elseifs -> optional (item TElse *> braced codeblock) >>= \iffalse -> - pure $ If cond iftrue iffalse + pure $ If [(cond,iftrue):elseifs] iffalse + where + elseif = list [TElse, TIf] *> + parenthised application >>= \cond -> + braced codeblock >>= \block -> + pure (cond, block) application :: Parser Token Application application -- cgit v1.2.3