- Parse sets initialization
authorunc0rr
Thu, 17 Nov 2011 17:57:45 +0400
changeset 6391 bd5851ab3157
parent 6390 3807d4cad077
child 6392 f2ef5a8cccb4
- Parse sets initialization - Render interface part of unit;
tools/PascalParser.hs
tools/pas2c.hs
--- a/tools/PascalParser.hs	Wed Nov 16 16:36:17 2011 -0500
+++ b/tools/PascalParser.hs	Thu Nov 17 17:57:45 2011 +0400
@@ -85,6 +85,7 @@
     | InitString String
     | InitChar String
     | BuiltInFunction String [InitExpression]
+    | InitSet [Identifier]
     | InitNull
     deriving Show
 
@@ -577,6 +578,7 @@
     where
     term = comments >> choice [
         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression 
+        , try $ brackets pas (commaSep pas $ iD) >>= return . InitSet
         , try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray
         , parens pas (semiSep pas $ recField) >>= return . InitRecord
         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
--- a/tools/pas2c.hs	Wed Nov 16 16:36:17 2011 -0500
+++ b/tools/pas2c.hs	Thu Nov 17 17:57:45 2011 +0400
@@ -15,8 +15,13 @@
          (Right a) -> (return . render . pascal2C) a
 
 pascal2C :: PascalUnit -> Doc
-pascal2C (Unit unitName interface implementation init fin) = implementation2C implementation
+pascal2C (Unit unitName interface implementation init fin) = 
+    interface2C interface
+    $+$ 
+    implementation2C implementation
 
+interface2C :: Interface -> Doc
+interface2C (Interface uses tvars) = typesAndVars2C tvars
 
 implementation2C :: Implementation -> Doc
 implementation2C (Implementation uses tvars) = typesAndVars2C tvars
@@ -48,7 +53,15 @@
     initExpr Nothing = empty
     initExpr (Just e) = text "=" <+> initExpr2C e
 
-initExpr2C :: InitExpression -> Doc    
+initExpr2C :: InitExpression -> Doc
+initExpr2C (InitBinOp op expr1 expr2) = parens $ (initExpr2C expr1) <+> op2C op <+> (initExpr2C expr2)
+initExpr2C (InitNumber s) = text s
+initExpr2C (InitFloat s) = text s
+initExpr2C (InitHexNumber s) = text "0x" <> (text . map toLower $ s)
+initExpr2C (InitString s) = doubleQuotes $ text s 
+initExpr2C (InitReference (Identifier i)) = text i
+
+
 initExpr2C _ = text "<<expression>>"
 
 type2C :: TypeDecl -> Doc