aboutsummaryrefslogtreecommitdiff
path: root/Sil/Parse.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-19 12:25:45 +0000
committerCamil Staps2017-07-19 12:25:45 +0000
commit2788df88e6261ac641adf9f39bbfe517a7d77d9c (patch)
tree49ee4f4932dccf4b06782bd4879898dfa6fdfe4e /Sil/Parse.icl
parentAdd readme and license (diff)
Add else if
Diffstat (limited to 'Sil/Parse.icl')
-rw-r--r--Sil/Parse.icl19
1 files changed, 13 insertions, 6 deletions
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