diff options
author | 2022-09-22 14:40:15 +0200 | |
---|---|---|
committer | 2022-09-22 14:40:15 +0200 | |
commit | 61b26469a7898930fd30ab2432d25105d1a57e22 (patch) | |
tree | 4598461006248ac15e8fe622a78fa2b609bf33c1 | |
download | marcus-61b26469a7898930fd30ab2432d25105d1a57e22.tar.gz marcus-61b26469a7898930fd30ab2432d25105d1a57e22.zip |
-rw-r--r-- | Makefile | 53 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | main.c | 42 | ||||
-rw-r--r-- | parser/marcus.y | 23 | ||||
-rw-r--r-- | scanner/marcus.h | 26 | ||||
-rw-r--r-- | scanner/marcus.l | 16 |
6 files changed, 162 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c54efed --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +# +# Copyright (C) 2022 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> +# +# This file is part of marcus. +# +# desiderio 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. +# +# desiderio 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 desiderio. If not, see <https://www.gnu.org/licenses/>. +# + +OUT = marcus +CC = cc +LEX = lex +YACC = yacc + +SRC != find * -name '*c' +OBJ = ${SRC:.c=.o} + +LEX_SRC != find * -name '*l' +LEX_OBJ = ${LEX_SRC:.l=.c} +OBJ += ${LEX_SRC:.l=.o} + +YACC_SRC != find * -name '*y' +YACC_C = ${YACC_SRC:.y=.c} +YACC_H = ${YACC_SRC:.y=.h} +SRC += ${YACC_C} + +${OUT}: ${YACC_C} ${LEX_OBJ} ${OBJ} + @echo -- Generating ${OUT} + ${CC} -o ${OUT} ${OBJ} + +.l.c: ${LEX_SRC} + @echo -- Generating scanner files + ${LEX} -o $@ $> + +.c.o: + ${CC} -o $@ -c $> + +.y.c: ${YACC_SRC} + @echo -- Generating parser files + ${YACC} -o $@ -d $> + +clean: + rm -f ${OBJ} ${OUT} ${LEX_OBJ} ${YACC_C} ${YACC_H} diff --git a/README.md b/README.md new file mode 100644 index 0000000..16ea0d7 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Marcus +Marcus is a template engine for the C language.
\ No newline at end of file @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of marcus. + * + * desiderio 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. + * + * desiderio 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 desiderio. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "parser/marcus.h" +#include "scanner/marcus.h" + +int main(int argc, char** argv) +{ + printf("Hello World! Marcus.\n"); + yyparse(); + + return 0; +} + +int yywrap(void) +{ + return 0; +} + +int yyerror(char *errormsg) +{ + fprintf(stderr, "%s\n", errormsg); + exit(1); +}
\ No newline at end of file diff --git a/parser/marcus.y b/parser/marcus.y new file mode 100644 index 0000000..3e61bba --- /dev/null +++ b/parser/marcus.y @@ -0,0 +1,23 @@ +%{ + + #include <stdio.h> + #include <stdlib.h> + int yylex(void); + int yyerror(const char *s); + +%} + +%token HI BYE + +%% + +program: + hi bye + ; + +hi: + HI { printf("Hello World\n"); } + ; +bye: + BYE { printf("Bye World\n"); exit(0); } + ; diff --git a/scanner/marcus.h b/scanner/marcus.h new file mode 100644 index 0000000..03fc03f --- /dev/null +++ b/scanner/marcus.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of marcus. + * + * desiderio 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. + * + * desiderio 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 desiderio. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef __SCANNER_MARCUS_H__ +#define __SCANNER_MARCUS_H__ + +int yyerror(char *errormsg); +int yyparse(); + +#endif
\ No newline at end of file diff --git a/scanner/marcus.l b/scanner/marcus.l new file mode 100644 index 0000000..e5f613b --- /dev/null +++ b/scanner/marcus.l @@ -0,0 +1,16 @@ +%{ + + #include "../parser/marcus.h" + #include "marcus.h" + +%} + +%% + +("hi"|"oi")"\n" { return HI; } +("tchau"|"bye")"\n" { return BYE; } +[-[]+.,><] { return yytext[0]; } +. { yyerror("Unknow char"); } + +%% + |