added conditions and if else branching
This commit is contained in:
@@ -10,6 +10,7 @@ type ZorthAST = [ZorthExpr]
|
||||
data ZorthExpr = ZorthASTInteger Int
|
||||
| ZorthASTWord String
|
||||
| ZorthASTWordDecl (String,ZorthAST)
|
||||
| ZorthASTIfElse (ZorthAST,ZorthAST)
|
||||
deriving Show
|
||||
|
||||
word1 :: Parser String
|
||||
@@ -55,8 +56,16 @@ pZorthWordDecl = do
|
||||
xs <- manyTill pZorthExpr (do { ZorthASTWord ";" <- pZorthWord; return () })
|
||||
return $ ZorthASTWordDecl (name,xs)
|
||||
|
||||
|
||||
pZorthIfElse :: Parser ZorthExpr
|
||||
pZorthIfElse = do
|
||||
ZorthASTWord "if" <- pZorthWord
|
||||
ifBranch <- manyTill pZorthExpr (do { ZorthASTWord "else" <- pZorthWord; return () })
|
||||
elseBranch <- manyTill pZorthExpr (do { ZorthASTWord "fi" <- pZorthWord; return () })
|
||||
return $ ZorthASTIfElse (ifBranch,elseBranch)
|
||||
|
||||
pZorthExpr :: Parser ZorthExpr
|
||||
pZorthExpr = pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
pZorthExpr = pZorthIfElse <|> pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
|
||||
pZorth :: Parser ZorthAST
|
||||
pZorth = some pZorthExpr
|
||||
|
||||
Reference in New Issue
Block a user