Progetto per il Corso di Linguaggi Formali e Traduttori
Translator
SDT
<prog>::==prog.lnext=newLabel()statlist.lnext=prog.lnext<statlist>emitLabel(prog.lnext)EOF<statlist>::==stat.lnext=newLabel()<stat>emitLabel(stat.lnext)statlistp.lnext=statlist.lnext<statlistp><statlistp>:: ; `stat.lnext=newLabel()` `` `emitLabel(lnext_stat)` ` ` :: goto statlistp.lnext<stat>:: = ID `stat.id_addr=st.lookupAddress(ID.lexeme)` `if(stat.id_addr-1) { stat.id_addr=count; st.insert(ID.lexeme,count++) }istore stat.id_addr || goto lnext::== print ()for(n=exprlist.n; n>0; n—){ invokestatic 1 }::== read ( ID )stat.id_addr = &ID.lexemeif(stat.id_addr-1) { stat.id_addr=count; st.insert(ID.lexeme,count++) }` `invokestatic 0 || istore stat.id_addr || goto lnext` :: condwhenlist.else=newLabel() || whenlist.exit=newLabel()<whenlist>emitLabel(whenlist.else)elsestat1.lnext=whenlist.exit<stat1>emitLabel(whenlist.exit)goto stat.lnext:: while ( `bexpr.true=newLabel() || bexpr.false=stat.lnext` `emitLabel(bexpr.true)` `` ) `stat1.lnext=stat.lnext` ` {` :: || statlist.lnext=stat.lnext ||<statlist>}<whenlist>::==whenitem.false = newLabel()<whenitem>goto whenitem.falseemitLabel(whenitem.false) ~whenlistp.exit = whenlist.exit<whenlistp>goto whenlist.else<whenlistp>:: `whenitem.false = newLabel()` `` `goto whenlistp_exit` `emitLabel(whenitem.false)` ` ` :: <whenitem>::== when (bexpr.true=newLabel()bexpr.false=whenitem.false<bexpr>) doemitLabel(bexpr.true)stat.lnext=newLabel()<stat>emitLabel(stat.lnext)<bexpr>:: RELOP `` ` true` `if_icmpRELOP bexpr.false` :: goto bexpr.true:: false `goto bexpr.false` :: !<bexpr1>goto bexpr1.false:: && ( `bexpr1.true=newLabel() || bexpr1.false=bexpr.false` `` `goto bexpr1.true` `emitLabel(bexpr1.true)` `bexpr2.true=bexpr.true || bexpr2.false=bexpr.false` ` || (` ) :: bexpr1.false=newLabel() || bexpr1.true=bexpr.true<bexpr1>goto bexpr.trueemitLabel(bexpr1.false)bexpr2.true=bexpr.true || bexpr2.false=bexpr.false<bexpr2>)<exprlist>::==<expr><exprlistp>exprlist.n=1+exprlistp.n<exprlistp>:: `` ` ` `exprlistp.n=1+exprlistp1.n` :: exprlistp.n=0<expr>:: + ( `` ) `for(n=exprlist.n-1; n>0; n--) { iadd }` :: -<expr><expr>isub:: \* ( `` ) `for(n=exprlist.n-1; n>0; n--) { imul }` :: /<expr><expr>idiv:: ID `expr.addr=st.lookupAddress(ID.lexeme)` `iload expr.addr` :: NUMldc NUM.value