Some flex help.

clayton@jazz.cc.gatech.edu (R. Clayton)
27 Dec 1998 01:09:19 -0500

          From comp.compilers

Related articles
Some flex help. clayton@jazz.cc.gatech.edu (1998-12-27)
Flex help received. clayton@ponce.cc.gatech.edu (1999-01-03)
| List of all articles for this month |

From: clayton@jazz.cc.gatech.edu (R. Clayton)
Newsgroups: comp.compilers
Date: 27 Dec 1998 01:09:19 -0500
Organization: College of Computing, Georgia Tech
Keywords: lex, question

I'm trying to parse a dvi file with the flex program


    /* stuff deleted */


    %%


    [\x00-\x7f] {
        }


    \x84(....)(....) {
        }


    /* stuff deleted */


    . {
        fprintf(stderr, "Unknown dvi command %hu (0x%02x).\n",
(byte) yytext[0], (byte) yytext[0]);
        exit(1);
        }


    %%


    /* stuff deleted */


but I'm running into some problems:


    po rm *cbp.o ; make type=bad
    flex -t bad-cbp.l > bad-cbp.c
    gcc -g -c bad-cbp.c -o bad-cbp.o
    gcc -g -o cbp bad-cbp.o -ll
    rm bad-cbp.c


    po cbp < ~/docs/dis/dis/dis.dvi
    Unknown dvi command 132 (0x84).


    po


If I replace


    \x84(....)(....) {
        }


with


    \x84 {
        read_natural(4);
        read_natural(4);
        }


and use


    static byte gc(void) {
        int c = input();
        assert(c != EOF);
        return (byte) c;
        }


    static natural read_natural(natural size) {
        natural n = 0;
        assert((1 <= size) && (size <= 4));
        for ( ; size > 0; size--)
            n = (n << 8) | gc();
        return n;
        }


everything works ok:


    po rm *cbp.o ; make type=good
    flex -t good-cbp.l > good-cbp.c
    gcc -g -c good-cbp.c -o good-cbp.o
    gcc -g -o cbp good-cbp.o -ll
    rm good-cbp.c


    po cbp < ~/docs/dis/dis/dis.dvi


    po


Does anybody know why I'm getting this behavior?


Notes:


  1 \x84........ doesn't work either.


  2 -lfl doesn't work either.


  3 lex doesn't work either (this is a clue, but I can't figure out for what).


  4 this is flex version 2.5.4 running on solaris 2.5.1.


  5 flex makes 8-bit scanners by default (scanner options: -vI8 -Cem).


R. Clayton
clayton@cc.gatech.edu


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.