Skip to content

Instantly share code, notes, and snippets.

@virtix
Created June 1, 2012 20:55
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 virtix/2855090 to your computer and use it in GitHub Desktop.
Save virtix/2855090 to your computer and use it in GitHub Desktop.
/*Simple lexer to talk with bison*/
%option noyywrap case-insensitive yylineno
%{
# include "bison1.tab.h"
%}
BAR (bar)
PREFIX ^([ \t]*\-[ \t]*)
HTTP (http[s]?://)
FETCH ("Open"|"Go"|"Go to"|"Goto"|"Fetch"|"Get")
POST ("Put"|"Post")
CLICK ("Click")
TYPE ("Type")
WS [ \t]+
ANY .+
WS_ANY {WS}{ANY}
%%
{BAR} {
yylval.s=strdup(yytext);
return BAR;
}
.|\n /* eat up any unmatched character */
%%
/* simple flex and bison integration. Spiking on how */
%{
# include <stdio.h>
%}
%union {
struct ast *a;
char * s;
}
/* declare tokens */
%token <s> BAR
%%
foo: /* nothing */
| foo BAR{ printf("BAR = %s\n> ", $2); }
;
%%
main() {
printf("> ");
yyparse();
}
yyerror(char *s) {
fprintf(stderr, "error: %s\n", s);
}
all: bison-1
bison-1: bison1.l bison1.y
bison -d bison1.y
flex -v -obison1.lex.c bison1.l
gcc -o $@ bison1.tab.c bison1.lex.c
clean:
rm -f bison-1 \
bison1.lex.c bison1.tab.h bison1.tab.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment