Skip to content Skip to sidebar Skip to footer

How To Make "print" Statement To Print Multiple Strings Javascript?

I am trying to make a small interpreter for print statement. Here is a demo of what I have done till now: DEMO What I want to reach now is to print multiple string connected with

Solution 1:

Building interpreters with only regexes is between difficult and impossible. You might rather tokenize your input (e.g. split at white spaces + before/after some selected special characters) and then detect and handle each token individually.

If you want to go more complex you should of course define a grammar for your language and match that using a library like PEG.js as @peter-schneider pointed out.

You should be able to detect string literals quite easily by whether the token starts with a " or ':

if (token[0] == '"' || token[1] == '\'') { /* ... */ }

Post a Comment for "How To Make "print" Statement To Print Multiple Strings Javascript?"