Created
November 24, 2018 03:06
-
-
Save nityeshaga/d523dfcbaa88056ef02fb71d74ff7f25 to your computer and use it in GitHub Desktop.
Sample yacc
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 characters
| %{ | |
| #include<stdio.h> | |
| #include<stdlib.h> | |
| %} | |
| %token IF ELSE ob cb sc tt vb nu op ass | |
| %left '+' '-' | |
| %left '*' '/' | |
| %% | |
| S: IF cond stat efs ELSE stat {printf("correct\n");} | |
| efs: | |
| |efs ef | |
| ; | |
| // ... | |
| // ... | |
| %% | |
| extern int linenum; | |
| int yywrap() | |
| { | |
| return 1; | |
| } | |
| int main() | |
| { | |
| printf("Enter the statement\n"); | |
| yyparse(); | |
| printf("\n valid expression"); | |
| return 0; | |
| } | |
| void yyerror() | |
| { | |
| printf("\n invalid expression %d\n",linenum); | |
| exit(0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment