1 / 6

Compiler 報告

Compiler 報告. 第 10 組 91156235 鮑志軒 92156227 劉致顯. Mixed-Mode Boolean Expressions. Boolean 簡單來說,其實就是一項敘述的正確值為1 ,若否定則其值為0 一個簡單的例子: (a<b) + (b<a) 此種情況下,若 a = b ,則其值為 0 a != b ,則其值為 1. Mixed-Mode Boolean Expressions.

aaralyn
Download Presentation

Compiler 報告

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. Compiler報告 第10組 91156235鮑志軒 92156227劉致顯

  2. Mixed-Mode Boolean Expressions • Boolean簡單來說,其實就是一項敘述的正確值為1 ,若否定則其值為0 • 一個簡單的例子:(a<b) + (b<a)此種情況下,若a = b ,則其值為0 a != b ,則其值為1

  3. Mixed-Mode Boolean Expressions • 今天有一個productionE -> E + E | E and E | E relop E | id • (E and E) ,(E relop E) 為boolean • (id) 為arithmetic • (E + E) 則比較特別,因為它有可能是2個arithmetic type相加,也有可能其中包含了boolean type

  4. Mixed-Mode Boolean Expressions • 因此在探討 (E -> E + E) 這一個部份時,我們給予其type的attribute值,並且把它改成(E -> E1 + E2) 以方便辨別 • 並且把 arithmetic 簡寫為 arith boolean 簡寫為 bool • 其中boolean type包含E.true & E.false兩值 • 而E.place則負責運算的部份

  5. Semantic rule for (E -> E + E) • E.type := arith; • if E1.type = arith and E2.type = arith • thenbegin • /* normal arithmetic add */ • E.place := newtemp; • E.code := E1.code || E2.code || • gen(E.place ':=' E1.place '+' E2.place) • end • elseif E1.type = arith and E2.type = bool • then begin • E.place := newtemp; • E2.true := newlabel; • E2.false := newlabel; • E.code := E1.code || E2.code || • gen(E2.true ':' E.place ':=' E1.place + 1)|| • gen('goto' nextstat + 1)|| • gen(E2.false ':' E.place ':=' E1.place) • end • else if .......................

  6. Mixed-Mode Boolean Expressions • E2.true : E.place := E1.place + 1 • goto nextstat + 1 • E2.false : E.place := E1.place

More Related