Language extension

This is a discussion on Language extension within the Contests Board forums, part of the Community Boards category; on the first assignment what about syntax errors. I am looking for a ( or a word Can I assume ...

  1. #16
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    on the first assignment what about syntax errors. I am looking for a ( or a word Can I assume they won't have
    Code:
    for )
    or something like that.

  2. #17
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Um linuxdude you are going from Pascal to C so you shouldn't be looking for
    Code:
    for (
    should be more along the lines of
    Code:
    for i := 0

  3. #18
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I figured we could have both types of for loops in the code

  4. #19
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ah, I would guess if there is a syntax error then you ignore it

  5. #20
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    One last question. Will all the for loops conditional part at least be on one line? Also can we assume that variable name isn't a keyword??

  6. #21
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Do not assume anything
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #22
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but when is it due?
    As long as it takes everyone to finish. When everyone who signed up in the first month submits and entry, the contest will be judged and the results posted. So feel free to take your time and do a good job.

    >I figured we could have both types of for loops in the code
    Yes. The extension shouldn't effect use of the rest of the language at all.

    >I would guess if there is a syntax error then you ignore it
    If it's a syntax error with the extension then you should handle it appropriately. I don't expect the preprocessor to completely understand anything more than the extension that it implements, but valid extension syntax should usually compile into valid C or C++ code.

    >Will all the for loops conditional part at least be on one line?
    Not necessarily. C and C++ are free-form languages.

    >Also can we assume that variable name isn't a keyword??
    Adding a check to ensure that the variable is a valid identifier and not a keyword would be a very good idea. The variable name does count as the syntax of the extension. Besides, such a check is relatively easy anyway.
    My best code is written with the delete key.

  8. #23
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    what about a loop like this. How is it in PASCAL?
    Code:
    for(i=0;i<250;x+=2);
    or
    for(i=0;i<100;x^=20);
    Do we have to incorporate those. And if so what is the syntax?

  9. #24
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Pascal for loops only increment or decrement by 1.

  10. #25
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    hmm, i'd enter this contest, but i'm too busy working on my actual language, lol. I'll just submit an OST->C++ converter program

  11. #26
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >is that what you mean?
    That would be a good start, but don't forget that the string has to be able to grow and shrink on its own. So using a statically sized array in the preprocessor doesn't meet the requirements.
    My best code is written with the delete key.

  12. #27
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I think the approach and method is for you to figure out.

  13. #28
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >that means that i will heavily use realloc()?
    Well, you don't have to. You could use malloc to allocate an array of some insanely huge size so that realloc or anything similar is unnecessary. As for the actual implementation, that's up to you to decide. You get to weigh different options and choose the one that fits the task best.
    My best code is written with the delete key.

  14. #29
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Quote Originally Posted by C+++C_forever
    ok, one more question and i am done: what's better:
    a.realloc() ,or
    b. free() and then malloc() ?
    thanks
    I don't like realloc. Any benefits you could get are destroyed by unpredictable behavior. You're effectively tricked into thinking that you're getting something when you're simply introducing subtle bugs. So rather than this:
    Code:
    T *temp = realloc(p, new_size);
    if (!temp) {
      error("Memory exhausted");
    }
    else {
      p = temp;
    }
    I prefer to do this:
    Code:
    T *temp = malloc(new_size);
    if (!temp) {
      error("Memory exhausted");
    }
    else {
      memcpy(temp, p, old_size);
      free(p);
      p = temp;
    }
    Now you can be sure of what's happening. Instead of hoping that any pointers into the memory block will not be invalidated, you ensure that they are so that they can be reseated accordingly. You also avoid sticky issues where realloc actually frees the memory instead of resizing it.
    My best code is written with the delete key.

  15. #30
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but isn't somehow like that realloc() is implemented?
    Yes, but realloc may or may not change the address of the original pointer which may or may not invalidate any pointers into the original memory. I'd rather be sure that it did so rather than hope it didn't and potentially get burned later when accessing a pointer outside of my address space.

    >here you meanthat it first frees the memory, then tries to alllocate a new block and it fails, right?
    No, I means that if the size is 0, realloc is the equivalent of free. No resizing is done, the memory is lost. The part that's sticky is that if the size were somehow set to 0 by accident, you'll end up accessing freed memory later.
    My best code is written with the delete key.

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What language did they make Java in?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 05:18 PM
  2. Strange loop
    By D@rk_force in forum C++ Programming
    Replies: 22
    Last Post: 12-18-2004, 02:40 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 02:11 PM
  4. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 02:20 AM
  5. Languages dying
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 07-29-2003, 11:08 AM

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