26.04.2013 Views

Analisi sintattica

Analisi sintattica

Analisi sintattica

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Ambiguita – Precedenza degli<br />

operatori<br />

Grammatiche ambigue possono essere rese non-ambigue<br />

in accordo alle precedenze degli operatori e alle regole di<br />

associativià degli operatori.<br />

E → E+E | E*E | E^E | id | (E)<br />

E → E+T | T<br />

T → T*F | F<br />

F → G^F | G<br />

G → id | (E)<br />

precedenze: ^ (right to left)<br />

* (left to right)<br />

+ (left to right)<br />

Ricorsione sinistra (Left Recursion)<br />

Una grammatica è “left recursive” se ha un non<br />

terminale A tale che<br />

+<br />

A ⇒ Aα per qualche stringa α<br />

Le tecniche di parser Top-down non possono gestire<br />

grammatiche left-recursive.<br />

Una grammatica left-recursive deve esssere<br />

convertita in una non left-recursive.<br />

La ricorsione sinistra può comparire in un singolo<br />

passo della derivazione (immediate left-recursion), o<br />

può comparire in più che un passo.<br />

12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!