^args) { String^s; int n,m; Console::WriteLine("Enter n="); s=Console::ReadLine(); n=Convert::ToInt32(s); Console::WriteLine("Enter m=");">
This presentation is the property of its rightful owner.
Sponsored Links
1 / 157

Перемноження матриць PowerPoint PPT Presentation


  • 64 Views
  • Uploaded on
  • Presentation posted in: General

Перемноження матриць. #include "stdafx.h" using namespace System; using namespace System::IO; int main(array<System::String ^> ^args) { String^s; int n,m; Console::WriteLine("Enter n="); s=Console::ReadLine(); n=Convert::ToInt32(s); Console::WriteLine("Enter m=");

Download Presentation

Перемноження матриць

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


6237318

#include "stdafx.h"

using namespace System;

using namespace System::IO;

int main(array<System::String ^> ^args)

{

String^s;

int n,m;

Console::WriteLine("Enter n=");

s=Console::ReadLine();

n=Convert::ToInt32(s);

Console::WriteLine("Enter m=");

s=Console::ReadLine();

m=Convert::ToInt32(s);


6237318

array<double,2>^x=gcnew array<double,2>(n,m);

array<double,2>^y=gcnew array<double,2>(m,n);

array<double,2>^c=gcnew array<double,2>(n,n);

StreamReader^sr=gcnew StreamReader("D:\\AVRPROG\\VISUAL\\TestFile20");

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

{

s=sr->ReadLine();

x[i,j]=Convert::ToDouble(s);

Console::WriteLine("x={0}",x[i,j]);

}

for(int i=0;i<m;i++)

for(int j=0;j<n;j++)

{

s=sr->ReadLine();

y[i,j]=Convert::ToDouble(s);

Console::WriteLine("y={0}",y[i,j]);

}


6237318

//sr->Close();

StreamWriter^sw=gcnew StreamWriter("D:\\AVRPROG\\VISUAL\\TestFile21.txt");

sw->AutoFlush::set(true);

for(int i=0;i<n;i++)

for(int j=0;j<n;j++)

{

c[i,j]=0;

for(int k=0;k<m;k++)

c[i,j]+=x[i,k]*y[k,j];

Console::WriteLine("c={0}",c[i,j]);

if(j%n==0)

sw->Write("\n");

sw->Write(" c[{0},{1}]={2} ",i,j,c[i,j]);

}

Console::WriteLine(L"Finish");

return 0;

}


Testfile20

TestFile20

  • 1

  • 2,5

  • 3

  • 4

  • 5

  • 6,7

  • 8

  • 10

  • 20

  • 30

  • 40

  • 50

  • 60

  • 70

  • 80


6237318


6237318

  • I , . .

  • ()- I.

  • I ().


6237318

xn- x n .

xR - x .

XY X Y.

X* - x .

X+- x .


6237318

| X | - .

{ } e .

[X] .


6237318

  • { , * | } I.

    I U { , * | } . .

    G=( T, N, P, S)

    T, N - .


6237318

P - .

S - .

intx,y,z;

DVARB - >intliden( , iden)* ;

PROG->(DVARB|DCONST|DFUNC)*eof


6237318

G=(T, N, P, S)

T={x, y, w, z}

N={ S, A, B }

P={A->AB, A ->x, A ->y, B->w, B->z}

L(G)={xw, yw, xz, yz}


6237318

A i - > r i, A i N

r i T U N.

A1 .

S - >AB

A - >x|y

B - > w|z


6237318

T = { , , , , , , }

N = {, , , }

- > *

- >|

- > |

- > |


6237318

. , , . :

[ [ x ] ]

G=(T,N,P,S

T={ [ , ], x, +} N={A,B}

P={A->x, A->[B], B->A, B->B+A}

LA(1) . .

A > [B] > [A] > [[B]] > [[A]] > [[x]]


6237318

: .


6237318

1|2|3|


6237318

1 2 3


6237318

*


6237318

  • 1) .

  • 2) .

  • , , , . .


6237318

  • , , , , . , X, .

  • W, .


6237318

  • , () .

  • , , . .

  • , .

  • . .


6237318


6237318

  • . :

  • ;

  • ;

  • ;

  • ;

  • ;

  • .


6237318

  • . , (, , , . .).

  • .

  • .

  • .


6237318

SPL

:

1) : A Z, a z

2) 0 9

3) + - * / % ( ) , ; = \n \t

, . 40 .

\n , \t .

.


6237318

  • : .

    :begin, end, read, print, return, if, then,do, while, int, const 11 .

    :

    ( )

    begin

    end


6237318

  • :

  • const a=12, b=4, d=- 5, s=0;

  • :

  • int x, y, z, teta ;

  • . end .

  • main()

  • .

  • return .

  • .


6237318

if

ifthen

end;

_1;

, then, ( ), , if ...


6237318

while

whiledo_

end;

1;

...

, do, . ( ), , .


A b b 0

ab b0


6237318

SPL, char TNM[400];

.


6237318

  • . ASCII. ( enum).

  • enum{BEGINL=257, ENDL, READL, PRITL, RETRL, IFL, THENL, WHILEL, DOL, CONSTL, INTL, IDEN, NUMB};

  • stdio.h

  • #define EOF -1


6237318

#include<stdio.h>

#include<stdlib.h>

#include<ctype.h>

#include<conio.h>

#include<alloc.h>

#include<string.h>

/* SPL*/

enum { BEGINL=257, ENDL, IFL, THENL,

WHILEL, DOL, RETRL, READL,

PRITL, INTL, CONSTL, IDEN, NUMB };


6237318

int nst=0; // SPL

int lex;// ( )

int lval; // ( , char TNM[400])

char nch='\n'; // , SPL

FILE*PF,*padres;// SPL

void get(void);

void number(void);

void word(void);

char*add(char*nm);


6237318

void main( int ac,char*av[ ] )

{

clrscr( );

if(!ac)

{

puts( ");

exit(1);

}

PF=fopen(av[1],"r");

padres=fopen("getrez.dan","w");

if(!PF)

puts(" ");

else

get( );//

}


6237318

void get()

{

while(nch!=EOF)

{

while(isspace(nch))

{

if( nch= = '\n )

nst++;

nch = getc(PF);

}


6237318

If ( isdigit ( nch ) )

number( );

else

if( isalpha ( nch ) )

word();

else

if(nch= ='( || nch= =') || nch= =', || nch= = '; ||nch== ='

||nch= ='+ ||nch= ='- ||nch= ='* || nch=='/ || nch= =%)

{

lex=nch;

nch=getc(PF);

}

}

if(nch= =EOF)

lex=EOF;

else

puts("H");

return;

}


6237318

void number()

{

for( lval=0; isdigit( nch ); nch= getc(PF))

lval=lval*10+nch - '0';

lex= NUMB;

return;

}


6237318

void word( )

{

int cdl [ ]={BEGINL,ENDL,IFL,THENL,WHILEL,DOL,

RETRL,READL,PRITL,INTL,CONSTL,IDEN,NUMB};

char*serv [ ]={"begin", "end", "if", "then, "while",

do", "return", read", "print", "int", "const };

int i;

char tx[40];

char*p;

for(p=tx; isdigit(nch) || isalpha(nch); nch=getc(PF))

*( p++ ) = nch;

*p='\0';


6237318

for( i=0; i<11; i++)

if( strcmp ( tx, serv [ i ] ) == 0)

{

lex=cdl [ i ];

return;

}

lex=IDEN;

lval= (int) add ( tx );

printf(" %s =%p\n",tx,lval);

fprintf(padres," %s =%p\n",tx,lval);

return;

}


6237318

char TNM[400];// char*ptn=TNM; // TNM[400 ]

//*******************************************

char*add(char*nm)

{

char*p;

for(p=TNM;p<ptn;p+=strlen(p)+1)

if(strcmp(p,nm)==0)

return p;

if((ptn+=strlen(nm)+1)>TNM+400)

{

puts(" ");

exit( 1 );

}

return ( strcpy ( p, nm ) );

}


6237318

SPL

  • .

  • :

  • PROG, DFUNC, DCONST, DVARB, CONS, PARAM, BODY, STML, STAT, EXPR, TERM, FACT, FCTL.


6237318

PROG - >(DCONST |DVARB|DFUNC )* eof

DCONST -> constl CONS (,CONS) * ;

CONS - >iden=[+|-]numb

DVARB -> intl iden(,iden)*;

DFUNC -> iden PARAM BODY

PARAM -> ( [ iden(,iden)* ] )

BODY->beginl(DVARB|DCONST)*STMLendl

STML - > STAT(;STAT)*


6237318

STAT- >iden=EXPR|

readliden|

pritlEXPR|

retrlEXPR|

iflEXPRthenlSTMLendl|whilelEXPRdolSTMLendl

//*************************************************

EXPR- >[+|-]TERM((+|-)TERM)*


6237318

TERM - > FACT((*|/|%)FACT)*

FACT- > (EXPR)|numb|iden[([FCTL])]

FCTL - > EXPR(,EXPR)*


6237318


6237318

void exam (int lx)

{

if (lex!=lx)

{

printf (

lex=%i lx=%i nst=%i \n, lex, lx, nst );

exit (1);

}

get ( );

return;

}


6237318

while (nch!=EOF)

{

}

if (nch = = EOF)

{

lex = EOF;

return;

}


6237318

PROG

PROG - > (DCONST |DVARB| DFUNC )* eof


6237318

void prog( )

{

while (lex!=EOF)

{

switch (lex)

{

case IDEN: dfunc( ); break;

case INTL: dvarb( ); break;

case CONSTL: dconst( ); break;

default:

printf( nst=%i lex=%i \n, nst, lex);

}

}

return;

}


6237318

DCONST -> constl CONS (,CONS) * ;


6237318

void dconst( )

{

//

// get( );

do

{

get( );

cons( );

} while (lex = = ,);

exam (;);

return;

}


6237318

CONS - >iden=[+|-]numb


6237318

//

void cons( )

{

exam (IDEN);

exam (=);

if (lex = = + || lex = = -)

get( );

exam (NUMB);

return;

}


6237318

DVARB - > intl iden(,iden)*;


6237318

void dvarb( )

{

do

{

get( );

exam(IDEN);

} while(lex = = ,);

exam(;);

return;

}


6237318

DFUNC - > iden PARAM BODY


6237318

void dfunc( )

{

get( );

param( );

body( );

return;

}


6237318

PARAM - >( [ iden(,iden)* ] )


6237318

void param( )

{

exam (();

if (lex ! = ) )

{

exam (IDEN);

while (lex = = ,)

{

get( );

exam (IDEN);

}

}

exam ());

return;

}


6237318

BODY->beginl(DVARB|DCONST)*STMLendl


6237318

void body( )

{

exam (BEGINL);

while(lex = = INTL || lex = = CONSTL)

if (lex = = INTL) dvarb( );

else

dconst( );

stml( );

exam(ENDL);

return;

}


6237318

STML - >STAT(;STAT)*


6237318

void stml( )

{

stat( );

while (lex = = ;)

{

get( );

stat( );

}

return;

}


6237318

STAT -> iden=EXPR|

readliden|

pritlEXPR|

retrlEXPR|

iflEXPRthenlSTMLendl|

whilelEXPRdolSTMLendl


6237318

void stat( )

{

switch (lex)

{

case IDEN: get( ); exam (=); expr( ); break;

case READL: get( ); exam (IDEN); break;

case PRITL: get( ); expr( ); break;

case RETRL: get( ); expr( ); break;

case IFL: get( ); expr( ); exam(THENL); stml( ); exam(ENDL); break;

case WHILEL: get( ); expr( ); exam(DOL); stml( ); exam(ENDL); break;

default:

printf(. stat nst=%i \n, nst);

}

return;

}


6237318

EXPR - > [+|-]TERM((+|-)TERM)*


6237318

void expr( )

{

if (lex = = + || lex = = -)

get( );

term( );

while (lex = = + || lex = = -)

{

get( );

term( );

}

return;

}


6237318

TERM - > FACT((*|/|%)FACT)*


6237318

void term()

{

fact();

while(lex=='*'|| lex == '/'||lex=='%')

{

get();

fact();

}

return;

}


6237318

FACT - >(EXPR)|numb|iden[([FCTL])]


6237318

void fact( )

{

switch(lex)

{

case '(': get(); expr(); exam(')'); break;

case IDEN: get(); if ( lex=='( )

{

get();

if ( lex != ') ) fctl( );

exam ( ') );

}

break;

case NUMB: get ( ); break;

default: puts( FACT");

}

return; }


6237318

FCTL - > EXPR(,EXPR)*


6237318

void fctl()

{

expr();

while(lex==',')

{

get();

expr();

}

return;

}


6237318

SPL , .

typedef struct

{

int cod; // ( )

int opd; // ( )

} cmd;

cmd TCD[300]; //

int tc=0; //


Int st 500

int st [ 500 ]

1) st[0], st[1],..st[n] .

int cgv = 0;

2) - - main().

3)

- main().

4) () ( main() -2 )


6237318

5) ()

( main() -1 )

6) main().

1) - -, , p0().

2)

- p0().

3) p0().

4) () p0().


6237318

sp.

5) sp p0().

t

k= 0,1,2,cgv. st[k].

st[sp+k].

k=1,2,3,clv.

k=- ( n+2 ),.-3

n .


6237318

f ( x , y , z )

begin

int a,b;

..

..

end

st[sp-5] x

st[sp-4] y

st[sp-3] z

st[sp+1] a

st[sp+2] b


6237318

1) char TNM [ 400] - .

2) cmd TCD [300] - . .

3) typedef struct

{

char * name;//

int what;//1- const, 2- . 3- .

int val; //. const k

} odc;

odc TOB[100]; //

odc*pto =TOB; odc*ptol=TOB;// . i

int out=1; // out =1 . out=0 .


6237318

4)typedef struct

{

char* name;//

int isd;// (1) (0)

int cpt;//

int start;// .

}fnd;

fnd TFN[30];//

fnd* ptf =TFN;// TFN[ ].


6237318

SPL

  • enum { OPR, LIT, LDE, LDI, STE, STI, CAL, INI, JMP, JMC };

  • OPR 1 stdin ;

  • OPR 2 - stdout ;

    OPR 3,4,5,6,7 +, -, *, /, %

    t-1, t . - t .


6237318

  • OPR 8 ;

  • OPR 9 , , ( return);

  • OPR 10 .

  • LIT a const a t (load into t);

  • LDE a t a (load exetrnal to st[a]) ;


6237318

  • LDI a - t a (load internal to st [sp + a]) ;

  • STE a , a (set external to st [a]);

  • STI a , a (set internal to st [sp + a] );


6237318

CAL a a cmdTCD[300];

INI a ( );

JMP a ;

JMC a ,

t 0. t!


6237318

SPL-

  • , a+b

  • <a><b>+

  • void push(int a)

  • int gen(int co,int op)


6237318

void push(int a)

{

If ( t >= 499 )

{

puts(" st");

exit(0);

}

st[+ + t ] = a;

return;

}


Cmd tcd 300

cmd TCD[300]

int gen(int co,int op)

{

if( tc >= 300)

{

puts(" TCD");

exit(1);

}

TCD[tc].cod=co;

TCD[tc].opd=op;

return tc++;// ++

}


6237318

1) val:

{ LIT val } SPL;

gen(LIT, val); - TCD[300];

push ( val ); - , .

2) { LDE a }

gen ( LDE a );

push ( st [ a ] ); st [a] .


6237318

  • 3) { LDI a }

    gen ( LDI,a );

    push ( st [ sp+a] ); st [ sp+a] t.

    4) read e; - SPL

    { OPR 1} { STE a} ;

    { OPR 1} { STI a} .


6237318

5) print e; SPL

<e> { OPR 2}

6) return e;

<e> { OPR 9}

7) e = - e;

<e> { OPR 8}

8) e1 op e2

<e1 ><e2> { OPRop}, op= 3, 4, 5, 6, 7

+ - * / %.


6237318

9) f (e1 , e2 , .. en ) , TCD

<e1><e2>.<en> { LIT n } { CAL a}

10)

F ( p1, p2 , .. pm )

begin

S

end

a : { INI m} < S > { OPR 10}


6237318

  • if e then s end

    < e > { JMC k } <s> k , k - s.


6237318

12) while e do s end

lb : <e> { JMC k} <s> {JMP lb} k


6237318

main ( x, y )

begin

int c;

read c;

c = x y / c ;

if c then return c

end


6237318

  • :

    body(); stat(); expr(); term(); fact();

  • :

    int cgv=0;// .

    int clv=0;//

    int tc=0;// .

    int out=1;// (1) (0)


Cmd tcd 3001

cmd TCD[300]

int gen ( int co,int op)

{

if( tc >= 300)

{

puts(" TCD");

exit(1);

}

TCD[tc].cod=co;

TCD[tc].opd=op;

return tc++;

}


6237318

int body()

{

int st;// TCD[]

exam(BEGINL); clv=0;

while(lex==CONSTL || lex==INTL)

if( lex==CONSTL) dconst();

else dvarb(); // clv

st=gen(INI,clv);

stml();

exam(ENDL);

gen(OPR,10);

return st;//

}


Nm tob

nm TOB[ ]

odc*findob(char*nm)

{

odc*p;

for(p=pto-1;p>=TOB; p--)

if(strcmp(nm,p->name)==0)

return p;

printf(" %s \n, nm );

return p;

}


6237318

void stat ()

{

odc*p;

int t1, t2;

switch(lex)

{

case IFL: get(); expr(); exam(THENL); t1=gen(JMC,0);

stml(); exam(ENDL); TCD[t1].opd=tc; break;

case WHILEL: get(); t1=tc; expr( ); exam (DOL); t2=gen(JMC,0);stml();gen(JMP,t1);TCD[t2].opd=tc;exam(ENDL);break;

case RETRL:get();expr();gen(OPR,9);break; case PRITL:get();expr();gen(OPR,2);break;


6237318

case READL: get( ); p = findob ( (char*) lval ); gen(OPR,1);

if(p->what==1) puts("lval ");

gen(p->what==2?STE:STI,p->val);

exam(IDEN);break;

case IDEN:p=findob((char*)lval);get();exam('=');expr();

if(p->what==1) puts("p->name ");

gen(p->what==2?STE:STI,p->val);

break;

default:

printf( stat()nst=%i lex=%i \n, nst, lex);

}

return;}


6237318

void expr()

{

int neg=( lex== '- );

If ( lex=='+ || lex=='- ) get();

term();

If ( neg ) gen(OPR,8);

while(lex=='+ || lex=='-')

{

neg = lex == '- ? 4 : 3;

get();

term(); gen(OPR,neg);

}

return;

}


6237318

void term()

{

int op;

fact();

while( lex== '* || lex == '/ || lex == '% )

{

op= lex=='*'? 5: lex== '/ ? 6: 7;

get();

fact();

gen(OPR,op);

}

return;

}


6237318

void fact()

{

char*nm; int cp; odc*p; fnd*pl;

switch(lex)

{

case IDEN: nm= (char*) lval; get();

if ( lex=='( )

{

get(); cp= ( lex==') ? 0: fctl ( ) ); exam( ') );

pl=eval (nm, cp); gen (LIT, cp);

cp= gen (CAL, pl->start);

if( !pl-> isd ) pl->start=cp;

}


6237318

else

{

p= findob (nm);

gen (p->what==1?LIT: (p->what==2?LDE:LDI),

p->val);

}

break;

case '(': get (); expr (); exam ( ') ); break;

case NUMB: gen( LIT, lval ); get (); break;

default:

printf( Errorinfact. nst=%i lex=%i\n,nst,lex);

}

return;

}


6237318

int fctl()

{

int cf =1; // 1-

expr();

while(lex==',')

{

get();

expr();

cf++;

}

return cf; //

}


6237318

void newob (char*name, int wt, int vl );

name ;

wt : 1- const, 2- . 3- .

vl - . const k .

:cons(); dvarb(); param();

get()

exam(IDEN); exam(NUMB);


6237318

void newob(char*nm,int wt,int vl)

{

odc* pe, *p;

pe = out ? TOB: ptol;

for ( p = pto-1; p> =pe; p-- )

{

if(strcmp (nm, p->name )==0 )

{

puts(""); exit(0);

}

}

if(pto>=TOB+100){puts(" TOB");exit(0);}

pto->name=nm;pto->what=wt;pto->val=vl;pto++; // ++

return;}


6237318

void cons()

{

char*nm= (char*)lval; int s;

exam(IDEN);

exam('=');

s=( lex=='-') ? -1 : 1;

if( lex=='+ || lex== '- )

get();

newob(nm,1,s*lval);puts("");

exam(NUMB);

return;

}


6237318

void dvarb()

{

do

{

get();

newob((char*)lval,(out?2:3), (out ? cgv++ : ++clv));

exam(IDEN);

}while(lex==',');

exam(';');

return;

}


6237318

void dfunc()

{

int cp,st;char*nm=(char*)lval;

get();

out=0;

cp=param ();

st=body();

out=1;

pto=ptol;

defin (nm, cp, st);

return;

}


6237318

int param(){

odc*p;int cp=0;

exam( '( );

if(lex!=))

{

newob((char*)lval,3,++cp);

exam(IDEN);

while(lex==',)

{

get();

newob((char*)lval,3,++cp);

exam(IDEN);

}}

exam());

for(p=ptol;p<pto;p++)

p->val- =cp+3;

return cp;

}


6237318

ptol, ( ), pto (cp+3) :

- (n+2) , . -3, -2 , -1 , 0

st[ sp -2 ] - ;

st[ sp -1 ] - ;

st[ sp] - - .


N ewfn tfn

newfn()- TFN

fnd*newfn(char*nm,int df,int cp,int ps)

{

if(ptf>=TFN+30)

{

puts(" TFN");

exit(0);

}

ptf->name=nm;ptf->start=ps;

ptf->isd=df;ptf->cpt=cp;

return ptf++;

}


6237318

/*findfn-nm TFN*/

fnd*findfn(char*nm)

{

fnd*p;

for(p=ptf-1;p>=TFN;p--)

If(strcmp(p->name,nm)==0)

return p;

return NULL;

}


6237318

/*eval()-nmcp*/

fnd*eval ( char*nm, int cp)

{

fnd*p;

if( !(p=findfn (nm))) return newfn(nm,0,cp,-1);

if(p->cpt==cp) return p;

printf(" %s , nm);exit(1);

return NULL;

}


6237318

/*defin()- nm; cp-,

ad-*/

void defin (char*nm,int cp,int ad)

{

fnd*p;

int c1,c2;

p=findfn(nm);

if(p)

{

if(p->isd)

{

printf(%s o\n, nm);

exit(1);

}


6237318

if(p->cpt!=cp)

{

printf( . %s \n, nm);

exit(1);

}

p->isd=1;

for(c1=p->start; c1!=-1; c1=c2 )

{

2=TCD[c1].opd;

TCD[c1].opd=ad;

}

p->start=ad;

} // if (p)

else newfn(nm,1,cp,ad);

return;

}


6237318

/*fmain()- main */

fnd*fmain()

{

static char nm[]="main;

fnd*pm=NULL;

fnd*p;

for(p=ptf1;p>=TFN;p--)

{

if( !p - > isd )

{

puts(" p->name");

exit(0);

}

if(strcmp(nm,p->name)==0)pm=p;

}

if(pm) return pm;

puts(" main");

return}


6237318

void prog()

{

fnd*p;

while(lex!=EOF)

{

switch(lex)

{

case CONSTL:dconst();break;

case INTL:dvarb();break;

case IDEN:dfunc();break;

default:puts("");

}

}

p=fmain();

adrnm=p->start; cpnm=p->cpt;

return;

}


6237318

/* stdin*/

red()

{

int v,c;

do

{

puts("");

fflush(stdin);

c=getchar();

}while(isspace(c));

if(!Isdigit(c))

puts( ");

for(v=0;isdigit(c);c=getchar())

v=v*10+c-'0';

ungetc(c,stdin);

return v;

}


6237318

void interp()

{

int i;

t=-1;

printf("SPL:");

for(i=0;i<cgv;i++)

push(0);

if(cpnm)

{

printf("%d>",cpnm);

fflush(stdin);

for(i=0;i<cpnm;i++)

push(red( ));

}


6237318

push(cpnm);

push(-2);

push(-1);

sp=t;

p=adrnm; // .

do

{

comman();

p++;

} while (p>=0);

if( p== -1)

printf ("st [%d] = %d \n ", t, st[ t ] );

}


6237318

/* */

comman()

{

int a=TCD[p].opd;

switch(TCD[p].cod)

{

case OPR:operat(a);break;

case LIT:push(a);break;

case LDE:push(st[a]);break;

case LDI:push(st[sp+a]);break;

case STE:st[a]=st[t--];break;

case STI:st[sp+a]=st[t--];break;

case CAL:push(p);push(sp);sp=t;p=a-1;break;


6237318

case INI:

{

int i;

for(i=0;i<a;i++)

push(0);

}

break;

case JMP:p=a-1;break;

case JMC:if(st[t--]<=0)p=a-1;

}

return;

}


6237318

/*operat- a */

void operat(int a)

{

int j=t-1;

switch(a)

{

case 1:printf("1>);

fflush(stdout);

push(red( ) );break;

case 2: printf ( %d \n ", st[ t - - ]); break;

case 3: st [ j ] + = st [ t - - ]; break;

case 4: st [ j ] - = st [ t - - ]; break;

case 5: st [ j ] * = st [ t - - ]; break;


6237318

case 6: if (st [t]==0)

puts( /: = 0 );

st [ j ] / = st [ t - - ]; break;

case 7: if (st [ t ] <=0 )

puts("%%: =0");

st [ j ] % = st [ t - - ]; break;

case 8: st [ t ] = - st [ t ]; break;

case 9: j = st [sp-2]; st [sp- j - 2]= st[t];

t = sp- j- 2; p=st [sp - 1]; sp= st [ sp ]; break;

case 10:p=-3;

}

return;

}


6237318

- SPL,


6237318

exp(a,b)

begin int z;

z=1;

while b do

if b%2 then z=z*a end;

a=a*a;b=b/2

end;

return z

end

main()

begin int x,y,z;

read x;

read y;

print exp(x,y);

z=x ^;

print z;

end


6237318

void get()

{

if(nch==EOF)

{

lex=EOF;

return;

}

while(isspace(nch))

{

if(nch=='\n')

nst++;

nch=getc(PF);

}

if(isdigit(nch))

number();

else


6237318

if(isalpha(nch))

word();

else

if(nch=='('||nch==')'||nch==','||nch==';'||nch=='='

||nch=='+'||nch=='-'||nch=='*'||nch=='/'||nch=='%'||nch=='^')

{

lex=nch;

nch=getc(PF);

}

else

if(nch==EOF)

lex=EOF;

else

puts("H ");

return;

}


6237318

void term()

{

int op;

fact();

while(lex=='*'||lex=='/'||lex=='%'||lex=='^')

{

op=lex=='*'?5:lex=='/'?6:lex=='%'?7:11;

get();

if(op!=11)

fact();

gen(OPR,op);

}

return;

}


6237318

void operat(int a)

{

int j=t-1,kk;

switch(a)

{

case 1:printf("1>");

fflush(stdout);push(red());break;

case 2:printf("%d\n",st[t--]);break;

case 3:st[j]+=st[t--];break;

case 4:st[j]-=st[t--];break;

case 5:st[j]*=st[t--];break;


6237318

case 6:if(st[t]==0) puts("/: =0");

st[j]/=st[t--];break;

case 7:if(st[t]<=0) puts("%%: =0");

st[j]%=st[t--];break;

case 8:st[t]=-st[t];break;

case 9:for(kk=0;kk<25;kk++)

fprintf(ptc,"tc[%i]=%d \n",kk,st[kk]);

j=st[sp-2];st[sp-j-2]=st[t];

t=sp-j-2;p=st[sp-1];sp=st[sp];break;

case 10:p=-3;

case 11:st[t]*=st[t];

}

return;

}


6237318

- SPL, .

, : (increment) .


6237318

exp(a ,b)

z;

z=1;

b

b%2 z=z*a ;

=a*a; b=b/2

main()

x,y;


6237318

x;

y;

exp(x,y);

x^;

x@;


6237318

/* SPL*/

enum{IFL=257,WHILEL,RETRL,PRITL,READL,BEGINL,ENDL,INTL,CONSTL,THENL,DOL,

NUMB,IDEN};

int isalpharus(char c);

int isspace1(char c);

int isdigit1(char c);


6237318

void get()

{

while(lex!=EOF)

{

while(isspace1(nch))

{

if(nch=='\n')

nst++;

nch=getc(PF);

}

if(isdigit1(nch))

number();


6237318

if(isalpharus(nch))

word();

else

if(nch=='('||nch==')'||nch==','||nch==';'||nch=='='

||nch=='+'||nch=='-'||nch=='*'||nch=='/'||nch=='%'|| nch=='^'|| nch=='@')

{

lex=nch;

nch=getc(PF);

}

else

if(nch==EOF)

lex=EOF;

else

printf("H nch=%c nst=%i\n",nch,nst);

return;

}


6237318

void word()

{

static char*serv[]={"","","","",

"","","","","",

"",""};

static int cdl[]={IFL,WHILEL,RETRL,PRITL,READL,BEGINL,

ENDL,INTL, CONSTL,THENL,DOL};

int i;

char tx[40];

char*p;

for(p=tx;isdigit1(nch)||isalpharus(nch);nch=getc(PF))

*(p++)=nch;

*p='\0';


6237318

int isalpharus(char c)

{

int v;

if(isalpha(c)||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''

||c==''||c==''||c==''||c==''||c==''||c==''||c==''||c==''

||c==''||c==''||c==''||c==''||c==''||c==''

||c==''||c==''||c==''||c==''||c=='')

v=8;

else

v=0;

return v;

}


6237318

int isspace1(char c)

{

int v;

if(c== \ ||c== \n ||c=='\ t ||c== \f ')

v=1;

else

v=0;

return v;

}


6237318

int isdigit1(char c)

{

int v;

if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9')

v=2;

else

v=0;

return v;

}


6237318

void term()

{

int op;

fact();

while(lex=='*'||lex=='/'||lex=='%'||lex=='^'||lex=='@')

{

op=lex=='*'?5:lex=='/'?6:lex=='%'?7:lex=='^'?11:12;

get();

if(op!=11 && op!=12)

{

fact();

}

gen(OPR,op);

}

return;

}


6237318

void operat(int a)

{

int j=t-1;

switch(a)

{

case 1:printf("1>");

fflush(stdout);push(red());break;

case 2:printf("%d\n",st[t--]);break;

case 3:st[j]+=st[t--];break;

case 4:st[j]-=st[t--];break;

case 5:st[j]*=st[t--];break;

case 6:if(st[t]==0) puts("/: =0");

st[j]/=st[t--];break;

case 7:if(st[t]<=0) puts("%%: =0");

st[j]%=st[t--];break;


6237318

case 8:st[t]=-st[t];break;

case 9:j=st[sp-2];st[sp-j-2]=st[t];

t=sp-j-2;p=st[sp-1];sp=st[sp];break;

case 10:p=-3;

case 11: st[t] *= st[t]; break;

case 12: st[t] += 2; break;

}

return;

}


6237318


  • Login