Created
March 27, 2022 01:13
-
-
Save melchisedech333/2b19520e374570ab19a62e988c6921fc to your computer and use it in GitHub Desktop.
Código Yacc
This file contains 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> | |
void yyerror (char *c); | |
int yylex (void); | |
%} | |
%union { | |
struct { | |
int type; | |
int integer; | |
char * unknown; | |
} token; | |
}; | |
%token TOKEN | |
%token TOKEN_UNKNOWN TOKEN_INTEGER | |
%% | |
SENTENCE: | |
SENTENCE TOKEN { | |
switch ( $<token.type>2 ) { | |
case TOKEN_UNKNOWN: | |
printf("type: UNKNOWN\ntoken: %s\n\n", $<token.unknown>2); | |
break; | |
case TOKEN_INTEGER: | |
printf("type: INTEGER\ntoken: %d\n\n", $<token.integer>2); | |
break; | |
} | |
} | |
| | |
; | |
%% | |
void yyerror (char *c) { | |
printf("Error: %s\n", c); | |
} | |
int main () { | |
yyparse(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment