53 | Phrases [Phrase] |
53 | Phrases [Phrase] |
54 | SwitchCase Expression [(Expression, Phrase)] (Maybe Phrase) |
54 | SwitchCase Expression [(Expression, Phrase)] (Maybe Phrase) |
55 | Assignment Reference Expression |
55 | Assignment Reference Expression |
56 deriving Show |
56 deriving Show |
57 data Expression = Expression String |
57 data Expression = Expression String |
|
58 | BuiltInFunCall [Expression] Reference |
58 | PrefixOp String Expression |
59 | PrefixOp String Expression |
59 | PostfixOp String Expression |
60 | PostfixOp String Expression |
60 | BinOp String Expression Expression |
61 | BinOp String Expression Expression |
61 | StringLiteral String |
62 | StringLiteral String |
62 | CharCode String |
63 | CharCode String |
66 | Reference Reference |
67 | Reference Reference |
67 | Null |
68 | Null |
68 deriving Show |
69 deriving Show |
69 data Reference = ArrayElement [Expression] Reference |
70 data Reference = ArrayElement [Expression] Reference |
70 | FunCall [Expression] Reference |
71 | FunCall [Expression] Reference |
71 | BuiltInFunCall [Expression] Reference |
|
72 | SimpleReference Identifier |
72 | SimpleReference Identifier |
73 | Dereference Reference |
73 | Dereference Reference |
74 | RecordField Reference Reference |
74 | RecordField Reference Reference |
75 | Address Reference |
75 | Address Reference |
76 deriving Show |
76 deriving Show |
101 , "implementation", "and", "or", "xor", "shl" |
103 , "implementation", "and", "or", "xor", "shl" |
102 , "shr", "while", "do", "repeat", "until", "case", "of" |
104 , "shr", "while", "do", "repeat", "until", "case", "of" |
103 , "type", "var", "const", "out", "array", "packed" |
105 , "type", "var", "const", "out", "array", "packed" |
104 , "procedure", "function", "with", "for", "to" |
106 , "procedure", "function", "with", "for", "to" |
105 , "downto", "div", "mod", "record", "set", "nil" |
107 , "downto", "div", "mod", "record", "set", "nil" |
106 , "string", "shortstring"--, "succ", "pred", "low" |
108 , "string", "shortstring" |
107 --, "high" |
109 ] ++ builtin |
108 ] |
|
109 , reservedOpNames= [] |
110 , reservedOpNames= [] |
110 , caseSensitive = False |
111 , caseSensitive = False |
111 } |
112 } |
|
113 |
|
114 caseInsensitiveString s = do |
|
115 mapM_ (\a -> satisfy (\b -> toUpper a == toUpper b)) s <?> s |
|
116 return s |
112 |
117 |
113 pas = patch $ makeTokenParser pascalLanguageDef |
118 pas = patch $ makeTokenParser pascalLanguageDef |
114 where |
119 where |
115 patch tp = tp {stringLiteral = sl} |
120 patch tp = tp {stringLiteral = sl} |
116 sl = do |
121 sl = do |
389 return $ Implementation u (TypesAndVars tv) |
394 return $ Implementation u (TypesAndVars tv) |
390 |
395 |
391 expression = buildExpressionParser table term <?> "expression" |
396 expression = buildExpressionParser table term <?> "expression" |
392 where |
397 where |
393 term = comments >> choice [ |
398 term = comments >> choice [ |
394 parens pas $ expression |
399 builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n)) |
|
400 , parens pas $ expression |
395 , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
401 , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
396 , try $ float pas >>= return . FloatLiteral . show |
402 , try $ float pas >>= return . FloatLiteral . show |
397 , try $ integer pas >>= return . NumberLiteral . show |
403 , try $ integer pas >>= return . NumberLiteral . show |
398 , stringLiteral pas >>= return . StringLiteral |
404 , stringLiteral pas >>= return . StringLiteral |
399 , char '#' >> many digit >>= return . CharCode |
405 , char '#' >> many digit >>= return . CharCode |
568 return u |
574 return u |
569 |
575 |
570 initExpression = buildExpressionParser table term <?> "initialization expression" |
576 initExpression = buildExpressionParser table term <?> "initialization expression" |
571 where |
577 where |
572 term = comments >> choice [ |
578 term = comments >> choice [ |
573 try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray |
579 liftM (uncurry BuiltInFunction) $ builtInFunction initExpression |
|
580 , try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray |
574 , parens pas (semiSep pas $ recField) >>= return . InitRecord |
581 , parens pas (semiSep pas $ recField) >>= return . InitRecord |
575 , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i |
582 , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i |
576 , try $ float pas >>= return . InitFloat . show |
583 , try $ float pas >>= return . InitFloat . show |
|
584 , try $ integer pas >>= return . InitNumber . show |
577 , stringLiteral pas >>= return . InitString |
585 , stringLiteral pas >>= return . InitString |
578 , char '#' >> many digit >>= return . InitChar |
586 , char '#' >> many digit >>= return . InitChar |
579 , char '$' >> many hexDigit >>= return . InitHexNumber |
587 , char '$' >> many hexDigit >>= return . InitHexNumber |
580 , try $ string "nil" >> return InitNull |
588 , try $ string "nil" >> return InitNull |
581 , iD >>= return . InitReference |
589 , iD >>= return . InitReference |
614 , [ Infix (try $ string "shl" >> return (InitBinOp "and")) AssocNone |
622 , [ Infix (try $ string "shl" >> return (InitBinOp "and")) AssocNone |
615 , Infix (try $ string "shr" >> return (InitBinOp "or")) AssocNone |
623 , Infix (try $ string "shr" >> return (InitBinOp "or")) AssocNone |
616 ] |
624 ] |
617 , [Prefix (try (string "not") >> return (InitPrefixOp "not"))] |
625 , [Prefix (try (string "not") >> return (InitPrefixOp "not"))] |
618 ] |
626 ] |
619 |
627 |
|
628 builtInFunction e = do |
|
629 name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin |
|
630 spaces |
|
631 exprs <- many1 e |
|
632 spaces |
|
633 return (name, exprs) |