subroutineparse_declarator
subroutine parse_declarator(text, name, dimension, initial, points)
Read one name of a declaration, such as x(3) = 1.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| text | character(len=*) | in | the text | |
| name | character(len=:) | out | allocatable | the name |
| dimension | character(len=:) | out | allocatable | the dimensions, if any |
| initial | character(len=:) | out | allocatable | the initial value, if any |
| points | logical | out | true if initialized with |
Calls
Source
Show the code
subroutine parse_declarator(text, name, dimension, initial, points)
character(len=*), intent(in) :: text !! the text
character(len=:), allocatable, intent(out) :: name !! the name
character(len=:), allocatable, intent(out) :: dimension !! the dimensions, if any
character(len=:), allocatable, intent(out) :: initial !! the initial value, if any
logical, intent(out) :: points !! true if initialized with `=>`
character(len=:), allocatable :: dec
integer :: at, stop_at
dec = remove_blanks(text)
points = .false.
at = top_index(dec, '=')
if (at > 0) then
points = dec(at + 1:min(at + 1, len(dec))) == '>'
initial = dec(at + merge(2, 1, points):)
dec = dec(:at - 1)
end if
stop_at = scan(dec, '([*')
if (stop_at > 1) then
dimension = dec(stop_at:)
name = dec(:stop_at - 1)
else
name = dec
end if
end subroutine parse_declarator