Skip to content

Instantly share code, notes, and snippets.

@alksl
Created September 14, 2013 14:05
Show Gist options
  • Save alksl/6562314 to your computer and use it in GitHub Desktop.
Save alksl/6562314 to your computer and use it in GitHub Desktop.
%{
#include <stdio.h>
%}
%option noyywrap
IDENTIFIER [a-zA-ZS+=][a-zA-Z0-9+=]*
DIGIT [0-9]
LPAREN \(
RPAREN \)
QUOTE [`']
DOT \.
LBRACKET \[
RBRACKET \]
%%
{IDENTIFIER} {
printf("An identifier: %s\n", yytext);
}
-?{DIGIT}+\.{DIGIT}+ {
printf("A float: %s\n", yytext);
}
-?{DIGIT}+ {
printf("An integer: %s\n", yytext);
}
{LPAREN} {
printf("LPAREN: %s\n", yytext);
}
{RPAREN} {
printf("RPAREN: %s\n", yytext);
}
{QUOTE} {
printf("A quote %s\n", yytext);
}
{DOT} {
printf("A Dot: %s\n", yytext);
}
{LBRACKET} {
printf("LBRACKET: %s\n", yytext);
}
{RBRACKET} {
printf("RBRACKET: %s\n", yytext);
}
%%
int main(int argc, char** argv) {
yylex();
}
@alksl
Copy link
Author

alksl commented Sep 14, 2013

Run with
flex scanner.yy && cc lex.yy.c && ./a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment