tools/PascalParser.hs
changeset 6357 52cb4807a78c
parent 6355 734fed7aefd3
child 6386 7d7703b26bda
equal deleted inserted replaced
6355:734fed7aefd3 6357:52cb4807a78c
    59     | PostfixOp String Expression
    59     | PostfixOp String Expression
    60     | BinOp String Expression Expression
    60     | BinOp String Expression Expression
    61     | StringLiteral String
    61     | StringLiteral String
    62     | CharCode String
    62     | CharCode String
    63     | NumberLiteral String
    63     | NumberLiteral String
       
    64     | FloatLiteral String
    64     | HexNumber String
    65     | HexNumber String
    65     | Reference Reference
    66     | Reference Reference
    66     | Null
    67     | Null
    67     deriving Show
    68     deriving Show
    68 data Reference = ArrayElement [Expression] Reference
    69 data Reference = ArrayElement [Expression] Reference
    69     | FunCall [Expression] Reference
    70     | FunCall [Expression] Reference
       
    71     | BuiltInFunCall [Expression] Reference
    70     | SimpleReference Identifier
    72     | SimpleReference Identifier
    71     | Dereference Reference
    73     | Dereference Reference
    72     | RecordField Reference Reference
    74     | RecordField Reference Reference
    73     | Address Reference
    75     | Address Reference
    74     deriving Show
    76     deriving Show
    82     | InitHexNumber String
    84     | InitHexNumber String
    83     | InitString String
    85     | InitString String
    84     | InitChar String
    86     | InitChar String
    85     | InitNull
    87     | InitNull
    86     deriving Show
    88     deriving Show
       
    89 
    87     
    90     
    88 pascalLanguageDef
    91 pascalLanguageDef
    89     = emptyDef
    92     = emptyDef
    90     { commentStart   = "(*"
    93     { commentStart   = "(*"
    91     , commentEnd     = "*)"
    94     , commentEnd     = "*)"
    98             , "implementation", "and", "or", "xor", "shl"
   101             , "implementation", "and", "or", "xor", "shl"
    99             , "shr", "while", "do", "repeat", "until", "case", "of"
   102             , "shr", "while", "do", "repeat", "until", "case", "of"
   100             , "type", "var", "const", "out", "array", "packed"
   103             , "type", "var", "const", "out", "array", "packed"
   101             , "procedure", "function", "with", "for", "to"
   104             , "procedure", "function", "with", "for", "to"
   102             , "downto", "div", "mod", "record", "set", "nil"
   105             , "downto", "div", "mod", "record", "set", "nil"
   103             , "string", "shortstring"
   106             , "string", "shortstring", "succ", "pred", "low"
       
   107             , "high"
   104             ]
   108             ]
   105     , reservedOpNames= [] 
   109     , reservedOpNames= [] 
   106     , caseSensitive  = False   
   110     , caseSensitive  = False   
   107     }
   111     }
   108     
   112     
   381 
   385 
   382 expression = buildExpressionParser table term <?> "expression"
   386 expression = buildExpressionParser table term <?> "expression"
   383     where
   387     where
   384     term = comments >> choice [
   388     term = comments >> choice [
   385         parens pas $ expression 
   389         parens pas $ expression 
       
   390         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
       
   391         , try $ float pas >>= return . FloatLiteral . show
   386         , try $ integer pas >>= return . NumberLiteral . show
   392         , try $ integer pas >>= return . NumberLiteral . show
   387         , stringLiteral pas >>= return . StringLiteral
   393         , stringLiteral pas >>= return . StringLiteral
   388         , char '#' >> many digit >>= return . CharCode
   394         , char '#' >> many digit >>= return . CharCode
   389         , char '$' >> many hexDigit >>= return . HexNumber
   395         , char '$' >> many hexDigit >>= return . HexNumber
   390         , try $ string "nil" >> return Null
   396         , try $ string "nil" >> return Null