mini-go-0.3.0.0: Mini Go parser and interpreter
Safe HaskellSafe-Inferred
LanguageHaskell2010

Parser.Ast

Description

Contains all AST elements, all of these produced by the Parser module.

Synopsis

Program

data Program Source #

The head of the AST.

Constructors

Program 

Fields

Instances

Instances details
Show Program Source # 
Instance details

Defined in Parser.Ast

data FunctionDef Source #

Function definition.

Constructors

FunctionDef 

Instances

Instances details
Show FunctionDef Source # 
Instance details

Defined in Parser.Ast

Expressions

data Expression Source #

Expression.

Constructors

ExprValue Value

Value expression, see Value.

ExprIdentifier Identifier

Identifier expression, see Identifier.

ExprUnaryOp UnaryOp Expression

Unary operation expression (e.g., !x, -4), see UnaryOp.

ExprBinaryOp BinaryOp Expression Expression

Binary operation expression (e.g., x + 7), see BinaryOp.

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 function call expression.

len("abcd") // returns 4
len([100] int {}) // returns 100
ExprPrintFuncCall [Expression]

print function call expression.

print("some logs...") // prints "some logs..."
print(3 + 6)  // prints "9"
print("abc", 2) // prints "abc2"
ExprPrintlnFuncCall [Expression]

println function call expression.

println("some logs...") // prints "some logs...\n"
println(3 + 6)  // prints "9\n"
println("abc", 2) // prints "abc 2\n"
ExprPanicFuncCall Expression

panic function call expression.

panic("ERROR!!!") // fails with "panic: ERROR!!!\n"

Instances

Instances details
Show Expression Source # 
Instance details

Defined in Parser.Ast

Operators

data BinaryOp Source #

Binary operators.

Constructors

OrOp

Or operator (a || b), works only for bool.

AndOp

And operator (a && b), works only for bool.

EqOp

Equality operator (a == b).

NeOp

Inequality operator (a != b).

LeOp

Less than or equal operator (a <= b), works only for int and string.

LtOp

Less than operator (a < b), works only for int and string.

MeOp

More than or equal operator (a >= b), works only for int and string.

MtOp

More than operator (a > b), works only for int and string.

PlusOp

Plus operator (a + b), works only for int and string.

MinusOp

Minus operator (a - b), works only for int.

MultOp

Multiply operator (a * b), works only for int.

DivOp

Divide operator (a / b), works only for int.

ModOp

Modulus operator (a % b), works only for int.

Instances

Instances details
Show BinaryOp Source # 
Instance details

Defined in Parser.Ast

data UnaryOp Source #

Unary operators.

Constructors

UnaryPlusOp

Unary plus operator (+a), works only for int.

UnaryMinusOp

Unary minus operator (-a), works only for int.

NotOp

Not operator (!a), works only for bool.

Instances

Instances details
Show UnaryOp Source # 
Instance details

Defined in Parser.Ast

Types

data Type Source #

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 ArrayType.

TFunction FunctionType

Function type, see FunctionType.

Instances

Instances details
Show Type Source # 
Instance details

Defined in Parser.Ast

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

data ArrayType Source #

Array type, it contains the length of the array and its elements type.

[3 + 4] int

Constructors

ArrayType 

Instances

Instances details
Show ArrayType Source # 
Instance details

Defined in Parser.Ast

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 

Instances

Instances details
Show FunctionType Source # 
Instance details

Defined in Parser.Ast

Statements

data Statement Source #

Statement.

Constructors

StmtReturn (MaybeVoid Expression)

Return statement with optional return value.

StmtForGoTo ForGoTo

For goto statement, see ForGoTo.

StmtFor For

For statement, see For.

StmtVarDecl VarDecl

Var declaration statement, see VarDecl.

StmtIfElse IfElse

If-else statement, see IfElse.

StmtBlock Block

Block statement, see Block.

{ 34; foo(34); if true {} else {}; return 17; }
StmtSimple SimpleStmt

Simple statement, see SimpleStmt.

Instances

Instances details
Show Statement Source # 
Instance details

Defined in Parser.Ast

type Block = [Statement] Source #

Block of statements.

data ForGoTo Source #

For goto statement (either break or continue), should be inside for.

Constructors

Break

Break statement.

Continue

Continue statement.

Instances

Instances details
Show ForGoTo Source # 
Instance details

Defined in Parser.Ast

data For Source #

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;

Constructors

For 

Fields

Instances

Instances details
Show For Source # 
Instance details

Defined in Parser.Ast

Methods

showsPrec :: Int -> For -> ShowS #

show :: For -> String #

showList :: [For] -> ShowS #

data ForHead Source #

For statement, can represent any of the 3 possible for kinds.

Instances

Instances details
Show ForHead Source # 
Instance details

Defined in Parser.Ast

data VarDecl Source #

Var declaration.

var x int = 3
var y = "hello"
var z int

Constructors

VarDecl 

Instances

Instances details
Show VarDecl Source # 
Instance details

Defined in Parser.Ast

data VarValue Source #

Var value.

Instances

Instances details
Show VarValue Source # 
Instance details

Defined in Parser.Ast

data IfElse Source #

If-else statement.

if i < 42 { return "hello"; } else { return "goodbye"; }
if true { println("hello"); }

Instances

Instances details
Show IfElse Source # 
Instance details

Defined in Parser.Ast

data Else Source #

Else part of the if-else statement.

Constructors

NoElse 
Else Block 
Elif IfElse 

Instances

Instances details
Show Else Source # 
Instance details

Defined in Parser.Ast

Methods

showsPrec :: Int -> Else -> ShowS #

show :: Else -> String #

showList :: [Else] -> ShowS #

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., x = 17, a[3] = "42").

StmtIncDec Lvalue IncDec

Increment or decrement statement (e.g., x++, a[3]++, x--, a[3]--).

StmtShortVarDecl Identifier Expression

Short var declaration statement (e.g., x := 3, y := true).

StmtExpression Expression

Expression statement.

Instances

Instances details
Show SimpleStmt Source # 
Instance details

Defined in Parser.Ast

data Lvalue Source #

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., x = 3, x++).

LvalArrEl Identifier [Expression]

Any array element can be lvalue (e.g., a[5][7] = 3, a[0]++).

Instances

Instances details
Show Lvalue Source # 
Instance details

Defined in Parser.Ast

data IncDec Source #

Increment or decrement.

Constructors

Inc 
Dec 

Instances

Instances details
Show IncDec Source # 
Instance details

Defined in Parser.Ast

Values

data Value Source #

Literal, array, or function value.

Constructors

ValInt Integer

Int literal value (e.g., 17, 0xFF, 0b101001).

ValBool Bool

Boolean literal value (e.g., true, false).

ValString Text

String literal value (e.g., "Hello", "", "Some\ntext").

ValArray ArrayValue

Array value, see ArrayValue.

ValFunction FunctionValue

Function value, see FunctionValue.

Instances

Instances details
Show Value Source # 
Instance details

Defined in Parser.Ast

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

data ArrayValue Source #

Array value.

[3] int {1, 2}
[10] bool {}

Constructors

ArrayValue 

Instances

Instances details
Show ArrayValue Source # 
Instance details

Defined in Parser.Ast

data FunctionValue Source #

Function value.

Constructors

AnonymousFunction Function

Anonymous function, see Function.

func (x int) int { return x * x; }
func () {}
Nil

Null literal (nil).

Instances

Instances details
Show FunctionValue Source # 
Instance details

Defined in Parser.Ast

data Function Source #

Function representation without name.

It contains the result of the function, its parameters, and its body.

Instances

Instances details
Show Function Source # 
Instance details

Defined in Parser.Ast

type Identifier = Text Source #

Any valid identifier (e.g., he42llo, _42).