Class: ParserASTNode<Semantics, TypeSemantics>
compiler.ParserASTNode
An Abstract Syntax Tree (AST) node, which wraps an Antlr4 parse rule context and simplifies its content down to a simplified representation, which can be used for semantic analysis and code translation.
Since
0.8.0
Type parameters
| Name | Type |
|---|---|
Semantics |
extends SemanticData |
TypeSemantics |
extends TypeData |
Hierarchy
ParserASTNode
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• Protected new ParserASTNode<Semantics, TypeSemantics>(antlrCtx, parent)
Type parameters
| Name | Type |
|---|---|
Semantics |
extends SemanticData |
TypeSemantics |
extends TypeData |
Parameters
| Name | Type |
|---|---|
antlrCtx |
KipperParserRuleContext |
parent |
undefined | ParserASTNode<any, any> |
Defined in
kipper/core/src/compiler/ast/ast-node.ts:67
Properties
_antlrRuleCtx
• Protected Readonly _antlrRuleCtx: KipperParserRuleContext
Defined in
kipper/core/src/compiler/ast/ast-node.ts:45
_children
• Protected Readonly _children: ParserASTNode<any, any>[]
Defined in
kipper/core/src/compiler/ast/ast-node.ts:46
_parent
• Protected Readonly _parent: undefined | ParserASTNode<any, any>
Defined in
kipper/core/src/compiler/ast/ast-node.ts:47
_semanticData
• Protected _semanticData: undefined | Semantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:48
_typeSemantics
• Protected _typeSemantics: undefined | TypeSemantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:49
Accessors
antlrRuleCtx
• get antlrRuleCtx(): KipperParserRuleContext
The antlr rule context containing the antlr4 metadata for this AST node.
Since
0.8.0
Returns
Defined in
kipper/core/src/compiler/ast/ast-node.ts:112
children
• get children(): ParserASTNode<any, any>[]
The children of this AST node.
Since
0.8.0
Returns
ParserASTNode<any, any>[]
Defined in
kipper/core/src/compiler/ast/ast-node.ts:139
kind
• Abstract get kind(): number
Returns the kind of this AST node. This represents the specific type of the antlrRuleCtx that this AST node wraps.
This may be compared using the KipperParser rule fields, for example RULE_expression.
Since
0.10.0
Returns
number
Defined in
kipper/core/src/compiler/ast/ast-node.ts:58
parent
• get parent(): undefined | ParserASTNode<any, any>
Returns the parent that has this node as a child. If parent is undefined, then this item is a root node.
Since
0.8.0
Returns
undefined | ParserASTNode<any, any>
Defined in
kipper/core/src/compiler/ast/ast-node.ts:121
ruleName
• Abstract get ruleName(): string
Returns the identifier of this AST node. This is a unique identifier that can be used to differentiate this AST node from other AST nodes.
Since
0.11.0
Returns
string
Defined in
kipper/core/src/compiler/ast/ast-node.ts:65
semanticData
• get semanticData(): undefined | Semantics
Returns the semantic data of this AST node.
Since
0.8.0
Returns
undefined | Semantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:78
• set semanticData(value): void
Sets the semantic data of this AST node.
Since
0.8.0
Parameters
| Name | Type | Description |
|---|---|---|
value |
undefined | Semantics |
The semantic data that should be written onto this AST node. |
Returns
void
Defined in
kipper/core/src/compiler/ast/ast-node.ts:87
sourceCode
• get sourceCode(): string
The Kipper source code that was used to generate this CompilableASTNode.
Any left-over whitespaces will be removed using trim().
Since
0.8.0
Returns
string
Defined in
kipper/core/src/compiler/ast/ast-node.ts:131
typeSemantics
• get typeSemantics(): undefined | TypeSemantics
Returns the type data of this AST node.
Since
0.10.0
Returns
undefined | TypeSemantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:95
• set typeSemantics(value): void
Sets the type data of this AST node.
Since
0.10.0
Parameters
| Name | Type | Description |
|---|---|---|
value |
undefined | TypeSemantics |
The semantic data that should be written onto this AST node. |
Returns
void
Defined in
kipper/core/src/compiler/ast/ast-node.ts:104
Methods
addNewChild
▸ addNewChild(newChild): void
Adds new child ctx item to this AST node. The child item should be in the order that they appeared in the this.antlrCtx parse tree.
This will also automatically set the parent of newChild to this instance.
Since
0.8.0
Parameters
| Name | Type |
|---|---|
newChild |
ParserASTNode<any, any> |
Returns
void
Defined in
kipper/core/src/compiler/ast/ast-node.ts:150
getAntlrRuleChildren
▸ getAntlrRuleChildren(): ParseTree[]
Returns the children of the antlrRuleCtx and throws an error in case they are undefined.
Throws
If antlrRuleCtx.children is undefined.
Since
0.8.0
Returns
ParseTree[]
Defined in
kipper/core/src/compiler/ast/ast-node.ts:159
getSemanticData
▸ getSemanticData(): Semantics
Returns the semantic data of this AST node and throws an error in case it is undefined.
Throws
If semanticData is undefined.
Since
0.8.0
Returns
Semantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:172
getTypeSemanticData
▸ getTypeSemanticData(): TypeSemantics
Returns the type semantic data of this AST node and throws an error in case it is undefined.
Throws
UndefinedSemanticsError If semanticData is undefined.
Since
0.10.0
Returns
TypeSemantics
Defined in
kipper/core/src/compiler/ast/ast-node.ts:185