parse Interface Package Parser Interface Parser Package Parser

  • Slides: 20
Download presentation

漸進的解析器の構成 • ソースコード中でクラスを定義して • クラスのインターフェイス(公開メソッ いる部分すべて見つけだす。 ドのシグネチャや公開インスタンス変 • parse. Interface()を呼び出して、そ 数の型)を調べてPackage. Parser に返 れらをInterface.

漸進的解析器の構成 • ソースコード中でクラスを定義して • クラスのインターフェイス(公開メソッ いる部分すべて見つけだす。 ドのシグネチャや公開インスタンス変 • parse. Interface()を呼び出して、そ 数の型)を調べてPackage. Parser に返 れらをInterface. Parser に渡す。 す。 • Package. Parser はその情報を interfaces に追加していく。 実行順序 Package. Parser #interfaces -code Class. Parser +parse(partial. Src): code #parser. Interface(partial. Src) : interface #parse. Class(partial. Src): code Interface. Parser #parse. Interface (partial. Src): interface 2004/02/24 #instance. Vars #methods #parse. Class(partial. Src): code #parse. Method(partial. Src): code Method. Parser #parameters #parse. Method(partial. Src): code 日本ソフトウェア科学会 第1回 ディペンダブルソフ トウェア ワークショップ 7

class C extends Object { Object value; C() { super(); this. value = new

class C extends Object { Object value; C() { super(); this. value = new Pair(new A(), new B()). setfst(new B()); } } 例題: Featherweight Java ◆ FWJ[7]の漸進的解析器を 開発する 階層的なスコープを持ち ■ 強く型付けされた ■ 非常に単純な構文規則 (Javaのサブセット)を持つ ■ class Pair extends Object { Object fst; Object snd; Pair(Object fst, Object snd) { super(); this. fst = fst; this. snd = snd; } Pair setfst(Object newfst) { return new Pair(newfst, this. snd); } } class A extends Object { A() { super(); } } [7] Igarashi, A. , Pierce, B. , and Wadler, P. : Featherweight Java: A Minimal Core Calculus for Java and GJ, ACM Trans. Programming class B extends Object { Languages and Systems, 23(3), pp. 396 -450 B() { super(); } 2004/02/24 日本ソフトウェア科学会 第1回 ディペンダブルソフ (2001). } トウェア ワークショップ 9

Input() : Class. Parser <LB> ( LOOKAHEAD(2) V() )* K() ( M() )* <RB>

Input() : Class. Parser <LB> ( LOOKAHEAD(2) V() )* K() ( M() )* <RB> V() : <TYPEID> <SEMICOLON> K() : <TYPEID> <LP> ( Param. L() )? <RP> Block. Like() Param. L() : <TYPEID> <ID> Package. Parser ( <COMMA> <TYPEID> <ID> )* Input() : M() : ( CL() ) * <EOF> ( <TYPEID> | <VOID> ) <ID> CL() : <LP> ( Param. L() )? <RP> <CLASS> <ID> <EXTENDS> <ID> Block. Like() : <LB> ( <ID> | <TYPEID> | <LP> | <RP> ( <ID> | <LP> | <RP> | <SUPER> | <THIS> | <DOT> | <EQUAL> | <SEMICOLON> | <COMMA> | <RETURN> | <NEW> | Block. Like() )* 第1回 ディペンダブルソフ 2004/02/24 11 日本ソフトウェア科学会 | <RETURN> | <NEW> | Block. Like() )* トウェア ワークショップ <RB> 漸進的解析器

構文エラーを含む入力例 2004/02/24 1: class A extends Object { 2: C() { super(); } 3:

構文エラーを含む入力例 2004/02/24 1: class A extends Object { 2: C() { super(); } 3: } 4: class Pair extends Object { 5: Object fst; 6: Object snd; 7: Pair(Object fst, Object snd) { 8: super(); 9: this. fst = fst; 10: this. snd = snd; 11: } 12: Pair(Object newfst) { 13: return new Pair(newfst, this. snd); 14: 日本ソフトウェア科学会 } 第1回 ディペンダブルソフ トウェア ワークショップ 15: } 12