Created
June 1, 2012 20:55
-
-
Save virtix/2855090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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 */ | |
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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