Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added switch example

  • Loading branch information...
commit c4085279b51a3af9b34b24c5700e0e010801db24 1 parent 6d6e0b9
@tj authored
Showing with 43 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +41 −0 examples/switch.g
View
2  .gitignore
@@ -1,3 +1,5 @@
.DS_Store
bin
*.o
+a.out
+examples/*.c
View
41 examples/switch.g
@@ -0,0 +1,41 @@
+
+%{
+#define YYSTYPE void *
+#define ON (void *) 1
+#define OFF (void *) 0
+%}
+
+program =
+ switch
+ | eol
+ | < (!eol .)* >
+ { fprintf(stderr, "parse error near '%s'\n", yytext); }
+ ;
+
+switch =
+ a:name - '=' - b:value
+ { printf("%s is now %s\n", a, b ? "on" : "off"); }
+ ;
+
+value =
+ 'on' { $$ = ON; }
+ | 'off' { $$ = OFF; }
+ ;
+
+name =
+ < [a-zA-Z_]+ >
+ { $$ = strdup(yytext); }
+ ;
+
+eol = '\n'
+- = [ \t]*
+
+%%
+
+int
+main(){
+ CDESCENT *G = yyparse_new(NULL);
+ while (yyparse(G)) ;
+ yyparse_free(G);
+ return 0;
+}

0 comments on commit c408527

Please sign in to comment.
Something went wrong with that request. Please try again.