htcc-0.0.0.1: The full scratch implementation of tiny C compiler (x86_64)
Copyright(c) roki 2019
LicenseMIT
Maintainerfalgon53@yahoo.co.jp
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Htcc.Parser.Parsing.Type

Description

The module of the Type parsing

Synopsis

Constant

type ConstantResult i = Maybe (ASTError i) Source #

The Just represents an error during construction of the syntax tree, and the Nothing represents no valid constant expression.

constantExp :: forall i. (Bits i, Integral i, Show i, Read i) => [TokenLC i] -> ConstructionData i -> Either (ConstantResult i) ([TokenLC i], i) Source #

constantExp evaluates to a constant expression from token list.

Utilities

isTypeName :: TokenLC i -> ConstructionData i -> Bool Source #

isTypeName returns True if the token is a type name, False otherwise.

Structure and Enum

takeStructFields :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text (StructMember i), ConstructionData i) Source #

\[ \begin{array}{ccc} \text{struct-decl}&=&\text{"struct"}\ \text{ident?}\ \left(\text{"\{"}\ \text{struct-member}\ \text{"\}"}\right)\text{?}\\ \text{struct-member}&=&\text{pre-type}\ \text{declaration}\ \text{array-decl-suffix}\ \text{";"} \end{array} \]

takeEnumFiels :: (Integral i, Show i, Read i, Bits i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (Map Text i, ConstructionData i) Source #

\[ \begin{array}{ccc} \text{enum-specifier}&=&\text{"enum"}\ \text{ident}\ \mid\ \text{"enum"}\ \text{ident?}\ \text{"\{"}\ \text{enum-list?}\ \text{"\}"}\\ \text{enum-list}&=&\text{enum-elem}\ \left(\text{","}\ \text{enum-elem}\right)\ast\ \text{","?}\\ \text{enum-elem}&=&\text{ident}\ \left(\text{"="}\ \text{const-expr}\right)\text{?} \end{array} \]

Declarations

arrayDeclSuffix :: forall i. (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Maybe (Either (ASTError i) (StorageClass i, [TokenLC i])) Source #

HT.TKReserved "[", n, HT.TKReserved "]" from the beginning of the token sequence. arrayDeclSuffix constructs an array type of the given type t based on the token sequence if \(k\leq 1\), wraps it in Right and Just and returns it with the rest of the token sequence. If the token HT.TKReserved "[" exists at the beginning of the token sequence, but the subsequent token sequence is invalid as an array declaration in C programming language, an error mesage and the token at the error location are returned wrapped in Left and Just. When \(k=0\), Nothing is returned.

\[ \text{array-decl-suffix}=\left(\text{"["}\ \text{const-expr?}\ \text{"]"}\ \text{array-decl-suffix}\right)\text{?} \]

absDeclaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i]) Source #

absDeclaration parses abstract type declarations:

\[ \text{abs-declaration} = \text{"*"*}\ \left(\text{"("}\ \text{abs-declaration}\ \text{")"}\right)\text{?}\ \text{array-decl-suffix} \]

declaration :: (Integral i, Bits i, Show i, Read i) => StorageClass i -> [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i]) Source #

\[ \text{declaration} = \text{"*"*}\ \left(\text{"("}\ \text{declaration}\ \text{")"}\ \mid\ \text{ident}\right)\ \text{array-decl-suffix} \]

Type

takePreType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i], ConstructionData i) Source #

It is obtained by parsing the front part of the type from the token string. e.g. int (*)[4] applied to this function yields int.

\[\begin{array}{ccc} \text{pre-type}&=&\text{builtin-type}\ \mid\ \text{struct-decl}\ \mid\ \text{typedef-name}\ \mid\ \text{enum-specifier}\\ \text{builtin-type}&=&\text{"void"}\ \mid\ \text{"_Bool"}\ \mid\ \text{"char"}\ \mid\ \text{"short"}\ \mid\ \text{"int"}\ \mid\ \text{"long"}\ \mid\ \text{"long "long"} \end{array} \]

takeType :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, Maybe (TokenLC i), [TokenLC i], ConstructionData i) Source #

takeType returns a pair of type (including pointer and array type) and the remaining tokens wrapped in Just only if the token starts with TKType, TKStruct or identifier that is declarated by typedef. Otherwise Nothing is returned.

\[ \text{type}=\text{pre-type}\ \text{declaration} \]

takeTypeName :: (Integral i, Show i, Read i, Bits i) => [TokenLC i] -> ConstructionData i -> Either (ASTError i) (StorageClass i, [TokenLC i]) Source #

takeTypeName is used to parse type names used for sizeof etc. Version without takeTypes identifier.