Is there an equivalent to JLex and JavaCup or Yacc for JavaScript? | Sololearn: Learn to code for FREE!

+3

Is there an equivalent to JLex and JavaCup or Yacc for JavaScript?

I want to parse, interpret, and analyze code from a custom programming language using JavaScript in a web browser. I made a few language translators with JLex and JavaCup in university which were pretty straightforward and wondered if there is anything similar implemented with JavaScript. I could relay the code to the server and use JLex and JavaCup there to parse the code but there are lots of benefits to doing it in the browser. If I had something like JLex and JavaCup that would generate a JavaScript implementation of the parser would be great. The custom programming language won't change in the web browser but the code from that custom programming language will so generating the parser in Java would be fine but I really want the parser to run in JavaScript with the code given as a string in JavaScript. If there is no similar JavaScript library, is there anything that will compile to WebAssembly? I see TeaVM can compile Java to WebAssembly but do you think JavaCup and JLex source code will require much change to become useful from JavaScript?

4/8/2021 3:49:28 PM

Josh Greig

1 Answer

New Answer

+1

PEG.js might do the trick. Here are some links about it: - https://pegjs.org/ - https://coderwall.com/p/316gba/beginning-parsers-with-peg-js - https://github.com/pegjs/pegjs I might make something with it in a few weeks. If anyone else has a better idea for a parser generator that makes JavaScript parsers without much work, please let me know.