Created
March 27, 2022 04:14
-
-
Save melchisedech333/7dc1b1e2f8abd3ce4d020bb965d2b52e to your computer and use it in GitHub Desktop.
Lex para analisar variáveis
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> | |
#include "y.tab.h" | |
void yyerror (char *c); | |
%} | |
CHARS [a-zA-Z0-9]+ | |
STRING \"{CHARS}\" | |
NUMBER [0-9]+ | |
IDENTIFIER {CHARS} | |
VARTYPE [:]{CHARS} | |
SPACETABS [ \t\n] | |
%% | |
var { | |
return START; | |
} | |
{STRING} { | |
yylval.value = strdup(yytext); | |
return STRING; | |
} | |
{NUMBER} { | |
yylval.value = strdup(yytext); | |
return INTEGER; | |
} | |
{IDENTIFIER} { | |
yylval.value = strdup(yytext); | |
return VARIABLE; | |
} | |
{VARTYPE} { | |
yylval.value = strdup(yytext); | |
return TYPE; | |
} | |
= { return ATTR; } | |
, { return SEPARATOR; } | |
; { return END; } | |
{SPACETABS} { } | |
%% | |
int yywrap () { | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment