Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > new question about old C compiler

Reply
Thread Tools

new question about old C compiler

 
 
Today's Mulan
Guest
Posts: n/a
 
      07-17-2006
I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?St=E9phane_Zuckerman?=
Guest
Posts: n/a
 
      07-17-2006
On Mon, 16 Jul 2006, Today's Mulan wrote:

> I guess this is new, at least to people who don't know about this, like
> me, please be prepared to give me a satifying answer,
> so please tell me how the compiler "knows" variable "i" as in a
> declaration of "int i" is of type "int"?


Er, because you told the compiler so ? You know, like in "int i;" ? Thus,
until the end of the current lexical scope, "i" is bound to be of type
"int".

--
"Je deteste les ordinateurs : ils font toujours ce que je dis, jamais ce
que je veux !"
"The obvious mathematical breakthrough would be development of an easy
way to factor large prime numbers." (Bill Gates, The Road Ahead)
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      07-17-2006
On 16 Jul 2006 17:28:30 -0700, "Today's Mulan"
<(E-Mail Removed)> wrote:

>I guess this is new, at least to people who don't know about this, like
>me, please be prepared to give me a satifying answer,
>so please tell me how the compiler "knows" variable "i" as in a
>declaration of "int i" is of type "int"?


There is nothing magical about i. The compiler doesn't know anything
about i until you tell it. In the case you cite, the compiler
recognizes the keyword int and applies that meaning the object name
that follows. If you had written "double i;", i would be a double and
not an int.

What is your real question?

Are you trying to learn how to write a compiler?

Are you trying to understand how your compiler parses the code?
(If so, the answer is it depends on the compiler.)


Remove del for email
 
Reply With Quote
 
prishil@slidemail.com
Guest
Posts: n/a
 
      07-17-2006

Barry Schwarz のメッセージ:

> On 16 Jul 2006 17:28:30 -0700, "Today's Mulan"
> <(E-Mail Removed)> wrote:
>
> >I guess this is new, at least to people who don't know about this, like
> >me, please be prepared to give me a satifying answer,
> >so please tell me how the compiler "knows" variable "i" as in a
> >declaration of "int i" is of type "int"?

>
> There is nothing magical about i. The compiler doesn't know anything
> about i until you tell it. In the case you cite, the compiler
> recognizes the keyword int and applies that meaning the object name
> that follows. If you had written "double i;", i would be a double and
> not an int.
>
> What is your real question?
>
> Are you trying to learn how to write a compiler?
>
> Are you trying to understand how your compiler parses the code?
> (If so, the answer is it depends on the compiler.)
>
>
> Remove del for email


Decalring double and int is different to the original question's
meaning ?

 
Reply With Quote
 
Rod Pemberton
Guest
Posts: n/a
 
      07-17-2006

"Today's Mulan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I guess this is new, at least to people who don't know about this, like
> me, please be prepared to give me a satifying answer,
> so please tell me how the compiler "knows" variable "i" as in a
> declaration of "int i" is of type "int"?
>


The compiler saves the variable name, i.e., identifier, and the variable
type, i.e., type-specifier, as two fields of a structure (which may have
more fields), usually in a binary tree (but, occasionally on stacks). The
information in the binary tree is what is left after the C code is lexed
(tokenized) and parsed (syntax checked). Since the information in the
binary tree _usually_ lacks lexical elements such as terminators,
punctuation, etc..., it is called an Abstract Syntax Tree (AST). If the
compiler implementors chose to retain the full lexical information of the C
code in the tree, it'd be called a Concrete Syntax Tree (CST). I guess if
you used stacks it'd be an "Abstract Syntax Stack"...


Rod Pemberton


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
So you think PythonCard is old? Here's new wine in an old bottle. John Henry Python 24 05-30-2008 12:00 AM
new hard disk on old, old pc Deano Computer Support 5 10-21-2005 12:32 PM
Can we use <compiler> tag to avoid RunTime Compiler error? Jack Wright ASP .Net 5 01-19-2004 04:36 PM
Compiler Error Message: The compiler failed with error code 128. Yan ASP .Net 0 07-21-2003 10:49 PM
use "old" .so-files with "new" compiler? Philipp C++ 2 07-01-2003 05:07 PM



Advertisments