1 / 3

4.5 構文解析の自動化 (1) YACC とは

4.5 構文解析の自動化 (1) YACC とは. YACC(yet another compiler compiler) ■ UNIX 上の構文解析自動生成システム ■ 構文規則を入力して、構文規則に合致した記号列を解析する C プログラムを生成する。 ■ 手法は LALR(1). (2) YACC の入力ファイル. 入力ファイルは以下の3部分から構成される。. ① トークンと演算子の宣言(優先順位は記述された順序) ② 構文規則の記述 ⅰ ) 構文がプログラム中に出現したときの処理を構文要素間に 中括弧で囲んで C プログラムで記述することができる。

nara
Download Presentation

4.5 構文解析の自動化 (1) YACC とは

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4.5 構文解析の自動化(1)YACCとは YACC(yet another compiler compiler) ■ UNIX上の構文解析自動生成システム ■ 構文規則を入力して、構文規則に合致した記号列を解析するCプログラムを生成する。 ■ 手法はLALR(1)

  2. (2)YACCの入力ファイル 入力ファイルは以下の3部分から構成される。 ① トークンと演算子の宣言(優先順位は記述された順序) ② 構文規則の記述 ⅰ) 構文がプログラム中に出現したときの処理を構文要素間に 中括弧で囲んでCプログラムで記述することができる。 ⅱ) 構文要素に何らかの値を対応させることで、その規則の 構文要素の値($$, $1, $2)を記号で参照することができる ⅲ) 構文エラーが起きたときどこまで解析をスキャンするかを 指定できる。 ③ 構文規則内のCの関数を記述(yylex と yyerror は名前固定)

  3. (3)YACC入力ファイル例 {if1(compile(T)$4,FJUMP));} statement {if2();} if_tail {if3();} | ………; if_tail : ELSE statement | /*empty/; ……… %% ……… static int yylex(){ ……… } yyerror(s) char *s; { print(“%4d: %s\n”,tokenline,s); errcnt++; } ……… %start program %token IDENT, LITERAL; ……… %right EQUAL; %left OROR; ……… %% program : {initCode();} ext_def_list {checkFunc();}; ext_def_list : ext_def_list external_def | ; external_def : val_decl | function | error SEMICOLON ; ……… Statement : ……… | IF {clearTree();} LPAR expression RPAR

More Related