l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
January 6: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2001 Dec 30 17:04

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] another C question (lex/yacc for parsing input)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] another C question (lex/yacc for parsing input)



On Mon 09 Apr 01, 11:56 AM, Micah Cowan said: 
> 
> I can't think of a good reason why you'd need to use memmove() in your
> parser - perhaps you should rethink the algorithm?

well, maybe there IS a better way of doing things.   but suppose a user inputs

        Computer,    initiate  auto-destruct sequence 520010

and what i care about (in fact, what i use to fulfill the commnad) are the
words:

        auto-destruct 520010

but i also want to allow the user to be more polite:

        Computer, pretty please initiate auto-destuct sequence 520010.

i use memmove to do things like:

   1. convert double spaces to single spaces
   2. get rid of superfluous tokens like "pretty please" and "Computer".

and then i ship off the resulting string

    auto-destruct 520010

to my parser which tokenizes the nouns and executes the relevant code for
auto destruction.


i know there are other ways of doing this (like searching the string for
certain tokens and building up a list from the start).   however, i tend to
like this method better.  because i can more easily see what's going on when my
parser handles "auto-destuct 520010" rather than (12 52 00 10).   there are a
lot of tokens, and i'd rather work with "auto-destruct" than "12".

it occurs to me that this is the sort of thing that's perfect for lex/yacc, but
i've been dragging my feet because it looks fairly complicated.   i think maybe
i'll take a look at it though.

pete

> I've lately been
> very interested in the subject in general, so I've been working
> through my copy of the Wizard book.  /Very/ informative reading (the C
> code's kinda dated, though).
> 
> Micah

-- 
"Coffee... I've conquered the Borg on coffee!"               p@dirac.org
       -- Kathryn Janeway on the virtues of coffee           www.dirac.org/p


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.