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@314 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Jul 2, 1998
1 parent 6f63e4a commit 7b8d694
Show file tree
Hide file tree
Showing 13 changed files with 636 additions and 196 deletions.
5 changes: 3 additions & 2 deletions modeq/Makefile
Expand Up @@ -14,8 +14,7 @@ RML = rmlc -g
PROG = modeq
AST = ast/libast.a

SRCRML= dae.rml \
types.rml \
SRCRML= types.rml \
absyn.rml \
explode.rml \
dump.rml \
Expand All @@ -26,8 +25,10 @@ SRCRML= dae.rml \
connect.rml \
classinf.rml \
exp.rml \
algorithm.rml \
staticexp.rml \
values.rml \
dae.rml \
mod.rml \
inst.rml \
main.rml
Expand Down
5 changes: 4 additions & 1 deletion modeq/absyn.rml
Expand Up @@ -76,7 +76,10 @@ module Absyn:
| EQ_FOR of Ident * Exp * Equation list

datatype Algorithm = ALG_ASSIGN of ComponentRef * Exp
| ALG_COND (* FIXME *)
| ALG_IF of Exp
* Algorithm list (* true branch *)
* (Exp * Algorithm list) list (* elseif *)
* Algorithm list (* else branch *)
| ALG_FOR of Ident * Exp * Algorithm list
| ALG_WHILE of Exp * Algorithm list
| ALG_WHEN of Exp * Algorithm list
Expand Down
12 changes: 11 additions & 1 deletion modeq/ast/attrib.c
Expand Up @@ -91,6 +91,7 @@ void print_attr(Attrib *attr, FILE *f)
tokprinter(OUTPUT); /* 23 */
tokprinter(FLOW); /* 24 */
tokprinter(EQUATION); /* 25 */
tokprinter(ALGORITHM); /* 27 */
tokprinter(FINAL); /* 28 */
tokprinter(PUBLIC); /* 29 */
tokprinter(PROTECTED); /* 30 */
Expand All @@ -102,24 +103,33 @@ void print_attr(Attrib *attr, FILE *f)
tokprinter(THEN); /* 37 */
tokprinter(ELSE); /* 38 */
tokprinter(ELSEIF); /* 39 */
tokprinter(WHEN);
tokprinter(DO);
tokprinter(AND); /* 40 */
tokprinter(NOT); /* 42 */
tokprinter(CONNECT);
tokprinter(IN);
tokprinter(FOR);
tokprinter(WHILE);
tokprinter(EQUALS); /* 49 */
tokprinter(ASSIGN); /* 50 */
tokprinter(PLUS); /* 51 */
tokprinter(MINUS); /* 52 */
tokprinter(MULT); /* 53 */
tokprinter(DIV); /* 54 */
tokprinter(DOT); /* 55 */
tokprinter(LESS);
tokprinter(LESSEQ); /* 57 */
tokprinter(GREATEREQ); /* 59 */
tokprinter(GREATER); /* 59 */
tokprinter(GREATEREQ); /* 60 */
tokprinter(COMPONENTS); /* 66 */
tokprinter(TYPE_PREFIX); /* 67 */
tokprinter(FUNCALL); /* 68 */
tokprinter(ELEMENT); /* 70 */
tokprinter(MODIFICATION); /* 71 */
tokprinter(SUBSCRIPT); /* 72 */
tokprinter(ROW);
tokprinter(COLUMN);

case zzEOF_TOKEN:
default:
Expand Down
63 changes: 44 additions & 19 deletions modeq/ast/modgram.g
Expand Up @@ -110,9 +110,8 @@ void unimpl(char *rule)
#token THEN "then"
#token ELSE "else"
#token ELSEIF "elseif"
/* #token ENDIF "endif" */
/* #token WHEN "when" */
/* #token ENDWHEN "endwhen" */
#token WHEN "when"
#token DO "do"
#token OR "or"
#token AND "and"
#token NOT "not"
Expand Down Expand Up @@ -166,6 +165,8 @@ void unimpl(char *rule)
#token ELEMENT
#token MODIFICATION
#token SUBSCRIPT
#token ROW
#token COLUMN

#token "//(~[\n])*" << zzskip(); >> /* skip C++-style comments */

Expand Down Expand Up @@ -530,7 +531,7 @@ algorithm :
;

conditional_equation_e :
<< void *tbranch, *ebranch, *fbranch;
<< void *tbranch, *ebranch, *fbranch = NULL;
AST *elseif = NULL; >>
IF^ c:expression THEN!
el:equation_list << tbranch = sibling_list(#el); >>
Expand All @@ -547,7 +548,8 @@ conditional_equation_e :
{ ELSE!
el2:equation_list << fbranch = sibling_list(#el2); >> }
END! IF!
<< #0->rml = Absyn__EQ_5fIF(#c->rml,tbranch,ebranch,fbranch); >>
<< #0->rml = Absyn__EQ_5fIF(#c->rml,tbranch,ebranch,
fbranch==NULL ? mk_nil() : fbranch); >>
;

equation_elseif :
Expand All @@ -557,14 +559,31 @@ equation_elseif :
;

conditional_equation_a :
i:IF^ expression THEN!
el:algorithm_list
( ELSEIF! expression THEN!
el1:algorithm_list )*
<< void *tbranch, *ebranch, *fbranch = NULL;
AST *elseif = NULL; >>
i:IF^ c:expression THEN!
el:algorithm_list << tbranch = sibling_list(#el); >>

( ei:algorithm_elseif
<< if (elseif == NULL) elseif = #ei; >> )*

/* Collect the elseif branches */
<< if (elseif == NULL)
ebranch = mk_nil();
else
ebranch = sibling_list(elseif); >>

{ ELSE!
el2:algorithm_list }
el2:algorithm_list << fbranch = sibling_list(#el2); >> }
END! IF!
<< unimpl("conditional_equation_a"); >>
<< #0->rml = Absyn__ALG_5fIF(#c->rml,tbranch,ebranch,
fbranch==NULL ? mk_nil() : fbranch); >>
;

algorithm_elseif :
ELSEIF^ c:expression THEN!
el:algorithm_list
<< #0->rml = mk_box2(0,#c->rml,sibling_list(#el)); >>
;

for_clause_e :
Expand Down Expand Up @@ -597,9 +616,9 @@ while_clause :
;

when_clause :
wh:WHEN^ e:expression LOOP!
wh:WHEN^ e:expression DO!
el:algorithm_list
END! WHILE!
END! WHEN!
<< #wh->rml = Absyn__ALG_5fWHEN(#e->rml, sibling_list(#el)); >>
;

Expand Down Expand Up @@ -750,9 +769,9 @@ primary : << bool is_matrix; >>
c:column_expression > [is_matrix]
<<
if (is_matrix) {
unimpl("primary (matrix)");
#0->rml = Absyn__MATRIX(#c->rml);
} else {
#0->rml = Absyn__ARRAY(sibling_list(#c));
#0->rml = Absyn__ARRAY(#c->rml);
}
>>
RBRACK!
Expand Down Expand Up @@ -802,15 +821,21 @@ function_call :
/* not in document's grammar */
column_expression > [bool is_matrix] :
<< $is_matrix=false; >>
row_expression ( ";"! row_expression << $is_matrix=true; >> )*
e:row_expression ( ";"! row_expression << $is_matrix=true; >> )*
<< if($is_matrix) {
Attrib a = $[COLUMN,"---"];
#0 = #(#[&a], #e);
#0->rml = sibling_list(#e);
} >>
;

row_expression :
expression
e:expression
( ","! expression
)*
/* create token with translation {, balancer }, type BALANCED */
<< /* #0=#(#[EXTRA_TOKEN,"{",OP_BALANCED,'}'],#0); */ >>
<< Attrib a = $[ROW,"---"];
#0 = #(#[&a], #e);
#0->rml = sibling_list(#e); >>
;

function_arguments :
Expand Down
6 changes: 3 additions & 3 deletions modeq/ast/parsemod.c
Expand Up @@ -72,9 +72,9 @@ RML_BEGIN_LABEL(Parser__parse)
RML_TAILCALLK(rmlFC);
} else {
/* fprintf(stderr, "root = %p root->rml = %p\n", root, root->rml); */
/* fprintf(stderr, "\n"); */
/* zzpre_ast(root, &print_token, &print_lpar, &print_rpar); */
/* fprintf(stderr, "\n\n"); */
fprintf(stderr, "\n");
zzpre_ast(root, &print_token, &print_lpar, &print_rpar);
fprintf(stderr, "\n\n");

/* if( !root )
* RML_TAILCALLK(rmlFC); */
Expand Down
90 changes: 70 additions & 20 deletions modeq/dae.rml
Expand Up @@ -15,6 +15,7 @@ module DAE:
with "dump.rml"
with "exp.rml"
with "explode.rml"
with "algorithm.rml"

type Ident = string

Expand All @@ -26,7 +27,7 @@ module DAE:
* Absyn.ArrayDim (*FIXME*)
| VARVAL of Ident * VarKind * Exp.Exp
| EQUATION of Exp.Exp
| ALGORITHM of SCode.Algorithm
| ALGORITHM of Algorithm.Algorithm
| COMP of Ident * DAEform
and DAEform = DAE of DAEcomp list

Expand Down Expand Up @@ -152,9 +153,9 @@ end
relation dump_algorithm : DAEcomp => () =

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

axiom dump_algorithm _

Expand Down Expand Up @@ -193,51 +194,100 @@ relation dump_algorithms: DAEcomp list => () =

end

(** relation: pp_algorithm
(** relation: pp_statement
**
** Prettyprint an algorithm element
** Prettyprint an algorithm statement
**)

relation pp_algorithm : Absyn.Algorithm => () =
relation pp_statement : Algorithm.Statement => () =

rule pp_alg (alg,2)
rule pp_stmt (alg,2)
--------------
pp_algorithm alg
pp_statement alg

end

relation pp_alg : (Absyn.Algorithm, int) => () =
relation pp_stmt : (Algorithm.Statement, int) => () =

rule indent i &
Dump.print_component_ref c &
Exp.print_component_ref c &
print " := " &
Dump.print_exp e &
Exp.print_exp e &
print ";\n"
----------
pp_alg (Absyn.ALG_ASSIGN(c,e), i)
pp_stmt (Algorithm.ASSIGN(c,e), i)

rule indent i &
print "while(" & Dump.print_exp e & print ") loop\n" &
print "if " & Exp.print_exp e & print " then\n" &
int_add(i,2) => i' &
pp_alg_list (algs, i') &
pp_stmt_list (then, i') &
pp_else (else, i) &
indent i & print "end if;\n"
-------------------
pp_stmt (Algorithm.IF(e,then,else), i)

rule indent i &
print "for " & print id & print " in " &
Exp.print_exp e & print " loop\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end for;\n"
-------------------
pp_stmt (Algorithm.FOR(id,e,stmts), i)

rule indent i &
print "while " & Exp.print_exp e & print " loop\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end while;\n"
-------------------
pp_alg (Absyn.ALG_WHILE(e,algs), i)
pp_stmt (Algorithm.WHILE(e,stmts), i)

rule indent i &
print "when " & Exp.print_exp e & print " do\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end when;\n"
-------------------
pp_stmt (Algorithm.WHEN(e,stmts), i)

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

end

relation pp_alg_list : (Absyn.Algorithm list, int) => () =
relation pp_stmt_list : (Algorithm.Statement list, int) => () =

axiom pp_alg_list ([],_)
axiom pp_stmt_list ([],_)

rule pp_alg (alg,i) & pp_alg_list(algs,i)
rule pp_stmt (stmt,i) & pp_stmt_list(stmts,i)
--------------------------------
pp_alg_list (alg::algs,i)
pp_stmt_list (stmt::stmts,i)

end

relation pp_else : (Algorithm.Else, int) => () =

axiom pp_else (Algorithm.NOELSE, _)

rule indent i &
print "elseif " & Exp.print_exp e & print " then\n" &
int_add(i,2) => i' &
pp_stmt_list (then, i') &
pp_else (else, i)
-----------------
pp_else (Algorithm.ELSEIF(e,then,else), i)

rule indent i &
print "else\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i')
------------------------
pp_else (Algorithm.ELSE(stmts), i)

end

Expand Down

0 comments on commit 7b8d694

Please sign in to comment.