Difference between revisions of "Attribute Grammars/Exercise 2: Numbers"

From Wiki**3

< Attribute Grammars
m
Line 1: Line 1:
 
<p><span lang="pt">Considere a seguinte gram&aacute;tica atributiva:</span></p>
 
<p><span lang="pt">Considere a seguinte gram&aacute;tica atributiva:</span></p>
 
<table border="0" cellpadding="3">
 
<table border="0" cellpadding="3">
<tbody>
 
 
<tr>
 
<tr>
 
<td align="right">s</td>
 
<td align="right">s</td>
Line 86: Line 85:
 
<td align="left">&nbsp;</td>
 
<td align="left">&nbsp;</td>
 
</tr>
 
</tr>
</tbody>
 
 
</table>
 
</table>
 
<p><span lang="pt"> <br /> O elemento lexical    <strong>dig</strong> representa um d&iacute;gito de    <strong>0</strong> a    <strong>9</strong>, e o seu atributo    <em>val</em> representa o valor num&eacute;rico correspondente.</span></p>
 
<p><span lang="pt"> <br /> O elemento lexical    <strong>dig</strong> representa um d&iacute;gito de    <strong>0</strong> a    <strong>9</strong>, e o seu atributo    <em>val</em> representa o valor num&eacute;rico correspondente.</span></p>

Revision as of 21:30, 19 April 2009

Considere a seguinte gramática atributiva:

s -> symbol 1 # symbol 2 {  
        s. val = symbol 1. val + symbol 2. val
        symbol 1. x = 1
        symbol 2. x = 1
      }  
symbol 1 -> symbol 2 dig {  
        symbol 2. x = symbol 1. x * 5
        symbol 1.val = symbol 2.val + dig.val * symbol 1.x
      }  
symbol -> dig {  
        symbol.val = dig.val * symbol.x
      }  


O elemento lexical dig representa um dígito de 0 a 9, e o seu atributo val representa o valor numérico correspondente.

  1. Represente a àrvore semântica para a entrada 328#37.
  2. Apresente uma gramática atributiva equivalente que apenas contenha atributos sintetizados.

Solution