mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
* cfg.mk: Disable checks where needed (e.g., we do want to check the behavior with tabs). (sc_at_parser_check): Remove. Unfortunately sincea11c144609we no longer use the './' prefix to run programs in the current directory. That was so that we could run Java programs like the other, although they are no run with the `./` prefix (see967a59d2c0). As a consequence this sc check no longer makes sense. However, since now AT_PARSER_CHECK passes the `./` prefix itself, this sc-check was superfluous. * examples/c/reccalc/scan.l: Use memcpy, not strncpy. * src/ielr.c, src/reader.c: Obfuscate "lr(0)" so that the sc-check for "space before paren" does not fire. * tests/diagnostics.at: Avoid space-tab, use tab-tab.
86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
/* Prologue (directives). -*- C++ -*- */
|
|
|
|
/* Disable Flex features we don't need, to avoid warnings. */
|
|
%option nodefault noinput nounput noyywrap
|
|
|
|
%option reentrant
|
|
|
|
%{
|
|
#include <assert.h>
|
|
#include <limits.h> /* INT_MIN */
|
|
#include <stdlib.h> /* 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 + yyleng + 1) \
|
|
{ \
|
|
do \
|
|
capacity = capacity ? 2 * capacity : 128; \
|
|
while (capacity < size + yyleng + 1); \
|
|
str = realloc (str, capacity); \
|
|
} \
|
|
memcpy (str + size, yytext, yyleng); \
|
|
size += yyleng; \
|
|
assert (size < capacity); \
|
|
} 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: %c", yytext[0]);
|
|
|
|
<SC_STRING>
|
|
{
|
|
"("+ nesting += yyleng; STR_APPEND ();
|
|
")" {
|
|
if (!--nesting)
|
|
{
|
|
BEGIN INITIAL;
|
|
if (str)
|
|
str[size] = 0;
|
|
yylval->TOK_STR = str;
|
|
return TOK_STR;
|
|
}
|
|
else
|
|
STR_APPEND ();
|
|
}
|
|
[^()]+ STR_APPEND ();
|
|
}
|
|
|
|
<<EOF>> return TOK_EOF;
|
|
%%
|
|
/* Epilogue (C code). */
|