Documentation
¶
Index ¶
- func IsBooleanType(dt DataType) bool
- func IsCharType(dt DataType) bool
- type AST
- type Addition
- type AdditionOperator
- type ArrayType
- type AssignmentStatement
- type Block
- type CaseLimb
- type CaseStatement
- type CharExpr
- type CharLiteral
- type CharType
- type CompoundStatement
- type ConstantDefinition
- type ConstantExpr
- type ConstantLiteral
- type DataType
- type DerefExpr
- type EnumType
- type EnumValue
- type EnumValueExpr
- type EnumValueLiteral
- type Expression
- type FieldDesignatorExpr
- type FileType
- type ForStatement
- type FormalParameter
- type FormatExpr
- type FunctionCallExpr
- type FunctionType
- func (t *FunctionType) Equals(dt DataType) bool
- func (t *FunctionType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *FunctionType) Named(_ string) DataType
- func (t *FunctionType) Resolve(b *Block) error
- func (t *FunctionType) TypeName() string
- func (t *FunctionType) TypeString() string
- type GotoStatement
- type IfStatement
- type IndexedVariableExpr
- type IntegerExpr
- type IntegerLiteral
- type IntegerType
- func (t *IntegerType) Equals(dt DataType) bool
- func (t *IntegerType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *IntegerType) Named(name string) DataType
- func (t *IntegerType) Resolve(_ *Block) error
- func (t *IntegerType) TypeName() string
- func (t *IntegerType) TypeString() string
- type Multiplication
- type MultiplicationOperator
- type NilExpr
- type NotExpr
- type PointerType
- func (t *PointerType) Equals(dt DataType) bool
- func (t *PointerType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *PointerType) Named(name string) DataType
- func (t *PointerType) Resolve(b *Block) error
- func (t *PointerType) TypeName() string
- func (t *PointerType) TypeString() string
- type ProcedureCallStatement
- type ProcedureType
- func (t *ProcedureType) Equals(dt DataType) bool
- func (t *ProcedureType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *ProcedureType) Named(_ string) DataType
- func (t *ProcedureType) Resolve(b *Block) error
- func (t *ProcedureType) TypeName() string
- func (t *ProcedureType) TypeString() string
- type RangeExpr
- type RealExpr
- type RealLiteral
- type RealType
- type RecordField
- type RecordType
- func (t *RecordType) Equals(dt DataType) bool
- func (t *RecordType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *RecordType) Named(name string) DataType
- func (t *RecordType) Resolve(b *Block) error
- func (t *RecordType) TypeName() string
- func (t *RecordType) TypeString() string
- type RecordVariant
- type RecordVariantField
- type RelationalExpr
- type RelationalOperator
- type RepeatStatement
- type Routine
- type SetExpr
- type SetType
- type SimpleExpr
- type Statement
- type StatementType
- type StringExpr
- type StringLiteral
- type StringType
- func (t *StringType) Equals(dt DataType) bool
- func (t *StringType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *StringType) Named(name string) DataType
- func (t *StringType) Resolve(_ *Block) error
- func (t *StringType) TypeName() string
- func (t *StringType) TypeString() string
- type SubExpr
- type SubrangeType
- func (t *SubrangeType) Equals(dt DataType) bool
- func (t *SubrangeType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
- func (t *SubrangeType) Named(name string) DataType
- func (t *SubrangeType) Resolve(_ *Block) error
- func (t *SubrangeType) TypeName() string
- func (t *SubrangeType) TypeString() string
- type TermExpr
- type TypeDefinition
- type Variable
- type VariableExpr
- type WhileStatement
- type WithStatement
- type WriteStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBooleanType ¶
IsBooleanType returns true if the provided type is the boolean type, false otherwise.
func IsCharType ¶
IsCharType returns true if the provided type is the char type, false otherwise.
Types ¶
type AST ¶
type AST struct { // Program name Name string // Files provided in the program heading. Files []string // Block contains the top-most block of the program that contains all global // declarations and definitions as well as the main program // to be executed. Block *Block }
AST describes the Abstract Syntax Tree of the parsed Pascal program.
type Addition ¶
type Addition struct { Operator AdditionOperator Term Expression }
Addition describes an addition operator and a term used in a simple expression.
type AdditionOperator ¶
type AdditionOperator string
AdditionOperator describes addition operators. "Addition" is used in a loose sense, is the preferred nomenclature in the Pascal EBNF, and primarily refers to its precedence.
const ( OperatorAdd AdditionOperator = "+" OperatorSubtract AdditionOperator = "-" OperatorOr AdditionOperator = "or" )
type ArrayType ¶
type ArrayType struct { IndexTypes []DataType ElementType DataType Packed bool // contains filtered or unexported fields }
ArrayType describes an array type. IndexTypes contains the types of the dimensions of the array, which must either be a subrange type or an enumerated type. ElementType describes the data type of an individual element of the array. The Packed flag indicates whether the array type is packed or not.
func (*ArrayType) IsCompatibleWith ¶
func (*ArrayType) TypeString ¶
type AssignmentStatement ¶
type AssignmentStatement struct { LeftExpr Expression RightExpr Expression // contains filtered or unexported fields }
AssignmentStatement describes an assignment of a value (the evaluated result from the expression on the right side of the assignment operator) to an assignable expression on the left side of the assignment operator.
func (*AssignmentStatement) Label ¶
func (s *AssignmentStatement) Label() *string
func (*AssignmentStatement) Type ¶
func (s *AssignmentStatement) Type() StatementType
type Block ¶
type Block struct { // Parent points to the block this block belongs to, e.g. a procedure block // declared at the top level points to the program's main block. The program's // main block has no parent. Parent *Block // Routine points to the Routine (procedure or function) this block belongs to. // This field is nil if the block is the program's main block. Routine *Routine // Labels contains all declared Labels in the block. All Labels are unsigned digit sequences. Labels []string // Constants contains all constant definitions in the block. Constants []*ConstantDefinition // Types contains all type definitions in the block. Types []*TypeDefinition // Variables contains all variables declared in the block. Variables []*Variable // EnumValues contains all enum values of a program. If any enum values exists, this is only set in the top-most block. EnumValues []*EnumValue // Procedure contains all procedures declared in the block. Procedures []*Routine // Functions contains all functions declared in the block. Functions []*Routine // Statements contains all Statements declared in the block. Statements []Statement }
Block describes a program block. A program block consists of declarations (label declarations, constant definitions, type definitions, variable declarations and procedure and function delcarations) and the statements associated with the block.
type CaseLimb ¶
type CaseLimb struct { Label []ConstantLiteral Statement Statement }
CaseLimb describes a case limb, which consists of a list of case labels (constants) and a statement.
type CaseStatement ¶
type CaseStatement struct { Expr Expression CaseLimbs []*CaseLimb // contains filtered or unexported fields }
CaseStatement describes a conditional statement. The provided expression is first evaluated, and depending on the value, the first case limb is chosen where the value matches any of the case labels. That case limb's statement is then executed. If no matching case limb can be found, then no statement is executed.
func (*CaseStatement) Label ¶
func (s *CaseStatement) Label() *string
func (*CaseStatement) Type ¶
func (s *CaseStatement) Type() StatementType
type CharExpr ¶
type CharExpr struct {
Value byte
}
func (*CharExpr) IsVariableExpr ¶
func (*CharExpr) Reduce ¶
func (e *CharExpr) Reduce() Expression
type CharLiteral ¶
type CharLiteral struct {
Value byte
}
CharLiteral describes a char literal
func (*CharLiteral) ConstantType ¶
func (l *CharLiteral) ConstantType() DataType
func (*CharLiteral) Negate ¶
func (l *CharLiteral) Negate() (ConstantLiteral, error)
func (*CharLiteral) String ¶
func (l *CharLiteral) String() string
type CharType ¶
type CharType struct {
// contains filtered or unexported fields
}
CharType describes the char type.
func (*CharType) IsCompatibleWith ¶
func (*CharType) TypeString ¶
type CompoundStatement ¶
type CompoundStatement struct { // The list of statements contained in the compound statements. Statements []Statement // contains filtered or unexported fields }
CompoundStatement describes a grouped list of statements.
func (*CompoundStatement) Label ¶
func (s *CompoundStatement) Label() *string
func (*CompoundStatement) Type ¶
func (s *CompoundStatement) Type() StatementType
type ConstantDefinition ¶
type ConstantDefinition struct { Name string Value ConstantLiteral }
type ConstantExpr ¶
ConstantExpr describes an expression that refers to a constant (defined elsewhere in the program) by its name and the type it represents.
func (*ConstantExpr) IsVariableExpr ¶
func (e *ConstantExpr) IsVariableExpr() bool
func (*ConstantExpr) Reduce ¶
func (e *ConstantExpr) Reduce() Expression
func (*ConstantExpr) String ¶
func (e *ConstantExpr) String() string
func (*ConstantExpr) Type ¶
func (e *ConstantExpr) Type() DataType
type ConstantLiteral ¶
type ConstantLiteral interface { ConstantType() DataType Negate() (ConstantLiteral, error) String() string }
ConstantLiteral very generally describes a constant literal.
type DataType ¶
type DataType interface { TypeString() string // TODO: rename to TypeString Equals(dt DataType) bool TypeName() string // non-empty if type was looked up by name (not in type definition). Named(name string) DataType // produces a copy of the data type but with a name. Resolve(b *Block) error IsCompatibleWith(dt DataType, assignmentCompatible bool) bool }
type DerefExpr ¶
type DerefExpr struct {
Expr Expression
}
DerefExpr describes a dereferencing expression, where a pointer is dereferenced to access the memory it points to, either for reading or writing purposes.
func (*DerefExpr) IsVariableExpr ¶
func (*DerefExpr) Reduce ¶
func (e *DerefExpr) Reduce() Expression
type EnumType ¶
type EnumType struct { // List of identifiers. Their indexes are equal to their respective integer values. Identifiers []string // contains filtered or unexported fields }
EnumType describes an enumerated type, consisting of a list of identifiers.
func (*EnumType) IsCompatibleWith ¶
func (*EnumType) TypeString ¶
type EnumValueExpr ¶
EnumValueExpr describes an enum value, with the enum value's name, its integer value, and the enum data type it is of.
func (*EnumValueExpr) IsVariableExpr ¶
func (e *EnumValueExpr) IsVariableExpr() bool
func (*EnumValueExpr) Reduce ¶
func (e *EnumValueExpr) Reduce() Expression
func (*EnumValueExpr) String ¶
func (e *EnumValueExpr) String() string
func (*EnumValueExpr) Type ¶
func (e *EnumValueExpr) Type() DataType
type EnumValueLiteral ¶
EnumValueLiteral describes a literal of an enumerated type, both by the enumerated type's symbol and the integral value that is associated with it.
func (*EnumValueLiteral) ConstantType ¶
func (l *EnumValueLiteral) ConstantType() DataType
func (*EnumValueLiteral) Negate ¶
func (l *EnumValueLiteral) Negate() (ConstantLiteral, error)
func (*EnumValueLiteral) String ¶
func (l *EnumValueLiteral) String() string
type Expression ¶
type Expression interface { // String returns a string representation of the expression for debugging purposes. String() string // Type returns the data type of the expression. Type() DataType // IsVariableExpr returns true if the expression is a variable expression, which means // that it can be used as a left expression in assignments. IsVariableExpr() bool // Reduce reduces nested expressions to the innermost single expression, as far as // possible. This is to remove overly complicated nesting of various expression types. Reduce() Expression }
Expression very generally describes any expression in a Pascal program.
type FieldDesignatorExpr ¶
type FieldDesignatorExpr struct { Expr Expression Field string Type_ DataType }
FieldDesignatorExpr describes an expression where a record type's field is accessed. Expr is an expression of a record type, Field contains the field name, while the type is the field's type and thus the expression's type.
func (*FieldDesignatorExpr) IsVariableExpr ¶
func (e *FieldDesignatorExpr) IsVariableExpr() bool
func (*FieldDesignatorExpr) Reduce ¶
func (e *FieldDesignatorExpr) Reduce() Expression
func (*FieldDesignatorExpr) String ¶
func (e *FieldDesignatorExpr) String() string
func (*FieldDesignatorExpr) Type ¶
func (e *FieldDesignatorExpr) Type() DataType
type FileType ¶
type FileType struct { // The element type. ElementType DataType // If true, indicates that the file type was declared as packed. Packed bool // contains filtered or unexported fields }
FileType describes a file type. A file type consists of elements of a particular element type, which can be either read from the file or written to the file.
func (*FileType) IsCompatibleWith ¶
func (*FileType) TypeString ¶
type ForStatement ¶
type ForStatement struct { // Variable name that is initialized with the initial expression. Name string // Initial expression. InitialExpr Expression // Final expression. FinalExpr Expression // Statement to execute. Statement Statement // If true, indicates that the variable is to be decremented rather than incremented. DownTo bool // contains filtered or unexported fields }
ForStatement describes a looping statement that initializes a provided variable with an initial expression, then executes the provides the statement and increments or decrements the variable until it has reached the final expression. When the final expression is reached, the statement is executed for one last time.
func (*ForStatement) Label ¶
func (s *ForStatement) Label() *string
func (*ForStatement) Type ¶
func (s *ForStatement) Type() StatementType
type FormalParameter ¶
func (*FormalParameter) String ¶
func (p *FormalParameter) String() string
type FormatExpr ¶
type FormatExpr struct { Expr Expression Width Expression DecimalPlaces Expression }
FormatExpr is solely used to format actual parameters to the write and writeln procedures. Expr is what is to be written, the optional Width expression describes the overall width that is used to write the expression, and the decimal places expression indicates how many decimal places shall be shown if Expr's type is a real.
func (*FormatExpr) IsVariableExpr ¶
func (e *FormatExpr) IsVariableExpr() bool
func (*FormatExpr) Reduce ¶
func (e *FormatExpr) Reduce() Expression
func (*FormatExpr) String ¶
func (e *FormatExpr) String() string
func (*FormatExpr) Type ¶
func (e *FormatExpr) Type() DataType
type FunctionCallExpr ¶
type FunctionCallExpr struct { Name string Type_ DataType ActualParams []Expression FormalParams []*FormalParameter }
FunctionCallExpr describes a function being called by name (defined elsewhere in the program or as a system function), with the actual parameters as expressions. The data type of the expression is the function's return type.
func (*FunctionCallExpr) IsVariableExpr ¶
func (e *FunctionCallExpr) IsVariableExpr() bool
func (*FunctionCallExpr) Reduce ¶
func (e *FunctionCallExpr) Reduce() Expression
func (*FunctionCallExpr) String ¶
func (e *FunctionCallExpr) String() string
func (*FunctionCallExpr) Type ¶
func (e *FunctionCallExpr) Type() DataType
type FunctionType ¶
type FunctionType struct { FormalParams []*FormalParameter ReturnType DataType }
FunctionType describes a function by its formal parameters and its return type. This is only used as the type of formal parameters itself, i.e. in procedure and function declarations.
func (*FunctionType) Equals ¶
func (t *FunctionType) Equals(dt DataType) bool
func (*FunctionType) IsCompatibleWith ¶
func (t *FunctionType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*FunctionType) Named ¶
func (t *FunctionType) Named(_ string) DataType
func (*FunctionType) Resolve ¶
func (t *FunctionType) Resolve(b *Block) error
func (*FunctionType) TypeName ¶
func (t *FunctionType) TypeName() string
func (*FunctionType) TypeString ¶
func (t *FunctionType) TypeString() string
type GotoStatement ¶
type GotoStatement struct { // The target label where execution shall continue next. Target string // contains filtered or unexported fields }
GotoStatement describes a goto statement.
func (*GotoStatement) Label ¶
func (s *GotoStatement) Label() *string
func (*GotoStatement) Type ¶
func (s *GotoStatement) Type() StatementType
type IfStatement ¶
type IfStatement struct { Condition Expression Statement Statement ElseStatement Statement // contains filtered or unexported fields }
IfStatement describes a conditional statement. If the condition is true, the statement is executed. If an else statement is present and the condition is false, the else statement is executed.
func (*IfStatement) Label ¶
func (s *IfStatement) Label() *string
func (*IfStatement) Type ¶
func (s *IfStatement) Type() StatementType
type IndexedVariableExpr ¶
type IndexedVariableExpr struct { Expr Expression // an expression of type *arrayType Type_ DataType IndexExprs []Expression }
IndexedVariableExpr describes an indexed access of an element of an expression (which is of an array type). The type describes the returned data type, while IndexExprs contains the expressions for the array's dimensions.
func (*IndexedVariableExpr) IsVariableExpr ¶
func (e *IndexedVariableExpr) IsVariableExpr() bool
func (*IndexedVariableExpr) Reduce ¶
func (e *IndexedVariableExpr) Reduce() Expression
func (*IndexedVariableExpr) String ¶
func (e *IndexedVariableExpr) String() string
func (*IndexedVariableExpr) Type ¶
func (e *IndexedVariableExpr) Type() DataType
type IntegerExpr ¶
type IntegerExpr struct {
Value int
}
IntegerExpr describes a literal of type integer, as an expression.
func (*IntegerExpr) IsVariableExpr ¶
func (e *IntegerExpr) IsVariableExpr() bool
func (*IntegerExpr) Reduce ¶
func (e *IntegerExpr) Reduce() Expression
func (*IntegerExpr) String ¶
func (e *IntegerExpr) String() string
func (*IntegerExpr) Type ¶
func (e *IntegerExpr) Type() DataType
type IntegerLiteral ¶
type IntegerLiteral struct { // The literal's integer value. Value int }
IntegerLiteral describes an integer literal with a particular value.
func (*IntegerLiteral) ConstantType ¶
func (l *IntegerLiteral) ConstantType() DataType
func (*IntegerLiteral) Negate ¶
func (l *IntegerLiteral) Negate() (ConstantLiteral, error)
func (*IntegerLiteral) String ¶
func (l *IntegerLiteral) String() string
type IntegerType ¶
type IntegerType struct {
// contains filtered or unexported fields
}
IntegerType describes the integer type.
func (*IntegerType) Equals ¶
func (t *IntegerType) Equals(dt DataType) bool
func (*IntegerType) IsCompatibleWith ¶
func (t *IntegerType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*IntegerType) Named ¶
func (t *IntegerType) Named(name string) DataType
func (*IntegerType) Resolve ¶
func (t *IntegerType) Resolve(_ *Block) error
func (*IntegerType) TypeName ¶
func (t *IntegerType) TypeName() string
func (*IntegerType) TypeString ¶
func (t *IntegerType) TypeString() string
type Multiplication ¶
type Multiplication struct { Operator MultiplicationOperator Factor Expression }
Multipliciation describes a multiplication operator and a factor used in a term.
type MultiplicationOperator ¶
type MultiplicationOperator string
MultiplicationOperator describes a multiplication operator. "Multiplication" is used here in a loose sense, as it is the preferred nomenclature of the Pascal EBNF, and primarily refers to its precedence.
const ( OperatorMultiply MultiplicationOperator = "*" OperatorFloatDivide MultiplicationOperator = "/" OperatorDivide MultiplicationOperator = "div" OperatorModulo MultiplicationOperator = "mod" OperatorAnd MultiplicationOperator = "and" )
type NilExpr ¶
type NilExpr struct{}
NilExpr describes the nil pointer, as an expression.
func (*NilExpr) IsVariableExpr ¶
func (*NilExpr) Reduce ¶
func (e *NilExpr) Reduce() Expression
type NotExpr ¶
type NotExpr struct {
Expr Expression
}
NotExpr describes a NOT expression which negates another boolean expression.
func (*NotExpr) IsVariableExpr ¶
func (*NotExpr) Reduce ¶
func (e *NotExpr) Reduce() Expression
type PointerType ¶
type PointerType struct { // Name of the type. May be empty. TargetName string // Dereferenced type. If it is nil, it indicates that the associated value is // compatible with any other pointer type. This is used to represent the type // of the nil literal. Type_ DataType // contains filtered or unexported fields }
PointerType describes a type that is a pointer to another type.
func (*PointerType) Equals ¶
func (t *PointerType) Equals(dt DataType) bool
func (*PointerType) IsCompatibleWith ¶
func (t *PointerType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*PointerType) Named ¶
func (t *PointerType) Named(name string) DataType
func (*PointerType) Resolve ¶
func (t *PointerType) Resolve(b *Block) error
func (*PointerType) TypeName ¶
func (t *PointerType) TypeName() string
func (*PointerType) TypeString ¶
func (t *PointerType) TypeString() string
type ProcedureCallStatement ¶
type ProcedureCallStatement struct { Name string ActualParams []Expression FormalParams []*FormalParameter // contains filtered or unexported fields }
ProcedureCallStatement describes a procedure call, including its name, the actual parameters provided, and, for validation purposes, the formal parameters of the procedure that is referenced.
func (*ProcedureCallStatement) Label ¶
func (s *ProcedureCallStatement) Label() *string
func (*ProcedureCallStatement) Type ¶
func (s *ProcedureCallStatement) Type() StatementType
type ProcedureType ¶
type ProcedureType struct {
FormalParams []*FormalParameter
}
ProcedureType describes a procedure by its formal parameters. This is only used as the type of formal parameters itself, i.e. in procedure and function declarations.
func (*ProcedureType) Equals ¶
func (t *ProcedureType) Equals(dt DataType) bool
func (*ProcedureType) IsCompatibleWith ¶
func (t *ProcedureType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*ProcedureType) Named ¶
func (t *ProcedureType) Named(_ string) DataType
func (*ProcedureType) Resolve ¶
func (t *ProcedureType) Resolve(b *Block) error
func (*ProcedureType) TypeName ¶
func (t *ProcedureType) TypeName() string
func (*ProcedureType) TypeString ¶
func (t *ProcedureType) TypeString() string
type RangeExpr ¶
type RangeExpr struct { LowerBound Expression UpperBound Expression }
func (*RangeExpr) IsVariableExpr ¶
func (*RangeExpr) Reduce ¶
func (e *RangeExpr) Reduce() Expression
type RealExpr ¶
RealExpr describes a literal of type real, as an expression.
func (*RealExpr) IsVariableExpr ¶
func (*RealExpr) Reduce ¶
func (e *RealExpr) Reduce() Expression
type RealLiteral ¶
type RealLiteral struct { // If true, the real value is negative. Minus bool // Digits before the comma. May be empty. BeforeComma string // Digits after the comma. May be empty. AfterComma string // The scale factor. It indicates by which power of ten // the value represented before and after the comma needs // to be multiplied. ScaleFactor int }
RealLiteral describes a real literal with a particular value.
func (*RealLiteral) ConstantType ¶
func (l *RealLiteral) ConstantType() DataType
func (*RealLiteral) Negate ¶
func (l *RealLiteral) Negate() (ConstantLiteral, error)
func (*RealLiteral) String ¶
func (l *RealLiteral) String() string
type RealType ¶
type RealType struct {
// contains filtered or unexported fields
}
RealType describes the real type.
func (*RealType) IsCompatibleWith ¶
func (*RealType) TypeString ¶
type RecordField ¶
func (*RecordField) String ¶
func (f *RecordField) String() string
type RecordType ¶
type RecordType struct { // Fixed record fields. Fields []*RecordField // If not nil, contains the variant field. VariantField *RecordVariantField // If true, the record type was declared as packed. Packed bool // contains filtered or unexported fields }
RecordType describes a record type, consisting of 1 or more fixed record fields, and an optional variant field. If a variant field is present, the fixed fields are optional.
func (*RecordType) Equals ¶
func (t *RecordType) Equals(dt DataType) bool
func (*RecordType) IsCompatibleWith ¶
func (t *RecordType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*RecordType) Named ¶
func (t *RecordType) Named(name string) DataType
func (*RecordType) Resolve ¶
func (t *RecordType) Resolve(b *Block) error
func (*RecordType) TypeName ¶
func (t *RecordType) TypeName() string
func (*RecordType) TypeString ¶
func (t *RecordType) TypeString() string
type RecordVariant ¶
type RecordVariant struct { CaseLabels []ConstantLiteral Fields *RecordType }
type RecordVariantField ¶
type RecordVariantField struct { TagField string Type DataType Variants []*RecordVariant }
type RelationalExpr ¶
type RelationalExpr struct { Left Expression Operator RelationalOperator Right Expression }
RelationalExpr expresses a relational expression in which a left expression is compared to a right expression. The resulting type of a relational expression is always boolean.
func (*RelationalExpr) IsVariableExpr ¶
func (e *RelationalExpr) IsVariableExpr() bool
func (*RelationalExpr) Reduce ¶
func (e *RelationalExpr) Reduce() Expression
func (*RelationalExpr) String ¶
func (e *RelationalExpr) String() string
func (*RelationalExpr) Type ¶
func (e *RelationalExpr) Type() DataType
type RelationalOperator ¶
type RelationalOperator string
RelationalOperator describes relational operators used in relational expressions.
const ( OpEqual RelationalOperator = "=" OpNotEqual RelationalOperator = "<>" OpLess RelationalOperator = "<" OpLessEqual RelationalOperator = "<=" OpGreater RelationalOperator = ">" OpGreaterEqual RelationalOperator = ">=" OpIn RelationalOperator = "in" )
type RepeatStatement ¶
type RepeatStatement struct { Condition Expression Statements []Statement // contains filtered or unexported fields }
RepeatStatement describes a looping statement that continues to execute the provided statement sequence until the condition evaluates true. The statement sequence is executed one time or more, i.e. the condition is evaluated only after the statement sequence has been executed for the first time.
func (*RepeatStatement) Label ¶
func (s *RepeatStatement) Label() *string
func (*RepeatStatement) Type ¶
func (s *RepeatStatement) Type() StatementType
type Routine ¶
type Routine struct { Name string Block *Block FormalParameters []*FormalParameter ReturnType DataType Forward bool // if true, routine is only forward-declared. // contains filtered or unexported fields }
func FindBuiltinFunction ¶
FindBuiltinFunction returns the _builtin_ function with the provided name. If no such function exists, it returns nil.
func FindBuiltinProcedure ¶
FindBuiltinProcedure returns the _builtin_ procedure with the provided name. If no such procedure exists, it returns nil.
type SetExpr ¶
type SetExpr struct { Elements []Expression Type_ DataType }
SetExpr describes a set literal, as an expression.
func (*SetExpr) IsVariableExpr ¶
func (*SetExpr) Reduce ¶
func (e *SetExpr) Reduce() Expression
type SetType ¶
type SetType struct { // The element type. ElementType DataType // If true, the set type was declared as packed. Packed bool // contains filtered or unexported fields }
SetType describes a type that consists of a set of elements of a particular type.
func (*SetType) IsCompatibleWith ¶
func (*SetType) TypeString ¶
type SimpleExpr ¶
type SimpleExpr struct { Sign string First Expression Next []*Addition }
SimpleExpr describes a simple expression, which consists of an optional sign, a starting term expression, and an optional list of pairs of addition operators ("addition" in the loosest sense) and further term expressions.
func (*SimpleExpr) IsVariableExpr ¶
func (e *SimpleExpr) IsVariableExpr() bool
func (*SimpleExpr) Reduce ¶
func (e *SimpleExpr) Reduce() Expression
func (*SimpleExpr) String ¶
func (e *SimpleExpr) String() string
func (*SimpleExpr) Type ¶
func (e *SimpleExpr) Type() DataType
type Statement ¶
type Statement interface { Type() StatementType Label() *string }
type StatementType ¶
type StatementType int
const ( StatementGoto StatementType = iota StatementAssignment StatementProcedureCall StatementCompoundStatement StatementWhile StatementRepeat StatementFor StatementIf StatementCase StatementWith StatementWrite )
type StringExpr ¶
type StringExpr struct {
Value string
}
StringExpr describes a literal of type string, as an expression.
func (*StringExpr) IsCharLiteral ¶
func (e *StringExpr) IsCharLiteral() bool
func (*StringExpr) IsVariableExpr ¶
func (e *StringExpr) IsVariableExpr() bool
func (*StringExpr) Reduce ¶
func (e *StringExpr) Reduce() Expression
func (*StringExpr) String ¶
func (e *StringExpr) String() string
func (*StringExpr) Type ¶
func (e *StringExpr) Type() DataType
type StringLiteral ¶
type StringLiteral struct {
Value string
}
StringLiteral describes a string literal.
func (*StringLiteral) ConstantType ¶
func (l *StringLiteral) ConstantType() DataType
func (*StringLiteral) IsCharLiteral ¶
func (l *StringLiteral) IsCharLiteral() bool
func (*StringLiteral) Negate ¶
func (l *StringLiteral) Negate() (ConstantLiteral, error)
func (*StringLiteral) String ¶
func (l *StringLiteral) String() string
type StringType ¶
type StringType struct {
// contains filtered or unexported fields
}
StringType describes the string type.
func (*StringType) Equals ¶
func (t *StringType) Equals(dt DataType) bool
func (*StringType) IsCompatibleWith ¶
func (t *StringType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*StringType) Named ¶
func (t *StringType) Named(name string) DataType
func (*StringType) Resolve ¶
func (t *StringType) Resolve(_ *Block) error
func (*StringType) TypeName ¶
func (t *StringType) TypeName() string
func (*StringType) TypeString ¶
func (t *StringType) TypeString() string
type SubExpr ¶
type SubExpr struct {
Expr Expression
}
SubExpr describes an expression that is surrounded by "(" and ")".
func (*SubExpr) IsVariableExpr ¶
func (*SubExpr) Reduce ¶
func (e *SubExpr) Reduce() Expression
type SubrangeType ¶
type SubrangeType struct { LowerBound int UpperBound int Type_ DataType // contains filtered or unexported fields }
SubrangeType describes a type that is a range with a lower and an upper boundary of an integral type.
func (*SubrangeType) Equals ¶
func (t *SubrangeType) Equals(dt DataType) bool
func (*SubrangeType) IsCompatibleWith ¶
func (t *SubrangeType) IsCompatibleWith(dt DataType, assignmentCompatible bool) bool
func (*SubrangeType) Named ¶
func (t *SubrangeType) Named(name string) DataType
func (*SubrangeType) Resolve ¶
func (t *SubrangeType) Resolve(_ *Block) error
func (*SubrangeType) TypeName ¶
func (t *SubrangeType) TypeName() string
func (*SubrangeType) TypeString ¶
func (t *SubrangeType) TypeString() string
type TermExpr ¶
type TermExpr struct { First Expression Next []*Multiplication }
TermExpr describes a term, which consists of a factor and an optional list of multiplication operators ("multiplication" in the loosest sense) and terms.
func (*TermExpr) IsVariableExpr ¶
func (*TermExpr) Reduce ¶
func (e *TermExpr) Reduce() Expression
type TypeDefinition ¶
type Variable ¶
type Variable struct { Name string Type DataType // the following fields are only set for variables that are looked up from within with statements, // and they indicate that Name and Type describe the field of a record variable of name BelongsTo of // type BelongsToType. IsRecordField bool // true if "variable" is a record field. BelongsToExpr Expression BelongsToType DataType }
type VariableExpr ¶
type VariableExpr struct { Name string Type_ DataType VarDecl *Variable ParamDecl *FormalParameter IsReturnValue bool }
VariableExpr describes an expression that refers to a variable or formal parameter (defined elsewhere in the program) by its name and the type it represents.
func (*VariableExpr) IsVariableExpr ¶
func (e *VariableExpr) IsVariableExpr() bool
func (*VariableExpr) Reduce ¶
func (e *VariableExpr) Reduce() Expression
func (*VariableExpr) String ¶
func (e *VariableExpr) String() string
func (*VariableExpr) Type ¶
func (e *VariableExpr) Type() DataType
type WhileStatement ¶
type WhileStatement struct { Condition Expression Statement Statement // contains filtered or unexported fields }
WhileStatement describes a looping statement that continues to execute the provided statement as long as the condition evaluates true. The statement is executed zero times or more, i.e. the condition is evaluated before the statement is executed for the first time.
func (*WhileStatement) Label ¶
func (s *WhileStatement) Label() *string
func (*WhileStatement) Type ¶
func (s *WhileStatement) Type() StatementType
type WithStatement ¶
type WithStatement struct { // The record variables for which the field names can be used directly. RecordVariables []string // TODO: should be removed. // The variable access expression for which the field names can be used directly. RecordExprs []Expression // Block containing the record variables' fields declared as variables as well as the // statement where these are valid. Block *Block // contains filtered or unexported fields }
WithStatement describes the with statement, which serves the purpose to denote fields of record variables by their field name instead of having to resort to the long-form notation within a statement.
func (*WithStatement) Label ¶
func (s *WithStatement) Label() *string
func (*WithStatement) Type ¶
func (s *WithStatement) Type() StatementType
type WriteStatement ¶
type WriteStatement struct { // If true, writeln was called. AppendNewLine bool // The not nil, the first actual parameter was a file variable. FileVar Expression // The list of actual parameters. If the first parameter was a file variable, // it is not contained in this list. ActualParams []Expression // contains filtered or unexported fields }
WriteStatement describes a write or writeln statement.
func (*WriteStatement) Label ¶
func (s *WriteStatement) Label() *string
func (*WriteStatement) Type ¶
func (s *WriteStatement) Type() StatementType