Skip to content

Commit

Permalink
Added incremental adding of top level classes
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@781 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Apr 22, 2002
1 parent 4f69e1c commit 3136a93
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
43 changes: 43 additions & 0 deletions modeq/absyn.rml
Expand Up @@ -248,6 +248,7 @@ module Absyn:
(** assigned special restrictions. *)


relation update_program: (Program,Program) => Program
relation path_string : Path => string
relation cref_to_path : ComponentRef => Path
relation element_spec_name : ElementSpec => Ident
Expand All @@ -256,6 +257,48 @@ module Absyn:
relation print_absyn_exp : Exp => () (*PR. for debugging.*)
end

(** relation: update_program
**
** This relation takes an old program, i.e. the old symboltable, and a new program, i.e. a new set of classes and updates the old program with the definitions in the new one.
**)

relation update_program: (Program,Program) => Program =
axiom update_program ([],prg) => prg

rule class_in_program(name,p2) => false &
print "class not in program\n" &
update_program(p1,c1::p2) => pnew
---------------------------------
update_program ((c1 as CLASS(name,_,_,_))::p1,p2) => pnew

rule class_in_program(name,p2) => true &
print "class in program\n" &
update_program(p1,p2) => pnew
-----------------------------
update_program ((c1 as CLASS(name,_,_,_))::p1,p2) => pnew

rule print "Further program merging not implemented yet\n"
------------------------
update_program (a,b) => b
end


(** relation: class_in_program
** This relation takes a name and a Program and returns true if the name exists as a top class in the program.
**)

relation class_in_program:(string,Program) => bool =

axiom class_in_program (str,[]) => false

rule not str = c1 &
class_in_program(str,p) => res
-----------------------
class_in_program (str, CLASS(c1,_,_,_)::p) => res

axiom class_in_program (_,_) => true
end

(** relation: path_string
**
** This relation simply converts a `Path' to a `string'.
Expand Down
4 changes: 2 additions & 2 deletions modeq/absyn_builder/Makefile.in
Expand Up @@ -32,8 +32,8 @@ walkergen= modelica_tree_parser.cpp modelica_tree_parser.hpp \
walkersrcs=$(filter %.cpp,$(walkergen))
walkerobjs=$(walkersrcs:.cpp=.o)

exprparsegen = modelica_expression_parser.cpp modelica_expression_parser.hpp \
modelica_tree_parserTokenTypes.txt
exprparsegen = modelica_expression_parser.cpp modelica_expression_parser.hpp

exprparsesrcs=$(filter %.cpp,$(exprparsegen))
exprparseobjs=$(exprparsesrcs:.cpp=.o)

Expand Down
35 changes: 19 additions & 16 deletions modeq/main.rml
Expand Up @@ -33,6 +33,7 @@ module Main:
relation main: string list => ()
end

with "absyn.rml"
with "modutil.rml"
with "parse.rml"
with "dump.rml"
Expand All @@ -58,11 +59,11 @@ relation server_loop: (int,Interactive.InteractiveSymbolTable) => Interactive.I
Debug.fprint ("interactivedump" ,"------- Recieved Data from client -----\n") &
Debug.fprint ("interactivedump" , str ) &
Debug.fprint ("interactivedump", "------- End recieved Data-----\n") &
handle_command str => true &
Socket.sendreply(shandle,"OK\n") &
server_loop (shandle,isymb) => newsymb
handle_command (str,isymb) => (true,replystr,newsymb) &
Socket.sendreply(shandle,replystr) &
server_loop (shandle,newsymb) => ressymb
-----------------------------
server_loop (shandle,isymb) => newsymb
server_loop (shandle,isymb) => ressymb

rule print "Exiting\n" &
Socket.sendreply(shandle, "quit requested, shutting server down") &
Expand Down Expand Up @@ -120,32 +121,34 @@ end
** This relation handles the commands in form of strings send to the server
** If the command is quit, the relation returns false, otherwise it sends the string to the parse relation and returns true.
**)
relation handle_command: string => bool =
rule let quitcmd = "quit()" &
string_length(quitcmd) => slen &
strncmp("quit()",str,slen) => true
---------------------------
handle_command str => false
relation handle_command: (string,Interactive.InteractiveSymbolTable) =>
(bool, string, Interactive.InteractiveSymbolTable) =

rule strncmp("quit()",str,6) => true
-------------------------------
handle_command (str, isymb) => (false,"Ok\n",isymb)

rule check_classdef str => true &
Debug.fprint ("dump","\nDetected class definition, parsing...\n") &
Parser.parsestring str => p &
Absyn.update_program (iprog,p) => newprog &
Debug.fprint ("dump", "\n--------------- Parsed program ---------------\n") &
Debug.fcall ("dumpgraphviz", DumpGraphviz.dump, p) &
Debug.fcall ("dump", Dump.dump, p)
------------------------------------
handle_command str => true
Debug.fcall ("dumpgraphviz", DumpGraphviz.dump, newprog) &
Debug.fcall ("dump", Dump.dump, newprog)
----------------------------------
handle_command (str, Interactive.SYMBOLTABLE(iprog,a,b,c)) =>
(true, "Ok\n",Interactive.SYMBOLTABLE(newprog,a,b,c))

rule Debug.fprint ("dump","\nNot a class definition, trying expresion parser\n") &
Parser.parsestringexp str => exp &
Debug.fprint ("dump", "\n--------------- Parsed expression ---------------\n") &
Debug.fcall ("dump", Dump.dump_istmt, exp)
--------------------------------------------------
handle_command str => true
handle_command (str, isymb) => (true, "No evaluation yet", isymb)

rule print "Error occured building AST\n"
----------------------------------
handle_command _ => true
handle_command (_,isymb) => (true,"Syntax Error\n", isymb)
end

(** relation: translate_file
Expand Down

0 comments on commit 3136a93

Please sign in to comment.