added while looping construct
This commit is contained in:
@@ -11,6 +11,7 @@ data ZorthExpr = ZorthASTInteger Int
|
||||
| ZorthASTWord String
|
||||
| ZorthASTWordDecl (String,ZorthAST)
|
||||
| ZorthASTIfElse (ZorthAST,ZorthAST)
|
||||
| ZorthASTWhile (ZorthAST,ZorthAST)
|
||||
deriving Show
|
||||
|
||||
word1 :: Parser String
|
||||
@@ -41,7 +42,6 @@ pZorthInteger :: Parser ZorthExpr
|
||||
pZorthInteger = do
|
||||
skipNonsenseSymbols
|
||||
i <- pZorthSignedInteger <|> pZorthUnsignedInteger
|
||||
eof <|> void nonsenseSymbol
|
||||
return i
|
||||
|
||||
pZorthWord :: Parser ZorthExpr
|
||||
@@ -64,8 +64,15 @@ pZorthIfElse = do
|
||||
elseBranch <- manyTill pZorthExpr (do { ZorthASTWord "fi" <- pZorthWord; return () })
|
||||
return $ ZorthASTIfElse (ifBranch,elseBranch)
|
||||
|
||||
pZorthWhile :: Parser ZorthExpr
|
||||
pZorthWhile = do
|
||||
ZorthASTWord "begin" <- pZorthWord
|
||||
condition <- manyTill pZorthExpr (do { ZorthASTWord "while" <- pZorthWord; return () })
|
||||
body <- manyTill pZorthExpr (do { ZorthASTWord "repeat" <- pZorthWord; return () })
|
||||
return $ ZorthASTWhile (condition,body)
|
||||
|
||||
pZorthExpr :: Parser ZorthExpr
|
||||
pZorthExpr = pZorthIfElse <|> pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
pZorthExpr = pZorthWhile <|> pZorthIfElse <|> pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
|
||||
pZorth :: Parser ZorthAST
|
||||
pZorth = some pZorthExpr
|
||||
|
||||
Reference in New Issue
Block a user