Skip to content

Commit

Permalink
Added split definitions, e.g. allowing 'package A' as input.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1066 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 13, 2004
1 parent 7cc3168 commit 6778075
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 50 deletions.
37 changes: 37 additions & 0 deletions modelica_parser/src/modelica_parser.g
Expand Up @@ -21,6 +21,7 @@ options {
tokens {
ALGORITHM_STATEMENT;
ARGUMENT_LIST;
BEGIN_DEFINITION;
CLASS_DEFINITION ;
CLASS_MODIFICATION;
CODE_EXPRESSION;
Expand All @@ -31,15 +32,18 @@ tokens {
CODE_ALGORITHM;
CODE_INITIALALGORITHM;
COMMENT;
COMPONENT_DEFINITION;
DECLARATION ;
DEFINITION ;
END_DEFINITION;
ENUMERATION_LITERAL;
ELEMENT ;
ELEMENT_MODIFICATION ;
ELEMENT_REDECLARATION ;
EQUATION_STATEMENT;
INITIAL_EQUATION;
INITIAL_ALGORITHM;
IMPORT_DEFINITION;
EXPRESSION_LIST;
EXTERNAL_FUNCTION_CALL;
FOR_INDICES ;
Expand All @@ -65,13 +69,46 @@ tokens {


stored_definition :
// To handle split models into several evaluations, "package A",
// "model test end test", "end A;" as in MathModelica
( (ENCAPSULATED)?
(PARTIAL)?
class_type
IDENT EOF ) => ( (ENCAPSULATED)?
(PARTIAL)?
class_type
IDENT EOF!)
{
#stored_definition = #([BEGIN_DEFINITION,"BEGIN_DEFINITION"],
#stored_definition);
}
|
END! IDENT SEMICOLON! EOF! {
#stored_definition = #([END_DEFINITION,"END_DEFINITION"],
#stored_definition);
}
|
(component_clause) => component_clause SEMICOLON! EOF!
{
#stored_definition = #([COMPONENT_DEFINITION,"COMPONENT_DEFINITION"],
#stored_definition);
}
|
import_clause SEMICOLON! EOF!
{
#stored_definition = #([IMPORT_DEFINITION,"IMPORT_DEFINITION"],
#stored_definition);
}
|
// End handle split models.
(within_clause SEMICOLON!)?
((f:FINAL)? class_definition SEMICOLON!)*
EOF!
{
#stored_definition = #([STORED_DEFINITION,"STORED_DEFINITION"],
#stored_definition);
}

;

within_clause :
Expand Down
11 changes: 11 additions & 0 deletions modeq/absyn.rml
Expand Up @@ -40,6 +40,17 @@ module Absyn:
(** - Programs *)
datatype Program = PROGRAM of Class list (* List of classes *)
* Within (* Within statement *)
| BEGIN_DEFINITION of Path (* For split definitions*)
* Restriction (* Class restriction *)
* bool (* Partial *)
* bool (* Encapsulated *)
| END_DEFINITION of Ident (* For split definitions *)
| COMP_DEFINITION of ElementSpec (* For split definitions*)
* Path option (* insert into.
Default, NONE *)
| IMPORT_DEFINITION of ElementSpec(* For split definitions*)
* Path option (* insert into.
Default, NONE *)

(** A program is simply a list of class definitions declared at top
** level in the source file, combined with a within statement that
Expand Down
2 changes: 1 addition & 1 deletion modeq/absyn_builder/parse.cpp
Expand Up @@ -161,7 +161,7 @@ RML_BEGIN_LABEL(Parser__parsestring)
parse_tree_dumper dumper(std::cout);
//dumper.initializeASTFactory(factory);
//dumper.setASTFactory(&factory);
//dumper.dump(t);
dumper.dump(t);
}

modelica_tree_parser build;
Expand Down
27 changes: 27 additions & 0 deletions modeq/absyn_builder/walker.g
Expand Up @@ -100,10 +100,37 @@ tokens {
stored_definition returns [void *ast]
{
void *within = 0;
void *restr = 0;
void *imp=0;
void *c=0;
void *class_def = 0;
l_stack el_stack;
}
:
#(BEGIN_DEFINITION (e:ENCAPSULATED)? (p:PARTIAL)?
restr = class_restriction i:IDENT)
{
ast = Absyn__BEGIN_5fDEFINITION(Absyn__IDENT(to_rml_str(i)),
restr,
RML_PRIM_MKBOOL(p != 0),
RML_PRIM_MKBOOL(e != 0));
}
|
#(END_DEFINITION i2:IDENT)
{
ast = Absyn__END_5fDEFINITION(to_rml_str(i2));
}
|
#(COMPONENT_DEFINITION c=component_clause)
{
ast = Absyn__COMP_5fDEFINITION(c,mk_none());
}
|
#(IMPORT_DEFINITION imp=import_clause)
{
ast = Absyn__IMPORT_5fDEFINITION(imp,mk_none());
}
|
#(STORED_DEFINITION
( within = within_clause )?
((f:FINAL )?
Expand Down
6 changes: 6 additions & 0 deletions modeq/ceval.rml
Expand Up @@ -921,6 +921,12 @@ relation ceval_interactive_functions: (Env.Env, Exp.Exp, Interactive.Interactive
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("saveModel"),[Exp.SCONST(filename),Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
=> (Values.BOOL(true),st)

rule Dump.unparse_str(p) => str &
System.write_file(filename,str)
--------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("saveAll"),[Exp.SCONST(filename)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
=> (Values.BOOL(true),st)

rule (*Error writing to file *)
Static.component_ref_to_path(cr) => classpath &
Interactive.get_pathed_class_in_program(classpath,p) => class &
Expand Down
8 changes: 7 additions & 1 deletion modeq/classloader.rml
Expand Up @@ -58,7 +58,13 @@ relation load_class: (Absyn.Path, string) => (Absyn.Program) =
-------------------------------------
load_class(Absyn.IDENT(classname),mp) => p

(** Qualified names: Load the complete package and then check that **)
rule (** Qualified names: First check if it is defined in a file pack.mo *)
System.strtok(mp,":") => mps &
load_class_from_mps(pack,mps) => p
-------------------------------------
load_class(Absyn.QUALIFIED(pack,rest),mp) => p

(** Qualified names: Else, load the complete package and then check that **)
(** the package contains the file **)
rule System.strtok(mp,":") => mps &
load_complete_package_from_mps(pack,mps,Absyn.TOP,Absyn.PROGRAM([],Absyn.TOP)) => p &
Expand Down
54 changes: 31 additions & 23 deletions modeq/dump.rml
Expand Up @@ -141,7 +141,7 @@ relation unparse_class_str: (int, Absyn.Class,string,string,string) => string =
select_string(f, "final ","") => s2 &
unparse_restriction_str (r) => s3 &
int_add(i,1) => i' &
unparse_class_part_str_lst(i',parts) => s4 &
unparse_class_part_str_lst(i',parts,true) => s4 &
unparse_string_comment_option(optcmt) => s5 &
Util.string_append_list([is, s1, s2, re, io, s3, " ", n, s5, "\n", s4, is, "end ", n]) => str
-----------------------------
Expand Down Expand Up @@ -455,67 +455,75 @@ relation print_external_decl : Absyn.ExternalDecl => () =

end

relation unparse_class_part_str_lst: (int, Absyn.ClassPart list) => string =
relation unparse_class_part_str_lst: (int, Absyn.ClassPart list,bool)
=> string =

axiom unparse_class_part_str_lst (_,[]) => ""
axiom unparse_class_part_str_lst (_,[],false) => ""

rule unparse_class_part_str(i,x) => s1 &
unparse_class_part_str_lst(i,xs) => s2 &
rule unparse_class_part_str(i,x,skippublic) => s1 &
unparse_class_part_str_lst(i,xs,false) => s2 &
string_append(s1,s2) => res
----------------------
unparse_class_part_str_lst(i,x::xs) => res
unparse_class_part_str_lst(i,x::xs,skippublic) => res
end

relation unparse_class_part_str: (int, Absyn.ClassPart) => string =
relation unparse_class_part_str: (int, Absyn.ClassPart,bool) => string =

axiom unparse_class_part_str(i, Absyn.PUBLIC([])) => ""
axiom unparse_class_part_str(i, Absyn.PROTECTED([])) => ""
axiom unparse_class_part_str(i, Absyn.EQUATIONS([])) => ""
axiom unparse_class_part_str(i, Absyn.INITIALEQUATIONS([])) => ""
axiom unparse_class_part_str(i, Absyn.ALGORITHMS([])) => ""
axiom unparse_class_part_str(i, Absyn.INITIALALGORITHMS([])) => ""
axiom unparse_class_part_str(i, Absyn.PUBLIC([]),_) => ""
axiom unparse_class_part_str(i, Absyn.PROTECTED([]),_) => ""
axiom unparse_class_part_str(i, Absyn.EQUATIONS([]),_) => ""
axiom unparse_class_part_str(i, Absyn.INITIALEQUATIONS([]),_) => ""
axiom unparse_class_part_str(i, Absyn.ALGORITHMS([]),_) => ""
axiom unparse_class_part_str(i, Absyn.INITIALALGORITHMS([]),_) => ""

rule unparse_elementitem_str_lst(i,el) => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list([is,"public \n",s1]) => str
Util.string_append_list([is,s1]) => str
-----------------------------------------------
unparse_class_part_str(i, Absyn.PUBLIC(el)) => str
unparse_class_part_str(i, Absyn.PUBLIC(el),true) => str

rule unparse_elementitem_str_lst(i,el) => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list([is,"public \n",s1]) => str
-----------------------------------------------
unparse_class_part_str(i, Absyn.PUBLIC(el),false) => str

rule unparse_elementitem_str_lst(i,el) => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list([is,"protected \n",s1]) => str
---------------------------------------
unparse_class_part_str(i, Absyn.PROTECTED(el)) => str
unparse_class_part_str(i, Absyn.PROTECTED(el),_) => str

rule unparse_equationitem_str_lst(i,eqs,";\n") => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list(["\n",is,"equation \n",s1]) => str
--------------------------------------
unparse_class_part_str(i, Absyn.EQUATIONS(eqs)) => str
unparse_class_part_str(i, Absyn.EQUATIONS(eqs),_) => str

rule unparse_equationitem_str_lst(i,eqs,";\n") => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list(["\n",is,"initial equation \n",s1]) => str
--------------------------------------
unparse_class_part_str(i, Absyn.INITIALEQUATIONS(eqs)) => str
unparse_class_part_str(i, Absyn.INITIALEQUATIONS(eqs),_) => str

rule unparse_algorithm_str_lst(i,eqs,"\n") => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list([is,"algorithm \n",s1]) => str
--------------------------------------
unparse_class_part_str(i, Absyn.ALGORITHMS(eqs)) => str
unparse_class_part_str(i, Absyn.ALGORITHMS(eqs),_) => str

rule unparse_algorithm_str_lst(i,eqs,"\n") => s1 &
int_sub(i,1) => i' &
indent_str(i') => is &
Util.string_append_list([is,"initial algorithm \n",s1]) => str
-----------------------------------------------
unparse_class_part_str(i, Absyn.INITIALALGORITHMS(eqs)) => str
unparse_class_part_str(i, Absyn.INITIALALGORITHMS(eqs),_) => str

rule get_extlang_str(lang) => langstr &
print_component_ref_str output => outputstr &
Expand All @@ -524,7 +532,7 @@ axiom unparse_class_part_str(i, Absyn.INITIALALGORITHMS([])) => ""
indent_str(i) => is &
Util.string_append_list(["\n", is, "external ",langstr," ", outputstr, "=",ident,"(",expstr,");\n"]) => str
--------------------------------------
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(SOME(ident),lang,SOME(output),expl)))
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(SOME(ident),lang,SOME(output),expl)),_)
=> str

rule get_extlang_str(lang) => langstr &
Expand All @@ -533,13 +541,13 @@ axiom unparse_class_part_str(i, Absyn.INITIALALGORITHMS([])) => ""
indent_str(i) => is &
Util.string_append_list(["\n", is, "external ", langstr," ",ident,"(",expstr,");\n"]) => str
--------------------------------------
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(SOME(ident),lang,NONE,expl)))
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(SOME(ident),lang,NONE,expl)),_)
=> str

rule indent_str(i) => is &
Util.string_append_list(["\n",is,"external;\n"]) => res
-----------------
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(NONE,_,NONE,_)))
unparse_class_part_str(i, Absyn.EXTERNAL(Absyn.EXTERNALDECL(NONE,_,NONE,_)),_)
=> res
end

Expand Down

0 comments on commit 6778075

Please sign in to comment.