Algorithm for matching declarators in C++

limweesi@iscs.nus.sg
Mon, 21 Jun 1993 10:36:08 GMT

          From comp.compilers

Related articles
Algorithm for matching declarators in C++ limweesi@iscs.nus.sg (1993-06-21)
Re: Algorithm for matching declarators in C++ hendrik@vedge.com (Hendrik Boom) (1993-06-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: limweesi@iscs.nus.sg
Keywords: C++, parse, question
Organization: National University of Singapore
Date: Mon, 21 Jun 1993 10:36:08 GMT

Hi,
I am involved in a C++ translator that requires me to check a
function signature (function call) against a list of function signatures
that are declared (overloading resolution). In the course of checking, I
have to match the declarator list of the actual argument to the
declarator list of the formal argument. This is where I am stuck !
Examples:


void f(int [][10][10]); \\ declarator list {[] [] []}
void g(int *[10]); \\ (array of pointers) { [] * }


main () {
int (**a)[], \\ { * * [] }
*(*b)[], \\ { * [] * }
* c[][10], \\ { [] [] * }


** d, \\ { * * }
e[][10]; \\ { [] [] }


f(a); \\ this will work
f(b); \\ this will fail
f(c); \\ this will fail


g(d); \\ this will work
g(e); \\ this will fail
}


The above result is obtained by compiling the code using CC (ver 2.1)
My main problem for this example is that I don't know when I can
convert a * declarator to a [] or vice versa. I believe there are some
rules or algorithms pertaining to this as it is exactly the same as C
language. Can somebody enlighten me on this, or point me to a book where
the matching algorithm or rules can be found. What about other form of
declarators { &, (), ::* } ? Do I also have to check on the const-ness
and volatile-ness of each declarator, if so, how ?




Thanx for any reply.


desperate email limweesi@iscs.nus.sg
  weesin
~~~~~~~~


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.