Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add example5, example6. But example6 will throw SEGV.

  • Loading branch information...
commit 592f5d827fb99d6b1ddf0eb331e1bac7370f9a28 1 parent c4acbea
@zigorou authored
View
16 CMakeLists.txt
@@ -25,3 +25,19 @@ add_executable(example4
${FLEX_Example4Scanner_OUTPUTS}
)
+BISON_TARGET(Example5Parser example5.y ${CMAKE_CURRENT_BINARY_DIR}/example5.tab.c)
+FLEX_TARGET(Example5Scanner example5.l ${CMAKE_CURRENT_BINARY_DIR}/example5.yy.c)
+ADD_FLEX_BISON_DEPENDENCY(Example5Scanner Example5Parser)
+add_executable(example5
+ ${BISON_Example5Parser_OUTPUTS}
+ ${FLEX_Example5Scanner_OUTPUTS}
+)
+
+BISON_TARGET(Example6Parser example6.y ${CMAKE_CURRENT_BINARY_DIR}/example6.tab.c)
+FLEX_TARGET(Example6Scanner example6.l ${CMAKE_CURRENT_BINARY_DIR}/example6.yy.c)
+ADD_FLEX_BISON_DEPENDENCY(Example6Scanner Example6Parser)
+add_executable(example6
+ ${BISON_Example6Parser_OUTPUTS}
+ ${FLEX_Example6Scanner_OUTPUTS}
+)
+
View
15 example5.l
@@ -0,0 +1,15 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "example5.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 linebreak */;
+[ \t]+ /* ignore tab */;
+%%
View
49 example5.y
@@ -0,0 +1,49 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+%}
+
+%token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE
+
+%%
+commands: /* empty */
+ | 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 %d\n", $3);
+ }
+ ;
+%%
+
+void yyerror(const char *str) {
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap() {
+ return 1;
+}
+
+int main(void) {
+ yyparse();
+ exit(0);
+}
View
18 example6.l
@@ -0,0 +1,18 @@
+%{
+#include <stdio.h>
+#include <string.h>
+#include "example6.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 linebreak */
+[ \t]+ /* ignore whitespaces */;
+%%
View
6 example6.txt
@@ -0,0 +1,6 @@
+zone "." {
+ type hint;
+ file "/etc/bind/db.root";
+ type hint;
+};
+
View
76 example6.y
@@ -0,0 +1,76 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define YYSTYPE char *
+%}
+
+%token ZONETOK FILETOK WORD FILENAME QUOTE OBRACE EBRACE SEMICOLON
+
+%%
+commands: /* empty */
+ | 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: /* empty */
+ |
+ zonestatements zonestatement SEMICOLON
+ ;
+
+zonestatement:
+ statements
+ |
+ FILETOK quotedname
+ {
+ printf("A zonefile name '%s' was encountered\n", $2);
+ }
+ ;
+
+block:
+ OBRACE zonestatements EBRACE SEMICOLON
+ ;
+
+statements: /* empty */
+ | statements statement
+ ;
+
+statement:
+ WORD | block | quotedname
+ ;
+%%
+
+void yyerror(const char *str) {
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap() {
+ return 1;
+}
+
+int main(void) {
+ yyparse();
+ exit(0);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.