Using the start and end of JavaScript

Is there any way to change the JavaScript language so that end equals character } and begin equals { ?

+4
source share
3 answers

No, you can’t. The best thing you could do is have a script that changes another script with an invalid type and changes it to a valid type so that you get an effect like.

 <script type="text/x-algolscript"> function hello() begin alert("Hello, world!"); end hello(); </script> <script type="text/javascript"> Array.prototype.forEach.call(document.getElementsByTagName('script'), function(script) { if(script.type === 'text/x-algolscript') { var oldParent = script.parentNode; var oldNext = script.nextSibling; oldParent.removeChild(script); script.textContent = script.textContent.replace(/\bbegin\b/g, '{').replace(/\bend\b/g, '}'); script.type = 'text/javascript'; oldParent.insertBefore(script, oldNext); } }); </script> 

It does not depend on the context, and will happily change your lines, etc.

Bonus: Minimum and more browser compatible version:

 !function(s,i,t,e,l,p,o,n){for(l=s.length;i<l;i++)((e=s[i]).type==='text/x-algolscript')&&t.push(e);for(i=0;i<t.length;i++)o=(e=t[i]).parentNode,n=e.nextSibling,o.removeChild(e),p='textContent',e[p]||(p='innerText'),e[p]=e[p].replace(/\bbegin\b/,'{').replace(/\bend\b/,'}'),e.type='text/javascript',o.insertBefore(e,n)}(document.getElementsByTagName('script'),0,[]); 
+6
source

You can write your own transcompiler that will parse our Pascalesque Javascript and output traditional Javascript. You can simply replace the begin / end words with brackets or use something more advanced like Jison .

+5
source

Take a look at META II .

... make a lot of compilers - and everything will be easy. No Ajax, Active X, DLL, SO, ASP, CGI, Java, plugins, modules, XML, cookies, PHP, Perl, Python, mask operations, the worldwide standard du jour or intergalactic dominance plans - just JavaScript in frames. You can also move the compiler to build these web pages and to your programming language of choice by cutting and gluing. After all, a compiler is just a program that reads text and writes text or a binary file.

Like an idea.


Alternatively, you can use the following (dubious) coding style (to familiarize yourself with ES grammar) at the beginning:
 function name(args){//begin // your code here }//end while(L--){//begin // your code here }//end 
+2
source

All Articles