Created
March 15, 2020 22:04
-
-
Save thunderInfy/3c5c69fd9e847fa4a56a7d11a143d387 to your computer and use it in GitHub Desktop.
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 <string.h> | |
| int yylex(); | |
| int yyerror(char *s); | |
| %} | |
| %token STRING NUMBER SEMICOLON OTHER | |
| %type <name> STRING | |
| %union{ | |
| char name[20]; | |
| } | |
| %% | |
| program: | |
| statements | |
| ; | |
| statements: | |
| | statement SEMICOLON statements | |
| ; | |
| statement: | |
| STRING { | |
| if(strcmp($1,"hello")==0){ | |
| printf("Hello to you too! How're you?"); | |
| } | |
| else{ | |
| printf("I know what you typed is a string but all I know is \"hello\" :("); | |
| } | |
| } | |
| | NUMBER { | |
| printf("This is a number"); | |
| } | |
| | OTHER { | |
| printf("Sorry, I can't comprehend this :("); | |
| } | |
| ; | |
| %% | |
| int yyerror(char *s){ | |
| printf("Syntax error\n"); | |
| return 0; | |
| } | |
| int main(){ | |
| yyparse(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment