parser.y 3. node.rb 4. CD-ROM

Similar documents
Microsoft PowerPoint - 13Kadai.pptx

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

r9.dvi

r1.dvi

Windows Cygwin Mac *1 Emacs Ruby ( ) 1 Cygwin Bash Cygwin Windows Cygwin Cygwin Mac 1 Mac 1.2 *2 ls *3 *1 OS Linux *2 *3 Enter ( ) 2

ohp07.dvi

Windows [ ] [ (R)..] cmd [OK] Z:\> mkdir progi [Enter] \ ) mkdir progi ) (command ) help [Enter] help ( help ) mkdir make directory Windows ) mkdir mk

( ) ( ) lex LL(1) LL(1)

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

r3.dvi

r3.dvi

untitled

R R S S 6 S S D D S3 S3 R R S 6 S 6 S S D D w.o S3 S3 R5 3-0 R S 06 S 6 6 S S 6 D D 30 S3 w.o S3 R R8 7 3-

Emacs Ruby..

listings-ext

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装

Ruby 50 Ruby UTF print, \n [Ruby-1] print("hello, Ruby.\n") [Ruby-2] Hello, Ruby. [Ruby-3] print("hello, \"Ruby\".\n") 2 [Ruby-4] seisuu = 10 pr

main

Ruby演習テキスト1


¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

2 1/2 1/4 x 1 x 2 x 1, x 2 9 3x 1 + 2x 2 9 (1.1) 1/3 RDA 1 15 x /4 RDA 1 6 x /6 1 x 1 3 x 2 15 x (1.2) (1.3) (1.4) 1 2 (1.5) x 1

untitled

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse



Microsoft PowerPoint - 11RubyIntro-No02.ppt [互換モード]

Microsoft PowerPoint - ruby_instruction.ppt

Ruby Ruby ruby Ruby G: Ruby>ruby Ks sample1.rb G: Ruby> irb (interactive Ruby) G: Ruby>irb -Ks irb(main):001:0> print( ) 44=>

第10回 コーディングと統合(WWW用).PDF

15 Phoenix HTML 15.1 ModestGreeter RAVT web/router.ex web/router.ex : 12 scope "/", ModestGreeter do 13 pipe_through :browser get "/", TopCont

untitled

ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1

() / (front end) (back end) (phase) (pass) 1 2

1 Ex Ex. 2 2

: gettoken(1) module P = Printf exception End_of_system (* *) let _ISTREAM = ref stdin let ch = ref ( ) let read () = (let c =!ch in ch := inp

8 if switch for while do while 2

情報科学概論 第1回資料

PowerPoint プレゼンテーション

Microsoft PowerPoint - 08LR-conflicts.ppt [互換モード]

Microsoft PowerPoint - Ruby n




(Basic Theory of Information Processing) Fortran Fortan Fortan Fortan 1

C言語によるアルゴリズムとデータ構造

離散数理工学 第 2回 数え上げの基礎:漸化式の立て方

fp.gby

untitled

B 5 (2) VBA R / B 5 ( ) / 34

r10.dvi

テキスト処理第 2 回 田中哲産業技術総合研究所情報技術研究部門 akira/textprocess/

離散数理工学 第 2回 数え上げの基礎:漸化式の立て方


/

コンピュータ概論

PL : pl0 ( ) 1 SableCC ( sablecc ) 1.1 sablecc sablecc Étienne Gagnon [1] Java sablecc sablecc ( ) Visitor DepthFirstAdapter 1 (Depth

1. A0 A B A0 A : A1,...,A5 B : B1,...,B

D0050.PDF

untitled

r07.dvi

ohp07.dvi

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

C 言語の式と文 C 言語の文 ( 関数の呼び出し ) printf("hello, n"); 式 a a+4 a++ a = 7 関数名関数の引数セミコロン 3 < a "hello" printf("hello") 関数の引数は () で囲み, 中に式を書く. 文 ( 式文 ) は

明解Java入門編

haskell.gby

r2.dvi


I J

lifedesign_contest_No3

javascript key

AJAN IO制御コマンド コマンドリファレンス

P03.ppt

Java演習(4) -- 変数と型 --

For_Beginners_CAPL.indd



10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false


Kyosuke MOROHASHI

r08.dvi

untitled

Sokushu2_perl

double float

インターネットマガジン2001年9月号―INTERNET magazine No.80

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

コンピュータ概論

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

I 1 1 ( *) ( *) ex1-1.rb ) 2 CGI

SystemC 2.0を用いた簡易CPUバスモデルの設計

Java学習教材

2

XMPによる並列化実装2

AC-1 procedure AC-1 (G) begin Q = f(i; j) (i; j) 2 arc(g), i 6= jg repeat begin CHANGE = false for each (i; j) 2 Q do CHANGE = REVISE((i; j)) _ CHANGE

ジェネリック医薬品販売会社(田辺製薬販売株式会社)の設立に伴う包装変更のご案内

06地図目録.pwd

橡82-93協力員原稿>授業

17. (1) 18. (1) 19. (1) 20. (1) 21. (1) (3) 22. (1) (3) 23. (1) (3) (1) (3) 25. (1) (3) 26. (1) 27. (1) (3) 28. (1) 29. (1) 2


Transcription:

1. 1 51 2. parser.y 3. node.rb 4. CD-ROM

1 10 2 i 0 i 10 " i i+1 3 for(i = 0; i <= 10; i++) printf(" \n"); i = 0; while(i <= 10) printf(" \n"); i++; 4 when /\A==/ @q.push [ :EQ, [lineno, == ] ] expr EQ expr ==, [val[0], val[2]] ) 5 when /\A==/, /\A[><]=?/ @q.push [ :COMPAIR, [lineno, $&.intern] ] 6 expr COMPAIR expr val[1][1], [val[0], val[2]] ) 7 prechigh nonassoc UMINUS left * / - 1 -

left + - nonassoc EQ preclow 8 prechigh nonassoc UMINUS left * / left + - nonassoc COMPAIR preclow 9 if_stmt : IF stmt THEN EOL stmt_list elsif_stmt else_stmt END result = IfNode.new( @fname, val[0][0], val[1], val[4], val[5], val[6] ) 10 elsif_stmt : ELSIF stmt THEN EOL stmt_list 11 elsif_stmt : elsif_stmt ELSIF stmt THEN EOL stmt_list result.push [val[2], val[5]] ELSIF stmt THEN EOL stmt_list result = [[val[1], val[4]]] 12 class IfNode < Node def initialize( fname, lineno, cond, tstmt, elsif_stmt, fstmt ) super fname, lineno @condition = cond @tstmt = tstmt @elsif_stmt = elsif_stmt @fstmt = fstmt def evaluate( intp ) if @condition.evaluate(intp) then exec_list intp, @tstmt else @@else_flug = true - 2 -

if @elsif_stmt then @elsif_stmt.each do @@each_elsif #p @@each_elsif if @@each_elsif[0].evaluate(intp) then exec_list intp, @@each_elsif[1] @@else_flug = false break if @@else_flug then exec_list intp, @fstmt if @fstmt 13 14 @@else_flug = true if @elsif_stmt then @elsif_stmt.each do @@each_elsif #p @@each_elsif if @@each_elsif[0].evaluate(intp) then exec_list intp, @@each_elsif[1] @@else_flug = false break if @@else_flug then => :IF => :IF 15 IDENT = expr 16 IDENT expr 17 @q.push [, [lineno, $&.intern] ] @q.push [, [lineno, $&.intern] ] when /\A / - 3 -

@q.push [, [lineno, $&.intern] ] IDENT expr 18 @q.push [ :WO, [lineno, $&.intern] ] @q.push [ :NI, [lineno, $&.intern] ] @q.push [ :DAINYU, [lineno, $&.intern] ] IDENT NI expr WO DAINYU 19 puts hello 20 a = hello 21 a hello a hello hello a hello a 22 a hello a hello 23 a hello hello a 24 @q.push [ :DAINYU, [lineno, $&.intern] ] @q.push [ :WO, [lineno, $&.intern] ] @q.push [ :NI, [lineno, $&.intern] ] assign : IDENT = expr - 4 -

IDENT NI expr WO DAINYU expr WO IDENT NI DAINYU 25 a = 1 26 a 1 a 1 1 a 1 a 27 when /\A ( )?/ @q.push [ :DAINYU, [lineno, $&.intern] ] @q.push [ :WO, [lineno, $&.intern] ] @q.push [ :NI, [lineno, $&.intern] ] assign : IDENT = expr IDENT NI expr WO DAINYU expr WO IDENT NI DAINYU 28 a b a b a b a b a b a b a b 29 when /\A / @q.push [ :HITOSII, [lineno, $&.intern] ] @q.push [ :IZYOU, [lineno, $&.intern] ] @q.push [ :IKA, [lineno, $&.intern] ] when /\A / @q.push [ :YORIOOKII, [lineno, $&.intern] ] when /\A /, /\A / @q.push [ :YORITIISAI, [lineno, $&.intern] ] - 5 -

expr : # expr TO expr GA HITOSII ==, [val[0], val[2]] ) expr GA expr TO HITOSII ==, [val[0], val[2]] ) expr GA expr IZYOU >=, [val[0], val[2]] ) expr GA expr IKA <=, [val[0], val[2]] ) expr GA expr YORIOOKII >, [val[0], val[2]] ) expr GA expr YORITIISAI <, [val[0], val[2]] ) 30 if a = 1 then puts a = 1 elsif a = 2 puts a = 2 else puts else 31 a 1 a = 1 a 2 a = 2 else - 6 -

32 @q.push [ :IF, [lineno, $&.intern] ] when /\A / @q.push [ :THEN, [lineno, $&.intern] ] when /\A ( )?/ @q.push [ :ELSIF, [lineno, $&.intern] ] when /\A ( )?/ @q.push [ :ELSE, [lineno, $&.intern] ], /\A /, /\A /, /\A / @q.push [ :END, [lineno, $&.intern] ] if_stmt : IF stmt THEN EOL stmt_list elsif_stmt else_stmt END else_stmt : ELSE EOL stmt_list elsif_stmt : elsif_stmt ELSIF stmt THEN EOL stmt_list ELSIF stmt THEN EOL stmt_list 33 i = 0 while i <= 10 puts i i += 1 34 i 0 i 10 i i i+1 35 when /\A / @q.push [ :KURIKAESU, [lineno, $&.intern] ] when /\A( )? / @q.push [ :AIDA, [lineno, $&.intern] ] while_stmt: WHILE stmt DO EOL stmt_list END stmt AIDA KURIKAESU EOL stmt_list END 36 puts( hello ) puts hello puts() - 7 -

puts 37 hello 38 when /\A ( ( )?)?/ word = puts @q.push [ :FUNCTION, [lineno, word.intern ] ] stmt : # stmt FUNCTION 39 40 when /\A ( ( )?)?/ word = puts @q.push [ :FUNCTION, [lineno, word.intern ] ] 41 when /\A ( )?/ word = print @q.push [ :FUNCTION, [lineno, word.intern ] ] 42 43 when /\A ( )?/ word = puts @q.push [ :KAIGYO, [lineno, word.intern ] ] KAIGYO result = FuncallNode.new( @fname, val[0][0], val[0][1], [] ) - 8 -

44 ruby jpprog src.txt data.txt 45 1 46 when /\A ( 1 )? ( )([a-za-z][a-za-z0-9_]*) ( )/ word = gets line_var = $3 @q.push [ :GETS, [lineno, line_var.intern ] ] funcall : # GETS tmp = FuncallNode.new( @fname, val[0][0], gets.intern, [] ) result = AssignNode.new( @fname, val[0][0], val[0][1], tmp ) 47 ARGV.shift 48 #@fname:#line: syntax error on #v.inspect 49 \n\n #@fname #line #v.inspect \n\n 50 51 @q.push [ :IF, [lineno, $&.intern] ] ruby jpprog src.txt - 9 -