Skip to content

Instantly share code, notes, and snippets.

@melchisedech333
Created March 27, 2022 01:12
Show Gist options
  • Save melchisedech333/be97d7f410b018ded40b81d50400b5bc to your computer and use it in GitHub Desktop.
Save melchisedech333/be97d7f410b018ded40b81d50400b5bc to your computer and use it in GitHub Desktop.
Código Lex
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
void yyerror (char *c);
%}
/* Todos outros tokens não especificados. */
OTHERS .
/* Ignora todos espaços, tabs e semelhantes. */
SPACE_TABS [[:space:]]+
/* Inteiros. */
INTEGER [0-9]+
%%
{INTEGER} {
yylval.token.type = TOKEN_INTEGER;
yylval.token.integer = atoi(yytext);
return TOKEN;
}
{SPACE_TABS} ;
{OTHERS} {
yylval.token.type = TOKEN_UNKNOWN;
yylval.token.unknown = strdup(yytext);
return TOKEN;
}
%%
int yywrap () {
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment