home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / FTREE0.3.LHA / ftree / src / RCS / lex.l,v < prev    next >
Encoding:
Text File  |  1994-04-27  |  9.2 KB  |  541 lines

  1. head    1.6;
  2. access;
  3. symbols
  4.     stage1:1.6;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.6
  10. date    94.03.10.21.28.26;    author peteric;    state Exp;
  11. branches;
  12. next    1.5;
  13.  
  14. 1.5
  15. date    94.03.01.23.25.36;    author peteric;    state Exp;
  16. branches;
  17. next    1.4;
  18.  
  19. 1.4
  20. date    94.02.27.19.33.34;    author peteric;    state Exp;
  21. branches;
  22. next    1.3;
  23.  
  24. 1.3
  25. date    94.02.13.16.41.58;    author peteric;    state Exp;
  26. branches;
  27. next    1.2;
  28.  
  29. 1.2
  30. date    94.02.12.20.00.19;    author peteric;    state Exp;
  31. branches;
  32. next    1.1;
  33.  
  34. 1.1
  35. date    94.02.12.19.52.11;    author peteric;    state Exp;
  36. branches;
  37. next    ;
  38.  
  39.  
  40. desc
  41. @flex parser for ftree database files.
  42. @
  43.  
  44.  
  45. 1.6
  46. log
  47. @Multiple pages working!
  48. @
  49. text
  50. @/*************************************************************************
  51.  *
  52.  *     $Name$
  53.  *
  54.  *    $Author: peteric $
  55.  *
  56.  *    $Date: 1994/03/01 23:25:36 $
  57.  *
  58.  *    $Revision: 1.5 $
  59.  *
  60.  *    Purpose:    Flex prser defintion for ftree family tree formatter.
  61.  *            
  62.  *    $Log: lex.l,v $
  63.  * Revision 1.5  1994/03/01  23:25:36  peteric
  64.  * added missing token ticklen.
  65.  *
  66.  * Revision 1.4  1994/02/27  19:33:34  peteric
  67.  * improved string handling, added new tokens, improved include file debug.
  68.  *
  69.  * Revision 1.3  1994/02/13  16:41:58  peteric
  70.  * added new include file processing, various extra tokens
  71.  * and corrected string rule to stop at newlines.
  72.  *
  73.  * Revision 1.2  1994/02/12  20:00:19  peteric
  74.  * added in comments etc.
  75.  *
  76.  *    
  77.  *
  78.  *************************************************************************/
  79.  
  80. %{
  81. #include <stdio.h>
  82. #include <stdlib.h>
  83. #include <string.h>
  84.  
  85. #include "parse.h"
  86. #include "ftree.h"
  87.  
  88. #define MAX_INCLUDE_DEPTH 10
  89.  
  90. struct include_frame
  91. {
  92.     YY_BUFFER_STATE buf;
  93.     char *filename;
  94.     int line;
  95. };
  96.  
  97. struct include_frame include_stack[MAX_INCLUDE_DEPTH];
  98. int include_sp = 0;
  99. %}
  100.  
  101. %x INCLUDE QUOTE
  102.  
  103. DIGIT    [0-9]
  104. SIGN    [-+]{0,1}
  105.  
  106. %%
  107.  
  108. <INITIAL>include    { BEGIN INCLUDE; }
  109.  
  110. <INCLUDE>[ \t]+
  111.  
  112. <INCLUDE>\"[^\"\n]+\"        {
  113.                 static char fbuf[512];
  114.                 char *p;
  115.                 
  116.                 /*
  117.                  * extract the filename from the string
  118.                  */
  119.                 strcpy(fbuf, (char*)yytext+1); 
  120.                 p = strrchr(fbuf, '\"');
  121.                 *p = '\0';
  122.                 dbprintf(("include: from line %d of \"%s\" file \"%s\"\n",
  123.                                 lineno, current_filename, fbuf));
  124.                 
  125.                 /*
  126.                  * check that we can do it!
  127.                  */
  128.                 if (include_sp >= MAX_INCLUDE_DEPTH)
  129.                 {
  130.                     errmsg("include statement nested too deeply (>%d)\n", MAX_INCLUDE_DEPTH);
  131.                 }
  132.                 /*
  133.                  * push the current filename/line on the stack & install the
  134.                  * new file & up the stack pointer.
  135.                  */
  136.                 include_stack[include_sp].line = lineno;
  137.                 include_stack[include_sp].filename = malloc(strlen(current_filename)+1);
  138.                 if (include_stack[include_sp].filename)
  139.                     strcpy(include_stack[include_sp].filename, current_filename);
  140.                 include_stack[include_sp].buf = YY_CURRENT_BUFFER;
  141.                 include_sp++;
  142.                 
  143.                 /*
  144.                  * set up the current details.
  145.                  */
  146.                 lineno = 1;
  147.                 current_filename = fbuf;
  148.                 yyin = fopen(fbuf, "r");
  149.                 if (!yyin)
  150.                     errmsg("cannot open include file \"%s\"\n", fbuf);
  151.                 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
  152.                 BEGIN INITIAL;
  153.             }
  154.  
  155. [Jj]an            { yylval.inum = 1; return MONTH; }
  156.  
  157. [Ff]eb            { yylval.inum = 2; return MONTH; }
  158.  
  159. [Mm]ar            { yylval.inum = 3; return MONTH; }
  160.  
  161. [Aa]pr            { yylval.inum = 4; return MONTH; }
  162.  
  163. [Mm]ay            { yylval.inum = 5; return MONTH; }
  164.  
  165. [Jj]un            { yylval.inum = 6; return MONTH; }
  166.  
  167. [Jj]ul            { yylval.inum = 7; return MONTH; }
  168.  
  169. [Aa]ug            { yylval.inum = 8; return MONTH; }
  170.  
  171. [Ss]ep            { yylval.inum = 9; return MONTH; }
  172.  
  173. [Oo]ct            { yylval.inum = 10; return MONTH; }
  174.  
  175. [Nn]ov            { yylval.inum = 11; return MONTH; }
  176.  
  177. [Dd]ec            { yylval.inum = 12; return MONTH; }
  178.  
  179. [A-Z][0-9]{1,4}        { 
  180.             yylval.inum = cvid(yytext);
  181.             return ID;
  182.             }
  183.  
  184. {SIGN}{DIGIT}+        {
  185.             yylval.inum = atoi(yytext);
  186.             return INT;
  187.             }
  188.  
  189. {SIGN}{DIGIT}+"."{DIGIT}*    {
  190.             float f;
  191.             sscanf(yytext, "%f", &f);
  192.             yylval.fnum = f;
  193.             return NUM;
  194.             }
  195.  
  196. "option"            return OPTION;
  197.  
  198. "{"            return OPENBRA;
  199.  
  200. "}"            return CLOSEBRA;
  201.  
  202. "person"        return PERSON;
  203. "children"        return CHILDREN;
  204. "sex"            return SEX;
  205. "male"            return MALE;
  206. "female"        return FEMALE;
  207. "family"|"lastname"|"surname"    return FAMILY;
  208. "christianname"|"firstname"    return FIRSTNAME;
  209. "living"        return LIVING;
  210. "dead"            return DEAD;
  211. "born"            return BORNON;
  212. "died"            return DIEDON;
  213. "bapt"|"baptised"    return BAPTISED;
  214. "wife"            return WIFE;
  215. "left"            return LEFT;
  216. "right"            return RIGHT;
  217. "husband"        return HUSBAND;
  218. "then"            return THEN;
  219. "marriage"        return MARRIAGE;
  220. "married"        return MARRIED;
  221. "divorced"        return DIVORCED;
  222. "separated"        return SEPARATED;
  223. "widowed"        return WIDOWED;
  224. "occupation"        return OCCUPATION;
  225. "font"            return FONT;
  226. "title"            return TITLE;
  227. "multipage"        return MULTIPAGE;
  228. "vspace"        return VSPACE;
  229. "hspace"        return HSPACE;
  230. "ticklen"        return TICKLEN;
  231. "chartref"        return CHARTREF;
  232. "ident"            return IDENT;
  233. "date"            return DATE;
  234. "symbol"        return SYMBOL;
  235. "pointsize"        return POINTSIZE;
  236. "outputfile"        return OUTPUTFILE;
  237. "pagesize"        return PAGESIZE;
  238. "portrait"        return PORTRAIT;
  239. "landscape"        return LANDSCAPE;
  240. "root"            return ROOT;
  241. "titlebox"        return TITLEBOX;
  242. "notitlebox"        return NOTITLEBOX;
  243. "orientation"        return ORIENTATION;
  244. ","            return COMMA;
  245. "-"            return DASH;
  246. "/"            return SLASH;
  247. "?"            return QMARK;
  248.  
  249. \"            {
  250.                 BEGIN QUOTE;
  251.                 yymore();
  252.             }
  253.  
  254. <QUOTE>[\"\n]        {
  255.                 if (yytext[yyleng - 1] == '\n')
  256.                 {
  257.                     errmsg("unterminated string");
  258.                     BEGIN INITIAL;
  259.                     return BAD;
  260.                 }
  261.                 /* dbprintf(("string? = yytext = '%s' ... ", yytext)); */
  262.                 fflush(stdout);
  263.                 if (yytext[yyleng - 2] == '\\')
  264.                 {
  265.                     /* dbprintf((" no\n")); */
  266.                     yymore();
  267.                 }
  268.                 else
  269.                 {
  270.                     static char b[256];
  271.                     char *p, *s;
  272.                     
  273.                     s = yytext+1;
  274.                     p = b;
  275.                     while(*s)
  276.                     {
  277.                         if (*s == '\\' && *(s+1) == '"')
  278.                         {
  279.                             *p++ = '"';
  280.                             s+=2;
  281.                         }
  282.                         else if (*s == '"' && *(s+1) == '\0')
  283.                             break;
  284.                         else
  285.                             *p++ = *s++;
  286.                     }
  287.                     *p = '\0';
  288.                     
  289.                     /* dbprintf((" yes: >%s<\n", b)); */
  290.                     
  291.                     yylval.txt = b;
  292.                     BEGIN INITIAL;
  293.                     return STRING;
  294.                 }
  295.             }
  296.  
  297. <QUOTE>[^\"\n]*        {
  298.                 yymore();
  299.             }
  300.  
  301. ";".*\n            { /* comment lines are ignored */ lineno++; }
  302.  
  303. "\n"            { /* increment line count */ lineno++; }
  304.  
  305. " "            { }
  306.  
  307. "    "        { }
  308.  
  309. <INITIAL,INCLUDE>.    {
  310.                 errmsg("syntax error; character - %c (%d) unexpected.\n", yytext[0], (int)yytext[0]);
  311.                 return (BAD);
  312.             }
  313.  
  314. <<EOF>>            {
  315.                 if (include_sp == 0)
  316.                 {
  317.                     yyterminate();
  318.                 }
  319.                 else
  320.                 {
  321.                     if (include_stack[include_sp].filename)
  322.                         free(include_stack[include_sp].filename);
  323.                     include_sp --;
  324.                     yy_switch_to_buffer(include_stack[include_sp].buf);
  325.                     current_filename = include_stack[include_sp].filename;
  326.                     lineno = include_stack[include_sp].line;
  327.                     dbprintf(("include: return to line %d of file \"%s\"\n",
  328.                             lineno, current_filename));
  329.                 }
  330.             }
  331.  
  332. %%
  333.  
  334. #ifndef yywrap
  335. int yywrap()
  336. {
  337.     return 1;
  338. }
  339. #endif
  340.  
  341. @
  342.  
  343.  
  344. 1.5
  345. log
  346. @added missing token ticklen.
  347. @
  348. text
  349. @d7 1
  350. a7 1
  351.  *    $Date: 1994/02/27 19:33:34 $
  352. d9 1
  353. a9 1
  354.  *    $Revision: 1.4 $
  355. d14 3
  356. a157 1
  357.  
  358. a159 1
  359.  
  360. d173 2
  361. a174 1
  362. "seperated"        return SEPERATED;
  363. d178 1
  364. d180 1
  365. d182 1
  366. @
  367.  
  368.  
  369. 1.4
  370. log
  371. @improved string handling, added new tokens, improved include file debug.
  372. @
  373. text
  374. @d7 1
  375. a7 1
  376.  *    $Date: 1994/02/13 16:41:58 $
  377. d9 1
  378. a9 1
  379.  *    $Revision: 1.3 $
  380. d14 3
  381. d177 1
  382. @
  383.  
  384.  
  385. 1.3
  386. log
  387. @added new include file processing, various extra tokens
  388. and corrected string rule to stop at newlines.
  389. @
  390. text
  391. @d7 1
  392. a7 1
  393.  *    $Date: 1994/02/12 20:00:19 $
  394. d9 1
  395. a9 1
  396.  *    $Revision: 1.2 $
  397. d14 4
  398. d26 2
  399. a31 2
  400. int lineno;
  401. char *current_filename;
  402. d46 1
  403. a46 1
  404. %x INCLUDE
  405. d67 1
  406. a67 1
  407.                 dbprintf(("include: from line %d of %s file %s\n",
  408. d75 1
  409. a75 1
  410.                     yyerror("include nested too deeply");
  411. d95 1
  412. a95 1
  413.                     yyerror("cannot open include file");
  414. d124 4
  415. a127 1
  416. [A-Z][A-Z0-9]+        { yylval.txt = (char*)yytext; return ID; }
  417. d129 4
  418. a132 1
  419. {SIGN}{DIGIT}+        { yylval.inum = atoi(yytext); return INT; }
  420. d134 6
  421. a139 1
  422. {SIGN}{DIGIT}+"."{DIGIT}*    { yylval.fnum = atof(yytext); return NUM; }
  423. d162 2
  424. d165 1
  425. d175 2
  426. d191 4
  427. a194 7
  428. \"[^\"\n]*\"    {
  429.                 static char b[256];
  430.                 char *p;
  431.                 strcpy(b, (char*)yytext+1); 
  432.                 p = strrchr(b, '\"');
  433.                 *p = '\0';
  434.                 yylval.txt = b;
  435. d196 41
  436. a236 1
  437.                 return STRING;
  438. d239 3
  439. a241 1
  440. ";".*\n            { /* comment lines are ok */ lineno++; }
  441. d243 2
  442. d251 3
  443. a253 5
  444. <INITIAL,INCLUDE>.            {
  445.                 char buf[32];
  446.                 sprintf(buf,"syntax error; character - %c (%d) unexpected.\n", yytext[0], (int)yytext[0]);
  447.                 yyerror(buf);
  448.                 return (255);
  449. d256 1
  450. a256 1
  451. <<EOF>>        {
  452. d269 1
  453. a269 1
  454.                     dbprintf(("include: return to line %d of file %s\n",
  455. d275 8
  456. @
  457.  
  458.  
  459. 1.2
  460. log
  461. @added in comments etc.
  462. @
  463. text
  464. @d5 1
  465. a5 1
  466.  *    $Author$
  467. d7 1
  468. a7 1
  469.  *    $Date$
  470. d9 1
  471. a9 1
  472.  *    $Revision$
  473. d13 4
  474. a16 1
  475.  *    $Log$
  476. d28 12
  477. d42 1
  478. a42 1
  479. %s OPTIONS
  480. d45 1
  481. d49 47
  482. d122 5
  483. a126 1
  484. <INITIAL>{DIGIT}+    { yylval.inum = atoi(yytext); return INT; }
  485. d128 3
  486. a130 2
  487. <OPTIONS>[-+]{DIGIT}*\.{DIGIT}+    { yylval.fnum = atof(yytext); return NUM; }
  488. <OPTIONS>[-+]{DIGIT}+\.{DIGIT}*    { yylval.fnum = atof(yytext); return NUM; }
  489. d145 1
  490. a151 1
  491. "baptised"        return BAPTISED;
  492. d163 2
  493. a165 10
  494. "option"        {
  495.                 BEGIN OPTIONS;
  496.                 return OPTION;
  497.             }
  498.  
  499. "{"            return OPENBRA;
  500. "}"            {
  501.                 BEGIN INITIAL;
  502.                 return CLOSEBRA;
  503.             }
  504. d171 1
  505. a171 1
  506. \"[^"]*\"        {
  507. d182 3
  508. a184 4
  509. ";".*\n            {
  510.                 /* comment lines are ok */
  511.                 lineno++;
  512.             }
  513. d186 1
  514. a186 4
  515. "\n"            {
  516.                 /* increment line count */
  517.                 lineno++;
  518.             }
  519. d188 1
  520. a188 2
  521. " "            {
  522.             }
  523. d190 5
  524. a194 1
  525. "    "        {
  526. d197 16
  527. a212 3
  528. .            {
  529.                 printf("bad - %c (%d)\n", yytext[0], (int)yytext[0]);
  530.                 return (255);
  531. @
  532.  
  533.  
  534. 1.1
  535. log
  536. @Initial revision
  537. @
  538. text
  539. @d1 16
  540. @
  541.