PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/opensource.apple.com/source/JavaScriptCore/JavaScriptCore-4523.12/kjs/grammar.y

#
Happy | 1041 lines | 890 code | 151 blank | 0 comment | 0 complexity | 64ee17eccb25848b1ea432e46f262375 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>grammar.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">grammar.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. %{
  24. /*
  25. * This file is part of the KDE libraries
  26. * Copyright (C) 1999-2000 Harri Porten (<a href="mailto:porten@kde.org">porten@kde.org</a>)
  27. * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
  28. *
  29. * This library is free software; you can redistribute it and/or
  30. * modify it under the terms of the GNU Lesser General Public
  31. * License as published by the Free Software Foundation; either
  32. * version 2 of the License, or (at your option) any later version.
  33. *
  34. * This library is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. * Lesser General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU Lesser General Public
  40. * License along with this library; if not, write to the Free Software
  41. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  42. *
  43. */
  44. #include &quot;config.h&quot;
  45. #include &lt;string.h&gt;
  46. #include &lt;stdlib.h&gt;
  47. #include &quot;value.h&quot;
  48. #include &quot;object.h&quot;
  49. #include &quot;types.h&quot;
  50. #include &quot;interpreter.h&quot;
  51. #include &quot;nodes.h&quot;
  52. #include &quot;lexer.h&quot;
  53. #include &quot;internal.h&quot;
  54. #include &quot;CommonIdentifiers.h&quot;
  55. // Not sure why, but yacc doesn't add this define along with the others.
  56. #define yylloc kjsyylloc
  57. #define YYMAXDEPTH 10000
  58. #define YYENABLE_NLS 0
  59. /* default values for bison */
  60. #define YYDEBUG 0
  61. #if !PLATFORM(DARWIN)
  62. // avoid triggering warnings in older bison
  63. #define YYERROR_VERBOSE
  64. #endif
  65. extern int kjsyylex();
  66. int kjsyyerror(const char *);
  67. static bool allowAutomaticSemicolon();
  68. #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon()) YYABORT; } while (0)
  69. #define DBG(l, s, e) (l)-&gt;setLoc((s).first_line, (e).last_line)
  70. using namespace KJS;
  71. static Node* makeAssignNode(Node* loc, Operator, Node* expr);
  72. static Node* makePrefixNode(Node* expr, Operator);
  73. static Node* makePostfixNode(Node* expr, Operator);
  74. static bool makeGetterOrSetterPropertyNode(PropertyNode*&amp; result, Identifier &amp;getOrSet, Identifier&amp; name, ParameterNode *params, FunctionBodyNode *body);
  75. static Node *makeFunctionCallNode(Node *func, ArgumentsNode *args);
  76. static Node *makeTypeOfNode(Node *expr);
  77. static Node *makeDeleteNode(Node *expr);
  78. #if COMPILER(MSVC)
  79. #pragma warning(disable: 4065)
  80. #pragma warning(disable: 4244)
  81. #pragma warning(disable: 4702)
  82. // At least some of the time, the declarations of malloc and free that bison
  83. // generates are causing warnings. A way to avoid this is to explicitly define
  84. // the macros so that bison doesn't try to declare malloc and free.
  85. #define YYMALLOC malloc
  86. #define YYFREE free
  87. #endif
  88. %}
  89. %union {
  90. int ival;
  91. double dval;
  92. UString *ustr;
  93. Identifier *ident;
  94. Node *node;
  95. StatementNode *stat;
  96. ParameterNode *param;
  97. FunctionBodyNode *body;
  98. FuncDeclNode *func;
  99. FuncExprNode *funcExpr;
  100. ProgramNode *prog;
  101. AssignExprNode *init;
  102. SourceElementsNode *srcs;
  103. ArgumentsNode *args;
  104. ArgumentListNode *alist;
  105. VarDeclNode *decl;
  106. VarDeclListNode *vlist;
  107. CaseBlockNode *cblk;
  108. ClauseListNode *clist;
  109. CaseClauseNode *ccl;
  110. ElementNode *elm;
  111. Operator op;
  112. PropertyListNode *plist;
  113. PropertyNode *pnode;
  114. PropertyNameNode *pname;
  115. }
  116. %start Program
  117. /* literals */
  118. %token NULLTOKEN TRUETOKEN FALSETOKEN
  119. /* keywords */
  120. %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE
  121. %token FUNCTION RETURN VOIDTOKEN DELETETOKEN
  122. %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
  123. %token SWITCH WITH RESERVED
  124. %token THROW TRY CATCH FINALLY
  125. %token DEBUGGER
  126. /* give an if without an else higher precedence than an else to resolve the ambiguity */
  127. %nonassoc IF_WITHOUT_ELSE
  128. %nonassoc ELSE
  129. /* punctuators */
  130. %token EQEQ NE /* == and != */
  131. %token STREQ STRNEQ /* === and !== */
  132. %token LE GE /* &lt; and &gt; */
  133. %token OR AND /* || and &amp;&amp; */
  134. %token PLUSPLUS MINUSMINUS /* ++ and -- */
  135. %token LSHIFT /* &lt;&lt; */
  136. %token RSHIFT URSHIFT /* &gt;&gt; and &gt;&gt;&gt; */
  137. %token PLUSEQUAL MINUSEQUAL /* += and -= */
  138. %token MULTEQUAL DIVEQUAL /* *= and /= */
  139. %token LSHIFTEQUAL /* &lt;&lt;= */
  140. %token RSHIFTEQUAL URSHIFTEQUAL /* &gt;&gt;= and &gt;&gt;&gt;= */
  141. %token ANDEQUAL MODEQUAL /* &amp;= and %= */
  142. %token XOREQUAL OREQUAL /* ^= and |= */
  143. /* terminal types */
  144. %token &lt;dval&gt; NUMBER
  145. %token &lt;ustr&gt; STRING
  146. %token &lt;ident&gt; IDENT
  147. /* automatically inserted semicolon */
  148. %token AUTOPLUSPLUS AUTOMINUSMINUS
  149. /* non-terminal types */
  150. %type &lt;node&gt; Literal ArrayLiteral
  151. %type &lt;node&gt; PrimaryExpr PrimaryExprNoBrace
  152. %type &lt;node&gt; MemberExpr MemberExprNoBF /* BF =&gt; brace or function */
  153. %type &lt;node&gt; NewExpr NewExprNoBF
  154. %type &lt;node&gt; CallExpr CallExprNoBF
  155. %type &lt;node&gt; LeftHandSideExpr LeftHandSideExprNoBF
  156. %type &lt;node&gt; PostfixExpr PostfixExprNoBF
  157. %type &lt;node&gt; UnaryExpr UnaryExprNoBF UnaryExprCommon
  158. %type &lt;node&gt; MultiplicativeExpr MultiplicativeExprNoBF
  159. %type &lt;node&gt; AdditiveExpr AdditiveExprNoBF
  160. %type &lt;node&gt; ShiftExpr ShiftExprNoBF
  161. %type &lt;node&gt; RelationalExpr RelationalExprNoIn RelationalExprNoBF
  162. %type &lt;node&gt; EqualityExpr EqualityExprNoIn EqualityExprNoBF
  163. %type &lt;node&gt; BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF
  164. %type &lt;node&gt; BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF
  165. %type &lt;node&gt; BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF
  166. %type &lt;node&gt; LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF
  167. %type &lt;node&gt; LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF
  168. %type &lt;node&gt; ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF
  169. %type &lt;node&gt; AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF
  170. %type &lt;node&gt; Expr ExprNoIn ExprNoBF
  171. %type &lt;node&gt; ExprOpt ExprNoInOpt
  172. %type &lt;stat&gt; Statement Block
  173. %type &lt;stat&gt; VariableStatement ConstStatement EmptyStatement ExprStatement
  174. %type &lt;stat&gt; IfStatement IterationStatement ContinueStatement
  175. %type &lt;stat&gt; BreakStatement ReturnStatement WithStatement
  176. %type &lt;stat&gt; SwitchStatement LabelledStatement
  177. %type &lt;stat&gt; ThrowStatement TryStatement
  178. %type &lt;stat&gt; DebuggerStatement
  179. %type &lt;stat&gt; SourceElement
  180. %type &lt;init&gt; Initializer InitializerNoIn
  181. %type &lt;func&gt; FunctionDeclaration
  182. %type &lt;funcExpr&gt; FunctionExpr
  183. %type &lt;body&gt; FunctionBody
  184. %type &lt;srcs&gt; SourceElements
  185. %type &lt;param&gt; FormalParameterList
  186. %type &lt;op&gt; AssignmentOperator
  187. %type &lt;args&gt; Arguments
  188. %type &lt;alist&gt; ArgumentList
  189. %type &lt;vlist&gt; VariableDeclarationList VariableDeclarationListNoIn ConstDeclarationList
  190. %type &lt;decl&gt; VariableDeclaration VariableDeclarationNoIn ConstDeclaration
  191. %type &lt;cblk&gt; CaseBlock
  192. %type &lt;ccl&gt; CaseClause DefaultClause
  193. %type &lt;clist&gt; CaseClauses CaseClausesOpt
  194. %type &lt;ival&gt; Elision ElisionOpt
  195. %type &lt;elm&gt; ElementList
  196. %type &lt;pname&gt; PropertyName
  197. %type &lt;pnode&gt; Property
  198. %type &lt;plist&gt; PropertyList
  199. %%
  200. Literal:
  201. NULLTOKEN { $$ = new NullNode(); }
  202. | TRUETOKEN { $$ = new BooleanNode(true); }
  203. | FALSETOKEN { $$ = new BooleanNode(false); }
  204. | NUMBER { $$ = new NumberNode($1); }
  205. | STRING { $$ = new StringNode($1); }
  206. | '/' /* regexp */ {
  207. Lexer *l = Lexer::curr();
  208. if (!l-&gt;scanRegExp()) YYABORT;
  209. $$ = new RegExpNode(l-&gt;pattern, l-&gt;flags);
  210. }
  211. | DIVEQUAL /* regexp with /= */ {
  212. Lexer *l = Lexer::curr();
  213. if (!l-&gt;scanRegExp()) YYABORT;
  214. $$ = new RegExpNode(&quot;=&quot; + l-&gt;pattern, l-&gt;flags);
  215. }
  216. ;
  217. PropertyName:
  218. IDENT { $$ = new PropertyNameNode(*$1); }
  219. | STRING { $$ = new PropertyNameNode(Identifier(*$1)); }
  220. | NUMBER { $$ = new PropertyNameNode($1); }
  221. ;
  222. Property:
  223. PropertyName ':' AssignmentExpr { $$ = new PropertyNode($1, $3, PropertyNode::Constant); }
  224. | IDENT IDENT '(' ')' FunctionBody { if (!makeGetterOrSetterPropertyNode($$, *$1, *$2, 0, $5)) YYABORT; }
  225. | IDENT IDENT '(' FormalParameterList ')' FunctionBody
  226. { if (!makeGetterOrSetterPropertyNode($$, *$1, *$2, $4, $6)) YYABORT; }
  227. ;
  228. PropertyList:
  229. Property { $$ = new PropertyListNode($1); }
  230. | PropertyList ',' Property { $$ = new PropertyListNode($3, $1); }
  231. ;
  232. PrimaryExpr:
  233. PrimaryExprNoBrace
  234. | '{' '}' { $$ = new ObjectLiteralNode(); }
  235. | '{' PropertyList '}' { $$ = new ObjectLiteralNode($2); }
  236. /* allow extra comma, see <a href="http://bugs.webkit.org/show_bug.cgi?id=5939">http://bugs.webkit.org/show_bug.cgi?id=5939</a> */
  237. | '{' PropertyList ',' '}' { $$ = new ObjectLiteralNode($2); }
  238. ;
  239. PrimaryExprNoBrace:
  240. THISTOKEN { $$ = new ThisNode(); }
  241. | Literal
  242. | ArrayLiteral
  243. | IDENT { $$ = new ResolveNode(*$1); }
  244. | '(' Expr ')' { $$ = ($2-&gt;isResolveNode() || $2-&gt;isGroupNode()) ?
  245. $2 : new GroupNode($2); }
  246. ;
  247. ArrayLiteral:
  248. '[' ElisionOpt ']' { $$ = new ArrayNode($2); }
  249. | '[' ElementList ']' { $$ = new ArrayNode($2); }
  250. | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2); }
  251. ;
  252. ElementList:
  253. ElisionOpt AssignmentExpr { $$ = new ElementNode($1, $2); }
  254. | ElementList ',' ElisionOpt AssignmentExpr
  255. { $$ = new ElementNode($1, $3, $4); }
  256. ;
  257. ElisionOpt:
  258. /* nothing */ { $$ = 0; }
  259. | Elision
  260. ;
  261. Elision:
  262. ',' { $$ = 1; }
  263. | Elision ',' { $$ = $1 + 1; }
  264. ;
  265. MemberExpr:
  266. PrimaryExpr
  267. | FunctionExpr { $$ = $1; }
  268. | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
  269. | MemberExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
  270. | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
  271. ;
  272. MemberExprNoBF:
  273. PrimaryExprNoBrace
  274. | MemberExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
  275. | MemberExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
  276. | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
  277. ;
  278. NewExpr:
  279. MemberExpr
  280. | NEW NewExpr { $$ = new NewExprNode($2); }
  281. ;
  282. NewExprNoBF:
  283. MemberExprNoBF
  284. | NEW NewExpr { $$ = new NewExprNode($2); }
  285. ;
  286. CallExpr:
  287. MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
  288. | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
  289. | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
  290. | CallExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
  291. ;
  292. CallExprNoBF:
  293. MemberExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
  294. | CallExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
  295. | CallExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
  296. | CallExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
  297. ;
  298. Arguments:
  299. '(' ')' { $$ = new ArgumentsNode(); }
  300. | '(' ArgumentList ')' { $$ = new ArgumentsNode($2); }
  301. ;
  302. ArgumentList:
  303. AssignmentExpr { $$ = new ArgumentListNode($1); }
  304. | ArgumentList ',' AssignmentExpr { $$ = new ArgumentListNode($1, $3); }
  305. ;
  306. LeftHandSideExpr:
  307. NewExpr
  308. | CallExpr
  309. ;
  310. LeftHandSideExprNoBF:
  311. NewExprNoBF
  312. | CallExprNoBF
  313. ;
  314. PostfixExpr:
  315. LeftHandSideExpr
  316. | LeftHandSideExpr PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
  317. | LeftHandSideExpr MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
  318. ;
  319. PostfixExprNoBF:
  320. LeftHandSideExprNoBF
  321. | LeftHandSideExprNoBF PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
  322. | LeftHandSideExprNoBF MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
  323. ;
  324. UnaryExprCommon:
  325. DELETETOKEN UnaryExpr { $$ = makeDeleteNode($2); }
  326. | VOIDTOKEN UnaryExpr { $$ = new VoidNode($2); }
  327. | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); }
  328. | PLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
  329. | AUTOPLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
  330. | MINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
  331. | AUTOMINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
  332. | '+' UnaryExpr { $$ = new UnaryPlusNode($2); }
  333. | '-' UnaryExpr { $$ = new NegateNode($2); }
  334. | '~' UnaryExpr { $$ = new BitwiseNotNode($2); }
  335. | '!' UnaryExpr { $$ = new LogicalNotNode($2); }
  336. UnaryExpr:
  337. PostfixExpr
  338. | UnaryExprCommon
  339. ;
  340. UnaryExprNoBF:
  341. PostfixExprNoBF
  342. | UnaryExprCommon
  343. ;
  344. MultiplicativeExpr:
  345. UnaryExpr
  346. | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3, '*'); }
  347. | MultiplicativeExpr '/' UnaryExpr { $$ = new MultNode($1, $3, '/'); }
  348. | MultiplicativeExpr '%' UnaryExpr { $$ = new MultNode($1, $3,'%'); }
  349. ;
  350. MultiplicativeExprNoBF:
  351. UnaryExprNoBF
  352. | MultiplicativeExprNoBF '*' UnaryExpr
  353. { $$ = new MultNode($1, $3, '*'); }
  354. | MultiplicativeExprNoBF '/' UnaryExpr
  355. { $$ = new MultNode($1, $3, '/'); }
  356. | MultiplicativeExprNoBF '%' UnaryExpr
  357. { $$ = new MultNode($1, $3,'%'); }
  358. ;
  359. AdditiveExpr:
  360. MultiplicativeExpr
  361. | AdditiveExpr '+' MultiplicativeExpr { $$ = new AddNode($1, $3, '+'); }
  362. | AdditiveExpr '-' MultiplicativeExpr { $$ = new AddNode($1, $3, '-'); }
  363. ;
  364. AdditiveExprNoBF:
  365. MultiplicativeExprNoBF
  366. | AdditiveExprNoBF '+' MultiplicativeExpr
  367. { $$ = new AddNode($1, $3, '+'); }
  368. | AdditiveExprNoBF '-' MultiplicativeExpr
  369. { $$ = new AddNode($1, $3, '-'); }
  370. ;
  371. ShiftExpr:
  372. AdditiveExpr
  373. | ShiftExpr LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); }
  374. | ShiftExpr RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); }
  375. | ShiftExpr URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); }
  376. ;
  377. ShiftExprNoBF:
  378. AdditiveExprNoBF
  379. | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); }
  380. | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); }
  381. | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); }
  382. ;
  383. RelationalExpr:
  384. ShiftExpr
  385. | RelationalExpr '&lt;' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); }
  386. | RelationalExpr '&gt;' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); }
  387. | RelationalExpr LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); }
  388. | RelationalExpr GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); }
  389. | RelationalExpr INSTANCEOF ShiftExpr { $$ = new RelationalNode($1, OpInstanceOf, $3); }
  390. | RelationalExpr INTOKEN ShiftExpr { $$ = new RelationalNode($1, OpIn, $3); }
  391. ;
  392. RelationalExprNoIn:
  393. ShiftExpr
  394. | RelationalExprNoIn '&lt;' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); }
  395. | RelationalExprNoIn '&gt;' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); }
  396. | RelationalExprNoIn LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); }
  397. | RelationalExprNoIn GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); }
  398. | RelationalExprNoIn INSTANCEOF ShiftExpr
  399. { $$ = new RelationalNode($1, OpInstanceOf, $3); }
  400. ;
  401. RelationalExprNoBF:
  402. ShiftExprNoBF
  403. | RelationalExprNoBF '&lt;' ShiftExpr { $$ = new RelationalNode($1, OpLess, $3); }
  404. | RelationalExprNoBF '&gt;' ShiftExpr { $$ = new RelationalNode($1, OpGreater, $3); }
  405. | RelationalExprNoBF LE ShiftExpr { $$ = new RelationalNode($1, OpLessEq, $3); }
  406. | RelationalExprNoBF GE ShiftExpr { $$ = new RelationalNode($1, OpGreaterEq, $3); }
  407. | RelationalExprNoBF INSTANCEOF ShiftExpr
  408. { $$ = new RelationalNode($1, OpInstanceOf, $3); }
  409. | RelationalExprNoBF INTOKEN ShiftExpr { $$ = new RelationalNode($1, OpIn, $3); }
  410. ;
  411. EqualityExpr:
  412. RelationalExpr
  413. | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, OpEqEq, $3); }
  414. | EqualityExpr NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); }
  415. | EqualityExpr STREQ RelationalExpr { $$ = new EqualNode($1, OpStrEq, $3); }
  416. | EqualityExpr STRNEQ RelationalExpr { $$ = new EqualNode($1, OpStrNEq, $3);}
  417. ;
  418. EqualityExprNoIn:
  419. RelationalExprNoIn
  420. | EqualityExprNoIn EQEQ RelationalExprNoIn
  421. { $$ = new EqualNode($1, OpEqEq, $3); }
  422. | EqualityExprNoIn NE RelationalExprNoIn
  423. { $$ = new EqualNode($1, OpNotEq, $3); }
  424. | EqualityExprNoIn STREQ RelationalExprNoIn
  425. { $$ = new EqualNode($1, OpStrEq, $3); }
  426. | EqualityExprNoIn STRNEQ RelationalExprNoIn
  427. { $$ = new EqualNode($1, OpStrNEq, $3);}
  428. ;
  429. EqualityExprNoBF:
  430. RelationalExprNoBF
  431. | EqualityExprNoBF EQEQ RelationalExpr
  432. { $$ = new EqualNode($1, OpEqEq, $3); }
  433. | EqualityExprNoBF NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); }
  434. | EqualityExprNoBF STREQ RelationalExpr
  435. { $$ = new EqualNode($1, OpStrEq, $3); }
  436. | EqualityExprNoBF STRNEQ RelationalExpr
  437. { $$ = new EqualNode($1, OpStrNEq, $3);}
  438. ;
  439. BitwiseANDExpr:
  440. EqualityExpr
  441. | BitwiseANDExpr '&amp;' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); }
  442. ;
  443. BitwiseANDExprNoIn:
  444. EqualityExprNoIn
  445. | BitwiseANDExprNoIn '&amp;' EqualityExprNoIn
  446. { $$ = new BitOperNode($1, OpBitAnd, $3); }
  447. ;
  448. BitwiseANDExprNoBF:
  449. EqualityExprNoBF
  450. | BitwiseANDExprNoBF '&amp;' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); }
  451. ;
  452. BitwiseXORExpr:
  453. BitwiseANDExpr
  454. | BitwiseXORExpr '^' BitwiseANDExpr { $$ = new BitOperNode($1, OpBitXOr, $3); }
  455. ;
  456. BitwiseXORExprNoIn:
  457. BitwiseANDExprNoIn
  458. | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn
  459. { $$ = new BitOperNode($1, OpBitXOr, $3); }
  460. ;
  461. BitwiseXORExprNoBF:
  462. BitwiseANDExprNoBF
  463. | BitwiseXORExprNoBF '^' BitwiseANDExpr
  464. { $$ = new BitOperNode($1, OpBitXOr, $3); }
  465. ;
  466. BitwiseORExpr:
  467. BitwiseXORExpr
  468. | BitwiseORExpr '|' BitwiseXORExpr { $$ = new BitOperNode($1, OpBitOr, $3); }
  469. ;
  470. BitwiseORExprNoIn:
  471. BitwiseXORExprNoIn
  472. | BitwiseORExprNoIn '|' BitwiseXORExprNoIn
  473. { $$ = new BitOperNode($1, OpBitOr, $3); }
  474. ;
  475. BitwiseORExprNoBF:
  476. BitwiseXORExprNoBF
  477. | BitwiseORExprNoBF '|' BitwiseXORExpr
  478. { $$ = new BitOperNode($1, OpBitOr, $3); }
  479. ;
  480. LogicalANDExpr:
  481. BitwiseORExpr
  482. | LogicalANDExpr AND BitwiseORExpr { $$ = new BinaryLogicalNode($1, OpAnd, $3); }
  483. ;
  484. LogicalANDExprNoIn:
  485. BitwiseORExprNoIn
  486. | LogicalANDExprNoIn AND BitwiseORExprNoIn
  487. { $$ = new BinaryLogicalNode($1, OpAnd, $3); }
  488. ;
  489. LogicalANDExprNoBF:
  490. BitwiseORExprNoBF
  491. | LogicalANDExprNoBF AND BitwiseORExpr
  492. { $$ = new BinaryLogicalNode($1, OpAnd, $3); }
  493. ;
  494. LogicalORExpr:
  495. LogicalANDExpr
  496. | LogicalORExpr OR LogicalANDExpr { $$ = new BinaryLogicalNode($1, OpOr, $3); }
  497. ;
  498. LogicalORExprNoIn:
  499. LogicalANDExprNoIn
  500. | LogicalORExprNoIn OR LogicalANDExprNoIn
  501. { $$ = new BinaryLogicalNode($1, OpOr, $3); }
  502. ;
  503. LogicalORExprNoBF:
  504. LogicalANDExprNoBF
  505. | LogicalORExprNoBF OR LogicalANDExpr { $$ = new BinaryLogicalNode($1, OpOr, $3); }
  506. ;
  507. ConditionalExpr:
  508. LogicalORExpr
  509. | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
  510. { $$ = new ConditionalNode($1, $3, $5); }
  511. ;
  512. ConditionalExprNoIn:
  513. LogicalORExprNoIn
  514. | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn
  515. { $$ = new ConditionalNode($1, $3, $5); }
  516. ;
  517. ConditionalExprNoBF:
  518. LogicalORExprNoBF
  519. | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr
  520. { $$ = new ConditionalNode($1, $3, $5); }
  521. ;
  522. AssignmentExpr:
  523. ConditionalExpr
  524. | LeftHandSideExpr AssignmentOperator AssignmentExpr
  525. { $$ = makeAssignNode($1, $2, $3); }
  526. ;
  527. AssignmentExprNoIn:
  528. ConditionalExprNoIn
  529. | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn
  530. { $$ = makeAssignNode($1, $2, $3); }
  531. ;
  532. AssignmentExprNoBF:
  533. ConditionalExprNoBF
  534. | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr
  535. { $$ = makeAssignNode($1, $2, $3); }
  536. ;
  537. AssignmentOperator:
  538. '=' { $$ = OpEqual; }
  539. | PLUSEQUAL { $$ = OpPlusEq; }
  540. | MINUSEQUAL { $$ = OpMinusEq; }
  541. | MULTEQUAL { $$ = OpMultEq; }
  542. | DIVEQUAL { $$ = OpDivEq; }
  543. | LSHIFTEQUAL { $$ = OpLShift; }
  544. | RSHIFTEQUAL { $$ = OpRShift; }
  545. | URSHIFTEQUAL { $$ = OpURShift; }
  546. | ANDEQUAL { $$ = OpAndEq; }
  547. | XOREQUAL { $$ = OpXOrEq; }
  548. | OREQUAL { $$ = OpOrEq; }
  549. | MODEQUAL { $$ = OpModEq; }
  550. ;
  551. Expr:
  552. AssignmentExpr
  553. | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
  554. ;
  555. ExprNoIn:
  556. AssignmentExprNoIn
  557. | ExprNoIn ',' AssignmentExprNoIn { $$ = new CommaNode($1, $3); }
  558. ;
  559. ExprNoBF:
  560. AssignmentExprNoBF
  561. | ExprNoBF ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
  562. ;
  563. Statement:
  564. Block
  565. | VariableStatement
  566. | ConstStatement
  567. | EmptyStatement
  568. | ExprStatement
  569. | IfStatement
  570. | IterationStatement
  571. | ContinueStatement
  572. | BreakStatement
  573. | ReturnStatement
  574. | WithStatement
  575. | SwitchStatement
  576. | LabelledStatement
  577. | ThrowStatement
  578. | TryStatement
  579. | DebuggerStatement
  580. ;
  581. Block:
  582. '{' '}' { $$ = new BlockNode(0); DBG($$, @2, @2); }
  583. | '{' SourceElements '}' { $$ = new BlockNode($2); DBG($$, @3, @3); }
  584. ;
  585. VariableStatement:
  586. VAR VariableDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); }
  587. | VAR VariableDeclarationList error { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  588. ;
  589. VariableDeclarationList:
  590. VariableDeclaration { $$ = new VarDeclListNode($1); }
  591. | VariableDeclarationList ',' VariableDeclaration
  592. { $$ = new VarDeclListNode($1, $3); }
  593. ;
  594. VariableDeclarationListNoIn:
  595. VariableDeclarationNoIn { $$ = new VarDeclListNode($1); }
  596. | VariableDeclarationListNoIn ',' VariableDeclarationNoIn
  597. { $$ = new VarDeclListNode($1, $3); }
  598. ;
  599. VariableDeclaration:
  600. IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Variable); }
  601. | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); }
  602. ;
  603. VariableDeclarationNoIn:
  604. IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Variable); }
  605. | IDENT InitializerNoIn { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); }
  606. ;
  607. ConstStatement:
  608. CONSTTOKEN ConstDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); }
  609. | CONSTTOKEN ConstDeclarationList error
  610. { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  611. ;
  612. ConstDeclarationList:
  613. ConstDeclaration { $$ = new VarDeclListNode($1); }
  614. | ConstDeclarationList ',' ConstDeclaration
  615. { $$ = new VarDeclListNode($1, $3); }
  616. ;
  617. ConstDeclaration:
  618. IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Constant); }
  619. | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Constant); }
  620. ;
  621. Initializer:
  622. '=' AssignmentExpr { $$ = new AssignExprNode($2); }
  623. ;
  624. InitializerNoIn:
  625. '=' AssignmentExprNoIn { $$ = new AssignExprNode($2); }
  626. ;
  627. EmptyStatement:
  628. ';' { $$ = new EmptyStatementNode(); }
  629. ;
  630. ExprStatement:
  631. ExprNoBF ';' { $$ = new ExprStatementNode($1); DBG($$, @1, @2); }
  632. | ExprNoBF error { $$ = new ExprStatementNode($1); DBG($$, @1, @1); AUTO_SEMICOLON; }
  633. ;
  634. IfStatement:
  635. IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
  636. { $$ = new IfNode($3, $5, 0); DBG($$, @1, @4); }
  637. | IF '(' Expr ')' Statement ELSE Statement
  638. { $$ = new IfNode($3, $5, $7); DBG($$, @1, @4); }
  639. ;
  640. IterationStatement:
  641. DO Statement WHILE '(' Expr ')' ';' { $$ = new DoWhileNode($2, $5); DBG($$, @1, @3);}
  642. | DO Statement WHILE '(' Expr ')' { $$ = new DoWhileNode($2, $5); DBG($$, @1, @3);}
  643. | WHILE '(' Expr ')' Statement { $$ = new WhileNode($3, $5); DBG($$, @1, @4); }
  644. | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement
  645. { $$ = new ForNode($3, $5, $7, $9); DBG($$, @1, @8); }
  646. | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
  647. { $$ = new ForNode($4, $6, $8, $10); DBG($$, @1, @9); }
  648. | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
  649. {
  650. Node *n = $3-&gt;nodeInsideAllParens();
  651. if (!n-&gt;isLocation())
  652. YYABORT;
  653. $$ = new ForInNode(n, $5, $7);
  654. DBG($$, @1, @6);
  655. }
  656. | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
  657. { $$ = new ForInNode(*$4, 0, $6, $8); DBG($$, @1, @7); }
  658. | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
  659. { $$ = new ForInNode(*$4, $5, $7, $9); DBG($$, @1, @8); }
  660. ;
  661. ExprOpt:
  662. /* nothing */ { $$ = 0; }
  663. | Expr
  664. ;
  665. ExprNoInOpt:
  666. /* nothing */ { $$ = 0; }
  667. | ExprNoIn
  668. ;
  669. ContinueStatement:
  670. CONTINUE ';' { $$ = new ContinueNode(); DBG($$, @1, @2); }
  671. | CONTINUE error { $$ = new ContinueNode(); DBG($$, @1, @1); AUTO_SEMICOLON; }
  672. | CONTINUE IDENT ';' { $$ = new ContinueNode(*$2); DBG($$, @1, @3); }
  673. | CONTINUE IDENT error { $$ = new ContinueNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  674. ;
  675. BreakStatement:
  676. BREAK ';' { $$ = new BreakNode(); DBG($$, @1, @2); }
  677. | BREAK error { $$ = new BreakNode(); DBG($$, @1, @1); AUTO_SEMICOLON; }
  678. | BREAK IDENT ';' { $$ = new BreakNode(*$2); DBG($$, @1, @3); }
  679. | BREAK IDENT error { $$ = new BreakNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  680. ;
  681. ReturnStatement:
  682. RETURN ';' { $$ = new ReturnNode(0); DBG($$, @1, @2); }
  683. | RETURN error { $$ = new ReturnNode(0); DBG($$, @1, @1); AUTO_SEMICOLON; }
  684. | RETURN Expr ';' { $$ = new ReturnNode($2); DBG($$, @1, @3); }
  685. | RETURN Expr error { $$ = new ReturnNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  686. ;
  687. WithStatement:
  688. WITH '(' Expr ')' Statement { $$ = new WithNode($3, $5); DBG($$, @1, @4); }
  689. ;
  690. SwitchStatement:
  691. SWITCH '(' Expr ')' CaseBlock { $$ = new SwitchNode($3, $5); DBG($$, @1, @4); }
  692. ;
  693. CaseBlock:
  694. '{' CaseClausesOpt '}' { $$ = new CaseBlockNode($2, 0, 0); }
  695. | '{' CaseClausesOpt DefaultClause CaseClausesOpt '}'
  696. { $$ = new CaseBlockNode($2, $3, $4); }
  697. ;
  698. CaseClausesOpt:
  699. /* nothing */ { $$ = 0; }
  700. | CaseClauses
  701. ;
  702. CaseClauses:
  703. CaseClause { $$ = new ClauseListNode($1); }
  704. | CaseClauses CaseClause { $$ = new ClauseListNode($1, $2); }
  705. ;
  706. CaseClause:
  707. CASE Expr ':' { $$ = new CaseClauseNode($2); }
  708. | CASE Expr ':' SourceElements { $$ = new CaseClauseNode($2, $4); }
  709. ;
  710. DefaultClause:
  711. DEFAULT ':' { $$ = new CaseClauseNode(0); }
  712. | DEFAULT ':' SourceElements { $$ = new CaseClauseNode(0, $3); }
  713. ;
  714. LabelledStatement:
  715. IDENT ':' Statement { $3-&gt;pushLabel(*$1); $$ = new LabelNode(*$1, $3); }
  716. ;
  717. ThrowStatement:
  718. THROW Expr ';' { $$ = new ThrowNode($2); DBG($$, @1, @3); }
  719. | THROW Expr error { $$ = new ThrowNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; }
  720. ;
  721. TryStatement:
  722. TRY Block FINALLY Block { $$ = new TryNode($2, CommonIdentifiers::shared()-&gt;nullIdentifier, 0, $4); DBG($$, @1, @2); }
  723. | TRY Block CATCH '(' IDENT ')' Block { $$ = new TryNode($2, *$5, $7, 0); DBG($$, @1, @2); }
  724. | TRY Block CATCH '(' IDENT ')' Block FINALLY Block
  725. { $$ = new TryNode($2, *$5, $7, $9); DBG($$, @1, @2); }
  726. ;
  727. DebuggerStatement:
  728. DEBUGGER ';' { $$ = new EmptyStatementNode(); DBG($$, @1, @2); }
  729. | DEBUGGER error { $$ = new EmptyStatementNode(); DBG($$, @1, @1); AUTO_SEMICOLON; }
  730. ;
  731. FunctionDeclaration:
  732. FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode(*$2, $5); }
  733. | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
  734. { $$ = new FuncDeclNode(*$2, $4, $6); }
  735. ;
  736. FunctionExpr:
  737. FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(CommonIdentifiers::shared()-&gt;nullIdentifier, $4); }
  738. | FUNCTION '(' FormalParameterList ')' FunctionBody
  739. { $$ = new FuncExprNode(CommonIdentifiers::shared()-&gt;nullIdentifier, $5, $3); }
  740. | FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncExprNode(*$2, $5); }
  741. | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
  742. { $$ = new FuncExprNode(*$2, $6, $4); }
  743. ;
  744. FormalParameterList:
  745. IDENT { $$ = new ParameterNode(*$1); }
  746. | FormalParameterList ',' IDENT { $$ = new ParameterNode($1, *$3); }
  747. ;
  748. FunctionBody:
  749. '{' '}' /* not in spec */ { $$ = new FunctionBodyNode(0); DBG($$, @1, @2); }
  750. | '{' SourceElements '}' { $$ = new FunctionBodyNode($2); DBG($$, @1, @3); }
  751. ;
  752. Program:
  753. /* not in spec */ { Parser::accept(new ProgramNode(0)); }
  754. | SourceElements { Parser::accept(new ProgramNode($1)); }
  755. ;
  756. SourceElements:
  757. SourceElement { $$ = new SourceElementsNode($1); }
  758. | SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); }
  759. ;
  760. SourceElement:
  761. FunctionDeclaration { $$ = $1; }
  762. | Statement { $$ = $1; }
  763. ;
  764. %%
  765. static Node* makeAssignNode(Node* loc, Operator op, Node* expr)
  766. {
  767. Node *n = loc-&gt;nodeInsideAllParens();
  768. if (!n-&gt;isLocation())
  769. return new AssignErrorNode(loc, op, expr);
  770. if (n-&gt;isResolveNode()) {
  771. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  772. return new AssignResolveNode(resolve-&gt;identifier(), op, expr);
  773. }
  774. if (n-&gt;isBracketAccessorNode()) {
  775. BracketAccessorNode *bracket = static_cast&lt;BracketAccessorNode *&gt;(n);
  776. return new AssignBracketNode(bracket-&gt;base(), bracket-&gt;subscript(), op, expr);
  777. }
  778. assert(n-&gt;isDotAccessorNode());
  779. DotAccessorNode *dot = static_cast&lt;DotAccessorNode *&gt;(n);
  780. return new AssignDotNode(dot-&gt;base(), dot-&gt;identifier(), op, expr);
  781. }
  782. static Node* makePrefixNode(Node *expr, Operator op)
  783. {
  784. Node *n = expr-&gt;nodeInsideAllParens();
  785. if (!n-&gt;isLocation())
  786. return new PrefixErrorNode(expr, op);
  787. if (n-&gt;isResolveNode()) {
  788. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  789. return new PrefixResolveNode(resolve-&gt;identifier(), op);
  790. }
  791. if (n-&gt;isBracketAccessorNode()) {
  792. BracketAccessorNode *bracket = static_cast&lt;BracketAccessorNode *&gt;(n);
  793. return new PrefixBracketNode(bracket-&gt;base(), bracket-&gt;subscript(), op);
  794. }
  795. assert(n-&gt;isDotAccessorNode());
  796. DotAccessorNode *dot = static_cast&lt;DotAccessorNode *&gt;(n);
  797. return new PrefixDotNode(dot-&gt;base(), dot-&gt;identifier(), op);
  798. }
  799. static Node* makePostfixNode(Node* expr, Operator op)
  800. {
  801. Node *n = expr-&gt;nodeInsideAllParens();
  802. if (!n-&gt;isLocation())
  803. return new PostfixErrorNode(expr, op);
  804. if (n-&gt;isResolveNode()) {
  805. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  806. return new PostfixResolveNode(resolve-&gt;identifier(), op);
  807. }
  808. if (n-&gt;isBracketAccessorNode()) {
  809. BracketAccessorNode *bracket = static_cast&lt;BracketAccessorNode *&gt;(n);
  810. return new PostfixBracketNode(bracket-&gt;base(), bracket-&gt;subscript(), op);
  811. }
  812. assert(n-&gt;isDotAccessorNode());
  813. DotAccessorNode *dot = static_cast&lt;DotAccessorNode *&gt;(n);
  814. return new PostfixDotNode(dot-&gt;base(), dot-&gt;identifier(), op);
  815. }
  816. static Node *makeFunctionCallNode(Node *func, ArgumentsNode *args)
  817. {
  818. Node *n = func-&gt;nodeInsideAllParens();
  819. if (!n-&gt;isLocation())
  820. return new FunctionCallValueNode(func, args);
  821. else if (n-&gt;isResolveNode()) {
  822. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  823. return new FunctionCallResolveNode(resolve-&gt;identifier(), args);
  824. } else if (n-&gt;isBracketAccessorNode()) {
  825. BracketAccessorNode *bracket = static_cast&lt;BracketAccessorNode *&gt;(n);
  826. if (n != func)
  827. return new FunctionCallParenBracketNode(bracket-&gt;base(), bracket-&gt;subscript(), args);
  828. else
  829. return new FunctionCallBracketNode(bracket-&gt;base(), bracket-&gt;subscript(), args);
  830. } else {
  831. assert(n-&gt;isDotAccessorNode());
  832. DotAccessorNode *dot = static_cast&lt;DotAccessorNode *&gt;(n);
  833. if (n != func)
  834. return new FunctionCallParenDotNode(dot-&gt;base(), dot-&gt;identifier(), args);
  835. else
  836. return new FunctionCallDotNode(dot-&gt;base(), dot-&gt;identifier(), args);
  837. }
  838. }
  839. static Node *makeTypeOfNode(Node *expr)
  840. {
  841. Node *n = expr-&gt;nodeInsideAllParens();
  842. if (n-&gt;isResolveNode()) {
  843. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  844. return new TypeOfResolveNode(resolve-&gt;identifier());
  845. } else
  846. return new TypeOfValueNode(expr);
  847. }
  848. static Node *makeDeleteNode(Node *expr)
  849. {
  850. Node *n = expr-&gt;nodeInsideAllParens();
  851. if (!n-&gt;isLocation())
  852. return new DeleteValueNode(expr);
  853. else if (n-&gt;isResolveNode()) {
  854. ResolveNode *resolve = static_cast&lt;ResolveNode *&gt;(n);
  855. return new DeleteResolveNode(resolve-&gt;identifier());
  856. } else if (n-&gt;isBracketAccessorNode()) {
  857. BracketAccessorNode *bracket = static_cast&lt;BracketAccessorNode *&gt;(n);
  858. return new DeleteBracketNode(bracket-&gt;base(), bracket-&gt;subscript());
  859. } else {
  860. assert(n-&gt;isDotAccessorNode());
  861. DotAccessorNode *dot = static_cast&lt;DotAccessorNode *&gt;(n);
  862. return new DeleteDotNode(dot-&gt;base(), dot-&gt;identifier());
  863. }
  864. }
  865. static bool makeGetterOrSetterPropertyNode(PropertyNode*&amp; result, Identifier&amp; getOrSet, Identifier&amp; name, ParameterNode *params, FunctionBodyNode *body)
  866. {
  867. PropertyNode::Type type;
  868. if (getOrSet == &quot;get&quot;)
  869. type = PropertyNode::Getter;
  870. else if (getOrSet == &quot;set&quot;)
  871. type = PropertyNode::Setter;
  872. else
  873. return false;
  874. result = new PropertyNode(new PropertyNameNode(name),
  875. new FuncExprNode(CommonIdentifiers::shared()-&gt;nullIdentifier, body, params), type);
  876. return true;
  877. }
  878. /* called by yyparse on error */
  879. int yyerror(const char *)
  880. {
  881. return 1;
  882. }
  883. /* may we automatically insert a semicolon ? */
  884. static bool allowAutomaticSemicolon()
  885. {
  886. return yychar == '}' || yychar == 0 || Lexer::curr()-&gt;prevTerminator();
  887. }
  888. </pre>
  889. <hr />
  890. </body></html>