Error n prefixexp var functioncall opb exp cpb ocb

This preview shows page 14 - 21 out of 24 pages.

| error ’\n’ ; prefixexp: var | functioncall | OPB exp CPB | OCB explist CCB | error ’\n’ ; function: FUNCTION funcbody ; | error ’\n’ functioncall: prefixexp args | prefixexp COLON NAME args | error ’\n’ ; funcbody: OPB parlist CPB block END | OPB CPB block END | error ’\n’ ; parlist : namelist | namelist COMMA TDOT | TDOT | error ’\n’ ; args : OPB CPB | OPB explist CPB | tableconstructor | string | error ’\n’ ; tableconstructor: OCB fieldlist CCB | OCB CCB | error ’\n’ ; field : OSB exp CSB ASSIGN exp 14
Image of page 14

Subscribe to view the full document.

| NAME ASSIGN exp | exp | error ’\n’ ; fieldlist: fieldlist2 optfieldsep | error ’\n’ ; fieldlist2: field | fieldlist2 fieldsep field | error ’\n’ ; optfieldsep: fieldsep | /* empty */ | error ’\n’ ; fieldsep: COMMA | SEMICOLON | error ’\n’ ; string : STRING | error ’\n’ ; /* opnd Priority */ op: opnd1 ; opnd1: opnd1 OR opnd2 | opnd2 ; opnd2: opnd2 AND opnd3 | opnd3 15
Image of page 15
; opnd3: opnd3 LT opnd4 | opnd3 LTE opnd4 | opnd3 GT opnd4 | opnd3 GTE opnd4 | opnd3 NEQS opnd4 | opnd3 EQS opnd4 | opnd4 ; opnd4: opnd4 APPEND opnd5 | opnd5 ; opnd5: opnd5 PLUS opnd6 | opnd5 MINUS opnd6 | opnd6 ; opnd6: opnd6 TIMES opnd7 | opnd6 DIVIDE opnd7 | opnd6 MODULO opnd7 | opnd7 ; opnd7: NOT opnd8 | SQUARE opnd8 | MINUS opnd8 | opnd8 ; opnd8: opnd8 POWER opnd9 | opnd9 ; opnd9: exp ; %% int main() 16
Image of page 16

Subscribe to view the full document.

{ yyin = fopen("test6.lua", "r"); do{ if(yyparse()) { printf("\nFailure"); exit(0); } }while(!feof(yyin)); printf("\nSuccess"); return 0; } 3. sym_table.h: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> #define TableLength 30 struct token { char name[100]; int index; unsigned int row,col; int type; }; typedef struct token Token; struct ListElement{ struct token t; char type[100]; int size; char scope; int argcount; int args[10]; int scope_counter; struct ListElement *next; }; 17
Image of page 17
struct ListElement *TABLE[TableLength]; Token newToken(char name[],int type) { Token t; strcpy(t.name,name); t.type=type; return t; } int HASH(char* str,int bias) { int sum=0; for(int i=0;i<strlen(str);i++) sum+=(str[i]*(i+1)); sum+=bias; return sum%29; } void Initialize() { for(int i=0;i<TableLength;i++) TABLE[i]=NULL; } void Display() { printf("Hash-name-type-scope-argcount-arguments\n"); for(int i=0;i<TableLength;i++) { struct ListElement* cur = TABLE[i]; while(cur!=NULL) { printf("%d-%s-%s-%c%d-%d-",HASH(cur->t.name,0),cur->t.name,cur->type,cur->sc if(cur->argcount>0) printf("%d",cur->args[0]); for(int i=1;i<cur->argcount;i++) printf(",%d",cur->args[i]); printf("\n"); 18
Image of page 18

Subscribe to view the full document.

cur=cur->next; } } } int SEARCH(char* str,int scope_counter) { struct ListElement* cur = TABLE[HASH(str,scope_counter)]; while(cur!=NULL) { if(strcmp(cur->t.name,str)==0 && scope_counter==cur->scope_counter) { return 1; } cur=cur->next; } return 0; } void INSERT(struct token tk,char type[],char scope,int argcount,int args[],int scope_cou { if(scope==’\0’) { printf("no scope \n"); return; } if(scope==’L’) { if(SEARCH(tk.name,scope_counter)==1) return; } else { if(SEARCH(tk.name,0)==1) return; } 19
Image of page 19
int val=HASH(tk.name,scope_counter); struct ListElement* cur= (struct ListElement*)malloc(sizeof(struct ListElement)); cur->t=tk; cur->scope=scope; strcpy(cur->type,type); cur->argcount=argcount; if(scope==’L’) cur->scope_counter=scope_counter; else cur->scope_counter=0; cur->next=NULL; for(int i=0;i<argcount;i++) { cur->args[i]=args[i]; } if(TABLE[val]==NULL) TABLE[val]=cur; else { struct ListElement* ele= TABLE[val]; while(ele->next!=NULL)
Image of page 20

Subscribe to view the full document.

Image of page 21
  • Fall '19
  • b,n kj
  • Block cipher

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern