1、 A C C Tiny Machine C C T M C C M i n u s(C)T I N Y C 5 B N F A.3 C C Tiny Machine C T MA.1 C 1.else if int return void while2.+-*/=!=;,()/*/3.I D N U M ID=letter letter*NUM=digit digit*letter=a|.|z|A|.|Zdigit=0|.|94.I D N U M 5.C/*.*/()A.2 C C B N F 1.p ro g r a m d e c l a r a t i o n-l i s t2.d e
2、 c l a r a t i o n-l i s t d e c l a r a t i o n-l i s t d e c l a r a t i o n|d e c l a r a t i o n3.d e c l a r a t i o n v a r-d e c l a r a t i o n|f u n-d e c l a r a t i o n4.v a r-d e c l a r a t i o n t y p e-s p e c i f i e r I D;|t y p e-s p e c i f i e r I D N U M;5.t y p e-s p e c i f i
3、e r i n t|v o i d6.f u n-d e c l a r a t i o n t y p e-s p e c i f i e r I D(p a r a m s)|c o m p o u n d-s t m t7.p a r a m s p a r a m s-l i s t|v o i d8.p a r a m-l i s t p a r a m-l i s t,p a r a m|p a r a m9.p a r a m t y p e-s p e c i f i e r I D|t y p e-s p e c i f i e r I D 10.c o m p o u n
4、d-s t m t l o c a l-d e c l a r a t i o ns s t a t e m e n t-l i s t 11.l o c a l-d e c l a r a t i o ns l o c a l-d e c l a r a t i o ns v a r-d e c l a r a t i o n|e m p t y12.s t a t e m e n t-l i s t s t a t e m e n t-l i s t s t a t e m e n t|e m p t y13.s t a t e m e n t e x p re s s i o n-s t
5、 m t|c o m p o u n d-s t m t|s e l e c t i o n-s t m t|i t e r a t i o n-s t m t|re t u r n-s t m t14.e x p re s s i o n-s t m t e x p re s s i o n;|;15.s e l e c t i o n-s t m t i f(e x p re s s i o n)s t a t e m e n t|i f(e x p re s s i o n)s t a t e m e n t e l s e s t a t e m e n t16.i t e r a t
6、 i o n-s t m t w h i l e(e x p re s s i o n)s t a t e m e n t17.re t u r n-s t m t return;|r e t u r n e x p re s s i o n;18.e x p re s s i o n v a r=e x p re s s i o n|s i m p l e-e x p re s s i o n19.v a r I D|I D e x p re s s i o n 20.s i m p l e-e x p re s s i o n a d d i t i v e-e x p re s s i
7、o n r e l o p a d d i t i v e-e x p re s s i o n|a d d i t i v e-e x p re s s i o n21.r e l o p=|=|=|!=22.a d d i t i v e-e x p re s s i o n a d d i t i v e-e x p re s s i o n a d d o p t e r m|t e r m23.a d d o p+|-24.t e r m t e r m m u l o p f a c t o r|f a c t o r25.m u l o p*|/26.f a c t o r(e
8、x p re s s i o n)|v a r|c a l l|N U M27.c a l l I D(a rg s)28.a rg s a rg-l i s t|e m p t y29.a r g-l i s t a rg-list,e x p re s s i o n|e x p re s s i o n1.p ro g r a m d e c l a r a t i o n-l i s t2.d e c l a r a t i o n-l i s t d e c l a r a t i o n-l i s t d e c l a r a t i o n|d e c l a r a t i
9、 o n3.d e c l a r a t i o n v a r-d e c l a r a t i o n|f u n-d e c l a r a t i o n()(C)(b a c k p a t c h i n g)m a i n C(C)4.v a r-d e c l a r a t i o n t y p e-s p e c i f i e r I D;|t y p e-s p e c i f i e r I D NUM;5.t y p e-s p e c i f i e r i n t|v o i d 0 N U M 1 C 3 7 4 i n t v o i d()6.f u
10、 n-d e c l a r a t i o n t y p e-s p e c i f i e r I D(p a r a m s)c o m p o u n d-s t m t7.p a r a m s p a r a m-l i s t|v o i d8.p a r a m-l i s t p a r a m-l i s t,p a r a m|p a r a m9.p a r a m t y p e-s p e c i f i e r I D|t y p e-s p e c i f i e r I D v o i d()v o i d()()()10.c o m p o u n d-s
11、 t m t l o c a l-d e c l a r a t i o ns s t a t e m e n t-l i s t 11.l o c a l-d e c l a r a t i o ns l o c a l-d e c l a r a t i o ns v a r-d e c l a r a t i o n|e m p t y12.s t a t e m e n t-l i s t s t a t e m e n t-l i s t s t a t e m e n t|e m p t y(e m p t y)13.s t a t e m e n t e x p re s s i
12、 o n-s t m t|c o m p o u n d-s t m t|s e l e c t i o n-s t m t|i t e r a t i o n-s t m t|r e t u r n-s t m t14.e x p re s s i o n-s t m t e x p re s s i o n;|;15.s e l e c t i o n-s t m t i f(e x p re s s i o n)s t a t e m e n t|i f(e x p re s s i o n)s t a t e m e n t e l s e s t a t e m e n ti f 0
13、 0 e l s e e l s e i f()16.i t e r a t i o n-s t m t w h i l e(e x p re s s i o n)s t a t e m e n tw h i l e C 0 0 17.r e t u r n-s t m t return;|r e t u r n e x p re s s i o n;v o i d v o i d r e t u r n(m a i n)18.e x p re s s i o n v a r=e x p re s s i o n|s i m p l e-e x p re s s i o n19.v a r I
14、 D|I D e x p re s s i o n()v a r A 3 7 5 v a r()(C)v a r C C C(l-v a l u e)C v a r C C 20.s i m p l e-e x p re s s i o n a d d i t i v e-e x p re s s i o n r e l o p a d d i t i v e-e x p re s s i o n|a d d i t i v e-e x p re s s i o n21.r e l o p=|=|=|!=()t u r e 1 f a l s e 0 22.a d d i t i v e-e
15、x p re s s i o n a d d i t i v e-e x p re s s i o n a d d o p t e r m|t e r m23.a d d o p+|-24.t e r m t e r m m u l o p f a c t o r|f a c t o r25.m u l o p*|/26.f a c t o r(e x p re s s i o n)|v a r|c a l l|N U M N U M ID()27.c a l l I D(a rg s)28.a rg s a rg-l i s t|e m p t y29.a rg-l i s t a rg-l
16、ist,e x p re s s i o n|e x p re s s i o n I D()C C C int input(void).void output(int x).i n p u t()o u t p u t()A.3 C/*A program to perform EuclidsAlgorithm to compute gcd.*/3 7 6 int gcd(int u,int v)if(v=0)return u;else return gcd(v,u-u/v*v);/*u-u/v*v=u mod v*/void main(void)int x;int y;x=input();y
17、=input();o u t p u t(g c d(x,y);1 0/*A program to perform selection sort on a 10element array.*/int x10;int minloc(int a,int low,int high)int i;int x;int k;k=low;x=alow;i=low+1;while(i high)if(ai x)x=ai;k=i;i=i+1;return k;void sort(int a,int low,int high)int i;int k;i=low;while(i high-1)int t;k=minl
18、oc(a,i,high);t=ak;ak=ai;ai=t;i=i+1;void main(void)int i;i=0;while(i 10)xi=input;i=i+1;A 3 7 7sort(x,0,10);i=0;while(i 10)output(xi);i=i+1;A.4 C Tiny Machine 8.7 Tiny Machine 7 C(T I N Y)d M e m 0 C(h e a p)C()f p(current frame pointer)o f p()7(control link)F O()i n i t F O Tiny Machine f p C int f(i
19、nt x,int y)int z;.x y z f 5(x y z)x y z 2 3 4 T I N Y g p T M 0 g p 0 0:LD gp,0(a c)*load gp with maxaddress1:LDA fp,0(g p)*copy gp to fp2:ST ac,0(a c)*clear location 0 p c()c o d e.h/3 7 8 fp c o d e.c e m i t R A b s()2 7 4 2 42:LDC pc,27(*)42:LDA pc,-16(pc)27(42+1)=1 6 1)r e t F O a c()ST ac,retF
20、O(fp)LD pc,retFO(fp)p c f p o f p F O f p f pST ac,frameoffset+initFO(fp)ST ac,frameoffset+initFO-1(fp)ST fp,frameoffset+ofpFO(fp)*store current fpLDA fp,frameoffset(fp)*push new frameLDA ac,1(pc)*save return in acLDA pc,.(pc)*relative jump to fuction entryLD fp,ofpFO(fp)*pop current frame2)ai:=ai+1;a i a i a i+1 a i+1 c G e n i s A d d r e s s c G e n g p()f p()a c LDA ac,offset(fp)*put address of local var in ac a c 3)A 3 7 9 L D L D A A.5 C T M T I N Y(B)C C(1/4)S p a r c P C()C 1.C 6 2.C D F A L e x 2 3.C4.C(C)Y a c c 4 5(3)5.C 6.C3 8 0 A A