diff --git a/src/FEQParse.F90 b/src/FEQParse.F90 index 1674796..886e85d 100644 --- a/src/FEQParse.F90 +++ b/src/FEQParse.F90 @@ -572,11 +572,9 @@ function Evaluate_sfp64(parser,x) result(f) case(Monadic_Token) if(trim(t%tokenString) == '-') then - call stack%Pop(a) a = -a call stack%Push(a) - endif case default @@ -1670,21 +1668,33 @@ integer function Priority(parser,toke) Priority = 5 - elseif(toke%tokenString(1:1) == '^') then + elseif(toke%tokenType == Operator_Token) then + + if(toke%tokenString(1:1) == '^') then - Priority = 4 + Priority = 4 - elseif(toke%tokenString(1:1) == '/') then + elseif(toke%tokenString(1:1) == '/') then - Priority = 3 + Priority = 3 - elseif(toke%tokenString(1:1) == '*') then + elseif(toke%tokenString(1:1) == '*') then - Priority = 2 + Priority = 2 - elseif(toke%tokenString(1:1) == '+' .or. toke%tokenString(1:1) == '-') then + elseif(toke%tokenString(1:1) == '+' .or. toke%tokenString(1:1) == '-') then + + Priority = 1 + + else - Priority = 1 + Priority = 0 + + endif + + elseif(toke%tokenType == Monadic_Token) then + + Priority = 5 else diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 53ccb26..4be87dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -189,5 +189,6 @@ add_fortran_tests ( "tan_sfp64.f90" "print_tokens.f90" "custom_r1fp64.f90" - "parsing_difficult_r1fp64.f90") + "parsing_difficult_r1fp64.f90" + "parsing_vanderpol_sfp64.f90") \ No newline at end of file diff --git a/test/parsing_vanderpol_sfp64.f90 b/test/parsing_vanderpol_sfp64.f90 new file mode 100644 index 0000000..a8b0843 --- /dev/null +++ b/test/parsing_vanderpol_sfp64.f90 @@ -0,0 +1,51 @@ +program test + + implicit none + integer :: exit_code + + exit_code = vanderpol_sfp64() + stop exit_code + +contains + + integer function vanderpol_sfp64() result(r) + use FEQParse + use iso_fortran_env + implicit none + integer,parameter :: N = 10 + type(EquationParser) :: f + character(len=128) :: fun_buf + real(real64) :: t,x,y,u,v + real(real64) :: feval + real(real64) :: fexact + + fun_buf = '-8.53*(1-x*x)*v-y' + f = equationparser('f = '//fun_buf,['t','x','y','u','v']) + + print*,"--------- Infix -------------------" + call f%Print_InFixTokens() + print*,"-----------------------------------" + print*,"--------- Postfix -------------------" + call f%Print_PostFixTokens() + print*,"-----------------------------------" + + t = 0.0_real64 + x = 1.0_real64 + y = 3.0_real64 + u = 12.0_real64 + v = 0.0_real64 + + feval = f%evaluate([t,x,y,u,v]) + + fexact = -8.53_real64*(1.0_real64-x*x)*v-y + + if((abs(feval-fexact)) <= epsilon(1.0_real64)) then + r = 0 + print*,feval,fexact + else + r = 1 + print*,feval,fexact + endif + + endfunction vanderpol_sfp64 +endprogram test