Skip to content

Instantly share code, notes, and snippets.

@melchisedech333
Created March 27, 2022 05:15
Show Gist options
  • Save melchisedech333/af619f2f423b6aa7a5124622cda0c9b9 to your computer and use it in GitHub Desktop.
Save melchisedech333/af619f2f423b6aa7a5124622cda0c9b9 to your computer and use it in GitHub Desktop.
Lexer da análise dos arrays
%{
#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 ARRAY_A_OPEN; }
\] { return ARRAY_A_CLOSE; }
= { 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