March 19, 2002 Would banning do-nothing statements make the language easier to parse? | ||||
---|---|---|---|---|
| ||||
Would it make it easier to parse if it didn't allow statements that did nothing? For example, consider this line of code: foo * bar; If foo is a type, then this is a declaration of a variable called bar, which is a pointer to foo. However, if foo and bar are both variables, then it simply multiplies foo times bar but does nothing with the result. Thus, the language cannot be context-free; the compiler needs to know about the list of declared types and variables in order to know how to interpret things. However, if we banned such "do-nothing" statements, then it would be clear. Since the expression does not include any assignment, it is illegal. Now, there are some obvious problems with this: * Function calls. You must be able to call a function, even if you don't do anything with the return value, so by necessity no function call can be considered a "do-nothing" * Operator overloading (if ever included in the language) However, if we get past those two problems, would this really help us? Maybe there are even more ambiguity problems in the structure of C/C++/D that we can't really get around... -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
March 20, 2002 Re: Would banning do-nothing statements make the language easier to parse? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | That particular ambiguity is resolved by the rule "if it's parseable as a declaration, then it is a declaration." "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3C97CB5B.A27B42F5@deming-os.org... > Would it make it easier to parse if it didn't allow statements that did > nothing? For example, consider this line of code: > foo * bar; > If foo is a type, then this is a declaration of a variable called bar, > which is a pointer to foo. However, if foo and bar are both variables, > then it simply multiplies foo times bar but does nothing with the > result. > > Thus, the language cannot be context-free; the compiler needs to know about the list of declared types and variables in order to know how to interpret things. However, if we banned such "do-nothing" statements, then it would be clear. Since the expression does not include any assignment, it is illegal. > > Now, there are some obvious problems with this: > * Function calls. You must be able to call a function, even if you > don't do anything with the return value, so by necessity no function > call can be considered a "do-nothing" > * Operator overloading (if ever included in the language) > > However, if we get past those two problems, would this really help us? Maybe there are even more ambiguity problems in the structure of C/C++/D that we can't really get around... > > -- > The Villagers are Online! villagersonline.com > > .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] > .[ (a version.of(English).(precise.more)) is(possible) ] > ?[ you want.to(help(develop(it))) ] > > |
Copyright © 1999-2021 by the D Language Foundation