ast

package
Version: v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataStructureMap = map[DataStructure]string{
	IntType:    "int",
	StringType: "string",
	BoolType:   "bool",
	VoidType:   "void",
}
View Source
var OperatorMap = map[Operator]string{
	Plus:     "+",
	Minus:    "-",
	Bang:     "!",
	Asterisk: "*",
	Slash:    "/",
	Mod:      "%",
	LT:       "<",
	GT:       ">",
	LTE:      "<=",
	GTE:      ">=",
	EQ:       "==",
	NOT_EQ:   "!=",
	LAND:     "&&",
	LOR:      "||",
}

Functions

This section is empty.

Types

type AssignStatement

type AssignStatement struct {
	Type     DataStructure
	Variable Identifier
	Value    Expression
}

Represent assign statement

func (*AssignStatement) String

func (a *AssignStatement) String() string

type BlockStatement

type BlockStatement struct {
	Statements []Statement
}

Represent block statement

func (*BlockStatement) String

func (b *BlockStatement) String() string

type BooleanLiteral

type BooleanLiteral struct {
	Value bool
}

Represent Boolean expression

func (*BooleanLiteral) String

func (b *BooleanLiteral) String() string

type CallExpression

type CallExpression struct {
	Function  Expression
	Arguments []Expression
}

Represent Call expression

func (*CallExpression) String

func (c *CallExpression) String() string

type Contract

type Contract struct {
	Functions []*FunctionLiteral
}

Represent Contract. Contract consists of multiple functions.

func (*Contract) String

func (c *Contract) String() string

type DataStructure

type DataStructure int

DataStructure represent identifier's data structure e.g. string, int, bool

const (
	IntType DataStructure
	StringType
	BoolType
	VoidType
)

func (DataStructure) String

func (ds DataStructure) String() string

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Represent Expression

type ExpressionStatement

type ExpressionStatement struct {
	Expr Expression
}

Represent function statement

func (*ExpressionStatement) String

func (e *ExpressionStatement) String() string

type FunctionLiteral

type FunctionLiteral struct {
	Name       *Identifier
	Parameters []*ParameterLiteral
	Body       *BlockStatement
	ReturnType DataStructure
}

FunctionLiteral represents function definition e.g. func foo(int a) { ... }

func (*FunctionLiteral) Signature

func (f *FunctionLiteral) Signature() string

func (*FunctionLiteral) String

func (f *FunctionLiteral) String() string

type Identifier

type Identifier struct {
	Name string
}

Represent identifier

func (*Identifier) String

func (i *Identifier) String() string

type IfStatement

type IfStatement struct {
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

Represent if statement

func (*IfStatement) String

func (i *IfStatement) String() string

type InfixExpression

type InfixExpression struct {
	Left Expression
	Operator
	Right Expression
}

Repersent Infix expression

func (*InfixExpression) String

func (i *InfixExpression) String() string

type IntegerLiteral

type IntegerLiteral struct {
	Value int64
}

Represent integer literal

func (*IntegerLiteral) String

func (i *IntegerLiteral) String() string

type Node

type Node interface {
	String() string
}

Node represent ast node

type Operator

type Operator int

Operator represent operator between expression

const (
	Plus     Operator // +
	Minus             // -
	Bang              // !
	Asterisk          // *
	Slash             // /
	Mod               // %
	LT                // <
	GT                // >
	LTE               // <=
	GTE               // >=
	EQ                // ==
	NOT_EQ            // !=
	LAND              // &&
	LOR               // ||
)

func (Operator) String

func (o Operator) String() string

type ParameterLiteral

type ParameterLiteral struct {
	Identifier *Identifier
	Type       DataStructure
}

Represent Function Parameter expression

func (*ParameterLiteral) String

func (p *ParameterLiteral) String() string

type PrefixExpression

type PrefixExpression struct {
	Operator
	Right Expression
}

Represent prefix expression

func (*PrefixExpression) String

func (p *PrefixExpression) String() string

type ReassignStatement

type ReassignStatement struct {
	Variable *Identifier
	Value    Expression
}

ReassignStatement is used when we want re-assign value to variable

func (*ReassignStatement) String

func (r *ReassignStatement) String() string

type ReturnStatement

type ReturnStatement struct {
	ReturnValue Expression
}

Represent return statement

func (*ReturnStatement) String

func (r *ReturnStatement) String() string

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Represent Statement

type StringLiteral

type StringLiteral struct {
	Value string
}

Represent string literal

func (*StringLiteral) String

func (s *StringLiteral) String() string

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL