Skip to content

Instantly share code, notes, and snippets.

@ztane
Last active October 24, 2016 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztane/59ba491c3eea1d5cfa85295bada3ca69 to your computer and use it in GitHub Desktop.
Save ztane/59ba491c3eea1d5cfa85295bada3ca69 to your computer and use it in GitHub Desktop.
Simple flex
%{
#include <stdio.h>
int line_num = 1;
%}
%%
"(" { printf("a opening parenthesis\n"); }
")" { printf("a closing parenthesis\n"); }
[0-9]+ { printf("a number: %s\n", yytext); }
[-*+/] { printf("an operator: %s\n", yytext); }
[\t ]+ { }
. { printf("line %d: error: unexpected: %s\n", line_num, yytext); }
\n { line_num++; }
%%
int yywrap(void){return 1;}
int main(int argc, char *argv[]) {
yylex();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment