Parsing l- and r-values (AI)
23 Aug 2004 12:10:35 -0400

          From comp.compilers

Related articles
Parsing l- and r-values (2004-08-23)
| List of all articles for this month |

From: (AI)
Newsgroups: comp.compilers
Date: 23 Aug 2004 12:10:35 -0400
Keywords: parse, question, comment
Posted-Date: 23 Aug 2004 12:10:35 EDT

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;
        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:

        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

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.