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

Modelica syntax issue with definition of primary

Modelica syntax issue with definition of primary

Is there anyone who could explain why Modelica syntax allows "(" output_expression_list ")" for primary?

Here is a clip from Modelica 3.3 spec (https://www.modelica.org/documents/ModelicaSpec33.pdf)

Code:


primary :
UNSIGNED_NUMBER
| STRING
| false
| true
| ( name | der | initial) function_call_args
| component_reference
| "(" output_expression_list ")"
| "[" expression_list { ";" expression_list } "]"
| "{" function_arguments "}"
| end

The problem is that output_expression_list allows expressions like (,,,,,,)^(,,,,,). They go unnoticed to compiler which obviously cannot process them. Should it be expression_list instead? Just wondering current/smile

Re: Modelica syntax issue with definition of primary

Hi,

I guess it is for brevity and to allow "(" output_expression_list ")"  = fcall(...);
Maybe it would be better to remove it and have equation include the case with output_expression_list on the left hand side.
You can add a ticket at http://trac.modelica.org with Modelica Specification as a component and point it out.

Cheers,
Adrian Pop/

Re: Modelica syntax issue with definition of primary

Modelica specification has a separate definition for that case:

Code:


statement :
( component_reference ( ":=" expression | function_call_args )
| "(" output_expression_list ")" ":=" component_reference function_call_args
| ...

Now when thinking of this, replacing output_expression_list with expression_list would allow (1,2,3)^(4,5,6,7,) which would not make much sense either.. Maybe that is just a forgotten legacy line for the function call case? I'll add that ticket and wait for smart people to resolve it current/smile

Re: Modelica syntax issue with definition of primary

The rule you give is for statements, not equations.
I was talking about equations where left hand side is a multiple output and right hand side is a function call returning multiple outputs.
(1, 2, 3)^(4,5,6) makes sense if you think about it as tuples, so is actually equivalent to (1^4, 2^5, 3^6).

Cheers,
Adrian Pop/

Re: Modelica syntax issue with definition of primary

That's only a rule for statements. For equations it is different... And I guess to make the grammar simpler those checks are not done.

And regardless, tuples "( ... )" are only allowed for function call results. A Modelica tool will not let it go unnoticed (except maybe during parsing; but that's a non-issue as most languages allow you to use syntax that is not really allowed later on).

Re: Modelica syntax issue with definition of primary

Thanks, it is all starting to make sense now!

This example shows why the output_expression_list is actually useful:

Code:


model Test

function func
  input Real a;
  input Real b;
  output Real c;
  output Real d;
algorithm
  c := a*a;
  d := b+b;
end func;

  parameter Real e = 3;
  parameter Real f = 5;
  Real g;
equation
  (,g) = func(e,f);
end Test;

I'll comment this also to the bug report.

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