40#include <visp3/core/vpConfig.h>
41#include <visp3/core/vpException.h>
54#ifndef DOXYGEN_SHOULD_SKIP_THIS
57static void count(
void);
58static void next_source(
void);
60void lexerr(
const char *path, ...);
105#define isnult(c) (scantbl[c] == _NULT)
106#define iscmtt(c) (scantbl[c] & _CMTT)
107#define isfptt(c) (scantbl[c] & _FPTT)
108#define isidnt(c) (scantbl[c] & _IDNT)
109#define isintt(c) (scantbl[c] & _INTT)
110#define issgnt(c) (scantbl[c] & _SGNT)
111#define isstgt(c) (scantbl[c] & _STGT)
127const char *lex_errtbl[] = {
130 "unexpected EOF in comment",
134 "unexpected EOF in string or char constant",
135 "newline in string or char constant",
142unsigned int mycolumno = 0;
148static char *lastline;
159 if ((chtbl = (Byte *)malloc(CHAR_NBR *
sizeof(Byte))) == NULL ||
160 (scantbl = (Byte *)malloc(CHAR_NBR *
sizeof(Byte))) == NULL) {
161 static char proc_name[] =
"open_lex";
170 for (
int i = 0;
i < ASCII_NBR;
i++) {
209 for (
int i = 0;
i < ASCII_NBR;
i++) {
211 scantbl[
i] = _CMTT | _IDNT | _STGT;
213 scantbl[
i] = _CMTT | _IDNT | _INTT | _STGT;
221 scantbl[
i] = _CMTT | _SGNT | _STGT;
224 scantbl[
i] = _CMTT | _FPTT | _STGT;
230 scantbl[
i] = _CMTT | _IDNT | _STGT;
233 scantbl[
i] = _CMTT | _STGT;
240 scantbl[EOB] = _NULT;
241 scantbl[EOF] = _NULT;
242 scantbl[EOL] = _NULT;
251 free((
char *)(chtbl - 2));
252 free((
char *)(scantbl - 2));
255#define ECHO printf("%c", *(mysptr))
256#define CURC (*((signed char *)mysptr))
257#define NEXTC (*((signed char *)mysptr + 1))
258#define PREVC (*((signed char *)mysptr - 1))
272 for (; chtbl[
static_cast<int>(CURC)] == SPCT; mysptr++) {
275 switch (chtbl[
static_cast<int>(CURC)]) {
288 if (mysptr == lastline)
302 for (; iscmtt(
static_cast<int>(CURC)); mysptr++) {
304 switch (chtbl[
static_cast<int>(CURC)]) {
309 lexerr(
"start", lex_errtbl[E_CMT_EOF], NULL);
312 if (mysptr == lastline)
331 for (; isidnt(
static_cast<int>(CURC)); mysptr++) {
333 mylength =
static_cast<int>(mysptr - mytext);
334 return (get_symbol(mytext, mylength));
338 myint =
static_cast<int>(CURC -
'0');
340 for (; isintt(
static_cast<int>(CURC)); mysptr++)
341 myint = myint * 10 +
static_cast<int>(CURC -
'0');
346 for (; isintt(
static_cast<int>(CURC)); mysptr++) {
348 if (CURC !=
'E' && CURC !=
'e') {
349 myfloat =
static_cast<float>(atof(mytext));
359 if (isintt(
static_cast<int>(CURC)))
361 else if (issgnt(
static_cast<int>(CURC)) && isintt(
static_cast<int>(NEXTC)))
365 myfloat =
static_cast<float>(atof(mytext));
368 for (; isintt(
static_cast<int>(CURC)); mysptr++) {
370 myfloat =
static_cast<float>(atof(mytext));
383 if (!isintt(
static_cast<int>(CURC)))
389 if (isintt(
static_cast<int>(CURC)))
391 if (isfptt(
static_cast<int>(CURC)) && isintt(
static_cast<int>(NEXTC)))
398 for (; isstgt(
static_cast<int>(CURC)); mysptr++) {
400 switch (chtbl[
static_cast<int>(CURC)]) {
405 lexerr(
"start", lex_errtbl[E_STG_EOF], NULL);
408 lexerr(
"start", lex_errtbl[E_STG_EOL], NULL);
413 mylength =
static_cast<int>(mysptr - mytext);
443int lexecho(FILE *f,
int token)
446 for (; chtbl[
static_cast<int>(CURC)] == SPCT; mysptr++)
447 fwrite(mysptr, 1, 1, f);
449 switch (chtbl[
static_cast<int>(CURC)]) {
454 if (token != *mytext)
455 fwrite(mytext, 1, 1, f);
467 fwrite(mysptr, 1, 1, f);
468 if (mysptr == lastline)
477 fwrite(mysptr, 1, 1, f);
482 fwrite(mysptr, 1, 1, f);
485 for (; iscmtt(
static_cast<int>(CURC)); mysptr++)
486 fwrite(mysptr, 1, 1, f);
487 switch (chtbl[
static_cast<int>(CURC)]) {
493 lexerr(
"start", lex_errtbl[E_CMT_EOF], NULL);
497 fwrite(mysptr, 1, 1, f);
498 if (mysptr == lastline)
507 fwrite(mysptr, 1, 1, f);
520 for (; isidnt(
static_cast<int>(CURC)); mysptr++) {
522 mylength =
static_cast<int>(mysptr - mytext);
523 if (token != get_symbol(mytext, mylength))
524 fwrite(mytext,
static_cast<size_t>(mylength), 1, f);
525 return (get_symbol(mytext, mylength));
531 for (; isintt(
static_cast<int>(CURC)); mysptr++) {
537 for (; isintt(
static_cast<int>(CURC)); mysptr++) {
539 if (CURC !=
'E' && CURC !=
'e') {
540 if (token != T_FLOAT)
541 fwrite(mytext,
static_cast<size_t>(mysptr - mytext), 1, f);
548 if (isintt(
static_cast<int>(CURC)))
550 else if (issgnt(
static_cast<int>(CURC)) && isintt(
static_cast<int>(NEXTC)))
554 if (token != T_FLOAT)
555 fwrite(mytext,
static_cast<size_t>(mysptr - mytext), 1, f);
558 for (; isintt(
static_cast<int>(CURC)); mysptr++) {
560 if (token != T_FLOAT)
561 fwrite(mytext,
static_cast<size_t>(mysptr - mytext), 1, f);
566 fwrite(mytext,
static_cast<size_t>(mysptr - mytext), 1, f);
574 if (!isintt(
static_cast<int>(CURC))) {
575 if (token != *mytext)
576 fwrite(mytext, 1, 1, f);
584 if (isintt(
static_cast<int>(CURC)))
586 if (isfptt(
static_cast<int>(CURC)) && isintt(
static_cast<int>(NEXTC)))
588 if (token != *mytext)
589 fwrite(mytext, 1, 1, f);
593 fwrite(mysptr, 1, 1, f);
597 for (; isstgt(
static_cast<int>(CURC)); mysptr++)
598 fwrite(mysptr, 1, 1, f);
599 switch (chtbl[
static_cast<int>(CURC)]) {
605 lexerr(
"start", lex_errtbl[E_STG_EOF], NULL);
609 lexerr(
"start", lex_errtbl[E_STG_EOL], NULL);
613 fwrite(mysptr, 1, 1, f);
616 mylength =
static_cast<int>(mysptr - mytext);
626 fwrite(mysptr, 1, 1, f);
638#define BUFSIZE (BUFSIZ << 5)
639#define LINESIZE (BUFSIZ - 1)
640#define TEXTSIZE (1 + LINESIZE + BUFSIZE + 1)
651void unlex(
void) { mysptr = mytext; }
660void open_source(FILE *fd,
const char *str)
662 if ((source = (
char *)malloc((strlen(str) + 1) *
sizeof(
char))) == NULL) {
663 static char proc_name[] =
"open_source";
668 if ((botbuf = (
char *)malloc(TEXTSIZE *
sizeof(
char))) == NULL) {
669 static char proc_name[] =
"open_source";
674 buf = botbuf + 1 + LINESIZE;
684void close_source(
void)
686 free((
char *)source);
687 free((
char *)botbuf);
693static void next_source(
void)
702 while ((*--bot = *--top) != EOL) {
704 myline = mysptr = bot + 1;
706 size = fread(buf,
sizeof(
char), BUFSIZE, fds);
719 while (*--top != EOL) {
730#define ERR_STACK_MAX 32
732static const char *err_stack[ERR_STACK_MAX];
733static int size_stack = 0;
739static void count(
void)
744 for (str = myline;
str <= mytext;
str++) {
745 (*
str ==
'\t') ? mycolumno += 8 - (mycolumno % 8) : mycolumno++;
762void lexerr(
const char *path, ...)
772 fprintf(stderr,
"\n%*c\n\"%s\", line %d:\n", mycolumno,
'^', source, mylineno);
776 for (i = 0;
i < size_stack;
i++)
777 fprintf(stderr,
"%s", err_stack[i]);
782 while ((cp = (
char *)va_arg(ap,
char *)) != NULL)
783 fprintf(stderr,
"%s", cp);
784 fprintf(stderr,
"\n");
795 if (--size_stack < 0) {
796 static char proc_name[] =
"poperr";
797 fprintf(stderr,
"%s: error stack underflow\n", proc_name);
805void popuperr(
const char *str)
807 if (size_stack <= 0) {
808 static const char proc_name[] =
"popuerr";
809 fprintf(stderr,
"%s: error stack underflow\n", proc_name);
812 err_stack[size_stack - 1] =
str;
818void pusherr(
const char *str)
820 if (size_stack >= ERR_STACK_MAX) {
821 static const char proc_name[] =
"pusherr";
822 fprintf(stderr,
"%s: error stack overflow\n", proc_name);
825 err_stack[size_stack++] =
str;
error that can be emitted by ViSP classes.