: :
: : 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?