testparse.c 534 B

12345678910111213141516171819202122232425262728
  1. /* testparse.c - test the parse object */
  2. #include <foo.h>
  3. int
  4. lex() {
  5. /* tokens are: "$","error","$illegal.", /* 0-2 */
  6. /* "'?'","'a'", "'b'","'/'", /* 3-6 */
  7. /* "script","slash", NULL /* 7-8 (non-terminals) */
  8. /* a b a b ? / */
  9. static int toks[] = {4, 5, 4, 5, 3, 6};
  10. static int inx = 0;
  11. if (inx >= sizeof(toks)/sizeof(toks[0])) return 0; /* eof */
  12. return toks[inx++];
  13. }
  14. main()
  15. {
  16. struct parser *p = foo_New();
  17. parser_SetDebug(1);
  18. printf("parser_Parse returns %d\n", parser_Parse(p, lex, NULL));
  19. }