How do I implement check_type() ?

seescreen@gmail.com
Fri, 22 May 2009 19:08:43 -0700 (PDT)

          From comp.compilers

Related articles
How do I implement check_type() ? seescreen@gmail.com (2009-05-22)
Re: How do I implement check_type() ? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-05-25)
Re: How do I implement check_type() ? m.helvensteijn@gmail.com (Michiel Helvensteijn) (2009-05-25)
| List of all articles for this month |
From: seescreen@gmail.com
Newsgroups: comp.compilers
Date: Fri, 22 May 2009 19:08:43 -0700 (PDT)
Organization: Compilers Central
Keywords: question, C++
Posted-Date: 24 May 2009 19:33:20 EDT

I am transforming the YACC grammar and LEX specification into a very
simple C++ interpreter. I am only adding classes from C++ to the
grammar referenced below. I parse all of the input source code file
into an Abstract Syntax Tree.


In the case of this project I need to return TYPE_NAME from the lexer
whenever I encounter a Class name. The problem seems to be that only
the parser knows whether or not the IDENTIFIER is a class name or not,
and yet the lexer sees the name before it goes to the parser.


What is the simplest way to get around this problem?


http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
http://www.lysator.liu.se/c/ANSI-C-grammar-l.html


int check_type()
{
/*
* pseudo code --- this is what it should check
*
* if (yytext == type_name)
* return(TYPE_NAME);
*
* return(IDENTIFIER);
*/


/*
* it actually will only return IDENTIFIER
*/


return(IDENTIFIER);
}


Post a followup to this message

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