You should have received a copy of the GNU General Public License
along with Bison; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
-/*
+/*
lex is the entry point. It is called from reader.c.
It returns one of the token-type codes defined in lex.h.
When an identifier is seen, the code IDENTIFIER is returned
symval is set to a pointer to the entry found. */
#include <stdio.h>
-#include <ctype.h>
#include "system.h"
#include "files.h"
#include "getopt.h" /* for optarg */
#include "symtab.h"
#include "lex.h"
-#include "new.h"
+#include "alloc.h"
/* flags set by % directives */
extern int definesflag; /* for -d */
extern int lineno;
extern int translations;
-int parse_percent_token();
+void init_lex PARAMS((void));
+char *grow_token_buffer PARAMS((char *));
+int skip_white_space PARAMS((void));
+int safegetc PARAMS((FILE *));
+int literalchar PARAMS((char **, int *, char));
+void unlex PARAMS((int));
+int lex PARAMS((void));
+int parse_percent_token PARAMS((void));
/* functions from main.c */
-extern char *printable_version();
-extern void fatal();
-extern void warni();
-extern void warn();
+extern char *printable_version PARAMS((int));
+extern void fatal PARAMS((char *));
+extern void warn PARAMS((char *));
+extern void warni PARAMS((char *, int));
+extern void warns PARAMS((char *, char *));
/* Buffer for storing the current token. */
char *token_buffer;
/* Allocated size of token_buffer, not including space for terminator. */
-static int maxtoken;
+int maxtoken;
bucket *symval;
int numval;
void
-init_lex()
+init_lex (void)
{
maxtoken = 100;
token_buffer = NEW2 (maxtoken + 1, char);
}
-static char *
-grow_token_buffer (p)
- char *p;
+char *
+grow_token_buffer (char *p)
{
int offset = p - token_buffer;
maxtoken *= 2;
int
-skip_white_space()
+skip_white_space (void)
{
register int c;
register int inside;
{
case '/':
c = getc(finput);
- if (c != '*' && c != '/')
+ if (c != '*' && c != '/')
{
- warn("unexpected `/' found and ignored");
+ warn(_("unexpected `/' found and ignored"));
break;
}
cplus_comment = (c == '/');
c = getc(finput);
}
else if (c == EOF)
- fatal("unterminated comment");
+ fatal(_("unterminated comment"));
else
c = getc(finput);
}
/* do a getc, but give error message if EOF encountered */
int
-safegetc(f)
- FILE *f;
+safegetc (FILE *f)
{
register int c = getc(f);
if (c == EOF)
- fatal("Unexpected end of file");
+ fatal(_("Unexpected end of file"));
return c;
}
report error for \n
*/
int
-literalchar(pp, pcode, term)
- char **pp;
- int *pcode;
- char term;
+literalchar (char **pp, int *pcode, char term)
{
register int c;
register char *p;
int wasquote = 0;
c = safegetc(finput);
- if (c == '\n')
+ if (c == '\n')
{
- warn("unescaped newline in constant");
+ warn(_("unescaped newline in constant"));
ungetc(c, finput);
code = '?';
wasquote = 1;
else if (c != '\\')
{
code = c;
- if (c == term)
+ if (c == term)
wasquote = 1;
}
else
else if (c == 'r') code = '\r';
else if (c == 'f') code = '\f';
else if (c == 'b') code = '\b';
- else if (c == 'v') code = 013;
+ else if (c == 'v') code = '\013';
else if (c == '\\') code = '\\';
else if (c == '\'') code = '\'';
else if (c == '\"') code = '\"';
code = (code * 8) + (c - '0');
if (code >= 256 || code < 0)
{
- warni("octal value outside range 0...255: `\\%o'", code);
+ warni(_("octal value outside range 0...255: `\\%o'"), code);
code &= 0xFF;
break;
}
code *= 16, code += c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
code *= 16, code += c - 'A' + 10;
- else
+ else
break;
if (code >= 256 || code<0)
{
- warni("hexadecimal value above 255: `\\x%x'", code);
+ warni(_("hexadecimal value above 255: `\\x%x'"), code);
code &= 0xFF;
break;
}
}
else
{
- warni ("unknown escape sequence: `\\' followed by `%s'",
+ warns (_("unknown escape sequence: `\\' followed by `%s'"),
printable_version(c));
code = '?';
}
so that `\012' and `\n' can be interchangeable. */
p = *pp;
- if (code >= 040 && code < 0177)
+ if (code == term && wasquote)
*p++ = code;
else if (code == '\\') {*p++ = '\\'; *p++ = '\\';}
else if (code == '\'') {*p++ = '\\'; *p++ = '\'';}
else if (code == '\"') {*p++ = '\\'; *p++ = '\"';}
+ else if (code >= 040 && code < 0177)
+ *p++ = code;
else if (code == '\t') {*p++ = '\\'; *p++ = 't';}
else if (code == '\n') {*p++ = '\\'; *p++ = 'n';}
else if (code == '\r') {*p++ = '\\'; *p++ = 'r';}
void
-unlex(token)
- int token;
+unlex (int token)
{
unlexed = token;
unlexed_symval = symval;
int
-lex()
+lex (void)
{
register int c;
char *p;
{
int code, discode;
char discard[10], *dp;
+
p = token_buffer;
*p++ = '\'';
literalchar(&p, &code, '\'');
c = getc(finput);
if (c != '\'')
{
- warn("use \"...\" for multi-character literal tokens");
- dp = discard;
- while (literalchar(&dp, &discode, '\'')) {}
+ warn(_("use \"...\" for multi-character literal tokens"));
+ while (1)
+ {
+ dp = discard;
+ if (! literalchar(&dp, &discode, '\''))
+ break;
+ }
}
*p++ = '\'';
*p = 0;
while (c != '>')
{
if (c == EOF)
- fatal("unterminated type name at end of file");
- if (c == '\n')
+ fatal(_("unterminated type name at end of file"));
+ if (c == '\n')
{
- warn("unterminated type name");
+ warn(_("unterminated type name"));
ungetc(c, finput);
break;
}
}
*p = 0;
return (TYPENAME);
-
+
case '%':
return (parse_percent_token());
}
}
-/* the following table dictates the action taken for the various
+/* the following table dictates the action taken for the various
% directives. A setflag value causes the named flag to be
set. A retval action returns the code.
*/
struct percent_table_struct {
char *name;
- void *setflag;
+ void *setflag;
int retval;
} percent_table[] =
{
/* These would be acceptable, but they do not affect processing */
{"verbose", &verboseflag, NOOP}, /* -v */
{"debug", &debugflag, NOOP}, /* -t */
- /* {"help", <print usage stmt>, NOOP}, /* -h */
- /* {"version", <print version number> , NOOP}, /* -V */
+ /* {"help", <print usage stmt>, NOOP},*/ /* -h */
+ /* {"version", <print version number> , NOOP},*/ /* -V */
#endif
{NULL, NULL, ILLEGAL}
Assumes the % has already been read and discarded. */
int
-parse_percent_token ()
+parse_percent_token (void)
{
register int c;
register char *p;
case '=':
return (PREC);
}
- if (!isalpha(c))
+ if (!isalpha(c))
return (ILLEGAL);
p = token_buffer;