LFTCompiler
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()<stat>emitLabel(lnext_stat)<statlistp>::== \(\epsilon\)goto statlistp.lnext<stat>::== = IDstat.id_addr=st.lookupAddress(ID.lexeme)if(stat.id_addr==-1) { stat.id_addr=count; st.insert(ID.lexeme,count++) }<expr>istore stat.id_addr || goto lnext::== print (<exprlist>)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.lnextemitLabel(bexpr.true)<bexpr>)stat1.lnext=stat.lnext<stat1>::== {|| 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()<whenitem>goto whenlistp_exitemitLabel(whenitem.false)<whenlistp>::== \(\epsilon\)<whenitem>::== when (bexpr.true=newLabel()bexpr.false=whenitem.false<bexpr>) doemitLabel(bexpr.true)stat.lnext=newLabel()<stat>emitLabel(stat.lnext)<bexpr>::== RELOP<expr><expr>if_icmpRELOP bexpr.false::== truegoto bexpr.true::== falsegoto bexpr.false::== !<bexpr1>goto bexpr1.false::== && (bexpr1.true=newLabel() || bexpr1.false=bexpr.false<bexpr1>goto bexpr1.trueemitLabel(bexpr1.true)bexpr2.true=bexpr.true || bexpr2.false=bexpr.false<bexpr2>) ::== || (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>::==<expr><exprlistp1>exprlistp.n=1+exprlistp1.n::== \(\epsilon\)exprlistp.n=0<expr>::== + (<exprlist>)for(n=exprlist.n-1; n>0; n--) { iadd }::== -<expr><expr>isub::== * (<exprlist>)for(n=exprlist.n-1; n>0; n--) { imul }::== /<expr><expr>idiv::== IDexpr.addr=st.lookupAddress(ID.lexeme)iload expr.addr::== NUMldc NUM.value