daveh@marob.MASA.COM (Dave Hammond) (07/25/88)
Can anyone suggest "novice level" reading material on the subjects:
1. Command parser design and implementation
2. YACC usage as it relates to #1 above.
I am involved with a project which currently does command parsing in a
brute-force manner (i.e. "if getchar is a begin-token then read till the
end-token, but lookout for comment lines along the way. Then do something
with the stuff between begin- and end-tokens").
I'm quite sure that with a better understanding of parser design I could do
this more efficiently. Also, perhaps YACC could do the trick for me, if I
knew how to make YACC do what I want.
Should it relate to the above, the syntax which I am attempting to parse is:
a. "procedures" consist of a name and a curly-brace surrounded
set of statements.
b. "statements" consist of a keyword, an optional set of comma
separated arguments, and a terminating semi-colon.
c. multi-word arguments must be surrounded with quotes.
d. comment lines may appear within (or between) procedures.
example:
# comment line
procedure {
keyword, arg1, arg2, "arg 3" ;
# comment line
keyword;
}
This is a bit simplified. For example, It would be helpful to
differentiate between "statement" and 'statement', check for
assignment operators (arg=text), etc.
Any pointers to appropriate reading materials, or suggestions for YACC
implementation of the above syntax would be appreciated.
Please e-mail responses. Thanks in advance.
Dave Hammond
DOMAIN: dsix2!daveh@masa.com
/dsix2!daveh
UUCP: {uunet | rutgers | spl1 | ...}!{masa.com | hombre}!<
\marob!daveh
USMAIL: DSI Communications Inc, 333 W. Merrick Road, Valley Stream, NY 11580
-----------------------------------------------------------------------------
daveb@laidbak.UUCP (Dave Burton) (07/29/88)
In article <342@marob.MASA.COM> daveh@marob.UUCP (Dave Hammond) writes: |Can anyone suggest "novice level" reading material on the subjects: | | 1. Command parser design and implementation | 2. YACC usage as it relates to #1 above. When you say `command parser' I think shell. If this is what you're after, you might try a book by Allen Holub called _On Command: Writing a UNIX-like Shell for MSDOS_. I believe it's published by M&T Pub., the same folks who do Doctor Dobb's Journal. The book is (also) sold through the magazine. _On Command_ is sold with complete sources for a PC csh-like shell. Another possibility, although much weaker, is Marc Rochkind's _Advanced UNIX Programming_. He develops a very simplistic shell. The benefit of this work is that it is very easy to understand and comprehend. If you're after more language oriented materials, but don't want alot of heavy compiler theory, you can try - you should try - a book by Arthur Pyster called _Compiler Design and Construction: Tools and Techniques_. This book gives a good *practical* background in parser design and construction. It has a section on YACC and lex, also. A somewhat more obtuse book, but dealing only with YACC and lex is one by Schreiner & Friedman called _Introduction to Compiler Construction with UNIX_. It's usable, but the Pyster book is better if you can find it. Since you requested novice level material, I assume you know of the `standard' reference work on compilation, the so-called new dragon book by Aho, Sethi and Ullman, whose exact title escapes me at present (the word `compiler' does figure prominently). Oops, I almost forgot. The book _The UNIX Programming Environment_ by Kernighan and Pike has an excellent section on YACC and its usage in the development (from scratch) of HOC, the High Order Calculator. It also uses a syntax fairly close to yours. Even if you don't care about parsers, IF YOU PROGRAM UNDER _UNIX_, YOU WANT THIS BOOK. -- Dave Burton * UNIX is a trademark of AT&T. (I didn't Email because I thought this might be of benefit to others, too.) -- Dave Burton | ``/* You are not expected to understand this. */'' ihnp4!laidbak!daveb | (312) 505-9100 x325 | Disclaimer: I channel only for myself.