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@288 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed May 29, 1998
1 parent fdabf67 commit 913cdd7
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 252 deletions.
3 changes: 2 additions & 1 deletion modeq/ast/Makefile
Expand Up @@ -26,6 +26,7 @@ DLG = $(BIN)/dlg
#CFLAGS = -ggdb -I. -I$(ANTLR_H) #does not work in linux
CFLAGS = -g -I. -I.. -I$(ANTLR_H) -I$(RMLINCLUDE)
#AFLAGS = -CC -gt
#AFLAGS = -gt -gl
AFLAGS = -gt -gl -gh
#DFLAGS = -C2 -CC -cs
DFLAGS = -C2
Expand Down Expand Up @@ -55,7 +56,7 @@ modgram.o: modgram.c attrib.h parser.h tokens.h \
scanner.o: scanner.c attrib.h parser.h
err.o: err.c attrib.h parser.h tokens.h
yacclib.o: yacclib.c $(RMLINCLUDE)/rml.h yacclib.h
attrib.o: attrib.c stdpccts.h attrib.h parser.h tokens.h mode.h
attrib.o: attrib.c attrib.h parser.h tokens.h mode.h stdpccts.h

$(SCAN).o : $(SCAN).c $(TOKENS)
$(CC) -c $(CFLAGS) -o $(SCAN).o $(SCAN).c
Expand Down
7 changes: 7 additions & 0 deletions modeq/ast/modgram.g
Expand Up @@ -21,6 +21,9 @@ typedef int bool;
ast->aux[3]=NULL; \
ast->aux[4]=NULL;

/* #define MATCH */

extern int parse_failed;
>>

<<
Expand Down Expand Up @@ -182,6 +185,10 @@ extern void *sibling_list(AST *ast);
/**************************************************************/
/* The main part of the Modelica parser. */

/* exception */
/* default : */
/* << parse_failed = 1; >> */

model_specification :
(
cl:class_definition[false,false] ";"!
Expand Down
36 changes: 23 additions & 13 deletions modeq/ast/parsemod.c
Expand Up @@ -52,6 +52,8 @@ void *sibling_list(AST *ast)
}
}

int parse_failed;

RML_BEGIN_LABEL(Parser__parse)
{
AST *root = NULL;
Expand All @@ -60,20 +62,28 @@ RML_BEGIN_LABEL(Parser__parse)
fprintf(stderr, "freopen %s failed: %s\n",
RML_STRINGDATA(a0), strerror(errno));
RML_TAILCALLK(rmlFC);
} else {
int fail;
parse_failed = 0;
ANTLR(model_specification(&root/*, &fail*/), stdin);
printf("fail = %d\n", fail);
if(parse_failed) {
fprintf(stderr, "parse erro\n");
RML_TAILCALLK(rmlFC);
} else {
/* fprintf(stderr, "root = %p\n", root); */
/* fprintf(stderr, "\n"); */
/* zzpre_ast(root, &print_token, &print_lpar, &print_rpar); */
fprintf(stderr, "\n\n");

/* if( !root )
* RML_TAILCALLK(rmlFC); */

rmlA0 = sibling_list(root);

RML_TAILCALLK(rmlSC);
}
}

ANTLR(model_specification(&root), stdin); /* start first rule */
/* fprintf(stderr, "root = %p\n", root); */
/* fprintf(stderr, "\n"); */
/* zzpre_ast(root, &print_token, &print_lpar, &print_rpar); */
fprintf(stderr, "\n\n");

/* if( !root )
* RML_TAILCALLK(rmlFC); */

rmlA0 = sibling_list(root);

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

18 changes: 9 additions & 9 deletions modeq/builtin.rml
Expand Up @@ -103,15 +103,15 @@ Env.FRAMEVAR("time", Absyn.ATTR(Absyn.NODIM, false, Absyn.VAR, Absyn.BIDIR),
relation initial_env =

rule Env.open_scope(Env.empty_env) => env1 &
Env.extend_frame_c(env1, rl_type, SCode.NOMOD) => env2 &
Env.extend_frame_c(env2, int_type, SCode.NOMOD) => env3 &
Env.extend_frame_c(env3, str_type, SCode.NOMOD) => env4 &
Env.extend_frame_c(env4, bool_type, SCode.NOMOD) => env5 &
Env.extend_frame_c(env5, real_type, SCode.NOMOD) => env6 &
Env.extend_frame_c(env6, integer_type, SCode.NOMOD) => env7 &
Env.extend_frame_c(env7, string_type, SCode.NOMOD) => env8 &
Env.extend_frame_c(env8, boolean_type, SCode.NOMOD) => env9 &
Env.extend_frame_c(env9, boolean_type, SCode.NOMOD) => env10 &
Env.extend_frame_c(env1, rl_type) => env2 &
Env.extend_frame_c(env2, int_type) => env3 &
Env.extend_frame_c(env3, str_type) => env4 &
Env.extend_frame_c(env4, bool_type) => env5 &
Env.extend_frame_c(env5, real_type) => env6 &
Env.extend_frame_c(env6, integer_type) => env7 &
Env.extend_frame_c(env7, string_type) => env8 &
Env.extend_frame_c(env8, boolean_type) => env9 &
Env.extend_frame_c(env9, boolean_type) => env10 &
Env.extend_frame_v(env10, time_var) => env11
----------------------------------------------
initial_env () => env11
Expand Down
5 changes: 3 additions & 2 deletions modeq/connect.rml
Expand Up @@ -5,6 +5,7 @@
module Connect :

with "exp.rml"
with "staticexp.rml"
with "dae.rml"

(* datatype Dir = IN | OUT *)
Expand Down Expand Up @@ -174,7 +175,7 @@ end

relation find_in_set_equ : (Exp.ComponentRef list, Exp.ComponentRef) => () =

rule Exp.eq_cref(c1,c2)
rule StaticExp.eq_cref(c1,c2)
------------------
find_in_set_equ(c1::_,c2)

Expand All @@ -187,7 +188,7 @@ end
relation find_in_set_flow : ((Exp.ComponentRef * Face) list, Exp.ComponentRef)
=> () =

rule Exp.eq_cref(c1,c2)
rule StaticExp.eq_cref(c1,c2)
------------------
find_in_set_flow((c1,_)::_,c2)

Expand Down
81 changes: 69 additions & 12 deletions modeq/dae.rml
Expand Up @@ -13,7 +13,9 @@ module DAE:

datatype VarKind = LOCAL | PARAM | CONST

datatype DAEcomp = VAR of Exp.ComponentRef * VarKind
datatype Type = REAL | INT | BOOL | STRING

datatype DAEcomp = VAR of Exp.ComponentRef * VarKind * Type
| VARVAL of Ident * VarKind * Exp.Exp
| EQUATION of Exp.Exp
| COMP of Ident * DAEform
Expand All @@ -27,25 +29,46 @@ end

relation dump_kind =

rule print " constant "
rule print " constant "
--------------------
dump_kind CONST

rule print " parameter "
--------------------
dump_kind PARAM

rule print " local "
rule print " variable "
--------------------
dump_kind LOCAL

end

relation dump_type =

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

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

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

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

end

relation dump_comp: DAEcomp => () =

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

rule dump_kind kind & print id &
print "=" & Exp.print_exp ex & print "\n"
Expand All @@ -64,21 +87,55 @@ relation dump_comp: DAEcomp => () =

end

relation dump_list: DAEcomp list => () =
relation dump_var : DAEcomp => () =

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

axiom dump_var _

end

relation dump_equation : DAEcomp => () =

axiom dump_list []
rule print " " & Exp.print_exp eq & print "\n"
--------------------------------------
dump_equation(EQUATION(eq))

axiom dump_equation _

end

relation dump_vars: DAEcomp list => () =

axiom dump_vars []

rule dump_comp first &
dump_list rest
rule dump_var first &
dump_vars rest
-------------------
dump_list first :: rest
dump_vars first :: rest

end

relation dump: DAEform => () =
relation dump_equations: DAEcomp list => () =

axiom dump_equations []

rule dump_list l
rule dump_equation first &
dump_equations rest
-------------------
dump_equations first :: rest

end

relation dump: DAEform => () =

rule dump_vars l &
print "\nequations\n\n" &
dump_equations l
----------------
dump DAE(l)

end
11 changes: 5 additions & 6 deletions modeq/env.rml
Expand Up @@ -9,7 +9,6 @@ module Env:
with "absyn.rml"
with "values.rml"
with "explode.rml"
with "mod.rml"
with "types.rml"
with "classinf.rml"

Expand All @@ -23,15 +22,15 @@ module Env:
| VALBOUND of Values.Value

datatype Frame = FRAME of (SCode.Ident*FrameVar) list
* (SCode.Ident*SCode.Class*SCode.Mod) list
* (SCode.Ident*SCode.Class) list

type Env = Frame list

val empty_frame : Frame
val empty_env : Env

relation open_scope : Env => Env
relation extend_frame_c : (Env, SCode.Class, SCode.Mod) => Env
relation extend_frame_c : (Env, SCode.Class) => Env
relation extend_frame_v : (Env, FrameVar) => Env

relation make_binding : Absyn.Exp option => Binding
Expand All @@ -47,10 +46,10 @@ relation open_scope: Env => Env =

end

relation extend_frame_c : (Env, SCode.Class, SCode.Mod) => Env =
relation extend_frame_c : (Env, SCode.Class) => Env =

axiom extend_frame_c(FRAME(vs,cs)::fs,c as SCode.CLASS(n,_,_,_),m)
=> ((FRAME(vs,(n,c,m)::cs)::fs))
axiom extend_frame_c(FRAME(vs,cs)::fs,c as SCode.CLASS(n,_,_,_))
=> ((FRAME(vs,(n,c)::cs)::fs))

end

Expand Down
67 changes: 0 additions & 67 deletions modeq/exp.rml
Expand Up @@ -67,7 +67,6 @@ module Exp:
(** translations of the corresponding types in the `Exp' module. *)

relation extend_cref : (ComponentRef, Ident, Subscript list) => ComponentRef
relation eq_cref : (ComponentRef, ComponentRef) => ()
relation print_exp : Exp => ()
relation print_component_ref : ComponentRef => ()
relation print_list : ('a list, 'a => (), string) => ()
Expand All @@ -92,72 +91,6 @@ relation extend_cref : (ComponentRef, Ident, Subscript list) => ComponentRef =

end

(** - Equality relations *)

(** relation: eq_cref
**
** This relation checks if two component references can be considered
** equal and fails if not. Two component references are equal if all
** corresponding identifiers are the same, and if the subscripts are
** equal, according to the relation `eq_subscripts'.
**)

relation eq_cref : (ComponentRef, ComponentRef) => () =

rule n1 = n2 &
eq_subscripts (s1,s2)
---------------------
eq_cref (CREF_IDENT(n1,s1), CREF_IDENT(n2,s2))

rule n1 = n2 &
eq_subscripts (s1,s2) &
eq_cref (c1,c2)
---------------
eq_cref (CREF_QUAL(n1,s1,c1), CREF_QUAL(n2,s2,c2))

end

(** relation: eq_subscripts
**
** Two list of subscripts are equal if they are of equal length and
** all their elements are pairwise equal according to the relation
** `eq_subscript'.
**)

relation eq_subscripts : (Subscript list, Subscript list) => () =

axiom eq_subscripts([],[])

rule eq_subscript(s1,s2) &
eq_subscripts(ss1,ss2)
----------------------
eq_subscripts(s1::ss1, s2::ss2)

end

(** relation: eq_subscript
**
** This relation test whether two subscripts are equal. Two
** subscripts are equal if they have the same constructor, and if all
** corresponding expressions are either syntactically equal, or if
** they have the same constant value.
**)

relation eq_subscript : (Subscript, Subscript) => () =

axiom eq_subscript(NOSUB,NOSUB)

(* FIXME: this is not complete at all *)
rule s1 = s2
-------------------------------
eq_subscript(SUB1(s1),SUB1(s2))

rule print "- eq_subscript failed\n"
-------------------------------
eq_subscript(_,_)

end

(**
** - Printing expressions
**
Expand Down

0 comments on commit 913cdd7

Please sign in to comment.