Like Tree1Likes
  • 1 Post By brewbuck

Lexical convention from Dennis Ritchie's manual

This is a discussion on Lexical convention from Dennis Ritchie's manual within the C Programming forums, part of the General Programming Boards category; Hi, I have been confused by this statement in the Dennis Ritchie's manual: "If the input stream has been parsed ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    3

    Lexical convention from Dennis Ritchie's manual

    Hi,

    I have been confused by this statement in the Dennis Ritchie's manual:

    "If the input stream has been parsed into tokens up to a given character, the next token is taken to include the longest
    string of characters which could possibly constitute a token."

    What does this mean? It is under the Lexical Convention section of the manual.

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    We say that the matching is greedy. For example, given the expression a+++b, we break it into the tokens a, ++, + and b rather than a, +, ++ and b.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,354
    To extend what laserlight said, it means that if more than one match is possible for the next sequence of characters, then use the longest one.

    The rule is actually rather critical, as it causes the sequence of characters 'abc' to be parsed as the single identifier 'abc', instead of the identifier 'a' followed by identifier 'b' followed by identifier 'c'.
    goodluck likes this.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    Thank you laserlight and brewbuck for your responses. That answers my question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dennis M. Ritchie
    By kermit in forum General Discussions
    Replies: 41
    Last Post: 10-17-2011, 04:39 PM
  2. The Father of C has Died Dennis Richie
    By zerokernel in forum C Programming
    Replies: 1
    Last Post: 10-14-2011, 09:15 AM
  3. Lexical Analyzer
    By ammad in forum C++ Programming
    Replies: 8
    Last Post: 11-18-2009, 05:59 PM
  4. Lexical analyzer for C
    By nishkarsh in forum C Programming
    Replies: 4
    Last Post: 08-26-2008, 08:05 AM
  5. Replies: 2
    Last Post: 01-04-2003, 12:16 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21