i wan to know - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

i wan to know

talhanasirtalhanasir Posts: 13Member
i want to put this bracket ) in which data type, can i assign this bracket (.

i want to know code of this line (2+2) = 4 . if user enters the line
(2+2) and answer 4 will come with the brackets i want to know the code of this line.
«1

Comments

  • LundinLundin Posts: 3,711Member
    : i want to put this bracket ) in which data type, can i assign this bracket (.
    :
    : i want to know code of this line (2+2) = 4 . if user enters the line
    : (2+2) and answer 4 will come with the brackets i want to know the code of this line.
    :


    It depends on what input the user is allowed to make, how much error handling you want to add etc. And we still won't write any code for you.
  • Gregry2Gregry2 Posts: 607Member
    : : i want to put this bracket ) in which data type, can i assign this bracket (.
    : :
    : : i want to know code of this line (2+2) = 4 . if user enters the line
    : : (2+2) and answer 4 will come with the brackets i want to know the code of this line.
    : :
    :
    :
    : It depends on what input the user is allowed to make, how much error handling you want to add etc. And we still won't write any code for you.
    :

    I'm writting a program that'll do that. I'm only working on its components (not the main program), and I already have a file thats 500+ lines. And thats only its support. I wrote a smaller program thats similar(it has errors i'm too lazy to fix) and it composed of at least 10 files, so of which had +100, if not +200 or 300 lines...I think.

    This that you are asking is NOT a simple task. However, if you are still itching to know how to do this, run a search on google for reverse polish notation and also look for link on how to write an interpreter.
    {2}rIng
  • tokoGtokoG Posts: 209Member
    : : : i want to put this bracket ) in which data type, can i assign this bracket (.
    : : :
    : : : i want to know code of this line (2+2) = 4 . if user enters the line
    : : : (2+2) and answer 4 will come with the brackets i want to know the code of this line.
    : : :
    : :
    : :
    : : It depends on what input the user is allowed to make, how much error handling you want to add etc. And we still won't write any code for you.
    : :
    :
    : I'm writting a program that'll do that. I'm only working on its components (not the main program), and I already have a file thats 500+ lines. And thats only its support. I wrote a smaller program thats similar(it has errors i'm too lazy to fix) and it composed of at least 10 files, so of which had +100, if not +200 or 300 lines...I think.
    :
    : This that you are asking is NOT a simple task. However, if you are still itching to know how to do this, run a search on google for reverse polish notation and also look for link on how to write an interpreter.
    : {2}rIng
    :


    Just wondering if you guys are talking about the topic out of my scope.. the navice level. Isn't this asking how to put bracket like in the printf?

    printf("(%d)", int);

    :P
  • Gregry2Gregry2 Posts: 607Member
    :
    : Just wondering if you guys are talking about the topic out of my scope.. the navice level. Isn't this asking how to put bracket like in the printf?
    :
    : printf("(%d)", int);
    :
    : :P
    :

    He asking about how to make a parser, its a program or part of a program that reads characters and determines which characters mean what and usually produce tokens that other parts of the program can understand.

    For example, we have a string

    "23+432"

    We know that the sequences 23 and 432, that is, the series of characters 2 & 3 and 4,3 & 2, really represent numbers, the numbers, of course, 23 and 432. The `+' is an operator, the addition operator, which we know states that the two numbers are added. Now of course, we've known this stuff since kindergarden (or was it pre-school?..i forgot), so we're able to recognize this right away.

    However, to a computer, or rather a program without a parser, the characters don't mean anything, they're just characters. No character has anything special over the other, they just can have the same number code or one thats greater or less...but basically, they're all characters.

    However, a computer/program doesn't "know" anything ,or rather, determine anything unless its programmed. So humans, trying to be the intelligent animals they claim to be...err are, have made programs that determine whether a sequence of characters in a string is a number, an operator, or something thats not supposed to be there.

    See, a parser would take "23+432" and be able to tell that "23" is a number, "432" is also a number, and "+" is an operator, and be able to output something that would tell the other parts of the program what the string meant and what that part needs to do.

    They usually, or rather, are in the form of a loop that scans a string, checking character and determining whether its a number or character or operator.

    But its alot harder then how I explained it(can you believe that, even after such long paragraphs...). Depending on how much you want to be recognized, the parser should be able to recognize other operators, like "-", "*" or "/", and even operator combinations, like the C/C++ operators "==", "!=", "<=", ">="...and you can't just check the first character and tell what it is, you'd have to make more checks to compensated for all the possible combinations. (e.g., you check the character "<", you can't just assume that the user only entered that but you have to check the character if its "=". Checking for things like this and keeping things generic can take a while to think about)

    And worse comes when you have to anticipate user errors. Say the user enters "3+#2", what will happen when the parser sees the "#", it'll have to determine that it is the error and be able to tell the user about it.

    A bazillion number of errors can occur, and you'd have to determine a generic way to deal with them. And all that depends on the syntax/grammar the parser would expect among other things. Thats why Lundin said it matters on what talhanser (sorry, forgot ur name) wants.

    It isn't simple, its as simple as that...and if u don't understand, sorry about it, but its not that important anyway, if you plan to be a use application developer. Not many people make parsers, and I even read somewhere that today most are generated
    {2}rIng
  • talhanasirtalhanasir Posts: 13Member
    : :

    thanks for your message but i want to know the code of (2+2)= 4 and is it possible or not just tell me thanks talha nasir.


    : : Just wondering if you guys are talking about the topic out of my scope.. the navice level. Isn't this asking how to put bracket like in the printf?
    : :
    : : printf("(%d)", int);
    : :
    : : :P
    : :
    :
    : He asking about how to make a parser, its a program or part of a program that reads characters and determines which characters mean what and usually produce tokens that other parts of the program can understand.
    :
    : For example, we have a string
    :
    : "23+432"
    :
    : We know that the sequences 23 and 432, that is, the series of characters 2 & 3 and 4,3 & 2, really represent numbers, the numbers, of course, 23 and 432. The `+' is an operator, the addition operator, which we know states that the two numbers are added. Now of course, we've known this stuff since kindergarden (or was it pre-school?..i forgot), so we're able to recognize this right away.
    :
    : However, to a computer, or rather a program without a parser, the characters don't mean anything, they're just characters. No character has anything special over the other, they just can have the same number code or one thats greater or less...but basically, they're all characters.
    :
    : However, a computer/program doesn't "know" anything ,or rather, determine anything unless its programmed. So humans, trying to be the intelligent animals they claim to be...err are, have made programs that determine whether a sequence of characters in a string is a number, an operator, or something thats not supposed to be there.
    :
    : See, a parser would take "23+432" and be able to tell that "23" is a number, "432" is also a number, and "+" is an operator, and be able to output something that would tell the other parts of the program what the string meant and what that part needs to do.
    :
    : They usually, or rather, are in the form of a loop that scans a string, checking character and determining whether its a number or character or operator.
    :
    : But its alot harder then how I explained it(can you believe that, even after such long paragraphs...). Depending on how much you want to be recognized, the parser should be able to recognize other operators, like "-", "*" or "/", and even operator combinations, like the C/C++ operators "==", "!=", "<=", ">="...and you can't just check the first character and tell what it is, you'd have to make more checks to compensated for all the possible combinations. (e.g., you check the character "<", you can't just assume that the user only entered that but you have to check the character if its "=". Checking for things like this and keeping things generic can take a while to think about)
    :
    : And worse comes when you have to anticipate user errors. Say the user enters "3+#2", what will happen when the parser sees the "#", it'll have to determine that it is the error and be able to tell the user about it.
    :
    : A bazillion number of errors can occur, and you'd have to determine a generic way to deal with them. And all that depends on the syntax/grammar the parser would expect among other things. Thats why Lundin said it matters on what talhanser (sorry, forgot ur name) wants.
    :
    : It isn't simple, its as simple as that...and if u don't understand, sorry about it, but its not that important anyway, if you plan to be a use application developer. Not many people make parsers, and I even read somewhere that today most are generated
    : {2}rIng
    :

  • tokoGtokoG Posts: 209Member
    : :
    : : Just wondering if you guys are talking about the topic out of my scope.. the navice level. Isn't this asking how to put bracket like in the printf?
    : :
    : : printf("(%d)", int);
    : :
    : : :P
    : :
    :
    : He asking about how to make a parser, its a program or part of a program that reads characters and determines which characters mean what and usually produce tokens that other parts of the program can understand.
    :
    : For example, we have a string
    :
    : "23+432"
    :
    : We know that the sequences 23 and 432, that is, the series of characters 2 & 3 and 4,3 & 2, really represent numbers, the numbers, of course, 23 and 432. The `+' is an operator, the addition operator, which we know states that the two numbers are added. Now of course, we've known this stuff since kindergarden (or was it pre-school?..i forgot), so we're able to recognize this right away.
    :
    : However, to a computer, or rather a program without a parser, the characters don't mean anything, they're just characters. No character has anything special over the other, they just can have the same number code or one thats greater or less...but basically, they're all characters.
    :
    : However, a computer/program doesn't "know" anything ,or rather, determine anything unless its programmed. So humans, trying to be the intelligent animals they claim to be...err are, have made programs that determine whether a sequence of characters in a string is a number, an operator, or something thats not supposed to be there.
    :
    : See, a parser would take "23+432" and be able to tell that "23" is a number, "432" is also a number, and "+" is an operator, and be able to output something that would tell the other parts of the program what the string meant and what that part needs to do.
    :
    : They usually, or rather, are in the form of a loop that scans a string, checking character and determining whether its a number or character or operator.
    :
    : But its alot harder then how I explained it(can you believe that, even after such long paragraphs...). Depending on how much you want to be recognized, the parser should be able to recognize other operators, like "-", "*" or "/", and even operator combinations, like the C/C++ operators "==", "!=", "<=", ">="...and you can't just check the first character and tell what it is, you'd have to make more checks to compensated for all the possible combinations. (e.g., you check the character "<", you can't just assume that the user only entered that but you have to check the character if its "=". Checking for things like this and keeping things generic can take a while to think about)
    :
    : And worse comes when you have to anticipate user errors. Say the user enters "3+#2", what will happen when the parser sees the "#", it'll have to determine that it is the error and be able to tell the user about it.
    :
    : A bazillion number of errors can occur, and you'd have to determine a generic way to deal with them. And all that depends on the syntax/grammar the parser would expect among other things. Thats why Lundin said it matters on what talhanser (sorry, forgot ur name) wants.
    :
    : It isn't simple, its as simple as that...and if u don't understand, sorry about it, but its not that important anyway, if you plan to be a use application developer. Not many people make parsers, and I even read somewhere that today most are generated
    : {2}rIng
    :



    ??
    I thought I replied to this message but it's gone! grrr
    Anyhow, wow thanks for the lengthly explanation, I didnt even know perser or persing existed. I checked the web sites for the word perser and got more information. :)

    But, simply... is it the translator emboded in the most of the language builder (like mine is Borland C++ Builder) to translate the programming languages to machine languages?? I thought the complier is doing what you explained already... and that for some ppl have to build by hand sometimes?
  • Gregry2Gregry2 Posts: 607Member
    [b][red]This message was edited by Gregry2 at 2006-6-29 22:40:4[/red][/b][hr]
    : ??
    : I thought I replied to this message but it's gone! grrr
    : Anyhow, wow thanks for the lengthly explanation, I didnt even know perser or persing existed. I checked the web sites for the word perser and got more information. :)
    :

    Lol, why are you thanking me. My reply was TOO long and I should have deleted it, but I was too lazy...

    : But, simply... is it the translator emboded in the most of the language builder (like mine is Borland C++ Builder) to translate the programming languages to machine languages?? I thought the complier is doing what you explained already...
    :
    Yeah, sorta. See the part of the compiler that reads and "understands" the text is the parser. The "translating", the generation of machine code is done based on what the parser has read and outputed, but the two can be one part, I believe.

    My program is somewhat like that, they are one part.

    Or maybe it is one part. I know at least that interpreters do that. They are like compilers, but they read code and directly execute, they don't generate an executable and then you execute the executable.

    : and that for some ppl have to build by hand sometimes?

    Yeah, actually, I didnt know something as complicated as that can be generated, but I read it somewhere...
    {2}rIng

    EDIT to talhansir:
    No, I can't give you code that works perfectly, sorry. Plus, it really matters on what syntax you want your program to expect. We can only help in describing, because code for a parser isn't that simple(ie. I can't write it in 10 min.).

    It isn't a simple task, but if you still want it, you need to start on your own. We'll help, if you ask more specific questions and questions we can answer in your and our timeframe.

    And if your still in need of code, I still suggest you start, because being my lazy self, it'll be a month or two...or more...before I'm finished. I might let you see, then.
    {2}rIng
  • tokoGtokoG Posts: 209Member
    : : ??
    : : I thought I replied to this message but it's gone! grrr
    : : Anyhow, wow thanks for the lengthly explanation, I didnt even know perser or persing existed. I checked the web sites for the word perser and got more information. :)
    : :
    :
    : Lol, why are you thanking me. My reply was TOO long and I should have deleted it, but I was too lazy...

    [blue]
    Of course I appreciate for someone taking a time or even be bothered to answer my questions!
    [/blue]
    :
    : : But, simply... is it the translator emboded in the most of the language builder (like mine is Borland C++ Builder) to translate the programming languages to machine languages?? I thought the complier is doing what you explained already...
    : :
    : Yeah, sorta. See the part of the compiler that reads and "understands" the text is the parser. The "translating", the generation of machine code is done based on what the parser has read and outputed, but the two can be one part, I believe.
    :
    : My program is somewhat like that, they are one part.
    :
    : Or maybe it is one part. I know at least that interpreters do that. They are like compilers, but they read code and directly execute, they don't generate an executable and then you execute the executable.


    :
    : : and that for some ppl have to build by hand sometimes?
    :
    : Yeah, actually, I didnt know something as complicated as that can be generated, but I read it somewhere...
    : {2}rIng
    :
    [blue]
    OK.. so perser is something within complier sort of.
    Maybe some ppl just want to change the setting.. for some reason unknown...OK.. good that it's not the topic my course will handle!!!!
    [/blue]
  • LundinLundin Posts: 3,711Member
    : : :
    :
    : thanks for your message but i want to know the code of (2+2)= 4 and is it possible or not just tell me thanks talha nasir.

    Yeah it is possible, I don't mind doing your homework, here you go:

    [code]
    #pragma MESSAGE DISABLE C5919
    FlashResult flashInit (const uint32 OSC_FREQ,
    const uint32 BUS_FREQ)
    {
    const double clk_us = 1/((double)BUS_FREQ) * 1000;
    const float CLKDIV = OSC_FREQ / 1000.0;
    const float CLKDIV8 = CLKDIV / 8.0;
    const float PRDCLK = ((OSC_FREQ > 12800) ? CLKDIV8 : CLKDIV) * (5.0 + clk_us);

    const uint8 FDIV = (const uint8)( ( (PRDCLK-(const uint16)PRDCLK) > 0.0 ) ?
    (const uint8)PRDCLK :
    (const uint8)PRDCLK - 1 );

    const uint8 fclkdiv = (0x3F & FDIV) | ((OSC_FREQ > 12800) ? PRDIV8 : 0);
    const float FLASHCLK = ((OSC_FREQ > 12800) ? CLKDIV8 : CLKDIV)*1000 / (1+FDIV);

    if(FLASHCLK < 150.0 || FLASHCLK > 200.0)
    return FLASH_PRESCALE_FAILURE;

    FCLKDIV = fclkdiv;


    return FLASH_OK;
    }
    #pragma MESSAGE DEFAULT C5919
    [/code]
  • Gregry2Gregry2 Posts: 607Member
    [b][red]This message was edited by Gregry2 at 2006-6-30 5:23:11[/red][/b][hr]
    : : : :
    : :
    : : thanks for your message but i want to know the code of (2+2)= 4 and is it possible or not just tell me thanks talha nasir.
    :
    : Yeah it is possible, I don't mind doing your homework, here you go:
    :
    : [code]
    : #pragma MESSAGE DISABLE C5919
    : FlashResult flashInit (const uint32 OSC_FREQ,
    : const uint32 BUS_FREQ)
    : {
    : const double clk_us = 1/((double)BUS_FREQ) * 1000;
    : const float CLKDIV = OSC_FREQ / 1000.0;
    : const float CLKDIV8 = CLKDIV / 8.0;
    : const float PRDCLK = ((OSC_FREQ > 12800) ? CLKDIV8 : CLKDIV) * (5.0 + clk_us);
    :
    : const uint8 FDIV = (const uint8)( ( (PRDCLK-(const uint16)PRDCLK) > 0.0 ) ?
    : (const uint8)PRDCLK :
    : (const uint8)PRDCLK - 1 );
    :
    : const uint8 fclkdiv = (0x3F & FDIV) | ((OSC_FREQ > 12800) ? PRDIV8 : 0);
    : const float FLASHCLK = ((OSC_FREQ > 12800) ? CLKDIV8 : CLKDIV)*1000 / (1+FDIV);
    :
    : if(FLASHCLK < 150.0 || FLASHCLK > 200.0)
    : return FLASH_PRESCALE_FAILURE;
    :
    : FCLKDIV = fclkdiv;
    :
    :
    : return FLASH_OK;
    : }
    : #pragma MESSAGE DEFAULT C5919
    : [/code]
    :

    To Lundin, who else:

    ...
    You are cold, inconsiderate, of evil heart. I have never know such a dark, wicked, and sinisterly funny individual in the whole of 16 years of existance on this cursed rock some of us call home
    ...
    take the compliment XD

    {2}rIng
«1
Sign In or Register to comment.