Syntax / Boolean Validation In Javascript?

I am creating a client solution that allows them to create very simple code, now I have done some basic syntax checks, but I am stuck in the check variable.

I know that JSLint does this using Javascript, and I was wondering if anyone knew of a good way to do this.

So, for example, let's say the user wrote the code

moose = "barry"
base = 0
if(moose == "barry"){base += 100}

Then I try to find a way to clarify that the if statement is in the correct syntax if the moose variable was initialized, etc. etc. but I want to do this without scanning the character by character, the code is a mini-language created only for this application, so it is very simple and does not need memory management or something like that.

I thought about arranging Carriage Return and then Space first, but there is nothing to say that the user will not write something like moose="barry"or if(moose=="barry") nothing to say that the user will not save the result of the inline condition.

Obviously, compilers and interpreters do this on a much broader scale, but I'm not sure if they do it by nature, and if they do, how are they optimized?

(Another option - I can send it back to PHP for processing, which would then cancel the browser liability)

Any suggestions?

thank

, , - , , , , PHP , , .

, , , 1,00 " ", " ".

So

base = 1;
if(additional > 100 && additional < 150){base += 50}
elseif(additional == 150){base *= 150}
else{base += additional;}

.


, , , 1000 , , P4 512 ( , )

PHP- , .. PHP-, ( ), javascript. ,

, , if if, , , ,

,

+3
3

— , , , " " — . . , , , , .

" ", , , - .

, JavaScript. , , ( ).

+4

JS/CC, , Javascript. , BNF EBNF. , JS/CC ( BNF/EBNF) . , JS/CC .

, , - . BNF/EBNF, . EBNF Javascript ( , YMMV).

, "". . , , .

if-elses . , . , - . , . , if-elses, ( , ). .

, 10- , . , , . , . , , , , ( ) . - (.. , ), , . .

+2

Javascript 'eval'.

var code = 'alert(1);';
eval(code);

. "eval" .

+1

Source: https://habr.com/ru/post/1782314/


All Articles