, , :
- : +, -, *, / ;
- : >=, ++, --, ;
- : >>=, <<=, .
:
- ;
- ;
- ;
- ;
. , . ,
L0 = { +, -, /, *, .}
: , , . ³, , , .
. , (), , . 1.
:
- Q={q0, q1, q2, q3, q4, q5, .., q17};
- S={0,1,..9, A, B,..F, a, b,..f, X, x, L, l, U, u};
- q0;
- F= Q\{ q0, q12};
- d .
, , :
- : , (qi, aj), ;
- : .
(qi, aj):
, . 1.
#include <stdio.h>
#define OK 1
#define ERROR 0
char alphabet[ ]="0123456789ABCDEFabcdefXxLlUu"; // - 28
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, a, b, c, d, e, f, X, x, L, l U, u
int sigma[ ][ ]= {
{6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // q0=1
|
|
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 5, 5 }, // q1=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, 4, 4 }, // q2=3
{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 }, // q3=4
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0 }, // q4=5
{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 }, // q5=6
{8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13, 0, 0, 0, 0 }, // q6=7
{8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 11, 11 }, //q7=8
{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, 10, 10 }, //q8=9
{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 }, //q9=10
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 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 }, //q11=12
{14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,0,0,0,0,0,0} //q12=13 {14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,0,0,17,17,15,15},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,16, 16, 0, 0}, //q14=15
{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 }, //q15=16
{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, 18, 18 }, //q16=17
{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 } //q17=18
};
// (qi,aj)-, M(qi,aj)=0
int finish[ ]={1,2,4,5,7,8,9,10,11,12,13,14,15,16,17,0}; //
//, alphabet
int index_litera (int litera)
{ for(int i=0; *(alphabet+i);i++)
if (litera = = *(alphabet+i)) return i;
return -1; // :
}
is_final (int row)
{ for (int i = 0; *(finish+i); i++) if (*(finish+i) == row) return 1;
return 0;
)
char text[80];
int * MASSIVE(sigma, row, column)
{ if (row == 0) return NULL else return (sigma+(row-1)*28+colomn); }
int automat (FILE*fp)
{int row, c, column, id=0; //row-' , column - '
*(text+id++)=0; row=0; //
while((c=fgetch(fp))!=EOF) {
if ((column = index_litera(c)) = = ERROR) break;
row=*MASSIV(sigma, row, column);
*(text+id++)=c; *(text+id)=0;
if (row = = ERROR) break;
}
// , , .
if (is_final (row)) //
return OK; else retutn ERROR;
}
main(int argc, char* argv[ ])
{FILE*fp; char file_name[80];
REPEAT:
printf(" ' :");
if(scant("%s", file_name) == 0) return 0; //
if(fp = fopen (file_name,"rt") == NULL)
{ printf (" %s .\ n"); goto REPEAT;}
while (! eof (fp))
if (automat(fp) == ERROR) printf (" - %s", text);
else printf ('' -%s", text);
}// main
, , : , \n, \v, \r, \t.. ' sigma, , , automat.
|
|
: alphabet , sigma , finish . ' sigma. , sigma , ERROR. , , (255 ), ' .