-
-
Save meldsza/856d9a07abc81e28c55028345010079a to your computer and use it in GitHub Desktop.
Revisions
-
meldsza created this gist
Feb 25, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ %{ #include "y.tab.h" %} %% [0-9] {return DIGIT;} [a-zA-Z] {return LETTER;} [_] {return UND;} \n {return NL;} . {return yytext[0];} %% int yywrap() { return 1; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ %{ #include <stdio.h> #include <stdlib.h> %} %token NL DIGIT LETTER UND %% id: letter_und alphanum NL { printf("Valid\n");exit(0);} ; letter_und: LETTER | UND alphanum_: LETTER|UND|DIGIT ; alphanum: alphanum_ alphanum | alphanum_ ; %% int yyerror(char *msg) { printf("Invalid statements\n"); exit(0); } int main() { printf("Enter input: \n"); yyparse(); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ %{ #include "y.tab.h" %} %% "if" {return IF;} [sS][0-9]* {return S;} [a-zA-Z][a-zA-Z0-9]* {return ID;} [0-9]+ {return NUM;} ">"|"<"|">="|"<="|"=="|"!=" {return RELOP;} \n {return NL;} . {return yytext[0];} %% int yywrap() { return 1; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ %{ #include <stdio.h> #include <stdlib.h> int count; %} %token NL S ID NUM IF RELOP %% stmt : ifstmt NL {printf("valid \t"); printf("Number of nested statements is : %d\n",count);exit(0);}; ifstmt : IF'('cond')''{'ifstmt'}' {count++;} | S | ; cond : X RELOP X ; X : ID | NUM ; %% int yyerror(char *msg) { printf("Invalid statement"); exit(0); } int main() { printf("Enter input: \n"); yyparse(); return 0; }