SQLite

Check-in [b43ac3309e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Removed %expect directive, on drh's advice.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | lemon-update-2010
Files: files | file ages | folders
SHA1: b43ac3309e77dc8ea2952bf62da6eaad5aef6653
User & Date: icculus 2010-02-16 16:09:03.000
Context
2010-02-17
05:40
Removed unused variables. (check-in: ca570a02f5 user: icculus tags: lemon-update-2010)
2010-02-16
16:09
Removed %expect directive, on drh's advice. (check-in: b43ac3309e user: icculus tags: lemon-update-2010)
16:07
Patched to compile. Accidentally removed va_list declaration. (check-in: 673d470c0c user: icculus tags: lemon-update-2010)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to tool/lemon.c.
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
293
294
295
296
297
298
299

300
301
302
303
304
305
306







-







  char *extracode;         /* Code appended to the generated file */
  char *tokendest;         /* Code to execute to destroy token data */
  char *vardest;           /* Code for the default non-terminal destructor */
  char *filename;          /* Name of the input file */
  char *outname;           /* Name of the current output file */
  char *tokenprefix;       /* A prefix added to token names in the .h file */
  int nconflict;           /* Number of parsing conflicts */
  int nexpected;           /* Number of expected parsing conflicts */
  int tablesize;           /* Size of the parse tables */
  int basisflag;           /* Print only basis configurations */
  int has_fallback;        /* True if any %fallback is seen in the grammar */
  int nolinenosflag;       /* True if #line statements should not be printed */
  char *argv0;             /* Name of the program */
};

1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445







-







  }
  if( OptNArgs()!=1 ){
    fprintf(stderr,"Exactly one filename argument is required.\n");
    exit(1);
  }
  memset(&lem, 0, sizeof(lem));
  lem.errorcnt = 0;
  lem.nexpected = -1;

  /* Initialize the machine */
  Strsafe_init();
  Symbol_init();
  State_init();
  lem.argv0 = argv[0];
  lem.filename = OptArg(0);
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529


1530
1531
1532
1533

1534
1535
1536
1537
1538
1539
1540
1516
1517
1518
1519
1520
1521
1522





1523
1524
1525
1526
1527

1528
1529
1530
1531
1532
1533
1534
1535







-
-
-
-
-
+
+



-
+







  }
  if( statistics ){
    printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n",
      lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
    printf("                   %d states, %d parser table entries, %d conflicts\n",
      lem.nstate, lem.tablesize, lem.nconflict);
  }
  if( lem.nexpected < 0 ) {
    lem.nexpected = 0;  /* grammar didn't have an %expect declaration. */
  }
  if( lem.nconflict != lem.nexpected ){
    fprintf(stderr,"%d parsing conflicts (%d expected).\n",lem.nconflict,lem.nexpected);
  if( lem.nconflict > 0 ){
    fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict);
  }

  /* return 0 on success, 1 on failure. */
  exitcode = ((lem.errorcnt > 0) || (lem.nconflict != lem.nexpected)) ? 1 : 0;
  exitcode = ((lem.errorcnt > 0) || (lem.nconflict > 0)) ? 1 : 0;
  successful_exit = (exitcode == 0);
  exit(exitcode);
  return (exitcode);
}
/******************** From the file "msort.c" *******************************/
/*
** A generic merge-sort program.
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1947
1948
1949
1950
1951
1952
1953

1954
1955
1956
1957
1958
1959
1960







-







  PRECEDENCE_MARK_1,
  PRECEDENCE_MARK_2,
  RESYNC_AFTER_RULE_ERROR,
  RESYNC_AFTER_DECL_ERROR,
  WAITING_FOR_DESTRUCTOR_SYMBOL,
  WAITING_FOR_DATATYPE_SYMBOL,
  WAITING_FOR_FALLBACK_ID,
  WAITING_FOR_EXPECT_VALUE,
  WAITING_FOR_WILDCARD_ID
};
struct pstate {
  char *filename;       /* Name of the input file */
  int tokenlineno;      /* Linenumber at which current token starts */
  int errorcnt;         /* Number of errors so far */
  char *tokenstart;     /* Text of current token */
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2262
2263
2264
2265
2266
2267
2268








2269
2270
2271
2272
2273
2274
2275







-
-
-
-
-
-
-
-







	}else if( strcmp(x,"type")==0 ){
          psp->state = WAITING_FOR_DATATYPE_SYMBOL;
        }else if( strcmp(x,"fallback")==0 ){
          psp->fallback = 0;
          psp->state = WAITING_FOR_FALLBACK_ID;
        }else if( strcmp(x,"wildcard")==0 ){
          psp->state = WAITING_FOR_WILDCARD_ID;
        }else if( strcmp(x,"expect")==0 ){
          if (psp->gp->nexpected >= 0) {
            ErrorMsg(psp->filename,psp->tokenlineno, "Multiple %expect declarations.");
            psp->errorcnt++;
            psp->state = RESYNC_AFTER_DECL_ERROR;
          } else {
            psp->state = WAITING_FOR_EXPECT_VALUE;
          }
        }else{
          ErrorMsg(psp->filename,psp->tokenlineno,
            "Unknown declaration keyword: \"%%%s\".",x);
          psp->errorcnt++;
          psp->state = RESYNC_AFTER_DECL_ERROR;
	}
      }else{
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2289
2290
2291
2292
2293
2294
2295













2296
2297
2298
2299
2300
2301
2302







-
-
-
-
-
-
-
-
-
-
-
-
-







        struct symbol *sp = Symbol_new(x);
        psp->declargslot = &sp->destructor;
        psp->decllinenoslot = &sp->destLineno;
        psp->insertLineMacro = 1;
        psp->state = WAITING_FOR_DECL_ARG;
      }
      break;
    case WAITING_FOR_EXPECT_VALUE:
        psp->gp->nexpected = (int) strtol(x, &endptr, 10);
        if( (*endptr != '\0') || (endptr == x) ) {
          ErrorMsg(psp->filename,psp->tokenlineno,
            "Integer expected after %%expect keyword");
          psp->errorcnt++;
        } else if (psp->gp->nexpected < 0) {
          ErrorMsg(psp->filename,psp->tokenlineno,
            "Integer can't be negative after %%expect keyword");
          psp->errorcnt++;
        }
        psp->state = WAITING_FOR_DECL_OR_RULE;
        break;
    case WAITING_FOR_DATATYPE_SYMBOL:
      if( !isalpha(x[0]) ){
        ErrorMsg(psp->filename,psp->tokenlineno,
          "Symbol name missing after %destructor keyword");
        psp->errorcnt++;
        psp->state = RESYNC_AFTER_DECL_ERROR;
      }else{