Re: Can we simplify "end"?
- Posted by Derek Parnell <ddparnell at bi?pond.co?> Aug 08, 2007
- 604 views
Bryan So wrote: > > I think it is quite redundant to use different endings for > > end procedure > end function > end if > end while > > etc... > > with proper indentation, which I am sure we all use, one > > end > > should be enough to end a loop or condition or function, etc, > without any ambiguity. If the language were being designed from scratch you might have a good arguement there. However, we have to consider all the existing code that uses the extra token. Remember that line endings don't mean a whole lot to the interpreter. So when we type ... for i = 1 to 10 do foo(i) end for for j = 11 to 20 do bar(j) end for the interpreter sees ... for i = 1 to 10 do foo(i) end for for j = 11 to 20 do bar(j) end for and when we remove the extra tokens ... for i = 1 to 10 do foo(i) end for j = 11 to 20 do bar(j) end So if the interpreter has to support both the existing syntax and the new syntax, whenever it sees the phrase "end for" it now has to work out Am I at the end of a for-loop or the beginning of a for-loop? To do that it has to look ahead a bit, back track to the right place and finalize the for-loop. This is not impossible, but with only the current syntax or only with the new syntax then no look-ahead/backtracking is needed. At least two other options are available to us to get around this. Create a new token that means 'end of loop' such as 'stop', 'done' or some such. for i = 1 to 10 do foo(i) done while sequence(X) do bar(X) done Or create a new token that can be used regardless of the type of loop being ended. for i = 1 to 10 do foo(i) end loop while sequence(X) do bar(X) end loop Both of these can co-exist with the old syntax and not introduce a significant performance hit on the intepreter. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell