.


:




:

































 

 

 

 


3. . . 8

-

.

 

 

 

1 30.08.2015 .

. ___________ ..

 

3...8

09.03.01

()

( )

 

, 2015

, . , .

. . , , .

, , - .

, .

, . . .

: , , , . .

.

 

1:

1.1

(), , , .

1.2

[1, 2] [3].

1.3

. ,

e:\prg.exe

>2*4-5

, , : .

:

1. ;

2. ;

 

ר

: , .

 

:

1. ;

2. , .

3. .

4. , .

 

:

1. :

2. :

N → aB

B → aB|bB| ε

3. , :

 

a b
N B E
B B B
E E E

 

2.

, .

.

.

.

1. :

tCond .

2. :

EOL .

3. :

ch ;

i () ;

alpha ;

ond tCond ;

Alph ;

Jump tCond .

C

 

#include <stdio.h>

#include <string.h>

 

// :

#define EOL '\0'

 

// :

typedef enum {N=0, B=1, E=2} tCond;

 

int main ()

{

// :

char Alph[] = {'a', 'b'};

 

// :

tCond Jump[sizeof(tCond)][sizeof(Alph)/sizeof(char)] = {

{B, E},

{B, B},

{E, E}

};

 

// :

tCond cond;

 

// :

char alpha[128];

 

// :

char ch;

 

// :

int i = 0;

 

// :

cond = N;

 

// :

printf(" :\n> ");

gets(alpha);

alpha[strlen(alpha)] = EOL;

 

while ((ch = alpha[i++])!= EOL && cond!= E)

{

switch (ch) {

case 'a':

cond = Jump[cond][0];

break;

case 'b':

cond = Jump[cond][1];

break;

default:

cond = E;

}

}

 

if(cond == B)

printf("\n \n");

else

printf("\n \n");

 

return 0;

}

C#

 

using System;
using System.Collections.Generic;
using Automatic;

namespace Automatic
{
class FinitAutomat
{
// :
enum tCond {N = 0, B = 1, E = 2};
// , :
static public bool IdLanguage(string alpha)
{
// :
tCond cond = tCond.N;

// :
tCond[,] Jump = new tCond[,] {

{ tCond.B, tCond.E },

{ tCond.B, tCond.B },

{ tCond.E, tCond.E }

};

// :
char[] liters = new char[] { 'a', 'b' };

// :
List<char> Alph = new List<char>(liters);

/*

: */
for (int i = 0; i < alpha.Length && cond!= tCond.E; i++) {
if (Alph.Contains (alpha [i])) { /* -
: */
cond = Jump [(int)cond, Alph.IndexOf (alpha [i])];
} else { //... - :
cond = tCond.E;
}
}

if (cond == tCond.B) // - :
return true;
else //- :
return false;
}
}
}

class Program
{
static void Main()
{
Console.Write (" :\n> ");

if (FinitAutomat.IdLanguage (Console.ReadLine ()))
Console.WriteLine (" !");
else
Console.WriteLine (" !");

}
}

 

: ( ).

0. . , , , .

1. . , , , .

2. . , , , .

3. .

4. .

5. .

6. ( ).

7. .

8. :

1 ⊗ 2,

1 2 ;

⊗ (>, <, =, <>, >=, <=).

9. . 1 () 0 (). AND ( ) OR ( ).

2.

2.1

.

2.2

[1, 2] [3].

2.3

. . : .

:

1. ;

2. ;

 

 

ר

: C.

1

 

 

 

 

 

2

, .

.

, , . .

1. .

2. , , .

1. :

eol , .

2. :

ch ;

i () ;

S .

3. :

NextChar() ;

Pointer() ;

Name() ;

ResetConsole() ;

ResetFile() , , ;

Error() .

C

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

 

char ch;

const char eol='\n';

char S[128];

int i;

 

void NextChar();

void Pointer();

void Name();

void ResetFile();

void ResetConsole();

void Error();

 

int main (int argc, char * const argv[])

{

ResetConsole();

Pointer();

if(ch == eol)

printf("\n !");

else

Error();

return 0;

}

 

void ResetConsole()

{

printf("\n \n> ");

gets(S);

i=0;

NextChar();

}

 

void NextChar()

{

if(i < strlen(S))

ch=S[i];

else

ch=eol;

i++;

}

 

void Pointer()

{

if(ch == '*')

{

NextChar();

Name();

}

else

Error();

}

 

void Error()

{

printf("\n !");

exit(0);

}

 

void Name()

{

if(isalpha(ch)!= 0)

{

while(ch!= eol)

{

if(isdigit(ch)!= 0 || isalpha(ch)!= 0)

NextChar();

else

Error();

}

}

else

Error();

}

using System;
using System.Collections.Generic;
using Automatic;

namespace Automatic
{
public class FinitAutomat
{
// :
enum tCond {N = 0, B = 1, E = 2};
/*
,
: */
static public bool IdLanguage(string alpha)
{
// :
tCond cond = tCond.N;

// :
tCond[,] Jump = new tCond[,] { { tCond.B, tCond.E }, { tCond.B, tCond.B }, { tCond.E, tCond.E } };

// :
char[] leters = new char[] { 'a', 'b' };

// :
List<char> Alph = new List<char>(leters);

// :
for (int i = 0; i < alpha.Length && cond!= tCond.E; i++) {
if (Alph.Contains (alpha [i])) { /* -
: */
cond = Jump [(int)cond, Alph.IndexOf (alpha [i])];
} else { //... - :
cond = tCond.E;
}
}

if (cond == tCond.B) // - :
return true;
else //- :
return false;
}
}

C#:
public class SintaxPointAnalizator
{
// :
string alpha;
// :
const char eol = '\0';
//:
int i;
// :
char ch;

//:
public SintaxPointAnalizator(string Alpha)
{
alpha = Alpha;
}

/* ,
: */
public bool PointLanguage()
{
i = 0;
NextChar ();

if (Pointer () && ch == eol)
return true;
else
return false;
}

// :
void NextChar()
{
if (i < alpha.Length)
ch = alpha [i];
else
ch = eol;
i++;
}

// :
bool Pointer()
{
if (ch == '*') {
NextChar ();
if (Name ())
return true;
else
return false;
} else
return false;
}

// :
bool Name()
{
if (char.IsLetter (ch)) {
while (ch!= eol) {
if (char.IsLetterOrDigit (ch))
NextChar ();
else
return false;
}
} else
return false;

return true;
}
}
}

class Program
{
static void Main()
{
Console.Write (" :\n> ");
string str = Console.ReadLine ();

if (FinitAutomat.IdLanguage (str))
Console.WriteLine (" - !");
else if ((new SintaxPointAnalizator (str)).PointLanguage ())
Console.WriteLine (" - !");
else
Console.WriteLine (" !");
}
}

 

 

0. , . .

1. .

2. .

3. .

4. .

5. .

6. .

7. .

8. .

9. ( ).

 

)

1. .. - : - 230100.62 . : , 2013. 52 .

2. .., .. . .: , 2011. 496 .

3. , .. Java: - : . : , 2011. 400 .

 

)

4. .. / .. . .: , 2007. 630 .

5. / .. . .: , 2010. 400 .

6. . : . / , .., , .., , .., , .. .: , 2010. 240 .

 



<== | ==>
, , , . | , ,
:


: 2017-04-15; !; : 303 |


:

:

, , .
==> ...

1870 - | 1505 -


© 2015-2024 lektsii.org - -

: 0.105 .