analisador sintatico
Implementação em C
#include
#include
typedef struct
{
int COD; char VALOR[50];
} TOKEN; int delta (int q, char ch)
{
int M[19][15] =
{ { 12, 13, 14, 15,
1, -2, -2,
4, 10,
7, 10, 10, 10,
0, -2 },
{ -1, -1, -1, -1,
1, -1,
2, -1, -1, -1, -1, -1, -1, -1, -2 },
{ -3, -3, -3, -3,
3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3 },
{ -1, -1, -1, -1,
3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10,
5, 10, 10, 10, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10,
6, 10, 10, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10, 10, 10, 10, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10, 10,
8, 10, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10, 10, 10,
9, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10, 10, 10, 10, 10, -1, -2 },
{ -1, -1, -1, -1, 10, 11, -1, 10, 10, 10, 10, 10, 10, -1, -2 },
{ -3, -3, -3, -3, 10, -3, -3, 10, 10, 10, 10, 10, 10, -3, -3 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2 },
{
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0 },
{
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0 },
{
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0 }
};
switch (ch)
{
case '+' : return M[q][0]; break; case '-' : return M[q][1]; break; case '*' : return M[q][2]; break; case '/' : return M[q][3]; break; case '_' : return M[q][5]; break; case '.' : return M[q][6]; break; case 'm' : return M[q][7]; break; case 'o' : return M[q][8]; break;
1
Construção de um analisador léxico e um sintático
Implementação em C
case 'd' : return M[q][9]; break; case 'i'