アニメ『コボちゃん』(1992~1994)
昔はロボットアニメ中心に見ていたので、放送してたことも知らなかったアニメです。
歳をとると、いろんな方面に興味が湧いてきて、ロックしか聞かなかったのに、クラシックが心地よくなったり。技術書でなく小説を読んでみたり。最近は農作物の栽培にも興味があります。
さて、古き良きプログラミング言語COBOL(open-cobol)を触ってみます。
インストールはコマンド一発です。
takk@ubu16:~$ sudo aptitude install open-cobol
さっそくHello Worldプログラム。
takk@ubu16:~/aaa$ cat test.cob IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. DISPLAY "Hello World!". STOP RUN.
コンパイルしてみます。
takk@ubu16:~/aaa$ cobc -x test.cob test.cob:1: Error: Invalid indicator 'F' at column 7 takk@ubu16:~/aaa$
うっ、だめです。一行目からcolumn 7でエラーがでます。
なぜ、7列目なのか。
実は7列目には、コメント行を表す*の文字か、有効行を表す空白しか書けません。
本文は8列目以降に書く必要があります。面白い制限ですね。
正しいフォーマットにしてコンパイルしてみます。
takk@ubu16:~/aaa$ cat test.cob
* コメント
*
*
*
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
takk@ubu16:~/aaa$ cobc -x test.cob
takk@ubu16:~/aaa$
通りました。
testファイルが生成されました。
takk@ubu16:~/aaa$ ls -l 合計 20 -rwxrwxr-x 1 takk takk 13528 8月 27 09:23 test -rw-rw-r-- 1 takk takk 204 8月 27 09:23 test.cob takk@ubu16:~/aaa$
実行権限xがついてますので、このまま実行できます。
takk@ubu16:~/aaa$ ./test Hello World! takk@ubu16:~/aaa$
動きました。こうなるともう他の言語と同じですね。
cobcコマンドのオプションは-h指定すれば確認できます。
当然かもしれませんが、最適化の-Oオプションもあるんですね。
takk@ubu16:~$ cobc -h
Usage: cobc [options] file...
Options:
--help Display this message
--version, -V Display compiler version
-v Display the programs invoked by the compiler
-x Build an executable program
-m Build a dynamically loadable module (default)
-std=<dialect> Compile for a specific dialect :
cobol2002 Cobol 2002
cobol85 Cobol 85
ibm IBM Compatible
mvs MVS Compatible
bs2000 BS2000 Compatible
mf Micro Focus Compatible
default When not specified
See config/default.conf and config/*.conf
-free Use free source format
-fixed Use fixed source format (default)
-O, -O2, -Os Enable optimization
-g Produce debugging information in the output
-debug Enable all run-time error checking
-o <file> Place the output into <file>
-b Combine all input files into a single
dynamically loadable module
-E Preprocess only; do not compile, assemble or link
-C Translation only; convert COBOL to C
-S Compile only; output assembly file
-c Compile and assemble, but do not link
-t <file> Generate and place a program listing into <file>
-I <directory> Add <directory> to copy/include search path
-L <directory> Add <directory> to library search path
-l <lib> Link the library <lib>
-D <define> Pass <define> to the C compiler
-conf=<file> User defined dialect configuration - See -std=
--list-reserved Display reserved words
--list-intrinsics Display intrinsic functions
--list-mnemonics Display mnemonic names
-save-temps(=<dir>) Save intermediate files (default current directory)
-MT <target> Set target file used in dependency list
-MF <file> Place dependency list into <file>
-ext <extension> Add default file extension
-W Enable ALL warnings
-Wall Enable all warnings except as noted below
-Wobsolete 廃要素が使われていれば警告する
-Warchaic 古い仕様が使われていれば警告する
-Wredefinition Warn incompatible redefinition of data items
-Wconstant 不適切な定数を警告する
-Wparentheses Warn lack of parentheses around AND within OR
-Wstrict-typing タイプの不適合を厳密に警告する
-Wimplicit-define Warn implicitly defined data items
-Wcall-params Warn non 01/77 items for CALL params (NOT set with -Wall)
-Wcolumn-overflow Warn text after column 72, FIXED format (NOT set with -Wall)
-Wterminator Warn lack of scope terminator END-XXX (NOT set with -Wall)
-Wtruncate Warn possible field truncation (NOT set with -Wall)
-Wlinkage Warn dangling LINKAGE items (NOT set with -Wall)
-Wunreachable Warn unreachable statements (NOT set with -Wall)
-ftrace Generate trace code (Executed SECTION/PARAGRAPH)
-ftraceall Generate trace code (Executed SECTION/PARAGRAPH/STATEMENTS)
-fsyntax-only 文法チェックのみ。何も出力しない
-fdebugging-line Enable debugging lines ('D' in indicator column)
-fsource-location Generate source location code (Turned on by -debug or -g)
-fimplicit-init Do automatic initialization of the Cobol runtime system
-fsign-ascii Numeric display sign ASCII (Default on ASCII machines)
-fsign-ebcdic Numeric display sign EBCDIC (Default on EBCDIC machines)
-fstack-check PERFORM stack checking (Turned on by -debug or -g)
-ffold-copy-lower Fold COPY subject to lower case (Default no transformation)
-ffold-copy-upper Fold COPY subject to upper case (Default no transformation)
-fnotrunc Do not truncate binary fields according to PICTURE
-ffunctions-all Allow use of intrinsic functions without FUNCTION keyword
-fmfcomment '*' or '/' in column 1 treated as comment (FIXED only)
-fnull-param Pass extra NULL terminating pointers on CALL statements
takk@ubu16:~$


コメント