new question about old C compiler

Discussion in 'C Programming' started by Today's Mulan, Jul 17, 2006.

  1. 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"?
    Today's Mulan, Jul 17, 2006
    #1
    1. Advertising

  2. 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)
    =?ISO-8859-1?Q?St=E9phane_Zuckerman?=, Jul 17, 2006
    #2
    1. Advertising

  3. On 16 Jul 2006 17:28:30 -0700, "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"?


    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
    Barry Schwarz, Jul 17, 2006
    #3
  4. Today's Mulan

    Guest

    Barry Schwarz ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:

    > On 16 Jul 2006 17:28:30 -0700, "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"?

    >
    > 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 ?
    , Jul 17, 2006
    #4
  5. "Today's Mulan" <> wrote in message
    news:...
    > 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
    Rod Pemberton, Jul 17, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philipp
    Replies:
    2
    Views:
    375
    Shane McDaniel
    Jul 1, 2003
  2. Jim Hill
    Replies:
    3
    Views:
    398
    Jim Hill
    Feb 12, 2007
  3. *Prot3anThr3ad*

    old repository for old C++ source code

    *Prot3anThr3ad*, Sep 29, 2006, in forum: C++
    Replies:
    6
    Views:
    371
    *Prot3anThr3ad*
    Oct 2, 2006
  4. jakester
    Replies:
    3
    Views:
    1,821
    jakester
    Apr 3, 2007
  5. John Henry
    Replies:
    24
    Views:
    1,008
    alex23
    May 30, 2008
Loading...

Share This Page