análisis sintáctico descendente sin retroceso - Blearning

análisis sintáctico descendente sin retroceso - Blearning análisis sintáctico descendente sin retroceso - Blearning

blearning.itmina.edu.mx
from blearning.itmina.edu.mx More from this publisher
09.05.2013 Views

Análisis sintáctico descendente sin retroceso Gramáticas LL(1) Seudocódigo del algoritmo para el cálculo de conjuntos de Seguidores SEGUIDORES (símbolo-inicial) := {$}; for todos los no terminales A ≠ símbolo-inicial do SEGUIDORES(A):={}; while existan cambios en cualquier conjunto SEGUIDORES do for cada producción A→X 1 X 2 ...X n do for cada X i que sea un no terminal do añadir INICIALES (X i+1 X i+2 ...X n ) - {λ} a SEGUIDORES (X i ) (* NOTA: si i=n, entonces X i+1 X i+2 ...X n = λ *) if λ está en INICIALES(X i+1 X i+2 ...X n ) then añadir SIGUIENTE (A) a SIGUIENTE (X i ) Página 26

Ejemplos: Análisis sintáctico descendente sin retroceso Gramáticas LL(1) Conjunto de Símbolos Seguidores sentencia → sent-if | otra sent-if → if (exp) sentencia parte-else parte-else → else sentencia | λ exp → 0 | 1 SEGUIDORES (sentencia) = {$, else} SEGUIDORES (sent-if) = {$, else} SEGUIDORES (parte-else) = {$, else} SEGUIDORES (exp) = {)} exp → term exp´ exp´ → opsuma term exp´ | λ opsuma → + | - term → factor term´ term´ → opmult factor term´ | λ opmult → * factor → ( exp ) | numero SEGUIDORES (exp) = {$, )} SEGUIDORES (exp´) = {$, )} SEGUIDORES (opsuma) = {(, numero} SEGUIDORES (term) = {$, ), +, -} SEGUIDORES (term´) = {$, ), +, -} SEGUIDORES (opmult) = {(, numero} SEGUIDORES (factor) = {$, ), +,-,*} Página 27

Ejemplos:<br />

Análisis <strong><strong>sin</strong>táctico</strong> <strong>descendente</strong> <strong>sin</strong> <strong>retroceso</strong><br />

Gramáticas LL(1)<br />

Conjunto de Símbolos Seguidores<br />

sentencia → sent-if | otra<br />

sent-if → if (exp) sentencia parte-else<br />

parte-else → else sentencia | λ<br />

exp → 0 | 1 SEGUIDORES (sentencia) = {$, else}<br />

SEGUIDORES (sent-if) = {$, else}<br />

SEGUIDORES (parte-else) = {$, else}<br />

SEGUIDORES (exp) = {)}<br />

exp → term exp´<br />

exp´ → opsuma term exp´ | λ<br />

opsuma → + | -<br />

term → factor term´<br />

term´ → opmult factor term´ | λ<br />

opmult → *<br />

factor → ( exp ) | numero<br />

SEGUIDORES (exp) = {$, )}<br />

SEGUIDORES (exp´) = {$, )}<br />

SEGUIDORES (opsuma) = {(, numero}<br />

SEGUIDORES (term) = {$, ), +, -}<br />

SEGUIDORES (term´) = {$, ), +, -}<br />

SEGUIDORES (opmult) = {(, numero}<br />

SEGUIDORES (factor) = {$, ), +,-,*}<br />

Página 27

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

Saved successfully!

Ooh no, something went wrong!