HELP NEEDED WITH CREATING A LANGUAGE!
[deleted]

So, I have this language that I have been developing. It uses Regex's to "translate" Hsuya's(My language) code to JavaScript. This works well and all but, I want to make it have errors. If anyone could help me with that, that would be great!

You are viewing a single comment. View All
Answered by Coder100 [earned 5 cycles]
View Answer
xxpertHacker

Options:
A) Validate the input, if it's invalid, throw an exception.
B) Validate the output, if the output isn't valid JS, throw an exception.
C) JavaScript is not a compilation target, Wasm is. (validating is as simple as calling WebAssembly.validate(output))

Regarding (B), if your output is incorrect, I'd consider it to be a compiler error, parse correctly and this won't happen.

[deleted]

Thanks! @xxpertHacker

xxpertHacker

@AJK4 Btw, I'd recommend using Coder100's answer, and using a parsing/lexing library instead of RegEx. You don't have to reinvent the wheel and parse by hand (it may even slow you down in fact), but ECMAScript RegEx won't help, recursive RegEx would be better, ex: PCRE syntax, but JS doesn't have anything else.

Just try to get a better parser that can stop when something isn't correct, so you can handle it yourself, or throw an error and abort the program.

charliecoates46
xxpertHacker

@charliecoates46 Do you have the wrong person?