├── .vscode └── settings.json ├── Assembly_Language_Generator ├── CODGEN.C ├── a.out └── int.txt ├── Constant-Propagation ├── CP.c └── a.out ├── First-Follow ├── FIRST.c ├── first.c ├── first_follow.c └── simple-first-follow.c ├── Intermediate_Code_Generator ├── INCODE.C ├── a.out ├── input.txt └── output.txt ├── LEX-Count ├── a.out ├── demo.l └── lex.yy.c ├── LEX-Substring ├── a.out ├── lex.yy.c └── pgm.l ├── LEX-Vowels ├── a.out ├── lex.yy.c └── pgm.l ├── Lab-Exam ├── LEX-AMSTRONG │ ├── a.out │ ├── input.txt │ ├── lex.l │ └── lex.yy.c ├── LEX-EMAIL&PHONE │ ├── a.out │ ├── input.txt │ ├── lex.l │ └── lex.yy.c ├── LEX-Palindrome-Num │ ├── a.out │ ├── input.txt │ ├── lex.l │ └── lex.yy.c ├── LEX-Palindrome-String │ ├── a.out │ ├── input.txt │ ├── lex.l │ └── lex.yy.c └── LEX-Prime │ ├── a.out │ ├── input.txt │ ├── lex.l │ └── lex.yy.c ├── Lexical-Analayzer-Using-C ├── input.txt ├── lexical.c └── output.txt ├── Lexical-Analyzer-Using-LEX ├── a.out ├── la.l ├── lex.yy.c └── var.c ├── NFA-to-DFA ├── Nfa_ip.txt ├── a.out └── pgm.c ├── README.md ├── Recursive_Descent_Parser ├── RDP.c ├── a.out └── parser.c ├── Shift-Reduce-Parser ├── 4-srp.c └── SRP.C ├── YACC-Calculator ├── a.out ├── cal.l ├── cal.y ├── lex.yy.c ├── y.tab.c └── y.tab.h ├── YACC-Valid-Expressions ├── a.out ├── exp.l ├── exp.y ├── lex.yy.c ├── y.tab.c └── y.tab.h └── YACC-Valid-Identifiers ├── a.out ├── identifier.l ├── identifier.y ├── lex.yy.c ├── y.tab.c └── y.tab.h /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "SRP.C": "cpp", 4 | "INCODE.C": "cpp", 5 | "CODGEN.C": "cpp" 6 | } 7 | } -------------------------------------------------------------------------------- /Assembly_Language_Generator/CODGEN.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct quadraple 5 | { 6 | int pos; 7 | char op; 8 | char arg1[5]; 9 | char arg2[5]; 10 | char result[5]; 11 | }quad[15]; 12 | int n=0; 13 | void assignment(int); 14 | void uminus(int ); 15 | void explore(); 16 | void codegen(const char*,int); 17 | char tuple[15][15]; 18 | int main(void) 19 | { 20 | FILE *src; 21 | int nRetInd,i; 22 | char str[15]; 23 | src=fopen("int.txt","r"); 24 | fscanf(src,"%s",str); 25 | while(!feof(src)) 26 | { 27 | strcpy(tuple[n++],str); 28 | fscanf(src,"%s",str); 29 | } 30 | printf("INPUT:\nIntermiate codes:\n"); 31 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | int n, m = 0, p, i = 0, j = 0; 7 | char a[10][10], f[10]; 8 | void follow(char c); 9 | void first(char c); 10 | int main() 11 | { 12 | 13 | int i, z; 14 | char c, ch; 15 | // clrscr(); 16 | printf("Enter the no of productions:\n"); 17 | scanf("%d", &n); 18 | printf("Enter the productions:\n"); 19 | for (i = 0; i < n; i++) 20 | scanf("%s%c", a[i], &ch); 21 | do 22 | { 23 | m = 0; 24 | printf("Enter the elemets whose fisrt & follow is to be found:"); 25 | scanf("%c", &c); 26 | first(c); 27 | printf("First(%c)={", c); 28 | for (i = 0; i < m; i++) 29 | printf("%c", f[i]); 30 | printf("}\n"); 31 | strcpy(f, " "); 32 | // flushall(); 33 | m = 0; 34 | follow(c); 35 | printf("Follow(%c)={", c); 36 | for (i = 0; i < m; i++) 37 | printf("%c", f[i]); 38 | printf("}\n"); 39 | printf("Continue(0/1)?"); 40 | scanf("%d%c", &z, &ch); 41 | } while (z == 1); 42 | return (0); 43 | } 44 | void first(char c) 45 | { 46 | int k; 47 | if (!isupper(c)) 48 | f[m++] = c; 49 | for (k = 0; k < n; k++) 50 | { 51 | if (a[k][0] == c) 52 | { 53 | if (a[k][2] == '$') 54 | follow(a[k][0]); 55 | else if (islower(a[k][2])) 56 | f[m++] = a[k][2]; 57 | else 58 | first(a[k][2]); 59 | } 60 | } 61 | } 62 | void follow(char c) 63 | { 64 | if (a[0][0] == c) 65 | f[m++] = '$'; 66 | for (i = 0; i < n; i++) 67 | { 68 | for (j = 2; j < strlen(a[i]); j++) 69 | { 70 | if (a[i][j] == c) 71 | { 72 | if (a[i][j + 1] != '\0') 73 | first(a[i][j + 1]); 74 | if (a[i][j + 1] == '\0' && c != a[i][0]) 75 | follow(a[i][0]); 76 | } 77 | } 78 | } 79 | } 80 | 81 | 82 | Start 83 | Calculating first, α → t β 84 | if α is a terminal, then FIRST(α) = { α }. 85 | if α is a non-terminal and α → ℇ is a production, then FIRST(α) = { ℇ }. 86 | if α is a non-terminal and α → 𝜸1 𝜸2 𝜸3 … 𝜸n and any FIRST(𝜸) contains then t is in FIRST(α). 87 | Calculating follow, 88 | if α is a start symbol, then FOLLOW() = $ 89 | if α is a non-terminal and has a production α → AB, then FIRST(B) is inFOLLOW(A) except ℇ. 90 | if α is a non-terminal and has a production α → AB, where B ℇ, thenFOLLOW(A) is in FOLLOW(α). 91 | Stop -------------------------------------------------------------------------------- /First-Follow/first.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int num_of_productions; 6 | char production_set[20][20]; 7 | 8 | void FIRST(char Result[], char c); 9 | void add_to_Result_Set(char result[], char c); 10 | 11 | int main() 12 | { 13 | int i; 14 | char choice; 15 | char c; 16 | char result[30]; 17 | 18 | printf("Enter the no. of productions : "); 19 | scanf("%d", &num_of_productions); 20 | puts("Enter the production string like \"E=E+T\" \nand epsilon as #"); 21 | 22 | for (i = 0; i < num_of_productions; ++i) 23 | { 24 | printf("Enter production Number %d : ", i + 1); 25 | scanf("%s", production_set[i]); 26 | } 27 | do 28 | { 29 | // memset( result, '\0', sizeof(result) ); 30 | 31 | printf("Find FIRST of --> "); 32 | scanf(" %c", &c); 33 | 34 | FIRST(result, c); 35 | 36 | printf("\nFirst (%c) = { ", c); 37 | for (i = 0; i < strlen(result); ++i) 38 | printf("%c ", result[i]); 39 | puts(" }"); 40 | 41 | printf("Press \'y\' or \'Y\' to continue : "); 42 | scanf(" %c", &choice); 43 | } while (choice == 'y' || choice == 'Y'); 44 | 45 | return 0; 46 | } 47 | 48 | void FIRST(char Result[], char c) 49 | { 50 | int i, j, k; 51 | char Sub_Result[20]; 52 | int found_epsilon; 53 | 54 | Sub_Result[0] = '\0'; 55 | Result[0] = '\0'; 56 | 57 | if (!(isupper(c))) 58 | { 59 | add_to_Result_Set(Result, c); 60 | return; 61 | } 62 | 63 | for (i = 0; i < num_of_productions; ++i) 64 | { 65 | if (production_set[i][0] == c) 66 | { 67 | if (production_set[i][2] == '#') 68 | add_to_Result_Set(Result, '#'); 69 | else 70 | { 71 | j = 2; 72 | 73 | while (production_set[i][j] != '\0') 74 | { 75 | found_epsilon = 1; 76 | 77 | FIRST(Sub_Result, production_set[i][j]); 78 | 79 | for (k = 0; k < strlen(Sub_Result); ++k) 80 | add_to_Result_Set(Result, Sub_Result[k]); 81 | 82 | for (k = 0; k < strlen(Sub_Result); ++k) 83 | if (Sub_Result[k] == '#') 84 | { 85 | found_epsilon = 0; 86 | break; 87 | } 88 | if (found_epsilon) 89 | break; 90 | j++; 91 | } 92 | } 93 | } 94 | } 95 | return; 96 | } 97 | 98 | void add_to_Result_Set(char Result[], char val) 99 | { 100 | int k; 101 | for (k = 0; Result[k] != '\0'; ++k) 102 | { 103 | if (Result[k] == val) 104 | { 105 | return; 106 | } 107 | } 108 | Result[k] = val; 109 | Result[k + 1] = '\0'; 110 | } 111 | -------------------------------------------------------------------------------- /First-Follow/first_follow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int nop, m = 0; 6 | char prod[10][10], res[10]; 7 | 8 | void FIRST(char c); 9 | void FOLLOW(char c); 10 | void result(char c); 11 | 12 | int main() 13 | { 14 | int i; 15 | int choice; 16 | char c; 17 | 18 | printf("Enter the no. of productions : "); 19 | scanf("%d", &nop); 20 | puts("\nEnter the production string like \"E=E+T\" \nand epsilon as #\n"); 21 | 22 | for (i = 0; i < nop; ++i) 23 | { 24 | printf("Enter production Number %d : ", i + 1); 25 | scanf("%s", prod[i]); 26 | } 27 | do 28 | { 29 | m = 0; 30 | memset(res, '\0', sizeof(res)); 31 | 32 | printf("\nFind FOLLOW of --> "); 33 | scanf(" %c", &c); 34 | 35 | if (isupper(c)) 36 | FOLLOW(c); 37 | else 38 | { 39 | printf("Not Possible"); 40 | return 0; 41 | } 42 | 43 | printf("Follow (%c) = { ", c); 44 | for (i = 0; i < m; ++i) 45 | printf("%c ", res[i]); 46 | puts(" }"); 47 | 48 | printf("Do you want to continue(Press 1 to continue...) ? "); 49 | scanf("%d", &choice); 50 | } while (choice == 1); 51 | 52 | return 0; 53 | } 54 | 55 | void FOLLOW(char c) 56 | { 57 | int i, j; 58 | if (prod[0][0] == c) 59 | result('$'); 60 | for (i = 0; i < nop; ++i) 61 | { 62 | for (j = 2; j <= strlen(prod[i]); ++j) 63 | { 64 | if (prod[i][j] == c) 65 | { 66 | if (prod[i][j + 1] != '\0') 67 | FIRST(prod[i][j + 1]); 68 | if (prod[i][j + 1] == '\0' && c != prod[i][0]) 69 | FOLLOW(prod[i][0]); 70 | } 71 | } 72 | } 73 | return; 74 | } 75 | 76 | void FIRST(char c) 77 | { 78 | int k; 79 | if (!(isupper(c))) 80 | result(c); 81 | for (k = 0; k < nop; ++k) 82 | { 83 | if (prod[k][0] == c) 84 | { 85 | if (prod[k][2] == '#') 86 | FOLLOW(prod[k][0]); 87 | else if (prod[k][2] == c) 88 | return; 89 | else if (islower(prod[k][2])) 90 | result(prod[k][2]); 91 | else 92 | FIRST(prod[k][2]); 93 | } 94 | } 95 | return; 96 | } 97 | 98 | void result(char c) 99 | { 100 | int i; 101 | for (i = 0; i <= m; ++i) 102 | if (res[i] == c) 103 | return; 104 | res[m++] = c; 105 | } 106 | 107 | /* 108 | Input/ Output :- 109 | ------------- 110 | Enter the no. of productions : 8 111 | Enter the production string like "E=E+T" 112 | and epsilon as # 113 | Enter production Number 1 : E=TX 114 | Enter production Number 2 : X=+TX 115 | Enter production Number 3 : X=# 116 | Enter production Number 4 : T=FY 117 | Enter production Number 5 : Y=*FY 118 | Enter production Number 6 : Y=# 119 | Enter production Number 7 : F=(E) 120 | Enter production Number 8 : F=i 121 | Find FOLLOW of --> E 122 | Follow (E) = { $ ) } 123 | Do you want to continue(Press 1 to continue...) ? 1 124 | Find FOLLOW of --> X 125 | Follow (X) = { $ ) } 126 | Do you want to continue(Press 1 to continue...) ? 1 127 | Find FOLLOW of --> T 128 | Follow (T) = { + $ ) } 129 | Do you want to continue(Press 1 to continue...) ? 1 130 | Find FOLLOW of --> Y 131 | Follow (Y) = { + $ ) } 132 | Do you want to continue(Press 1 to continue...) ? 1 133 | Find FOLLOW of --> F 134 | Follow (F) = { * + $ ) } 135 | Do you want to continue(Press 1 to continue...) ? 0 136 | */ 137 | -------------------------------------------------------------------------------- /First-Follow/simple-first-follow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Functions to calculate Follow 6 | void followfirst(char, int, int); 7 | void follow(char c); 8 | 9 | // Function to calculate First 10 | void findfirst(char, int, int); 11 | 12 | int count, n = 0; 13 | 14 | // Stores the final result 15 | // of the First Sets 16 | char calc_first[10][100]; 17 | 18 | // Stores the final result 19 | // of the Follow Sets 20 | char calc_follow[10][100]; 21 | int m = 0; 22 | 23 | // Stores the production rules 24 | char production[10][10]; 25 | char f[10], first[10]; 26 | int k; 27 | char ck; 28 | int e; 29 | 30 | int main(int argc, char **argv) 31 | { 32 | int jm = 0; 33 | int km = 0; 34 | int i, choice; 35 | char c, ch, prod[10]; 36 | 37 | printf("Enter the number of productions: "); 38 | scanf("%d",&count); 39 | for(i=0;i 2 | #include 3 | char op[2], arg1[5], arg2[5], result[5]; 4 | int main() 5 | { 6 | FILE *fp1, *fp2; 7 | fp1 = fopen("input.txt", "r"); 8 | fp2 = fopen("output.txt", "w"); 9 | while (!feof(fp1)) 10 | { 11 | 12 | fscanf(fp1, "%s%s%s%s", op, arg1, arg2, result); 13 | if (strcmp(op, "+") == 0) 14 | { 15 | fprintf(fp2, "\nMOV R0,%s", arg1); 16 | fprintf(fp2, "\nADD R0,%s", arg2); 17 | fprintf(fp2, "\nMOV %s,R0", result); 18 | } 19 | if (strcmp(op, "*") == 0) 20 | { 21 | fprintf(fp2, "\nMOV R0,%s", arg1); 22 | fprintf(fp2, "\nMUL R0,%s", arg2); 23 | fprintf(fp2, "\nMOV %s,R0", result); 24 | } 25 | if (strcmp(op, "-") == 0) 26 | { 27 | fprintf(fp2, "\nMOV R0,%s", arg1); 28 | fprintf(fp2, "\nSUB R0,%s", arg2); 29 | fprintf(fp2, "\nMOV %s,R0", result); 30 | } 31 | if (strcmp(op, "/") == 0) 32 | { 33 | fprintf(fp2, "\nMOV R0,%s", arg1); 34 | fprintf(fp2, "\nDIV R0,%s", arg2); 35 | fprintf(fp2, "\nMOV %s,R0", result); 36 | } 37 | if (strcmp(op, "=") == 0) 38 | { 39 | fprintf(fp2, "\nMOV R0,%s", arg1); 40 | fprintf(fp2, "\nMOV %s,R0", result); 41 | } 42 | } 43 | fclose(fp1); 44 | fclose(fp2); 45 | } -------------------------------------------------------------------------------- /Intermediate_Code_Generator/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Intermediate_Code_Generator/a.out -------------------------------------------------------------------------------- /Intermediate_Code_Generator/input.txt: -------------------------------------------------------------------------------- 1 | + a b t1 2 | * c d t2 3 | - t1 t2 t 4 | = t ? x -------------------------------------------------------------------------------- /Intermediate_Code_Generator/output.txt: -------------------------------------------------------------------------------- 1 | 2 | MOV R0,a 3 | ADD R0,b 4 | MOV t1,R0 5 | MOV R0,c 6 | MUL R0,d 7 | MOV t2,R0 8 | MOV R0,t1 9 | SUB R0,t2 10 | MOV t,R0 11 | MOV R0,t 12 | MOV x,R0 -------------------------------------------------------------------------------- /LEX-Count/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/LEX-Count/a.out -------------------------------------------------------------------------------- /LEX-Count/demo.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | int sc=0,wc=0,lc=0,cc=0; 4 | %} 5 | %% 6 | [\n] { lc++; cc+=yyleng;} 7 | [ \t] { sc++; cc+=yyleng;} 8 | [^\t\n ]+ { wc++; cc+=yyleng;} 9 | %% 10 | int main(int argc ,char* argv[ ]) 11 | { 12 | printf("Enter the input:\n"); 13 | yylex(); 14 | printf("The number of lines=%d\n",lc); 15 | printf("The number of spaces=%d\n",sc); 16 | printf("The number of words=%d\n",wc); 17 | printf("The number of characters are=%d\n",cc); 18 | } 19 | int yywrap( ) 20 | { 21 | return 1; 22 | } 23 | 24 | // to compile type lex demo.l 25 | // then type cc lex.yy.c 26 | // then type ./a.out 27 | /* 28 | Enter the input: Greetings from CEC 29 | Welcome to Chengannur 30 | Lex Yacc Program 31 | (Note: After input string press enter and ctrl+d) 32 | The number of lines=3 33 | The number of spaces=6 34 | The number of words=9 35 | The number of characters are=58 36 | */ -------------------------------------------------------------------------------- /LEX-Substring/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/LEX-Substring/a.out -------------------------------------------------------------------------------- /LEX-Substring/pgm.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | int i; 5 | %}//contains the header files and the global variables 6 | 7 | %%//contains the regular expressions and the actions 8 | [a-z A-Z]* { 9 | for(i=0;i<=yyleng;i++) 10 | { 11 | if((yytext[i]=='a') && (yytext[i+1]=='b')&&(yytext[i+2]=='c')) 12 | { 13 | yytext[i]='A'; 14 | yytext[i+1]='B'; 15 | yytext[i+2]='C'; 16 | } 17 | } 18 | printf("%s",yytext); 19 | } 20 | [\t]* return 1; 21 | .* {ECHO;} 22 | \n {printf("%s",yytext);} 23 | %% 24 | 25 | int main() 26 | { 27 | yylex();//calling the yylex function to start the lexical analysis 28 | } 29 | //for ignoring the comments 30 | int yywrap() 31 | { 32 | return 1; 33 | } 34 | 35 | //to compile the code 36 | // lex pgm.l 37 | // gcc lex.yy.c 38 | // ./a.out 39 | 40 | // Output 41 | // Enter the string 42 | // abc 43 | // ABC 44 | 45 | -------------------------------------------------------------------------------- /LEX-Vowels/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/LEX-Vowels/a.out -------------------------------------------------------------------------------- /LEX-Vowels/pgm.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | int vow_count=0; 4 | int const_count =0; 5 | %} 6 | 7 | %% 8 | [aeiouAEIOU] {vow_count++;} 9 | [bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ] {const_count++;} 10 | %% 11 | 12 | int main() 13 | { 14 | yylex(); 15 | printf("Vowels = %d and Consonants = %d",vow_count,const_count); 16 | return 0; 17 | } 18 | 19 | int yywrap() 20 | { 21 | return 1; 22 | } 23 | 24 | //to compile the code 25 | // lex pgm.l 26 | // gcc lex.yy.c 27 | // ./a.out 28 | 29 | // Output 30 | // hello 31 | // Vowels = 2 and Consonants = 3 32 | -------------------------------------------------------------------------------- /Lab-Exam/LEX-AMSTRONG/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lab-Exam/LEX-AMSTRONG/a.out -------------------------------------------------------------------------------- /Lab-Exam/LEX-AMSTRONG/input.txt: -------------------------------------------------------------------------------- 1 | 153 -------------------------------------------------------------------------------- /Lab-Exam/LEX-AMSTRONG/lex.l: -------------------------------------------------------------------------------- 1 | /* Lex Program to check Amstrong Number */ 2 | 3 | %{ 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int isAmstrong(int n) 10 | { 11 | int sum = 0, temp = n, rem, count = 0; 12 | 13 | while (temp != 0) 14 | { 15 | temp /= 10; 16 | count++; 17 | } 18 | 19 | temp = n; 20 | while (temp != 0) 21 | { 22 | rem = temp % 10; 23 | sum += pow(rem, count); 24 | temp /= 10; 25 | } 26 | 27 | if (sum == n) 28 | return 1; 29 | else 30 | return 0; 31 | } 32 | %} 33 | 34 | /* Rule Section */ 35 | %% 36 | 37 | [0-9]+ { 38 | if (isAmstrong(atoi(yytext))) 39 | printf("Amstrong Number"); 40 | else 41 | printf("Not Amstrong Number"); 42 | 43 | } 44 | 45 | .+ { 46 | printf("Invalid input"); 47 | } 48 | 49 | 50 | 51 | %% 52 | 53 | // driver code 54 | int main() 55 | { 56 | // read input from file 57 | freopen("input.txt", "r", stdin); 58 | yylex(); 59 | return 0; 60 | } 61 | 62 | int yywrap() 63 | { 64 | return 1; 65 | } 66 | 67 | 68 | // Algorithm 69 | 70 | // 1. Read input from file. 71 | // 2. Send input to yylex() function. 72 | // 3. yylex() function will check for the pattern. 73 | // 4. If pattern matches, it will call the function for checking Amstrong Number. 74 | // 5. If Amstrong Number, it will print "Amstrong Number". 75 | // 6. If not Amstrong Number, it will print "Not Amstrong Number". 76 | // 7. If input is invalid, it will print "Invalid input". 77 | // 8. Stop. 78 | 79 | -------------------------------------------------------------------------------- /Lab-Exam/LEX-EMAIL&PHONE/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lab-Exam/LEX-EMAIL&PHONE/a.out -------------------------------------------------------------------------------- /Lab-Exam/LEX-EMAIL&PHONE/input.txt: -------------------------------------------------------------------------------- 1 | aromalsanthosh@hotmail.com 2 | 7902293783 3 | aromal@katha.today 4 | 1234 5 | aromal@cec -------------------------------------------------------------------------------- /Lab-Exam/LEX-EMAIL&PHONE/lex.l: -------------------------------------------------------------------------------- 1 | /* Lex Program to check EMail & phone number */ 2 | %{ 3 | #include 4 | #include 5 | #include 6 | 7 | %} 8 | 9 | /* Rule Section */ 10 | %% 11 | 12 | 13 | [a-zA-Z0-9_]+@[a-zA-Z0-9_]+[.][a-zA-Z0-9_]+ { printf("%s is Valid Email ID", yytext); } 14 | 15 | [0-9]{10} { printf("%s is Valid Mobile Number", yytext); } 16 | 17 | .+ { printf("%s is Invalid Input", yytext); } 18 | 19 | %% 20 | 21 | // driver code 22 | int main() 23 | { 24 | // read input from file 25 | freopen("input.txt", "r", stdin); 26 | yylex(); 27 | return 0; 28 | } 29 | 30 | int yywrap() 31 | { 32 | return 1; 33 | } 34 | 35 | 36 | // Algorithm 37 | 38 | // 1. Read input from file. 39 | // 2. Send input to yylex() function. 40 | // 3. yylex() function will check for the pattern. 41 | // 4. If pattern matches, then it will print the output. 42 | // 5. If pattern does not match, then it will print the invalid input. 43 | // 6. If input is EOF, then it will return 1. 44 | // 7. Step 2 to 6 will be repeated until EOF is reached. 45 | // 8. Stop -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-Num/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lab-Exam/LEX-Palindrome-Num/a.out -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-Num/input.txt: -------------------------------------------------------------------------------- 1 | 1221 -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-Num/lex.l: -------------------------------------------------------------------------------- 1 | /* Lex Program to check Palindrome Number */ 2 | 3 | %{ 4 | #include 5 | #include 6 | #include 7 | 8 | int isPalindrome(int n) 9 | { 10 | int rev = 0, temp = n; 11 | while (temp != 0) 12 | { 13 | rev = rev * 10 + temp % 10; 14 | temp /= 10; 15 | } 16 | return rev == n; 17 | } 18 | %} 19 | 20 | /* Rule Section */ 21 | %% 22 | 23 | [0-9]+ { 24 | if (isPalindrome(atoi(yytext))) 25 | printf("Palindrome Number"); 26 | else 27 | printf("Not a Palindrome Number"); 28 | 29 | } 30 | 31 | .+ { 32 | printf("Invalid input"); 33 | } 34 | 35 | 36 | 37 | %% 38 | 39 | // driver code 40 | int main() 41 | { 42 | // read input from file 43 | freopen("input.txt", "r", stdin); 44 | yylex(); 45 | return 0; 46 | } 47 | 48 | int yywrap() 49 | { 50 | return 1; 51 | } 52 | 53 | 54 | // Algorithm 55 | 56 | // 1. Read input from file. 57 | // 2. Send input to yylex() function. 58 | // 3. yylex() function will check for the pattern. 59 | // 4. If pattern matches, then it will call the function isPalindrome(). 60 | // 5. isPalindrome() function will check if the number is palindrome or not. 61 | // 6. If the number is palindrome, then it will print Palindrome Number. 62 | // 7. If the number is not palindrome, then it will print Not a Palindrome Number. 63 | // 8. If the input is invalid, then it will print Invalid input. 64 | // 9. Stop the program. -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-String/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lab-Exam/LEX-Palindrome-String/a.out -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-String/input.txt: -------------------------------------------------------------------------------- 1 | aromal -------------------------------------------------------------------------------- /Lab-Exam/LEX-Palindrome-String/lex.l: -------------------------------------------------------------------------------- 1 | /* Lex Program to check Palindrome String */ 2 | 3 | %{ 4 | #include 5 | #include 6 | #include 7 | 8 | // function to check palindrome 9 | int isPalindrome(char str[]) 10 | { 11 | // Start from leftmost and rightmost corners of str 12 | int l = 0; 13 | int h = strlen(str) - 1; 14 | 15 | // Keep comparing characters while they are same 16 | while (h > l) 17 | { 18 | if (str[l++] != str[h--]) 19 | { 20 | return 0; 21 | } 22 | } 23 | return 1; 24 | } 25 | %} 26 | 27 | /* Rule Section */ 28 | %% 29 | 30 | [a-zA-Z]+ { 31 | if (isPalindrome(yytext)) { 32 | printf("%s is a palindrome\n", yytext); 33 | } 34 | else { 35 | printf("%s is not a palindrome\n", yytext); 36 | } 37 | } 38 | 39 | . { 40 | // do nothing, just skip the character 41 | } 42 | 43 | %% 44 | 45 | // driver code 46 | int main() 47 | { 48 | // read input from file 49 | freopen("input.txt", "r", stdin); 50 | yylex(); 51 | return 0; 52 | } 53 | 54 | int yywrap() 55 | { 56 | return 1; 57 | } 58 | 59 | 60 | // Algorithm 61 | 62 | // 1. Read input from file. 63 | // 2. Send input to yylex() function. 64 | // 3. yylex() function will check for the pattern. 65 | // 4. If pattern matches, then it will call the function isPalindrome(). 66 | // 5. isPalindrome() function will check if the string is palindrome or not. 67 | // 6. If the string is palindrome, then it will print Palindrome string. 68 | // 7. If the string is not palindrome, then it will print Not a Palindrome string. 69 | // 8. If the input is invalid, then it will print Invalid input. 70 | // 9. Stop the program. -------------------------------------------------------------------------------- /Lab-Exam/LEX-Prime/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lab-Exam/LEX-Prime/a.out -------------------------------------------------------------------------------- /Lab-Exam/LEX-Prime/input.txt: -------------------------------------------------------------------------------- 1 | 169 -------------------------------------------------------------------------------- /Lab-Exam/LEX-Prime/lex.l: -------------------------------------------------------------------------------- 1 | /* Lex Program to check Prime Number */ 2 | 3 | %{ 4 | #include 5 | #include 6 | #include 7 | 8 | int isPrime(int n) 9 | { 10 | int i; 11 | for (i = 2; i < n; i++) 12 | { 13 | if (n % i == 0) 14 | return 0; 15 | } 16 | return 1; 17 | } 18 | 19 | int oddEven(int num){ 20 | if(num % 2 == 0){ 21 | return 1; 22 | } 23 | return 0; 24 | } 25 | 26 | int factorial(int num){ 27 | int i; 28 | int fact = 1; 29 | for(i = 1; i <= num; i++){ 30 | fact = fact * i; 31 | } 32 | return fact; 33 | } 34 | %} 35 | 36 | /* Rule Section */ 37 | %% 38 | 39 | [0-9]+ { 40 | if (isPrime(atoi(yytext))) 41 | printf("%s is a prime number", yytext); 42 | else 43 | printf("%s is not a prime number", yytext); 44 | } 45 | 46 | .+ { 47 | printf("Invalid input"); 48 | } 49 | 50 | 51 | 52 | %% 53 | 54 | // driver code 55 | int main() 56 | { 57 | // read input from file 58 | freopen("input.txt", "r", stdin); 59 | yylex(); 60 | return 0; 61 | } 62 | 63 | int yywrap() 64 | { 65 | return 1; 66 | } 67 | 68 | // Algorithm 69 | 70 | // 1. Read input from file. 71 | // 2. Send input to yylex() function. 72 | // 3. yylex() function will check for the pattern. 73 | // 4. If pattern matches, then it will call the function isPrime(). 74 | // 5. isPrime() function will check if the number is prime or not. 75 | // 6. If the number is prime, then it will print “is a prime number”. 76 | // 7. If the number is not prime, then it will print “is not a prime number”. 77 | // 8. If the pattern does not match, then it will print “Invalid input”. 78 | // 9. Stop -------------------------------------------------------------------------------- /Lexical-Analayzer-Using-C/input.txt: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | printf("Hello World"); 5 | } 6 | -------------------------------------------------------------------------------- /Lexical-Analayzer-Using-C/lexical.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | 8 | FILE *input, *output; 9 | int l=1; 10 | int t=0; 11 | int j=0; 12 | int i,flag; 13 | char ch,str[20]; 14 | input = fopen("input.txt","r"); 15 | output = fopen("output.txt","w"); 16 | char keyword[30][30] = {"int","main","if","else","do","while"}; 17 | fprintf(output,"Line no. \t Token no. \t\t Token \t\t Lexeme\n\n"); 18 | 19 | while(!feof(input)) 20 | { 21 | i=0; 22 | flag=0; 23 | ch=fgetc(input); 24 | 25 | if( ch=='+' || ch== '-' || ch=='*' || ch=='/' ) 26 | { 27 | fprintf(output,"%7d\t\t %7d\t\t Operator\t %7c\n",l,t,ch); 28 | t++; 29 | } 30 | 31 | else if( ch==';' || ch=='{' || ch=='}' || ch=='(' || ch==')' || ch=='?' || ch=='@' ||ch=='!' || ch=='%') 32 | 33 | { 34 | 35 | fprintf(output,"%7d\t\t %7d\t\t Special symbol\t %7c\n",l,t,ch); 36 | t++; 37 | } 38 | 39 | else if(isdigit(ch)) 40 | { 41 | fprintf(output,"%7d\t\t %7d\t\t Digit\t\t %7c\n",l,t,ch); 42 | t++; 43 | } 44 | 45 | else if(isalpha(ch)) 46 | { 47 | str[i]=ch; 48 | i++; 49 | ch=fgetc(input); 50 | 51 | while(isalnum(ch) && ch!=' ') 52 | { 53 | str[i]=ch; 54 | i++; 55 | ch=fgetc(input); 56 | } 57 | 58 | str[i]='\0'; 59 | 60 | for(j=0;j<=30;j++) 61 | 62 | { 63 | if(strcmp(str,keyword[j])==0) 64 | { 65 | flag=1; 66 | break; 67 | } 68 | } 69 | 70 | if(flag==1) 71 | { 72 | fprintf(output,"%7d\t\t %7d\t\t Keyword\t %7s\n",l,t,str); 73 | t++; 74 | } 75 | 76 | else 77 | { 78 | fprintf(output,"%7d\t\t %7d\t\t Identifier\t %7s\n",l,t,str); 79 | t++; 80 | } 81 | 82 | } 83 | 84 | else if(ch=='\n') 85 | 86 | { 87 | l++; 88 | } 89 | } 90 | 91 | fclose(input); 92 | fclose(output); 93 | return 0; 94 | 95 | } 96 | -------------------------------------------------------------------------------- /Lexical-Analayzer-Using-C/output.txt: -------------------------------------------------------------------------------- 1 | Line no. Token no. Token Lexeme 2 | 3 | 1 0 Identifier include 4 | 1 1 Identifier stdio 5 | 1 2 Identifier h 6 | 2 3 Identifier void 7 | 2 4 Keyword main 8 | 2 5 Special symbol ) 9 | 3 6 Special symbol { 10 | 4 7 Identifier printf 11 | 4 8 Identifier Hello 12 | 4 9 Identifier World 13 | 4 10 Special symbol ) 14 | 4 11 Special symbol ; 15 | 5 12 Special symbol } 16 | -------------------------------------------------------------------------------- /Lexical-Analyzer-Using-LEX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Lexical-Analyzer-Using-LEX/a.out -------------------------------------------------------------------------------- /Lexical-Analyzer-Using-LEX/la.l: -------------------------------------------------------------------------------- 1 | 2 | %{ 3 | int COMMENT=0; 4 | %} 5 | 6 | 7 | identifier [a-zA-Z][a-zA-Z0-9]* 8 | 9 | 10 | %% 11 | #.* {printf("\n%s is a preprocessor directive",yytext);} 12 | int | 13 | float | 14 | char | 15 | double | 16 | while | 17 | for | 18 | struct | 19 | typedef | 20 | do | 21 | if | 22 | break | 23 | continue | 24 | void | 25 | switch | 26 | return | 27 | else | 28 | goto {printf("\n\t%s is a keyword",yytext);} 29 | "/*" {COMMENT=1;}{printf("\n\t %s is a COMMENT",yytext);} 30 | {identifier}\( {if(!COMMENT)printf("\nFUNCTION \n\t%s",yytext);} 31 | \{ {if(!COMMENT)printf("\n BLOCK BEGINS");} 32 | \} {if(!COMMENT)printf("BLOCK ENDS ");} 33 | {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);} 34 | \".*\" {if(!COMMENT)printf("\n\t %s is a STRING",yytext);} 35 | [0-9]+ {if(!COMMENT) printf("\n %s is a NUMBER ",yytext);} 36 | \)(\:)? {if(!COMMENT)printf("\n\t");ECHO;printf("\n");} 37 | \( ECHO; 38 | = {if(!COMMENT)printf("\n\t %s is an ASSIGNMENT OPERATOR",yytext);} 39 | \<= | 40 | \>= | 41 | \< | 42 | == | 43 | \> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);} 44 | %% 45 | 46 | 47 | int main(int argc, char **argv) 48 | { 49 | FILE *file; 50 | file=fopen("var.c","r"); 51 | if(!file) 52 | { 53 | printf("could not open the file"); 54 | exit(0); 55 | } 56 | yyin=file; 57 | yylex(); 58 | printf("\n"); 59 | return(0); 60 | } 61 | int yywrap() 62 | { 63 | return(1); 64 | } 65 | 66 | // Compile By 67 | // lex lex.l 68 | // gcc lex.yy.c 69 | // ./a.out -------------------------------------------------------------------------------- /Lexical-Analyzer-Using-LEX/var.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int a,b,c; 7 | a=1; 8 | b=2; 9 | c=a+b; 10 | printf("Sum:%d",c); 11 | } -------------------------------------------------------------------------------- /NFA-to-DFA/Nfa_ip.txt: -------------------------------------------------------------------------------- 1 | 1,2 1 2 | -1 2 3 | -1 -1# 4 | 0 5 | 2 -------------------------------------------------------------------------------- /NFA-to-DFA/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/NFA-to-DFA/a.out -------------------------------------------------------------------------------- /NFA-to-DFA/pgm.c: -------------------------------------------------------------------------------- 1 | #include 2 | int Fa[10][10][10], states[2][10], row = 0, col = 0, sr = 0, sc = 0, th = 0, in, stat, new_state[10][10], max_inp = -1, no_stat; 3 | FILE *fp; 4 | int search(int search_var) 5 | { 6 | int i; 7 | for (i = 0; i < no_stat; i++) 8 | if (search_var == states[1][i]) 9 | return 1; 10 | return 0; 11 | } 12 | int sort(int *arr, int count) 13 | { 14 | int temp, i, j; 15 | for (i = 0; i < count - 1; i++) 16 | { 17 | for (j = i + 1; j < count; j++) 18 | { 19 | if (arr[i] >= arr[j]) 20 | { 21 | temp = arr[i]; 22 | arr[i] = arr[j]; 23 | arr[j] = temp; 24 | } 25 | } 26 | } 27 | return 0; 28 | } 29 | int checkcon(int *arr, int *count) // for doing this {4,1}={1,2,1}=={1,2} 30 | { 31 | int i, temp, j, k, c, t, m; 32 | for (i = 0; i < *count; i++) 33 | { 34 | if (arr[i] > row) 35 | { 36 | temp = arr[i]; 37 | c = 0; 38 | t = 0; 39 | while (new_state[arr[i]][t] != -1) 40 | { 41 | t++; 42 | c++; 43 | } 44 | // right shift from ith postion (c-2) th time 45 | for (k = 0; k <= c - 2; k++) 46 | { 47 | for (j = 9; j >= i + 1 + k; j--) 48 | { 49 | arr[j] = arr[j - 1]; 50 | } 51 | } 52 | t = 0; 53 | for (j = i; j < c; j++) 54 | { 55 | arr[j] = new_state[temp][t]; 56 | t++; 57 | } 58 | } 59 | } 60 | c = 0; 61 | for (i = 0; arr[i] != -1; i++) 62 | c++; 63 | *count = c; 64 | return 0; 65 | } 66 | int remove_duplicate(int *arr, int *count) 67 | { 68 | int i, j = 0; 69 | for (i = 1; i < *count; i++) 70 | { 71 | if (arr[i] != arr[j]) 72 | { 73 | j++; 74 | arr[j] = arr[i]; 75 | } 76 | } 77 | *count = j + 1; 78 | return 0; 79 | } 80 | int check(int i, int j, int c, int *name) /// for checking is this a new state or not 81 | { 82 | int t, l, f; 83 | for (l = 0; l <= stat; l++) 84 | { 85 | t = 0; 86 | f = 0; 87 | while (Fa[i][j][t] != -1) 88 | { 89 | if (Fa[i][j][t] == new_state[l][t]) 90 | t++; 91 | else 92 | { 93 | f = 1; 94 | break; 95 | } 96 | } 97 | if ((t == c) && !f) 98 | { 99 | *name = l; 100 | return 1; 101 | } 102 | } 103 | return 0; 104 | } 105 | int trans(int i ,int j,int t,int c,int *count,int *arr)//transition o/p for particular i/p on states 106 | { 107 | int k = 0, co, temp; 108 | *count = 0; 109 | for (k = 0; k < c; k++) 110 | { 111 | temp = Fa[i][j][k]; 112 | co = 0; 113 | while (Fa[temp][t][co] != -1) 114 | { 115 | arr[*count] = Fa[temp][t][co++]; 116 | (*count)++; 117 | } 118 | } 119 | return 0; 120 | } 121 | int nfa2dfa(int start, int end) 122 | { 123 | int j, t, c, i, k, count, arr[10], name, l; 124 | for (i = start; i <= end; i++) 125 | { 126 | for (j = 0; j <= max_inp; j++) 127 | { 128 | c = 0; 129 | t = 0; 130 | while (Fa[i][j][t] >= 0) 131 | { 132 | t++; 133 | c++; 134 | } 135 | if (c > 1) 136 | { 137 | if (check(i, j, c, &name) == 0) 138 | { 139 | for (k = 0; k < c; k++) 140 | { 141 | new_state[stat][k] = Fa[i][j][k]; 142 | for (l = 0; states[1][l] != -1; l++) 143 | if (new_state[stat][k] == states[1][l] && !search(stat)) 144 | states[1][no_stat++] = stat; 145 | } 146 | for (t = 0; t <= max_inp; t++) 147 | { 148 | count = 0; 149 | for (k = 0; k < 10; k++) 150 | arr[k] = -1; 151 | trans(i, j, t, c, &count, arr); 152 | checkcon(arr, &count); 153 | sort(arr, count); 154 | remove_duplicate(arr, &count); 155 | for (k = 0; k < count; k++) 156 | Fa[stat][t][k] = arr[k]; 157 | } 158 | Fa[i][j][0] = stat++; 159 | for (t = 1; t < c; t++) 160 | Fa[i][j][t] = -1; 161 | } 162 | else 163 | { 164 | Fa[i][j][0] = name; 165 | for (t = 1; t < c; t++) 166 | Fa[i][j][t] = -1; 167 | } 168 | } 169 | } 170 | } 171 | return 0; 172 | } 173 | int main() 174 | { 175 | int i, j, k, flag = 0, start, end; 176 | char c, ch; 177 | fp = fopen("Nfa_ip.txt", "r+"); 178 | for (i = 0; i < 2; i++) 179 | for (j = 0; j < 10; j++) 180 | states[i][j] = -1; 181 | for (i = 0; i < 10; i++) 182 | for (j = 0; j < 10; j++) 183 | new_state[i][j] = -1; 184 | for (i = 0; i < 10; i++) 185 | for (j = 0; j < 10; j++) 186 | for (k = 0; k < 10; k++) 187 | Fa[i][j][k] = -1; 188 | while (fscanf(fp, "%d", &in) != EOF) 189 | { 190 | fscanf(fp, "%c", &c); 191 | if (flag) 192 | { 193 | states[sr][sc++] = in; 194 | if (c == '\n') 195 | { 196 | sr++; 197 | sc = 0; 198 | } 199 | } 200 | else if (c == '#') 201 | { 202 | flag = 1; 203 | Fa[row][col][th] = in; 204 | } 205 | else if (!flag) 206 | { 207 | Fa[row][col][th] = in; 208 | if (c == ',') 209 | { 210 | th++; 211 | } 212 | else if (c == '\n') 213 | { 214 | if (max_inp < col) 215 | max_inp = col; 216 | col = 0; 217 | row++; 218 | th = 0; 219 | } 220 | else if (c != ',') 221 | { 222 | col++; 223 | th = 0; 224 | } 225 | } 226 | } 227 | no_stat = 0; 228 | i = 0; 229 | while (states[1][i++] != -1) 230 | no_stat++; 231 | stat = row + 1; 232 | start = 0; 233 | end = row; 234 | while (1) 235 | { 236 | nfa2dfa(start, end); 237 | start = end + 1; 238 | end = row; 239 | if (start > end) 240 | break; 241 | } 242 | printf("\n\nDFA IS : \n\n\n"); 243 | for (i = 0; i <= max_inp; i++) 244 | printf("\t%d", i); 245 | printf("\n"); 246 | printf("----------------------------\n"); 247 | for (i = 0; i < stat; i++) 248 | { 249 | printf("%d-> |", i); 250 | for (j = 0; j <= max_inp; j++) 251 | { 252 | printf("%2d ", Fa[i][j][0]); 253 | } 254 | printf("\n"); 255 | } 256 | printf("\n\n"); 257 | printf("Total Number Of State Is : %d \n\n", stat); 258 | printf("Final States Are : "); 259 | for (i = 0; states[1][i] != -1; i++) 260 | printf("%d ", states[1][i]); 261 | printf("\n\n"); 262 | return 0; 263 | } 264 | 265 | //Algorithm for NFA to DFA conversion 266 | 267 | 268 | 269 | //Example -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | CSL411 Compiler Lab 5 | 6 |

7 | 8 | 9 | 10 | 11 |
12 | 13 | This repository contains a collection of programs written as part of KTU CSL411 Compiler Lab 14 | 15 |
16 | 17 | 18 | 19 | 20 | ### Compiler Design Programs 21 | 22 | 1. Design and implement a lexical analyzer using C language to recognize all valid tokens in the input program. The lexical analyzer should ignore redundant spaces, tabs and newlines. It should also ignore comments. 23 | [Link](/Lexical-Analayzer-Using-C) 24 | 2. LEX Programs
25 | - LEX Program to count the numbers of lines, words, spaces, and characters in a given statement [Link](/LEX-Count)
26 | - LEX Program to convert the substring abc to ABC from the given input string.[Link](/LEX-Substring)
27 | - LEX program to find out total number of vowels and consonants from the given input sting.[Link](/LEX-Vowels)
28 | 29 | 3. YACC Programs
30 | - Generate a YACC specification to recognize a valid arithmetic expression that uses 31 | operators +, – , *,/ and parenthesis. [Link](/YACC-Valid-Expressions)
32 | - Generate a YACC specification to recognize a valid identifier which starts with a letter 33 | followed by any number of letters or digits. [Link](/YACC-Valid-Identifiers)
34 | - Implementation of Calculator using LEX and YACC. [Link](/YACC-Calculator)
35 | 36 | 4. [First & Follow](/First-Follow/) 37 | 5. [Shift Reduce Parser](/Shift-Reduce-Parser/) 38 | 6. [Recursive Descent Parser](/Recursive_Descent_Parser/) 39 | 7. [Intermediate Code Generator](/Intermediate_Code_Generator/) 40 | 8. [Constant Propagation](/Constant-Propagation/) 41 | 9. [Assembly Language Generator](/Assembly_Language_Generator/) 42 | 10. [NFA to DFA](/NFA-to-DFA/) 43 | 11. [Lexical Analyzer Using LEX](/Lexical-Analyzer-Using-LEX/) 44 | 45 | 46 | -------------------------------------------------------------------------------- /Recursive_Descent_Parser/RDP.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "string.h" 3 | #include "stdlib.h" 4 | #include "ctype.h" 5 | 6 | char ip_sym[15], ip_ptr = 0, op[50], tmp[50]; 7 | void e_prime(); 8 | void e(); 9 | void t_prime(); 10 | void t(); 11 | void f(); 12 | void advance(); 13 | int n = 0; 14 | void e() 15 | { 16 | strcpy(op, "TE'"); 17 | printf("E=%-25s", op); 18 | printf("E->TE'\n"); 19 | t(); 20 | e_prime(); 21 | } 22 | 23 | void e_prime() 24 | { 25 | int i, n = 0, l; 26 | for (i = 0; i <= strlen(op); i++) 27 | if (op[i] != 'e') 28 | tmp[n++] = op[i]; 29 | strcpy(op, tmp); 30 | l = strlen(op); 31 | for (n = 0; n < l && op[n] != 'E'; n++) 32 | ; 33 | if (ip_sym[ip_ptr] == '+') 34 | { 35 | i = n + 2; 36 | do 37 | { 38 | op[i + 2] = op[i]; 39 | i++; 40 | } while (i <= l); 41 | op[n++] = '+'; 42 | op[n++] = 'T'; 43 | op[n++] = 'E'; 44 | op[n++] = 39; 45 | printf("E=%-25s", op); 46 | printf("E'->+TE'\n"); 47 | advance(); 48 | t(); 49 | e_prime(); 50 | } 51 | else 52 | { 53 | op[n] = 'e'; 54 | for (i = n + 1; i <= strlen(op); i++) 55 | op[i] = op[i + 1]; 56 | printf("E=%-25s", op); 57 | printf("E'->e"); 58 | } 59 | } 60 | void t() 61 | { 62 | int i, n = 0, l; 63 | for (i = 0; i <= strlen(op); i++) 64 | if (op[i] != 'e') 65 | tmp[n++] = op[i]; 66 | strcpy(op, tmp); 67 | l = strlen(op); 68 | for (n = 0; n < l && op[n] != 'T'; n++) 69 | ; 70 | 71 | i = n + 1; 72 | do 73 | { 74 | op[i + 2] = op[i]; 75 | i++; 76 | } while (i < l); 77 | op[n++] = 'F'; 78 | op[n++] = 'T'; 79 | op[n++] = 39; 80 | printf("E=%-25s", op); 81 | printf("T->FT'\n"); 82 | f(); 83 | t_prime(); 84 | } 85 | 86 | void t_prime() 87 | { 88 | int i, n = 0, l; 89 | for (i = 0; i <= strlen(op); i++) 90 | if (op[i] != 'e') 91 | tmp[n++] = op[i]; 92 | strcpy(op, tmp); 93 | l = strlen(op); 94 | for (n = 0; n < l && op[n] != 'T'; n++) 95 | ; 96 | if (ip_sym[ip_ptr] == '*') 97 | { 98 | i = n + 2; 99 | do 100 | { 101 | op[i + 2] = op[i]; 102 | i++; 103 | } while (i < l); 104 | op[n++] = '*'; 105 | op[n++] = 'F'; 106 | op[n++] = 'T'; 107 | op[n++] = 39; 108 | printf("E=%-25s", op); 109 | printf("T'->*FT'\n"); 110 | advance(); 111 | f(); 112 | t_prime(); 113 | } 114 | else 115 | { 116 | op[n] = 'e'; 117 | for (i = n + 1; i <= strlen(op); i++) 118 | op[i] = op[i + 1]; 119 | printf("E=%-25s", op); 120 | printf("T'->e\n"); 121 | } 122 | } 123 | 124 | void f() 125 | { 126 | int i, n = 0, l; 127 | for (i = 0; i <= strlen(op); i++) 128 | if (op[i] != 'e') 129 | tmp[n++] = op[i]; 130 | strcpy(op, tmp); 131 | l = strlen(op); 132 | for (n = 0; n < l && op[n] != 'F'; n++) 133 | ; 134 | if ((ip_sym[ip_ptr] == 'i') || (ip_sym[ip_ptr] == 'I')) 135 | { 136 | op[n] = 'i'; 137 | printf("E=%-25s", op); 138 | printf("F->i\n"); 139 | advance(); 140 | } 141 | else 142 | { 143 | if (ip_sym[ip_ptr] == '(') 144 | { 145 | advance(); 146 | e(); 147 | if (ip_sym[ip_ptr] == ')') 148 | { 149 | advance(); 150 | i = n + 2; 151 | do 152 | { 153 | op[i + 2] = op[i]; 154 | i++; 155 | } while (i <= l); 156 | op[n++] = '('; 157 | op[n++] = 'E'; 158 | op[n++] = ')'; 159 | printf("E=%-25s", op); 160 | printf("F->(E)\n"); 161 | } 162 | } 163 | else 164 | { 165 | printf("\n\t syntax error"); 166 | 167 | exit(1); 168 | } 169 | } 170 | } 171 | 172 | void advance() 173 | { 174 | ip_ptr++; 175 | } 176 | 177 | void main() 178 | { 179 | int i; 180 | 181 | printf("\nGrammar without left recursion"); 182 | printf("\n\t\t E->TE' \n\t\t E'->+TE'|e \n\t\t T->FT' "); 183 | printf("\n\t\t T'->*FT'|e \n\t\t F->(E)|i"); 184 | printf("\n Enter the input expression:"); 185 | scanf("%s", ip_sym); 186 | printf("Expressions"); 187 | printf("\t Sequence of production rules\n"); 188 | e(); 189 | for (i = 0; i < strlen(ip_sym); i++) 190 | { 191 | if (ip_sym[i] != '+' && ip_sym[i] != '*' && ip_sym[i] != '(' && 192 | ip_sym[i] != ')' && ip_sym[i] != 'i' && ip_sym[i] != 'I') 193 | { 194 | printf("\nSyntax error"); 195 | break; 196 | } 197 | for (i = 0; i <= strlen(op); i++) 198 | if (op[i] != 'e') 199 | tmp[n++] = op[i]; 200 | strcpy(op, tmp); 201 | printf("\nE=%-25s", op); 202 | } 203 | printf("\n"); 204 | } 205 | 206 | // Algorithm for Recursive Descent Parser 207 | 208 | 209 | 210 | -------------------------------------------------------------------------------- /Recursive_Descent_Parser/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/Recursive_Descent_Parser/a.out -------------------------------------------------------------------------------- /Recursive_Descent_Parser/parser.c: -------------------------------------------------------------------------------- 1 | // C program to Construct of recursive descent parsing for 2 | // the following grammar 3 | // E->TE’ 4 | // E’->+TE/@ 5 | // T->FT’ 6 | // T`->*FT’/@ 7 | // F->(E)/id where @ represents null character 8 | 9 | #include 10 | #include 11 | #include 12 | char input[100]; 13 | int i, l; 14 | 15 | int E(); 16 | int EP(); 17 | int T(); 18 | int TP(); 19 | int F(); 20 | 21 | 22 | void main() 23 | { 24 | printf("\nRecursive descent parsing for the following grammar\n"); 25 | printf("\nE->TE'\nE'->+TE'/@\nT->FT'\nT'->*FT'/@\nF->(E)/ID\n"); 26 | printf("\nEnter the string to be checked:"); 27 | scanf("%s", input); 28 | if (E()) 29 | { 30 | if (input[i + 1] == '\0') 31 | printf("\nString is accepted"); 32 | else 33 | printf("\nString is not accepted"); 34 | } 35 | else 36 | printf("\nString not accepted"); 37 | } 38 | int E() 39 | { 40 | if (T()) 41 | { 42 | if (EP()) 43 | return (1); 44 | else 45 | return (0); 46 | } 47 | else 48 | return (0); 49 | } 50 | int EP() 51 | { 52 | if (input[i] == '+') 53 | { 54 | i++; 55 | if (T()) 56 | { 57 | if (EP()) 58 | return (1); 59 | else 60 | return (0); 61 | } 62 | else 63 | return (0); 64 | } 65 | else 66 | return (1); 67 | } 68 | int T() 69 | { 70 | if (F()) 71 | { 72 | if (TP()) 73 | return (1); 74 | else 75 | return (0); 76 | } 77 | else 78 | return (0); 79 | } 80 | int TP() 81 | { 82 | if (input[i] == '*') 83 | { 84 | i++; 85 | if (F()) 86 | { 87 | if (TP()) 88 | return (1); 89 | else 90 | return (0); 91 | } 92 | else 93 | return (0); 94 | } 95 | else 96 | return (1); 97 | } 98 | int F() 99 | { 100 | if (input[i] == '(') 101 | { 102 | i++; 103 | if (E()) 104 | { 105 | if (input[i] == ')') 106 | { 107 | i++; 108 | return (1); 109 | } 110 | else 111 | return (0); 112 | } 113 | else 114 | return (0); 115 | } 116 | else if (input[i] >= 'a' && input[i] <= 'z' || input[i] >= 'A' && input[i] <= 'Z') 117 | { 118 | i++; 119 | return (1); 120 | } 121 | else 122 | return (0); 123 | } -------------------------------------------------------------------------------- /Shift-Reduce-Parser/4-srp.c: -------------------------------------------------------------------------------- 1 | // Grammar: E->2E2|3E3|4 2 | #include 3 | #include 4 | #include 5 | 6 | void main() { 7 | char buff[100]; 8 | char rules[3][10] = {"2E2", "3E3", "4"}; 9 | char stack[100]; 10 | int top = -1; 11 | 12 | printf("Input String: "); 13 | scanf("%s", buff); 14 | strcat(buff, "$"); 15 | 16 | int index = 0; 17 | 18 | do { 19 | if (top != -1) { 20 | int i; 21 | for (i = 0; i < 3; ++i) 22 | if (strstr(stack, rules[i]) != NULL) 23 | break; 24 | if (i < 3) { 25 | // Reduce 26 | char *p; 27 | p = strstr(stack, rules[i]); 28 | p[0] = 'E'; 29 | //while (&(stack[top]) != p) 30 | // stack[top--] = '\0'; 31 | p[1] = '\0'; 32 | top = (int)(p - stack); 33 | } 34 | else { 35 | // Shift 36 | stack[++top] = buff[index++]; 37 | stack[top + 1] = '\0'; 38 | 39 | } 40 | } 41 | else { 42 | // Input is finished 43 | if (buff[index] == '$') 44 | break; 45 | 46 | // Else shift again... 47 | stack[++top] = buff[index++]; 48 | stack[top + 1] = '\0'; 49 | } 50 | } while (index > 0 && buff[index - 1] != '$'); 51 | 52 | if (strcmp(stack, "E$") == 0) 53 | printf("String Accepted\n"); 54 | else 55 | printf("String Rejected\n"); 56 | } 57 | -------------------------------------------------------------------------------- /Shift-Reduce-Parser/SRP.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int k = 0, z = 0, i = 0, j = 0, c = 0; 4 | char a[16], ac[20], stk[15], act[10]; 5 | void check(); 6 | int main() 7 | { 8 | 9 | puts("GRAMMAR is E->E+E \n E->E*E \n E->(E) \n E->id"); 10 | puts("enter input string "); 11 | scanf("%s", a); 12 | c = strlen(a); 13 | strcpy(act, "SHIFT->"); 14 | puts("stack \t input \t action"); 15 | for (k = 0, i = 0; j < c; k++, i++, j++) 16 | { 17 | if (a[j] == 'i' && a[j + 1] == 'd') 18 | { 19 | stk[i] = a[j]; 20 | stk[i + 1] = a[j + 1]; 21 | stk[i + 2] = '\0'; 22 | a[j] = ' '; 23 | a[j + 1] = ' '; 24 | printf("\n$%s\t%s$\t%sid", stk, a, act); 25 | check(); 26 | } 27 | else 28 | { 29 | stk[i] = a[j]; 30 | stk[i + 1] = '\0'; 31 | a[j] = ' '; 32 | printf("\n$%s\t%s$\t%ssymbols", stk, a, act); 33 | check(); 34 | } 35 | } 36 | printf("\n"); 37 | } 38 | void check() 39 | { 40 | strcpy(ac, "REDUCE TO E"); 41 | for (z = 0; z < c; z++) 42 | if (stk[z] == 'i' && stk[z + 1] == 'd') 43 | { 44 | stk[z] = 'E'; 45 | stk[z + 1] = '\0'; 46 | printf("\n$%s\t%s$\t%s", stk, a, ac); 47 | j++; 48 | } 49 | for (z = 0; z < c; z++) 50 | if (stk[z] == 'E' && stk[z + 1] == '+' && stk[z + 2] == 'E') 51 | { 52 | stk[z] = 'E'; 53 | stk[z + 1] = '\0'; 54 | stk[z + 2] = '\0'; 55 | printf("\n$%s\t%s$\t%s", stk, a, ac); 56 | i = i - 2; 57 | } 58 | for (z = 0; z < c; z++) 59 | if (stk[z] == 'E' && stk[z + 1] == '*' && stk[z + 2] == 'E') 60 | { 61 | stk[z] = 'E'; 62 | stk[z + 1] = '\0'; 63 | stk[z + 1] = '\0'; 64 | printf("\n$%s\t%s$\t%s", stk, a, ac); 65 | i = i - 2; 66 | } 67 | for (z = 0; z < c; z++) 68 | if (stk[z] == '(' && stk[z + 1] == 'E' && stk[z + 2] == ')') 69 | { 70 | stk[z] = 'E'; 71 | stk[z + 1] = '\0'; 72 | stk[z + 1] = '\0'; 73 | printf("\n$%s\t%s$\t%s", stk, a, ac); 74 | i = i - 2; 75 | } 76 | } -------------------------------------------------------------------------------- /YACC-Calculator/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/YACC-Calculator/a.out -------------------------------------------------------------------------------- /YACC-Calculator/cal.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | #include "y.tab.h" 6 | 7 | extern int yylval; 8 | 9 | %} 10 | 11 | 12 | 13 | %% 14 | 15 | [0-9]+ { 16 | 17 | yylval=atoi(yytext); 18 | 19 | return NUMBER; 20 | 21 | } 22 | 23 | [\t] ; 24 | 25 | [\n] return 0; 26 | 27 | . return yytext[0]; 28 | 29 | %% 30 | 31 | int yywrap() 32 | 33 | { 34 | 35 | return 1; 36 | 37 | } 38 | 39 | 40 | /* tO cOMPILE 41 | 42 | yacc -d calc.y 43 | lex calc.l 44 | gcc lex.yy.c y.tab.c -w 45 | ./a.out 46 | */ 47 | 48 | // Algorithm YACC & LEX Calculator 49 | 50 | // 1. Start 51 | // 2. Read the expression 52 | // 3. Check for the valid expression matching the grammar 53 | // 4. If the expression is valid, then evaluate the expression 54 | // 5. If the expression is invalid, then display the error message 55 | // 6. Stop -------------------------------------------------------------------------------- /YACC-Calculator/cal.y: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | int flag=0; 6 | 7 | 8 | %} 9 | 10 | %token NUMBER 11 | 12 | 13 | 14 | %left '+' '-' 15 | 16 | %left '*' '/' '%' 17 | 18 | %left '(' ')' 19 | 20 | %% 21 | 22 | ArithmeticExpression: E{ 23 | 24 | printf("\nResult=%d\n",$$); 25 | 26 | return 0; 27 | 28 | }; 29 | 30 | E:E'+'E {$$=$1+$3;} 31 | 32 | |E'-'E {$$=$1-$3;} 33 | 34 | |E'*'E {$$=$1*$3;} 35 | 36 | |E'/'E {$$=$1/$3;} 37 | 38 | |E'%'E {$$=$1%$3;} 39 | 40 | |'('E')' {$$=$2;} 41 | 42 | | NUMBER {$$=$1;} 43 | 44 | ; 45 | 46 | %% 47 | 48 | 49 | 50 | void main() 51 | 52 | { 53 | 54 | printf("\nEnter Any Arithmetic Expression which can have operations Addition, Subtraction, Multiplication, Divison, Modulus and Round brackets:\n"); 55 | 56 | yyparse(); 57 | 58 | if(flag==0) 59 | 60 | printf("\nEntered arithmetic expression is Valid\n\n"); 61 | 62 | } 63 | 64 | void yyerror() 65 | 66 | { 67 | 68 | printf("\nEntered arithmetic expression is Invalid\n\n"); 69 | 70 | flag=1; 71 | 72 | } 73 | 74 | 75 | /* tO cOMPILE 76 | 77 | yacc -d calc.y 78 | lex calc.l 79 | gcc lex.yy.c y.tab.c -w 80 | ./a.out 81 | */ -------------------------------------------------------------------------------- /YACC-Calculator/y.tab.c: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison implementation for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* C LALR(1) parser skeleton written by Richard Stallman, by 35 | simplifying the original so-called "semantic" parser. */ 36 | 37 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 38 | especially those whose name start with YY_ or yy_. They are 39 | private implementation details that can be changed or removed. */ 40 | 41 | /* All symbols defined below should begin with yy or YY, to avoid 42 | infringing on user name space. This should be done even for local 43 | variables, as they might otherwise be expanded by user macros. 44 | There are some unavoidable exceptions within include files to 45 | define necessary library symbols; they are noted "INFRINGES ON 46 | USER NAME SPACE" below. */ 47 | 48 | /* Identify Bison output, and Bison version. */ 49 | #define YYBISON 30802 50 | 51 | /* Bison version string. */ 52 | #define YYBISON_VERSION "3.8.2" 53 | 54 | /* Skeleton name. */ 55 | #define YYSKELETON_NAME "yacc.c" 56 | 57 | /* Pure parsers. */ 58 | #define YYPURE 0 59 | 60 | /* Push parsers. */ 61 | #define YYPUSH 0 62 | 63 | /* Pull parsers. */ 64 | #define YYPULL 1 65 | 66 | 67 | 68 | 69 | /* First part of user prologue. */ 70 | #line 1 "cal.y" 71 | 72 | 73 | #include 74 | 75 | int flag=0; 76 | 77 | 78 | 79 | #line 80 "y.tab.c" 80 | 81 | # ifndef YY_CAST 82 | # ifdef __cplusplus 83 | # define YY_CAST(Type, Val) static_cast (Val) 84 | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) 85 | # else 86 | # define YY_CAST(Type, Val) ((Type) (Val)) 87 | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) 88 | # endif 89 | # endif 90 | # ifndef YY_NULLPTR 91 | # if defined __cplusplus 92 | # if 201103L <= __cplusplus 93 | # define YY_NULLPTR nullptr 94 | # else 95 | # define YY_NULLPTR 0 96 | # endif 97 | # else 98 | # define YY_NULLPTR ((void*)0) 99 | # endif 100 | # endif 101 | 102 | /* Use api.header.include to #include this header 103 | instead of duplicating it here. */ 104 | #ifndef YY_YY_Y_TAB_H_INCLUDED 105 | # define YY_YY_Y_TAB_H_INCLUDED 106 | /* Debug traces. */ 107 | #ifndef YYDEBUG 108 | # define YYDEBUG 0 109 | #endif 110 | #if YYDEBUG 111 | extern int yydebug; 112 | #endif 113 | 114 | /* Token kinds. */ 115 | #ifndef YYTOKENTYPE 116 | # define YYTOKENTYPE 117 | enum yytokentype 118 | { 119 | YYEMPTY = -2, 120 | YYEOF = 0, /* "end of file" */ 121 | YYerror = 256, /* error */ 122 | YYUNDEF = 257, /* "invalid token" */ 123 | NUMBER = 258 /* NUMBER */ 124 | }; 125 | typedef enum yytokentype yytoken_kind_t; 126 | #endif 127 | /* Token kinds. */ 128 | #define YYEMPTY -2 129 | #define YYEOF 0 130 | #define YYerror 256 131 | #define YYUNDEF 257 132 | #define NUMBER 258 133 | 134 | /* Value type. */ 135 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 136 | typedef int YYSTYPE; 137 | # define YYSTYPE_IS_TRIVIAL 1 138 | # define YYSTYPE_IS_DECLARED 1 139 | #endif 140 | 141 | 142 | extern YYSTYPE yylval; 143 | 144 | 145 | int yyparse (void); 146 | 147 | 148 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 149 | /* Symbol kind. */ 150 | enum yysymbol_kind_t 151 | { 152 | YYSYMBOL_YYEMPTY = -2, 153 | YYSYMBOL_YYEOF = 0, /* "end of file" */ 154 | YYSYMBOL_YYerror = 1, /* error */ 155 | YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ 156 | YYSYMBOL_NUMBER = 3, /* NUMBER */ 157 | YYSYMBOL_4_ = 4, /* '+' */ 158 | YYSYMBOL_5_ = 5, /* '-' */ 159 | YYSYMBOL_6_ = 6, /* '*' */ 160 | YYSYMBOL_7_ = 7, /* '/' */ 161 | YYSYMBOL_8_ = 8, /* '%' */ 162 | YYSYMBOL_9_ = 9, /* '(' */ 163 | YYSYMBOL_10_ = 10, /* ')' */ 164 | YYSYMBOL_YYACCEPT = 11, /* $accept */ 165 | YYSYMBOL_ArithmeticExpression = 12, /* ArithmeticExpression */ 166 | YYSYMBOL_E = 13 /* E */ 167 | }; 168 | typedef enum yysymbol_kind_t yysymbol_kind_t; 169 | 170 | 171 | 172 | 173 | #ifdef short 174 | # undef short 175 | #endif 176 | 177 | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure 178 | and (if available) are included 179 | so that the code can choose integer types of a good width. */ 180 | 181 | #ifndef __PTRDIFF_MAX__ 182 | # include /* INFRINGES ON USER NAME SPACE */ 183 | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 184 | # include /* INFRINGES ON USER NAME SPACE */ 185 | # define YY_STDINT_H 186 | # endif 187 | #endif 188 | 189 | /* Narrow types that promote to a signed type and that can represent a 190 | signed or unsigned integer of at least N bits. In tables they can 191 | save space and decrease cache pressure. Promoting to a signed type 192 | helps avoid bugs in integer arithmetic. */ 193 | 194 | #ifdef __INT_LEAST8_MAX__ 195 | typedef __INT_LEAST8_TYPE__ yytype_int8; 196 | #elif defined YY_STDINT_H 197 | typedef int_least8_t yytype_int8; 198 | #else 199 | typedef signed char yytype_int8; 200 | #endif 201 | 202 | #ifdef __INT_LEAST16_MAX__ 203 | typedef __INT_LEAST16_TYPE__ yytype_int16; 204 | #elif defined YY_STDINT_H 205 | typedef int_least16_t yytype_int16; 206 | #else 207 | typedef short yytype_int16; 208 | #endif 209 | 210 | /* Work around bug in HP-UX 11.23, which defines these macros 211 | incorrectly for preprocessor constants. This workaround can likely 212 | be removed in 2023, as HPE has promised support for HP-UX 11.23 213 | (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of 214 | . */ 215 | #ifdef __hpux 216 | # undef UINT_LEAST8_MAX 217 | # undef UINT_LEAST16_MAX 218 | # define UINT_LEAST8_MAX 255 219 | # define UINT_LEAST16_MAX 65535 220 | #endif 221 | 222 | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ 223 | typedef __UINT_LEAST8_TYPE__ yytype_uint8; 224 | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ 225 | && UINT_LEAST8_MAX <= INT_MAX) 226 | typedef uint_least8_t yytype_uint8; 227 | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX 228 | typedef unsigned char yytype_uint8; 229 | #else 230 | typedef short yytype_uint8; 231 | #endif 232 | 233 | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ 234 | typedef __UINT_LEAST16_TYPE__ yytype_uint16; 235 | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ 236 | && UINT_LEAST16_MAX <= INT_MAX) 237 | typedef uint_least16_t yytype_uint16; 238 | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX 239 | typedef unsigned short yytype_uint16; 240 | #else 241 | typedef int yytype_uint16; 242 | #endif 243 | 244 | #ifndef YYPTRDIFF_T 245 | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ 246 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ 247 | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ 248 | # elif defined PTRDIFF_MAX 249 | # ifndef ptrdiff_t 250 | # include /* INFRINGES ON USER NAME SPACE */ 251 | # endif 252 | # define YYPTRDIFF_T ptrdiff_t 253 | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX 254 | # else 255 | # define YYPTRDIFF_T long 256 | # define YYPTRDIFF_MAXIMUM LONG_MAX 257 | # endif 258 | #endif 259 | 260 | #ifndef YYSIZE_T 261 | # ifdef __SIZE_TYPE__ 262 | # define YYSIZE_T __SIZE_TYPE__ 263 | # elif defined size_t 264 | # define YYSIZE_T size_t 265 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 266 | # include /* INFRINGES ON USER NAME SPACE */ 267 | # define YYSIZE_T size_t 268 | # else 269 | # define YYSIZE_T unsigned 270 | # endif 271 | #endif 272 | 273 | #define YYSIZE_MAXIMUM \ 274 | YY_CAST (YYPTRDIFF_T, \ 275 | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ 276 | ? YYPTRDIFF_MAXIMUM \ 277 | : YY_CAST (YYSIZE_T, -1))) 278 | 279 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) 280 | 281 | 282 | /* Stored state numbers (used for stacks). */ 283 | typedef yytype_int8 yy_state_t; 284 | 285 | /* State numbers in computations. */ 286 | typedef int yy_state_fast_t; 287 | 288 | #ifndef YY_ 289 | # if defined YYENABLE_NLS && YYENABLE_NLS 290 | # if ENABLE_NLS 291 | # include /* INFRINGES ON USER NAME SPACE */ 292 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 293 | # endif 294 | # endif 295 | # ifndef YY_ 296 | # define YY_(Msgid) Msgid 297 | # endif 298 | #endif 299 | 300 | 301 | #ifndef YY_ATTRIBUTE_PURE 302 | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) 303 | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) 304 | # else 305 | # define YY_ATTRIBUTE_PURE 306 | # endif 307 | #endif 308 | 309 | #ifndef YY_ATTRIBUTE_UNUSED 310 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) 311 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 312 | # else 313 | # define YY_ATTRIBUTE_UNUSED 314 | # endif 315 | #endif 316 | 317 | /* Suppress unused-variable warnings by "using" E. */ 318 | #if ! defined lint || defined __GNUC__ 319 | # define YY_USE(E) ((void) (E)) 320 | #else 321 | # define YY_USE(E) /* empty */ 322 | #endif 323 | 324 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ 325 | #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ 326 | # if __GNUC__ * 100 + __GNUC_MINOR__ < 407 327 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 328 | _Pragma ("GCC diagnostic push") \ 329 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") 330 | # else 331 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 332 | _Pragma ("GCC diagnostic push") \ 333 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ 334 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 335 | # endif 336 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 337 | _Pragma ("GCC diagnostic pop") 338 | #else 339 | # define YY_INITIAL_VALUE(Value) Value 340 | #endif 341 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 342 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 343 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END 344 | #endif 345 | #ifndef YY_INITIAL_VALUE 346 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ 347 | #endif 348 | 349 | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 350 | # define YY_IGNORE_USELESS_CAST_BEGIN \ 351 | _Pragma ("GCC diagnostic push") \ 352 | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") 353 | # define YY_IGNORE_USELESS_CAST_END \ 354 | _Pragma ("GCC diagnostic pop") 355 | #endif 356 | #ifndef YY_IGNORE_USELESS_CAST_BEGIN 357 | # define YY_IGNORE_USELESS_CAST_BEGIN 358 | # define YY_IGNORE_USELESS_CAST_END 359 | #endif 360 | 361 | 362 | #define YY_ASSERT(E) ((void) (0 && (E))) 363 | 364 | #if !defined yyoverflow 365 | 366 | /* The parser invokes alloca or malloc; define the necessary symbols. */ 367 | 368 | # ifdef YYSTACK_USE_ALLOCA 369 | # if YYSTACK_USE_ALLOCA 370 | # ifdef __GNUC__ 371 | # define YYSTACK_ALLOC __builtin_alloca 372 | # elif defined __BUILTIN_VA_ARG_INCR 373 | # include /* INFRINGES ON USER NAME SPACE */ 374 | # elif defined _AIX 375 | # define YYSTACK_ALLOC __alloca 376 | # elif defined _MSC_VER 377 | # include /* INFRINGES ON USER NAME SPACE */ 378 | # define alloca _alloca 379 | # else 380 | # define YYSTACK_ALLOC alloca 381 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 382 | # include /* INFRINGES ON USER NAME SPACE */ 383 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 384 | # ifndef EXIT_SUCCESS 385 | # define EXIT_SUCCESS 0 386 | # endif 387 | # endif 388 | # endif 389 | # endif 390 | # endif 391 | 392 | # ifdef YYSTACK_ALLOC 393 | /* Pacify GCC's 'empty if-body' warning. */ 394 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 395 | # ifndef YYSTACK_ALLOC_MAXIMUM 396 | /* The OS might guarantee only one guard page at the bottom of the stack, 397 | and a page size can be as small as 4096 bytes. So we cannot safely 398 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 399 | to allow for a few compiler-allocated temporary stack slots. */ 400 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 401 | # endif 402 | # else 403 | # define YYSTACK_ALLOC YYMALLOC 404 | # define YYSTACK_FREE YYFREE 405 | # ifndef YYSTACK_ALLOC_MAXIMUM 406 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 407 | # endif 408 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ 409 | && ! ((defined YYMALLOC || defined malloc) \ 410 | && (defined YYFREE || defined free))) 411 | # include /* INFRINGES ON USER NAME SPACE */ 412 | # ifndef EXIT_SUCCESS 413 | # define EXIT_SUCCESS 0 414 | # endif 415 | # endif 416 | # ifndef YYMALLOC 417 | # define YYMALLOC malloc 418 | # if ! defined malloc && ! defined EXIT_SUCCESS 419 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 420 | # endif 421 | # endif 422 | # ifndef YYFREE 423 | # define YYFREE free 424 | # if ! defined free && ! defined EXIT_SUCCESS 425 | void free (void *); /* INFRINGES ON USER NAME SPACE */ 426 | # endif 427 | # endif 428 | # endif 429 | #endif /* !defined yyoverflow */ 430 | 431 | #if (! defined yyoverflow \ 432 | && (! defined __cplusplus \ 433 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 434 | 435 | /* A type that is properly aligned for any stack member. */ 436 | union yyalloc 437 | { 438 | yy_state_t yyss_alloc; 439 | YYSTYPE yyvs_alloc; 440 | }; 441 | 442 | /* The size of the maximum gap between one aligned stack and the next. */ 443 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) 444 | 445 | /* The size of an array large to enough to hold all stacks, each with 446 | N elements. */ 447 | # define YYSTACK_BYTES(N) \ 448 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ 449 | + YYSTACK_GAP_MAXIMUM) 450 | 451 | # define YYCOPY_NEEDED 1 452 | 453 | /* Relocate STACK from its old location to the new one. The 454 | local variables YYSIZE and YYSTACKSIZE give the old and new number of 455 | elements in the stack, and YYPTR gives the new location of the 456 | stack. Advance YYPTR to a properly aligned location for the next 457 | stack. */ 458 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 459 | do \ 460 | { \ 461 | YYPTRDIFF_T yynewbytes; \ 462 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 463 | Stack = &yyptr->Stack_alloc; \ 464 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ 465 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ 466 | } \ 467 | while (0) 468 | 469 | #endif 470 | 471 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED 472 | /* Copy COUNT objects from SRC to DST. The source and destination do 473 | not overlap. */ 474 | # ifndef YYCOPY 475 | # if defined __GNUC__ && 1 < __GNUC__ 476 | # define YYCOPY(Dst, Src, Count) \ 477 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) 478 | # else 479 | # define YYCOPY(Dst, Src, Count) \ 480 | do \ 481 | { \ 482 | YYPTRDIFF_T yyi; \ 483 | for (yyi = 0; yyi < (Count); yyi++) \ 484 | (Dst)[yyi] = (Src)[yyi]; \ 485 | } \ 486 | while (0) 487 | # endif 488 | # endif 489 | #endif /* !YYCOPY_NEEDED */ 490 | 491 | /* YYFINAL -- State number of the termination state. */ 492 | #define YYFINAL 6 493 | /* YYLAST -- Last index in YYTABLE. */ 494 | #define YYLAST 26 495 | 496 | /* YYNTOKENS -- Number of terminals. */ 497 | #define YYNTOKENS 11 498 | /* YYNNTS -- Number of nonterminals. */ 499 | #define YYNNTS 3 500 | /* YYNRULES -- Number of rules. */ 501 | #define YYNRULES 9 502 | /* YYNSTATES -- Number of states. */ 503 | #define YYNSTATES 18 504 | 505 | /* YYMAXUTOK -- Last valid token kind. */ 506 | #define YYMAXUTOK 258 507 | 508 | 509 | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 510 | as returned by yylex, with out-of-bounds checking. */ 511 | #define YYTRANSLATE(YYX) \ 512 | (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 513 | ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 514 | : YYSYMBOL_YYUNDEF) 515 | 516 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 517 | as returned by yylex. */ 518 | static const yytype_int8 yytranslate[] = 519 | { 520 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 521 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 522 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 523 | 2, 2, 2, 2, 2, 2, 2, 8, 2, 2, 524 | 9, 10, 6, 4, 2, 5, 2, 7, 2, 2, 525 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 526 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 527 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 528 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 529 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 530 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 531 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 532 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 533 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 534 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 535 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 536 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 537 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 538 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 539 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 540 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 541 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 542 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 543 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 544 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 545 | 2, 2, 2, 2, 2, 2, 1, 2, 3 546 | }; 547 | 548 | #if YYDEBUG 549 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 550 | static const yytype_int8 yyrline[] = 551 | { 552 | 0, 22, 22, 30, 32, 34, 36, 38, 40, 42 553 | }; 554 | #endif 555 | 556 | /** Accessing symbol of state STATE. */ 557 | #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) 558 | 559 | #if YYDEBUG || 0 560 | /* The user-facing name of the symbol whose (internal) number is 561 | YYSYMBOL. No bounds checking. */ 562 | static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 563 | 564 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 565 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 566 | static const char *const yytname[] = 567 | { 568 | "\"end of file\"", "error", "\"invalid token\"", "NUMBER", "'+'", "'-'", 569 | "'*'", "'/'", "'%'", "'('", "')'", "$accept", "ArithmeticExpression", 570 | "E", YY_NULLPTR 571 | }; 572 | 573 | static const char * 574 | yysymbol_name (yysymbol_kind_t yysymbol) 575 | { 576 | return yytname[yysymbol]; 577 | } 578 | #endif 579 | 580 | #define YYPACT_NINF (-6) 581 | 582 | #define yypact_value_is_default(Yyn) \ 583 | ((Yyn) == YYPACT_NINF) 584 | 585 | #define YYTABLE_NINF (-1) 586 | 587 | #define yytable_value_is_error(Yyn) \ 588 | 0 589 | 590 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 591 | STATE-NUM. */ 592 | static const yytype_int8 yypact[] = 593 | { 594 | 12, -6, 12, 4, 18, 6, -6, 12, 12, 12, 595 | 12, 12, -6, -5, -5, -6, -6, -6 596 | }; 597 | 598 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 599 | Performed when YYTABLE does not specify something else to do. Zero 600 | means the default is an error. */ 601 | static const yytype_int8 yydefact[] = 602 | { 603 | 0, 9, 0, 0, 2, 0, 1, 0, 0, 0, 604 | 0, 0, 8, 3, 4, 5, 6, 7 605 | }; 606 | 607 | /* YYPGOTO[NTERM-NUM]. */ 608 | static const yytype_int8 yypgoto[] = 609 | { 610 | -6, -6, -2 611 | }; 612 | 613 | /* YYDEFGOTO[NTERM-NUM]. */ 614 | static const yytype_int8 yydefgoto[] = 615 | { 616 | 0, 3, 4 617 | }; 618 | 619 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 620 | positive, shift that token. If negative, reduce the rule whose 621 | number is the opposite. If YYTABLE_NINF, syntax error. */ 622 | static const yytype_int8 yytable[] = 623 | { 624 | 5, 9, 10, 11, 6, 13, 14, 15, 16, 17, 625 | 7, 8, 9, 10, 11, 1, 12, 0, 0, 0, 626 | 0, 2, 7, 8, 9, 10, 11 627 | }; 628 | 629 | static const yytype_int8 yycheck[] = 630 | { 631 | 2, 6, 7, 8, 0, 7, 8, 9, 10, 11, 632 | 4, 5, 6, 7, 8, 3, 10, -1, -1, -1, 633 | -1, 9, 4, 5, 6, 7, 8 634 | }; 635 | 636 | /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of 637 | state STATE-NUM. */ 638 | static const yytype_int8 yystos[] = 639 | { 640 | 0, 3, 9, 12, 13, 13, 0, 4, 5, 6, 641 | 7, 8, 10, 13, 13, 13, 13, 13 642 | }; 643 | 644 | /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ 645 | static const yytype_int8 yyr1[] = 646 | { 647 | 0, 11, 12, 13, 13, 13, 13, 13, 13, 13 648 | }; 649 | 650 | /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ 651 | static const yytype_int8 yyr2[] = 652 | { 653 | 0, 2, 1, 3, 3, 3, 3, 3, 3, 1 654 | }; 655 | 656 | 657 | enum { YYENOMEM = -2 }; 658 | 659 | #define yyerrok (yyerrstatus = 0) 660 | #define yyclearin (yychar = YYEMPTY) 661 | 662 | #define YYACCEPT goto yyacceptlab 663 | #define YYABORT goto yyabortlab 664 | #define YYERROR goto yyerrorlab 665 | #define YYNOMEM goto yyexhaustedlab 666 | 667 | 668 | #define YYRECOVERING() (!!yyerrstatus) 669 | 670 | #define YYBACKUP(Token, Value) \ 671 | do \ 672 | if (yychar == YYEMPTY) \ 673 | { \ 674 | yychar = (Token); \ 675 | yylval = (Value); \ 676 | YYPOPSTACK (yylen); \ 677 | yystate = *yyssp; \ 678 | goto yybackup; \ 679 | } \ 680 | else \ 681 | { \ 682 | yyerror (YY_("syntax error: cannot back up")); \ 683 | YYERROR; \ 684 | } \ 685 | while (0) 686 | 687 | /* Backward compatibility with an undocumented macro. 688 | Use YYerror or YYUNDEF. */ 689 | #define YYERRCODE YYUNDEF 690 | 691 | 692 | /* Enable debugging if requested. */ 693 | #if YYDEBUG 694 | 695 | # ifndef YYFPRINTF 696 | # include /* INFRINGES ON USER NAME SPACE */ 697 | # define YYFPRINTF fprintf 698 | # endif 699 | 700 | # define YYDPRINTF(Args) \ 701 | do { \ 702 | if (yydebug) \ 703 | YYFPRINTF Args; \ 704 | } while (0) 705 | 706 | 707 | 708 | 709 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 710 | do { \ 711 | if (yydebug) \ 712 | { \ 713 | YYFPRINTF (stderr, "%s ", Title); \ 714 | yy_symbol_print (stderr, \ 715 | Kind, Value); \ 716 | YYFPRINTF (stderr, "\n"); \ 717 | } \ 718 | } while (0) 719 | 720 | 721 | /*-----------------------------------. 722 | | Print this symbol's value on YYO. | 723 | `-----------------------------------*/ 724 | 725 | static void 726 | yy_symbol_value_print (FILE *yyo, 727 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 728 | { 729 | FILE *yyoutput = yyo; 730 | YY_USE (yyoutput); 731 | if (!yyvaluep) 732 | return; 733 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 734 | YY_USE (yykind); 735 | YY_IGNORE_MAYBE_UNINITIALIZED_END 736 | } 737 | 738 | 739 | /*---------------------------. 740 | | Print this symbol on YYO. | 741 | `---------------------------*/ 742 | 743 | static void 744 | yy_symbol_print (FILE *yyo, 745 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 746 | { 747 | YYFPRINTF (yyo, "%s %s (", 748 | yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); 749 | 750 | yy_symbol_value_print (yyo, yykind, yyvaluep); 751 | YYFPRINTF (yyo, ")"); 752 | } 753 | 754 | /*------------------------------------------------------------------. 755 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | 756 | | TOP (included). | 757 | `------------------------------------------------------------------*/ 758 | 759 | static void 760 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) 761 | { 762 | YYFPRINTF (stderr, "Stack now"); 763 | for (; yybottom <= yytop; yybottom++) 764 | { 765 | int yybot = *yybottom; 766 | YYFPRINTF (stderr, " %d", yybot); 767 | } 768 | YYFPRINTF (stderr, "\n"); 769 | } 770 | 771 | # define YY_STACK_PRINT(Bottom, Top) \ 772 | do { \ 773 | if (yydebug) \ 774 | yy_stack_print ((Bottom), (Top)); \ 775 | } while (0) 776 | 777 | 778 | /*------------------------------------------------. 779 | | Report that the YYRULE is going to be reduced. | 780 | `------------------------------------------------*/ 781 | 782 | static void 783 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, 784 | int yyrule) 785 | { 786 | int yylno = yyrline[yyrule]; 787 | int yynrhs = yyr2[yyrule]; 788 | int yyi; 789 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", 790 | yyrule - 1, yylno); 791 | /* The symbols being reduced. */ 792 | for (yyi = 0; yyi < yynrhs; yyi++) 793 | { 794 | YYFPRINTF (stderr, " $%d = ", yyi + 1); 795 | yy_symbol_print (stderr, 796 | YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), 797 | &yyvsp[(yyi + 1) - (yynrhs)]); 798 | YYFPRINTF (stderr, "\n"); 799 | } 800 | } 801 | 802 | # define YY_REDUCE_PRINT(Rule) \ 803 | do { \ 804 | if (yydebug) \ 805 | yy_reduce_print (yyssp, yyvsp, Rule); \ 806 | } while (0) 807 | 808 | /* Nonzero means print parse trace. It is left uninitialized so that 809 | multiple parsers can coexist. */ 810 | int yydebug; 811 | #else /* !YYDEBUG */ 812 | # define YYDPRINTF(Args) ((void) 0) 813 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 814 | # define YY_STACK_PRINT(Bottom, Top) 815 | # define YY_REDUCE_PRINT(Rule) 816 | #endif /* !YYDEBUG */ 817 | 818 | 819 | /* YYINITDEPTH -- initial size of the parser's stacks. */ 820 | #ifndef YYINITDEPTH 821 | # define YYINITDEPTH 200 822 | #endif 823 | 824 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 825 | if the built-in stack extension method is used). 826 | 827 | Do not make this value too large; the results are undefined if 828 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 829 | evaluated with infinite-precision integer arithmetic. */ 830 | 831 | #ifndef YYMAXDEPTH 832 | # define YYMAXDEPTH 10000 833 | #endif 834 | 835 | 836 | 837 | 838 | 839 | 840 | /*-----------------------------------------------. 841 | | Release the memory associated to this symbol. | 842 | `-----------------------------------------------*/ 843 | 844 | static void 845 | yydestruct (const char *yymsg, 846 | yysymbol_kind_t yykind, YYSTYPE *yyvaluep) 847 | { 848 | YY_USE (yyvaluep); 849 | if (!yymsg) 850 | yymsg = "Deleting"; 851 | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); 852 | 853 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 854 | YY_USE (yykind); 855 | YY_IGNORE_MAYBE_UNINITIALIZED_END 856 | } 857 | 858 | 859 | /* Lookahead token kind. */ 860 | int yychar; 861 | 862 | /* The semantic value of the lookahead symbol. */ 863 | YYSTYPE yylval; 864 | /* Number of syntax errors so far. */ 865 | int yynerrs; 866 | 867 | 868 | 869 | 870 | /*----------. 871 | | yyparse. | 872 | `----------*/ 873 | 874 | int 875 | yyparse (void) 876 | { 877 | yy_state_fast_t yystate = 0; 878 | /* Number of tokens to shift before error messages enabled. */ 879 | int yyerrstatus = 0; 880 | 881 | /* Refer to the stacks through separate pointers, to allow yyoverflow 882 | to reallocate them elsewhere. */ 883 | 884 | /* Their size. */ 885 | YYPTRDIFF_T yystacksize = YYINITDEPTH; 886 | 887 | /* The state stack: array, bottom, top. */ 888 | yy_state_t yyssa[YYINITDEPTH]; 889 | yy_state_t *yyss = yyssa; 890 | yy_state_t *yyssp = yyss; 891 | 892 | /* The semantic value stack: array, bottom, top. */ 893 | YYSTYPE yyvsa[YYINITDEPTH]; 894 | YYSTYPE *yyvs = yyvsa; 895 | YYSTYPE *yyvsp = yyvs; 896 | 897 | int yyn; 898 | /* The return value of yyparse. */ 899 | int yyresult; 900 | /* Lookahead symbol kind. */ 901 | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; 902 | /* The variables used to return semantic value and location from the 903 | action routines. */ 904 | YYSTYPE yyval; 905 | 906 | 907 | 908 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 909 | 910 | /* The number of symbols on the RHS of the reduced rule. 911 | Keep to zero when no symbol should be popped. */ 912 | int yylen = 0; 913 | 914 | YYDPRINTF ((stderr, "Starting parse\n")); 915 | 916 | yychar = YYEMPTY; /* Cause a token to be read. */ 917 | 918 | goto yysetstate; 919 | 920 | 921 | /*------------------------------------------------------------. 922 | | yynewstate -- push a new state, which is found in yystate. | 923 | `------------------------------------------------------------*/ 924 | yynewstate: 925 | /* In all cases, when you get here, the value and location stacks 926 | have just been pushed. So pushing a state here evens the stacks. */ 927 | yyssp++; 928 | 929 | 930 | /*--------------------------------------------------------------------. 931 | | yysetstate -- set current state (the top of the stack) to yystate. | 932 | `--------------------------------------------------------------------*/ 933 | yysetstate: 934 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 935 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); 936 | YY_IGNORE_USELESS_CAST_BEGIN 937 | *yyssp = YY_CAST (yy_state_t, yystate); 938 | YY_IGNORE_USELESS_CAST_END 939 | YY_STACK_PRINT (yyss, yyssp); 940 | 941 | if (yyss + yystacksize - 1 <= yyssp) 942 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE 943 | YYNOMEM; 944 | #else 945 | { 946 | /* Get the current used size of the three stacks, in elements. */ 947 | YYPTRDIFF_T yysize = yyssp - yyss + 1; 948 | 949 | # if defined yyoverflow 950 | { 951 | /* Give user a chance to reallocate the stack. Use copies of 952 | these so that the &'s don't force the real ones into 953 | memory. */ 954 | yy_state_t *yyss1 = yyss; 955 | YYSTYPE *yyvs1 = yyvs; 956 | 957 | /* Each stack pointer address is followed by the size of the 958 | data in use in that stack, in bytes. This used to be a 959 | conditional around just the two extra args, but that might 960 | be undefined if yyoverflow is a macro. */ 961 | yyoverflow (YY_("memory exhausted"), 962 | &yyss1, yysize * YYSIZEOF (*yyssp), 963 | &yyvs1, yysize * YYSIZEOF (*yyvsp), 964 | &yystacksize); 965 | yyss = yyss1; 966 | yyvs = yyvs1; 967 | } 968 | # else /* defined YYSTACK_RELOCATE */ 969 | /* Extend the stack our own way. */ 970 | if (YYMAXDEPTH <= yystacksize) 971 | YYNOMEM; 972 | yystacksize *= 2; 973 | if (YYMAXDEPTH < yystacksize) 974 | yystacksize = YYMAXDEPTH; 975 | 976 | { 977 | yy_state_t *yyss1 = yyss; 978 | union yyalloc *yyptr = 979 | YY_CAST (union yyalloc *, 980 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); 981 | if (! yyptr) 982 | YYNOMEM; 983 | YYSTACK_RELOCATE (yyss_alloc, yyss); 984 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); 985 | # undef YYSTACK_RELOCATE 986 | if (yyss1 != yyssa) 987 | YYSTACK_FREE (yyss1); 988 | } 989 | # endif 990 | 991 | yyssp = yyss + yysize - 1; 992 | yyvsp = yyvs + yysize - 1; 993 | 994 | YY_IGNORE_USELESS_CAST_BEGIN 995 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", 996 | YY_CAST (long, yystacksize))); 997 | YY_IGNORE_USELESS_CAST_END 998 | 999 | if (yyss + yystacksize - 1 <= yyssp) 1000 | YYABORT; 1001 | } 1002 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ 1003 | 1004 | 1005 | if (yystate == YYFINAL) 1006 | YYACCEPT; 1007 | 1008 | goto yybackup; 1009 | 1010 | 1011 | /*-----------. 1012 | | yybackup. | 1013 | `-----------*/ 1014 | yybackup: 1015 | /* Do appropriate processing given the current state. Read a 1016 | lookahead token if we need one and don't already have one. */ 1017 | 1018 | /* First try to decide what to do without reference to lookahead token. */ 1019 | yyn = yypact[yystate]; 1020 | if (yypact_value_is_default (yyn)) 1021 | goto yydefault; 1022 | 1023 | /* Not known => get a lookahead token if don't already have one. */ 1024 | 1025 | /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ 1026 | if (yychar == YYEMPTY) 1027 | { 1028 | YYDPRINTF ((stderr, "Reading a token\n")); 1029 | yychar = yylex (); 1030 | } 1031 | 1032 | if (yychar <= YYEOF) 1033 | { 1034 | yychar = YYEOF; 1035 | yytoken = YYSYMBOL_YYEOF; 1036 | YYDPRINTF ((stderr, "Now at end of input.\n")); 1037 | } 1038 | else if (yychar == YYerror) 1039 | { 1040 | /* The scanner already issued an error message, process directly 1041 | to error recovery. But do not keep the error token as 1042 | lookahead, it is too special and may lead us to an endless 1043 | loop in error recovery. */ 1044 | yychar = YYUNDEF; 1045 | yytoken = YYSYMBOL_YYerror; 1046 | goto yyerrlab1; 1047 | } 1048 | else 1049 | { 1050 | yytoken = YYTRANSLATE (yychar); 1051 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1052 | } 1053 | 1054 | /* If the proper action on seeing token YYTOKEN is to reduce or to 1055 | detect an error, take that action. */ 1056 | yyn += yytoken; 1057 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1058 | goto yydefault; 1059 | yyn = yytable[yyn]; 1060 | if (yyn <= 0) 1061 | { 1062 | if (yytable_value_is_error (yyn)) 1063 | goto yyerrlab; 1064 | yyn = -yyn; 1065 | goto yyreduce; 1066 | } 1067 | 1068 | /* Count tokens shifted since error; after three, turn off error 1069 | status. */ 1070 | if (yyerrstatus) 1071 | yyerrstatus--; 1072 | 1073 | /* Shift the lookahead token. */ 1074 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1075 | yystate = yyn; 1076 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1077 | *++yyvsp = yylval; 1078 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1079 | 1080 | /* Discard the shifted token. */ 1081 | yychar = YYEMPTY; 1082 | goto yynewstate; 1083 | 1084 | 1085 | /*-----------------------------------------------------------. 1086 | | yydefault -- do the default action for the current state. | 1087 | `-----------------------------------------------------------*/ 1088 | yydefault: 1089 | yyn = yydefact[yystate]; 1090 | if (yyn == 0) 1091 | goto yyerrlab; 1092 | goto yyreduce; 1093 | 1094 | 1095 | /*-----------------------------. 1096 | | yyreduce -- do a reduction. | 1097 | `-----------------------------*/ 1098 | yyreduce: 1099 | /* yyn is the number of a rule to reduce with. */ 1100 | yylen = yyr2[yyn]; 1101 | 1102 | /* If YYLEN is nonzero, implement the default value of the action: 1103 | '$$ = $1'. 1104 | 1105 | Otherwise, the following line sets YYVAL to garbage. 1106 | This behavior is undocumented and Bison 1107 | users should not rely upon it. Assigning to YYVAL 1108 | unconditionally makes the parser a bit smaller, and it avoids a 1109 | GCC warning that YYVAL may be used uninitialized. */ 1110 | yyval = yyvsp[1-yylen]; 1111 | 1112 | 1113 | YY_REDUCE_PRINT (yyn); 1114 | switch (yyn) 1115 | { 1116 | case 2: /* ArithmeticExpression: E */ 1117 | #line 22 "cal.y" 1118 | { 1119 | 1120 | printf("\nResult=%d\n",yyval); 1121 | 1122 | return 0; 1123 | 1124 | } 1125 | #line 1126 "y.tab.c" 1126 | break; 1127 | 1128 | case 3: /* E: E '+' E */ 1129 | #line 30 "cal.y" 1130 | {yyval=yyvsp[-2]+yyvsp[0];} 1131 | #line 1132 "y.tab.c" 1132 | break; 1133 | 1134 | case 4: /* E: E '-' E */ 1135 | #line 32 "cal.y" 1136 | {yyval=yyvsp[-2]-yyvsp[0];} 1137 | #line 1138 "y.tab.c" 1138 | break; 1139 | 1140 | case 5: /* E: E '*' E */ 1141 | #line 34 "cal.y" 1142 | {yyval=yyvsp[-2]*yyvsp[0];} 1143 | #line 1144 "y.tab.c" 1144 | break; 1145 | 1146 | case 6: /* E: E '/' E */ 1147 | #line 36 "cal.y" 1148 | {yyval=yyvsp[-2]/yyvsp[0];} 1149 | #line 1150 "y.tab.c" 1150 | break; 1151 | 1152 | case 7: /* E: E '%' E */ 1153 | #line 38 "cal.y" 1154 | {yyval=yyvsp[-2]%yyvsp[0];} 1155 | #line 1156 "y.tab.c" 1156 | break; 1157 | 1158 | case 8: /* E: '(' E ')' */ 1159 | #line 40 "cal.y" 1160 | {yyval=yyvsp[-1];} 1161 | #line 1162 "y.tab.c" 1162 | break; 1163 | 1164 | case 9: /* E: NUMBER */ 1165 | #line 42 "cal.y" 1166 | {yyval=yyvsp[0];} 1167 | #line 1168 "y.tab.c" 1168 | break; 1169 | 1170 | 1171 | #line 1172 "y.tab.c" 1172 | 1173 | default: break; 1174 | } 1175 | /* User semantic actions sometimes alter yychar, and that requires 1176 | that yytoken be updated with the new translation. We take the 1177 | approach of translating immediately before every use of yytoken. 1178 | One alternative is translating here after every semantic action, 1179 | but that translation would be missed if the semantic action invokes 1180 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1181 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1182 | incorrect destructor might then be invoked immediately. In the 1183 | case of YYERROR or YYBACKUP, subsequent parser actions might lead 1184 | to an incorrect destructor call or verbose syntax error message 1185 | before the lookahead is translated. */ 1186 | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); 1187 | 1188 | YYPOPSTACK (yylen); 1189 | yylen = 0; 1190 | 1191 | *++yyvsp = yyval; 1192 | 1193 | /* Now 'shift' the result of the reduction. Determine what state 1194 | that goes to, based on the state we popped back to and the rule 1195 | number reduced by. */ 1196 | { 1197 | const int yylhs = yyr1[yyn] - YYNTOKENS; 1198 | const int yyi = yypgoto[yylhs] + *yyssp; 1199 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp 1200 | ? yytable[yyi] 1201 | : yydefgoto[yylhs]); 1202 | } 1203 | 1204 | goto yynewstate; 1205 | 1206 | 1207 | /*--------------------------------------. 1208 | | yyerrlab -- here on detecting error. | 1209 | `--------------------------------------*/ 1210 | yyerrlab: 1211 | /* Make sure we have latest lookahead translation. See comments at 1212 | user semantic actions for why this is necessary. */ 1213 | yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); 1214 | /* If not already recovering from an error, report this error. */ 1215 | if (!yyerrstatus) 1216 | { 1217 | ++yynerrs; 1218 | yyerror (YY_("syntax error")); 1219 | } 1220 | 1221 | if (yyerrstatus == 3) 1222 | { 1223 | /* If just tried and failed to reuse lookahead token after an 1224 | error, discard it. */ 1225 | 1226 | if (yychar <= YYEOF) 1227 | { 1228 | /* Return failure if at end of input. */ 1229 | if (yychar == YYEOF) 1230 | YYABORT; 1231 | } 1232 | else 1233 | { 1234 | yydestruct ("Error: discarding", 1235 | yytoken, &yylval); 1236 | yychar = YYEMPTY; 1237 | } 1238 | } 1239 | 1240 | /* Else will try to reuse lookahead token after shifting the error 1241 | token. */ 1242 | goto yyerrlab1; 1243 | 1244 | 1245 | /*---------------------------------------------------. 1246 | | yyerrorlab -- error raised explicitly by YYERROR. | 1247 | `---------------------------------------------------*/ 1248 | yyerrorlab: 1249 | /* Pacify compilers when the user code never invokes YYERROR and the 1250 | label yyerrorlab therefore never appears in user code. */ 1251 | if (0) 1252 | YYERROR; 1253 | ++yynerrs; 1254 | 1255 | /* Do not reclaim the symbols of the rule whose action triggered 1256 | this YYERROR. */ 1257 | YYPOPSTACK (yylen); 1258 | yylen = 0; 1259 | YY_STACK_PRINT (yyss, yyssp); 1260 | yystate = *yyssp; 1261 | goto yyerrlab1; 1262 | 1263 | 1264 | /*-------------------------------------------------------------. 1265 | | yyerrlab1 -- common code for both syntax error and YYERROR. | 1266 | `-------------------------------------------------------------*/ 1267 | yyerrlab1: 1268 | yyerrstatus = 3; /* Each real token shifted decrements this. */ 1269 | 1270 | /* Pop stack until we find a state that shifts the error token. */ 1271 | for (;;) 1272 | { 1273 | yyn = yypact[yystate]; 1274 | if (!yypact_value_is_default (yyn)) 1275 | { 1276 | yyn += YYSYMBOL_YYerror; 1277 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) 1278 | { 1279 | yyn = yytable[yyn]; 1280 | if (0 < yyn) 1281 | break; 1282 | } 1283 | } 1284 | 1285 | /* Pop the current state because it cannot handle the error token. */ 1286 | if (yyssp == yyss) 1287 | YYABORT; 1288 | 1289 | 1290 | yydestruct ("Error: popping", 1291 | YY_ACCESSING_SYMBOL (yystate), yyvsp); 1292 | YYPOPSTACK (1); 1293 | yystate = *yyssp; 1294 | YY_STACK_PRINT (yyss, yyssp); 1295 | } 1296 | 1297 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1298 | *++yyvsp = yylval; 1299 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1300 | 1301 | 1302 | /* Shift the error token. */ 1303 | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); 1304 | 1305 | yystate = yyn; 1306 | goto yynewstate; 1307 | 1308 | 1309 | /*-------------------------------------. 1310 | | yyacceptlab -- YYACCEPT comes here. | 1311 | `-------------------------------------*/ 1312 | yyacceptlab: 1313 | yyresult = 0; 1314 | goto yyreturnlab; 1315 | 1316 | 1317 | /*-----------------------------------. 1318 | | yyabortlab -- YYABORT comes here. | 1319 | `-----------------------------------*/ 1320 | yyabortlab: 1321 | yyresult = 1; 1322 | goto yyreturnlab; 1323 | 1324 | 1325 | /*-----------------------------------------------------------. 1326 | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | 1327 | `-----------------------------------------------------------*/ 1328 | yyexhaustedlab: 1329 | yyerror (YY_("memory exhausted")); 1330 | yyresult = 2; 1331 | goto yyreturnlab; 1332 | 1333 | 1334 | /*----------------------------------------------------------. 1335 | | yyreturnlab -- parsing is finished, clean up and return. | 1336 | `----------------------------------------------------------*/ 1337 | yyreturnlab: 1338 | if (yychar != YYEMPTY) 1339 | { 1340 | /* Make sure we have latest lookahead translation. See comments at 1341 | user semantic actions for why this is necessary. */ 1342 | yytoken = YYTRANSLATE (yychar); 1343 | yydestruct ("Cleanup: discarding lookahead", 1344 | yytoken, &yylval); 1345 | } 1346 | /* Do not reclaim the symbols of the rule whose action triggered 1347 | this YYABORT or YYACCEPT. */ 1348 | YYPOPSTACK (yylen); 1349 | YY_STACK_PRINT (yyss, yyssp); 1350 | while (yyssp != yyss) 1351 | { 1352 | yydestruct ("Cleanup: popping", 1353 | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); 1354 | YYPOPSTACK (1); 1355 | } 1356 | #ifndef yyoverflow 1357 | if (yyss != yyssa) 1358 | YYSTACK_FREE (yyss); 1359 | #endif 1360 | 1361 | return yyresult; 1362 | } 1363 | 1364 | #line 46 "cal.y" 1365 | 1366 | 1367 | 1368 | 1369 | void main() 1370 | 1371 | { 1372 | 1373 | printf("\nEnter Any Arithmetic Expression which can have operations Addition, Subtraction, Multiplication, Divison, Modulus and Round brackets:\n"); 1374 | 1375 | yyparse(); 1376 | 1377 | if(flag==0) 1378 | 1379 | printf("\nEntered arithmetic expression is Valid\n\n"); 1380 | 1381 | } 1382 | 1383 | void yyerror() 1384 | 1385 | { 1386 | 1387 | printf("\nEntered arithmetic expression is Invalid\n\n"); 1388 | 1389 | flag=1; 1390 | 1391 | } 1392 | -------------------------------------------------------------------------------- /YACC-Calculator/y.tab.h: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison interface for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 35 | especially those whose name start with YY_ or yy_. They are 36 | private implementation details that can be changed or removed. */ 37 | 38 | #ifndef YY_YY_Y_TAB_H_INCLUDED 39 | # define YY_YY_Y_TAB_H_INCLUDED 40 | /* Debug traces. */ 41 | #ifndef YYDEBUG 42 | # define YYDEBUG 0 43 | #endif 44 | #if YYDEBUG 45 | extern int yydebug; 46 | #endif 47 | 48 | /* Token kinds. */ 49 | #ifndef YYTOKENTYPE 50 | # define YYTOKENTYPE 51 | enum yytokentype 52 | { 53 | YYEMPTY = -2, 54 | YYEOF = 0, /* "end of file" */ 55 | YYerror = 256, /* error */ 56 | YYUNDEF = 257, /* "invalid token" */ 57 | NUMBER = 258 /* NUMBER */ 58 | }; 59 | typedef enum yytokentype yytoken_kind_t; 60 | #endif 61 | /* Token kinds. */ 62 | #define YYEMPTY -2 63 | #define YYEOF 0 64 | #define YYerror 256 65 | #define YYUNDEF 257 66 | #define NUMBER 258 67 | 68 | /* Value type. */ 69 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 70 | typedef int YYSTYPE; 71 | # define YYSTYPE_IS_TRIVIAL 1 72 | # define YYSTYPE_IS_DECLARED 1 73 | #endif 74 | 75 | 76 | extern YYSTYPE yylval; 77 | 78 | 79 | int yyparse (void); 80 | 81 | 82 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 83 | -------------------------------------------------------------------------------- /YACC-Valid-Expressions/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/YACC-Valid-Expressions/a.out -------------------------------------------------------------------------------- /YACC-Valid-Expressions/exp.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include "y.tab.h" 4 | 5 | %} 6 | 7 | %% 8 | 9 | [a-zA-Z_][a-zA-Z_0-9]* return id; 10 | 11 | [0-9]+(\.[0-9]*)? return num; 12 | 13 | [+/*] return op; 14 | 15 | . return yytext[0]; 16 | 17 | \n return 0; 18 | 19 | %% 20 | 21 | int yywrap() 22 | 23 | { 24 | 25 | return 1; 26 | 27 | } 28 | 29 | // To compile this file, use the following command: 30 | // yacc -d exp.y 31 | // lex exp.l 32 | // gcc lex.yy.c y.tab.c -w 33 | // ./a.out -------------------------------------------------------------------------------- /YACC-Valid-Expressions/exp.y: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | int valid=1; 6 | 7 | %} 8 | 9 | %token num id op 10 | 11 | %% 12 | 13 | start : id '=' s ';' 14 | 15 | s : id x 16 | 17 | | num x 18 | 19 | | '-' num x 20 | 21 | | '(' s ')' x 22 | 23 | ; 24 | 25 | x : op s 26 | 27 | | '-' s 28 | 29 | | 30 | 31 | ; 32 | 33 | %% 34 | 35 | int yyerror() 36 | 37 | { 38 | 39 | valid=0; 40 | 41 | printf("\nInvalid expression!\n"); 42 | 43 | return 0; 44 | 45 | } 46 | 47 | int main() 48 | 49 | { 50 | 51 | printf("\nEnter the expression:\n"); 52 | 53 | yyparse(); 54 | 55 | if(valid) 56 | 57 | { 58 | 59 | printf("\nValid expression!\n"); 60 | 61 | } 62 | 63 | } 64 | 65 | // To compile this file, use the following command: 66 | // yacc -d exp.y 67 | // lex exp.l 68 | // gcc lex.yy.c y.tab.c -w 69 | // ./a.out -------------------------------------------------------------------------------- /YACC-Valid-Expressions/y.tab.c: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison implementation for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* C LALR(1) parser skeleton written by Richard Stallman, by 35 | simplifying the original so-called "semantic" parser. */ 36 | 37 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 38 | especially those whose name start with YY_ or yy_. They are 39 | private implementation details that can be changed or removed. */ 40 | 41 | /* All symbols defined below should begin with yy or YY, to avoid 42 | infringing on user name space. This should be done even for local 43 | variables, as they might otherwise be expanded by user macros. 44 | There are some unavoidable exceptions within include files to 45 | define necessary library symbols; they are noted "INFRINGES ON 46 | USER NAME SPACE" below. */ 47 | 48 | /* Identify Bison output, and Bison version. */ 49 | #define YYBISON 30802 50 | 51 | /* Bison version string. */ 52 | #define YYBISON_VERSION "3.8.2" 53 | 54 | /* Skeleton name. */ 55 | #define YYSKELETON_NAME "yacc.c" 56 | 57 | /* Pure parsers. */ 58 | #define YYPURE 0 59 | 60 | /* Push parsers. */ 61 | #define YYPUSH 0 62 | 63 | /* Pull parsers. */ 64 | #define YYPULL 1 65 | 66 | 67 | 68 | 69 | /* First part of user prologue. */ 70 | #line 1 "exp.y" 71 | 72 | 73 | #include 74 | 75 | int valid=1; 76 | 77 | 78 | #line 79 "y.tab.c" 79 | 80 | # ifndef YY_CAST 81 | # ifdef __cplusplus 82 | # define YY_CAST(Type, Val) static_cast (Val) 83 | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) 84 | # else 85 | # define YY_CAST(Type, Val) ((Type) (Val)) 86 | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) 87 | # endif 88 | # endif 89 | # ifndef YY_NULLPTR 90 | # if defined __cplusplus 91 | # if 201103L <= __cplusplus 92 | # define YY_NULLPTR nullptr 93 | # else 94 | # define YY_NULLPTR 0 95 | # endif 96 | # else 97 | # define YY_NULLPTR ((void*)0) 98 | # endif 99 | # endif 100 | 101 | /* Use api.header.include to #include this header 102 | instead of duplicating it here. */ 103 | #ifndef YY_YY_Y_TAB_H_INCLUDED 104 | # define YY_YY_Y_TAB_H_INCLUDED 105 | /* Debug traces. */ 106 | #ifndef YYDEBUG 107 | # define YYDEBUG 0 108 | #endif 109 | #if YYDEBUG 110 | extern int yydebug; 111 | #endif 112 | 113 | /* Token kinds. */ 114 | #ifndef YYTOKENTYPE 115 | # define YYTOKENTYPE 116 | enum yytokentype 117 | { 118 | YYEMPTY = -2, 119 | YYEOF = 0, /* "end of file" */ 120 | YYerror = 256, /* error */ 121 | YYUNDEF = 257, /* "invalid token" */ 122 | num = 258, /* num */ 123 | id = 259, /* id */ 124 | op = 260 /* op */ 125 | }; 126 | typedef enum yytokentype yytoken_kind_t; 127 | #endif 128 | /* Token kinds. */ 129 | #define YYEMPTY -2 130 | #define YYEOF 0 131 | #define YYerror 256 132 | #define YYUNDEF 257 133 | #define num 258 134 | #define id 259 135 | #define op 260 136 | 137 | /* Value type. */ 138 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 139 | typedef int YYSTYPE; 140 | # define YYSTYPE_IS_TRIVIAL 1 141 | # define YYSTYPE_IS_DECLARED 1 142 | #endif 143 | 144 | 145 | extern YYSTYPE yylval; 146 | 147 | 148 | int yyparse (void); 149 | 150 | 151 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 152 | /* Symbol kind. */ 153 | enum yysymbol_kind_t 154 | { 155 | YYSYMBOL_YYEMPTY = -2, 156 | YYSYMBOL_YYEOF = 0, /* "end of file" */ 157 | YYSYMBOL_YYerror = 1, /* error */ 158 | YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ 159 | YYSYMBOL_num = 3, /* num */ 160 | YYSYMBOL_id = 4, /* id */ 161 | YYSYMBOL_op = 5, /* op */ 162 | YYSYMBOL_6_ = 6, /* '=' */ 163 | YYSYMBOL_7_ = 7, /* ';' */ 164 | YYSYMBOL_8_ = 8, /* '-' */ 165 | YYSYMBOL_9_ = 9, /* '(' */ 166 | YYSYMBOL_10_ = 10, /* ')' */ 167 | YYSYMBOL_YYACCEPT = 11, /* $accept */ 168 | YYSYMBOL_start = 12, /* start */ 169 | YYSYMBOL_s = 13, /* s */ 170 | YYSYMBOL_x = 14 /* x */ 171 | }; 172 | typedef enum yysymbol_kind_t yysymbol_kind_t; 173 | 174 | 175 | 176 | 177 | #ifdef short 178 | # undef short 179 | #endif 180 | 181 | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure 182 | and (if available) are included 183 | so that the code can choose integer types of a good width. */ 184 | 185 | #ifndef __PTRDIFF_MAX__ 186 | # include /* INFRINGES ON USER NAME SPACE */ 187 | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 188 | # include /* INFRINGES ON USER NAME SPACE */ 189 | # define YY_STDINT_H 190 | # endif 191 | #endif 192 | 193 | /* Narrow types that promote to a signed type and that can represent a 194 | signed or unsigned integer of at least N bits. In tables they can 195 | save space and decrease cache pressure. Promoting to a signed type 196 | helps avoid bugs in integer arithmetic. */ 197 | 198 | #ifdef __INT_LEAST8_MAX__ 199 | typedef __INT_LEAST8_TYPE__ yytype_int8; 200 | #elif defined YY_STDINT_H 201 | typedef int_least8_t yytype_int8; 202 | #else 203 | typedef signed char yytype_int8; 204 | #endif 205 | 206 | #ifdef __INT_LEAST16_MAX__ 207 | typedef __INT_LEAST16_TYPE__ yytype_int16; 208 | #elif defined YY_STDINT_H 209 | typedef int_least16_t yytype_int16; 210 | #else 211 | typedef short yytype_int16; 212 | #endif 213 | 214 | /* Work around bug in HP-UX 11.23, which defines these macros 215 | incorrectly for preprocessor constants. This workaround can likely 216 | be removed in 2023, as HPE has promised support for HP-UX 11.23 217 | (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of 218 | . */ 219 | #ifdef __hpux 220 | # undef UINT_LEAST8_MAX 221 | # undef UINT_LEAST16_MAX 222 | # define UINT_LEAST8_MAX 255 223 | # define UINT_LEAST16_MAX 65535 224 | #endif 225 | 226 | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ 227 | typedef __UINT_LEAST8_TYPE__ yytype_uint8; 228 | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ 229 | && UINT_LEAST8_MAX <= INT_MAX) 230 | typedef uint_least8_t yytype_uint8; 231 | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX 232 | typedef unsigned char yytype_uint8; 233 | #else 234 | typedef short yytype_uint8; 235 | #endif 236 | 237 | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ 238 | typedef __UINT_LEAST16_TYPE__ yytype_uint16; 239 | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ 240 | && UINT_LEAST16_MAX <= INT_MAX) 241 | typedef uint_least16_t yytype_uint16; 242 | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX 243 | typedef unsigned short yytype_uint16; 244 | #else 245 | typedef int yytype_uint16; 246 | #endif 247 | 248 | #ifndef YYPTRDIFF_T 249 | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ 250 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ 251 | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ 252 | # elif defined PTRDIFF_MAX 253 | # ifndef ptrdiff_t 254 | # include /* INFRINGES ON USER NAME SPACE */ 255 | # endif 256 | # define YYPTRDIFF_T ptrdiff_t 257 | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX 258 | # else 259 | # define YYPTRDIFF_T long 260 | # define YYPTRDIFF_MAXIMUM LONG_MAX 261 | # endif 262 | #endif 263 | 264 | #ifndef YYSIZE_T 265 | # ifdef __SIZE_TYPE__ 266 | # define YYSIZE_T __SIZE_TYPE__ 267 | # elif defined size_t 268 | # define YYSIZE_T size_t 269 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 270 | # include /* INFRINGES ON USER NAME SPACE */ 271 | # define YYSIZE_T size_t 272 | # else 273 | # define YYSIZE_T unsigned 274 | # endif 275 | #endif 276 | 277 | #define YYSIZE_MAXIMUM \ 278 | YY_CAST (YYPTRDIFF_T, \ 279 | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ 280 | ? YYPTRDIFF_MAXIMUM \ 281 | : YY_CAST (YYSIZE_T, -1))) 282 | 283 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) 284 | 285 | 286 | /* Stored state numbers (used for stacks). */ 287 | typedef yytype_int8 yy_state_t; 288 | 289 | /* State numbers in computations. */ 290 | typedef int yy_state_fast_t; 291 | 292 | #ifndef YY_ 293 | # if defined YYENABLE_NLS && YYENABLE_NLS 294 | # if ENABLE_NLS 295 | # include /* INFRINGES ON USER NAME SPACE */ 296 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 297 | # endif 298 | # endif 299 | # ifndef YY_ 300 | # define YY_(Msgid) Msgid 301 | # endif 302 | #endif 303 | 304 | 305 | #ifndef YY_ATTRIBUTE_PURE 306 | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) 307 | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) 308 | # else 309 | # define YY_ATTRIBUTE_PURE 310 | # endif 311 | #endif 312 | 313 | #ifndef YY_ATTRIBUTE_UNUSED 314 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) 315 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 316 | # else 317 | # define YY_ATTRIBUTE_UNUSED 318 | # endif 319 | #endif 320 | 321 | /* Suppress unused-variable warnings by "using" E. */ 322 | #if ! defined lint || defined __GNUC__ 323 | # define YY_USE(E) ((void) (E)) 324 | #else 325 | # define YY_USE(E) /* empty */ 326 | #endif 327 | 328 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ 329 | #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ 330 | # if __GNUC__ * 100 + __GNUC_MINOR__ < 407 331 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 332 | _Pragma ("GCC diagnostic push") \ 333 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") 334 | # else 335 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 336 | _Pragma ("GCC diagnostic push") \ 337 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ 338 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 339 | # endif 340 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 341 | _Pragma ("GCC diagnostic pop") 342 | #else 343 | # define YY_INITIAL_VALUE(Value) Value 344 | #endif 345 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 346 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 347 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END 348 | #endif 349 | #ifndef YY_INITIAL_VALUE 350 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ 351 | #endif 352 | 353 | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 354 | # define YY_IGNORE_USELESS_CAST_BEGIN \ 355 | _Pragma ("GCC diagnostic push") \ 356 | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") 357 | # define YY_IGNORE_USELESS_CAST_END \ 358 | _Pragma ("GCC diagnostic pop") 359 | #endif 360 | #ifndef YY_IGNORE_USELESS_CAST_BEGIN 361 | # define YY_IGNORE_USELESS_CAST_BEGIN 362 | # define YY_IGNORE_USELESS_CAST_END 363 | #endif 364 | 365 | 366 | #define YY_ASSERT(E) ((void) (0 && (E))) 367 | 368 | #if !defined yyoverflow 369 | 370 | /* The parser invokes alloca or malloc; define the necessary symbols. */ 371 | 372 | # ifdef YYSTACK_USE_ALLOCA 373 | # if YYSTACK_USE_ALLOCA 374 | # ifdef __GNUC__ 375 | # define YYSTACK_ALLOC __builtin_alloca 376 | # elif defined __BUILTIN_VA_ARG_INCR 377 | # include /* INFRINGES ON USER NAME SPACE */ 378 | # elif defined _AIX 379 | # define YYSTACK_ALLOC __alloca 380 | # elif defined _MSC_VER 381 | # include /* INFRINGES ON USER NAME SPACE */ 382 | # define alloca _alloca 383 | # else 384 | # define YYSTACK_ALLOC alloca 385 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 386 | # include /* INFRINGES ON USER NAME SPACE */ 387 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 388 | # ifndef EXIT_SUCCESS 389 | # define EXIT_SUCCESS 0 390 | # endif 391 | # endif 392 | # endif 393 | # endif 394 | # endif 395 | 396 | # ifdef YYSTACK_ALLOC 397 | /* Pacify GCC's 'empty if-body' warning. */ 398 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 399 | # ifndef YYSTACK_ALLOC_MAXIMUM 400 | /* The OS might guarantee only one guard page at the bottom of the stack, 401 | and a page size can be as small as 4096 bytes. So we cannot safely 402 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 403 | to allow for a few compiler-allocated temporary stack slots. */ 404 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 405 | # endif 406 | # else 407 | # define YYSTACK_ALLOC YYMALLOC 408 | # define YYSTACK_FREE YYFREE 409 | # ifndef YYSTACK_ALLOC_MAXIMUM 410 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 411 | # endif 412 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ 413 | && ! ((defined YYMALLOC || defined malloc) \ 414 | && (defined YYFREE || defined free))) 415 | # include /* INFRINGES ON USER NAME SPACE */ 416 | # ifndef EXIT_SUCCESS 417 | # define EXIT_SUCCESS 0 418 | # endif 419 | # endif 420 | # ifndef YYMALLOC 421 | # define YYMALLOC malloc 422 | # if ! defined malloc && ! defined EXIT_SUCCESS 423 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 424 | # endif 425 | # endif 426 | # ifndef YYFREE 427 | # define YYFREE free 428 | # if ! defined free && ! defined EXIT_SUCCESS 429 | void free (void *); /* INFRINGES ON USER NAME SPACE */ 430 | # endif 431 | # endif 432 | # endif 433 | #endif /* !defined yyoverflow */ 434 | 435 | #if (! defined yyoverflow \ 436 | && (! defined __cplusplus \ 437 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 438 | 439 | /* A type that is properly aligned for any stack member. */ 440 | union yyalloc 441 | { 442 | yy_state_t yyss_alloc; 443 | YYSTYPE yyvs_alloc; 444 | }; 445 | 446 | /* The size of the maximum gap between one aligned stack and the next. */ 447 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) 448 | 449 | /* The size of an array large to enough to hold all stacks, each with 450 | N elements. */ 451 | # define YYSTACK_BYTES(N) \ 452 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ 453 | + YYSTACK_GAP_MAXIMUM) 454 | 455 | # define YYCOPY_NEEDED 1 456 | 457 | /* Relocate STACK from its old location to the new one. The 458 | local variables YYSIZE and YYSTACKSIZE give the old and new number of 459 | elements in the stack, and YYPTR gives the new location of the 460 | stack. Advance YYPTR to a properly aligned location for the next 461 | stack. */ 462 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 463 | do \ 464 | { \ 465 | YYPTRDIFF_T yynewbytes; \ 466 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 467 | Stack = &yyptr->Stack_alloc; \ 468 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ 469 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ 470 | } \ 471 | while (0) 472 | 473 | #endif 474 | 475 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED 476 | /* Copy COUNT objects from SRC to DST. The source and destination do 477 | not overlap. */ 478 | # ifndef YYCOPY 479 | # if defined __GNUC__ && 1 < __GNUC__ 480 | # define YYCOPY(Dst, Src, Count) \ 481 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) 482 | # else 483 | # define YYCOPY(Dst, Src, Count) \ 484 | do \ 485 | { \ 486 | YYPTRDIFF_T yyi; \ 487 | for (yyi = 0; yyi < (Count); yyi++) \ 488 | (Dst)[yyi] = (Src)[yyi]; \ 489 | } \ 490 | while (0) 491 | # endif 492 | # endif 493 | #endif /* !YYCOPY_NEEDED */ 494 | 495 | /* YYFINAL -- State number of the termination state. */ 496 | #define YYFINAL 4 497 | /* YYLAST -- Last index in YYTABLE. */ 498 | #define YYLAST 17 499 | 500 | /* YYNTOKENS -- Number of terminals. */ 501 | #define YYNTOKENS 11 502 | /* YYNNTS -- Number of nonterminals. */ 503 | #define YYNNTS 4 504 | /* YYNRULES -- Number of rules. */ 505 | #define YYNRULES 9 506 | /* YYNSTATES -- Number of states. */ 507 | #define YYNSTATES 22 508 | 509 | /* YYMAXUTOK -- Last valid token kind. */ 510 | #define YYMAXUTOK 260 511 | 512 | 513 | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 514 | as returned by yylex, with out-of-bounds checking. */ 515 | #define YYTRANSLATE(YYX) \ 516 | (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 517 | ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 518 | : YYSYMBOL_YYUNDEF) 519 | 520 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 521 | as returned by yylex. */ 522 | static const yytype_int8 yytranslate[] = 523 | { 524 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 525 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 526 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 527 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 528 | 9, 10, 2, 2, 2, 8, 2, 2, 2, 2, 529 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 530 | 2, 6, 2, 2, 2, 2, 2, 2, 2, 2, 531 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 532 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 533 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 534 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 535 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 536 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 537 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 538 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 539 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 540 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 541 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 542 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 543 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 544 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 545 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 546 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 547 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 548 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 549 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 550 | 5 551 | }; 552 | 553 | #if YYDEBUG 554 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 555 | static const yytype_int8 yyrline[] = 556 | { 557 | 0, 13, 13, 15, 17, 19, 21, 25, 27, 29 558 | }; 559 | #endif 560 | 561 | /** Accessing symbol of state STATE. */ 562 | #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) 563 | 564 | #if YYDEBUG || 0 565 | /* The user-facing name of the symbol whose (internal) number is 566 | YYSYMBOL. No bounds checking. */ 567 | static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 568 | 569 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 570 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 571 | static const char *const yytname[] = 572 | { 573 | "\"end of file\"", "error", "\"invalid token\"", "num", "id", "op", 574 | "'='", "';'", "'-'", "'('", "')'", "$accept", "start", "s", "x", YY_NULLPTR 575 | }; 576 | 577 | static const char * 578 | yysymbol_name (yysymbol_kind_t yysymbol) 579 | { 580 | return yytname[yysymbol]; 581 | } 582 | #endif 583 | 584 | #define YYPACT_NINF (-7) 585 | 586 | #define yypact_value_is_default(Yyn) \ 587 | ((Yyn) == YYPACT_NINF) 588 | 589 | #define YYTABLE_NINF (-1) 590 | 591 | #define yytable_value_is_error(Yyn) \ 592 | 0 593 | 594 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 595 | STATE-NUM. */ 596 | static const yytype_int8 yypact[] = 597 | { 598 | -1, 9, 4, -2, -7, 5, 5, 2, -2, 10, 599 | -2, -2, -7, -7, 5, 6, -7, -7, -7, -7, 600 | 5, -7 601 | }; 602 | 603 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 604 | Performed when YYTABLE does not specify something else to do. Zero 605 | means the default is an error. */ 606 | static const yytype_int8 yydefact[] = 607 | { 608 | 0, 0, 0, 0, 1, 9, 9, 0, 0, 0, 609 | 0, 0, 4, 3, 9, 0, 2, 7, 8, 5, 610 | 9, 6 611 | }; 612 | 613 | /* YYPGOTO[NTERM-NUM]. */ 614 | static const yytype_int8 yypgoto[] = 615 | { 616 | -7, -7, 1, -6 617 | }; 618 | 619 | /* YYDEFGOTO[NTERM-NUM]. */ 620 | static const yytype_int8 yydefgoto[] = 621 | { 622 | 0, 2, 9, 12 623 | }; 624 | 625 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 626 | positive, shift that token. If negative, reduce the rule whose 627 | number is the opposite. If YYTABLE_NINF, syntax error. */ 628 | static const yytype_int8 yytable[] = 629 | { 630 | 13, 5, 6, 1, 4, 14, 7, 8, 19, 15, 631 | 10, 17, 18, 11, 21, 3, 20, 16 632 | }; 633 | 634 | static const yytype_int8 yycheck[] = 635 | { 636 | 6, 3, 4, 4, 0, 3, 8, 9, 14, 8, 637 | 5, 10, 11, 8, 20, 6, 10, 7 638 | }; 639 | 640 | /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of 641 | state STATE-NUM. */ 642 | static const yytype_int8 yystos[] = 643 | { 644 | 0, 4, 12, 6, 0, 3, 4, 8, 9, 13, 645 | 5, 8, 14, 14, 3, 13, 7, 13, 13, 14, 646 | 10, 14 647 | }; 648 | 649 | /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ 650 | static const yytype_int8 yyr1[] = 651 | { 652 | 0, 11, 12, 13, 13, 13, 13, 14, 14, 14 653 | }; 654 | 655 | /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ 656 | static const yytype_int8 yyr2[] = 657 | { 658 | 0, 2, 4, 2, 2, 3, 4, 2, 2, 0 659 | }; 660 | 661 | 662 | enum { YYENOMEM = -2 }; 663 | 664 | #define yyerrok (yyerrstatus = 0) 665 | #define yyclearin (yychar = YYEMPTY) 666 | 667 | #define YYACCEPT goto yyacceptlab 668 | #define YYABORT goto yyabortlab 669 | #define YYERROR goto yyerrorlab 670 | #define YYNOMEM goto yyexhaustedlab 671 | 672 | 673 | #define YYRECOVERING() (!!yyerrstatus) 674 | 675 | #define YYBACKUP(Token, Value) \ 676 | do \ 677 | if (yychar == YYEMPTY) \ 678 | { \ 679 | yychar = (Token); \ 680 | yylval = (Value); \ 681 | YYPOPSTACK (yylen); \ 682 | yystate = *yyssp; \ 683 | goto yybackup; \ 684 | } \ 685 | else \ 686 | { \ 687 | yyerror (YY_("syntax error: cannot back up")); \ 688 | YYERROR; \ 689 | } \ 690 | while (0) 691 | 692 | /* Backward compatibility with an undocumented macro. 693 | Use YYerror or YYUNDEF. */ 694 | #define YYERRCODE YYUNDEF 695 | 696 | 697 | /* Enable debugging if requested. */ 698 | #if YYDEBUG 699 | 700 | # ifndef YYFPRINTF 701 | # include /* INFRINGES ON USER NAME SPACE */ 702 | # define YYFPRINTF fprintf 703 | # endif 704 | 705 | # define YYDPRINTF(Args) \ 706 | do { \ 707 | if (yydebug) \ 708 | YYFPRINTF Args; \ 709 | } while (0) 710 | 711 | 712 | 713 | 714 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 715 | do { \ 716 | if (yydebug) \ 717 | { \ 718 | YYFPRINTF (stderr, "%s ", Title); \ 719 | yy_symbol_print (stderr, \ 720 | Kind, Value); \ 721 | YYFPRINTF (stderr, "\n"); \ 722 | } \ 723 | } while (0) 724 | 725 | 726 | /*-----------------------------------. 727 | | Print this symbol's value on YYO. | 728 | `-----------------------------------*/ 729 | 730 | static void 731 | yy_symbol_value_print (FILE *yyo, 732 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 733 | { 734 | FILE *yyoutput = yyo; 735 | YY_USE (yyoutput); 736 | if (!yyvaluep) 737 | return; 738 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 739 | YY_USE (yykind); 740 | YY_IGNORE_MAYBE_UNINITIALIZED_END 741 | } 742 | 743 | 744 | /*---------------------------. 745 | | Print this symbol on YYO. | 746 | `---------------------------*/ 747 | 748 | static void 749 | yy_symbol_print (FILE *yyo, 750 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 751 | { 752 | YYFPRINTF (yyo, "%s %s (", 753 | yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); 754 | 755 | yy_symbol_value_print (yyo, yykind, yyvaluep); 756 | YYFPRINTF (yyo, ")"); 757 | } 758 | 759 | /*------------------------------------------------------------------. 760 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | 761 | | TOP (included). | 762 | `------------------------------------------------------------------*/ 763 | 764 | static void 765 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) 766 | { 767 | YYFPRINTF (stderr, "Stack now"); 768 | for (; yybottom <= yytop; yybottom++) 769 | { 770 | int yybot = *yybottom; 771 | YYFPRINTF (stderr, " %d", yybot); 772 | } 773 | YYFPRINTF (stderr, "\n"); 774 | } 775 | 776 | # define YY_STACK_PRINT(Bottom, Top) \ 777 | do { \ 778 | if (yydebug) \ 779 | yy_stack_print ((Bottom), (Top)); \ 780 | } while (0) 781 | 782 | 783 | /*------------------------------------------------. 784 | | Report that the YYRULE is going to be reduced. | 785 | `------------------------------------------------*/ 786 | 787 | static void 788 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, 789 | int yyrule) 790 | { 791 | int yylno = yyrline[yyrule]; 792 | int yynrhs = yyr2[yyrule]; 793 | int yyi; 794 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", 795 | yyrule - 1, yylno); 796 | /* The symbols being reduced. */ 797 | for (yyi = 0; yyi < yynrhs; yyi++) 798 | { 799 | YYFPRINTF (stderr, " $%d = ", yyi + 1); 800 | yy_symbol_print (stderr, 801 | YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), 802 | &yyvsp[(yyi + 1) - (yynrhs)]); 803 | YYFPRINTF (stderr, "\n"); 804 | } 805 | } 806 | 807 | # define YY_REDUCE_PRINT(Rule) \ 808 | do { \ 809 | if (yydebug) \ 810 | yy_reduce_print (yyssp, yyvsp, Rule); \ 811 | } while (0) 812 | 813 | /* Nonzero means print parse trace. It is left uninitialized so that 814 | multiple parsers can coexist. */ 815 | int yydebug; 816 | #else /* !YYDEBUG */ 817 | # define YYDPRINTF(Args) ((void) 0) 818 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 819 | # define YY_STACK_PRINT(Bottom, Top) 820 | # define YY_REDUCE_PRINT(Rule) 821 | #endif /* !YYDEBUG */ 822 | 823 | 824 | /* YYINITDEPTH -- initial size of the parser's stacks. */ 825 | #ifndef YYINITDEPTH 826 | # define YYINITDEPTH 200 827 | #endif 828 | 829 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 830 | if the built-in stack extension method is used). 831 | 832 | Do not make this value too large; the results are undefined if 833 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 834 | evaluated with infinite-precision integer arithmetic. */ 835 | 836 | #ifndef YYMAXDEPTH 837 | # define YYMAXDEPTH 10000 838 | #endif 839 | 840 | 841 | 842 | 843 | 844 | 845 | /*-----------------------------------------------. 846 | | Release the memory associated to this symbol. | 847 | `-----------------------------------------------*/ 848 | 849 | static void 850 | yydestruct (const char *yymsg, 851 | yysymbol_kind_t yykind, YYSTYPE *yyvaluep) 852 | { 853 | YY_USE (yyvaluep); 854 | if (!yymsg) 855 | yymsg = "Deleting"; 856 | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); 857 | 858 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 859 | YY_USE (yykind); 860 | YY_IGNORE_MAYBE_UNINITIALIZED_END 861 | } 862 | 863 | 864 | /* Lookahead token kind. */ 865 | int yychar; 866 | 867 | /* The semantic value of the lookahead symbol. */ 868 | YYSTYPE yylval; 869 | /* Number of syntax errors so far. */ 870 | int yynerrs; 871 | 872 | 873 | 874 | 875 | /*----------. 876 | | yyparse. | 877 | `----------*/ 878 | 879 | int 880 | yyparse (void) 881 | { 882 | yy_state_fast_t yystate = 0; 883 | /* Number of tokens to shift before error messages enabled. */ 884 | int yyerrstatus = 0; 885 | 886 | /* Refer to the stacks through separate pointers, to allow yyoverflow 887 | to reallocate them elsewhere. */ 888 | 889 | /* Their size. */ 890 | YYPTRDIFF_T yystacksize = YYINITDEPTH; 891 | 892 | /* The state stack: array, bottom, top. */ 893 | yy_state_t yyssa[YYINITDEPTH]; 894 | yy_state_t *yyss = yyssa; 895 | yy_state_t *yyssp = yyss; 896 | 897 | /* The semantic value stack: array, bottom, top. */ 898 | YYSTYPE yyvsa[YYINITDEPTH]; 899 | YYSTYPE *yyvs = yyvsa; 900 | YYSTYPE *yyvsp = yyvs; 901 | 902 | int yyn; 903 | /* The return value of yyparse. */ 904 | int yyresult; 905 | /* Lookahead symbol kind. */ 906 | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; 907 | /* The variables used to return semantic value and location from the 908 | action routines. */ 909 | YYSTYPE yyval; 910 | 911 | 912 | 913 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 914 | 915 | /* The number of symbols on the RHS of the reduced rule. 916 | Keep to zero when no symbol should be popped. */ 917 | int yylen = 0; 918 | 919 | YYDPRINTF ((stderr, "Starting parse\n")); 920 | 921 | yychar = YYEMPTY; /* Cause a token to be read. */ 922 | 923 | goto yysetstate; 924 | 925 | 926 | /*------------------------------------------------------------. 927 | | yynewstate -- push a new state, which is found in yystate. | 928 | `------------------------------------------------------------*/ 929 | yynewstate: 930 | /* In all cases, when you get here, the value and location stacks 931 | have just been pushed. So pushing a state here evens the stacks. */ 932 | yyssp++; 933 | 934 | 935 | /*--------------------------------------------------------------------. 936 | | yysetstate -- set current state (the top of the stack) to yystate. | 937 | `--------------------------------------------------------------------*/ 938 | yysetstate: 939 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 940 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); 941 | YY_IGNORE_USELESS_CAST_BEGIN 942 | *yyssp = YY_CAST (yy_state_t, yystate); 943 | YY_IGNORE_USELESS_CAST_END 944 | YY_STACK_PRINT (yyss, yyssp); 945 | 946 | if (yyss + yystacksize - 1 <= yyssp) 947 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE 948 | YYNOMEM; 949 | #else 950 | { 951 | /* Get the current used size of the three stacks, in elements. */ 952 | YYPTRDIFF_T yysize = yyssp - yyss + 1; 953 | 954 | # if defined yyoverflow 955 | { 956 | /* Give user a chance to reallocate the stack. Use copies of 957 | these so that the &'s don't force the real ones into 958 | memory. */ 959 | yy_state_t *yyss1 = yyss; 960 | YYSTYPE *yyvs1 = yyvs; 961 | 962 | /* Each stack pointer address is followed by the size of the 963 | data in use in that stack, in bytes. This used to be a 964 | conditional around just the two extra args, but that might 965 | be undefined if yyoverflow is a macro. */ 966 | yyoverflow (YY_("memory exhausted"), 967 | &yyss1, yysize * YYSIZEOF (*yyssp), 968 | &yyvs1, yysize * YYSIZEOF (*yyvsp), 969 | &yystacksize); 970 | yyss = yyss1; 971 | yyvs = yyvs1; 972 | } 973 | # else /* defined YYSTACK_RELOCATE */ 974 | /* Extend the stack our own way. */ 975 | if (YYMAXDEPTH <= yystacksize) 976 | YYNOMEM; 977 | yystacksize *= 2; 978 | if (YYMAXDEPTH < yystacksize) 979 | yystacksize = YYMAXDEPTH; 980 | 981 | { 982 | yy_state_t *yyss1 = yyss; 983 | union yyalloc *yyptr = 984 | YY_CAST (union yyalloc *, 985 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); 986 | if (! yyptr) 987 | YYNOMEM; 988 | YYSTACK_RELOCATE (yyss_alloc, yyss); 989 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); 990 | # undef YYSTACK_RELOCATE 991 | if (yyss1 != yyssa) 992 | YYSTACK_FREE (yyss1); 993 | } 994 | # endif 995 | 996 | yyssp = yyss + yysize - 1; 997 | yyvsp = yyvs + yysize - 1; 998 | 999 | YY_IGNORE_USELESS_CAST_BEGIN 1000 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", 1001 | YY_CAST (long, yystacksize))); 1002 | YY_IGNORE_USELESS_CAST_END 1003 | 1004 | if (yyss + yystacksize - 1 <= yyssp) 1005 | YYABORT; 1006 | } 1007 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ 1008 | 1009 | 1010 | if (yystate == YYFINAL) 1011 | YYACCEPT; 1012 | 1013 | goto yybackup; 1014 | 1015 | 1016 | /*-----------. 1017 | | yybackup. | 1018 | `-----------*/ 1019 | yybackup: 1020 | /* Do appropriate processing given the current state. Read a 1021 | lookahead token if we need one and don't already have one. */ 1022 | 1023 | /* First try to decide what to do without reference to lookahead token. */ 1024 | yyn = yypact[yystate]; 1025 | if (yypact_value_is_default (yyn)) 1026 | goto yydefault; 1027 | 1028 | /* Not known => get a lookahead token if don't already have one. */ 1029 | 1030 | /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ 1031 | if (yychar == YYEMPTY) 1032 | { 1033 | YYDPRINTF ((stderr, "Reading a token\n")); 1034 | yychar = yylex (); 1035 | } 1036 | 1037 | if (yychar <= YYEOF) 1038 | { 1039 | yychar = YYEOF; 1040 | yytoken = YYSYMBOL_YYEOF; 1041 | YYDPRINTF ((stderr, "Now at end of input.\n")); 1042 | } 1043 | else if (yychar == YYerror) 1044 | { 1045 | /* The scanner already issued an error message, process directly 1046 | to error recovery. But do not keep the error token as 1047 | lookahead, it is too special and may lead us to an endless 1048 | loop in error recovery. */ 1049 | yychar = YYUNDEF; 1050 | yytoken = YYSYMBOL_YYerror; 1051 | goto yyerrlab1; 1052 | } 1053 | else 1054 | { 1055 | yytoken = YYTRANSLATE (yychar); 1056 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1057 | } 1058 | 1059 | /* If the proper action on seeing token YYTOKEN is to reduce or to 1060 | detect an error, take that action. */ 1061 | yyn += yytoken; 1062 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1063 | goto yydefault; 1064 | yyn = yytable[yyn]; 1065 | if (yyn <= 0) 1066 | { 1067 | if (yytable_value_is_error (yyn)) 1068 | goto yyerrlab; 1069 | yyn = -yyn; 1070 | goto yyreduce; 1071 | } 1072 | 1073 | /* Count tokens shifted since error; after three, turn off error 1074 | status. */ 1075 | if (yyerrstatus) 1076 | yyerrstatus--; 1077 | 1078 | /* Shift the lookahead token. */ 1079 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1080 | yystate = yyn; 1081 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1082 | *++yyvsp = yylval; 1083 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1084 | 1085 | /* Discard the shifted token. */ 1086 | yychar = YYEMPTY; 1087 | goto yynewstate; 1088 | 1089 | 1090 | /*-----------------------------------------------------------. 1091 | | yydefault -- do the default action for the current state. | 1092 | `-----------------------------------------------------------*/ 1093 | yydefault: 1094 | yyn = yydefact[yystate]; 1095 | if (yyn == 0) 1096 | goto yyerrlab; 1097 | goto yyreduce; 1098 | 1099 | 1100 | /*-----------------------------. 1101 | | yyreduce -- do a reduction. | 1102 | `-----------------------------*/ 1103 | yyreduce: 1104 | /* yyn is the number of a rule to reduce with. */ 1105 | yylen = yyr2[yyn]; 1106 | 1107 | /* If YYLEN is nonzero, implement the default value of the action: 1108 | '$$ = $1'. 1109 | 1110 | Otherwise, the following line sets YYVAL to garbage. 1111 | This behavior is undocumented and Bison 1112 | users should not rely upon it. Assigning to YYVAL 1113 | unconditionally makes the parser a bit smaller, and it avoids a 1114 | GCC warning that YYVAL may be used uninitialized. */ 1115 | yyval = yyvsp[1-yylen]; 1116 | 1117 | 1118 | YY_REDUCE_PRINT (yyn); 1119 | switch (yyn) 1120 | { 1121 | 1122 | #line 1123 "y.tab.c" 1123 | 1124 | default: break; 1125 | } 1126 | /* User semantic actions sometimes alter yychar, and that requires 1127 | that yytoken be updated with the new translation. We take the 1128 | approach of translating immediately before every use of yytoken. 1129 | One alternative is translating here after every semantic action, 1130 | but that translation would be missed if the semantic action invokes 1131 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1132 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1133 | incorrect destructor might then be invoked immediately. In the 1134 | case of YYERROR or YYBACKUP, subsequent parser actions might lead 1135 | to an incorrect destructor call or verbose syntax error message 1136 | before the lookahead is translated. */ 1137 | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); 1138 | 1139 | YYPOPSTACK (yylen); 1140 | yylen = 0; 1141 | 1142 | *++yyvsp = yyval; 1143 | 1144 | /* Now 'shift' the result of the reduction. Determine what state 1145 | that goes to, based on the state we popped back to and the rule 1146 | number reduced by. */ 1147 | { 1148 | const int yylhs = yyr1[yyn] - YYNTOKENS; 1149 | const int yyi = yypgoto[yylhs] + *yyssp; 1150 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp 1151 | ? yytable[yyi] 1152 | : yydefgoto[yylhs]); 1153 | } 1154 | 1155 | goto yynewstate; 1156 | 1157 | 1158 | /*--------------------------------------. 1159 | | yyerrlab -- here on detecting error. | 1160 | `--------------------------------------*/ 1161 | yyerrlab: 1162 | /* Make sure we have latest lookahead translation. See comments at 1163 | user semantic actions for why this is necessary. */ 1164 | yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); 1165 | /* If not already recovering from an error, report this error. */ 1166 | if (!yyerrstatus) 1167 | { 1168 | ++yynerrs; 1169 | yyerror (YY_("syntax error")); 1170 | } 1171 | 1172 | if (yyerrstatus == 3) 1173 | { 1174 | /* If just tried and failed to reuse lookahead token after an 1175 | error, discard it. */ 1176 | 1177 | if (yychar <= YYEOF) 1178 | { 1179 | /* Return failure if at end of input. */ 1180 | if (yychar == YYEOF) 1181 | YYABORT; 1182 | } 1183 | else 1184 | { 1185 | yydestruct ("Error: discarding", 1186 | yytoken, &yylval); 1187 | yychar = YYEMPTY; 1188 | } 1189 | } 1190 | 1191 | /* Else will try to reuse lookahead token after shifting the error 1192 | token. */ 1193 | goto yyerrlab1; 1194 | 1195 | 1196 | /*---------------------------------------------------. 1197 | | yyerrorlab -- error raised explicitly by YYERROR. | 1198 | `---------------------------------------------------*/ 1199 | yyerrorlab: 1200 | /* Pacify compilers when the user code never invokes YYERROR and the 1201 | label yyerrorlab therefore never appears in user code. */ 1202 | if (0) 1203 | YYERROR; 1204 | ++yynerrs; 1205 | 1206 | /* Do not reclaim the symbols of the rule whose action triggered 1207 | this YYERROR. */ 1208 | YYPOPSTACK (yylen); 1209 | yylen = 0; 1210 | YY_STACK_PRINT (yyss, yyssp); 1211 | yystate = *yyssp; 1212 | goto yyerrlab1; 1213 | 1214 | 1215 | /*-------------------------------------------------------------. 1216 | | yyerrlab1 -- common code for both syntax error and YYERROR. | 1217 | `-------------------------------------------------------------*/ 1218 | yyerrlab1: 1219 | yyerrstatus = 3; /* Each real token shifted decrements this. */ 1220 | 1221 | /* Pop stack until we find a state that shifts the error token. */ 1222 | for (;;) 1223 | { 1224 | yyn = yypact[yystate]; 1225 | if (!yypact_value_is_default (yyn)) 1226 | { 1227 | yyn += YYSYMBOL_YYerror; 1228 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) 1229 | { 1230 | yyn = yytable[yyn]; 1231 | if (0 < yyn) 1232 | break; 1233 | } 1234 | } 1235 | 1236 | /* Pop the current state because it cannot handle the error token. */ 1237 | if (yyssp == yyss) 1238 | YYABORT; 1239 | 1240 | 1241 | yydestruct ("Error: popping", 1242 | YY_ACCESSING_SYMBOL (yystate), yyvsp); 1243 | YYPOPSTACK (1); 1244 | yystate = *yyssp; 1245 | YY_STACK_PRINT (yyss, yyssp); 1246 | } 1247 | 1248 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1249 | *++yyvsp = yylval; 1250 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1251 | 1252 | 1253 | /* Shift the error token. */ 1254 | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); 1255 | 1256 | yystate = yyn; 1257 | goto yynewstate; 1258 | 1259 | 1260 | /*-------------------------------------. 1261 | | yyacceptlab -- YYACCEPT comes here. | 1262 | `-------------------------------------*/ 1263 | yyacceptlab: 1264 | yyresult = 0; 1265 | goto yyreturnlab; 1266 | 1267 | 1268 | /*-----------------------------------. 1269 | | yyabortlab -- YYABORT comes here. | 1270 | `-----------------------------------*/ 1271 | yyabortlab: 1272 | yyresult = 1; 1273 | goto yyreturnlab; 1274 | 1275 | 1276 | /*-----------------------------------------------------------. 1277 | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | 1278 | `-----------------------------------------------------------*/ 1279 | yyexhaustedlab: 1280 | yyerror (YY_("memory exhausted")); 1281 | yyresult = 2; 1282 | goto yyreturnlab; 1283 | 1284 | 1285 | /*----------------------------------------------------------. 1286 | | yyreturnlab -- parsing is finished, clean up and return. | 1287 | `----------------------------------------------------------*/ 1288 | yyreturnlab: 1289 | if (yychar != YYEMPTY) 1290 | { 1291 | /* Make sure we have latest lookahead translation. See comments at 1292 | user semantic actions for why this is necessary. */ 1293 | yytoken = YYTRANSLATE (yychar); 1294 | yydestruct ("Cleanup: discarding lookahead", 1295 | yytoken, &yylval); 1296 | } 1297 | /* Do not reclaim the symbols of the rule whose action triggered 1298 | this YYABORT or YYACCEPT. */ 1299 | YYPOPSTACK (yylen); 1300 | YY_STACK_PRINT (yyss, yyssp); 1301 | while (yyssp != yyss) 1302 | { 1303 | yydestruct ("Cleanup: popping", 1304 | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); 1305 | YYPOPSTACK (1); 1306 | } 1307 | #ifndef yyoverflow 1308 | if (yyss != yyssa) 1309 | YYSTACK_FREE (yyss); 1310 | #endif 1311 | 1312 | return yyresult; 1313 | } 1314 | 1315 | #line 33 "exp.y" 1316 | 1317 | 1318 | int yyerror() 1319 | 1320 | { 1321 | 1322 | valid=0; 1323 | 1324 | printf("\nInvalid expression!\n"); 1325 | 1326 | return 0; 1327 | 1328 | } 1329 | 1330 | int main() 1331 | 1332 | { 1333 | 1334 | printf("\nEnter the expression:\n"); 1335 | 1336 | yyparse(); 1337 | 1338 | if(valid) 1339 | 1340 | { 1341 | 1342 | printf("\nValid expression!\n"); 1343 | 1344 | } 1345 | 1346 | } 1347 | -------------------------------------------------------------------------------- /YACC-Valid-Expressions/y.tab.h: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison interface for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 35 | especially those whose name start with YY_ or yy_. They are 36 | private implementation details that can be changed or removed. */ 37 | 38 | #ifndef YY_YY_Y_TAB_H_INCLUDED 39 | # define YY_YY_Y_TAB_H_INCLUDED 40 | /* Debug traces. */ 41 | #ifndef YYDEBUG 42 | # define YYDEBUG 0 43 | #endif 44 | #if YYDEBUG 45 | extern int yydebug; 46 | #endif 47 | 48 | /* Token kinds. */ 49 | #ifndef YYTOKENTYPE 50 | # define YYTOKENTYPE 51 | enum yytokentype 52 | { 53 | YYEMPTY = -2, 54 | YYEOF = 0, /* "end of file" */ 55 | YYerror = 256, /* error */ 56 | YYUNDEF = 257, /* "invalid token" */ 57 | num = 258, /* num */ 58 | id = 259, /* id */ 59 | op = 260 /* op */ 60 | }; 61 | typedef enum yytokentype yytoken_kind_t; 62 | #endif 63 | /* Token kinds. */ 64 | #define YYEMPTY -2 65 | #define YYEOF 0 66 | #define YYerror 256 67 | #define YYUNDEF 257 68 | #define num 258 69 | #define id 259 70 | #define op 260 71 | 72 | /* Value type. */ 73 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 74 | typedef int YYSTYPE; 75 | # define YYSTYPE_IS_TRIVIAL 1 76 | # define YYSTYPE_IS_DECLARED 1 77 | #endif 78 | 79 | 80 | extern YYSTYPE yylval; 81 | 82 | 83 | int yyparse (void); 84 | 85 | 86 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 87 | -------------------------------------------------------------------------------- /YACC-Valid-Identifiers/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cechengannur/Compiler-Design-Lab-S7/ca14cfe5f86c72a5bc0cb81cc950e01d98750353/YACC-Valid-Identifiers/a.out -------------------------------------------------------------------------------- /YACC-Valid-Identifiers/identifier.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include "y.tab.h" 4 | 5 | %} 6 | 7 | %% 8 | 9 | [a-zA-Z_][a-zA-Z_0-9]* return letter; 10 | 11 | [0-9] return digit; 12 | 13 | . return yytext[0]; 14 | 15 | \n return 0; 16 | 17 | %% 18 | 19 | int yywrap() 20 | 21 | { 22 | 23 | return 1; 24 | 25 | } 26 | 27 | // To compile this file, use the following command: 28 | // yacc -d identifier.y 29 | // lex identifier.l 30 | // gcc lex.yy.c y.tab.c -w 31 | // ./a.out -------------------------------------------------------------------------------- /YACC-Valid-Identifiers/identifier.y: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | int valid=1; 6 | 7 | %} 8 | 9 | %token digit letter 10 | 11 | %% 12 | 13 | start : letter s 14 | 15 | s : letter s 16 | 17 | | digit s 18 | 19 | | 20 | 21 | ; 22 | 23 | %% 24 | 25 | int yyerror() 26 | 27 | { 28 | 29 | printf("\nIts not a identifier!\n"); 30 | 31 | valid=0; 32 | 33 | return 0; 34 | 35 | } 36 | 37 | int main() 38 | 39 | { 40 | 41 | printf("\nEnter a name to tested for identifier "); 42 | 43 | yyparse(); 44 | 45 | if(valid) 46 | 47 | { 48 | 49 | printf("\nIt is a identifier!\n"); 50 | 51 | } 52 | 53 | } 54 | 55 | // To compile this file, use the following command: 56 | // yacc -d identifier.y 57 | // lex identifier.l 58 | // gcc lex.yy.c y.tab.c -w 59 | // ./a.out -------------------------------------------------------------------------------- /YACC-Valid-Identifiers/y.tab.c: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison implementation for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* C LALR(1) parser skeleton written by Richard Stallman, by 35 | simplifying the original so-called "semantic" parser. */ 36 | 37 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 38 | especially those whose name start with YY_ or yy_. They are 39 | private implementation details that can be changed or removed. */ 40 | 41 | /* All symbols defined below should begin with yy or YY, to avoid 42 | infringing on user name space. This should be done even for local 43 | variables, as they might otherwise be expanded by user macros. 44 | There are some unavoidable exceptions within include files to 45 | define necessary library symbols; they are noted "INFRINGES ON 46 | USER NAME SPACE" below. */ 47 | 48 | /* Identify Bison output, and Bison version. */ 49 | #define YYBISON 30802 50 | 51 | /* Bison version string. */ 52 | #define YYBISON_VERSION "3.8.2" 53 | 54 | /* Skeleton name. */ 55 | #define YYSKELETON_NAME "yacc.c" 56 | 57 | /* Pure parsers. */ 58 | #define YYPURE 0 59 | 60 | /* Push parsers. */ 61 | #define YYPUSH 0 62 | 63 | /* Pull parsers. */ 64 | #define YYPULL 1 65 | 66 | 67 | 68 | 69 | /* First part of user prologue. */ 70 | #line 1 "identifier.y" 71 | 72 | 73 | #include 74 | 75 | int valid=1; 76 | 77 | 78 | #line 79 "y.tab.c" 79 | 80 | # ifndef YY_CAST 81 | # ifdef __cplusplus 82 | # define YY_CAST(Type, Val) static_cast (Val) 83 | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) 84 | # else 85 | # define YY_CAST(Type, Val) ((Type) (Val)) 86 | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) 87 | # endif 88 | # endif 89 | # ifndef YY_NULLPTR 90 | # if defined __cplusplus 91 | # if 201103L <= __cplusplus 92 | # define YY_NULLPTR nullptr 93 | # else 94 | # define YY_NULLPTR 0 95 | # endif 96 | # else 97 | # define YY_NULLPTR ((void*)0) 98 | # endif 99 | # endif 100 | 101 | /* Use api.header.include to #include this header 102 | instead of duplicating it here. */ 103 | #ifndef YY_YY_Y_TAB_H_INCLUDED 104 | # define YY_YY_Y_TAB_H_INCLUDED 105 | /* Debug traces. */ 106 | #ifndef YYDEBUG 107 | # define YYDEBUG 0 108 | #endif 109 | #if YYDEBUG 110 | extern int yydebug; 111 | #endif 112 | 113 | /* Token kinds. */ 114 | #ifndef YYTOKENTYPE 115 | # define YYTOKENTYPE 116 | enum yytokentype 117 | { 118 | YYEMPTY = -2, 119 | YYEOF = 0, /* "end of file" */ 120 | YYerror = 256, /* error */ 121 | YYUNDEF = 257, /* "invalid token" */ 122 | digit = 258, /* digit */ 123 | letter = 259 /* letter */ 124 | }; 125 | typedef enum yytokentype yytoken_kind_t; 126 | #endif 127 | /* Token kinds. */ 128 | #define YYEMPTY -2 129 | #define YYEOF 0 130 | #define YYerror 256 131 | #define YYUNDEF 257 132 | #define digit 258 133 | #define letter 259 134 | 135 | /* Value type. */ 136 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 137 | typedef int YYSTYPE; 138 | # define YYSTYPE_IS_TRIVIAL 1 139 | # define YYSTYPE_IS_DECLARED 1 140 | #endif 141 | 142 | 143 | extern YYSTYPE yylval; 144 | 145 | 146 | int yyparse (void); 147 | 148 | 149 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 150 | /* Symbol kind. */ 151 | enum yysymbol_kind_t 152 | { 153 | YYSYMBOL_YYEMPTY = -2, 154 | YYSYMBOL_YYEOF = 0, /* "end of file" */ 155 | YYSYMBOL_YYerror = 1, /* error */ 156 | YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ 157 | YYSYMBOL_digit = 3, /* digit */ 158 | YYSYMBOL_letter = 4, /* letter */ 159 | YYSYMBOL_YYACCEPT = 5, /* $accept */ 160 | YYSYMBOL_start = 6, /* start */ 161 | YYSYMBOL_s = 7 /* s */ 162 | }; 163 | typedef enum yysymbol_kind_t yysymbol_kind_t; 164 | 165 | 166 | 167 | 168 | #ifdef short 169 | # undef short 170 | #endif 171 | 172 | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure 173 | and (if available) are included 174 | so that the code can choose integer types of a good width. */ 175 | 176 | #ifndef __PTRDIFF_MAX__ 177 | # include /* INFRINGES ON USER NAME SPACE */ 178 | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 179 | # include /* INFRINGES ON USER NAME SPACE */ 180 | # define YY_STDINT_H 181 | # endif 182 | #endif 183 | 184 | /* Narrow types that promote to a signed type and that can represent a 185 | signed or unsigned integer of at least N bits. In tables they can 186 | save space and decrease cache pressure. Promoting to a signed type 187 | helps avoid bugs in integer arithmetic. */ 188 | 189 | #ifdef __INT_LEAST8_MAX__ 190 | typedef __INT_LEAST8_TYPE__ yytype_int8; 191 | #elif defined YY_STDINT_H 192 | typedef int_least8_t yytype_int8; 193 | #else 194 | typedef signed char yytype_int8; 195 | #endif 196 | 197 | #ifdef __INT_LEAST16_MAX__ 198 | typedef __INT_LEAST16_TYPE__ yytype_int16; 199 | #elif defined YY_STDINT_H 200 | typedef int_least16_t yytype_int16; 201 | #else 202 | typedef short yytype_int16; 203 | #endif 204 | 205 | /* Work around bug in HP-UX 11.23, which defines these macros 206 | incorrectly for preprocessor constants. This workaround can likely 207 | be removed in 2023, as HPE has promised support for HP-UX 11.23 208 | (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of 209 | . */ 210 | #ifdef __hpux 211 | # undef UINT_LEAST8_MAX 212 | # undef UINT_LEAST16_MAX 213 | # define UINT_LEAST8_MAX 255 214 | # define UINT_LEAST16_MAX 65535 215 | #endif 216 | 217 | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ 218 | typedef __UINT_LEAST8_TYPE__ yytype_uint8; 219 | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ 220 | && UINT_LEAST8_MAX <= INT_MAX) 221 | typedef uint_least8_t yytype_uint8; 222 | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX 223 | typedef unsigned char yytype_uint8; 224 | #else 225 | typedef short yytype_uint8; 226 | #endif 227 | 228 | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ 229 | typedef __UINT_LEAST16_TYPE__ yytype_uint16; 230 | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ 231 | && UINT_LEAST16_MAX <= INT_MAX) 232 | typedef uint_least16_t yytype_uint16; 233 | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX 234 | typedef unsigned short yytype_uint16; 235 | #else 236 | typedef int yytype_uint16; 237 | #endif 238 | 239 | #ifndef YYPTRDIFF_T 240 | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ 241 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ 242 | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ 243 | # elif defined PTRDIFF_MAX 244 | # ifndef ptrdiff_t 245 | # include /* INFRINGES ON USER NAME SPACE */ 246 | # endif 247 | # define YYPTRDIFF_T ptrdiff_t 248 | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX 249 | # else 250 | # define YYPTRDIFF_T long 251 | # define YYPTRDIFF_MAXIMUM LONG_MAX 252 | # endif 253 | #endif 254 | 255 | #ifndef YYSIZE_T 256 | # ifdef __SIZE_TYPE__ 257 | # define YYSIZE_T __SIZE_TYPE__ 258 | # elif defined size_t 259 | # define YYSIZE_T size_t 260 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 261 | # include /* INFRINGES ON USER NAME SPACE */ 262 | # define YYSIZE_T size_t 263 | # else 264 | # define YYSIZE_T unsigned 265 | # endif 266 | #endif 267 | 268 | #define YYSIZE_MAXIMUM \ 269 | YY_CAST (YYPTRDIFF_T, \ 270 | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ 271 | ? YYPTRDIFF_MAXIMUM \ 272 | : YY_CAST (YYSIZE_T, -1))) 273 | 274 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) 275 | 276 | 277 | /* Stored state numbers (used for stacks). */ 278 | typedef yytype_int8 yy_state_t; 279 | 280 | /* State numbers in computations. */ 281 | typedef int yy_state_fast_t; 282 | 283 | #ifndef YY_ 284 | # if defined YYENABLE_NLS && YYENABLE_NLS 285 | # if ENABLE_NLS 286 | # include /* INFRINGES ON USER NAME SPACE */ 287 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 288 | # endif 289 | # endif 290 | # ifndef YY_ 291 | # define YY_(Msgid) Msgid 292 | # endif 293 | #endif 294 | 295 | 296 | #ifndef YY_ATTRIBUTE_PURE 297 | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) 298 | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) 299 | # else 300 | # define YY_ATTRIBUTE_PURE 301 | # endif 302 | #endif 303 | 304 | #ifndef YY_ATTRIBUTE_UNUSED 305 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) 306 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 307 | # else 308 | # define YY_ATTRIBUTE_UNUSED 309 | # endif 310 | #endif 311 | 312 | /* Suppress unused-variable warnings by "using" E. */ 313 | #if ! defined lint || defined __GNUC__ 314 | # define YY_USE(E) ((void) (E)) 315 | #else 316 | # define YY_USE(E) /* empty */ 317 | #endif 318 | 319 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ 320 | #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ 321 | # if __GNUC__ * 100 + __GNUC_MINOR__ < 407 322 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 323 | _Pragma ("GCC diagnostic push") \ 324 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") 325 | # else 326 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 327 | _Pragma ("GCC diagnostic push") \ 328 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ 329 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 330 | # endif 331 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 332 | _Pragma ("GCC diagnostic pop") 333 | #else 334 | # define YY_INITIAL_VALUE(Value) Value 335 | #endif 336 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 337 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 338 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END 339 | #endif 340 | #ifndef YY_INITIAL_VALUE 341 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ 342 | #endif 343 | 344 | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 345 | # define YY_IGNORE_USELESS_CAST_BEGIN \ 346 | _Pragma ("GCC diagnostic push") \ 347 | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") 348 | # define YY_IGNORE_USELESS_CAST_END \ 349 | _Pragma ("GCC diagnostic pop") 350 | #endif 351 | #ifndef YY_IGNORE_USELESS_CAST_BEGIN 352 | # define YY_IGNORE_USELESS_CAST_BEGIN 353 | # define YY_IGNORE_USELESS_CAST_END 354 | #endif 355 | 356 | 357 | #define YY_ASSERT(E) ((void) (0 && (E))) 358 | 359 | #if !defined yyoverflow 360 | 361 | /* The parser invokes alloca or malloc; define the necessary symbols. */ 362 | 363 | # ifdef YYSTACK_USE_ALLOCA 364 | # if YYSTACK_USE_ALLOCA 365 | # ifdef __GNUC__ 366 | # define YYSTACK_ALLOC __builtin_alloca 367 | # elif defined __BUILTIN_VA_ARG_INCR 368 | # include /* INFRINGES ON USER NAME SPACE */ 369 | # elif defined _AIX 370 | # define YYSTACK_ALLOC __alloca 371 | # elif defined _MSC_VER 372 | # include /* INFRINGES ON USER NAME SPACE */ 373 | # define alloca _alloca 374 | # else 375 | # define YYSTACK_ALLOC alloca 376 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 377 | # include /* INFRINGES ON USER NAME SPACE */ 378 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 379 | # ifndef EXIT_SUCCESS 380 | # define EXIT_SUCCESS 0 381 | # endif 382 | # endif 383 | # endif 384 | # endif 385 | # endif 386 | 387 | # ifdef YYSTACK_ALLOC 388 | /* Pacify GCC's 'empty if-body' warning. */ 389 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 390 | # ifndef YYSTACK_ALLOC_MAXIMUM 391 | /* The OS might guarantee only one guard page at the bottom of the stack, 392 | and a page size can be as small as 4096 bytes. So we cannot safely 393 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 394 | to allow for a few compiler-allocated temporary stack slots. */ 395 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 396 | # endif 397 | # else 398 | # define YYSTACK_ALLOC YYMALLOC 399 | # define YYSTACK_FREE YYFREE 400 | # ifndef YYSTACK_ALLOC_MAXIMUM 401 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 402 | # endif 403 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ 404 | && ! ((defined YYMALLOC || defined malloc) \ 405 | && (defined YYFREE || defined free))) 406 | # include /* INFRINGES ON USER NAME SPACE */ 407 | # ifndef EXIT_SUCCESS 408 | # define EXIT_SUCCESS 0 409 | # endif 410 | # endif 411 | # ifndef YYMALLOC 412 | # define YYMALLOC malloc 413 | # if ! defined malloc && ! defined EXIT_SUCCESS 414 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 415 | # endif 416 | # endif 417 | # ifndef YYFREE 418 | # define YYFREE free 419 | # if ! defined free && ! defined EXIT_SUCCESS 420 | void free (void *); /* INFRINGES ON USER NAME SPACE */ 421 | # endif 422 | # endif 423 | # endif 424 | #endif /* !defined yyoverflow */ 425 | 426 | #if (! defined yyoverflow \ 427 | && (! defined __cplusplus \ 428 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 429 | 430 | /* A type that is properly aligned for any stack member. */ 431 | union yyalloc 432 | { 433 | yy_state_t yyss_alloc; 434 | YYSTYPE yyvs_alloc; 435 | }; 436 | 437 | /* The size of the maximum gap between one aligned stack and the next. */ 438 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) 439 | 440 | /* The size of an array large to enough to hold all stacks, each with 441 | N elements. */ 442 | # define YYSTACK_BYTES(N) \ 443 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ 444 | + YYSTACK_GAP_MAXIMUM) 445 | 446 | # define YYCOPY_NEEDED 1 447 | 448 | /* Relocate STACK from its old location to the new one. The 449 | local variables YYSIZE and YYSTACKSIZE give the old and new number of 450 | elements in the stack, and YYPTR gives the new location of the 451 | stack. Advance YYPTR to a properly aligned location for the next 452 | stack. */ 453 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 454 | do \ 455 | { \ 456 | YYPTRDIFF_T yynewbytes; \ 457 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 458 | Stack = &yyptr->Stack_alloc; \ 459 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ 460 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ 461 | } \ 462 | while (0) 463 | 464 | #endif 465 | 466 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED 467 | /* Copy COUNT objects from SRC to DST. The source and destination do 468 | not overlap. */ 469 | # ifndef YYCOPY 470 | # if defined __GNUC__ && 1 < __GNUC__ 471 | # define YYCOPY(Dst, Src, Count) \ 472 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) 473 | # else 474 | # define YYCOPY(Dst, Src, Count) \ 475 | do \ 476 | { \ 477 | YYPTRDIFF_T yyi; \ 478 | for (yyi = 0; yyi < (Count); yyi++) \ 479 | (Dst)[yyi] = (Src)[yyi]; \ 480 | } \ 481 | while (0) 482 | # endif 483 | # endif 484 | #endif /* !YYCOPY_NEEDED */ 485 | 486 | /* YYFINAL -- State number of the termination state. */ 487 | #define YYFINAL 6 488 | /* YYLAST -- Last index in YYTABLE. */ 489 | #define YYLAST 5 490 | 491 | /* YYNTOKENS -- Number of terminals. */ 492 | #define YYNTOKENS 5 493 | /* YYNNTS -- Number of nonterminals. */ 494 | #define YYNNTS 3 495 | /* YYNRULES -- Number of rules. */ 496 | #define YYNRULES 5 497 | /* YYNSTATES -- Number of states. */ 498 | #define YYNSTATES 9 499 | 500 | /* YYMAXUTOK -- Last valid token kind. */ 501 | #define YYMAXUTOK 259 502 | 503 | 504 | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 505 | as returned by yylex, with out-of-bounds checking. */ 506 | #define YYTRANSLATE(YYX) \ 507 | (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 508 | ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 509 | : YYSYMBOL_YYUNDEF) 510 | 511 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 512 | as returned by yylex. */ 513 | static const yytype_int8 yytranslate[] = 514 | { 515 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 516 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 517 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 518 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 519 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 520 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 521 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 522 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 523 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 524 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 525 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 526 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 527 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 528 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 529 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 530 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 531 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 532 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 533 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 534 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 535 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 536 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 537 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 538 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 539 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 540 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4 541 | }; 542 | 543 | #if YYDEBUG 544 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 545 | static const yytype_int8 yyrline[] = 546 | { 547 | 0, 13, 13, 15, 17, 19 548 | }; 549 | #endif 550 | 551 | /** Accessing symbol of state STATE. */ 552 | #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) 553 | 554 | #if YYDEBUG || 0 555 | /* The user-facing name of the symbol whose (internal) number is 556 | YYSYMBOL. No bounds checking. */ 557 | static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 558 | 559 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 560 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 561 | static const char *const yytname[] = 562 | { 563 | "\"end of file\"", "error", "\"invalid token\"", "digit", "letter", 564 | "$accept", "start", "s", YY_NULLPTR 565 | }; 566 | 567 | static const char * 568 | yysymbol_name (yysymbol_kind_t yysymbol) 569 | { 570 | return yytname[yysymbol]; 571 | } 572 | #endif 573 | 574 | #define YYPACT_NINF (-4) 575 | 576 | #define yypact_value_is_default(Yyn) \ 577 | ((Yyn) == YYPACT_NINF) 578 | 579 | #define YYTABLE_NINF (-1) 580 | 581 | #define yytable_value_is_error(Yyn) \ 582 | 0 583 | 584 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 585 | STATE-NUM. */ 586 | static const yytype_int8 yypact[] = 587 | { 588 | 0, -3, 5, -3, -3, -4, -4, -4, -4 589 | }; 590 | 591 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 592 | Performed when YYTABLE does not specify something else to do. Zero 593 | means the default is an error. */ 594 | static const yytype_int8 yydefact[] = 595 | { 596 | 0, 5, 0, 5, 5, 2, 1, 4, 3 597 | }; 598 | 599 | /* YYPGOTO[NTERM-NUM]. */ 600 | static const yytype_int8 yypgoto[] = 601 | { 602 | -4, -4, -1 603 | }; 604 | 605 | /* YYDEFGOTO[NTERM-NUM]. */ 606 | static const yytype_int8 yydefgoto[] = 607 | { 608 | 0, 2, 5 609 | }; 610 | 611 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 612 | positive, shift that token. If negative, reduce the rule whose 613 | number is the opposite. If YYTABLE_NINF, syntax error. */ 614 | static const yytype_int8 yytable[] = 615 | { 616 | 3, 4, 7, 8, 1, 6 617 | }; 618 | 619 | static const yytype_int8 yycheck[] = 620 | { 621 | 3, 4, 3, 4, 4, 0 622 | }; 623 | 624 | /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of 625 | state STATE-NUM. */ 626 | static const yytype_int8 yystos[] = 627 | { 628 | 0, 4, 6, 3, 4, 7, 0, 7, 7 629 | }; 630 | 631 | /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ 632 | static const yytype_int8 yyr1[] = 633 | { 634 | 0, 5, 6, 7, 7, 7 635 | }; 636 | 637 | /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ 638 | static const yytype_int8 yyr2[] = 639 | { 640 | 0, 2, 2, 2, 2, 0 641 | }; 642 | 643 | 644 | enum { YYENOMEM = -2 }; 645 | 646 | #define yyerrok (yyerrstatus = 0) 647 | #define yyclearin (yychar = YYEMPTY) 648 | 649 | #define YYACCEPT goto yyacceptlab 650 | #define YYABORT goto yyabortlab 651 | #define YYERROR goto yyerrorlab 652 | #define YYNOMEM goto yyexhaustedlab 653 | 654 | 655 | #define YYRECOVERING() (!!yyerrstatus) 656 | 657 | #define YYBACKUP(Token, Value) \ 658 | do \ 659 | if (yychar == YYEMPTY) \ 660 | { \ 661 | yychar = (Token); \ 662 | yylval = (Value); \ 663 | YYPOPSTACK (yylen); \ 664 | yystate = *yyssp; \ 665 | goto yybackup; \ 666 | } \ 667 | else \ 668 | { \ 669 | yyerror (YY_("syntax error: cannot back up")); \ 670 | YYERROR; \ 671 | } \ 672 | while (0) 673 | 674 | /* Backward compatibility with an undocumented macro. 675 | Use YYerror or YYUNDEF. */ 676 | #define YYERRCODE YYUNDEF 677 | 678 | 679 | /* Enable debugging if requested. */ 680 | #if YYDEBUG 681 | 682 | # ifndef YYFPRINTF 683 | # include /* INFRINGES ON USER NAME SPACE */ 684 | # define YYFPRINTF fprintf 685 | # endif 686 | 687 | # define YYDPRINTF(Args) \ 688 | do { \ 689 | if (yydebug) \ 690 | YYFPRINTF Args; \ 691 | } while (0) 692 | 693 | 694 | 695 | 696 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 697 | do { \ 698 | if (yydebug) \ 699 | { \ 700 | YYFPRINTF (stderr, "%s ", Title); \ 701 | yy_symbol_print (stderr, \ 702 | Kind, Value); \ 703 | YYFPRINTF (stderr, "\n"); \ 704 | } \ 705 | } while (0) 706 | 707 | 708 | /*-----------------------------------. 709 | | Print this symbol's value on YYO. | 710 | `-----------------------------------*/ 711 | 712 | static void 713 | yy_symbol_value_print (FILE *yyo, 714 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 715 | { 716 | FILE *yyoutput = yyo; 717 | YY_USE (yyoutput); 718 | if (!yyvaluep) 719 | return; 720 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 721 | YY_USE (yykind); 722 | YY_IGNORE_MAYBE_UNINITIALIZED_END 723 | } 724 | 725 | 726 | /*---------------------------. 727 | | Print this symbol on YYO. | 728 | `---------------------------*/ 729 | 730 | static void 731 | yy_symbol_print (FILE *yyo, 732 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) 733 | { 734 | YYFPRINTF (yyo, "%s %s (", 735 | yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); 736 | 737 | yy_symbol_value_print (yyo, yykind, yyvaluep); 738 | YYFPRINTF (yyo, ")"); 739 | } 740 | 741 | /*------------------------------------------------------------------. 742 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | 743 | | TOP (included). | 744 | `------------------------------------------------------------------*/ 745 | 746 | static void 747 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) 748 | { 749 | YYFPRINTF (stderr, "Stack now"); 750 | for (; yybottom <= yytop; yybottom++) 751 | { 752 | int yybot = *yybottom; 753 | YYFPRINTF (stderr, " %d", yybot); 754 | } 755 | YYFPRINTF (stderr, "\n"); 756 | } 757 | 758 | # define YY_STACK_PRINT(Bottom, Top) \ 759 | do { \ 760 | if (yydebug) \ 761 | yy_stack_print ((Bottom), (Top)); \ 762 | } while (0) 763 | 764 | 765 | /*------------------------------------------------. 766 | | Report that the YYRULE is going to be reduced. | 767 | `------------------------------------------------*/ 768 | 769 | static void 770 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, 771 | int yyrule) 772 | { 773 | int yylno = yyrline[yyrule]; 774 | int yynrhs = yyr2[yyrule]; 775 | int yyi; 776 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", 777 | yyrule - 1, yylno); 778 | /* The symbols being reduced. */ 779 | for (yyi = 0; yyi < yynrhs; yyi++) 780 | { 781 | YYFPRINTF (stderr, " $%d = ", yyi + 1); 782 | yy_symbol_print (stderr, 783 | YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), 784 | &yyvsp[(yyi + 1) - (yynrhs)]); 785 | YYFPRINTF (stderr, "\n"); 786 | } 787 | } 788 | 789 | # define YY_REDUCE_PRINT(Rule) \ 790 | do { \ 791 | if (yydebug) \ 792 | yy_reduce_print (yyssp, yyvsp, Rule); \ 793 | } while (0) 794 | 795 | /* Nonzero means print parse trace. It is left uninitialized so that 796 | multiple parsers can coexist. */ 797 | int yydebug; 798 | #else /* !YYDEBUG */ 799 | # define YYDPRINTF(Args) ((void) 0) 800 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 801 | # define YY_STACK_PRINT(Bottom, Top) 802 | # define YY_REDUCE_PRINT(Rule) 803 | #endif /* !YYDEBUG */ 804 | 805 | 806 | /* YYINITDEPTH -- initial size of the parser's stacks. */ 807 | #ifndef YYINITDEPTH 808 | # define YYINITDEPTH 200 809 | #endif 810 | 811 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 812 | if the built-in stack extension method is used). 813 | 814 | Do not make this value too large; the results are undefined if 815 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 816 | evaluated with infinite-precision integer arithmetic. */ 817 | 818 | #ifndef YYMAXDEPTH 819 | # define YYMAXDEPTH 10000 820 | #endif 821 | 822 | 823 | 824 | 825 | 826 | 827 | /*-----------------------------------------------. 828 | | Release the memory associated to this symbol. | 829 | `-----------------------------------------------*/ 830 | 831 | static void 832 | yydestruct (const char *yymsg, 833 | yysymbol_kind_t yykind, YYSTYPE *yyvaluep) 834 | { 835 | YY_USE (yyvaluep); 836 | if (!yymsg) 837 | yymsg = "Deleting"; 838 | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); 839 | 840 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 841 | YY_USE (yykind); 842 | YY_IGNORE_MAYBE_UNINITIALIZED_END 843 | } 844 | 845 | 846 | /* Lookahead token kind. */ 847 | int yychar; 848 | 849 | /* The semantic value of the lookahead symbol. */ 850 | YYSTYPE yylval; 851 | /* Number of syntax errors so far. */ 852 | int yynerrs; 853 | 854 | 855 | 856 | 857 | /*----------. 858 | | yyparse. | 859 | `----------*/ 860 | 861 | int 862 | yyparse (void) 863 | { 864 | yy_state_fast_t yystate = 0; 865 | /* Number of tokens to shift before error messages enabled. */ 866 | int yyerrstatus = 0; 867 | 868 | /* Refer to the stacks through separate pointers, to allow yyoverflow 869 | to reallocate them elsewhere. */ 870 | 871 | /* Their size. */ 872 | YYPTRDIFF_T yystacksize = YYINITDEPTH; 873 | 874 | /* The state stack: array, bottom, top. */ 875 | yy_state_t yyssa[YYINITDEPTH]; 876 | yy_state_t *yyss = yyssa; 877 | yy_state_t *yyssp = yyss; 878 | 879 | /* The semantic value stack: array, bottom, top. */ 880 | YYSTYPE yyvsa[YYINITDEPTH]; 881 | YYSTYPE *yyvs = yyvsa; 882 | YYSTYPE *yyvsp = yyvs; 883 | 884 | int yyn; 885 | /* The return value of yyparse. */ 886 | int yyresult; 887 | /* Lookahead symbol kind. */ 888 | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; 889 | /* The variables used to return semantic value and location from the 890 | action routines. */ 891 | YYSTYPE yyval; 892 | 893 | 894 | 895 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 896 | 897 | /* The number of symbols on the RHS of the reduced rule. 898 | Keep to zero when no symbol should be popped. */ 899 | int yylen = 0; 900 | 901 | YYDPRINTF ((stderr, "Starting parse\n")); 902 | 903 | yychar = YYEMPTY; /* Cause a token to be read. */ 904 | 905 | goto yysetstate; 906 | 907 | 908 | /*------------------------------------------------------------. 909 | | yynewstate -- push a new state, which is found in yystate. | 910 | `------------------------------------------------------------*/ 911 | yynewstate: 912 | /* In all cases, when you get here, the value and location stacks 913 | have just been pushed. So pushing a state here evens the stacks. */ 914 | yyssp++; 915 | 916 | 917 | /*--------------------------------------------------------------------. 918 | | yysetstate -- set current state (the top of the stack) to yystate. | 919 | `--------------------------------------------------------------------*/ 920 | yysetstate: 921 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 922 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); 923 | YY_IGNORE_USELESS_CAST_BEGIN 924 | *yyssp = YY_CAST (yy_state_t, yystate); 925 | YY_IGNORE_USELESS_CAST_END 926 | YY_STACK_PRINT (yyss, yyssp); 927 | 928 | if (yyss + yystacksize - 1 <= yyssp) 929 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE 930 | YYNOMEM; 931 | #else 932 | { 933 | /* Get the current used size of the three stacks, in elements. */ 934 | YYPTRDIFF_T yysize = yyssp - yyss + 1; 935 | 936 | # if defined yyoverflow 937 | { 938 | /* Give user a chance to reallocate the stack. Use copies of 939 | these so that the &'s don't force the real ones into 940 | memory. */ 941 | yy_state_t *yyss1 = yyss; 942 | YYSTYPE *yyvs1 = yyvs; 943 | 944 | /* Each stack pointer address is followed by the size of the 945 | data in use in that stack, in bytes. This used to be a 946 | conditional around just the two extra args, but that might 947 | be undefined if yyoverflow is a macro. */ 948 | yyoverflow (YY_("memory exhausted"), 949 | &yyss1, yysize * YYSIZEOF (*yyssp), 950 | &yyvs1, yysize * YYSIZEOF (*yyvsp), 951 | &yystacksize); 952 | yyss = yyss1; 953 | yyvs = yyvs1; 954 | } 955 | # else /* defined YYSTACK_RELOCATE */ 956 | /* Extend the stack our own way. */ 957 | if (YYMAXDEPTH <= yystacksize) 958 | YYNOMEM; 959 | yystacksize *= 2; 960 | if (YYMAXDEPTH < yystacksize) 961 | yystacksize = YYMAXDEPTH; 962 | 963 | { 964 | yy_state_t *yyss1 = yyss; 965 | union yyalloc *yyptr = 966 | YY_CAST (union yyalloc *, 967 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); 968 | if (! yyptr) 969 | YYNOMEM; 970 | YYSTACK_RELOCATE (yyss_alloc, yyss); 971 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); 972 | # undef YYSTACK_RELOCATE 973 | if (yyss1 != yyssa) 974 | YYSTACK_FREE (yyss1); 975 | } 976 | # endif 977 | 978 | yyssp = yyss + yysize - 1; 979 | yyvsp = yyvs + yysize - 1; 980 | 981 | YY_IGNORE_USELESS_CAST_BEGIN 982 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", 983 | YY_CAST (long, yystacksize))); 984 | YY_IGNORE_USELESS_CAST_END 985 | 986 | if (yyss + yystacksize - 1 <= yyssp) 987 | YYABORT; 988 | } 989 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ 990 | 991 | 992 | if (yystate == YYFINAL) 993 | YYACCEPT; 994 | 995 | goto yybackup; 996 | 997 | 998 | /*-----------. 999 | | yybackup. | 1000 | `-----------*/ 1001 | yybackup: 1002 | /* Do appropriate processing given the current state. Read a 1003 | lookahead token if we need one and don't already have one. */ 1004 | 1005 | /* First try to decide what to do without reference to lookahead token. */ 1006 | yyn = yypact[yystate]; 1007 | if (yypact_value_is_default (yyn)) 1008 | goto yydefault; 1009 | 1010 | /* Not known => get a lookahead token if don't already have one. */ 1011 | 1012 | /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ 1013 | if (yychar == YYEMPTY) 1014 | { 1015 | YYDPRINTF ((stderr, "Reading a token\n")); 1016 | yychar = yylex (); 1017 | } 1018 | 1019 | if (yychar <= YYEOF) 1020 | { 1021 | yychar = YYEOF; 1022 | yytoken = YYSYMBOL_YYEOF; 1023 | YYDPRINTF ((stderr, "Now at end of input.\n")); 1024 | } 1025 | else if (yychar == YYerror) 1026 | { 1027 | /* The scanner already issued an error message, process directly 1028 | to error recovery. But do not keep the error token as 1029 | lookahead, it is too special and may lead us to an endless 1030 | loop in error recovery. */ 1031 | yychar = YYUNDEF; 1032 | yytoken = YYSYMBOL_YYerror; 1033 | goto yyerrlab1; 1034 | } 1035 | else 1036 | { 1037 | yytoken = YYTRANSLATE (yychar); 1038 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1039 | } 1040 | 1041 | /* If the proper action on seeing token YYTOKEN is to reduce or to 1042 | detect an error, take that action. */ 1043 | yyn += yytoken; 1044 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1045 | goto yydefault; 1046 | yyn = yytable[yyn]; 1047 | if (yyn <= 0) 1048 | { 1049 | if (yytable_value_is_error (yyn)) 1050 | goto yyerrlab; 1051 | yyn = -yyn; 1052 | goto yyreduce; 1053 | } 1054 | 1055 | /* Count tokens shifted since error; after three, turn off error 1056 | status. */ 1057 | if (yyerrstatus) 1058 | yyerrstatus--; 1059 | 1060 | /* Shift the lookahead token. */ 1061 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1062 | yystate = yyn; 1063 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1064 | *++yyvsp = yylval; 1065 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1066 | 1067 | /* Discard the shifted token. */ 1068 | yychar = YYEMPTY; 1069 | goto yynewstate; 1070 | 1071 | 1072 | /*-----------------------------------------------------------. 1073 | | yydefault -- do the default action for the current state. | 1074 | `-----------------------------------------------------------*/ 1075 | yydefault: 1076 | yyn = yydefact[yystate]; 1077 | if (yyn == 0) 1078 | goto yyerrlab; 1079 | goto yyreduce; 1080 | 1081 | 1082 | /*-----------------------------. 1083 | | yyreduce -- do a reduction. | 1084 | `-----------------------------*/ 1085 | yyreduce: 1086 | /* yyn is the number of a rule to reduce with. */ 1087 | yylen = yyr2[yyn]; 1088 | 1089 | /* If YYLEN is nonzero, implement the default value of the action: 1090 | '$$ = $1'. 1091 | 1092 | Otherwise, the following line sets YYVAL to garbage. 1093 | This behavior is undocumented and Bison 1094 | users should not rely upon it. Assigning to YYVAL 1095 | unconditionally makes the parser a bit smaller, and it avoids a 1096 | GCC warning that YYVAL may be used uninitialized. */ 1097 | yyval = yyvsp[1-yylen]; 1098 | 1099 | 1100 | YY_REDUCE_PRINT (yyn); 1101 | switch (yyn) 1102 | { 1103 | 1104 | #line 1105 "y.tab.c" 1105 | 1106 | default: break; 1107 | } 1108 | /* User semantic actions sometimes alter yychar, and that requires 1109 | that yytoken be updated with the new translation. We take the 1110 | approach of translating immediately before every use of yytoken. 1111 | One alternative is translating here after every semantic action, 1112 | but that translation would be missed if the semantic action invokes 1113 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1114 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1115 | incorrect destructor might then be invoked immediately. In the 1116 | case of YYERROR or YYBACKUP, subsequent parser actions might lead 1117 | to an incorrect destructor call or verbose syntax error message 1118 | before the lookahead is translated. */ 1119 | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); 1120 | 1121 | YYPOPSTACK (yylen); 1122 | yylen = 0; 1123 | 1124 | *++yyvsp = yyval; 1125 | 1126 | /* Now 'shift' the result of the reduction. Determine what state 1127 | that goes to, based on the state we popped back to and the rule 1128 | number reduced by. */ 1129 | { 1130 | const int yylhs = yyr1[yyn] - YYNTOKENS; 1131 | const int yyi = yypgoto[yylhs] + *yyssp; 1132 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp 1133 | ? yytable[yyi] 1134 | : yydefgoto[yylhs]); 1135 | } 1136 | 1137 | goto yynewstate; 1138 | 1139 | 1140 | /*--------------------------------------. 1141 | | yyerrlab -- here on detecting error. | 1142 | `--------------------------------------*/ 1143 | yyerrlab: 1144 | /* Make sure we have latest lookahead translation. See comments at 1145 | user semantic actions for why this is necessary. */ 1146 | yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); 1147 | /* If not already recovering from an error, report this error. */ 1148 | if (!yyerrstatus) 1149 | { 1150 | ++yynerrs; 1151 | yyerror (YY_("syntax error")); 1152 | } 1153 | 1154 | if (yyerrstatus == 3) 1155 | { 1156 | /* If just tried and failed to reuse lookahead token after an 1157 | error, discard it. */ 1158 | 1159 | if (yychar <= YYEOF) 1160 | { 1161 | /* Return failure if at end of input. */ 1162 | if (yychar == YYEOF) 1163 | YYABORT; 1164 | } 1165 | else 1166 | { 1167 | yydestruct ("Error: discarding", 1168 | yytoken, &yylval); 1169 | yychar = YYEMPTY; 1170 | } 1171 | } 1172 | 1173 | /* Else will try to reuse lookahead token after shifting the error 1174 | token. */ 1175 | goto yyerrlab1; 1176 | 1177 | 1178 | /*---------------------------------------------------. 1179 | | yyerrorlab -- error raised explicitly by YYERROR. | 1180 | `---------------------------------------------------*/ 1181 | yyerrorlab: 1182 | /* Pacify compilers when the user code never invokes YYERROR and the 1183 | label yyerrorlab therefore never appears in user code. */ 1184 | if (0) 1185 | YYERROR; 1186 | ++yynerrs; 1187 | 1188 | /* Do not reclaim the symbols of the rule whose action triggered 1189 | this YYERROR. */ 1190 | YYPOPSTACK (yylen); 1191 | yylen = 0; 1192 | YY_STACK_PRINT (yyss, yyssp); 1193 | yystate = *yyssp; 1194 | goto yyerrlab1; 1195 | 1196 | 1197 | /*-------------------------------------------------------------. 1198 | | yyerrlab1 -- common code for both syntax error and YYERROR. | 1199 | `-------------------------------------------------------------*/ 1200 | yyerrlab1: 1201 | yyerrstatus = 3; /* Each real token shifted decrements this. */ 1202 | 1203 | /* Pop stack until we find a state that shifts the error token. */ 1204 | for (;;) 1205 | { 1206 | yyn = yypact[yystate]; 1207 | if (!yypact_value_is_default (yyn)) 1208 | { 1209 | yyn += YYSYMBOL_YYerror; 1210 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) 1211 | { 1212 | yyn = yytable[yyn]; 1213 | if (0 < yyn) 1214 | break; 1215 | } 1216 | } 1217 | 1218 | /* Pop the current state because it cannot handle the error token. */ 1219 | if (yyssp == yyss) 1220 | YYABORT; 1221 | 1222 | 1223 | yydestruct ("Error: popping", 1224 | YY_ACCESSING_SYMBOL (yystate), yyvsp); 1225 | YYPOPSTACK (1); 1226 | yystate = *yyssp; 1227 | YY_STACK_PRINT (yyss, yyssp); 1228 | } 1229 | 1230 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1231 | *++yyvsp = yylval; 1232 | YY_IGNORE_MAYBE_UNINITIALIZED_END 1233 | 1234 | 1235 | /* Shift the error token. */ 1236 | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); 1237 | 1238 | yystate = yyn; 1239 | goto yynewstate; 1240 | 1241 | 1242 | /*-------------------------------------. 1243 | | yyacceptlab -- YYACCEPT comes here. | 1244 | `-------------------------------------*/ 1245 | yyacceptlab: 1246 | yyresult = 0; 1247 | goto yyreturnlab; 1248 | 1249 | 1250 | /*-----------------------------------. 1251 | | yyabortlab -- YYABORT comes here. | 1252 | `-----------------------------------*/ 1253 | yyabortlab: 1254 | yyresult = 1; 1255 | goto yyreturnlab; 1256 | 1257 | 1258 | /*-----------------------------------------------------------. 1259 | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | 1260 | `-----------------------------------------------------------*/ 1261 | yyexhaustedlab: 1262 | yyerror (YY_("memory exhausted")); 1263 | yyresult = 2; 1264 | goto yyreturnlab; 1265 | 1266 | 1267 | /*----------------------------------------------------------. 1268 | | yyreturnlab -- parsing is finished, clean up and return. | 1269 | `----------------------------------------------------------*/ 1270 | yyreturnlab: 1271 | if (yychar != YYEMPTY) 1272 | { 1273 | /* Make sure we have latest lookahead translation. See comments at 1274 | user semantic actions for why this is necessary. */ 1275 | yytoken = YYTRANSLATE (yychar); 1276 | yydestruct ("Cleanup: discarding lookahead", 1277 | yytoken, &yylval); 1278 | } 1279 | /* Do not reclaim the symbols of the rule whose action triggered 1280 | this YYABORT or YYACCEPT. */ 1281 | YYPOPSTACK (yylen); 1282 | YY_STACK_PRINT (yyss, yyssp); 1283 | while (yyssp != yyss) 1284 | { 1285 | yydestruct ("Cleanup: popping", 1286 | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); 1287 | YYPOPSTACK (1); 1288 | } 1289 | #ifndef yyoverflow 1290 | if (yyss != yyssa) 1291 | YYSTACK_FREE (yyss); 1292 | #endif 1293 | 1294 | return yyresult; 1295 | } 1296 | 1297 | #line 23 "identifier.y" 1298 | 1299 | 1300 | int yyerror() 1301 | 1302 | { 1303 | 1304 | printf("\nIts not a identifier!\n"); 1305 | 1306 | valid=0; 1307 | 1308 | return 0; 1309 | 1310 | } 1311 | 1312 | int main() 1313 | 1314 | { 1315 | 1316 | printf("\nEnter a name to tested for identifier "); 1317 | 1318 | yyparse(); 1319 | 1320 | if(valid) 1321 | 1322 | { 1323 | 1324 | printf("\nIt is a identifier!\n"); 1325 | 1326 | } 1327 | 1328 | } 1329 | -------------------------------------------------------------------------------- /YACC-Valid-Identifiers/y.tab.h: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison interface for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 35 | especially those whose name start with YY_ or yy_. They are 36 | private implementation details that can be changed or removed. */ 37 | 38 | #ifndef YY_YY_Y_TAB_H_INCLUDED 39 | # define YY_YY_Y_TAB_H_INCLUDED 40 | /* Debug traces. */ 41 | #ifndef YYDEBUG 42 | # define YYDEBUG 0 43 | #endif 44 | #if YYDEBUG 45 | extern int yydebug; 46 | #endif 47 | 48 | /* Token kinds. */ 49 | #ifndef YYTOKENTYPE 50 | # define YYTOKENTYPE 51 | enum yytokentype 52 | { 53 | YYEMPTY = -2, 54 | YYEOF = 0, /* "end of file" */ 55 | YYerror = 256, /* error */ 56 | YYUNDEF = 257, /* "invalid token" */ 57 | digit = 258, /* digit */ 58 | letter = 259 /* letter */ 59 | }; 60 | typedef enum yytokentype yytoken_kind_t; 61 | #endif 62 | /* Token kinds. */ 63 | #define YYEMPTY -2 64 | #define YYEOF 0 65 | #define YYerror 256 66 | #define YYUNDEF 257 67 | #define digit 258 68 | #define letter 259 69 | 70 | /* Value type. */ 71 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 72 | typedef int YYSTYPE; 73 | # define YYSTYPE_IS_TRIVIAL 1 74 | # define YYSTYPE_IS_DECLARED 1 75 | #endif 76 | 77 | 78 | extern YYSTYPE yylval; 79 | 80 | 81 | int yyparse (void); 82 | 83 | 84 | #endif /* !YY_YY_Y_TAB_H_INCLUDED */ 85 | --------------------------------------------------------------------------------