subroutinenext_tokenprivate
subroutine next_token(c, s)
Go to the next token.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| s | type(scan_t) | inout | the expression |
Calls
Source
Show the code
subroutine next_token(c, s)
type(fypp_t), intent(inout) :: c !! the state
type(scan_t), intent(inout) :: s !! the expression
integer :: n, start
character :: ch
n = len(s%text)
do while (s%pos <= n)
ch = s%text(s%pos:s%pos)
if (ch == '#') then
do while (s%pos <= n)
if (s%text(s%pos:s%pos) == NL) exit
s%pos = s%pos + 1
end do
else if (is_blank(ch) .or. ch == NL) then
s%pos = s%pos + 1
else
exit
end if
end do
s%word = ''
if (s%pos > n) then
s%kind = T_END
return
end if
ch = s%text(s%pos:s%pos)
start = s%pos
if (ch == '"' .or. ch == "'") then
s%kind = T_STR
call read_string(c, s)
else if ((ch == 'f' .or. ch == 'F') .and. s%pos < n) then
if (s%text(s%pos + 1:s%pos + 1) == '"' .or. s%text(s%pos + 1:s%pos + 1) == "'") then
s%pos = s%pos + 1
s%kind = T_FSTR
call read_string(c, s)
else
call read_name(s)
end if
else if (starts_name(ch)) then
call read_name(s)
else if (is_digit(ch)) then
s%kind = T_INT
s%number = 0
do while (s%pos <= n)
if (.not. is_digit(s%text(s%pos:s%pos))) exit
s%number = 10*s%number + iachar(s%text(s%pos:s%pos)) - iachar('0')
s%pos = s%pos + 1
end do
else
s%kind = T_OP
s%pos = s%pos + 1
if (s%pos <= n) then
if (s%text(s%pos:s%pos) == '=' .and. index('=!<>', ch) > 0) s%pos = s%pos + 1
end if
s%word = s%text(start:s%pos - 1)
end if
end subroutine next_token