Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@291 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Jun 10, 1998
1 parent 34a9c2b commit bfbd36a
Show file tree
Hide file tree
Showing 12 changed files with 532 additions and 297 deletions.
8 changes: 2 additions & 6 deletions modeq/absyn.rml
Expand Up @@ -88,9 +88,7 @@ module Absyn:
datatype Direction = INPUT | OUTPUT | BIDIR

(** - Array dimensions *)
datatype ArrayDim = NODIM
| ONEDIM of Subscript
| TWODIM of Subscript * Subscript
type ArrayDim = Subscript list
(** Variables in Modelica can be scalar, one-dimensional arrays, or *)
(** two-dimensional matrices. This datatype is used to indicate the *)
(** dimensionality of a variable or a type definition. *)
Expand Down Expand Up @@ -122,9 +120,7 @@ module Absyn:

(** - Subscripts *)
datatype Subscript = NOSUB
| SUB1 of Exp
| SUB2 of Exp * Exp
| SUB3 of Exp * Exp * Exp
| SUBSCRIPT of Exp
(** The `Subscript' datatype is used in variable references. An *)
(** one-dimensional array variable `a' can be supscriptet as `a[1]', *)
(** `a[1:2]' or `a[1:2:3]'. *)
Expand Down
57 changes: 20 additions & 37 deletions modeq/ast/modgram.g
Expand Up @@ -361,51 +361,34 @@ component_declaration :

declaration :
i:IDENT^
{ a:array_dimensions }
{ a:array_subscripts }
{ m:modification }
<< #i->rml = Absyn__COMPONENT(mk_scon($i.u.stringval),
#a ? #a->rml : Absyn__NODIM,
#m ? mk_some(#m->rml) : mk_none()); >>
;

array_dimensions :
brak:LBRACK^
s1:subscript { ","! s2:subscript }
RBRACK!
<< if(#s2) #0->rml = Absyn__TWODIM(#s1->rml,#s2->rml);
else #0->rml = Absyn__ONEDIM(#s1->rml); >>
;

subscripts :
brak:LBRACK^
s:subscript_list
RBRACK!
<< #0->rml = sibling_list(#s); >>
;

subscript_list :
subscript { ","! subscript { ","! subscript }}
array_subscripts :
brak:LBRACK^
s:subscript ( ","! subscript )*
RBRACK!
<< #0->rml = sibling_list(#s); >>
;

subscript :
<< Attrib a = $[SUBSCRIPT,"---"]; >>
ex1:expression { ":"! ex2:expression { ":"! ex3:expression } }
<<
#0 = #(#[&a],#0);
if(#ex3)
#0->rml = Absyn__SUB3(#ex1->rml, #ex2->rml, #ex3->rml);
else if(#ex2)
#0->rml = Absyn__SUB2(#ex1->rml, #ex2->rml);
else
#0->rml = Absyn__SUB1(#ex1->rml);
>>
<< Attrib a = $[SUBSCRIPT,"---"]; >>
ex1:expression
<<
#0 = #(#[&a],#0);
#0->rml = Absyn__SUBSCRIPT(#ex1->rml);
>>

| ":"!
<<
#0 = #(#[&a],#0);
#0->rml = Absyn__NOSUB;
>>
;
<<
#0 = #(#[&a],#0);
#0->rml = Absyn__NOSUB;
>>
;

/*
* Modifications
Expand Down Expand Up @@ -612,9 +595,9 @@ connect_clause :
;

connector_ref : << void *tail = NULL; >>
i1:IDENT^ { a1:subscripts }
i1:IDENT^ { a1:array_subscripts }
<< #i1->rml = mk_scon($i1.u.stringval); >>
{ dot:DOT^ i2:IDENT { a2:subscripts }
{ dot:DOT^ i2:IDENT { a2:array_subscripts }
<< tail = Absyn__CREF_5fIDENT(mk_scon($i2.u.stringval),
#a2?#a2->rml:mk_nil()); >>
}
Expand Down Expand Up @@ -780,7 +763,7 @@ name_path : << bool qualified = false; >>
/* ; */

component_reference : << void *tail = NULL;>>
i:IDENT^ { a:subscripts }
i:IDENT^ { a:array_subscripts }
<< #i->rml = mk_scon($i.u.stringval); >>
{ dot:DOT^ c:component_reference << tail = #c->rml; >> }
<< if(tail)
Expand Down
6 changes: 3 additions & 3 deletions modeq/builtin.rml
Expand Up @@ -46,7 +46,7 @@ SCode.CLASS("Real",false,Absyn.R_PREDEFINED_REAL,
SCode.PARTS
([(* quantity *)
SCode.COMPONENT("unit",true,false,
Absyn.ATTR(Absyn.NODIM,
Absyn.ATTR([],
false,
Absyn.VAR,
Absyn.BIDIR),
Expand All @@ -63,7 +63,7 @@ SCode.CLASS("Integer",false,Absyn.R_PREDEFINED_INT,
SCode.PARTS
([(* quantity *)
SCode.COMPONENT("unit",true,false,
Absyn.ATTR(Absyn.NODIM,
Absyn.ATTR([],
false,
Absyn.VAR,
Absyn.BIDIR),
Expand Down Expand Up @@ -95,7 +95,7 @@ SCode.CLASS("Boolean",false,Absyn.R_PREDEFINED_BOOL,

(* FIXME: Shuold contain components (attributes) from the real Real type *)
val time_var =
Env.FRAMEVAR("time", Absyn.ATTR(Absyn.NODIM, false, Absyn.VAR, Absyn.BIDIR),
Env.FRAMEVAR("time", Absyn.ATTR([] , false, Absyn.VAR, Absyn.BIDIR),
Types.TYPE(ClassInf.TYPE_REAL("time"), []), Env.UNBOUND)

(** - Initial environment *)
Expand Down
43 changes: 24 additions & 19 deletions modeq/dae.rml
Expand Up @@ -19,6 +19,7 @@ module DAE:
datatype Type = REAL | INT | BOOL | STRING

datatype DAEcomp = VAR of Exp.ComponentRef * VarKind * Type
* Absyn.ArrayDim (*FIXME*)
| VARVAL of Ident * VarKind * Exp.Exp
| EQUATION of Exp.Exp
| ALGORITHM of SCode.Algorithm
Expand All @@ -45,27 +46,27 @@ relation dump_kind =
--------------------
dump_kind DISCRETE

rule print " variable "
rule print " "
--------------------
dump_kind VARIABLE

end

relation dump_type =

rule print "integer "
rule print "Integer "
----------------
dump_type INT

rule print "real "
rule print "Real "
----------------
dump_type REAL

rule print "bool "
rule print "Boolean "
----------------
dump_type BOOL

rule print "string "
rule print "String "
----------------
dump_type STRING

Expand All @@ -74,9 +75,9 @@ end
relation dump_comp: DAEcomp => () =

rule dump_kind kind & dump_type typ &
Exp.print_component_ref id & print "\n"
Exp.print_component_ref id & Dump.print_arraydim ad & print "\n"
--------------------------------------
dump_comp(VAR(id, kind, typ))
dump_comp(VAR(id, kind, typ, ad))

rule dump_kind kind & print id &
print "=" & Exp.print_exp ex & print "\n"
Expand All @@ -98,17 +99,17 @@ end
relation dump_var : DAEcomp => () =

rule dump_kind kind & dump_type typ &
Exp.print_component_ref id & print "\n"
Exp.print_component_ref id & Dump.print_arraydim ad & print ";\n"
--------------------------------------
dump_var(VAR(id, kind, typ))
dump_var(VAR(id, kind, typ, ad))

axiom dump_var _

end

relation dump_equation : DAEcomp => () =

rule print " " & Exp.print_exp eq & print "\n"
rule print " " & Exp.print_exp eq & print ";\n"
--------------------------------------
dump_equation(EQUATION(eq))

Expand All @@ -118,9 +119,8 @@ end

relation dump_algorithm : DAEcomp => () =

rule print "\nalgorithm\n\n" &
Dump.print_list(alg, pp_algorithm, "") &
print "\n"
rule print "algorithm\n" &
Dump.print_list(alg, pp_algorithm, "")
----------------------------------------------
dump_algorithm ALGORITHM(SCode.ALGORITHM(alg))

Expand Down Expand Up @@ -163,9 +163,14 @@ end

relation dump: DAEform => () =

rule print "\nvariables\n\n" &
dump_vars l &
print "\nequations\n\n" &
rule print "fclass " & print n & print "\n" &
dump(l) &
print "end " & print n & print ";\n"
-----------------------------------
dump DAE([COMP(n,l)])

rule dump_vars l &
print "equation\n" &
dump_equations l &
dump_algorithms l
-----------------
Expand All @@ -192,7 +197,7 @@ relation pp_alg : (Absyn.Algorithm, int) => () =
Dump.print_component_ref c &
print " := " &
Dump.print_exp e &
print "\n"
print ";\n"
----------
pp_alg (Absyn.ALG_ASSIGN(c,e), i)

Expand All @@ -201,11 +206,11 @@ relation pp_alg : (Absyn.Algorithm, int) => () =
int_add(i,2) => i' &
pp_alg_list (algs, i') &
indent i &
print "end while\n"
print "end while;\n"
-------------------
pp_alg (Absyn.ALG_WHILE(e,algs), i)

rule indent i & print "**ALGORITHM**\n"
rule indent i & print "**ALGORITHM**;\n"
----------------------------------
pp_alg (_,i)

Expand Down
45 changes: 15 additions & 30 deletions modeq/dump.rml
Expand Up @@ -15,6 +15,8 @@ module Dump:
relation dump: Absyn.Program => ()
relation print_exp: Absyn.Exp => ()
relation print_component_ref: Absyn.ComponentRef => ()
relation print_subscripts : Absyn.Subscript list => ()
relation print_arraydim: Absyn.ArrayDim => ()
relation print_equation: Absyn.Equation => ()
relation print_algorithm: Absyn.Algorithm => ()
relation print_list : ('a list, 'a => (), string) => ()
Expand Down Expand Up @@ -196,16 +198,9 @@ end

relation print_arraydim: Absyn.ArrayDim => () =

axiom print_arraydim(Absyn.NODIM)

rule print "[" & print_subscript(s) & print "]"
-----------------------------------------
print_arraydim(Absyn.ONEDIM(s))

rule print "[" & print_subscript(s1) &
print "," & print_subscript(s2) & print "]"
-----------------------------------------
print_arraydim(Absyn.TWODIM(s1,s2))
rule print_subscripts(s)
-------------------
print_arraydim(s)

end

Expand All @@ -217,16 +212,7 @@ relation print_subscript: Absyn.Subscript => () =

rule print_exp(e1)
----------
print_subscript(Absyn.SUB1(e1))

rule print_exp(e1) & print ":" & print_exp(e2)
-------------
print_subscript(Absyn.SUB2(e1,e2))

rule print_exp(e1) & print ":" &
print_exp(e2) & print ":" & print_exp(e3)
----------------------------------------------
print_subscript(Absyn.SUB3(e1,e2,e3))
print_subscript(Absyn.SUBSCRIPT(e1))

end

Expand Down Expand Up @@ -338,27 +324,26 @@ end

relation print_component_ref : Absyn.ComponentRef => () =

rule print_component_ref2 (s,subs)
----------------------------
rule print s &
print_subscripts subs
---------------------
print_component_ref Absyn.CREF_IDENT(s,subs)

rule print_component_ref2 (s,subs) &
rule print s &
print_subscripts subs &
print "." &
print_component_ref cr
---------------------
print_component_ref Absyn.CREF_QUAL(s,subs,cr)
end

relation print_component_ref2 =
relation print_subscripts : Absyn.Subscript list => () =

rule print s
-------
print_component_ref2 (s,[])
axiom print_subscripts []

rule print s &
print "[" & print_list(l,print_subscript,",") & print "]"
rule print "[" & print_list(l,print_subscript,",") & print "]"
-------------------------------------------------------
print_component_ref2 (s,l)
print_subscripts l

end

Expand Down

0 comments on commit bfbd36a

Please sign in to comment.