"Compiling principle" lesson notes

Source: Internet
Author: User


March 30, 2015 textbook P24 P226 P259 (left, 7-1 figure) 1. external declaration external-declarationexternal int A;int B;void f () {}2.ucc\examples\sc\ DECL.C Textbook P24 Declaration-----> int Declarator Declarator-----> * Declarator | Postfixdeclarator------------>d = {PD,*PD,**PD,***PD,.....} Postfixdeclarator---> Directdeclarator | postfixdeclarator [num] | Postfixdeclarator (parameterlist)------------>pd{dd,dd[num],dd (void), dd[num][num],dd (void), Dd[num] ( void), DD (void) [num],........} Parameterlist---> int | parameterlist, int directdeclarator-----> ID | (Declarator) 3.p226 "type expression" int--operand "operator": *--pointer type, []--array type, ()--array of function type 3.1 pointers: int *arr[4]; Pointer to array: int (*ptr) [4];typedef int* intpir typedef int ARRAY[4]INTPIR ARR[4]; ARRAY[4] *prt;4.p259 code area static area "compile-time" (global variable, static variable, constant) heap area "Runtime" (New,malloc) Free memory "runtime" Stack "Runtime" (local, formal parameter) 4.1 parameter printf ("%d", a); printf ("%d%d", A, b);p rintf (const CHAR*FMT, ...); 4.2.13.png (c language variable layout) anonymous parameter unnamed parameter-----> parameter Lifting CHAR,SHORT-> Intfloat->double

Stmt.c

March 16, 2015 parser algorithm: (UCC/EXAMPLES/SC/EXPR.C) 1.PrimaryExpression-----> ID | num | (Expression)------PE--->-----| | ||     | * / || ---pe<--void primaryexpression (void) {if (Curtoken = = ID) next_token;else if ((Curtoken = = NUM) next_token;else if (( Curtoken = = LP) {next_token;if ((Curtoken = = RP) Next_token;} Elseerror ("(Is missed.");} 2. "Left combination" multiplicativeexpression-----> Primaryexpressionmultiplicativeexpression-----> Multiplicativeexpression * primaryexpressionmultiplicativeexpression-----> multiplicativeexpression/ Primaryexpressionvoid multiplicativeexpression (void) {primaryexpression (); while (Curtoken = = MUL | Curtoken = = DIV) {next_token; Primaryexpression ();}} 3.E = {t,t+t,...} = T{e,+t,+t+t,...} +t e ' void e ' (void) {if (Currenttoken = = +) {next_token), T e ' e ' T (); E ' ();} Else{}}4. " Right Combine "me-> PE me '->e (empty)->*|/mevoid multiplicativeexpression (void) {primaryexpression (); if (Curtoken = = MUL | Curtoken = = DIV) {next_token; Multiplicativeexpression ();}Else{}}5.visitarithmeticnode () (a+b) *ct1*t0c+ab Intermediate code generation: T0 = a+b;t1 = T0+c;6.int (*f (Int,int,int)) [4]eg.int (*arr) [4] typedef int Array[4]array *f (int,int,int)

Expr.c

March 22, 2015 textbook p2411.s->if (B) s1if (! B) goto label0; S1label0:2.if (B) S1 else s2if (! B) goto label0; S1goto Label1;label0:s2goto label1;label1:3.while (B) s1label0:if (! B) Goto Label1; S1goto label0;label1:4. Write Do...while () in the experiment class; statement????? 5.if Statement Kids[0]->label0kids[1]->label1expr->expressionthenstmt->then Statement elsestmt-> Else Statement Nextaststmtnode Textbook p1296.visitstatementnode->if (c) A=f;else b=k;kids[0]->label0kids[1]->label1expr- >cthenstmt->a=f;elsestmt->b=k;7.expressionstatement (void) {}->a=3+5;kids[0]->aexpr-> + 3 58.Com    Pund statement------------|    |->| |------  ------..........| next|--|next| Set of first (a) symbols 9.linux system make results: [email protected]:~$ CD SRC/UCC/EXAMPLES/SC[EMAIL&NBSP;PROTECTED]:~/SRC/UCC /examples/sc$ Makeucc-o SC lex.c expr.c error.c decl.c stmt.c main.ccat demo.c{int (*f (Int,int,int)) [4];int (* (*FP2) (int, Int,int)) (int); if (c) A = F;else{b = k;} while (c) {while (d) {if (e) {d = d-1;}} c = c-1;}}. /sc < DEMO.CF is:function (Int,int,int) WHich returns pointer to array[4] of int fp2 is:pointer to function (int,int,int) which returns pointer to function (int) W Hich returns int if (!C) goto label_0 a = f goto label_1 label_0:b = k Label_1:Label_2:if (!c) goto label_6 label_3:if (!d) G Oto label_5 if (!e) goto label_4 t0 = d-1 d = T0 Label_4:goto label_3 label_5:t1 = c-1 c = T1 goto label_2 label_6:

  

"Compiling principle" lesson notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.