semantics

package
v0.0.0-...-21e7071 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreCompatibleTypes

func AreCompatibleTypes(a, b types.Type) bool

AreCompatibleTypes checks whether type provided types are 'compatible'.

func IsOrdinalType

func IsOrdinalType(t types.Type) bool

func IsSimpleType

func IsSimpleType(t types.Type) bool

Types

type Boolean

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

Boolean ...

func NewBoolean

func NewBoolean(name string, kind Kind, typ types.Type) *Boolean

NewBoolean creates and returns a new real-type symbol

func (*Boolean) Depth

func (b *Boolean) Depth() int

Depth ...

func (*Boolean) Kind

func (b *Boolean) Kind() Kind

Kind returns the kind of this symbol

func (*Boolean) Name

func (b *Boolean) Name() string

Name returns the name of this symbol

func (*Boolean) SetDepth

func (b *Boolean) SetDepth(d int)

SetDepth ...

func (*Boolean) SetVar

func (b *Boolean) SetVar(sym Symbol)

SetVar ...

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) Type

func (b *Boolean) Type() types.Type

Type returns the type of this symbol

func (*Boolean) Var

func (b *Boolean) Var() Symbol

Var ...

type Char

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

Char ...

func NewChar

func NewChar(name string, kind Kind, typ types.Type) *Char

NewChar creates and returns a new integer-type symbol

func (*Char) Depth

func (c *Char) Depth() int

Depth ...

func (*Char) Kind

func (c *Char) Kind() Kind

Kind returns the kind of this symbol

func (*Char) Name

func (c *Char) Name() string

Name returns the name of this symbol

func (*Char) SetDepth

func (c *Char) SetDepth(d int)

SetDepth ...

func (*Char) SetVar

func (c *Char) SetVar(sym Symbol)

SetVar ...

func (*Char) String

func (c *Char) String() string

func (*Char) Type

func (c *Char) Type() types.Type

Type returns the type of this symbol

func (*Char) Var

func (c *Char) Var() Symbol

Var ...

type Const

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

Const denotes a constant symbol

func NewConst

func NewConst(name string, kind Kind, typ types.Type, val ast.Expression) *Const

NewConst creates and returns a new constant symbol

func (*Const) Depth

func (c *Const) Depth() int

Depth ...

func (*Const) Kind

func (c *Const) Kind() Kind

Kind returns the kind of this symbol

func (*Const) Name

func (c *Const) Name() string

Name returns the name of this symbol

func (*Const) SetDepth

func (c *Const) SetDepth(d int)

SetDepth ...

func (*Const) SetVar

func (c *Const) SetVar(sym Symbol)

SetVar ...

func (*Const) String

func (c *Const) String() string

func (*Const) Type

func (c *Const) Type() types.Type

Type returns the type of this symbol

func (*Const) Value

func (c *Const) Value() ast.Expression

func (*Const) Var

func (c *Const) Var() Symbol

Var ...

type Field

type Field struct {
	Offset uint64
	// contains filtered or unexported fields
}

Field denotes a record field symbol

func NewField

func NewField(name string, kind Kind, typ types.Type, offset uint64) *Field

NewField creates and returns a new field symbol

func (*Field) Depth

func (f *Field) Depth() int

Depth ...

func (*Field) Kind

func (f *Field) Kind() Kind

Kind returns the kind of this symbol

func (*Field) Name

func (f *Field) Name() string

Name returns the name of this symbol

func (*Field) SetDepth

func (f *Field) SetDepth(d int)

SetDepth ...

func (*Field) SetVar

func (f *Field) SetVar(sym Symbol)

SetVar ...

func (*Field) String

func (f *Field) String() string

func (*Field) Type

func (f *Field) Type() types.Type

Type returns the type of this symbol

func (*Field) Var

func (f *Field) Var() Symbol

Var ...

type Function

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

Function denotes a function symbol

func NewFunction

func NewFunction(name string, kind Kind, typ types.Type) *Function

NewFunction creates and returns a new function symbol

func NewProcedure

func NewProcedure(name string, kind Kind, typ types.Type) *Function

NewProcedure creates and returns a new procedure symbol

func (*Function) Depth

func (f *Function) Depth() int

Depth ...

func (*Function) Kind

func (f *Function) Kind() Kind

Kind returns the kind of this symbol

func (*Function) Name

func (f *Function) Name() string

Name returns the name of this symbol

func (*Function) SetDepth

func (f *Function) SetDepth(d int)

SetDepth ...

func (*Function) SetVar

func (f *Function) SetVar(sym Symbol)

SetVar ...

func (*Function) String

func (f *Function) String() string

func (*Function) Type

func (f *Function) Type() types.Type

Type returns the type of this symbol

func (*Function) Var

func (f *Function) Var() Symbol

Var ...

type Integer

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

Integer ...

func NewInteger

func NewInteger(name string, kind Kind, typ types.Type) *Integer

NewInteger creates and returns a new integer-type symbol

func (*Integer) Depth

func (i *Integer) Depth() int

Depth ...

func (*Integer) Kind

func (i *Integer) Kind() Kind

Kind returns the kind of this symbol

func (*Integer) Name

func (i *Integer) Name() string

Name returns the name of this symbol

func (*Integer) SetDepth

func (i *Integer) SetDepth(d int)

SetDepth ...

func (*Integer) SetVar

func (i *Integer) SetVar(sym Symbol)

SetVar ...

func (*Integer) String

func (i *Integer) String() string

func (*Integer) Type

func (i *Integer) Type() types.Type

Type returns the type of this symbol

func (*Integer) Var

func (i *Integer) Var() Symbol

Var ...

type Kind

type Kind byte

Kind denotes the category of the symbol. e.g. variable, function

const (
	VARIABLE Kind = iota
	FUNCTION
	PROCEDURE
	TYPE
	CONST
	LABEL
	FIELD
)

type LValueVisitor

type LValueVisitor struct {
	Visitor
}

LValueVisitor ...

func (*LValueVisitor) VisitFieldDesignator

func (l *LValueVisitor) VisitFieldDesignator(f *ast.FieldDesignator) error

func (*LValueVisitor) VisitIdentifier

func (l *LValueVisitor) VisitIdentifier(id *ast.Identifier) error

VisitIdentifier ...

func (*LValueVisitor) VisitIndexedVariable

func (l *LValueVisitor) VisitIndexedVariable(iv *ast.IndexedVariable) error

VisitIndexedVariable ...

type Label

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

Label denotes a label symbol

func NewLabel

func NewLabel(name string, kind Kind, typ types.Type) *Label

NewLabel returns a new label symbol

func (*Label) Depth

func (l *Label) Depth() int

Depth ...

func (*Label) Kind

func (l *Label) Kind() Kind

Kind returns the kind of this symbol

func (*Label) Name

func (l *Label) Name() string

Name returns the name of this symbol

func (*Label) SetDepth

func (l *Label) SetDepth(d int)

SetDepth ...

func (*Label) SetVar

func (l *Label) SetVar(sym Symbol)

SetVar ...

func (*Label) String

func (l *Label) String() string

func (*Label) Type

func (l *Label) Type() types.Type

Type returns the type of this symbol

func (*Label) Var

func (l *Label) Var() Symbol

Var ...

type Procedure

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

Procedure denotes a procedure symbol

func (*Procedure) Depth

func (p *Procedure) Depth() int

Depth ...

func (*Procedure) Kind

func (p *Procedure) Kind() Kind

Kind returns the kind of this symbol

func (*Procedure) Name

func (p *Procedure) Name() string

Name returns the name of this symbol

func (*Procedure) SetDepth

func (p *Procedure) SetDepth(d int)

SetDepth ...

func (*Procedure) SetVar

func (p *Procedure) SetVar(sym Symbol)

SetVar ...

func (*Procedure) String

func (p *Procedure) String() string

func (*Procedure) Type

func (p *Procedure) Type() types.Type

Type returns the type of this symbol

func (*Procedure) Var

func (p *Procedure) Var() Symbol

Var ...

type Real

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

Real ...

func NewReal

func NewReal(name string, kind Kind, typ types.Type) *Real

NewReal creates and returns a new real-type symbol

func (*Real) Depth

func (r *Real) Depth() int

Depth ...

func (*Real) Kind

func (r *Real) Kind() Kind

Kind returns the kind of this symbol

func (*Real) Name

func (r *Real) Name() string

Name returns the name of this symbol

func (*Real) SetDepth

func (r *Real) SetDepth(d int)

SetDepth ...

func (*Real) SetVar

func (r *Real) SetVar(sym Symbol)

SetVar ...

func (*Real) String

func (r *Real) String() string

func (*Real) Type

func (r *Real) Type() types.Type

Type returns the type of this symbol

func (*Real) Var

func (r *Real) Var() Symbol

Var ...

type Scope

type Scope interface {
	OpenScope()
	CloseScope()
	EnterSymbol(string, Symbol)
	RetrieveSymbol(string) Symbol
	DeclaredLocally(string) bool
}

Scope ...

type Symbol

type Symbol interface {
	Name() string
	Kind() Kind
	Type() types.Type

	Depth() int
	Var() Symbol
	SetVar(Symbol)
	SetDepth(int)
}

Symbol denotes a generic symbol

type SymbolTable

type SymbolTable struct {
	Depth        int
	Table        map[string]Symbol
	ScopeDisplay map[int][]Symbol
}

SymbolTable ...

func NewSymbolTable

func NewSymbolTable() *SymbolTable

NewSymbolTable ...

func (*SymbolTable) CloseScope

func (w *SymbolTable) CloseScope()

CloseScope ...

func (*SymbolTable) DeclaredLocally

func (w *SymbolTable) DeclaredLocally(name string) bool

DeclaredLocally ...

func (*SymbolTable) EnterSymbol

func (w *SymbolTable) EnterSymbol(name string, sym Symbol)

EnterSymbol ...

func (*SymbolTable) OpenScope

func (w *SymbolTable) OpenScope()

OpenScope ...

func (*SymbolTable) RetrieveSymbol

func (w *SymbolTable) RetrieveSymbol(name string) Symbol

RetrieveSymbol ...

type TypeDef

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

TypeDef ...

func NewTypeDef

func NewTypeDef(name string, kind Kind, typ types.Type) *TypeDef

NewTypeDef returns a new type definition symbol

func (*TypeDef) Depth

func (t *TypeDef) Depth() int

Depth ...

func (*TypeDef) Kind

func (t *TypeDef) Kind() Kind

Kind returns the kind of this symbol

func (*TypeDef) Name

func (t *TypeDef) Name() string

Name returns the name of this symbol

func (*TypeDef) SetDepth

func (t *TypeDef) SetDepth(d int)

SetDepth ...

func (*TypeDef) SetVar

func (t *TypeDef) SetVar(sym Symbol)

SetVar ...

func (*TypeDef) String

func (t *TypeDef) String() string

func (*TypeDef) Type

func (t *TypeDef) Type() types.Type

Type ...

func (*TypeDef) Var

func (t *TypeDef) Var() Symbol

Var ...

type Variable

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

Variable denotes a variable symbol

func NewVariable

func NewVariable(name string, kind Kind, typ types.Type) *Variable

NewVariable returns a new variable symbol type

func (*Variable) Depth

func (v *Variable) Depth() int

Depth ...

func (*Variable) Kind

func (v *Variable) Kind() Kind

Kind returns the kind of this symbol

func (*Variable) Name

func (v *Variable) Name() string

Name returns the name of this symbol

func (*Variable) SetDepth

func (v *Variable) SetDepth(d int)

SetDepth ...

func (*Variable) SetVar

func (v *Variable) SetVar(sym Symbol)

SetVar ...

func (*Variable) String

func (v *Variable) String() string

func (*Variable) Type

func (v *Variable) Type() types.Type

Type returns the type of this symbol

func (*Variable) Var

func (v *Variable) Var() Symbol

Var ...

type Visitor

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

Visitor ...

func NewSemaVisitor

func NewSemaVisitor(program *ast.Program, symTable *SymbolTable) *Visitor

func (*Visitor) AreAssignmentCompatible

func (s *Visitor) AreAssignmentCompatible(src ast.Expression, dest ast.Expression) bool

AreAssignmentCompatible checks whether the provided types are 'assignment-compatible'. Any types T1 is said to be 'assignment-compatible' with T2 if any of the following conditions are satisfied:

a) T1 and T2 are the same type, and that type is permissible as the component-type of a file-type (see 6.4.3.5). b) T1 is the real-type and T2 is the integer-type. c) T1 and T2 are compatible ordinal-types, and the value of type T2 is in the closed interval specified by the type T1. d) T1 and T2 are compatible set-types, and all the members of the value of type T2 are in the closed interval specified by the base-type of T1. e) T1 and T2 are compatible string-types.

func (*Visitor) VisitAssignStmt

func (s *Visitor) VisitAssignStmt(a *ast.AssignStatement) error

VisitAssignStmt ...

func (*Visitor) VisitBinaryExpr

func (s *Visitor) VisitBinaryExpr(b *ast.BinaryExpression) error

func (*Visitor) VisitBlock

func (s *Visitor) VisitBlock(blk *ast.Block) error

func (*Visitor) VisitBoolLiteral

func (s *Visitor) VisitBoolLiteral(b *ast.BoolLiteral) error

func (*Visitor) VisitCaseStatement

func (s *Visitor) VisitCaseStatement(cse *ast.CaseStatement) error

func (*Visitor) VisitCompoundStatement

func (s *Visitor) VisitCompoundStatement(cs *ast.CompoundStatement) error

func (*Visitor) VisitConstDef

func (s *Visitor) VisitConstDef(constDef *ast.ConstDefinition) error

func (*Visitor) VisitFieldDesignator

func (s *Visitor) VisitFieldDesignator(f *ast.FieldDesignator) error

func (*Visitor) VisitForStatement

func (s *Visitor) VisitForStatement(f *ast.ForStatement) error

func (*Visitor) VisitFuncDeclaration

func (s *Visitor) VisitFuncDeclaration(f *ast.FuncDeclaration) error

func (*Visitor) VisitFuncDesignator

func (s *Visitor) VisitFuncDesignator(f *ast.FuncDesignator) error

func (*Visitor) VisitFuncHeading

func (s *Visitor) VisitFuncHeading(f *ast.FuncHeading) error

func (*Visitor) VisitGotoStatement

func (s *Visitor) VisitGotoStatement(g *ast.GotoStatement) error

func (*Visitor) VisitIdentifiedVariable

func (s *Visitor) VisitIdentifiedVariable(i *ast.IdentifiedVariable) error

func (*Visitor) VisitIdentifier

func (s *Visitor) VisitIdentifier(id *ast.Identifier) error

VisitIdentifier ...

func (*Visitor) VisitIfStatement

func (s *Visitor) VisitIfStatement(i *ast.IfStatement) error

func (*Visitor) VisitIndexedVariable

func (s *Visitor) VisitIndexedVariable(iv *ast.IndexedVariable) error

VisitIndexedVariable ...

func (*Visitor) VisitLabelDef

func (s *Visitor) VisitLabelDef(label *ast.LabelDefinition) error

func (*Visitor) VisitNil

func (s *Visitor) VisitNil(n *ast.NilValue) error

func (*Visitor) VisitProcedureDecl

func (s *Visitor) VisitProcedureDecl(p *ast.ProcedureDeclaration) error

func (*Visitor) VisitProcedureHeading

func (s *Visitor) VisitProcedureHeading(p *ast.ProcedureHeading) error

func (*Visitor) VisitProcedureStmt

func (s *Visitor) VisitProcedureStmt(p *ast.ProcedureStmt) error

func (*Visitor) VisitProgram

func (s *Visitor) VisitProgram() error

func (*Visitor) VisitRange

func (s *Visitor) VisitRange(r *ast.Range) error

func (*Visitor) VisitRead

func (s *Visitor) VisitRead(r *ast.Read) error

func (*Visitor) VisitReadLn

func (s *Visitor) VisitReadLn(r *ast.ReadLn) error

func (*Visitor) VisitRepeatStatement

func (s *Visitor) VisitRepeatStatement(rpt *ast.RepeatStatement) error

func (*Visitor) VisitReturnStatement

func (s *Visitor) VisitReturnStatement(ret *ast.ReturnStatement) error

func (*Visitor) VisitSetConstructor

func (s *Visitor) VisitSetConstructor(st *ast.SetConstructor) error

func (*Visitor) VisitStrLiteral

func (s *Visitor) VisitStrLiteral(str *ast.StrLiteral) error

func (*Visitor) VisitTypeDef

func (s *Visitor) VisitTypeDef(types *ast.TypeDefinition) error

func (*Visitor) VisitUIntLiteral

func (s *Visitor) VisitUIntLiteral(i *ast.UIntegerLiteral) error

VisitUIntLiteral ...

func (*Visitor) VisitURealLiteral

func (s *Visitor) VisitURealLiteral(ur *ast.URealLiteral) error

func (*Visitor) VisitUnaryExpr

func (s *Visitor) VisitUnaryExpr(u *ast.UnaryExpression) error

func (*Visitor) VisitValueParam

func (s *Visitor) VisitValueParam(v *ast.ValueParam) error

func (*Visitor) VisitVarDecl

func (s *Visitor) VisitVarDecl(decl *ast.VarDeclaration) error

func (*Visitor) VisitVariableParam

func (s *Visitor) VisitVariableParam(v *ast.VariableParam) error

func (*Visitor) VisitWhileStatement

func (s *Visitor) VisitWhileStatement(whl *ast.WhileStatement) error

func (*Visitor) VisitWithStatement

func (s *Visitor) VisitWithStatement(with *ast.WithStatement) error

func (*Visitor) VisitWrite

func (s *Visitor) VisitWrite(w *ast.Write) error

func (*Visitor) VisitWriteParameter

func (s *Visitor) VisitWriteParameter(w *ast.WriteParameter) error

func (*Visitor) VisitWriteln

func (s *Visitor) VisitWriteln(w *ast.Writeln) error

Jump to

Keyboard shortcuts

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