Related articles |
---|
How to parse char **argv? supercat@planet.net.hk (Raymond Li) (1997-09-07) |
Re: How to parse char **argv? wasser@jamin.enet.dec.com (1997-09-12) |
From: | Raymond Li <supercat@planet.net.hk> |
Newsgroups: | comp.lang.c,comp.compilers,comp.lang.c++ |
Date: | 7 Sep 1997 14:59:54 -0400 |
Organization: | Hong Kong Star Internet Ltd. |
Keywords: | C, parse, question |
Hello,
I have actually three questions, all related to the parsing of
C/C++:
Question 1:
Reading Section 5.2 of Brian and Dennis's The C Programming Language,
I tried to parse the following with the syntax rules defined in A8.5:
The rules in the book:
declarator:
pointer OPT direct-declarator
direct-declarator:
identifier
( declarator )
direct-declarator [ constant-expression OPT ]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list OPT )
The parse I tried:
char * * argv
| | |
| | identifer
| | |
| | direct-declarator
| | |
| -- declarator
| |
------ ???
My first question is: which grammer rule is it used for the last
line (???)?
Question 2:
In r.17.4 of Bjarne Stroustrup's The C++ Programming Language (second
edition)
It has the rules as:
declarator:
dname
ptr-operator declarator
declarator ( argument-declaration-list ) cv-qualifer-list OPT
declarator [ constant-expression OPT ]
( declarator )
With these rules, I found that the following parse seems to be
derived:
int * daytab [13]
| | |
pointer dname |
| | |
| declarator |
| | |
-----declarator |
| |
declarator----
But it is different from what I expected with rules of A8.3 of
Brian's book.
int * daytab [13]
| | |
pointer dname |
| | |
| declarator----
| |
-----declarator
What is the correct parsing and what rules should be used?
Question 3:
How are precedence (of operators ) defined in C 's grammar? Is it
defined implicitly with the ordering of the grammar rules? [Yes, -John]
For instance, books said that [] has a higher precedence than * in
*daytab[13], how is it defined in C language?
All advice and comments are welcomed. Thanks in advance for your
response. And please cc to my e-mail supercat@planet.net.hk as well.
Regards,
Raymond Li Cheuk Fai, supercat@planet.net.hk
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.