Ask coding questions

← Back to all posts
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!

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
asdfasdfa123123
xtdpoittc
anpbtq
cbccyl
fawq123
nanec
AjkBot
Deepjk
JackWinton
Comments
hotnewtop
Coder100

Would you like to see the tutorial I used to learn to program the language?
https://craftinginterpreters.com
it is only slightly biased towards the fact that it is a class-based language, but it should be a very good start.

[deleted]

Thank you all for your helpful comments. I realize I wasn't asking the right question. As I stated, I created this using Regex's that transpiled it to JavaScript but I would like to add my own errors for this language because at the time it is not really showing them. Here is a picture of what I mean:


Coder100

oh, well ideally you should catch those errors yourself. You would need some way to actually know what that string was, and you would do that by actually parsing through the text. RegEx can only go so far when making a language. @AJK4

[deleted]

Okay, now I understand. @Coder100

Coder100

nice! @AJK4

programmeruser

@Coder100 I just read the source code of cookeylang lol
(it's really just a implementation of the principles in Crafting Interpreters)

Coder100

lol yeah it is
when you use a tutorial your code usually is based on the logic of the tutorial @programmeruser

darkdarcool

lol yeah I can help

xxpertHacker

@CoderCactus Hey, can you check this out?

This post is being bot upvoted by new, 0 cycle accounts.

@AjkBot
@Deepjk
@AJK14
@AJK4
^ Obvious examples

I think just reading the names of these accounts is enough to show that these are bots, especially considering how the last two are similiar in more than just username.

I was going to report this, but the report box has a size limit of 0xFF chars :/

[deleted]

Those have been there before I got warned by a Moderator. Once I got warned I stopped doing it. @xxpertHacker

xxpertHacker

@AJK4 Oh, maybe that was a useless ping then

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?

RYANTADIPARTHI

wdym by real language? Do you mean host it on the web or something?

19wintersp

I'm not sure what you mean by a "real" language; a transpiled language is still a language (think of TypeScript, for example). If you want to create a language which compiles to binaries, look into the LLVM.

xxpertHacker

@19wintersp Oh nice, use RegEx to parse text into LLVM code, then compile to native machine binary. Smart.