🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41961

Hacking gcc and yyparse

#41961
From: Chris Madison
Date: Tue, 30 Jan 1996 00:00
58 lines
2557 bytes
The system is a Solaris box with gcc-2.7.2.

I am attempting to modify the grammer in yyparse to extract 
structure information amongst other things.  For example if 
a .h has struct def of:

	struct a {
		double d;
	};

I would like to extract this and print it to a file.  In this
case extracting IDENTIFIER 'a' and determining the start and
finish of the structure is trivial.  Something like:

structsp:
	STRUCT identifier '{' 
	{  /* normal stuff */
	   fprintf(stderr, "structure %s\n", IDENTIFIER_POINTER($2));
	}
	component_decl_list
	'}' {  /* finish struct*/
		fprintf(stderr, "structure ends at line %d\n", lineno);
	    }
      | //...

works just fine.

The problem comes when trying to extract, in this case, double d.
An easy solution has been found, namely when yylex() is called
and double has been found to be a TYPESPEC, one has the ridpointers[]
available and can just set a some global variable char * to be "double."

However I would much rather use the macros available in tree.h and
other places to just print out the info once the identifier has
been reached.  Every time I use, say TREE_NAME() or TREE_CODE()
the compilation receives a sig 11, so apparently I'm not doing
something right - and we all know gcc isn't to blame:-)

Printing out a yydebug dump reveals that in the case above
double d is being reduced in 
component_decl -> typed_typespecs setspecs components,
so I am playing with component_declarator: to extract the information.

Sifting through the code for grokfield() and decl_attributes()
has been helpful, but something just isn't clicking.  And again,
using IDENTIFIER_POINTER with $3 in component_declarator easily
extracts the identifier.

I would appreciate any pointers on how to traverse a tree to
extract the type information.  Or even if a component that has
been declared as char, will have "char" (or some representation)
stored in the tree somewhere besides just INTEGRAL_TYPE.

Thanks,
chris
================================================================
cmadison@vnet.net	|   	 tippy is now running under
root@tippy.vnet.net	|	     FreeBSD 2.1 Release!
Technical Details
Message-ID: <4ekgn4$6hn@ralph.vnet.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,8b7c2661b3c3cc33,start
X-Google-Attributes: gid11318c,public
From: root@tippy.vnet.net (Chris Madison)
Subject: Hacking gcc and yyparse
Date: 1996/01/30
Message-ID: <4ekgn4$6hn@ralph.vnet.net>
X-Deja-AN: 137241117
organization: Vnet Internet Access, Charlotte, NC - info@char.vnet.net
newsgroups: gnu.gcc.help