已阅读5页,还剩15页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
REXX基本概念、主要语法及程序设计复习1. REXX:Restructured EXtended eXecutor;CLIST:Command LIST。REXX和CLIST的主要区别:NOREXXCLIST(1)NewOld(2)Good string handlingBad for data strings(3)English-likeLots of &(4)ClearObscure at times(5)Excellent control structuresGood control structures(6)Good for mathBad for math(7)Many good functionsFew useful functions(8)CommonUnique(9)No prompting for positional parmsPrompts for positional parms(10)REXX programs are generally contained in libraries (PDSs) whose names end in .EXEC. (.EXEC not required, but recommended).CLISTs are generally contained in libraries (PDSs) whose names end in .CLIST. (.CLIST not required, but recommended).参考教材P12关于CLIST和REXX的使用方法。2. Rexx语言是一种解释型、非编译型、高级的脚本语言,要与C/C+、Java、COBOL等语言的区分开来。Rexx语言是一种解释型的“胶水”语言,它可以方便地调用其他语言编写的模块。无需对变量进行声明、赋初值即可使用,变量不区分大小写;但注意变量不能以“09”或“.”开头。所有变量都是无类型的“typeless”(也可以认为是单一数据类型,字符串)。要注意Rexx语言不适合使用的场合:如内存读写、驱动等。3. 了解Rexx所属的标准范畴,TRL-1, 1985, Level 3.50;TRL-2, 1990, Level 4.00;ANSI X3.274-1996, Level 5.00。TRL:The Rexx Language。4. Rexx注释使用“/* */”,可包含多行;大型机上的Rexx程序,第一条语句通常使用包含REXX的注释,比如“/* REXX */”。5. Rexx包含字符(串)可使用或“”,注意字符串输出时混用以输出带有同样符号的字符串。6. 在TSO/E环境下编写REXX脚本,可使用“HI REXX”命令对REXX代码高亮显示。7. REXX代码的书写:逗号“,”可表示续行,分号“;”可在一行分隔多条指令。8. REXX程序在TSO/E环境下的执行方式及参数传递方式,参见实验内容及P14、P33、P162。9. Rexx十六进制、二进制的表示:Num41inHex = 41x/* 41 is the number 65 in base 16*/Say Num41inHex/* display alphabet A*/hexString = 3E 11 4AX/* Assigns a hex string value*/Say hexString/* display J*/bin_41_string = 0100 0001b/* display A*/Bin_61_string = 0110 0001B/* display a*/say 414243X/* ABC*/X = 5 + 6say The answer is X/* 语法错误*/10. Rexx算数运算符:11. Rexx数值精度numeric:(1) To control the number of significant digits in arithmetic results(2) Sometimes refers to the precision of the result.(3) Default numeric precision = 9 digits.say 2/3 /*displays 0.666666667 by default */numeric digits 12 /* set numeric precision to 12 digits */say 2/3 /* displays: 0.666666666667 */默认情况下,使用“say digits()”可得到精度值9。12. 比较操作符:Program:a = b = 2Say a = aSay b = bThen the result:a = , b = .This program checks to see if b=2. If it is, it produces a 1, so a is set to 1. If it is not, a is set to 0. The value b is not declared, so its value is B.13. 逻辑操作符:14. 字符合并:(abuttal) |: Concatenate without blank(blank) : Concatenate with blank15. 结构化指令/语句,重点掌握do语句;do 10 /* Execute 10 times */ call sub_routineenddo j = 1 to 10 by 1 call sub_routineenddo j = 1 to 10 by 1 for 3 say Loop executed: j times. /* Ends with: Loop executed: 3 times. */end16. 非结构化指令/语句:Leave指令和Iterate指令都可终止循环结束,但终止退出的位置不同,见下图。Do Forever指令mIterate指令nEnd指令pDo Forever指令aLeave指令bEnd指令cLeave指令将中断并跳出当前的活动循环,在上面将直接跳至指令c;Iterate指令将忽略循环体内剩余的循环指令,直接运行至循环体的End指令。17. Signal和Iterate的区别,Signal和GOTO的区别j = 1do forever/* do some work here */j = j + 1if j = 4 then signal my_routine /*无条件转移到MY_ROUTINE */end/* 此处的其他代码被SIGNAL指令忽略 */my_routine: say SIGNAL instruction was executed, MY_ROUTINE entered The iterate instruction causes control to be passed from the current statement in the do loop to the bottom of the loop. j=1do until j = 2 say Loop j = j was entered j = j + 1if j = 2 then iterate /*“注意去掉if j = 2 then”的运行结果,若换成leave的结果*/ say ITERATE 1. say ITERATE 2.endsay In the end18. Select指令用法:selectwhen gender = M thensay Gender is malewhen gender = F then dosay Gender is femalefemale_count = female_count + 1endotherwisesay Error - Gender is missing or invalidsay Please check input recordend /* this END pairs with the SELECT instruction itself */19. CALL语句用法:Rexxs call instruction invokes a subroutine, where the subroutine may be one of three kinds:l InternalConsists of Rexx code residing in the same file as the caller.l Built-inOne of the Rexx built-in functions.l ExternalCode residing in a different file than the invoking script. An external subroutine may be another Rexx script, or it may be written in any language supporting Rexxs interface.结合教材P28、P47掌握函数调用、返回值相关要点。20. 非结构化控制指令21. 数组初始化:list. = 0books. = 不允许:members. = members. + 5lista. = listb.lista.0 通常设置为数组的大小22. I/O linein Reads one line from an input stream. By default this reads the line from default standard input (usually the keyboard). lineout Writes a line to an output stream. By default this writes to standard output (usually the display screen). Returns 0 if the line was successfully written or 1 otherwise. lines Returns either 1 or the number of lines left to read in an input stream (which could be 0).程序:/* FIND PAYMENTS: */* Reads accounts lines one by one, writes overdue payments*/* (containing the phrase PAYMENT OVERDUE) to an output file.*/parse arg filein fileout /* get 2 filenames */do while lines(filein) 0 /* do while a line to read */input_line = linein(filein) /* read an input line */if pos(PAYMENT OVERDUE,input_line) = 1 then /* $ Due? */call lineout fileout,input_line /* write line if $ overdue */end运行:regina find_payments.rexx invoices_in.txt lost_payments_list_out.txtlineout/charout函数两种用法:l call lineout fileout, input_linel feedback = lineout(fileout, input_line)l rc = lineout(fileout, input_line)注意:单单使用lineout(fileout, input_line)错误。lines函数:l lines(file_name,C) Count. Returns the number of lines left to read.l lines(file_name,N) Normal. Returns 1 if there are lines left to read. (For backward compatibility, this case is the default.)文件打开关闭:l 1. Close a file and flush the buffers by encoding a lineout function:call lineout c:output_file /* flushes the buffers and */ /* closes the file in most Rexx implementations */l 2. Use stream function to close files: status_string = stream(file_name) status_string = stream(file_name, S)/* S option requests return of file STATUS */v Basic functions for standard character I/O: l charin Returns one or more characters read from an input stream. By default this reads one character from default standard input (usually the keyboard).l charout Writes zero or more characters to an output stream. By default this writes to standard output (usually the display screen). Returns 0 if all characters were successfully written. Or, it returns the number of characters remaining after a failed write.l output (usually the display screen) Returns 0 if all characters were successfully written. Or, it returns the number of characters remaining after a failed write.l chars Returns either 1 or the number of characters left to read in an input stream (which could be 0)/* TRANSLATE CHARS: */* Reads characters one by one, shows what they are in hex format*/parse arg filein fileout . /* get input & output filenames */out_string = /* initialize output string to null */do j=1 while chars(filein) 0 /* do while a character to read*/out_string = c2x(charin(filein)/* convert it to hex*/call charout ,out_string /* write to display */call charout fileout, out_string/* write to a file too*/end重定向I/O:l : Redirects output to a new file. Creates a new file or overwrites an existing file if one exists with that filename.l : Appends (adds on to) an existing file. Creates a new output file if one does not already exist having the filename.l : Redirects input from the specified file用法:regina four_letter_words.rexx output.txt23. EXECIO命令掌握对数据集内容的复制、显示、拷贝,再对数据集操作前,先使用ALLOCATE将数据集分配给一个文件;内容复制可先创建数据栈(NEWSTACK)对内容进行临时保存。参考教材P7883内容,掌握其中的示例。了解EXECIO返回码。24. 字符串操作apple=-Applesay Candy | | apple | | Rodeo/* displays: Candy -Apple Rodeo*/say Candyapple/* displays: Candy-Apple */say Candy apple/* displays: Candy -Apple */say Candyapple apple Rodeo/* displays: Candy-Apple Apple Rodeo */25. parse指令pull is short for the instruction:parse upper pull templatetemplate is a list of symbols separated by blanks and/or patterns. upper means uppercase translation occurs. Its presence is optional on the parse instruction. To avoid uppercase translation, just leave the upper keyword out of the parse instruction.More detailed parse instruction:parse upper value expression with templateparse upper var expression templateThe expression evaluates to some string that is parsed according to the template. The template provides for three basic kinds of parsing:l By words (character strings delimited by blanks or spaces)l By pattern (one character or a string other than blanks by which the expression string will be analyzed and separated)l By numeric pattern (numbers that specify column starting positions for each substring within the expression)Parse source:parse source system invocation filename .say System: system Invocation: invocation Filename: filename输出:System: WIN32 Invocation: COMMAND Filename: C:Reginapgmsparseenv.rexxparse version:parse version language level date month year .say Language: language Level: level Date: date Month: month Year: year输出:Language: REXX-Regina_3.2(MT) Level: 5.00 Date: 25 Month: Apr Year: 2003phone = 011-311-458-3758(1)parse value phone with country_code - area_code - prefix - suffixsep = - /* the dash will be the delimiter . */parse value phone with country_code (sep) area_code (sep) prefix (sep) suffix输出:country_code = 011area_code = 311prefix = 458suffix = 3758(2)parse value phone with country_code 4 5 area_code 8 9 prefix 12 13 suffixparse value phone with country_code 4 +1 area_code 8 +1 prefix 12 +1 suffix输出:country_code = 011area_code = 311prefix = 458suffix = 3758a = ABC; b = ABC if(a = b) then d = 0else say dsay d 0i = 0do j = 1 to 20 by 3 i = i + 1endsay i 7i = 0do 10 i = i + 1endsay i 10fruit. = fruit.chery = Tastysub_str = cherysay fruit.sub_str Tastya = ABC; b = ABC if(a = b) then i = jelse i = jsay i = J 1a = ABC; b = ABC if a = b then e = 0else say e = 1 0numeric digits 4numeric fuzz 2say 2.98 say digits()/* displays setting for NUMERIC DIGITS: 9 */say fuzz()/* displays setting for NUMERIC FUZZ: 0 */say form()/* displays setting for NUMERIC FORM: SCIENTIFIC*/参考教材P2930的内容。format(number_string,before,after)l before indicates how many characters appear in the integer part and after indicates how many characters appear in the decimal part.l If before is too small to contain the number, an error results. If after is too small, the number is rounded to fit.l If before is larger than the integer requires, blanks precede the number. If after is larger than the decimal part requires, extra zeroes are added on the right.format(number ,before ,after ,expp ,expt)l expp and expt control the formatting of the exponential part of the result.l expp is the number of digits used for the exponential part, while expt sets the trigger for the use of exponential notation.Format用法只需了解。27. 函数、子程序Inernal Routines: Classified as either functions or subroutines. l Functions include those that are provided as part of the Rexx language (the built-in functions) and those that you write yourself (user-defined functions).Difference between functions and subroutines:l Functions must return a single result string to the caller through the return instruction with which they end. Rexx replaces the function code in any statement with the returned value from the function.l Subroutines may or may not send back a value to their caller via their return instruction. The returned value from a subroutine, if there is one, is placed into the special variable named result.函数的返回结果存放于rc,子程序的返回结果存放于result。parse arg input_1, input_2, input_3 .arg(3,O) :E (Exists)Returns 1 if the nth argument exists. Otherwise returns 0.O (Omitted)Returns 1 if the nth argument was Omitted. Otherwise returns 0.In Rexx the function search order is:(1) Internal function The label exists in the current script file.(2) Built-in function Rexx sees if the function is one of its own built-in functions.(3) External function Rexx seeks an external function with the name. It may be written in Rexx or any language conforming to the system-dependent interface that Rexx uses to invoke it and pass the parameter(s).Function override:To avoid this, code the function reference as an uppercase string in quotation marks. E.g.,call substr/* own defined func */;call SUBSTR/* Rexx func */Rexx标准定义了返回某个数的绝对值的函数abs(val)。为扩展应用,我们需要重新定义该函数,则在程序中,调用相应的自定义函数的用法为 call abs val ,调用标准Rexx语言的用法为 call ABS val 。/* Simple “test driver” for the REVERSE function. */parse arg string .call reverse string/* call the REVERSE function */say The reversed string is: result /* display the RESULT */exit 0reverse: procedureparse arg string/* read the string to reverse*/if string = /* heres the end recursion condition*/ then return else return substr(string,length(string),1) | , reverse(substr(string,1,length(string)-1)28. Rexx程序在错误跟踪过程中,可使用call指令设置跟踪条件的参数是NOTREADY,注意不能用其他参数如NOVALUE、SYNTAX、LOSTDIGITS。29. 大型机上的Rexx程序文件类型,通常存在于以下的哪一种EXEC或XEDIT,Windows为rexx或rex文件,早期的文件类型还有cmd。30. “trace ?r”的含义:如果在此程序前result跟踪状态是打开的,则执行此语句后关闭;否则,打开此跟踪状态。31. 要传送命令到指定的主机环境(比如:TSO),应使用ADDRESS TSO。32. 有一个称为DEMO的REXX程序(或REXX EXEC)存放于数据集TBISUSR.REXXCRS.EXEC中,则可使用TSO命令“EXEC TBISUSR.REXXCRS.EXEC(DEMO) EXEC”来执行。33. 当使用语句CALL SUBROUT1,.来调用子程序时,将执行内建(built-in)子程序SUBROUT1,而忽略用户定义的内部子程序。34. 比较语句 0088=88 中,Rexx语言是按照数字类型进行比较判断的;而对于 88=88 语句,则是按照字符类型进行比较。35. Rexx语言中,函数的返回结果存放于rc,子程序的返回结果存放于result。36. 变量a在程序中已经赋过值,要将其还原为未初始化状态可使用语句“drop a”。37. 函数参数调用过程中,要想知道该函数传递了多少个参数,可使用Rexx的内建函数arg()。38. 调用程序要禁止被调用程序读或修改其变量,并且调用程序也无法看到被调用程序内的变量,则可在被调用程序(子程序或函数)后添加指令procedure;相反地,要使被调用程序可以修改主调用程序传递过来的参数,且主调用程序也可访问被调用程序中的变量,则可在被调用程序(子程序或函数)后添加指令“procedure expose”。39. 最有用也是Rexx标准缺省的跟踪用法(正常情况)是“trace n”;要跟踪语句的最终执行结果,可使用语句“trace r”。40. Rexx语言中的内建函数“symbol”可用来判断变量有无初始化或赋了某个值;如果判断结果返回字符串VAR,则表明该变量是有值的,反之,则返回字符串LIT。41. 语句Say 313233X的结果为123。(已知数字1的ASCII码为31)42. REXX数据栈操作及应用(P3435、P7677)(1)NEWSTACK、DELSTACK创建数据栈、删除最新创建的数据栈及里面的全部元素。(2)MAKEBUF、DROPBUF在数据栈上创建新的缓冲区、删除最新创建的缓冲区。注意,“DROPBUF 2”指删除2号及其以后创建的所有缓冲区。(3)QSTACK返回先前创建的数据栈的数量。(4)QBUF计算新创建的数据栈上建立的缓冲区数量,存放在RC中。(5)QELEM计算新创建缓冲区中元素的数量。(6)PUSH、QUEUE在数据栈顶部(LIFO)、底部(FIFO)增加数据。(7)PULL、PARSE从数据栈顶端移除数据,PULL、PARSE PULL。(8)QUEUE函数返回一个数据栈中的元素数量。43. Rexx语言的子例程(Subroutine)或函数(function)通常包含:内部(Internal)、内建(Build-in)、外部(External)三种类型。调用这些子例程(函数)的顺序为Internal、Build-in以及External。44. Rexx语言中函数和子程序的特点及区别。Rexx语言中函数必须有返回值return;而子程序可以有返回值,也可以没有返回值;若子程序有返回值,则其结果存放于result中。子程序的调用只能用call指令来完成,而函数的调用既可显式地用call指令,也可隐含在其他语句中。45. 已知Windows下sort命令是将数字、字符进行排序。若在Rexx程序中有如下语句:sort sortout.txt该语句的含义是将sortin.txt文件中的内容作为输入,对其进行排序;排序后的结果输出到文件sortout.txt中。该语句的另外一种表示法为:address SYSTEM sort WITH INPUT STREAM sortin.txt, OUTPUT SYSTEM sortout.txt46. 已知接收输入的ARG语句为“ARG a b c”,如果输入的内容为“Tom Helen 100 200”,则ARG后面各变量的值分别为:a = TOM;b = HELEN;c = 100 200。47. 已知接收输入的ARG语句为“ARG a b c .”,如果输入的内容为“Tom Helen 100 200”,则ARG后面各变量的值分别为:a = TOM;b = HELEN;c = 100。48. 已知接收输入的ARG语句为“PARSE ARG a b c d e”,如果输入的内容为“Tom Helen 100 200”,则ARG后面各变量的值分别为:a = Tom;b = Helen;c = 100;d = 200;e = null。49. 有如下程序:quote = Experience is the best teacher./* .+.1.+.2.+.3. */PARSE VAR quote v1 v2 15 v3 3 v4则v1、v2、v3、v4的值为:v1 = Experiencev2 = isv3 = the best teacher.v4 = perience is the best teacher.50. 有如下程序:quote = Experience is the best teacher./* .+.1.+.2.+.3. */PARSE UPPER VAR quote 15 v1 +16 =12 v2 +2 1 v3 +10则v1、v2、v3的值为:v1 = THE BEST TEACHERv2 = ISv3 = EXPERIENCE51. 有如下程序:quote = Experience is the best teacher./* .+.1.+.2.+.3. */PARSE VAR quote 1 v1 +11 v2 +6 v3 -4 v4则v1、v2、v3的值为:v1 = Experience v2 = is thev3 = best teacher.v4 = the best teacher.注:实际v1v4的值为单引号中的内容。52. 有如下程序:first = 7quote = Experience is the best teacher./* .+.1.+.2.+.3. */PARSE VAR quote 1 v1 =(first) v2 +6 v3则v1、v2、v3的值为:v1 = Experiv2 = ence iv3 = s the best teacher.注:实际v1v4的值为单引号中的内容。53. 有如下程序:quote1 = Knowledge is power.quote2 = Ignorance is bliss.quote3 = Experience is the best teacher.CALL sub1 quote1, quote2, quote3EXITsub1:PARSE ARG word1 . . , word2 . . , word3 .则word1、word2、word3的值为:word1 = Knowledgeword2 = Ignoranceword3 = Experience54. 关于堆栈与队列,研究以下程序:do j=1 to 2pus
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 租赁房车协议书样本
- 石材供货合同协议书
- 经销商培训合同范本
- 男女婚前协议书范本
- 缅甸矿山投资协议书
- 礼品定制合同协议书
- 租赁压桩机合同范本
- 石场承包地合同范本
- 电脑店入股合同范本
- 空气能热水合同范本
- 河南省青桐鸣大联考2025-2026学年高三11月月考语文试题(含答案)
- 2025安徽合肥水务集团有限公司招聘56人笔试历年参考题库附带答案详解
- 2025年国企招聘考试(文秘)历年参考题库含答案详解(5卷)
- 射血分数保留的心力衰竭诊断与治疗中国专家共识 2025解读
- 2025~2026学年天津市滨海新区大港实验中学高一上学期第一次月考数学试卷
- 找准位置精准发力高效突破最后180天!-2025-2026学年高三上学期期中考试家长会
- 初一上英语教学大纲教案资料(2025-2026学年)
- 2025年及未来5年市场数据中国促卵泡激素市场发展现状调查及投资趋势前景分析报告
- 劳动工资统计培训
- 无人机植保服务在现代农业推广分析方案
- 2024年广东省航道事务中心所属事业单位招聘笔试真题
评论
0/150
提交评论