Constructor for token_t
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str | String to parse |
New token_t
function newToken(str) result(self)
!! Constructor for token_t
character(*),intent(in)::str
!! String to parse
type(token_t)::self
!! New token_t
character(:),allocatable::buf
self%s = str
if(verify(str,ops)==0) then
select case(str)
case(',')
self%t = T_CMA
case('(')
self%t = T_LPR
case(')')
self%t = T_RPR
case('+')
self%t = T_ADD
case('-')
self%t = T_SUB
case('*')
self%t = T_MUL
case('/')
self%t = T_DIV
case('^')
self%t = T_POW
end select
else if(verify(str,' .+-0123456789E')==0) then
self%t = T_REAL
read(str,*) self%a
else if(verify(str,' .+-0123456789EJj')==0) then
self%t = T_IMAG
buf = removeJ(str)
read(buf,*) self%a
else if(str=='sqrt') then
self%t = T_SQRT
else if(str=='exp') then
self%t = T_EXP
else if(str=='log') then
self%t = T_LOG
else if(str=='abs') then
self%t = T_ABS
else if(str=='sin') then
self%t = T_SIN
else if(str=='cos') then
self%t = T_COS
else if(str=='tan') then
self%t = T_TAN
else if(str=='asin') then
self%t = T_ASIN
else if(str=='acos') then
self%t = T_ACOS
else if(str=='atan') then
self%t = T_ATAN
else if(str=='log10') then
self%t = T_LOG10
else
self%t = T_VAR
end if
contains
function removeJ(str) result(o)
character(*),intent(in)::str
character(:),allocatable::o
character(1),dimension(:),allocatable::a,b
a = charToArray(str)
b = pack(a, a/='j' .and. a/='J' )
o = arrayToChar(b)
end function removeJ
end function newToken