Parsing l- and r-values

threeangrymonkeys@hotmail.com (AI)
23 Aug 2004 12:10:35 -0400

          From comp.compilers

Related articles
Parsing l- and r-values threeangrymonkeys@hotmail.com (2004-08-23)
| List of all articles for this month |
From: threeangrymonkeys@hotmail.com (AI)
Newsgroups: comp.compilers
Date: 23 Aug 2004 12:10:35 -0400
Organization: http://groups.google.com
Keywords: parse, question, comment
Posted-Date: 23 Aug 2004 12:10:35 EDT

Hi,
I have to write a simplified static analyzer for ANSI C, able (among
other things) to identify global variables usage (i.e. which global
variables are changed, and which are used into expressions) for each
function. For example:


extern int a;
extern int b;
foo()
{
        ...
        a = b++/2;
        ...
}


In this case, I need to detect that either a and b are changed by
foo(), and b is used into an expression. In a first time I can ignore
"complicated" cases as indirect assignments:


foo()
{
        int *d = &c;
        *d = 3; /* c is changed */
}


I have very little experience with parsers; I've used sometimes
flex/yacc for some trivial tasks, nothing more complicated than the
usual didactic examples. Before I start, I'd like to have your opinion
on the complexity of this task. Do you think it's possible to use
these lexers/parsers to solve the problem? All of the yacc C grammars
I've found don't make such distinction as "l-value" or "r-value", but
I suppose I can slightly modify the grammar. Or I need something
different?


Can you point me at some document/example I may find useful?


Thank you!
[I think it's more common to check for l-values in semantic code, not
in the grammar. -John]


Post a followup to this message

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