Language.Pascal.Types
- type Id = String
- data Annotate node ann = Annotate {
- content :: node
- annotation :: ann
- data SrcPos = SrcPos {}
- data TypeAnn = TypeAnn {}
- type :~ node ann = Annotate (node ann) ann
- withType :: Annotate a SrcPos -> Type -> Annotate a TypeAnn
- setType :: Annotate Symbol a -> Type -> Annotate Symbol a
- annotate :: ann -> Annotate node old -> Annotate node ann
- data Program a = Program {
- progConsts :: [(Id, Expression :~ a)]
- progTypes :: Map Id Type
- progVariables :: [Annotate Symbol a]
- progFunctions :: [Function :~ a]
- progBody :: [Statement :~ a]
- data Function a = Function {}
- type SymbolTable = [Map Id Symbol]
- data Symbol = Symbol {
- symbolName :: Id
- symbolType :: Type
- symbolDefLine :: Int
- symbolDefCol :: Int
- showSymbol :: Symbol -> String
- symbolNameC :: Annotate Symbol ann -> Id
- symbolTypeC :: Annotate Symbol ann -> Type
- typeOfA :: Annotate node TypeAnn -> Type
- (#) :: Id -> Type -> Symbol
- data Type
- data LValue a
- data Statement a
- = Assign (LValue :~ a) (Expression :~ a)
- | Procedure Id [Expression :~ a]
- | Return (Expression :~ a)
- | Break
- | Continue
- | Exit
- | IfThenElse (Expression :~ a) [Statement :~ a] [Statement :~ a]
- | For Id (Expression :~ a) (Expression :~ a) [Statement :~ a]
- data Lit
- data Expression a
- = Variable Id
- | ArrayItem Id (Expression :~ a)
- | RecordField Id Id
- | Literal Lit
- | Call Id [Expression :~ a]
- | Op BinOp (Expression :~ a) (Expression :~ a)
- data BinOp
- data TError = TError {
- errLine :: Int
- errColumn :: Int
- errContext :: Context
- errMessage :: String
- data Context
- = Unknown
- | Outside
- | ProgramBody
- | ForLoop Id Int
- | InFunction Id Type
- contextId :: Context -> String
- data CheckState = CheckState {
- userTypes :: Map Id Type
- userConsts :: [(Id, Expression :~ TypeAnn)]
- symbolTable :: SymbolTable
- contexts :: [Context]
- ckLine :: Int
- ckColumn :: Int
- data CodeGenState = CGState {}
- emptyGState :: CodeGenState
- newtype Generate a = Generate {
- runGenerate :: ErrorT TError (State CodeGenState) a
- newtype Check a = Check {
- runCheck :: ErrorT TError (State CheckState) a
- class Monad m => Checker m where
- enterContext :: Context -> m ()
- dropContext :: m ()
- failCheck :: String -> m a
- inContext :: Checker m => Context -> m a -> m a
Documentation
Attach annotation to node
Constructors
Annotate | |
Fields
|
Position of node in the source code
Node type info
Program
Constructors
Program | |
Fields
|
Function (or procedure)
Constructors
Function | |
type SymbolTable = [Map Id Symbol]Source
Symbol table
A symbol
Constructors
Symbol | |
Fields
|
showSymbol :: Symbol -> StringSource
symbolNameC :: Annotate Symbol ann -> IdSource
symbolTypeC :: Annotate Symbol ann -> TypeSource
Supported data types
Assignment LHS value: variable or array item
Program statements
Constructors
Assign (LValue :~ a) (Expression :~ a) | lvalue := expression; |
Procedure Id [Expression :~ a] | procedureName(arguments); |
Return (Expression :~ a) | return expression; |
Break | break (for loop) |
Continue | contnune (for loop) |
Exit | exit (procedure or program) |
IfThenElse (Expression :~ a) [Statement :~ a] [Statement :~ a] | if expression then ... else ... |
For Id (Expression :~ a) (Expression :~ a) [Statement :~ a] | for i := start to end do ... |
Literal values
data Expression a Source
Expressions
Constructors
Variable Id | named variable value |
ArrayItem Id (Expression :~ a) | array item |
RecordField Id Id | record field |
Literal Lit | literal value |
Call Id [Expression :~ a] | functionName(arguments) |
Op BinOp (Expression :~ a) (Expression :~ a) | binary operation (x+y etc) |
Instances
Typed Expression | |
Eq a => Eq (Expression a) | |
Show (Expression a) | |
CodeGen (Expression TypeAnn) | |
CodeGen (:~ Expression TypeAnn) |
Supported binary operations
Compiler error
Constructors
TError | |
Fields
|
Compiler context (where we are?)
Constructors
Unknown | unknown context (== internal error) |
Outside | Outside program body or functions |
ProgramBody | In the program body |
ForLoop Id Int | In the for loop (started on nth instruction, with named counter) |
InFunction Id Type | In the named function (returning named type) |
data CheckState Source
Type checker state
Constructors
CheckState | |
Fields
|
Instances
emptyGState :: CodeGenStateSource
Starting code generator state
Constructors
Generate | |
Fields
|
Instances