491B 200203 - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

491B 200203

Description:

Jan 03. EEE/GEF 491B. 1-1. Produits de d veloppement et maintenance ... C functions to support iterating over the special module states, viewed as a sequence: ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 27
Provided by: terrys8
Category:
Tags: 491b | iterating

less

Transcript and Presenter's Notes

Title: 491B 200203


1
GEF/EEE 491B 2002/03 symtbl.ppt
Produits de développement et maintenance du
logiciel Software Work Products and Maintenance
C.D. (Terry) Shepard, BSc, MA, PhD, PEng SB 4019
x6031 Home 541 0631 email shepard_at_rmc.ca
2
symtbl - Module Interface Specification (MIS) - 1
Interface syntax define ST_MAXSYMS 50
/maximum number of symbols/ define
ST_MAXSYMLEN 20 /maximum symbol length/
3
symtbl MIS - 2
Interface semantics state variables tbl set of
tuple of (sym string, loc integer) state
invariant 1. tbl ST_MAXSYMS 2. (t 0
tbl)(t.sym ST_MAXSYMLEN) 3. (t1 , t2 0
tbl)(t1 t2 v t1.sym t2.sym)
assumptions st_s_init is called before any of
the other access routine. All string parameters
are legal C strings.
4
symtbl MIS - 3
access routine semantics 1 st_s_init transition
tbl exceptions none st_s_add(sym, loc)
transition tbl tbl c ltsym, locgt
exceptions exc (sym gt ST_MAXSYMLEN
st_maxlen (loc1)(ltsym, loc1gt 0
tbl) st_exsym tbl ST_MAXSYMS
st_full) st_g_exsym(sym) output out
(loc)(ltsym, locgt 0 tbl) exceptions none
5
symtbl MIS - 4
access routine semantics 2 st_s_loc(sym,
loc) transition tbl (tbl - ltsym, loc1gt) c
ltsym, locgt
where ltsym, loc1gt 0 tbl exceptions exc
(loc1)(ltsym, loc1gt 0 tbl) st_notexsym st_g_lo
c(sym) output out loc, where ltsym, locgt 0
tbl exceptions exc (loc1)(ltsym, loc1gt 0
tbl) st_notexsym st_g_siz output out
tbl exceptions none
6
symtbl MID - 1
state variables struct char symST_MAXSYMLEN1
int loc tblST_MAXSYMS int tblcnt state
invariant 1. Every symbol in tbl0..tblcnt-1
contains a null. 2. There are no duplicate
symbols in tbl0..tblcnt-1. 3. tblcnt 0
0..ST_MAXSYMS
7
symtbl MID - 2
abstraction function tbl ltsym, locgt(i0
0..tblcnt-1)(sym tbli.sym v loc
tbli.loc) access routine semantics
1 st_s_init transition tblcnt
0 exceptions none st_s_add(sym, loc)
transition tblcnt, tbltblcnt tblcnt 1,
ltsym, locgt exceptions exc (sym gt
ST_MAXSYMLEN st_maxlen findsym(sym)
NOTFOUND st_exsym tblCNT ST_MAXSYMS
st_full)
8
symtbl MID - 3
access routine semantics 2 st_g_exsym(sym)
output out findsym(sym) NOTFOUND
exceptions none st_s_loc(sym, loc)
transition tblfindsym(sym).loc loc
exceptions exc findsym(sym) NOTFOUND
st_notexsym st_g_loc(sym) output out
tblfindsym(sym).loc exceptions exc
findsym(sym) NOTFOUND st_notexsym st_g_siz
output out tblcnt exceptions none
9
symtbl MID - 4
local constants define NOTFOUND -1 local
functions findsym string v integer findsym(s)
(i0 0..tblcnt-1)(s tbli.sym i true
NOTFOUND)
10
symtbl makefile 1
INC ../include CFLAGS -I(INC) export
symtbl.o symtbl_e.o symtbl_b symtbl_b.o
symtbl.o cc -o symtbl_b symtbl_b.o
symtbl.o tcov symtbl_b.o cc -a -c -I(INC)
symtbl.c cc -a -o symtbl_b symtbl_b.o
symtbl.o symtbl_b tcov symtbl.c rm -f symtbl.o
tcov version is dangerous to leave around
11
symtbl makefile 2
symtbl_i symtbl_i.o symtbl_e.o symtbl.o cc -o
symtbl_i symtbl_i.o symtbl_e.o symtbl.o symtbl_b.
o (INC)/symtbl.h (INC)/system.h symtbl_i.o
(INC)/symtbl.h (INC)/system.h symtbl.o
(INC)/symtbl.h (INC)/system.h symtbl_e.o
(INC)/symtbl.h (INC)/system.h symtbl_b.c
symtbl.script pgmgen symtbl.script mv test.c
symtbl_b.c lint symtbl_b.c lint -I(INC)
symtbl_b.c symtbl.c clean rm -f symtbl_i
symtbl_b .o symtbl_b.c symtbl.c.tcov symtbl.c.d
12
symtbl.h
/constants/ define ST_MAXSYMS 50
/maximum number of symbols/ define
ST_MAXSYMLEN 20 /maximum symbol
length/ /types/ /access
routines/ void st_s_init() void
st_s_add(char sym,int loc) int
st_g_siz() /boolean/ int st_g_exsym(char
sym) void st_s_loc(char sym,int loc) int
st_g_loc(char sym) void st_g_dump() /for
testing purposes only/ /exception
handlers/ void st_exsym() void
st_maxlen() void st_notexsym() void st_full()
13
symtbl.c 1
  • include "system.h"
  • include "symtbl.h"
  • /constants/
  • define NOTFOUND -1
  • /types/
  • /module state/
  • static struct
  • char symST_MAXSYMLEN1 /symbol value/
  • int loc /symbol location/
  • tblST_MAXSYMS /one entry per symbol/
  • static int tblcnt /number of symbols in tbl/
  • /local functions/

14
symtbl.c 2
  • /access routines/
  • void st_s_init()
  • tblcnt 0
  • void st_s_add(char sym,int loc)
  • if (strlen(sym) gt ST_MAXSYMLEN)
  • st_maxlen()
  • return
  • else if (findsym(sym) ! NOTFOUND)
  • st_exsym()
  • return
  • else if (tblcnt ST_MAXSYMS)
  • st_full()
  • return

15
symtbl.c 3
  • void st_s_loc(char sym,int loc)
  • int i
  • i findsym(sym)
  • if (i NOTFOUND)
  • st_notexsym()
  • return
  • tbli.loc loc
  • int st_g_loc(char sym)
  • int i
  • i findsym(sym)
  • if (i NOTFOUND)
  • st_notexsym()

16
symtbl_e.c
  • include "system.h"
  • include "symtbl.h"
  • void st_exsym()
  • fprintf(sy_excfilp,"Exception st_exsym
    occurred\n")
  • void st_maxlen()
  • fprintf(sy_excfilp,"Exception st_maxlen
    occurred\n")
  • void st_notexsym()
  • fprintf(sy_excfilp,"Exception st_notexsym
    occurred\n")
  • void st_full()

17
symtbl.tplan 1
  • Assumptions
  • ST_MAXSYMLEN gt length of ST_MAXSYMS - 1 in
    string form
  • ST_MAXINTLEN gt 0
  •  
  • Test environment
  • PGMGEN driver
  • no stubs
  •  
  • Test-case selection strategy
  •  
  • special values
  •  
  • module state
  • number of symbols in table 0, 1, ST_MAXSYMS/2,
    ST_MAXSYMS
  • symbol length short, ST_MAXSYMLEN
  •  
  • access routine parameters
  • st_s_add strings of length 0, 1, ST_MAXSYMLEN
    1, 2 ST_MAXSYMLEN
  • st_s_add, st_s_loc, st_g_loc, st_g_exsym empty
    string

18
symtbl.tplan 2
  • test cases (cond)
  •  
  • normal
  •  
  • check st_g_exsym for empty string in empty table
  • add the empty string, check and change its
    location
  • for each special module state
  • check table length
  • check that a very long symbol is not in table
  • for each i in 0..ST_MAXSYMS-1
  • if i in 0..t_siz - 1
  • check t_sym(i) in table with correct location
  • check st_s_loc resets location
  • else
  • check t_sym(i) not in table
  •  
  •  
  • Test implementation strategy
  •  

19
symtbl.scr 1
  • module
  • st_
  •  
  • accprogs
  • lts_init,s_add,g_exsym,s_loc,g_loc,g_sizgt
  •  
  • exceptions
  • ltexsym,maxlen,notexsym,fullgt
  •  
  • globcod
  • include "system.h"
  • include "symtbl.h"
  •  
  • define T_FILLCHAR ''
  •  
  • static int i,cur
  •  
  • static struct

20
 
symtbl.scr 2
  • static void t_init()
  • cur -1
  • static char t_mksym(i,len)
  • int i,len
  • static char buf2ST_MAXSYMLEN1
  • int j
  •  
  • sprintf(buf,"d",i) /convert i to ASCII/
  • if (len gt strlen(buf))
  • for (j strlen(buf) j lt len j) /pad right
    with ''/
  • bufj T_FILLCHAR
  • buflen '\0' /add string terminator/
  • return(buf)

21
 
symtbl.scr 3
  • static int t_siz()
  • return(tblcur.syms)
  • static char t_sym(i)
  • int i
  • return(t_mksym(i,tblcur.symlen))
  •  
  • static int t_loc(i)
  • int i
  • return(10i)
  •  
  • cases

22
 
symtbl.scr 4
  • /exceptions (cond)/
  • /set and get locations for symbols not in the
    table/
  • lts_loc(t_mksym(t_siz(),0),0), notexsym, dc, dc,
    dcgt
  • lts_loc("",0), notexsym, dc, dc, dcgt
  • ltg_loc(t_mksym(t_siz(),0)), notexsym, dc, dc,
    dcgt
  • ltg_loc(""), notexsym, dc, dc, dcgt
  •  
  • /add every symbol in the table/
  • for (i 0 i lt t_siz() i)
  • lts_add(t_sym(i),0), exsym, dc, dc, dcgt
  • t_next()
  • /normal case/

23
symtbl.scr 5
  • /normal case (cond)/
  • t_init()
  • t_next()
  • while (!t_end())
  • /check table length/
  • lt , noexc, g_siz(), t_siz(), intgt
  • /check that a very long symbol is not in
    table/
  • lt , noexc, g_exsym(t_mksym(0,2ST_MAXSYMLEN)),
    0, boolgt
  • for (i 0 i lt ST_MAXSYMS i)
  • if (i lt t_siz())
  • /check t_sym(i) in table with correct
    location/
  • lt , noexc, g_exsym(t_sym(i)), 1, boolgt
  • lt , noexc, g_loc(t_sym(i)), t_loc(i), intgt
  • /check s_loc resets location/

24
symtbl_i.c 1
  • include "system.h"
  • include "symtbl.h"
  • define QUIT 0
  • define S_INIT 1
  • define S_ADD 2
  • define G_EXSYM 3
  • define S_LOC 4
  • define G_LOC 5
  • define G_SIZ 6
  • define G_DUMP 7
  • define BUFLEN 80
  • FILE sy_excfilp stderr

25
symtbl_i.c 2
  • int nextcall()
  • int reply
  • char s81
  • do
  • printf("\nEnter command\n")
  • printf("\t0quit\n")
  • printf("\t1s_init\n")
  • printf("\t2s_add\n")
  • printf("\t3g_exsym\n")
  • printf("\t4s_loc\n")
  • printf("\t5g_loc\n")
  • printf("\t6g_siz\n")
  • printf("\t7g_dump")
  • gets(s)
  • if (sscanf(s,"d",reply) ! 1)
  • reply -1 /user error - stay in loop/
  • while (reply lt 0 reply gt G_DUMP)

26
symtbl_i.c 3
  • main()
  • int reply,i
  • char s80
  • while ((replynextcall()) ! QUIT)
  • switch(reply)
  • case S_INIT
  • st_s_init()
  • break
  • case S_ADD
  • printf("Enter sym")
  • gets(s)
  • sscanf(s,"s",s)
  • i readint("Enter loc")
  • st_s_add(s,i)
  • break
  • case G_EXSYM
  • printf("Enter sym")

case G_LOC printf("Enter sym") gets(s)
sscanf(s,"s",s) i st_g_loc(s) print
f("returns d\n",i) break case G_SIZ i
st_g_siz() printf("returns
d\n",i) break case G_DUMP st_g_dump()
break return(0)
Write a Comment
User Comments (0)
About PowerShow.com