From 1e76448ceda79070fa153ed4cc02bf86472f9501 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 23 Feb 2019 11:39:19 +0100 Subject: [PATCH] examples: remove stray examples * examples/c/reentrant-calc: Remove. I did not mean to include this example, it was replaced by examples/c/reccalc. --- examples/c/reccalc/reccalc.test | 2 +- examples/c/reentrant-calc/Makefile | 35 ------ examples/c/reentrant-calc/README.md | 28 ----- examples/c/reentrant-calc/lexcalc.test | 33 ----- examples/c/reentrant-calc/local.mk | 37 ------ examples/c/reentrant-calc/parse.y | 160 ------------------------- examples/c/reentrant-calc/scan.l | 81 ------------- 7 files changed, 1 insertion(+), 375 deletions(-) delete mode 100644 examples/c/reentrant-calc/Makefile delete mode 100644 examples/c/reentrant-calc/README.md delete mode 100644 examples/c/reentrant-calc/lexcalc.test delete mode 100644 examples/c/reentrant-calc/local.mk delete mode 100644 examples/c/reentrant-calc/parse.y delete mode 100644 examples/c/reentrant-calc/scan.l diff --git a/examples/c/reccalc/reccalc.test b/examples/c/reccalc/reccalc.test index 280fb182..5d95b4e0 100644 --- a/examples/c/reccalc/reccalc.test +++ b/examples/c/reccalc/reccalc.test @@ -44,7 +44,7 @@ do done echo "$input" > input run 0 '0' - + cat >input <. ----> diff --git a/examples/c/reentrant-calc/lexcalc.test b/examples/c/reentrant-calc/lexcalc.test deleted file mode 100644 index bd9f3929..00000000 --- a/examples/c/reentrant-calc/lexcalc.test +++ /dev/null @@ -1,33 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2018-2019 Free Software Foundation, Inc. -# -# This program 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 . - -cat >input <input <input <. - -lexcalcdir = $(docdir)/%D% - -## ------ ## -## Calc. ## -## ------ ## - -check_PROGRAMS += %D%/lexcalc -TESTS += %D%/lexcalc.test -EXTRA_DIST += %D%/lexcalc.test %D%/scan.l -%C%_lexcalc_SOURCES = %D%/parse.y %D%/parse.h -nodist_%C%_lexcalc_SOURCES = %D%/scan.c %D%/scan.h -%D%/lexcalc.c: $(dependencies) - -%D%/scan.c: %D%/scan.l - $(AM_V_LEX) $(LEX) -o %D%/scan.c --header-file=%D%/scan.h $< - -# Don't use gnulib's system headers. -%C%_lexcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D% - -dist_lexcalc_DATA = %D%/parse.y %D%/scan.l %D%/Makefile %D%/README.md -CLEANFILES += %D%/lexcalc %D%/*.o %D%/parse.c %D%/scan.c -CLEANDIRS += %D%/*.dSYM diff --git a/examples/c/reentrant-calc/parse.y b/examples/c/reentrant-calc/parse.y deleted file mode 100644 index c04b9119..00000000 --- a/examples/c/reentrant-calc/parse.y +++ /dev/null @@ -1,160 +0,0 @@ -// Prologue (directives). -%expect 0 - -// Emitted in the header file, before the definition of YYSTYPE. -%code requires -{ - typedef void* yyscan_t; - typedef struct - { - // Whether to print the intermediate results. - int verbose; - // Value of the last computation. - int value; - // Number of errors. - int nerrs; - } result; -} - -// Emitted in the header file, after the definition of YYSTYPE. -%code provides -{ - // Tell Flex the expected prototype of yylex. - // The scanner argument must be named yyscanner. -#define YY_DECL \ - enum yytokentype yylex (YYSTYPE* yylval, yyscan_t yyscanner, result *res) - YY_DECL; - - void yyerror (yyscan_t scanner, result *res, const char *msg); -} - -// Emitted on top of the implementation file. -%code top -{ -#include /* printf. */ -#include /* getenv. */ -} - -%code -{ - result parse_string (const char* cp); - result parse (void); -} - -%define api.pure full -%define api.token.prefix {TOK_} -%define api.value.type union -%define parse.error verbose -%define parse.trace - // Scanner and error count are exchanged between main, yyparse and yylex. -%param {yyscan_t scanner}{result *res} - -%token - PLUS "+" - MINUS "-" - STAR "*" - SLASH "/" - EOL "end-of-line" - EOF 0 "end-of-file" -; - -%token NUM "number" -%type exp line -%printer { fprintf (yyo, "%d", $$); } - -%token STR "string" -%printer { fprintf (yyo, "\"%s\"", $$); } - -// Precedence (from lowest to highest) and associativity. -%left "+" "-" -%left "*" "/" - -%% -// Rules. -input: - %empty -| input line - { - res->value = $line; - if (res->verbose) - printf ("%d\n", $line); - } -; - -line: - exp EOL { $$ = $1; } -| exp { $$ = $1; } -| error EOL { $$ = 0; yyerrok; } -; - -exp: - exp "+" exp { $$ = $1 + $3; } -| exp "-" exp { $$ = $1 - $3; } -| exp "*" exp { $$ = $1 * $3; } -| exp "/" exp - { - if ($3 == 0) - { - yyerror (scanner, res, "invalid division by zero"); - YYERROR; - } - else - $$ = $1 / $3; - } -| STR - { - result r = parse_string ($1); - free ($1); - if (r.nerrs) - { - res->nerrs += r.nerrs; - YYERROR; - } - else - $$ = r.value; - } -| NUM { $$ = $1; } -; -%% -#include "scan.h" - -result -parse (void) -{ - result res = {1, 0, 0}; - yyscan_t scanner; - yylex_init (&scanner); - yyparse (scanner, &res); - yylex_destroy (scanner); - return res; -} - -result -parse_string (const char *str) -{ - result res = {0, 0, 0}; - yyscan_t scanner; - yylex_init (&scanner); - YY_BUFFER_STATE buf = yy_scan_string (str, scanner); - yyparse (scanner, &res); - yy_delete_buffer(buf, scanner); - yylex_destroy (scanner); - return res; -} - -// Epilogue (C code). -void yyerror (yyscan_t scanner, result *res, const char *msg) -{ - (void) scanner; - fprintf (stderr, "%s\n", msg); - res->nerrs += 1; -} - -int main (void) -{ - // Possibly enable parser runtime debugging. - yydebug = !!getenv ("YYDEBUG"); - result res = parse (); - // Exit on failure if there were errors. - return !!res.nerrs; -} diff --git a/examples/c/reentrant-calc/scan.l b/examples/c/reentrant-calc/scan.l deleted file mode 100644 index 62274733..00000000 --- a/examples/c/reentrant-calc/scan.l +++ /dev/null @@ -1,81 +0,0 @@ -/* Prologue (directives). -*- C++ -*- */ - -/* Disable Flex features we don't need, to avoid warnings. */ -%option nodefault noinput nounput noyywrap - -%option reentrant - -%{ -#include /* INT_MIN */ -#include /* strtol */ - -#include "parse.h" -%} - -%x SC_STRING - -%% -%{ - int nesting = 0; - char *str = NULL; - int size = 0; - int capacity = 0; -#define STR_APPEND() \ - do { \ - if (capacity < size + 1) \ - { \ - do \ - capacity = capacity ? 2 * capacity : 128; \ - while (capacity < size + 1); \ - str = realloc (str, capacity); \ - } \ - strncpy (str + size, yytext, yyleng); \ - size += yyleng; \ - } while (0) -%} - - // Rules. - -"+" return TOK_PLUS; -"-" return TOK_MINUS; -"*" return TOK_STAR; -"/" return TOK_SLASH; - -"(" nesting += 1; BEGIN SC_STRING; - - /* Scan an integer. */ -[0-9]+ { - errno = 0; - long n = strtol (yytext, NULL, 10); - if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE)) - yyerror (yyscanner, res, "integer is out of range"); - yylval->TOK_NUM = (int) n; - return TOK_NUM; -} - - /* Ignore white spaces. */ -[ \t]+ continue; - -"\n" return TOK_EOL; - -. yyerror (yyscanner, res, "syntax error, invalid character"); - - -{ - "("* nesting += yyleng; STR_APPEND (); - ")" { - if (!--nesting) - { - BEGIN INITIAL; - yylval->TOK_STR = str; - return TOK_STR; - } - else - STR_APPEND (); - } - [^()]+ STR_APPEND (); -} - -<> return TOK_EOF; -%% -/* Epilogue (C code). */