Skip to content

Instantly share code, notes, and snippets.

@nityeshaga
Created November 24, 2018 03:06
Show Gist options
  • Select an option

  • Save nityeshaga/d523dfcbaa88056ef02fb71d74ff7f25 to your computer and use it in GitHub Desktop.

Select an option

Save nityeshaga/d523dfcbaa88056ef02fb71d74ff7f25 to your computer and use it in GitHub Desktop.
Sample yacc
%{
#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