From ad5576a5c88dabc4f80b45c0ee9e06dbd34bc46a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 7 Feb 2019 16:57:28 +0100 Subject: Skeleton parser --- src/sc2_test.c | 6 ++++ src/sc_lex.l | 38 ------------------------ src/sc_parse.y | 91 --------------------------------------------------------- src/storycode.l | 35 ++++++++++++++++++++++ src/storycode.y | 55 ++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 129 deletions(-) delete mode 100644 src/sc_lex.l delete mode 100644 src/sc_parse.y create mode 100644 src/storycode.l create mode 100644 src/storycode.y (limited to 'src') diff --git a/src/sc2_test.c b/src/sc2_test.c index c8f016a..f626f26 100644 --- a/src/sc2_test.c +++ b/src/sc2_test.c @@ -26,7 +26,13 @@ #include #include +#include "storycode.h" + int main(int argc, char *argv[]) { + printf("Here goes...\n"); + sc_scan_string("PRESTITLE: Hello\n"); + scparse(); + printf("Done.\n"); return 0; } diff --git a/src/sc_lex.l b/src/sc_lex.l deleted file mode 100644 index a636588..0000000 --- a/src/sc_lex.l +++ /dev/null @@ -1,38 +0,0 @@ -/* - * sc_lex.l - * - * Copyright © 2019 Thomas White - * - * This file is part of Colloquium. - * - * Colloquium is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -%{ - #include "sc_parse.tab.h" - -%} -%% -StoryCode { return STORYCODE; } -type { return TYPE; } -end { return END; } -[ \t\n] ; -[0-9]+\.[0-9]+ { sclval.fval = atof(yytext); return FLOAT; } -[0-9]+ { sclval.ival = atoi(yytext); return INT; } -[a-zA-Z0-9]+ { - sclval.sval = strdup(yytext); - return STRING; -} -%% diff --git a/src/sc_parse.y b/src/sc_parse.y deleted file mode 100644 index cb881f6..0000000 --- a/src/sc_parse.y +++ /dev/null @@ -1,91 +0,0 @@ -/* - * sc2_parse.y - * - * Copyright © 2019 Thomas White - * - * This file is part of Colloquium. - * - * Colloquium is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -%{ - // stuff from flex that bison needs to know about: - extern int sclex(); - extern int scparse(); - extern FILE *scin; - - void scerror(const char *s); -%} - -%union { - int ival; - float fval; - char *sval; -} - -%token STORYCODE TYPE -%token END - -%token INT -%token FLOAT -%token STRING - -%% - -storycode: - header template body_section footer { - printf("End of storycode\n"); - } - ; -header: - STORYCODE FLOAT { - printf("Reading Storycode version $2\n"); - } - ; -template: - typelines - ; -typelines: - typelines typeline - | typeline - ; -typeline: - TYPE STRING { - printf("type\n"); - free($2); - } - ; -body_section: - body_lines - ; -body_lines: - body_lines body_line - | body_line - ; -body_line: - INT INT INT INT STRING { - printf("type\n"); - free($5); - } - ; -footer: - END - ; - -%% - -void scerror(const char *s) { - printf("Error\n"); -} diff --git a/src/storycode.l b/src/storycode.l new file mode 100644 index 0000000..80d1a70 --- /dev/null +++ b/src/storycode.l @@ -0,0 +1,35 @@ +/* + * storycode.l + * + * Copyright © 2019 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +%{ + #include "storycode.tab.h" +%} + +%option noyywrap nounput noinput + +%% + +STYLES { return SC_STYLES; } +PRESTITLE { return SC_PRESTITLE; } +[a-zA-Z0-9]+ { sclval = strdup(yytext); return SC_STRING; } + +%% diff --git a/src/storycode.y b/src/storycode.y new file mode 100644 index 0000000..25d7bc2 --- /dev/null +++ b/src/storycode.y @@ -0,0 +1,55 @@ +/* + * storycode.y + * + * Copyright © 2019 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +%{ + extern int sclex(); + extern int scparse(); + void scerror(const char *s); +%} + +%define api.value.type {char *} +%token SC_STYLES +%token SC_PRESTITLE +%token SC_STRING + +%% + +storycode: + %empty + | scblock '\n' storycode { printf("End of storycode\n"); } + ; + +scblock: + stylesheet + | prestitle + +stylesheet: + SC_STYLES ':' + +prestitle: + SC_PRESTITLE ':' SC_STRING { printf("Presentation title: '%s'\n", $1); } + +%% + +void scerror(const char *s) { + printf("Error\n"); +} -- cgit v1.2.3