Annotation of OpenXM/src/k097/Doc/intro.jp.txt, Revision 1.1
1.1 ! maekawa 1: (yacc/Doc/intro.jp.txt, 1997, 4/9)
! 2:
! 3: Q. まず, k0 ってどんな言語ですか?
! 4:
! 5: A. C と Java 風の class 宣言をとりいれたインタプリタです.
! 6:
! 7: 電卓として使用するには, k0 を起動後, たとえば
! 8:
! 9: 2^10+1 :
! 10:
! 11: と入力すれば 2の10乗足す1の結果を表示してくれます.
! 12:
! 13: 変数も使えて,
! 14: a = 2^10+1 ;
! 15: a^3 :
! 16:
! 17: と入力すれば (2^10+1)^3 を計算できます.
! 18:
! 19: : をおすと評価結果を表示します.
! 20: ; は評価をおこなうだけで, 結果の表示はしません.
! 21: k0 は大文字と小文字の区別をおこないますので注意して下さい.
! 22:
! 23:
! 24: では, 一つプログラムをお見せしましょう.
! 25: これは, 1!, 2!, ..., n! を表示するプログラムです.
! 26: afo(20); の入力で 20 までの階乗の表を出力します.
! 27:
! 28: def afo(n) {
! 29: local tmp,i;
! 30: tmp = 1;
! 31: for (i=1; i<=n ; i++) {
! 32: tmp = tmp*i;
! 33: Println(tmp);
! 34: }
! 35: return(tmp);
! 36: }
! 37: afo(20);
! 38:
! 39: ある程度のプログラムの経験がある人は上の例をみればすぐ使い方が
! 40: 分かるでしょう.
! 41: クラスを用いた例については, kxx97/yacc/debug/trip3.k を見て下さい.
! 42:
! 43: help(); と入力すると利用できる関数の一覧が表示されます.
! 44:
! 45: quit(); と入力すると終了します.
! 46:
! 47: Q. 文法で特に注意する点.
! 48:
! 49: A. break は, while のみに使えます.
! 50:
! 51: Q. k0 のエラーメッセージはどのようにみますか?
! 52:
! 53: A.
! 54: 例で説明しましょう.
! 55:
! 56: [1,2]+1 :
! 57:
! 58: と入力すると, 次のようなエラーがでます.
! 59: WARNING(kanExport[0|1].c): KooAdd() has not supported yet these objects.
! 60: ERROR(kanExport[0|1].c):
! 61: --- Engine error or interrupt : The error occured on the top level.
! 62: Type in Cleards() to exit the debug mode and Where() to see the stack trace.
! 63:
! 64: ひとつづつ意味を見ましょう.
! 65: >WARNING(kanExport[0|1].c): KooAdd() has not supported yet these objects.
! 66: KooAdd() は, PrimitiveObject を足す(add)関数です. ここでは,
! 67: array 型の [1,2] と, integer 型の 1 はたせないといっています.
! 68:
! 69: >--- Engine error or interrupt : The error occured on the top level.
! 70: エラーは, top level で生じたということを説明しています.
! 71:
! 72: もうひとつ例をあげましょう.
! 73:
! 74: def foo(n) {
! 75: local a;
! 76: a = n^2;
! 77: return(a);
! 78: }
! 79:
! 80: foo("abc");
! 81: と入力すると次のようなエラーがでます.
! 82:
! 83: WARNING(kanExport[0|1].c): KooMult() has not supported yet these objects.
! 84: ERROR(kanExport[0|1].c):
! 85: --- Engine error or interrupt : In function : foo of class PrimitiveObject
! 86: Type in Cleards() to exit the debug mode and Where() to see the stack trace.
! 87:
! 88: 文字列のかけ算 "abc"^2 を実行しようとして, このエラーがでました.
! 89: >--- Engine error or interrupt : In function : foo of class PrimitiveObject
! 90: これは, エラーが, 関数 foo の中でおきたことをしめしています.
! 91: >of class PrimitiveObject
! 92: は, class を用いて関数の overload をするようになると意味をもちます.
! 93: class を利用しなければ, つねに of class PrimitiveObject です.
! 94:
! 95: >Type in Cleards() to exit the debug mode and Where() to see the stack trace.
! 96: これはどういった意味でしょう.
! 97: プログラムがエラーで中断した時点で各変数は, 中断した時点の値がはいっています.
! 98: たとえば,
! 99: n:
! 100: と入力すると,
! 101: abc
! 102: なる値がかえってきます.
! 103: Cleards();
! 104: と入力すると変数を, 関数をぬけでたもとの状態にもどします.
! 105: Clearing DebugStack and ErrorStack...
! 106: Restoring variables....Done
! 107: In[12]=n :
! 108: %[null]
! 109:
! 110: %[null] は, null のことです.
! 111:
! 112: Q. Syntax Error にたいしてはどう対処しますか?
! 113:
! 114: A.
! 115: Syntax error のときは, ; を数回入力すれば, Prompt
! 116: In[i]=
! 117: がでます.
! 118: たとえば,
! 119: foo(10;
! 120: と入力すると,
! 121:
! 122: Syntax Error in the line 0:parse error
! 123: The error occured when the system is reading the line: foo(10;
! 124:
! 125: と出力されます.
! 126: The error occured when the system is reading the line: foo(10;
! 127: の意味は, foo(10 の次に ; を読み込んだ時点で, エラーとなったことを
! 128: 意味しています.
! 129:
! 130: ; と入力すれば,
! 131: In[6]=
! 132: となります.
! 133:
! 134: Q. (経験者の質問) k0 にはどんなデータ型がありますか?
! 135:
! 136: A. PrimitiveObject として,
! 137: null (ヌル)
! 138: string (文字列)
! 139: integer (無限多倍長整数型)
! 140: array (配列型またはリスト型)
! 141: polynomial (多項式型)
! 142: rational (有理型, integer や polynomial の組)
! 143: class (クラス型, 内部的な PrimitiveObject の拡張に使います.)
! 144: Object (Object 型, Object は, すべてのクラスのルートです.
! 145: Object は, array と最初の要素のタグで構成されます.)
! 146:
! 147: k0 は, backend エンジンとして, kan/sm1 を用いています.
! 148: sm1 は, kan96xx/ 以下の directory にあります.
! 149: PrimitiveObject と sm1 のデータ型の対応は以下のとおりです.
! 150:
! 151: k0 判定関数 sm1
! 152: ---------------------------------------------------------
! 153: string IsString(x) string (Sdollar)
! 154: integer IsInteger(x) universalNumber (SuniversalNumber)
! 155: polynomial IsPolynomial(x) poly (Spoly)
! 156: rational IsRational(x) rational (Srational)
! 157: array IsArray(x) array (Sarray)
! 158: Object x.IsObject() [class.context, .... ]
! 159:
! 160:
! 161: Q. (経験者の質問) 現在の context をみるには?
! 162:
! 163: A.
! 164: sm1(" [(CurrentContextp)] system_variable :: ");
! 165: と入力して下さい.
! 166:
! 167:
! 168: Q. (経験者の質問) 現在の context を変更するには?
! 169: 現在の context の名前辞書を表示するには?
! 170:
! 171: A. 例で説明しましょう.
! 172:
! 173: load("debug/trip3.k"); /* Complex が定義されます. */
! 174: sm1(Complex," 0 get setcontext "); /* 現在の context を Complex にします.*/
! 175: sm1(" show_user_dictionary "); と入力すると以下のデータが表示されます.
! 176:
! 177: DictionaryName=Complex, super= Object
! 178: new0 show
! 179:
! 180: new0 と show が定義されているのがわかります.
! 181:
! 182: 標準の辞書に戻すには,
! 183: sm1(PrimitiveObject," 0 get setcontext ");
! 184: と入力して下さい.
! 185:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>