Sode.tmp.rb

Path: Sode.tmp.rb
Last Update: Wed Jan 23 12:07:24 GMT-6:00 2008
                                                       ###

   File:     Sode.rb

   Subject:  Ruby program to generate a Ruby program ("Diffeq.rb")
              to solve a system of ordinary differential equations
              with long Taylor series.

   Author:   Dennis J. Darland

   Date:     April 8, 2007

Copyright (C) 2007,2008 Dennis J. Darland

This program is free software you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Methods

Constants

DEBUG = 0  
                                                       ###

   File:     Sode.rb

   Subject:  Ruby program to generate a Ruby program ("Diffeq.rb")
              to solve a system of ordinary differential equations
              with long Taylor series.

   Author:   Dennis J. Darland

   Date:     April 8, 2007
Copyright (C) 2007,2008 Dennis J. Darland

This program is free software you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

NUM = 1
IDENTIFIER = 2
NONE = -1

Public Instance methods

 code between #DJDSTOP & #DJDSTART commented out by djdpre.rb (for ease in converting from unicon)
 this code was developed to test priority code

DJDSTOP

 def read_eq_db
   eq_db =  File.new("db","r")
   line = eq_db.gets
   while line do
     line = line.chomp
     if line =~ $lhs_re then
       lhs = $&
       rest = $'
     else
       puts "error in dependancies 1"
       $stderr.puts "error in dependencies 1"
       exit 1
     end
     if rest =~ $skip_re then
       rest = $'
     else
       puts "error in dependancies 2"
       $stderr.puts "error in dependencies 2"
       exit 1
     end
     if rest =~ $degree_re then
       degree = $&.to_i
       rest = $'
     else
       puts "error in dependancies 1"
       $stderr.puts "error in dependencies 1"
       exit 1
     end
     $eq_dep_data[lhs] = Eq_dep_rec.new(degree)

     while rest =~ $skip_re do
       $no_eqs += 1
       rest = $'
       if rest =~ $rhs_re then
         rhs = $&
         rest = $'
       else
         puts "error in dependancies 1"
         $stderr.puts "error in dependencies 1"
         exit 1
       end
       if rest =~ $skip_re then
         rest = $'
       else
         puts "error in dependancies 2"
         $stderr.puts "error in dependencies 2"
         exit 1
       end
       if rest =~ $degree_re then
         degree = $&.to_i
         rest = $'
       else
         puts "error in dependancies 1"
         $stderr.puts "error in dependencies 1"
         exit 1
       end
       if degree > $eq_dep_data[lhs].rhs_dat_val(rhs) then
         $eq_dep_data[lhs].rhs_dat_put(rhs,degree)
       end
     end

     line = eq_db.gets
   end
 end

 #DJDSTART

DJDSTOP

 def emit_pre_Si,operand)
 i
 no_a1
 no_a2
 no_a3
 no_a1 = no + "_a1"
 no_a2 = no + "_a2"
 no_a3 = no + "_a3"
 $sym_tbl[no_a1] = Sym_tbl_entry.new(IDENTIFIER,no_a1)
 $sym_tbl[no_a2] = Sym_tbl_entry.new(IDENTIFIER,no_a2)
 $sym_tbl[no_a3] = Sym_tbl_entry.new(IDENTIFIER,no_a3)

 i = 1
 while i <= $min_hdrs do
 if (j == 1) then
     $outhdr[1].puts no,"[1] = ",EVALF,"(Si(", operand,"[1]))"
     $outhdr[1].puts no_a1,"[1] = ",EVALF,"(ap_sin(",operand, "[1]))"
     $outhdr[1].puts no_a2,"[1] = ",EVALF,"(ap_cos(",operand, "[1]))"
     $outhdr[1].puts no_a3,"[1] = ",no_a1,"[1]  /", operand,"[1]"
 end
 else
     $outhdr[i].puts no_a1,"[",i,"] = (ATT(",i-1,",",no_a2,",",operand,",1))"
     $outhdr[i].puts no_a2,"[",i,"] = - ATT(",i-1,",",no_a1,",",operand,",1)"
     $outhdr[i].puts no_a3,"[",i,"] = ",EVALF,"((", no_a1,"[",i,"] - ATS(",i,",",operand,",",no_a3,",2))/",operand,"[1])"
     $outhdr[i].puts no,"[",i,"] = ATT(",i-1,",",no_a3,",",operand,",1)"

 end
 i += 1
 end
 return
 end
 def emit_Si(no,operand)
 no_a1
 no_a2
 no_a3
 no_a1 = no + "_a1"
 no_a2 = no + "_a2"
 no_a3 = no + "_a3"
     $outfile4.puts no_a1,"[k] = (ATT(k-1,",no_a2,",",operand,",1))"
     $outfile4.puts no_a2,"[k] = - ATT(k-1,",no_a1,",",operand,",1)"
     $outfile4.puts no_a3,"[k] = ",EVALF,"((", no_a1,"[k] - ATS(k,",operand,",",no_a3,",2))/",operand,"[1])"
     $outfile4.puts no,"[k] = ATT(k-1,",no_a3,",",operand,",1)"

 return
 end
 #----------------------------------------------------------
 #DJDSTART

get next token

lexical analysis and parsing derived in part from _Compilers - Principles, Techniques, and Tools_ by Alfred V. Aho, Ravi Sethi, Jeffery D. Ullman especially pages 74-78, and _Principles of Compiler Design_ by Alfred V. Aho, Jeffery D. Ullman

  1. 181

lexical box determine tokens

parse

scan to determine priorities

DJDSTOP

 #main to test priority code
 #start main
 $eq_dep_data = Hash.new(0)
 $lhs_re = Regexp.new("^[a-zA-z]+[a-zA-Z0-9]*")
 $rhs_re = Regexp.new("^[a-zA-z]+[a-zA-Z0-9]*")
 $degree_re = Regexp.new("^[0-9]*")
 $skip_re = Regexp.new("^,")
 $no_eqs = 0
 read_eq_db
 echo_eq_db
 determine_priority
 echo_eq_db

 #DJDSTART

[Validate]