Prog Languages help

Discussion in 'OT Technology' started by Coottie, Feb 19, 2007.

  1. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Ok this is my last hope....hopefully one of you guys can help me.

    I'm supposed to specify the semantics of the for statement in C++. I don't even know where to start. Any suggestions???





    Iblearn2google
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    PHP:
    for(010i++)
    {
        
    google("C++ for");
    }

    for(
    initial_setting 'foo'initial_setting != 'bar';;)
    {
       if(
    are_humans_good()) { }

       else 
       {
          
    give_planet_back_to_squirrels();
          
    initial_setting 'bar';
       }
    }
     
  3. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    that's the syntax...I need the semantics.

    fucking textbook sux
     
  4. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    for( i = 'initial_state'; i < 'conditional_test'; iterative_action) {}
     
  5. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    I thought that was the grammar.
     
  6. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Ah fuck.
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    The semantics?

    for(i = 0;i < 10; i++)

    means

    i = 0;
    while(i < 10) { i++; }
     
  8. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    I don't really know...that's part of what I'm trying to find out is WTF are the semantics?? I read that the semantics give meaning to the syntax.
     
  9. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    the book also says we can specify the semantics in 3 ways:
    1. by a language reference manual
    2. by defining a translator and
    3. by a formal definition - similar to mathmatical models

    but then it launches into discussions of attributes, bindings, functions and all sorts of other stuff. I'm soo confused.
     
  10. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    here's a clearer definition:
    Semantics reveals the meaning of syntactically valid strings in a language.
    For natural languages, this means correlating sentences and
    phrases with the objects, thoughts, and feelings of our experiences. For
    programming languages, semantics describes the behavior that a computer
    follows when executing a program in the language. We might disclose
    this behavior by describing the relationship between the input and
    output of a program or by a step-by-step explanation of how a program
    will execute on a real or an abstract machine.
     
  11. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    For operational semantics, you can just specify a list of inference rules.

    Code:
    for(i = 0; i < 10; i++)
    {
        // do something
    }
    
    Let b = the condition i < 10
    c = the commands in the block of the loop
    S = state notation

    The rules would be:

    Code:
               <b, S> --> false
    -----------------------------------
     <for (i=0; b; i++) do c, S> --> S
    
    and 
    
       <b, S> --> true  <c, S> --> S''   <for (i=0; b; i++) do c, S''> --> S'
    --------------------------------------------------------------------------
                         <for (i=0; b; i++) do c, S> --> S'
    
     
  12. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    hmm...ok...thanks.

    Don't think I've seen that notation used to describe the semantics of a language.

    What about bindings, scope, declarations, symbols and those sorts of things?? How does a symbol table fit into the semantic description??
     
  13. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    You're reading too much into it. The semantics of the loop does not need to concern itself with such things. A loop is defined by state transitions and a boolean expression. The contents of the loop block and anything outside the loop is irrelevant.
     
  14. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    hmmm...Ok so I'm still a bit confused then. I thought loops were considered to have a scope within the loop structure and bindings actually occured on the variables used to control the loops. Aren't the symbols of the language also part of this??? Don't I need to discuss these things in the semantics??

    The reason I think I'm confused is our text has a whole chapter titled semantics. It starts with the 3 ways to describe semantics then it launches into discussions about all those other things I'm mentioning. He doesn't give any examples on the 3 methods nor does he refer back to them...unless I missed it. I'm also unable to find where he refers to things like bindings and scope as semantics....they are just included in the chapter.
     
  15. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    You're partly correct except you're not generalizing enough. For the purpose of describing semantics of a loop, you should consider the loop condition as a boolean expression only. Otherwise you would need to define the syntax and semantics of all possible boolean expressions as well. Boolean expressions could therefore be composed of different atoms like integers, booleans, classes with references to public methods that return booleans, etc, etc... You would have to then describe all of these extraneous items. The focus needs to be on the loop itself because the inference rules for boolean expressions are MUCH longer than the rules for the loop itself. Remember that you're describing the semantics of the loop, not the entire language.

    What are the three ways? Operational, axiomatic, and denotational? Which book are you using?
     
  16. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    That makes a lot more sense...thanks. I think I'm starting to understand...but it's still a little fuzzy. I'm going to do a bit more research cuz I'm not sure how to formulate my next question. But thanks for your help so far.

    The 3 ways from the book are:
    1. by a language reference manual
    2. by defining a translator and
    3. by a formal definition - similar to mathmatical models


    And the book is this one:
    http://www.amazon.com/gp/product/0534953417/ref=pd_kar_gw_1/102-6944009-9693715

    If you know of a better book, lemme know. I tend to prefer more verbose writing styles.
     
  17. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
  18. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Ok finally got some clarification on what my prof wants. Seems he wants an explanation of how the statements are executed with flow charts diagraming the flow of the loop. This is much easier to do then I was thinking....but thanks again for all the help!
     
  19. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Das what I was tryin to show you, mang!
     
  20. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Yeah...thanks for trying.

    I would have listened but the book just threw me way off. My prof is also not very good about splainin' stuff. In fact, many of my classmate were also totally confused until we reviewed some of his previous answers. It's crazy cuz the way he answered the question in not even shown in the book.

    The prof was even saying tonight that he couldn't understand what the book was saying....this time the subject was data types. fook...i hate dis book.
     
  21. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Nice Mexicish accent deh, bwoss.
     
  22. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    I though it was Messican
     
  23. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    You mean Meheecano? Nah, it's only similar; hence "mexicISH". :fawk:
     

Share This Page