pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lexer woes


From: Ben Pfaff
Subject: Re: Lexer woes
Date: Tue, 23 Sep 2008 08:12:56 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

John Darrington <address@hidden> writes:

> I'm battling with the lexer again implementing subcommands of NPAR
> TESTS.  The problem is, some of the subcommands have hyphens. Eg
> NPAR TESTS /K-W foo BY bar (1,2).
> I ran into this once before with T-TEST, which could be worked around
> with a bit of a kludge, but I can't see how to do this in the present
> case without becoming very inelegent.

Are you parsing by hand or with q2c?  If you're doing it by hand,
then you should be able to do something like this:

        if (lex_token (lexer) == T_ID
            && !strcmp (lex_tokid (lexer), "K")
            && lex_look_ahead (lexer) == '-')
          {
            /* We know we're at "K-".  The only acceptable
               follow-on to this is "W". */
            lex_get ();
            lex_force_match (lexer, '-');
            if (!lex_force_match_id (lexer, "W"))
              {
                 ....abort parsing....
              }
            ...got K-W...
          }
        else
          {
            ...not K-W...
          }

If you are using q2c, we will have to teach it a similar trick.
-- 
Ben Pfaff 
http://benpfaff.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]