Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

incomprehensible ERROR message

incomprehensible ERROR message

Hello everybody,


I would like to evaluate the class below, but OpenModelica always gives me the message:
[<interactive>:33:1-33:4:writeable] Error: No viable alternative near token: end

Following the advice it might has something to do with the last phrase "end cpW;", but I see no error there. Any ideas of yours? Thank you very much!!


code:


class cpW

//specific isobaric heat capacity of water or steam
//cpW in kJ/(kg K)
//temperature in K
//pressure in bar
//cpW = -1: temperature and/or pressure outside range

extends pSatW;
extends cpreg1;
extends cpreg2;
extends cpreg3;
extends pBound;
extends tBound;
extends densreg3;
parameter Real temperature;
parameter Real pressure;
Real density;
Real cpW;

equation
if (temperature >= 273.15) and (temperature <= 623.15) and (pressure >= pSatW) and (pressure <= 1000.00) then
cpW = cpreg1; //region 1
else if (temperature >= 273.15 and temperature <= 623.15 and pressure > 0 and pressure <= pSatW) or (temperature >= 623.15 and temperature <= 863.15 and pressure > 0 and pressure <= pBound) or (temperature >= 863.15 and temperature <= 1073.15 and pressure > 0 and pressure <= 1000.00) then
cpW = cpreg2; //region 2
else if temperature >= 623.15 and temperature <= tBound and pressure >= pBound and pressure <= 1000.00 then
density = densreg3; //region 3
cpW = cpreg3;
else
cpW = -1.00; //outside range
end if;

end cpW;

Re: incomprehensible ERROR message

The problem is that you are using the pattern

Code:

if X then

  ...
else if X
  ...
end if;

With proper indentation it is easy to spot the problem:

Code:

if X then

  ...
else
   if X then
    ...
   end if;
end /* expected if */

(Use elseif instead of else if; it has a quite different meaning)

I will see if I can make the parser return a better error-message for this case; it seems that it is easy to make this syntax error as a novice.

Re: incomprehensible ERROR message

Hello sjoelund.se,

many thanks for replying so quickly! Now it's working, I wanted to try with "elseif" before, but it wasn't marked as red in the editor, e.g. like "else if".

Regards
Georg

Re: incomprehensible ERROR message

Now the following code generates a good error-message:

Code:

// name: IfElseIf

// status: correct

model IfElseIf
equation
  if cond then
    abc();
  else if cond then
    def();
  end if;
end IfElseIf;

// Result:
// Error processing file: IfElseIf.mo
// [IfElseIf.mo:11:1-11:13:writable] Error: Parse error: Expected 'end if'; did you use a nested 'else if' instead of 'elseif'?
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult

What editor were you using? OMEdit shows 'elseif' as a keyword.

Re: incomprehensible ERROR message

Thank you for your effort!

I am  sorry haven't seen your reply so far. I use the 1.7 version. I ment, that "elseif" isn't marked in extra colors, that's why I thought it isn't a keyword.

Regards Georg

There are 0 guests and 0 other users also viewing this topic
You are here: