src

package
v0.0.0-...-be41600 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpAst

func DumpAst(w io.Writer, ast Ast)

Prints the AST.

func DumpTokens

func DumpTokens(w io.Writer, tokens []Token)

Print all the tokens

func SowoCompileFile

func SowoCompileFile(options CompilerOptions)

Compiles a sowo program file given some options

Types

type Ast

type Ast struct {
	Type             AstType
	Children         []*Ast
	Name             string
	DataType         TypeAnnotation
	NumberDataValue  int
	BooleanDataValue bool
	StringDataValue  string
	Operator         BinaryOperator
}

func (Ast) String

func (ast Ast) String() (ret string)

type AstType

type AstType int
const (
	AstNoop AstType = iota
	AstModule
	AstFunction
	AstFuncArgs
	AstFuncReturnType
	AstBlock
	AstStatement
	AstVariable
	AstTypeAnnotation
	AstLocalVariable
	AstExpression
	AstAssignment
	AstBinaryOp
	AstNumberLiteral
	AstBooleanLiteral
	AstStringLiteral
	AstVariableRef
	AstIf
	AstWhile
	AstFuncCall
	AstReturn
	AstPrint
)

func (AstType) MarshalJSON

func (t AstType) MarshalJSON() ([]byte, error)

func (AstType) String

func (t AstType) String() (ret string)

type BinaryOperator

type BinaryOperator int

Represents the operator of a binary operation.

const (
	OpPlus BinaryOperator = iota
	OpMinus
	OpTimes
	OpDivide
	OpEquals
	OpLessThen
	OpGreaterThen
	OpLessThenEqual
	OpGreaterThenEqual
)

func (BinaryOperator) MarshalJSON

func (op BinaryOperator) MarshalJSON() ([]byte, error)

func (BinaryOperator) String

func (op BinaryOperator) String() (ret string)

type CFrontend

type CFrontend struct {
	Imports      []string
	MainFunction string
	Functions    []string
}

type CompilerOptions

type CompilerOptions struct {
	PrintTokens bool
	PrintAst    bool
	SaveTokens  bool
	SaveAst     bool
	SkipCompile bool
	InputFile   string
	OutputFile  string
}

Represents a set of options used by the compiler.

type Lexer

type Lexer struct {
	// The program string in input.
	Input string
}

Struct representing a lexer.

type Parser

type Parser struct {
	// List of tokens that need to be parsed
	Tokens []Token
}

Represent a parser with methods to parse a list of tokens into a Module.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

func (Scope) String

func (s Scope) String() string

type Token

type Token struct {
	// Type of the token.
	Type TokenType
	// Value of the token.
	Value string
}

Represent a single Token.

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int

Represent all the possible token types.

const (
	TokenFunc TokenType = iota
	TokenSymbol
	TokenOpenParen
	TokenCloseParen
	TokenOpenCurly
	TokenCloseCurly
	TokenVar
	TokenColon
	TokenComma
	TokenEqual
	TokenEqualEqual
	TokenLessThen
	TokenGreaterThen
	TokenLessThenEqual
	TokenGreaterThenEqual
	TokenSemicolon
	TokenPlus
	TokenMinus
	TokenAsterisk
	TokenSlash
	TokenIf
	TokenElse
	TokenWhile
	TokenNumberLiteral
	TokenStringLiteral
	TokenHash
	TokenReturn
	TokenTrue
	TokenFalse
	TokenPrint
)

func (TokenType) String

func (tt TokenType) String() (ret string)

type TypeAnnotation

type TypeAnnotation int

Represents the type of a variable. It can be:

  • Void
  • Integer
const (
	TypeVoid TypeAnnotation = iota
	TypeInteger
	TypeBoolean
	TypeString
)

func (TypeAnnotation) MarshalJSON

func (t TypeAnnotation) MarshalJSON() ([]byte, error)

func (TypeAnnotation) String

func (t TypeAnnotation) String() (ret string)

type VarDef

type VarDef struct {
	Name string
	Type TypeAnnotation
}

func (VarDef) String

func (vd VarDef) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL