Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Parser.Ast
Description
Contains all AST elements, all of these produced by the Parser module.
Synopsis
- data Program = Program {}
- data FunctionDef = FunctionDef {
- funcName :: Identifier
- func :: Function
- data Expression
- = ExprValue Value
- | ExprIdentifier Identifier
- | ExprUnaryOp UnaryOp Expression
- | ExprBinaryOp BinaryOp Expression Expression
- | ExprArrayAccessByIndex Expression Expression
- | ExprFuncCall Expression [Expression]
- | ExprLenFuncCall Expression
- | ExprPrintFuncCall [Expression]
- | ExprPrintlnFuncCall [Expression]
- | ExprPanicFuncCall Expression
- data BinaryOp
- data UnaryOp
- data Type
- data ArrayType = ArrayType {}
- data FunctionType = FunctionType {
- funcParamsTs :: [Type]
- funcResultT :: MaybeVoid Type
- data Statement
- type Block = [Statement]
- data ForGoTo
- data For = For {}
- data ForHead = ForHead {}
- data VarDecl = VarDecl {}
- data VarValue
- data IfElse = IfElse {
- ifPreStmt :: Maybe SimpleStmt
- ifCondition :: Expression
- ifBody :: Block
- elseStmt :: Else
- data Else
- data SimpleStmt
- data Lvalue
- data IncDec
- data Value
- data ArrayValue = ArrayValue {
- arrT :: ArrayType
- arrElements :: [Expression]
- data FunctionValue
- data Function = Function {
- funcParams :: [(Identifier, Type)]
- funcResult :: MaybeVoid Type
- funcBody :: Block
- type Identifier = Text
Program
The head of the AST.
Constructors
Program | |
Fields
|
data FunctionDef Source #
Function definition.
Constructors
FunctionDef | |
Fields
|
Instances
Show FunctionDef Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> FunctionDef -> ShowS # show :: FunctionDef -> String # showList :: [FunctionDef] -> ShowS # |
Expressions
data Expression Source #
Expression.
Constructors
ExprValue Value | Value expression, see |
ExprIdentifier Identifier | Identifier expression, see |
ExprUnaryOp UnaryOp Expression | Unary operation expression (e.g., |
ExprBinaryOp BinaryOp Expression Expression | Binary operation expression (e.g., |
ExprArrayAccessByIndex Expression Expression | Array access by index expression. a[3] // func foo() int ([2] int {3, 5})[1 + foo()] |
ExprFuncCall Expression [Expression] | Function call expression. foo(17, x, bar()) (func (x int) int { return x * x; })(3) |
ExprLenFuncCall Expression |
len("abcd") // returns 4 len([100] int {}) // returns 100 |
ExprPrintFuncCall [Expression] |
print("some logs...") // prints "some logs..." print(3 + 6) // prints "9" print("abc", 2) // prints "abc2" |
ExprPrintlnFuncCall [Expression] |
println("some logs...") // prints "some logs...\n" println(3 + 6) // prints "9\n" println("abc", 2) // prints "abc 2\n" |
ExprPanicFuncCall Expression |
panic("ERROR!!!") // fails with "panic: ERROR!!!\n" |
Instances
Show Expression Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> Expression -> ShowS # show :: Expression -> String # showList :: [Expression] -> ShowS # |
Operators
Binary operators.
Constructors
OrOp | Or operator ( |
AndOp | And operator ( |
EqOp | Equality operator ( |
NeOp | Inequality operator ( |
LeOp | Less than or equal operator ( |
LtOp | Less than operator ( |
MeOp | More than or equal operator ( |
MtOp | More than operator ( |
PlusOp | Plus operator ( |
MinusOp | Minus operator ( |
MultOp | Multiply operator ( |
DivOp | Divide operator ( |
ModOp | Modulus operator ( |
Unary operators.
Constructors
UnaryPlusOp | Unary plus operator ( |
UnaryMinusOp | Unary minus operator ( |
NotOp | Not operator ( |
Types
All existing types.
Constructors
TInt | 32-bit/64-bit (depending on the machine) integer type. |
TBool | Boolean type. |
TString | String type. |
TArray ArrayType | Array type, see |
TFunction FunctionType | Function type, see |
Array type, it contains the length of the array and its elements type.
[3 + 4] int
Constructors
ArrayType | |
Fields
|
data FunctionType Source #
Function type, it contains the result of the function and its parameters types.
func (int, string) bool
func ([3] int)
Constructors
FunctionType | |
Fields
|
Instances
Show FunctionType Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> FunctionType -> ShowS # show :: FunctionType -> String # showList :: [FunctionType] -> ShowS # |
Statements
Statement.
Constructors
StmtReturn (MaybeVoid Expression) | Return statement with optional return value. |
StmtForGoTo ForGoTo | For goto statement, see |
StmtFor For | For statement, see |
StmtVarDecl VarDecl | Var declaration statement, see |
StmtIfElse IfElse | If-else statement, see |
StmtBlock Block | Block statement, see { 34; foo(34); if true {} else {}; return 17; } |
StmtSimple SimpleStmt | Simple statement, see |
For goto statement (either break
or continue
), should be inside for
.
For statement, can represent any of the 3 possible for
kinds.
For kind, represents classic for
loop.
for i := 0; i < n; i++ { foo(i * i); }
for ; ; {} // same as `for {}`
While kind, represents classic while
loop.
for i < n { foo(i * i); i = i + 2; }
Loop kind, represents endless loop (while true
).
for { temp := foo(i * i * i); if temp == 108 { break; } i = i + 23;
For statement, can represent any of the 3 possible for
kinds.
Constructors
ForHead | |
Fields |
Var declaration.
var x int = 3
var y = "hello"
var z int
Constructors
VarDecl | |
Fields
|
Var value.
Constructors
VarValue (Maybe Type) Expression | |
DefaultedVarValue Type |
If-else statement.
if i < 42 { return "hello"; } else { return "goodbye"; }
if true { println("hello"); }
Constructors
IfElse | |
Fields
|
Else part of the if-else statement.
data SimpleStmt Source #
Simple statement, its main difference between other statements is that it can be used inside for
"pre" and "post" statements.
for i := 0; i < n; i++ { println(i); }
Constructors
StmtAssignment Lvalue Expression | Assignment statement (e.g., |
StmtIncDec Lvalue IncDec | Increment or decrement statement (e.g., |
StmtShortVarDecl Identifier Expression | Short var declaration statement (e.g., |
StmtExpression Expression | Expression statement. |
Instances
Show SimpleStmt Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> SimpleStmt -> ShowS # show :: SimpleStmt -> String # showList :: [SimpleStmt] -> ShowS # |
Lvalue, i.e. an expression that can be placed on the left-hand side of the assignment, increment, or decrement statements.
Constructors
LvalVar Identifier | Any variable can be lvalue (e.g., |
LvalArrEl Identifier [Expression] | Any array element can be lvalue (e.g., |
Increment or decrement.
Values
Literal, array, or function value.
Constructors
ValInt Integer | Int literal value (e.g., |
ValBool Bool | Boolean literal value (e.g., |
ValString Text | String literal value (e.g., |
ValArray ArrayValue | Array value, see |
ValFunction FunctionValue | Function value, see |
data ArrayValue Source #
Array value.
[3] int {1, 2}
[10] bool {}
Constructors
ArrayValue | |
Fields
|
Instances
Show ArrayValue Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> ArrayValue -> ShowS # show :: ArrayValue -> String # showList :: [ArrayValue] -> ShowS # |
data FunctionValue Source #
Function value.
Constructors
AnonymousFunction Function | Anonymous function, see func (x int) int { return x * x; } func () {} |
Nil | Null literal ( |
Instances
Show FunctionValue Source # | |
Defined in Parser.Ast Methods showsPrec :: Int -> FunctionValue -> ShowS # show :: FunctionValue -> String # showList :: [FunctionValue] -> ShowS # |
Function representation without name.
It contains the result of the function, its parameters, and its body.
Constructors
Function | |
Fields
|
type Identifier = Text Source #
Any valid identifier (e.g., he42llo
, _42
).