⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscript.g

📁 奇趣公司比较新的qt/emd版本
💻 G
📖 第 1 页 / 共 4 页
字号:
-------------------------------------------------------------------------------- Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.---- This file is part of the QtScript module of the Qt Toolkit.---- This file may be used under the terms of the GNU General Public-- License version 2.0 as published by the Free Software Foundation-- and appearing in the file LICENSE.GPL included in the packaging of-- this file.  Please review the following information to ensure GNU-- General Public Licensing requirements will be met:-- http://trolltech.com/products/qt/licenses/licensing/opensource/---- If you are unsure which license is appropriate for your use, please-- review the following information:-- http://trolltech.com/products/qt/licenses/licensing/licensingoverview-- or contact the sales department at sales@trolltech.com.---- In addition, as a special exception, Trolltech gives you certain-- additional rights. These rights are described in the Trolltech GPL-- Exception version 1.0, which can be found at-- http://www.trolltech.com/products/qt/gplexception/ and in the file-- GPL_EXCEPTION.txt in this package.---- In addition, as a special exception, Trolltech, as the sole copyright-- holder for Qt Designer, grants users of the Qt/Eclipse Integration-- plug-in the right for the Qt/Eclipse Integration to link to-- functionality provided by Qt Designer and its related libraries.---- Trolltech reserves all rights not expressly granted herein.---- This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE-- WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.------------------------------------------------------------------------------%parser         QScriptGrammar%decl           qscriptparser_p.h%impl           qscriptparser.cpp%expect         3%expect-rr      1%token T_AND "&"                T_AND_AND "&&"              T_AND_EQ "&="%token T_BREAK "break"          T_CASE "case"               T_CATCH "catch"%token T_COLON ":"              T_COMMA ";"                 T_CONTINUE "continue"%token T_DEFAULT "default"      T_DELETE "delete"           T_DIVIDE_ "/"%token T_DIVIDE_EQ "/="         T_DO "do"                   T_DOT "."%token T_ELSE "else"            T_EQ "="                    T_EQ_EQ "=="%token T_EQ_EQ_EQ "==="         T_FINALLY "finally"         T_FOR "for"%token T_FUNCTION "function"    T_GE ">="                   T_GT ">"%token T_GT_GT ">>"             T_GT_GT_EQ ">>="            T_GT_GT_GT ">>>"%token T_GT_GT_GT_EQ ">>>="     T_IDENTIFIER "identifier"   T_IF "if"%token T_IN "in"                T_INSTANCEOF "instanceof"   T_LBRACE "{"%token T_LBRACKET "["           T_LE "<="                   T_LPAREN "("%token T_LT "<"                 T_LT_LT "<<"                T_LT_LT_EQ "<<="%token T_MINUS "-"              T_MINUS_EQ "-="             T_MINUS_MINUS "--"%token T_NEW "new"              T_NOT "!"                   T_NOT_EQ "!="%token T_NOT_EQ_EQ "!=="        T_NUMERIC_LITERAL "numeric literal"     T_OR "|"%token T_OR_EQ "|="             T_OR_OR "||"                T_PLUS "+"%token T_PLUS_EQ "+="           T_PLUS_PLUS "++"            T_QUESTION "?"%token T_RBRACE "}"             T_RBRACKET "]"              T_REMAINDER "%"%token T_REMAINDER_EQ "%="      T_RETURN "return"           T_RPAREN ")"%token T_SEMICOLON ";"          T_AUTOMATIC_SEMICOLON       T_STAR "*"%token T_STAR_EQ "*="           T_STRING_LITERAL "string literal"%token T_SWITCH "switch"        T_THIS "this"               T_THROW "throw"%token T_TILDE "~"              T_TRY "try"                 T_TYPEOF "typeof"%token T_VAR "var"              T_VOID "void"               T_WHILE "while"%token T_WITH "with"            T_XOR "^"                   T_XOR_EQ "^="%token T_NULL "null"            T_TRUE "true"               T_FALSE "false"%token T_CONST "const"%token T_RESERVED_WORD "reserved word"%start Program/./******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the $MODULE$ of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <QtCore/QtDebug>#include <string.h>#include "qscriptengine.h"#include "qscriptengine_p.h"#include "qscriptvalueimpl_p.h"#include "qscriptcontext_p.h"#include "qscriptmember_p.h"#include "qscriptobject_p.h"#include "qscriptlexer_p.h"#include "qscriptast_p.h"#include "qscriptnodepool_p.h"#define Q_SCRIPT_UPDATE_POSITION(node, startloc, endloc) do { \    node->startLine = startloc.startLine;     \    node->startColumn = startloc.startColumn; \    node->endLine = endloc.endLine;           \    node->endColumn = endloc.endColumn;       \} while (0).//:/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the $MODULE$ of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/////  W A R N I N G//  -------------//// This file is not part of the Qt API.  It exists purely as an// implementation detail.  This header file may change from version to// version without notice, or even be removed.//// We mean it.//#ifndef QSCRIPTPARSER_P_H#define QSCRIPTPARSER_P_H#include "qscriptgrammar_p.h"#include "qscriptastfwd_p.h"class QString;class QScriptEnginePrivate;class QScriptNameIdImpl;class QScriptParser: protected $table{public:    union Value {      int ival;      double dval;      QScriptNameIdImpl *sval;      QScript::AST::ArgumentList *ArgumentList;      QScript::AST::CaseBlock *CaseBlock;      QScript::AST::CaseClause *CaseClause;      QScript::AST::CaseClauses *CaseClauses;      QScript::AST::Catch *Catch;      QScript::AST::DefaultClause *DefaultClause;      QScript::AST::ElementList *ElementList;      QScript::AST::Elision *Elision;      QScript::AST::ExpressionNode *Expression;      QScript::AST::Finally *Finally;      QScript::AST::FormalParameterList *FormalParameterList;      QScript::AST::FunctionBody *FunctionBody;      QScript::AST::FunctionDeclaration *FunctionDeclaration;      QScript::AST::Node *Node;      QScript::AST::PropertyName *PropertyName;      QScript::AST::PropertyNameAndValueList *PropertyNameAndValueList;      QScript::AST::SourceElement *SourceElement;      QScript::AST::SourceElements *SourceElements;      QScript::AST::Statement *Statement;      QScript::AST::StatementList *StatementList;      QScript::AST::VariableDeclaration *VariableDeclaration;      QScript::AST::VariableDeclarationList *VariableDeclarationList;    };    struct Location {      int startLine;      int startColumn;      int endLine;      int endColumn;    };public:    QScriptParser();    ~QScriptParser();    bool parse(QScriptEnginePrivate *driver);    inline QString errorMessage() const    { return error_message; }    inline int errorLineNumber() const    { return error_lineno; }    inline int errorColumnNumber() const    { return error_column; }protected:    inline void reallocateStack();    inline Value &sym(int index)    { return sym_stack [tos + index - 1]; }    inline Location &loc(int index)    { return location_stack [tos + index - 2]; }protected:    int tos;    int stack_size;    Value *sym_stack;    int *state_stack;    Location *location_stack;    QString error_message;    int error_lineno;    int error_column;};inline void QScriptParser::reallocateStack(){    if (! stack_size)        stack_size = 128;    else        stack_size <<= 1;    sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value)));    state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));    location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location)));}#endif // QSCRIPTPARSER_P_H://.#include "qscriptparser_p.h"inline static bool automatic(QScriptEnginePrivate *driver, int token){    return token == $table::T_RBRACE        || token == 0        || driver->lexer()->prevTerminator();}QScriptParser::QScriptParser():    tos(0),    stack_size(0),    sym_stack(0),    state_stack(0),    location_stack(0){}QScriptParser::~QScriptParser(){    if (stack_size) {        qFree(sym_stack);        qFree(state_stack);        qFree(location_stack);    }}static inline QScriptParser::Location location(QScript::Lexer *lexer){    QScriptParser::Location loc;    loc.startLine = lexer->startLineNo();    loc.startColumn = lexer->startColumnNo();    loc.endLine = lexer->endLineNo();    loc.endColumn = lexer->endColumnNo();    return loc;}bool QScriptParser::parse(QScriptEnginePrivate *driver){  const int INITIAL_STATE = 0;  QScript::Lexer *lexer = driver->lexer();  int yytoken = -1;  int saved_yytoken = -1;  reallocateStack();  tos = 0;  state_stack[++tos] = INITIAL_STATE;  while (true)    {      const int state = state_stack [tos];      if (yytoken == -1 && - TERMINAL_COUNT != action_index [state])        {          if (saved_yytoken == -1)            {              yytoken = lexer->lex();              location_stack [tos] = location(lexer);            }          else            {              yytoken = saved_yytoken;              saved_yytoken = -1;            }        }      int act = t_action (state, yytoken);      if (act == ACCEPT_STATE)        return true;      else if (act > 0)        {          if (++tos == stack_size)            reallocateStack();          sym_stack [tos].dval = lexer->dval ();          state_stack [tos] = act;          location_stack [tos] = location(lexer);          yytoken = -1;        }      else if (act < 0)        {          int r = - act - 1;          tos -= rhs [r];          act = state_stack [tos++];          switch (r) {./PrimaryExpression: T_THIS ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::ThisExpression> (driver->nodePool());  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_IDENTIFIER ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::IdentifierExpression> (driver->nodePool(), sym(1).sval);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_NULL ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::NullExpression> (driver->nodePool());  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_TRUE ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::TrueLiteral> (driver->nodePool());  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_FALSE ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::FalseLiteral> (driver->nodePool());  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_NUMERIC_LITERAL ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::NumericLiteral> (driver->nodePool(), sym(1).dval);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_STRING_LITERAL ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::StringLiteral> (driver->nodePool(), sym(1).sval);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_DIVIDE_ ;/.case $rule_number: {  bool rx = lexer->scanRegExp();  if (!rx) {      error_message = lexer->errorMessage();      return false;  }  sym(1).Node = QScript::makeAstNode<QScript::AST::RegExpLiteral> (driver->nodePool(), lexer->pattern, lexer->flags);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(1));} break;./PrimaryExpression: T_LBRACKET ElisionOpt T_RBRACKET ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::ArrayLiteral> (driver->nodePool(), sym(2).Elision);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(3));} break;./PrimaryExpression: T_LBRACKET ElementList T_RBRACKET ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::ArrayLiteral> (driver->nodePool(), sym(2).ElementList->finish ());  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(3));} break;./PrimaryExpression: T_LBRACKET ElementList T_COMMA ElisionOpt T_RBRACKET ;/.case $rule_number: {  sym(1).Node = QScript::makeAstNode<QScript::AST::ArrayLiteral> (driver->nodePool(), sym(2).ElementList->finish (), sym(4).Elision);  Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(5));} break;./-- PrimaryExpression: T_LBRACE T_RBRACE ;-- /.-- case $rule_number: {--   sym(1).Node = QScript::makeAstNode<QScript::AST::ObjectLiteral> (driver->nodePool());--   Q_SCRIPT_UPDATE_POSITION(sym(1).Node, loc(1), loc(2));-- } break;-- ./

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -