Warning, /frameworks/kjs/src/kjs/grammar.y is written in an unsupported language. File is not indexed.
0001 %{ 0002 0003 /* 0004 * This file is part of the KDE libraries 0005 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 0006 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 0007 * Copyright (C) 2019 froglogic GmbH (contact@froglogic.com) 0008 * 0009 * This library is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU Lesser General Public 0011 * License as published by the Free Software Foundation; either 0012 * version 2 of the License, or (at your option) any later version. 0013 * 0014 * This library is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 * Lesser General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Lesser General Public 0020 * License along with this library; if not, write to the Free Software 0021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0022 * 0023 */ 0024 0025 #include <string.h> 0026 #include <stdlib.h> 0027 #include <stdio.h> 0028 #include "value.h" 0029 #include "object.h" 0030 #include "types.h" 0031 #include "interpreter.h" 0032 #include "nodes.h" 0033 #include "makenodes.h" 0034 #include "lexer.h" 0035 #include "internal.h" 0036 0037 // Not sure why, but yacc doesn't add this define along with the others. 0038 #define yylloc kjsyylloc 0039 0040 /* default values for bison */ 0041 #define YYDEBUG 0 // Set to 1 to debug a parse error. 0042 #define kjsyydebug 0 // Set to 1 to debug a parse error. 0043 #if !PLATFORM(DARWIN) 0044 // avoid triggering warnings in older bison 0045 #define YYERROR_VERBOSE 0046 #endif 0047 0048 extern int kjsyylex(); 0049 int kjsyyerror(const char *); 0050 static bool allowAutomaticSemicolon(); 0051 0052 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon()) YYABORT; } while (0) 0053 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line) 0054 0055 #ifndef __GNUC__ 0056 # define __attribute__(x) 0057 #endif 0058 0059 using namespace KJS; 0060 0061 %} 0062 0063 %union { 0064 int ival; 0065 double dval; 0066 UString *ustr; 0067 Identifier *ident; 0068 Node *node; 0069 StatementNode *stat; 0070 ParameterNode *param; 0071 FunctionBodyNode *body; 0072 FuncDeclNode *func; 0073 FuncExprNode *funcExpr; 0074 ProgramNode *prog; 0075 AssignExprNode *init; 0076 SourceElementsNode *srcs; 0077 ArgumentsNode *args; 0078 ArgumentListNode *alist; 0079 VarDeclNode *decl; 0080 VarDeclListNode *vlist; 0081 CaseBlockNode *cblk; 0082 ClauseListNode *clist; 0083 CaseClauseNode *ccl; 0084 ElementNode *elm; 0085 Operator op; 0086 PropertyListNode *plist; 0087 PropertyNode *pnode; 0088 PropertyNameNode *pname; 0089 PackageNameNode *pkgn; 0090 } 0091 0092 %start Program 0093 0094 /* literals */ 0095 %token NULLTOKEN TRUETOKEN FALSETOKEN 0096 0097 /* keywords */ 0098 %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE 0099 %token FUNCTION RETURN VOIDTOKEN DELETETOKEN 0100 %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF 0101 %token SWITCH WITH RESERVED 0102 %token THROW TRY CATCH FINALLY 0103 %token DEBUGGER IMPORT 0104 0105 /* give an if without an else higher precedence than an else to resolve the ambiguity */ 0106 %nonassoc IF_WITHOUT_ELSE 0107 %nonassoc ELSE 0108 0109 /* punctuators */ 0110 %token EQEQ NE /* == and != */ 0111 %token STREQ STRNEQ /* === and !== */ 0112 %token LE GE /* < and > */ 0113 %token OR AND /* || and && */ 0114 %token PLUSPLUS MINUSMINUS /* ++ and -- */ 0115 %token LSHIFT /* << */ 0116 %token RSHIFT URSHIFT /* >> and >>> */ 0117 %token T_EXP /* ** */ 0118 %token PLUSEQUAL MINUSEQUAL /* += and -= */ 0119 %token MULTEQUAL DIVEQUAL /* *= and /= */ 0120 %token EXPEQUAL /* **= */ 0121 %token LSHIFTEQUAL /* <<= */ 0122 %token RSHIFTEQUAL URSHIFTEQUAL /* >>= and >>>= */ 0123 %token ANDEQUAL MODEQUAL /* &= and %= */ 0124 %token XOREQUAL OREQUAL /* ^= and |= */ 0125 0126 /* terminal types */ 0127 %token <dval> NUMBER 0128 %token <ustr> STRING 0129 %token <ident> IDENT 0130 0131 /* automatically inserted semicolon */ 0132 %token AUTOPLUSPLUS AUTOMINUSMINUS 0133 0134 /* non-terminal types */ 0135 %type <node> Literal ArrayLiteral 0136 0137 %type <node> PrimaryExpr PrimaryExprNoBrace 0138 %type <node> MemberExpr MemberExprNoBF /* BF => brace or function */ 0139 %type <node> NewExpr NewExprNoBF 0140 %type <node> CallExpr CallExprNoBF 0141 %type <node> LeftHandSideExpr LeftHandSideExprNoBF 0142 %type <node> UpdateExpr UpdateExprNoBF UpdateExprCommon 0143 %type <node> UnaryExpr UnaryExprNoBF UnaryExprCommon 0144 %type <node> ExponentiationExpr ExponentiationExprNoBF 0145 %type <node> MultiplicativeExpr MultiplicativeExprNoBF 0146 %type <node> AdditiveExpr AdditiveExprNoBF 0147 %type <node> ShiftExpr ShiftExprNoBF 0148 %type <node> RelationalExpr RelationalExprNoIn RelationalExprNoBF 0149 %type <node> EqualityExpr EqualityExprNoIn EqualityExprNoBF 0150 %type <node> BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF 0151 %type <node> BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF 0152 %type <node> BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF 0153 %type <node> LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF 0154 %type <node> LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF 0155 %type <node> ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF 0156 %type <node> AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF 0157 %type <node> Expr ExprNoIn ExprNoBF 0158 %type <node> ExprOpt ExprNoInOpt 0159 0160 %type <stat> Statement Block 0161 %type <stat> VariableStatement ConstStatement EmptyStatement ExprStatement 0162 %type <stat> IfStatement IterationStatement ContinueStatement 0163 %type <stat> BreakStatement ReturnStatement WithStatement 0164 %type <stat> SwitchStatement LabelledStatement 0165 %type <stat> ThrowStatement TryStatement 0166 %type <stat> DebuggerStatement ImportStatement 0167 %type <stat> SourceElement 0168 0169 %type <init> Initializer InitializerNoIn 0170 %type <func> FunctionDeclaration 0171 %type <funcExpr> FunctionExpr 0172 %type <body> FunctionBody 0173 %type <srcs> SourceElements 0174 %type <param> FormalParameterList 0175 %type <op> AssignmentOperator 0176 %type <args> Arguments 0177 %type <alist> ArgumentList 0178 %type <vlist> VariableDeclarationList VariableDeclarationListNoIn ConstDeclarationList 0179 %type <decl> VariableDeclaration VariableDeclarationNoIn ConstDeclaration 0180 %type <cblk> CaseBlock 0181 %type <ccl> CaseClause DefaultClause 0182 %type <clist> CaseClauses CaseClausesOpt 0183 %type <ival> Elision ElisionOpt 0184 %type <elm> ElementList 0185 %type <pname> PropertyName 0186 %type <pnode> Property 0187 %type <plist> PropertyList 0188 %type <pkgn> PackageName 0189 %type <ident> Keywords 0190 %type <ident> IdentifierName 0191 %% 0192 0193 Keywords: 0194 BREAK { $$ = new Identifier("break"); } 0195 | CASE { $$ = new Identifier("case"); } 0196 | DEFAULT { $$ = new Identifier("default"); } 0197 | FOR { $$ = new Identifier("for"); } 0198 | NEW { $$ = new Identifier("new"); } 0199 | VAR { $$ = new Identifier("var"); } 0200 | CONSTTOKEN { $$ = new Identifier("const"); } 0201 | CONTINUE { $$ = new Identifier("continue"); } 0202 | FUNCTION { $$ = new Identifier("function"); } 0203 | RETURN { $$ = new Identifier("return"); } 0204 | VOIDTOKEN { $$ = new Identifier("void"); } 0205 | DELETETOKEN { $$ = new Identifier("delete"); } 0206 | IF { $$ = new Identifier("if"); } 0207 | THISTOKEN { $$ = new Identifier("this"); } 0208 | DO { $$ = new Identifier("do"); } 0209 | WHILE { $$ = new Identifier("while"); } 0210 | INTOKEN { $$ = new Identifier("in"); } 0211 | INSTANCEOF { $$ = new Identifier("instanceof"); } 0212 | TYPEOF { $$ = new Identifier("typeof"); } 0213 | SWITCH { $$ = new Identifier("switch"); } 0214 | WITH { $$ = new Identifier("with"); } 0215 | THROW { $$ = new Identifier("throw"); } 0216 | TRY { $$ = new Identifier("try"); } 0217 | CATCH { $$ = new Identifier("catch"); } 0218 | FINALLY { $$ = new Identifier("finally"); } 0219 | DEBUGGER { $$ = new Identifier("debugger"); } 0220 | IMPORT { $$ = new Identifier("import"); } 0221 | NULLTOKEN { $$ = new Identifier("null"); } 0222 | TRUETOKEN { $$ = new Identifier("true"); } 0223 | FALSETOKEN { $$ = new Identifier("false"); } 0224 | ELSE { $$ = new Identifier("else"); } 0225 ; 0226 0227 IdentifierName: 0228 IDENT { $$ = $1; } 0229 | Keywords { $$ = $1; } 0230 ; 0231 0232 Literal: 0233 NULLTOKEN { $$ = new NullNode(); } 0234 | TRUETOKEN { $$ = new BooleanNode(true); } 0235 | FALSETOKEN { $$ = new BooleanNode(false); } 0236 | NUMBER { $$ = new NumberNode($1); } 0237 | STRING { $$ = new StringNode($1); } 0238 | '/' /* regexp */ { 0239 Lexer& l = lexer(); 0240 if (!l.scanRegExp()) 0241 YYABORT; 0242 $$ = new RegExpNode(l.pattern(), l.flags()); 0243 } 0244 | DIVEQUAL /* regexp with /= */ { 0245 Lexer& l = lexer(); 0246 if (!l.scanRegExp()) 0247 YYABORT; 0248 $$ = new RegExpNode("=" + l.pattern(), l.flags()); 0249 } 0250 ; 0251 0252 PropertyName: 0253 IdentifierName { $$ = new PropertyNameNode(*$1); } 0254 | STRING { $$ = new PropertyNameNode(Identifier(*$1)); } 0255 | NUMBER { $$ = new PropertyNameNode(Identifier(UString::from($1))); } 0256 ; 0257 0258 Property: 0259 PropertyName ':' AssignmentExpr { $$ = new PropertyNode($1, $3, PropertyNode::Constant); } 0260 | IDENT IdentifierName '(' ')' {inFuncExpr();} FunctionBody { 0261 if (!makeGetterOrSetterPropertyNode($$, *$1, *$2, nullptr, $6)) 0262 YYABORT; 0263 } 0264 | IDENT IdentifierName '(' FormalParameterList ')' {inFuncExpr();} FunctionBody { 0265 if (!makeGetterOrSetterPropertyNode($$, *$1, *$2, $4, $7)) 0266 YYABORT; 0267 } 0268 ; 0269 0270 PropertyList: 0271 Property { $$ = new PropertyListNode($1); } 0272 | PropertyList ',' Property { $$ = new PropertyListNode($3, $1); } 0273 ; 0274 0275 PrimaryExpr: 0276 PrimaryExprNoBrace 0277 | '{' '}' { $$ = new ObjectLiteralNode(); } 0278 | '{' PropertyList '}' { $$ = new ObjectLiteralNode($2); } 0279 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */ 0280 | '{' PropertyList ',' '}' { $$ = new ObjectLiteralNode($2); } 0281 ; 0282 0283 PrimaryExprNoBrace: 0284 THISTOKEN { $$ = new ThisNode(); } 0285 | Literal 0286 | ArrayLiteral 0287 | IDENT { $$ = new VarAccessNode(*$1); } 0288 | '(' Expr ')' { $$ = makeGroupNode($2); } 0289 0290 ; 0291 0292 ArrayLiteral: 0293 '[' ElisionOpt ']' { $$ = new ArrayNode($2); } 0294 | '[' ElementList ']' { $$ = new ArrayNode($2); } 0295 | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2); } 0296 ; 0297 0298 ElementList: 0299 ElisionOpt AssignmentExpr { $$ = new ElementNode($1, $2); } 0300 | ElementList ',' ElisionOpt AssignmentExpr 0301 { $$ = new ElementNode($1, $3, $4); } 0302 ; 0303 0304 ElisionOpt: 0305 /* nothing */ { $$ = nullptr; } 0306 | Elision 0307 ; 0308 0309 Elision: 0310 ',' { $$ = 1; } 0311 | Elision ',' { $$ = $1 + 1; } 0312 ; 0313 0314 MemberExpr: 0315 PrimaryExpr 0316 | FunctionExpr { $$ = $1; } 0317 | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 0318 | MemberExpr '.' IdentifierName { $$ = new DotAccessorNode($1, *$3); } 0319 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); } 0320 ; 0321 0322 MemberExprNoBF: 0323 PrimaryExprNoBrace 0324 | MemberExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 0325 | MemberExprNoBF '.' IdentifierName { $$ = new DotAccessorNode($1, *$3); } 0326 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); } 0327 ; 0328 0329 NewExpr: 0330 MemberExpr 0331 | NEW NewExpr { $$ = new NewExprNode($2); } 0332 ; 0333 0334 NewExprNoBF: 0335 MemberExprNoBF 0336 | NEW NewExpr { $$ = new NewExprNode($2); } 0337 ; 0338 0339 CallExpr: 0340 MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 0341 | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); } 0342 | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 0343 | CallExpr '.' IdentifierName { $$ = new DotAccessorNode($1, *$3); } 0344 ; 0345 0346 CallExprNoBF: 0347 MemberExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); } 0348 | CallExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); } 0349 | CallExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); } 0350 | CallExprNoBF '.' IdentifierName { $$ = new DotAccessorNode($1, *$3); } 0351 ; 0352 0353 Arguments: 0354 '(' ')' { $$ = new ArgumentsNode(); } 0355 | '(' ArgumentList ')' { $$ = new ArgumentsNode($2); } 0356 ; 0357 0358 ArgumentList: 0359 AssignmentExpr { $$ = new ArgumentListNode($1); } 0360 | ArgumentList ',' AssignmentExpr { $$ = new ArgumentListNode($1, $3); } 0361 ; 0362 0363 LeftHandSideExpr: 0364 NewExpr 0365 | CallExpr 0366 ; 0367 0368 LeftHandSideExprNoBF: 0369 NewExprNoBF 0370 | CallExprNoBF 0371 ; 0372 0373 UpdateExprCommon: 0374 PLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); } 0375 | AUTOPLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); } 0376 | MINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); } 0377 | AUTOMINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); } 0378 ; 0379 0380 UpdateExpr: 0381 LeftHandSideExpr 0382 | LeftHandSideExpr PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); } 0383 | LeftHandSideExpr MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); } 0384 | UpdateExprCommon 0385 ; 0386 0387 UpdateExprNoBF: 0388 LeftHandSideExprNoBF 0389 | LeftHandSideExprNoBF PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); } 0390 | LeftHandSideExprNoBF MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); } 0391 | UpdateExprCommon 0392 ; 0393 0394 UnaryExprCommon: 0395 DELETETOKEN UnaryExpr { $$ = makeDeleteNode($2); } 0396 | VOIDTOKEN UnaryExpr { $$ = new VoidNode($2); } 0397 | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); } 0398 | '+' UnaryExpr { $$ = makeUnaryPlusNode($2); } 0399 | '-' UnaryExpr { $$ = makeNegateNode($2); } 0400 | '~' UnaryExpr { $$ = makeBitwiseNotNode($2); } 0401 | '!' UnaryExpr { $$ = makeLogicalNotNode($2); } 0402 0403 UnaryExpr: 0404 UpdateExpr 0405 | UnaryExprCommon 0406 ; 0407 0408 UnaryExprNoBF: 0409 UpdateExprNoBF 0410 | UnaryExprCommon 0411 ; 0412 0413 ExponentiationExpr: 0414 UnaryExpr 0415 | UpdateExpr T_EXP ExponentiationExpr { $$ = makeMultNode($1, $3, OpExp); } 0416 ; 0417 0418 ExponentiationExprNoBF: 0419 UnaryExprNoBF 0420 | UpdateExprNoBF T_EXP ExponentiationExpr { $$ = makeMultNode($1, $3, OpExp); } 0421 ; 0422 0423 MultiplicativeExpr: 0424 ExponentiationExpr 0425 | MultiplicativeExpr '*' ExponentiationExpr { $$ = makeMultNode($1, $3, OpMult); } 0426 | MultiplicativeExpr '/' ExponentiationExpr { $$ = makeMultNode($1, $3, OpDiv); } 0427 | MultiplicativeExpr '%' ExponentiationExpr { $$ = makeMultNode($1, $3, OpMod); } 0428 ; 0429 0430 MultiplicativeExprNoBF: 0431 ExponentiationExprNoBF 0432 | MultiplicativeExprNoBF '*' ExponentiationExpr 0433 { $$ = makeMultNode($1, $3, OpMult); } 0434 | MultiplicativeExprNoBF '/' ExponentiationExpr 0435 { $$ = makeMultNode($1, $3, OpDiv); } 0436 | MultiplicativeExprNoBF '%' ExponentiationExpr 0437 { $$ = makeMultNode($1, $3, OpMod); } 0438 ; 0439 0440 AdditiveExpr: 0441 MultiplicativeExpr 0442 | AdditiveExpr '+' MultiplicativeExpr { $$ = makeAddNode($1, $3, OpPlus); } 0443 | AdditiveExpr '-' MultiplicativeExpr { $$ = makeAddNode($1, $3, OpMinus); } 0444 ; 0445 0446 AdditiveExprNoBF: 0447 MultiplicativeExprNoBF 0448 | AdditiveExprNoBF '+' MultiplicativeExpr 0449 { $$ = makeAddNode($1, $3, OpPlus); } 0450 | AdditiveExprNoBF '-' MultiplicativeExpr 0451 { $$ = makeAddNode($1, $3, OpMinus); } 0452 ; 0453 0454 ShiftExpr: 0455 AdditiveExpr 0456 | ShiftExpr LSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpLShift); } 0457 | ShiftExpr RSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpRShift); } 0458 | ShiftExpr URSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpURShift); } 0459 ; 0460 0461 ShiftExprNoBF: 0462 AdditiveExprNoBF 0463 | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpLShift); } 0464 | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpRShift); } 0465 | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = makeShiftNode($1, $3, OpURShift); } 0466 ; 0467 0468 RelationalExpr: 0469 ShiftExpr 0470 | RelationalExpr '<' ShiftExpr { $$ = makeRelationalNode($1, OpLess, $3); } 0471 | RelationalExpr '>' ShiftExpr { $$ = makeRelationalNode($1, OpGreater, $3); } 0472 | RelationalExpr LE ShiftExpr { $$ = makeRelationalNode($1, OpLessEq, $3); } 0473 | RelationalExpr GE ShiftExpr { $$ = makeRelationalNode($1, OpGreaterEq, $3); } 0474 | RelationalExpr INSTANCEOF ShiftExpr { $$ = makeRelationalNode($1, OpInstanceOf, $3); } 0475 | RelationalExpr INTOKEN ShiftExpr { $$ = makeRelationalNode($1, OpIn, $3); } 0476 ; 0477 0478 RelationalExprNoIn: 0479 ShiftExpr 0480 | RelationalExprNoIn '<' ShiftExpr { $$ = makeRelationalNode($1, OpLess, $3); } 0481 | RelationalExprNoIn '>' ShiftExpr { $$ = makeRelationalNode($1, OpGreater, $3); } 0482 | RelationalExprNoIn LE ShiftExpr { $$ = makeRelationalNode($1, OpLessEq, $3); } 0483 | RelationalExprNoIn GE ShiftExpr { $$ = makeRelationalNode($1, OpGreaterEq, $3); } 0484 | RelationalExprNoIn INSTANCEOF ShiftExpr 0485 { $$ = makeRelationalNode($1, OpInstanceOf, $3); } 0486 ; 0487 0488 RelationalExprNoBF: 0489 ShiftExprNoBF 0490 | RelationalExprNoBF '<' ShiftExpr { $$ = makeRelationalNode($1, OpLess, $3); } 0491 | RelationalExprNoBF '>' ShiftExpr { $$ = makeRelationalNode($1, OpGreater, $3); } 0492 | RelationalExprNoBF LE ShiftExpr { $$ = makeRelationalNode($1, OpLessEq, $3); } 0493 | RelationalExprNoBF GE ShiftExpr { $$ = makeRelationalNode($1, OpGreaterEq, $3); } 0494 | RelationalExprNoBF INSTANCEOF ShiftExpr 0495 { $$ = makeRelationalNode($1, OpInstanceOf, $3); } 0496 | RelationalExprNoBF INTOKEN ShiftExpr { $$ = makeRelationalNode($1, OpIn, $3); } 0497 ; 0498 0499 EqualityExpr: 0500 RelationalExpr 0501 | EqualityExpr EQEQ RelationalExpr { $$ = makeEqualNode($1, OpEqEq, $3); } 0502 | EqualityExpr NE RelationalExpr { $$ = makeEqualNode($1, OpNotEq, $3); } 0503 | EqualityExpr STREQ RelationalExpr { $$ = makeEqualNode($1, OpStrEq, $3); } 0504 | EqualityExpr STRNEQ RelationalExpr { $$ = makeEqualNode($1, OpStrNEq, $3);} 0505 ; 0506 0507 EqualityExprNoIn: 0508 RelationalExprNoIn 0509 | EqualityExprNoIn EQEQ RelationalExprNoIn 0510 { $$ = makeEqualNode($1, OpEqEq, $3); } 0511 | EqualityExprNoIn NE RelationalExprNoIn 0512 { $$ = makeEqualNode($1, OpNotEq, $3); } 0513 | EqualityExprNoIn STREQ RelationalExprNoIn 0514 { $$ = makeEqualNode($1, OpStrEq, $3); } 0515 | EqualityExprNoIn STRNEQ RelationalExprNoIn 0516 { $$ = makeEqualNode($1, OpStrNEq, $3);} 0517 ; 0518 0519 EqualityExprNoBF: 0520 RelationalExprNoBF 0521 | EqualityExprNoBF EQEQ RelationalExpr 0522 { $$ = makeEqualNode($1, OpEqEq, $3); } 0523 | EqualityExprNoBF NE RelationalExpr { $$ = makeEqualNode($1, OpNotEq, $3); } 0524 | EqualityExprNoBF STREQ RelationalExpr 0525 { $$ = makeEqualNode($1, OpStrEq, $3); } 0526 | EqualityExprNoBF STRNEQ RelationalExpr 0527 { $$ = makeEqualNode($1, OpStrNEq, $3);} 0528 ; 0529 0530 BitwiseANDExpr: 0531 EqualityExpr 0532 | BitwiseANDExpr '&' EqualityExpr { $$ = makeBitOperNode($1, OpBitAnd, $3); } 0533 ; 0534 0535 BitwiseANDExprNoIn: 0536 EqualityExprNoIn 0537 | BitwiseANDExprNoIn '&' EqualityExprNoIn 0538 { $$ = makeBitOperNode($1, OpBitAnd, $3); } 0539 ; 0540 0541 BitwiseANDExprNoBF: 0542 EqualityExprNoBF 0543 | BitwiseANDExprNoBF '&' EqualityExpr { $$ = makeBitOperNode($1, OpBitAnd, $3); } 0544 ; 0545 0546 BitwiseXORExpr: 0547 BitwiseANDExpr 0548 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = makeBitOperNode($1, OpBitXOr, $3); } 0549 ; 0550 0551 BitwiseXORExprNoIn: 0552 BitwiseANDExprNoIn 0553 | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn 0554 { $$ = makeBitOperNode($1, OpBitXOr, $3); } 0555 ; 0556 0557 BitwiseXORExprNoBF: 0558 BitwiseANDExprNoBF 0559 | BitwiseXORExprNoBF '^' BitwiseANDExpr 0560 { $$ = makeBitOperNode($1, OpBitXOr, $3); } 0561 ; 0562 0563 BitwiseORExpr: 0564 BitwiseXORExpr 0565 | BitwiseORExpr '|' BitwiseXORExpr { $$ = makeBitOperNode($1, OpBitOr, $3); } 0566 ; 0567 0568 BitwiseORExprNoIn: 0569 BitwiseXORExprNoIn 0570 | BitwiseORExprNoIn '|' BitwiseXORExprNoIn 0571 { $$ = makeBitOperNode($1, OpBitOr, $3); } 0572 ; 0573 0574 BitwiseORExprNoBF: 0575 BitwiseXORExprNoBF 0576 | BitwiseORExprNoBF '|' BitwiseXORExpr 0577 { $$ = makeBitOperNode($1, OpBitOr, $3); } 0578 ; 0579 0580 LogicalANDExpr: 0581 BitwiseORExpr 0582 | LogicalANDExpr AND BitwiseORExpr { $$ = makeBinaryLogicalNode($1, OpAnd, $3); } 0583 ; 0584 0585 LogicalANDExprNoIn: 0586 BitwiseORExprNoIn 0587 | LogicalANDExprNoIn AND BitwiseORExprNoIn 0588 { $$ = makeBinaryLogicalNode($1, OpAnd, $3); } 0589 ; 0590 0591 LogicalANDExprNoBF: 0592 BitwiseORExprNoBF 0593 | LogicalANDExprNoBF AND BitwiseORExpr 0594 { $$ = makeBinaryLogicalNode($1, OpAnd, $3); } 0595 ; 0596 0597 LogicalORExpr: 0598 LogicalANDExpr 0599 | LogicalORExpr OR LogicalANDExpr { $$ = makeBinaryLogicalNode($1, OpOr, $3); } 0600 ; 0601 0602 LogicalORExprNoIn: 0603 LogicalANDExprNoIn 0604 | LogicalORExprNoIn OR LogicalANDExprNoIn 0605 { $$ = makeBinaryLogicalNode($1, OpOr, $3); } 0606 ; 0607 0608 LogicalORExprNoBF: 0609 LogicalANDExprNoBF 0610 | LogicalORExprNoBF OR LogicalANDExpr { $$ = makeBinaryLogicalNode($1, OpOr, $3); } 0611 ; 0612 0613 ConditionalExpr: 0614 LogicalORExpr 0615 | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr 0616 { $$ = makeConditionalNode($1, $3, $5); } 0617 ; 0618 0619 ConditionalExprNoIn: 0620 LogicalORExprNoIn 0621 | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn 0622 { $$ = makeConditionalNode($1, $3, $5); } 0623 ; 0624 0625 ConditionalExprNoBF: 0626 LogicalORExprNoBF 0627 | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr 0628 { $$ = makeConditionalNode($1, $3, $5); } 0629 ; 0630 0631 AssignmentExpr: 0632 ConditionalExpr 0633 | LeftHandSideExpr AssignmentOperator AssignmentExpr 0634 { $$ = makeAssignNode($1, $2, $3); } 0635 ; 0636 0637 AssignmentExprNoIn: 0638 ConditionalExprNoIn 0639 | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn 0640 { $$ = makeAssignNode($1, $2, $3); } 0641 ; 0642 0643 AssignmentExprNoBF: 0644 ConditionalExprNoBF 0645 | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr 0646 { $$ = makeAssignNode($1, $2, $3); } 0647 ; 0648 0649 AssignmentOperator: 0650 '=' { $$ = OpEqual; } 0651 | PLUSEQUAL { $$ = OpPlusEq; } 0652 | MINUSEQUAL { $$ = OpMinusEq; } 0653 | MULTEQUAL { $$ = OpMultEq; } 0654 | DIVEQUAL { $$ = OpDivEq; } 0655 | EXPEQUAL { $$ = OpExpEq; } 0656 | LSHIFTEQUAL { $$ = OpLShift; } 0657 | RSHIFTEQUAL { $$ = OpRShift; } 0658 | URSHIFTEQUAL { $$ = OpURShift; } 0659 | ANDEQUAL { $$ = OpAndEq; } 0660 | XOREQUAL { $$ = OpXOrEq; } 0661 | OREQUAL { $$ = OpOrEq; } 0662 | MODEQUAL { $$ = OpModEq; } 0663 ; 0664 0665 Expr: 0666 AssignmentExpr 0667 | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); } 0668 ; 0669 0670 ExprNoIn: 0671 AssignmentExprNoIn 0672 | ExprNoIn ',' AssignmentExprNoIn { $$ = new CommaNode($1, $3); } 0673 ; 0674 0675 ExprNoBF: 0676 AssignmentExprNoBF 0677 | ExprNoBF ',' AssignmentExpr { $$ = new CommaNode($1, $3); } 0678 ; 0679 0680 Statement: 0681 Block 0682 | VariableStatement 0683 | ConstStatement 0684 | EmptyStatement 0685 | ExprStatement 0686 | IfStatement 0687 | IterationStatement 0688 | ContinueStatement 0689 | BreakStatement 0690 | ReturnStatement 0691 | WithStatement 0692 | SwitchStatement 0693 | LabelledStatement 0694 | ThrowStatement 0695 | TryStatement 0696 | DebuggerStatement 0697 | ImportStatement 0698 ; 0699 0700 Block: 0701 '{' '}' { $$ = new BlockNode(nullptr); DBG($$, @2, @2); } 0702 | '{' SourceElements '}' { $$ = new BlockNode($2); DBG($$, @3, @3); } 0703 ; 0704 0705 VariableStatement: 0706 VAR VariableDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); } 0707 | VAR VariableDeclarationList error { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0708 ; 0709 0710 VariableDeclarationList: 0711 VariableDeclaration { $$ = new VarDeclListNode($1); } 0712 | VariableDeclarationList ',' VariableDeclaration 0713 { $$ = new VarDeclListNode($1, $3); } 0714 ; 0715 0716 VariableDeclarationListNoIn: 0717 VariableDeclarationNoIn { $$ = new VarDeclListNode($1); } 0718 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn 0719 { $$ = new VarDeclListNode($1, $3); } 0720 ; 0721 0722 VariableDeclaration: 0723 IDENT { $$ = new VarDeclNode(*$1, nullptr, VarDeclNode::Variable); } 0724 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); } 0725 ; 0726 0727 VariableDeclarationNoIn: 0728 IDENT { $$ = new VarDeclNode(*$1, nullptr, VarDeclNode::Variable); } 0729 | IDENT InitializerNoIn { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Variable); } 0730 ; 0731 0732 ConstStatement: 0733 CONSTTOKEN ConstDeclarationList ';' { $$ = new VarStatementNode($2); DBG($$, @1, @3); } 0734 | CONSTTOKEN ConstDeclarationList error 0735 { $$ = new VarStatementNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0736 ; 0737 0738 ConstDeclarationList: 0739 ConstDeclaration { $$ = new VarDeclListNode($1); } 0740 | ConstDeclarationList ',' ConstDeclaration 0741 { $$ = new VarDeclListNode($1, $3); } 0742 ; 0743 0744 ConstDeclaration: 0745 IDENT { $$ = new VarDeclNode(*$1, 0, VarDeclNode::Constant); } 0746 | IDENT Initializer { $$ = new VarDeclNode(*$1, $2, VarDeclNode::Constant); } 0747 ; 0748 0749 Initializer: 0750 '=' AssignmentExpr { $$ = new AssignExprNode($2); } 0751 ; 0752 0753 InitializerNoIn: 0754 '=' AssignmentExprNoIn { $$ = new AssignExprNode($2); } 0755 ; 0756 0757 EmptyStatement: 0758 ';' { $$ = new EmptyStatementNode(); } 0759 ; 0760 0761 ExprStatement: 0762 ExprNoBF ';' { $$ = new ExprStatementNode($1); DBG($$, @1, @2); } 0763 | ExprNoBF error { $$ = new ExprStatementNode($1); DBG($$, @1, @1); AUTO_SEMICOLON; } 0764 ; 0765 0766 IfStatement: 0767 IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE 0768 { $$ = makeIfNode($3, $5, nullptr); DBG($$, @1, @4); } 0769 | IF '(' Expr ')' Statement ELSE Statement 0770 { $$ = makeIfNode($3, $5, $7); DBG($$, @1, @4); } 0771 ; 0772 0773 IterationStatement: 0774 DO Statement WHILE '(' Expr ')' ';' { $$ = new DoWhileNode($2, $5); DBG($$, @1, @3);} 0775 | DO Statement WHILE '(' Expr ')' error { $$ = new DoWhileNode($2, $5); DBG($$, @1, @3); AUTO_SEMICOLON; } 0776 | WHILE '(' Expr ')' Statement { $$ = new WhileNode($3, $5); DBG($$, @1, @4); } 0777 | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement 0778 { $$ = new ForNode($3, $5, $7, $9); DBG($$, @1, @8); } 0779 | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement 0780 { $$ = new ForNode($4, $6, $8, $10); DBG($$, @1, @9); } 0781 | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement 0782 { 0783 Node *n = $3->nodeInsideAllParens(); 0784 if (!n->isLocation()) 0785 YYABORT; 0786 $$ = new ForInNode(n, $5, $7); 0787 DBG($$, @1, @6); 0788 } 0789 | FOR '(' VAR IDENT INTOKEN Expr ')' Statement 0790 { $$ = new ForInNode(*$4, nullptr, $6, $8); DBG($$, @1, @7); } 0791 | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement 0792 { $$ = new ForInNode(*$4, $5, $7, $9); DBG($$, @1, @8); } 0793 ; 0794 0795 ExprOpt: 0796 /* nothing */ { $$ = nullptr; } 0797 | Expr 0798 ; 0799 0800 ExprNoInOpt: 0801 /* nothing */ { $$ = nullptr; } 0802 | ExprNoIn 0803 ; 0804 0805 ContinueStatement: 0806 CONTINUE ';' { $$ = new ContinueNode(); DBG($$, @1, @2); } 0807 | CONTINUE error { $$ = new ContinueNode(); DBG($$, @1, @1); AUTO_SEMICOLON; } 0808 | CONTINUE IDENT ';' { $$ = new ContinueNode(*$2); DBG($$, @1, @3); } 0809 | CONTINUE IDENT error { $$ = new ContinueNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0810 ; 0811 0812 BreakStatement: 0813 BREAK ';' { $$ = new BreakNode(); DBG($$, @1, @2); } 0814 | BREAK error { $$ = new BreakNode(); DBG($$, @1, @1); AUTO_SEMICOLON; } 0815 | BREAK IDENT ';' { $$ = new BreakNode(*$2); DBG($$, @1, @3); } 0816 | BREAK IDENT error { $$ = new BreakNode(*$2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0817 ; 0818 0819 ReturnStatement: 0820 RETURN ';' { $$ = new ReturnNode(nullptr); DBG($$, @1, @2); } 0821 | RETURN error { $$ = new ReturnNode(nullptr); DBG($$, @1, @1); AUTO_SEMICOLON; } 0822 | RETURN Expr ';' { $$ = new ReturnNode($2); DBG($$, @1, @3); } 0823 | RETURN Expr error { $$ = new ReturnNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0824 ; 0825 0826 WithStatement: 0827 WITH '(' Expr ')' Statement { $$ = new WithNode($3, $5); DBG($$, @1, @4); } 0828 ; 0829 0830 SwitchStatement: 0831 SWITCH '(' Expr ')' CaseBlock { $$ = new SwitchNode($3, $5); DBG($$, @1, @4); } 0832 ; 0833 0834 CaseBlock: 0835 '{' CaseClausesOpt '}' { $$ = new CaseBlockNode($2, nullptr, nullptr); } 0836 | '{' CaseClausesOpt DefaultClause CaseClausesOpt '}' 0837 { $$ = new CaseBlockNode($2, $3, $4); } 0838 ; 0839 0840 CaseClausesOpt: 0841 /* nothing */ { $$ = nullptr; } 0842 | CaseClauses 0843 ; 0844 0845 CaseClauses: 0846 CaseClause { $$ = new ClauseListNode($1); } 0847 | CaseClauses CaseClause { $$ = new ClauseListNode($1, $2); } 0848 ; 0849 0850 CaseClause: 0851 CASE Expr ':' { $$ = new CaseClauseNode($2); } 0852 | CASE Expr ':' SourceElements { $$ = new CaseClauseNode($2, $4); } 0853 ; 0854 0855 DefaultClause: 0856 DEFAULT ':' { $$ = new CaseClauseNode(nullptr); } 0857 | DEFAULT ':' SourceElements { $$ = new CaseClauseNode(nullptr, $3); } 0858 ; 0859 0860 LabelledStatement: 0861 IDENT ':' Statement { $$ = makeLabelNode(*$1, $3); } 0862 ; 0863 0864 ThrowStatement: 0865 THROW Expr ';' { $$ = new ThrowNode($2); DBG($$, @1, @3); } 0866 | THROW Expr error { $$ = new ThrowNode($2); DBG($$, @1, @2); AUTO_SEMICOLON; } 0867 ; 0868 0869 TryStatement: 0870 TRY Block FINALLY Block { $$ = new TryNode($2, CommonIdentifiers::shared()->nullIdentifier, 0, $4); DBG($$, @1, @2); } 0871 | TRY Block CATCH '(' IDENT ')' Block { $$ = new TryNode($2, *$5, $7, nullptr); DBG($$, @1, @2); } 0872 | TRY Block CATCH '(' IDENT ')' Block FINALLY Block 0873 { $$ = new TryNode($2, *$5, $7, $9); DBG($$, @1, @2); } 0874 ; 0875 0876 DebuggerStatement: 0877 DEBUGGER ';' { $$ = new EmptyStatementNode(); DBG($$, @1, @2); } 0878 | DEBUGGER error { $$ = new EmptyStatementNode(); DBG($$, @1, @1); AUTO_SEMICOLON; } 0879 ; 0880 0881 PackageName: 0882 IDENT { $$ = new PackageNameNode(*$1); } 0883 | PackageName '.' IDENT { $$ = new PackageNameNode($1, *$3); } 0884 ; 0885 0886 ImportStatement: 0887 IMPORT PackageName '.' '*' ';' { $$ = makeImportNode($2, true, nullptr); 0888 DBG($$, @1, @5); } 0889 | IMPORT PackageName '.' '*' error { $$ = makeImportNode($2, true, nullptr); 0890 DBG($$, @1, @5); AUTO_SEMICOLON; } 0891 | IMPORT PackageName ';' { $$ = makeImportNode($2, false, nullptr); 0892 DBG($$, @1, @3); } 0893 | IMPORT PackageName error { $$ = makeImportNode($2, false, nullptr); 0894 DBG($$, @1, @3); AUTO_SEMICOLON; } 0895 | IMPORT IDENT '=' PackageName ';' { $$ = makeImportNode($4, false, *$2); 0896 DBG($$, @1, @5); } 0897 | IMPORT IDENT '=' PackageName error { $$ = makeImportNode($4, false, *$2); 0898 DBG($$, @1, @5); AUTO_SEMICOLON; } 0899 ; 0900 0901 FunctionDeclaration: 0902 FUNCTION IDENT '(' ')' {inFuncDecl();} FunctionBody { $$ = new FuncDeclNode(*$2, $6); } 0903 | FUNCTION IDENT '(' FormalParameterList ')' {inFuncDecl();} FunctionBody 0904 { $$ = new FuncDeclNode(*$2, $4, $7); } 0905 ; 0906 0907 FunctionExpr: 0908 FUNCTION '(' ')' {inFuncExpr();} FunctionBody { 0909 $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $5); 0910 } 0911 | FUNCTION '(' FormalParameterList ')' {inFuncExpr();} FunctionBody { 0912 $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $6, $3); 0913 } 0914 | FUNCTION IDENT '(' ')' {inFuncExpr();} FunctionBody { $$ = new FuncExprNode(*$2, $6); } 0915 | FUNCTION IDENT '(' FormalParameterList ')' {inFuncExpr();} FunctionBody { 0916 $$ = new FuncExprNode(*$2, $7, $4); 0917 } 0918 ; 0919 0920 FormalParameterList: 0921 IDENT { $$ = new ParameterNode(*$1); } 0922 | FormalParameterList ',' IDENT { $$ = new ParameterNode($1, *$3); } 0923 ; 0924 0925 FunctionBody: 0926 '{' '}' /* not in spec */ { $$ = new FunctionBodyNode(nullptr); DBG($$, @1, @2); } 0927 | '{' SourceElements '}' { $$ = new FunctionBodyNode($2); DBG($$, @1, @3); } 0928 ; 0929 0930 Program: 0931 /* not in spec */ { parser().didFinishParsing(new ProgramNode(nullptr)); } 0932 | SourceElements { parser().didFinishParsing(new ProgramNode($1)); } 0933 ; 0934 0935 SourceElements: 0936 SourceElement { $$ = new SourceElementsNode($1); } 0937 | SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); } 0938 ; 0939 0940 SourceElement: 0941 FunctionDeclaration { $$ = $1; } 0942 | Statement { $$ = $1; } 0943 ; 0944 0945 %% 0946 0947 /* called by yyparse on error */ 0948 int yyerror(const char *) 0949 { 0950 // fprintf(stderr, "ERROR: %s at line %d\n", s, KJS::Lexer::curr()->lineNo()); 0951 return 1; 0952 } 0953 0954 /* may we automatically insert a semicolon ? */ 0955 static bool allowAutomaticSemicolon() 0956 { 0957 return yychar == '}' || yychar == 0 || lexer().prevTerminator(); 0958 } 0959 0960 // kate: indent-width 2; replace-tabs on; tab-width 4; space-indent on;