__pycache__
+lex-yacc-examples/*.c
+lex-yacc-examples/*.h
+lex-yacc-examples/*.o
+lex-yacc-examples/*.xml
+lex-yacc-examples/example4
+lex-yacc-examples/example7
+skel/lex.yy.c
+skel/lex.yy.c.orig
tests/*.c
tests/*.o
tests/*.xml
tests/cal
tests/flex0
tests/flex1
-skel/lex.yy.c
-skel/lex.yy.c.orig
--- /dev/null
+all: example4 example7
+
+# example4 program
+example4: example4.tab.o example4.yy.o
+ ${CC} -o $@ $^
+
+example4.tab.o: example4.tab.c
+
+example4.tab.c: example4.y
+ ../../bootstrap_bison.git/src/bison -dy $< 2>$<.xml
+ mv y.tab.h example4.tab.h
+ mv y.tab.c $@
+
+example4.yy.o: example4.yy.c
+
+example4.yy.c: example4.l
+ ../../bootstrap_flex.git/src/flex -o /dev/null $< 2>$<.xml
+ ../bootstrap_plex.py $<.xml
+ mv lex.yy.c $@
+
+# example7 program
+example7: example7.tab.o example7.yy.o
+ ${CC} -o $@ $^
+
+example7.tab.o: example7.tab.c
+
+example7.tab.c: example7.y
+ ../../bootstrap_bison.git/src/bison -dy $< 2>$<.xml
+ mv y.tab.h example7.tab.h
+ mv y.tab.c $@
+
+example7.yy.o: example7.yy.c
+
+example7.yy.c: example7.l
+ ../../bootstrap_flex.git/src/flex -o /dev/null $< 2>$<.xml
+ ../bootstrap_plex.py $<.xml
+ mv lex.yy.c $@
+
+# other
+clean:
+ rm -f *.c *.o *.xml example4 example7
--- /dev/null
+lex example1.l
+cc lex.yy.c -o example1 -ll
--- /dev/null
+%{
+#include <stdio.h>
+%}
+
+%%
+stop printf("Stop command received\n");
+start printf("Start command received\n");
+%%
--- /dev/null
+lex example2.l
+cc lex.yy.c -o example2 -ll
--- /dev/null
+%{
+#include <stdio.h>
+%}
+
+%%
+[0123456789]+ printf("NUMBER\n");
+[a-zA-Z][a-zA-Z0-9]* printf("WORD\n");
+%%
--- /dev/null
+lex example3.l
+cc lex.yy.c -o example3 -ll
--- /dev/null
+%{
+#include <stdio.h>
+%}
+
+%%
+[a-zA-Z][a-zA-Z0-9]* printf("WORD ");
+[a-zA-Z0-9\/.-]+ printf("FILENAME ");
+\" printf("QUOTE ");
+\{ printf("OBRACE ");
+\} printf("EBRACE ");
+; printf("SEMICOLON ");
+\n printf("\n");
+[ \t]+ /* ignore whitespace */;
+%%
--- /dev/null
+lex example4.l
+yacc -d example4.y
+cc lex.yy.c y.tab.c -o example4
--- /dev/null
+%{
+#include <stdio.h>
+#include "example4.tab.h" /*"y.tab.h"*/
+%}
+%%
+[0-9]+ return NUMBER;
+heat return TOKHEAT;
+on|off return STATE;
+target return TOKTARGET;
+temperature return TOKTEMPERATURE;
+\n /* ignore end of line */;
+[ \t]+ /* ignore whitespace */;
+%%
--- /dev/null
+%{
+#include <stdio.h>
+#include <string.h>
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yyparse();
+}
+
+%}
+
+%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
+
+%%
+
+commands: /* empty */
+ | commands command
+ ;
+
+
+command:
+ heat_switch
+ |
+ target_set
+ ;
+
+heat_switch:
+ TOKHEAT STATE
+ {
+ printf("\tHeat turned on or off\n");
+ }
+ ;
+
+target_set:
+ TOKTARGET TOKTEMPERATURE NUMBER
+ {
+ printf("\tTemperature set\n");
+ }
+ ;
+
--- /dev/null
+lex example5.l
+yacc -d example5.y
+cc lex.yy.c y.tab.c -o example5
--- /dev/null
+%{
+#include <stdio.h>
+#include "example5.tab.h" /*"y.tab.h"*/
+%}
+%%
+[0-9]+ yylval=atoi(yytext); return NUMBER;
+heat return TOKHEAT;
+on|off yylval=!strcmp(yytext,"on"); return STATE;
+target return TOKTARGET;
+temperature return TOKTEMPERATURE;
+\n /* ignore end of line */;
+[ \t]+ /* ignore whitespace */;
+%%
--- /dev/null
+%{
+#include <stdio.h>
+#include <string.h>
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yyparse();
+}
+
+%}
+
+%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
+
+%%
+
+commands:
+ | commands command
+ ;
+
+
+command:
+ heat_switch
+ |
+ target_set
+ ;
+
+heat_switch:
+ TOKHEAT STATE
+ {
+ if($2)
+ printf("\tHeat turned on\n");
+ else
+ printf("\tHeat turned off\n");
+ }
+ ;
+
+target_set:
+ TOKTARGET TOKTEMPERATURE NUMBER
+ {
+ printf("\tTemperature set to %d\n",$3);
+ }
+ ;
+
--- /dev/null
+lex example6.l
+yacc --verbose --debug -d example6.y
+cc lex.yy.c y.tab.c -o example6
--- /dev/null
+%{
+#include <stdio.h>
+#include "example6.tab.h" /*"y.tab.h"*/
+%}
+
+%%
+
+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 */;
+%%
--- /dev/null
+%{
+#include <stdio.h>
+#include <string.h>
+
+#define YYSTYPE char *
+
+int yydebug=0;
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yyparse();
+}
+
+%}
+
+%token WORD FILENAME QUOTE OBRACE EBRACE SEMICOLON ZONETOK 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
--- /dev/null
+lex example7.l
+yacc -d example7.y
+cc lex.yy.c y.tab.c -o example7
--- /dev/null
+%{
+#include <stdio.h>
+#include <string.h>
+#include "example7.tab.h" /*"y.tab.h"*/
+%}
+%%
+[0-9]+ yylval.number=atoi(yytext); return NUMBER;
+heater return TOKHEATER;
+heat return TOKHEAT;
+on|off yylval.number=!strcmp(yytext,"on"); return STATE;
+target return TOKTARGET;
+temperature return TOKTEMPERATURE;
+[a-z0-9]+ yylval.string=strdup(yytext);return WORD;
+\n /* ignore end of line */;
+[ \t]+ /* ignore whitespace */;
+%%
--- /dev/null
+%{
+#include <stdio.h>
+#include <string.h>
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yyparse();
+}
+
+char *heater="default";
+
+%}
+
+%token TOKHEATER TOKHEAT TOKTARGET TOKTEMPERATURE
+
+%union
+{
+ int number;
+ char *string;
+}
+
+%token <number> STATE
+%token <number> NUMBER
+%token <string> WORD
+
+%%
+
+commands:
+ | commands command
+ ;
+
+
+command:
+ heat_switch | target_set | heater_select
+
+heat_switch:
+ TOKHEAT STATE
+ {
+ if($2)
+ printf("\tHeater '%s' turned on\n", heater);
+ else
+ printf("\tHeat '%s' turned off\n", heater);
+ }
+ ;
+
+target_set:
+ TOKTARGET TOKTEMPERATURE NUMBER
+ {
+ printf("\tHeater '%s' temperature set to %d\n",heater, $3);
+ }
+ ;
+
+heater_select:
+ TOKHEATER WORD
+ {
+ printf("\tSelected heater '%s'\n",$2);
+ heater=$2;
+ }
+ ;
\ No newline at end of file