C compiler reads from right to left or left to right?
C compiler reads from right to left or left to right?
What's that supposed to mean.
Are you talking about
- source code
- expressions
- parameter passing
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Haha.... lets not forget about top down.
@OP This question is a bit much for a thread topic. If you are actually interested in compiler design, which will allow you to understand how the C compiler works, a good starting point for beginners is a series of articles that were written by Jack Crenshaw entitled - Let's Build a Compiler.
Otherwise as Salem pointed out you will need to ask a much more specific question, e.g. how does the C compiler interpret....<this specific example>
There no answer like 'YES' or 'NO' to this question. Its much more complicated than that to explain the whole lot. But from the lexical parsing point of view 'yes' it is left to right, but then later on the tokenised code it sent to syntax analyser which then becomes much more complicated in term like checking the grammar, stack machine and the rest.
ssharish
Last edited by ssharish2005; 07-16-2011 at 10:48 AM.
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Can anyone help me understand the code below:
Code:int main() { int var=7; printf("%d", var++ * ++var); return 0; }
No, because the code below isn't valid. It's not defined which side of * is evaluated first, and at what point a post-increment will happen (other than "before the start of the next line"). Therefore you can get many different possible outputs.
Ah, so this program is the underlying reason for your question in this thread?Originally Posted by ajishgopalr
Read this FAQ: comp.lang.c FAQ list · Question 3.2
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
May not be the best idea when dealing with undefined behaviour.Best bet... run it and see what happens. Change things a bit... run it again, until you understand it.
Like tabstop said, this is undefined. Just because you get one answer from your implementation doesn't mean you'll always get it.
I wonder, in written languages that read from right to left, if they can make source code that is right to left. I mean we use left to right, so the compiler does, so we write "int" instead of "tni". But I wonder - because the language itself shouldn't actually care - if you could have a right to left compiler. I mean I guess you could. You could always swap out a different character to represent 'int', right? Hm, I never thought about that. Might be interesting to see.
Quzah.
Hope is the first step on the road to disappointment.
Anything is possible as long as the parser for the compiler is written for it. I mean he*l, they even made a whitespace programming language.
Back in school, I learned to read and write Chinese (or more accurately, Mandarin) characters from left to right, top to bottom, just like English. However, traditionally, the characters are written top to bottom, right to left. If you want to be funky, you could have variants like bottom to top, left to right, or right to left, bottom to top.Originally Posted by quzah
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)