![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: Based on which syntax rules? ECMAScript's, JavaScript's, JScripts or others'? And if the Function constructor is not supported, the whole thing breaks. By trying get nasty do not get dorky ![]() |
#12
| |||
| |||
|
|
code = '{a = 1; b = 2}' = a = 1; return b = 2; snip |
#13
| |||
| |||
|
|
So the question, exercise, or problem is: given a function which will tell you whether or not you have a syntactically correct javascript, can you semi reasonably isolate the last statement to determine whether it should be prefixed with a return, and to do so in such case. |

#14
| |||
| |||
|
|
On Tue, 3 Nov 2009 at 16:42:34, in comp.lang.javascript, Csaba Gabor wrote: * <snip>>code = '{a = 1; b = 2}' = *a = 1; *return b = 2; * <snip b=2 is not the last statement. The last statement is the one that ends with } . You do know that a block statement, { ... }, is a statement, don't you ? |
#15
| |||
| |||
|
|
Csaba *Gabor wrote: So the question, exercise, or problem is: given a function which will tell you whether or not you have a syntactically correct javascript, can you semi reasonably isolate the last statement to determine whether it should be prefixed with a return, and to do so in such case. No, it is not possible because it would violate Rice's Theorem and respectively would violate the halting problem which is known to be undecidable. For the full description seehttp://en.wikipedia.org/wiki/Rice%27s_theorem in a very simplified yet useful form it states that "Any question about what an arbitrary script does with an arbitrary input is undecidable, unless it is trivial". |
#16
| |||
| |||
|
|
Csaba Gabor wrote: So the question, exercise, or problem is: given a function which will tell you whether or not you have a syntactically correct javascript, can you semi reasonably isolate the last statement to determine whether it should be prefixed with a return, and to do so in such case. No, it is not possible because it would violate Rice's Theorem and respectively would violate the halting problem which is known to be undecidable. For the full description see http://en.wikipedia.org/wiki/ Rice%27s_theorem in a very simplified yet useful form it states that "Any question about what an arbitrary script does with an arbitrary input is undecidable, unless it is trivial". snip |
#17
| |||
| |||
|
|
On Nov 4, 8:35*pm, John G Harris <j... (AT) nospam (DOT) demon.co.uk> wrote: On Tue, 3 Nov 2009 at 16:42:34, in comp.lang.javascript, Csaba Gabor wrote: * <snip>>code = '{a = 1; b = 2}' = *a = 1; *return b = 2; * <snip b=2 is not the last statement. The last statement is the one that ends with } . You do know that a block statement, { ... }, is a statement, don't you ? A rhetorical question? Nevertheless, since it has come up a few times in this thread... This exercise is about determining the last statement and its location (in possibly transformed code), and the method is more interesting to me than the exact definition used to get at an answer. What I am saying is that I would be just as happy with either the original {a = 1; b = 2} in the example above being returned, or the b = 2 portion that FF indicates. |
#18
| |||
| |||
|
|
Let's consider this same question in the PHP world, where it is easier to handle. In PHP land, all statements except the last one must end with ; or }. |
|
Thus, ignoring the final character in the code, find the prior occurrence of either ; or }. Strip the string from the next character to the end and syntax check it. If it doesn't pass, keep looking back for the next prior occurrence of ; or }. |
#19
| |||
| |||
|
|
Csaba Gabor wrote: So the question, exercise, or problem is: given a function which will tell you whether or not you have a syntactically correct javascript, can you semi reasonably isolate the last statement to determine whether it should be prefixed with a return, and to do so in such case. No, it is not possible because it would violate Rice's Theorem and respectively would violate the halting problem which is known to be undecidable. For the full description see http://en.wikipedia.org/wiki/Rice%27s_theorem in a very simplified yet useful form it states that "Any question about what an arbitrary script does with an arbitrary input is undecidable, unless it is trivial". |
#20
| ||||
| ||||
|
|
John G Harris wrote: Csaba Gabor wrote: snip>>code = '{a = 1; b = 2}' = a = 1; return b = 2; snip b=2 is not the last statement. The last statement is the one that ends with } . You do know that a block statement, { ... }, is a statement, don't you ? A rhetorical question? |
|
Nevertheless, since it has come up a few times in this thread... This exercise is about determining the last statement and its location (in possibly transformed code), |
|
and the method is more interesting to me than the exact definition used to get at an answer. |
|
What I am saying is that I would be just as happy with either the original {a = 1; b = 2} in the example above being returned, or the b = 2 portion that FF indicates. |
![]() |
| Thread Tools | |
| Display Modes | |
| |