diff --git a/Makefile b/Makefile index d748995..16dd71c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ CC = g++ CFLAGS = -g -all: cyoa -cyoa: cyoa.c +all: storybook +storybook: main.c cyoa.c + $(CC) $(CFLAGS) main.c -o storybook cyoa.c: cyoa.leg leg -o $@ $^ clean: - rm -f cyoa.c cyoa + rm -f cyoa.c cyoa storybook diff --git a/cyoa.leg b/cyoa.leg index 8dafaec..383b1df 100644 --- a/cyoa.leg +++ b/cyoa.leg @@ -85,29 +85,27 @@ union value { %} -Story = BlankLine* (p:Page { pages.push_back(p.page); })+ EndOfFile; +Story = BlankLine* (p:Page { pages.push_back(p.page); })+ EndOfFile Page = h:Header b:Body { $$.page = b.page; $$.page->id = h.string} - BlankLine*; + BlankLine* Header = < i:Identifier > Newline BlankLine* { $$ = i; } -Identifier = < [A-Z][A-Z0-9_]+ > - { $$.string = strndup(yytext, yyleng); }; +Identifier = < [A-Z][A-Z0-9_]+ > - { $$.string = strndup(yytext, yyleng); } -Body = Footer | t:TextLine b:Body { $$ = b; append_body(b.page, t.string);}; +Body = Footer | t:TextLine b:Body { $$ = b; append_body(b.page, t.string);} -TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng); }; +TextLine = < (!Newline .)* Newline > { $$.string = strndup(yytext, yyleng); } Footer = Ending { $$.page = emit_ending(); } | g:Goto { $$.page = emit_goto(g.string); } | c:ChoiceList { $$.page = emit_choices(c.choices); } - ; Goto = 'GOTO' - < i:Identifier > Newline { $$.string = strndup(yytext, yyleng); } - ; -Ending = 'THE END' Newline; +Ending = 'THE END' Newline ChoiceList = c:Choice l:ChoiceList { $$ = l; $$.choices->push_back(c.choice); } | c:Choice { $$.choices = new std::vector(); $$.choices->push_back(c.choice); } @@ -117,11 +115,11 @@ Choice = b:Bullet f:Freetext r:Redirect $$ = r; $$.choice->option = b.num; $$.choice->flavor = f.string; - }; + } -Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); }; +Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); } -Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); }; +Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); } Redirect = ck:StatCheck? '[' i:Identifier ']' - cg:StatChange? Newline { $$.choice = new Choice(i.string, ck.statcheck, cg.statchange); } @@ -132,7 +130,7 @@ StatCheck = '<' n:StatName v:StatVal r:StatRel '>' - StatChange = '(' ('+' | '-') v:StatVal n:StatName ')' { $$.statchange = new statchange_t{n.string, v.num}; } -StatName = < [A-Za-z]+ > - { $$.string = strdup(yytext); }; +StatName = < [A-Za-z]+ > - { $$.string = strdup(yytext); } StatVal = < [0-9]+ > - { $$.num = atoi(yytext); } @@ -231,18 +229,6 @@ std::vector CyoaParse(FILE *file) { return pages; } -int main(int argc, char **argv) { - if (argc < 2) { - return 1; - } - FILE* fin = fopen(argv[1], "r"); - auto mypages = CyoaParse(fin); - for (Page* page : pages) { - print_page(page); - } - return 0; -} - /* Local Variables: */ /* mode: text */ /* End: */ diff --git a/main.c b/main.c new file mode 100644 index 0000000..a95fda4 --- /dev/null +++ b/main.c @@ -0,0 +1,13 @@ +#include "cyoa.c" + +int main(int argc, char **argv) { + if (argc < 2) { + return 1; + } + FILE* fin = fopen(argv[1], "r"); + auto mypages = CyoaParse(fin); + for (Page* page : pages) { + print_page(page); + } + return 0; +} diff --git a/storybook b/storybook new file mode 100755 index 0000000..12453c9 Binary files /dev/null and b/storybook differ