Thread: Syntax design...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Smile Syntax design...

    Mmm... anyone know what kind of diagram is this?
    I saw something like this on ORACLE SQL Reference...

    http://audinue.navhost.com/Draft.jpg

    Maybe I can use it to design a programming language syntax.

    Thanks in advance.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is, uh, a syntax diagram. They arguably are an easier to trace alternative to EBNF, but a downside is that they are harder to translate and feed into parser generators.
    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,396
    Quote Originally Posted by laserlight View Post
    It is, uh, a syntax diagram. They arguably are an easier to trace alternative to EBNF, but a downside is that they are harder to translate and feed into parser generators.
    In this case the diagram looks like it was generated by Antlr, so it probably started out in parser form in the first place.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    It is, uh, a syntax diagram. They arguably are an easier to trace alternative to EBNF, but a downside is that they are harder to translate and feed into parser generators.
    Eww.. thanks for the answer laserlight! *_*

    In this case the diagram looks like it was generated by Antlr, so it probably started out in parser form in the first place.
    I drew it myself using Visio, there is a lot of mistake in it since I don't know what Syntax Diagram is.

    Umm... can I add the second silly question?

    We know three types of regular numbers in C...
    Can you tell me what are their name please?

    Code:
    1. 123321, 223311, 1024, 4096
    2. 0x00ff, 0x0123, 0x1212a
    3. 0.1232, 123.121, 0.0001231
    I know the second numbers are known as "hexadecimal numbers"...

    Thank you.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The first are integers in decimal notation.
    The second are integers in hexdecimal notation.
    The third are floating point numbers in point notation.

    There's also integers in octal notation and floating point numbers in scientific notation.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And in C99, there's also the exciting "floating point numbers in hexadecimal scientific notation".

  7. #7
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    There's also integers in octal notation and floating point numbers in scientific notation.

    And in C99, there's also the exciting "floating point numbers in hexadecimal scientific notation".
    Any example please?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You've never seen scientific notation before?
    Anyway, octal always starts with 0, so 037 is octal.
    Scientific notation is what it is: 4.75e128
    And the funky hex stuff uses hex for the significand, but decimal for the exponent, so that same number would look like 0x4.cp128.

  9. #9
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Oh my god... I never saw those thing.

    o_O... Incredible.

    And yet another silly question...

    I just curious of decimal notation...

    Why we not allowed to start a number from 0?

    For instance: 0000123, 00523

    It will give a clear looks of constants instead of hexadecimal number.

    Code:
    #define ERROR_XXX    00001
    #define ERROR_XXXX   00082
    #define ERROR_XYZ    00103
    #define ERROR_YYY    00127
    Last edited by audinue; 11-16-2008 at 08:39 AM.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because numbers that start with zero are in octal notation.
    Last edited by tabstop; 11-16-2008 at 08:45 AM.

  11. #11
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    That "syntax diagram" looks like a failed Railroad Diagram. I would find EBNF easier to understand than those ovals and arrows. whats w/ those arrows anyway, they certainatly don't make it easier to follow.
    Also, I didn't know that numbers that start w/ 0 are in base 8. I am suprised the 0s don't get truncated. Still, in maths (outside of C) 00001 is exactly the same as 1, becasue one has to explicitly define if the number is in a different base to 10 which is default. It works well though as it doesn't limit either number base.
    So something to remember: 0x~ = hex, 0~ = octal, where ~ represents a number
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by P4R4N01D
    That "syntax diagram" looks like a failed Railroad Diagram. I would find EBNF easier to understand than those ovals and arrows. whats w/ those arrows anyway, they certainatly don't make it easier to follow.
    I believe that "syntax diagram" and "railroad diagram" are synonyms. The arrows allow the reader to distinguish between repetition and alternatives.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM