マクロ処理 -- 機能の追加2017年01月13日 21:19

機能を2つ追加します。定義してあるマクロを取り消す--undef と簡単な条件判断を 行う--ifdef です。

undefは、以下のように使います。定義していないマクロ名を指定しても無視されます。

     define(EOF,-1) # マクロEOFの定義
          :
          :
          :
     undef(EOF)     # マクロEOFの削除

ifdefは、以下のように使います。

     define(CPU1,1)
          :
          :
          :
     ifdef(CPU1,define(WORD,4)) # CPU1が定義されていれば、WORDは、4
     ifdef(CPU2,define(WORD,8)) # CPU2が定義されていれば、WORDは、8

これらの機能を組み込むには、defineの変更が必要です。undef,ifdefを マクロテーブルに登録することと、undefルーチンuninst()の呼び出し、 ifdefの処理ロジックの追加が必要です。

RATFOR版は、

# define.r4 -- simple string replacement macro processor
      program define
      integer gettok
      character defn(MAXDEF),t,token(MAXTOK)
      integer lookup

      string defnam "define"
      string udenam "undef"
      string ifdnam "ifdef"

      character deftyp(2)
      data deftyp(1)/DEFTYPE/,deftyp(2)/EOS/
      character udftyp(2)
      data udftyp(1)/UDFTYPE/,udftyp(2)/EOS/
      character ifdtyp(2)
      data ifdtyp(1)/IFDTYPE/,ifdtyp(2)/EOS/

      call initfile
      call inittbl
      call initbuf
      call instal(defnam,deftyp)
      call instal(udfnam,udftyp)
      call instal(ifdnam,ifdtyp)

      for(t = gettok(token,MAXTOK);t != EOF;t = gettok(token,MAXTOK))
          if (t != ALPHA)               # output non-alpha tokens
              call putlin(token,STDOUT)
          else if (lookup(token,defn) == NO)
              call putlin(token,STDOUT)
          else if (defn(1) == DEFTYPE) { # get definition
              call getdef(token,MAXTOK,defn,MAXTOK)
              call instal(token,defn)
              }
          else if (defn(1) == UDFTYPE ) {
              call getnam(token,MAXTOK)
              if (lookup(token,defn) == YES) # and defined
                  call uninst(token)
              }
          else if (defn(1) == IFDTYPE) {
              call getdef(token,MAXTOK,defn,MAXDEF))
              if (lookup(token,junk) == YES)
                  call pbstr(defn)
              }
          else
              call pbstr(defn)          # push replacement
      stop
      end

WATCOM fortran 77版は、

c define.f -- simple string replacement macro processor
      program define
      integer gettok
      integer*1 defn(82),t,token(82),junk(82) ! MAXDEF(82) MAXTOK(82) MAXDEF(82)
      integer lookup
      integer*1 defnam(7)
      character $defnam(7)
      equivalence (defnam,$defnam)
      data $defnam(1)/'d'/
      data $defnam(2)/'e'/
      data $defnam(3)/'f'/
      data $defnam(4)/'i'/
      data $defnam(5)/'n'/
      data $defnam(6)/'e'/
      data defnam(7)/-2/                ! EOF(-2)
      integer*1 udfnam(6)
      character $udfnam(6)
      equivalence (udfnam,$udfnam)
      data $udfnam(1)/'u'/
      data $udfnam(2)/'n'/
      data $udfnam(3)/'d'/
      data $udfnam(4)/'e'/
      data $udfnam(5)/'f'/
      data udfnam(6)/-2/                ! EOS(-2)
      integer*1 ifdnam(6)
      character $ifdnam(6)
      equivalence (ifdnam,$ifdnam)
      data $ifdnam(1)/'i'/
      data $ifdnam(2)/'f'/
      data $ifdnam(3)/'d'/
      data $ifdnam(4)/'e'/
      data $ifdnam(5)/'f'/
      data ifdnam(6)/-2/                ! EOS(-2)
      integer*1 deftyp(2)
      data deftyp(1)/-4/,deftyp(2)/-2/  ! DEFTYPE(-4) EOS(-2)
      integer*1 udftyp(2)
      data udftyp(1)/-5/,udftyp(2)/-2/  ! UDFTYPE(-5) EOS(-2)
      integer*1 ifdtyp(2)
      data ifdtyp(1)/-6/,ifdtyp(2)/-2/  ! IFDTYPE(-6) EOS(-2)

      call initfile
      call inittbl
      call initbuf
      call instal(defnam,deftyp)
      call instal(udfnam,udftyp)
      call instal(ifdnam,ifdtyp)

      t = gettok(token,82)              ! MAXTOK(82)
      while (t .ne. -1) do              ! EOF(-1
          if (t .ne. 97) then           ! ALPHA(97) output non-alpha tokens
              call putlin(token,6)      ! STDOUT(6)
          else if (lookup(token,defn) .eq. 0) then ! NO(0) and undefined
              call putlin(token,6)      ! STDOUT(6)
          else if (defn(1) .eq. -4) then ! DEFTYPE(-4)get definition
              call getdef(token,82,defn,82) ! MAXTOK(82) MAXDEF(82)
              call instal(token,defn)
          else if (defn(1) .eq. -5) then ! UDFTYPE(-5)
              call getnam(token,82)     ! MAXTOK(82)
              if (lookup(token,defn) .eq. 1) then ! YES(1) and defined
                  call uninst(token)
              end if
          else if (defn(1) .eq. -6) then ! IFDTYPE(-6)
              call getdef(token,82,defn,82) ! MAXTOK(82) MAXDEF(82)
              if (lookup(token,junk) .eq. 1) then ! YES(1)
                  call pbstr(defn)
              end if
          else
              call pbstr(defn)          ! push replacement
          end if
          t = gettok(token,82)          ! MAXTOK(82)
      end while
      stop
      end

getnam()は、マクロ名を取り出す。

RATFOR版は、以下の通り。

# getnam.r4 -- get name
      subroutine getnam(token,toksiz)
      integer toksiz
      character token(toksiz)
      character gettok,ngetc
      character c
      integer i,nlpar

      if (ngetc(c) != LPAREN)
          call error('missing left paren.')
      else if (gettok(token,toksiz) != ALPHA)
          call error('non-alphanumeric name.')

      for (nlpar = 0; nlpar >= 0; ) 
          if (ngetc(c) == EOF)
              call error('missing right paren.')
          else if (c == LPAREN)
              nlpar = nlpar + 1
          else if (c == RPAREN)
              nlpar = nlpar - 1
          # else normal character indefn(i)
      return
      end

WATCOM fortran 77版は、

c getnam.f -- get name
      include ratfor.def
      subroutine getnam(token,toksiz)
      integer toksiz
      integer*1 token(toksiz)
      integer*1 gettok,ngetc
      integer*1 c
      integer i,nlpar

      if (ngetc(c) .ne. LPAREN) then
          call error('missing left paren.')
      else if (gettok(token,toksiz) .ne. ALPHA) then
          call error('non-alphanumeric name.')
      end if

      nlpar = 0
      while (nlpar .ge. 0) do
          if (ngetc(c) .eq. EOF) then
              call error('missing right paren.')
          else if (c .eq. LPAREN) then
              nlpar = nlpar + 1
          else if (c .eq. RPAREN) then
              nlpar = nlpar - 1
          ! else normal character indefn(i)
          end if
          i = i + 1
      end while
      return
      end

このモジュールをコンパイルするには、fid.batを使って、マクロを展開する 必要があります。

uninst()はマクロの定義を取り消します。

RATFOR版は、以下の通り。

# uninst.r4 -- undefine macro
      subroutine uninst(defnam)
      character defnam(MAXTOK)
      character name(MAXTOK),defn(MAXDEF)
      integer i,nlen,dlen
      integer length,equal
      include clook.fi

      lastt = 0
      for (i = 1; i <= lastp; i = i + 1) {
          call scopy(table,namptr(i),name,1)
          if (equal(defnam,name) == NO) {
              nlen = length(name) + 1
              call scopy(table,namptr(i) + nlen,defn,1)
              dlen = length(defn) + 1
              namptr(i) = lastt + 1
              call scopy(name,1,table,lastt+1)
              call scopy(defn,1,table,lastt+nlen+1)
              lastt = lastt + nlen + dlen
              }
          }
      lastp = lastp - 1
      return
      end

WATCOM fortran 77版は、

c uninst.f -- purge macro
      include ratfor.def
      subroutine uninst(defnam)
      integer*1 defnam(MAXTOK)
      integer*1 name(MAXTOK),defn(MAXDEF)
      integer i,nlen,dlen
      integer length,equal
      include clook.fi

      lastt = 0
      i = 1
      while (i .le. lastp) do
          call scopy(table,namptr(i),name,1)
          if (equal(defnam,name) .eq. NO) then
              nlen = length(name) + 1
              call scopy(table,namptr(i) + nlen,defn,1)
              dlen = length(defn) + 1
              namptr(i) = lastt + 1
              call scopy(name,1,table,lastt+1)
              call scopy(defn,1,table,lastt+nlen+1)
              lastt = lastt + nlen + dlen
          end if
          i = i + 1
      end while
      lastp = lastp - 1
      return
      end

getnam()uninst()にincludeするratfor.defは、以下の通り。

c ratfor.def -- ratfor constants
define(LET0,48)
define(LET1,49)
define(LET2,50)
define(LET3,51)
define(LET4,52)
define(LET5,53)
define(LET6,54)
define(LET7,55)
define(LET8,56)
define(LET9,57)
define(LETA,65)
define(LETB,66)
define(LETC,67)
define(LETD,68)
define(LETE,69)
define(LETF,70)
define(LETG,71)
define(LETH,72)
define(LETI,73)
define(LETJ,74)
define(LETK,75)
define(LETL,76)
define(LETM,77)
define(LETN,78)
define(LETO,79)
define(LETP,80)
define(LETQ,81)
define(LETR,82)
define(LETS,83)
define(LETT,84)
define(LETU,85)
define(LETV,86)
define(LETW,87)
define(LETX,88)
define(LETY,89)
define(LETZ,90)
define(LETa,97)
define(LETb,98)
define(LETc,99)
define(LETd,100)
define(LETe,101)
define(LETf,102)
define(LETg,103)
define(LETh,104)
define(LETi,105)
define(LETj,106)
define(LETk,107)
define(LETl,108)
define(LETm,109)
define(LETn,110)
define(LETo,111)
define(LETp,112)
define(LETq,113)
define(LETr,114)
define(LETs,115)
define(LETt,116)
define(LETu,117)
define(LETv,118)
define(LETw,119)
define(LETx,120)
define(LETy,121)
define(LETz,122)
define(STDIN,5)
define(STDOUT,6)
define(ERROUT,6)
define(EOF,-1)
define(EOS,-2)
define(TAB,9)
define(NEWLINE,10)
define(BLANK,32)
define(BUFSIZE,1000)
define(LETTER,97)
define(DIGIT,48)
define(MAXLINE,82)
define(MAXDEF,82)
define(MAXTOK,82)
define(MAXPTR,500)
define(MAXTBL,5000)
define(ARGSIZE,82)
define(DEFTYPE,-4)
define(IFDTYPE,-5)
define(UDFTYPE,-6)
define(IFTYPE,-7)
define(INCTYPE,-8)
define(SUBTYPE,-9)
define(LENTYPE,-10)
define(EVALSIZE,1000)
define(ALPHA,LETa)
define(NO,0)
define(YES,1)
define(LPAREN,40)
define(RPAREN,41)
define(LBRACK,91)
define(RBRACK,93)
define(COMMA,44)
define(DQUOTE,34)
define(QUOTE,39)
define(SEMICOL,59)
define(CALLSIZE,1000)
define(DOLLAR,36)
define(ARGFLAG,36)
define(DNL,36)
define(EXCLAM,33)

コメント

_ tinder dating site ― 2017年02月26日 01:08

great points altogether, you just gained a new reader. What would you suggest
in regards to your post that you made some days ago? Any sure?

_ tinder dating site ― 2017年02月27日 09:24

I for all time emailed this webpage post page to all my
associates, as if like to read it then my contacts will too.

_ tinder dating site ― 2017年02月28日 11:00

Thanks in support of sharing such a pleasant idea, post is nice, thats why i have read it completely

_ tinder dating site ― 2017年03月02日 14:44

Have you ever thought about publishing an ebook or guest authoring on other sites?
I have a blog centered on the same topics you discuss and would really
like to have you share some stories/information. I know my viewers would enjoy your work.
If you&#39;re even remotely interested, feel free to shoot me an email.

_ minecraft ― 2017年03月03日 01:34

I was able to find good advice from your content.

_ tinder dating site ― 2017年03月05日 02:59

I enjoy what you guys are up too. Such clever work and exposure!
Keep up the awesome works guys I&#39;ve incorporated you guys to our blogroll.

_ minecraft ― 2017年03月07日 15:54

Hey! This is my first visit to your blog! We are a team of
volunteers and starting a new initiative in a community in the same
niche. Your blog provided us valuable information to work
on. You have done a marvellous job!

_ mrdrain.com ― 2017年03月09日 21:15

I am sure this post has touched all the internet visitors, its really really fastidious paragraph on building up new weblog.

_ tinyurl.com ― 2017年03月10日 22:59

Heya i am for the first time here. I came across this board and I find It truly useful &amp; it helped me out much.
I hope to give something back and help others like you aided me.

_ tinyurl.com ― 2017年03月11日 02:02

You&#39;re so cool! I don&#39;t think I have read something like that before.
So nice to find another person with original thoughts on this issue.
Seriously.. thank you for starting this up. This web site is one thing that is required on the web, someone with some originality!

_ tinyurl.com ― 2017年03月11日 15:22

Thank you for sharing your info. I truly appreciate your efforts and I will
be waiting for your next post thanks once again.

_ tinder dating site ― 2017年03月13日 15:22

Very good post. I will be experiencing many of these issues as well..

_ tinder dating site ― 2017年03月14日 07:03

Hello are using Wordpress for your site platform?

I&#39;m new to the blog world but I&#39;m trying
to get started and create my own. Do you need any html coding expertise to make your own blog?
Any help would be really appreciated!

_ tinder dating site ― 2017年03月14日 11:48

Hi! This post could not be written any better! Reading through this post reminds me of my previous room mate!
He always kept talking about this. I will forward this write-up to him.
Fairly certain he will have a good read. Thank you for sharing!

_ tinder dating site ― 2017年03月15日 09:16

Hi there, I found your blog by way of Google even as looking for a related topic, your site came up, it looks great.
I have bookmarked it in my google bookmarks.

Hello there, simply became alert to your weblog thru Google, and located that it is
truly informative. I am going to watch out for brussels.
I will appreciate in case you proceed this in future.
Many other people can be benefited out of your writing.
Cheers!

_ tinder dating site ― 2017年03月18日 09:11

Very quickly this web site will be famous amid all blogging visitors, due to it&#39;s good articles or reviews

_ tinder dating site ― 2017年03月19日 22:12

Do you mind if I quote a couple of your posts as long as I
provide credit and sources back to your website?
My blog site is in the very same niche as yours and my users would genuinely
benefit from some of the information you present here.
Please let me know if this alright with you. Thanks!

_ free dating sites no fees ― 2017年03月22日 02:28

It is perfect time to make some plans for the future and it&#39;s time to be
happy. I have read this post and if I could I
wish to suggest you some interesting things or advice.

Perhaps you could write next articles referring to this article.
I desire to read even more things about it!

_ list of the best free dating sites ― 2017年03月22日 06:11

I feel this is among the so much significant info for me.

And i&#39;m satisfied reading your article. But should observation on few
basic issues, The web site taste is great, the articles is in reality great : D.
Excellent activity, cheers

_ free dating sites no fees ― 2017年03月23日 03:28

Greate post. Keep posting such kind of info on your page.
Im really impressed by your site.
Hello there, You have done a great job. I&#39;ll definitely digg it and individually recommend to my
friends. I am sure they&#39;ll be benefited from this website.

_ minecraft.net ― 2017年03月26日 03:27

If you desire to obtain a good deal from this article
then you have to apply such methods to your won weblog.

_ minecraft demo ― 2017年03月26日 17:52

I&#39;ve been exploring for a little bit for any high quality articles or weblog posts on this sort of house
. Exploring in Yahoo I ultimately stumbled upon this web site.
Studying this info So i&#39;m happy to express that I have
a very just right uncanny feeling I came upon exactly what I needed.
I so much undoubtedly will make certain to don?t disregard this site and
provides it a glance on a relentless basis.

_ manicure ― 2017年04月03日 11:32

I really like your blog.. very nice colors &amp; theme.
Did you create this website yourself or did you hire someone to do it for you?
Plz answer back as I&#39;m looking to design my own blog and would like to know where u got this
from. appreciate it

_ manicure ― 2017年04月11日 01:19

It&#39;s an amazing piece of writing in support of all the online visitors; they will get
advantage from it I am sure.

_ BHW ― 2017年04月12日 19:07

Hey! I&#39;m at work browsing your blog from my new iphone!
Just wanted to say I love reading your blog and look forward to all your posts!
Keep up the excellent work!

_ BHW ― 2017年04月15日 17:27

Very nice post. I just stumbled upon your weblog and wished to say that I&#39;ve really enjoyed surfing around
your blog posts. After all I will be subscribing
to your rss feed and I am hoping you write once more soon!

_ www.krogerfeedback.com ― 2017年04月29日 02:22

It&#39;s an amazing article designed for all the web users; they will get
benefit from it I am sure.

_ www.krogerfeedback.com ― 2017年05月01日 01:55

It is really a nice and useful piece of information. I am happy that you simply shared this helpful information with us.
Please stay us up to date like this. Thank you for sharing.

_ www.krogerfeedback.com ― 2017年05月01日 11:10

You ought to take part in a contest for one of the finest blogs on the
web. I most certainly will recommend this site!

_ racialprogressi03.soup.io ― 2017年05月02日 08:46

Stunning story there. What occurred after? Thanks!

_ manicure ― 2017年05月03日 11:05

Asking questions are in fact pleasant thing if you are not understanding something completely, however this
post gives fastidious understanding yet.

_ Minecraft ― 2017年05月19日 18:46

I&#39;m impressed, I must say. Rarely do I encounter a blog
that&#39;s both equally educative and engaging, and without a doubt, you&#39;ve hit the nail on the head.
The problem is something which not enough people are speaking intelligently about.

Now i&#39;m very happy I found this in my hunt for something regarding this.

_ Minecraft ― 2017年05月20日 02:26

I do consider all the ideas you&#39;ve offered to
your post. They are very convincing and will definitely work.
Still, the posts are too quick for beginners. May just you
please prolong them a little from subsequent time? Thanks
for the post.

_ Minecraft ― 2017年05月20日 14:56

I’m not that much of a internet reader to be honest but your blogs really nice, keep it up!
I&#39;ll go ahead and bookmark your website to come back in the future.
Cheers

_ instacart promo code ― 2017年08月21日 17:40

Thanks very interesting blog!

_ tinyurl.com ― 2017年08月22日 04:17

Fantastic site you have here but I was curious about if you
knew of any forums that cover the same topics talked about in this article?

I&#39;d really like to be a part of community where I can get advice from other
experienced individuals that share the same interest. If you have any recommendations, please let me know.
Thank you!

_ tinyurl.com ― 2017年08月22日 17:21

Hi, I do believe this is a great blog. I stumbledupon it ;) I will return once again since i have
bookmarked it. Money and freedom is the best
way to change, may you be rich and continue to guide other people.

_ tinyurl.com ― 2017年08月24日 16:17

When someone writes an article he/she keeps the plan of a
user in his/her mind that how a user can know it.
Thus that&#39;s why this article is perfect. Thanks!

_ tinyurl.com ― 2017年08月24日 23:23

There is certainly a great deal to learn about this topic.
I love all the points you&#39;ve made.

_ tinyurl.com ― 2017年08月25日 08:15

This info is priceless. When can I find out more?

_ http://tinyurl.com/y7dxfu77 ― 2017年08月25日 16:32

You have made some really good points there.

I checked on the web for more information about the issue and found most individuals will go along with
your views on this website.

_ tinyurl.com ― 2017年08月25日 18:56

Hi colleagues, how is everything, and what you would like to say about
this paragraph, in my view its genuinely remarkable in support
of me.

_ tinyurl.com ― 2017年08月25日 23:22

I go to see daily a few blogs and websites to read articles or reviews, however this webpage gives
quality based writing.

_ tinyurl.com ― 2017年08月26日 05:56

This excellent website truly has all the information I wanted about
this subject and didn&#39;t know who to ask.

_ publix.com/delivery ― 2017年09月29日 02:23

This is very interesting, You&#39;re a very skilled blogger.
I have joined your rss feed and look forward to seeking more of your excellent post.
Also, I&#39;ve shared your site in my social networks!

_ publix grocery delivery ― 2017年09月29日 02:23

I do not even know how I ended up here, but
I thought this post was good. I don&#39;t know who you are
but definitely you&#39;re going to a famous blogger if you are not already ;) Cheers!

_ publix grocery delivery service ― 2017年09月30日 09:04

My spouse and I stumbled over here by a different web
page and thought I may as well check things out.
I like what I see so now i&#39;m following you. Look forward to
looking at your web page yet again.

_ publix deli online ordering ― 2017年09月30日 17:34

Great article, just what I was looking for.

_ publix grocery delivery service ― 2017年09月30日 23:30

Hi, i believe that i noticed you visited my weblog thus i got
here to return the choose?.I&#39;m trying to in finding things to enhance my site!I suppose
its good enough to make use of a few of your ideas!!

_ instacart promo code ― 2017年10月02日 09:53

Usually I do not learn article on blogs,
however I wish to say that this write-up very pressured me to try and do so!
Your writing taste has been amazed me. Thank you, quite great post.

※コメントの受付件数を超えているため、この記事にコメントすることができません。

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2017/01/13/8320144/tb