1 / 6

Parsing and Symbol Table

Parsing and Symbol Table. if (sym==constsym) { getsym(); do { constdeclaration(lev,&tx,&dx); while(sym==comma) { getsym(); constdeclaration(lev,&tx,&dx); } if(sym==semicolon)getsym(); else error(5); } while (sym==ident); }

genera
Download Presentation

Parsing and Symbol Table

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parsing and Symbol Table

  2. if (sym==constsym) { getsym(); do { constdeclaration(lev,&tx,&dx); while(sym==comma) { getsym(); constdeclaration(lev,&tx,&dx); } if(sym==semicolon)getsym(); else error(5); } while (sym==ident); } if (sym==varsym) { getsym(); do { vardeclaration(lev,&tx,&dx); while (sym==comma) { getsym(); vardeclaration(lev,&tx,&dx); } if(sym==semicolon) getsym(); else error(5); } while(sym==ident); } const N = 100, k = 6; M = 20; var a,b; c;

  3. constdeclaration(lev,ptx,pdx) int lev,*ptx,*pdx; { if (sym==ident) { getsym(); if ((sym==eql) || (sym==becomes)) { if (sym==becomes) error(1); getsym(); if (sym==number) {enter(constant,ptx,pdx,lev); getsym();} } } } const N = 100, k = 6; M = 20;

  4. while(sym==procsym) { getsym(); if(sym==ident){ enter(procedure,&tx,&dx,lev); getsym(); } else error(4); if (sym==semicolon) getsym(); else if (sym==lparen); else error(5); block(lev+1, tx); if(sym==semicolon) { getsym(); } else error(5); }

  5. vardeclaration(lev,ptx,pdx) int *ptx,*pdx,lev; { if (sym==ident) {enter(variable, ptx,pdx,lev); getsym();} else error(4); } var a,b; c;

  6. struct namerecord{ int kind; char name[10]; int val; int level; int adr; int indirect; }; enter(k,ptx,pdx,lev) int k; int *ptx; int *pdx;int lev; { char *id1; int ii,len; (*ptx)++; id1=id; len=strlen(id); for (ii=0;ii<=len;ii++){table[*ptx].name[ii]=*id1; id1++;} table[*ptx].kind=k; if (k==constant) table[*ptx].val=num; else if (k==variable) { table[*ptx].level=lev; table[*ptx].adr=*pdx; table[*ptx].indirect=flag; (*pdx)++; } else /* procedure */ { table[*ptx].level=lev;}} struct namerecord table[1000];

More Related