{"id":"7U534V2KG9","url":"https://pastebin.ca/7U534V2KG9","raw_url":"https://raw.anybin.ca/7U534V2KG9","visibility":"public","access":"public","created_at":1794509978372,"expires_at":1797101978372,"fetch_limit":null,"fetches_used":0,"reads_remaining":null,"size_bytes":3161,"syntax_hint":null,"title":null,"filename":null,"change_note":null,"cipher":null,"cipher_meta":null,"parent_id":null,"root_id":"7U534V2KG9","version":1,"owner_id":null,"recipient_id":null,"body":"RECURSIVE DESCENT\n---------------------------------\n\n#include <stdio.h>\n#include <string.h>\n\nchar str[50];\nint pt = 0, flag = 0;\n\nvoid E();\nvoid Eprime();\nvoid T();\nvoid Tprime();\nvoid F();\n\nvoid E() {\n    T();\n    Eprime();\n}\n\nvoid Eprime() {\n    if (str[pt] == '+') {\n        pt++;\n        T();\n        Eprime();\n    }\n}\n\nvoid T() {\n    F();\n    Tprime();\n}\n\nvoid Tprime() {\n    if (str[pt] == '*') {\n        pt++;\n        F();\n        Tprime();\n    }\n}\n\nvoid F() {\n    if (str[pt] == '(') {\n        pt++;\n        E();\n        if (str[pt] == ')')\n            pt++;\n        else\n            flag = 1;\n    } else if (str[pt] == 'a') {\n        pt++;\n    } else {\n        flag = 1;\n    }\n}\n\nint main() {\n    printf(\"Enter string: \");\n    scanf(\"%s\", str);\n\n    E();\n\n    if (flag == 0 && pt == strlen(str))\n        printf(\"String is Accepted\\n\");\n    else\n        printf(\"String is Rejected\\n\");\n\n    return 0;\n}\n\n----------------------------------------------\n\nE CLOSURE\n\n----------------------------------------------\n\n#include<stdio.h>\n#include<string.h>\n\nint main(){\n\n    char states[20][10],s1[20][10],in[20][10],s2[20][10],curr[10];\n    int i,k,n,t;\n\n    printf(\"Enter the Number of states: \");\n    scanf(\"%d\",&n);\n\n    printf(\"\\nEnter the states: \");\n    for(k=0;k<n;k++)\n        scanf(\"%s\",states[k]);\n\n    printf(\"\\nEnter the number of transitions: \");\n    scanf(\"%d\",&t);\n\n    printf(\"Enter the Transitions:\\n STATE1 -- INPUT -- STATE2\\n\");\n    for(i=0;i<t;i++)\n        scanf(\"%s %s %s\", s1[i],in[i],s2[i]);\n\n    for(k=0;k<n;k++){\n        strcpy(curr,states[k]);\n        printf(\"Epsilon closure of %s = { %s\",curr,curr);\n\n        for(i=0;i<t;i++){\n            if(strcmp(curr,s1[i])==0 && strcmp(in[i],\"e\")==0){\n                printf(\" , %s\",s2[i]);\n                strcpy(curr,s2[i]);\n            }\n        }\n        printf(\" }\\n\");\n    }\n    return 0;\n}\n\n---------------------------------------------------------------------\n\ncalculator\n\n\n--------------------------------------------------------------\n\n**********calc.l****************\n\n%{\n#include <stdio.h>\n#include <stdlib.h>\n#include \"y.tab.h\"\nextern int yylval;\n%}\n\n%%\n[ \\t]+      { ; }\n[0-9]+      { yylval = atoi(yytext); return NUMBER; }\n\\n          { return 0; }\n.           { return yytext[0]; }\n%%\n\nint yywrap() {\n    return 1;\n}\n\n**********calc.y***************\n\n%{\n#include <stdio.h>\n#include <stdlib.h>\nint flag = 0;\nint yylex(void);\nint yyerror(char *s);\n%}\n\n%token NUMBER\n%left '+' '-'\n%left '*' '/'\n%left '(' ')'\n\n%%\nArithmeticExpression: E { printf(\"\\nResult = %d\\n\", $1); return 0; }\n;\n\nE: E '+' E { $$ = $1 + $3; }\n | E '-' E { $$ = $1 - $3; }\n | E '*' E { $$ = $1 * $3; }\n | E '/' E {\n     if ($3 == 0) {\n         yyerror(\"Division by zero\");\n         flag = 1;\n         YYABORT;\n     } else {\n         $$ = $1 / $3;\n     }\n   }\n | '(' E ')' { $$ = $2; }\n | NUMBER { $$ = $1; }\n;\n%%\n\nint main() {\n    printf(\"\\nEnter any arithmetic expression:\\n\");\n    yyparse();\n    if (!flag)\n    {\n        printf(\"Entered arithmetic expression is valid\\n\");\n    }\n    return 0;\n}\n\nint yyerror(char *s) {\n    printf(\"\\nEntered arithmetic expression is invalid\\n\");\n    flag = 1;\n    return 0;\n}"}