[Assorted-commits] SF.net SVN: assorted: [851] sandbox/trunk/src/flex-bison/lex-yacc-howto
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-06-03 17:32:43
|
Revision: 851 http://assorted.svn.sourceforge.net/assorted/?rev=851&view=rev Author: yangzhang Date: 2008-06-03 10:32:50 -0700 (Tue, 03 Jun 2008) Log Message: ----------- added ex6 Added Paths: ----------- sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/Makefile sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.l sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.y Copied: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/Makefile (from rev 848, sandbox/trunk/src/flex-bison/lex-yacc-howto/ex5/Makefile) =================================================================== --- sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/Makefile (rev 0) +++ sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/Makefile 2008-06-03 17:32:50 UTC (rev 851) @@ -0,0 +1,13 @@ +all: ex6 + +%: %.tab.c %.yy.c + gcc -Wall -o $@ $^ + +%.yy.c: %.l %.tab.h + flex -o $@ $< + +%.tab.c: %.y + bison -d $< + +%.tab.h: %.y + bison -d $< Added: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.l =================================================================== --- sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.l (rev 0) +++ sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.l 2008-06-03 17:32:50 UTC (rev 851) @@ -0,0 +1,22 @@ +%{ +// Note that this ordering is important; #define YYSTYPE must come before the +// #include "ex6.tab.h"! +#define YYSTYPE char * +#include "ex6.tab.h" +%} + +%option nounput + +%% + +zone return ZONETOK; +file return FILETOK; +[a-zA-Z][a-zA-Z0-9]* yylval=strdup(yytext); return WORD; +[a-zA-Z0-9\/.-]+ yylval=strdup(yytext); return FILENAME; +\" return QUOTE; +\{ return OBRACE; +\} return EBRACE; +; return SEMICOLON; +\n /* ignore EOL */; +[ \t]+ /* ignore whitespace */; +%% Added: sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.y =================================================================== --- sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.y (rev 0) +++ sandbox/trunk/src/flex-bison/lex-yacc-howto/ex6/ex6.y 2008-06-03 17:32:50 UTC (rev 851) @@ -0,0 +1,81 @@ +%{ +#include <stdio.h> +#include <string.h> + +#define YYSTYPE char * + +int yylex(void); + +void yyerror(const char *str) +{ + fprintf(stderr,"error: %s\n",str); +} + +int yywrap() +{ + return 1; +} + +%} + +%token SEMICOLON ZONETOK OBRACE EBRACE QUOTE FILENAME WORD FILETOK + +%% + +commands: + | + commands command SEMICOLON + ; + + +command: + zone_set + ; + +zone_set: + ZONETOK quotedname zonecontent + { + printf("Complete zone for '%s' found\n",$2); + } + ; + +zonecontent: + OBRACE zonestatements EBRACE + +quotedname: + QUOTE FILENAME QUOTE + { + $$=$2; + } + +zonestatements: + | + zonestatements zonestatement SEMICOLON + ; + +zonestatement: + statements + | + FILETOK quotedname + { + printf("A zonefile name '%s' was encountered\n", $2); + } + ; + +block: + OBRACE zonestatements EBRACE SEMICOLON + ; + +statements: + | statements statement + ; + +statement: WORD | block | quotedname + +%% + +int main() +{ + yyparse(); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |