forgex_syntax_tree_node_m Module

Theforgex_syntax_tree_m module defines parsing and the tree_node_t derived-type for building syntax-tree.

The regular expression parsing performed by this module is done using recursive descent parsing.



Variables

Type Visibility Attributes Name Initial
character(len=UTF8_CHAR_SIZE), public, parameter :: EMPTY = char(0)
type(tree_node_t), public, parameter :: terminal = tree_node_t(op=op_not_init, left_i=TERMINAL_INDEX, right_i=TERMINAL_INDEX, parent_i=INVALID_INDEX, own_i=INVALID_INDEX, min_repeat=INVALID_REPEAT_VAL, max_repeat=INVALID_REPEAT_VAL)

Derived Types

type, public ::  tape_t

This type holds the input pattern string and manages the index of the character it is currently focused.

Components

Type Visibility Attributes Name Initial
integer(kind=int32), public :: current_token
integer(kind=int32), public :: idx = 0
character(len=:), public, allocatable :: str
character(len=UTF8_CHAR_SIZE), public :: token_char = EMPTY

Type-Bound Procedures

procedure, public :: get_token

type, public ::  tree_node_t

This type is used to construct a concrete syntax tree, later converted to NFA.

Components

Type Visibility Attributes Name Initial
type(segment_t), public, allocatable :: c(:)
logical, public :: is_registered = .false.
integer(kind=int32), public :: left_i = INVALID_INDEX
integer(kind=int32), public :: max_repeat
integer(kind=int32), public :: min_repeat
integer(kind=int32), public :: op = op_not_init
integer(kind=int32), public :: own_i = INVALID_INDEX
integer(kind=int32), public :: parent_i = INVALID_INDEX
integer(kind=int32), public :: right_i = INVALID_INDEX

Functions

public pure function make_atom(segment) result(node)

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: segment

Return Value type(tree_node_t)

public pure function make_repeat_node(min, max) result(node)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: min
integer(kind=int32), intent(in) :: max

Return Value type(tree_node_t)

public pure function make_tree_node(op) result(node)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: op

Return Value type(tree_node_t)


Subroutines

private pure subroutine deallocate_tree(tree)

This subroutine deallocate the syntax tree.

Arguments

Type IntentOptional Attributes Name
type(tree_node_t), intent(inout), allocatable :: tree(:)

private pure subroutine get_token(self, class_flag)

Get the currently focused character (1 to 4 bytes) from the entire string inside the type_t derived-type, and store the enumerator's numeric value in the current_token component. This is a type-bound procedure of tape_t.

Arguments

Type IntentOptional Attributes Name
class(tape_t), intent(inout) :: self
logical, intent(in), optional :: class_flag

private pure subroutine reallocate_tree(tree, alloc_count)

Arguments

Type IntentOptional Attributes Name
type(tree_node_t), intent(inout), allocatable :: tree(:)
integer, intent(inout) :: alloc_count