When parsing Javascript, what determines the meaning of a slash?

后端 未结 5 1411
清歌不尽
清歌不尽 2020-12-01 07:43

Javascript has a tricky grammar to parse. Forward-slashes can mean a number of different things: division operator, regular expression literal, comment introducer, or line-

5条回答
  •  囚心锁ツ
    2020-12-01 08:23

    You can only know how to interpret the / by also implementing a syntax parser. Whichever lex path arrives at a valid parse determines how to interpret the character. Apparently, this is something they had considered fixing, but didn't. More reading here: http://www-archive.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions

提交回复
热议问题