📄 grammar.y
字号:
%pure_parser%{/* * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2007 Eric Seidel <eric@webkit.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */#include "config.h"#include <string.h>#include <stdlib.h>#include "JSValue.h"#include "JSObject.h"#include "Nodes.h"#include "Lexer.h"#include "JSString.h"#include "JSGlobalData.h"#include "CommonIdentifiers.h"#include "NodeInfo.h"#include "Parser.h"#include <wtf/MathExtras.h>#define YYMAXDEPTH 10000#define YYENABLE_NLS 0/* default values for bison */#define YYDEBUG 0 // Set to 1 to debug a parse error.#define jscyydebug 0 // Set to 1 to debug a parse error.#if !PLATFORM(DARWIN) // avoid triggering warnings in older bison#define YYERROR_VERBOSE#endifint jscyylex(void* lvalp, void* llocp, void* globalPtr);int jscyyerror(const char*);static inline bool allowAutomaticSemicolon(JSC::Lexer&, int);#define GLOBAL_DATA static_cast<JSGlobalData*>(globalPtr)#define LEXER (GLOBAL_DATA->lexer)#define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon(*LEXER, yychar)) YYABORT; } while (0)#define SET_EXCEPTION_LOCATION(node, start, divot, end) node->setExceptionSourceCode((divot), (divot) - (start), (end) - (divot))#define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line)using namespace JSC;using namespace std;static ExpressionNode* makeAssignNode(void*, ExpressionNode* loc, Operator, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end);static ExpressionNode* makePrefixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end);static ExpressionNode* makePostfixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end);static PropertyNode* makeGetterOrSetterPropertyNode(void*, const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceCode&);static ExpressionNodeInfo makeFunctionCallNode(void*, ExpressionNodeInfo func, ArgumentsNodeInfo, int start, int divot, int end);static ExpressionNode* makeTypeOfNode(void*, ExpressionNode*);static ExpressionNode* makeDeleteNode(void*, ExpressionNode*, int start, int divot, int end);static ExpressionNode* makeNegateNode(void*, ExpressionNode*);static NumberNode* makeNumberNode(void*, double);static ExpressionNode* makeBitwiseNotNode(void*, ExpressionNode*);static ExpressionNode* makeMultNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static ExpressionNode* makeDivNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static ExpressionNode* makeAddNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static ExpressionNode* makeSubNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static ExpressionNode* makeLeftShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static ExpressionNode* makeRightShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);static StatementNode* makeVarStatementNode(void*, ExpressionNode*);static ExpressionNode* combineVarInitializers(void*, ExpressionNode* list, AssignResolveNode* init);#if COMPILER(MSVC)#pragma warning(disable: 4065)#pragma warning(disable: 4244)#pragma warning(disable: 4702)// At least some of the time, the declarations of malloc and free that bison// generates are causing warnings. A way to avoid this is to explicitly define// the macros so that bison doesn't try to declare malloc and free.#define YYMALLOC malloc#define YYFREE free#endif#define YYPARSE_PARAM globalPtr#define YYLEX_PARAM globalPtrtemplate <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls, ParserRefCountedData<DeclarationStacks::FunctionStack>* funcDecls, CodeFeatures info, int numConstants) { ASSERT((info & ~AllFeatures) == 0); NodeDeclarationInfo<T> result = {node, varDecls, funcDecls, info, numConstants}; return result;}template <typename T> NodeInfo<T> createNodeInfo(T node, CodeFeatures info, int numConstants){ ASSERT((info & ~AllFeatures) == 0); NodeInfo<T> result = {node, info, numConstants}; return result;}template <typename T> T mergeDeclarationLists(T decls1, T decls2) { // decls1 or both are null if (!decls1) return decls2; // only decls1 is non-null if (!decls2) return decls1; // Both are non-null decls1->data.append(decls2->data); // We manually release the declaration lists to avoid accumulating many many // unused heap allocated vectors decls2->ref(); decls2->deref(); return decls1;}static void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs){ if (!varDecls) varDecls = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA); varDecls->data.append(make_pair(ident, attrs));}static inline void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl){ unsigned attrs = DeclarationStacks::IsConstant; if (decl->m_init) attrs |= DeclarationStacks::HasInitializer; appendToVarDeclarationList(globalPtr, varDecls, decl->m_ident, attrs);}%}%union { int intValue; double doubleValue; Identifier* ident; // expression subtrees ExpressionNodeInfo expressionNode; FuncDeclNodeInfo funcDeclNode; PropertyNodeInfo propertyNode; ArgumentsNodeInfo argumentsNode; ConstDeclNodeInfo constDeclNode; CaseBlockNodeInfo caseBlockNode; CaseClauseNodeInfo caseClauseNode; FuncExprNodeInfo funcExprNode; // statement nodes StatementNodeInfo statementNode; FunctionBodyNode* functionBodyNode; ProgramNode* programNode; SourceElementsInfo sourceElements; PropertyListInfo propertyList; ArgumentListInfo argumentList; VarDeclListInfo varDeclList; ConstDeclListInfo constDeclList; ClauseListInfo clauseList; ElementListInfo elementList; ParameterListInfo parameterList; Operator op;}%start Program/* literals */%token NULLTOKEN TRUETOKEN FALSETOKEN/* keywords */%token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE%token FUNCTION RETURN VOIDTOKEN DELETETOKEN%token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -