Dec 112017
 
Tool to understand complex C expressions; helpful for those who don't recall all precedence rules. With C, lex, yacc sources.
File CPAREN.ZIP from The Programmer’s Corner in
Category C Source Code
Tool to understand complex C expressions; helpful for those who don’t recall all precedence rules. With C, lex, yacc sources.
File Name File Size Zip Size Zip Type
CPAREN.1 1726 927 deflated
CPAREN.C 3748 1526 deflated
CPAREN.DOC 2123 966 deflated
CPAREN.EXE 20941 11473 deflated
CPAREN.H 2260 940 deflated
HID.C 419 293 deflated
INFO 1438 716 deflated
LEX.C 28128 7285 deflated
LEX.L 6906 2143 deflated
MAKEFILE.DOS 1702 757 deflated
MAKEFILE.UNX 995 413 deflated
PARSE.C 41106 9752 deflated
PARSE.Y 7140 2363 deflated
README.1ST 2951 1466 deflated
Y_TAB.H 1636 598 deflated

Download File CPAREN.ZIP Here

Contents of the README.1ST file


README.1ST
==========

This was originally intended for BSD UNIX(tm), and by use of the
-Dindex=strchr, etc made compilable on USG (Sys V) and now fixed to
compile under MSDOS. This readme gives the main purpose of the util,
very briefly (read info and cparen.doc for details), what is needed to
build this under MSDOS, and what appears to be an annoying MSC bug.

The program is NOT intended to process whole C files, so don't even
try. This would require the program being able to parse the whole C
language. It is intended to have an expression one wants to check
piped thru it from an editor, or, one can start the program, type in
the expression standing alone, and end with (for MSDOS, a ^Z) EOF.
Cparen will output the expression with parentheses added showing how
it is evaluated. The purpose is to aid those that cannot remember all
the subleties of the precedence and associativity of C operators,
etc., and thus reduce the adding of parentheses in the actual code to
ensure that it is evaluated as one wants. Too many parentheses
clutter things up, and make the code even HARDER to read.

Since the YACC and LEX utils from UNIX(tm) are used to build the
parser and lexical analyzer, one cannot directly port the program to
MSDOS, and include the generated parse.c and lex.c files as that
output of yacc and lex are covered by copyright. However, the
Freeware utils BISON and FLEX, which are functionally the same, are
available for MSDOS, and while there are some differences, in most
cases these can be used in place of the AT&T utils. Flex has an
additional advantage for many cases in that a lex library is not
required, all references are either defined in the output as macros,
or as functions. In the case of CPAREN, there were no
incompatabilities.

In building for DOS though, I ran across a "feature" of MSC 5.1 that
resulted in failure of the output of bison (run as yacc) to compile.
The resultant file, renamed to parse.c, has a construct that goes:

#ifndef YYSTYPE
#define YYSTYPE int;
#endif

which didn't recognize YYSTYPE as being previously defined, and made
YYSTYPE be defined as int. Earlier, in an include, YYSTYPE was
typedef'd as a union. Apparently, #ifndef / #ifdef considers a
typedef'd identifier as not being defined, and overrides it. Fix was
to edit and use a %define in parse.y, and remove the typedef from the
header (cparen.h). Using the " %union YYSTYPE {... " in the parse.y
file causes bison to make the typedef, and being aware of it, doesn't
place the #ifndef YYSTYPE lines in the resultant parse.c file. Also,
this makes it appear in y_tab.h so the YYSTYPE is defined for other
files that include the header.

Anyway, after all this, the thing works, so enjoy. For those without
FLEX or BISON (PD YACC), I included the PARSE.C, Y_TAB.H, and LEX.C
files generated in the archive.

pat@rwingMon Oct 16 11:40:55 PDT 1989



 December 11, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)