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

📄 compiler.js

📁 一个类似windows
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*
 * Internal definitions.
 * Copyright (c) 1998 New Generation Software (NGS) Oy
 *
 * Author: Markku Rossi <mtr@ngs.fi>
 */

/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA
 */

/*
 * $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/jsc/compiler.js,v $
 * $Id: compiler.js 21681 2006-04-21 15:00:24Z peterw $
 */

/*
 * Constants.
 */

/* Tokens. */

JSC$tEOF 	= 128;
JSC$tINTEGER	= 129;
JSC$tFLOAT 	= 130;
JSC$tSTRING	= 131;
JSC$tIDENTIFIER	= 132;

JSC$tBREAK 	= 133;
JSC$tCONTINUE 	= 134;
JSC$tDELETE 	= 135;
JSC$tELSE 	= 136;
JSC$tFOR 	= 137;
JSC$tFUNCTION	= 138;
JSC$tIF 	= 139;
JSC$tIN 	= 140;
JSC$tNEW 	= 141;
JSC$tRETURN 	= 142;
JSC$tTHIS 	= 143;
JSC$tTYPEOF 	= 144;
JSC$tVAR 	= 145;
JSC$tVOID 	= 146;
JSC$tWHILE	= 147;
JSC$tWITH 	= 148;

JSC$tCASE	= 149;
JSC$tCATCH	= 150;
JSC$tCLASS	= 151;
JSC$tCONST	= 152;
JSC$tDEBUGGER	= 153;
JSC$tDEFAULT	= 154;
JSC$tDO		= 155;
JSC$tENUM	= 156;
JSC$tEXPORT	= 157;
JSC$tEXTENDS	= 158;
JSC$tFINALLY	= 159;
JSC$tIMPORT	= 160;
JSC$tSUPER	= 161;
JSC$tSWITCH	= 162;
JSC$tTHROW	= 163;
JSC$tTRY	= 164;

JSC$tNULL 	= 165;
JSC$tTRUE 	= 166;
JSC$tFALSE 	= 167;

JSC$tEQUAL 	= 168;
JSC$tNEQUAL 	= 169;
JSC$tLE 	= 170;
JSC$tGE 	= 171;
JSC$tAND 	= 172;
JSC$tOR 	= 173;
JSC$tPLUSPLUS 	= 174;
JSC$tMINUSMINUS	= 175;
JSC$tMULA	= 176;
JSC$tDIVA	= 177;
JSC$tMODA	= 178;
JSC$tADDA	= 179;
JSC$tSUBA	= 180;
JSC$tANDA	= 181;
JSC$tXORA	= 182;
JSC$tORA	= 183;
JSC$tLSIA	= 184;
JSC$tLSHIFT	= 185;
JSC$tRSHIFT	= 186;
JSC$tRRSHIFT	= 187;
JSC$tRSIA	= 188;
JSC$tRRSA	= 189;
JSC$tSEQUAL	= 190;
JSC$tSNEQUAL	= 191;


/* Expressions. */

JSC$EXPR_COMMA			= 0;
JSC$EXPR_ASSIGNMENT		= 1;
JSC$EXPR_QUEST_COLON		= 2;
JSC$EXPR_LOGICAL		= 3;
JSC$EXPR_BITWISE		= 4;
JSC$EXPR_EQUALITY		= 5;
JSC$EXPR_RELATIONAL		= 6;
JSC$EXPR_SHIFT			= 7;
JSC$EXPR_MULTIPLICATIVE		= 8;
JSC$EXPR_ADDITIVE		= 9;
JSC$EXPR_THIS			= 10;
JSC$EXPR_NULL			= 11;
JSC$EXPR_TRUE			= 12;
JSC$EXPR_FALSE			= 13;
JSC$EXPR_IDENTIFIER		= 14;
JSC$EXPR_FLOAT			= 15;
JSC$EXPR_INTEGER		= 16;
JSC$EXPR_STRING			= 17;
JSC$EXPR_CALL			= 18;
JSC$EXPR_OBJECT_PROPERTY	= 19;
JSC$EXPR_OBJECT_ARRAY		= 20;
JSC$EXPR_NEW			= 21;
JSC$EXPR_DELETE			= 22;
JSC$EXPR_VOID			= 23;
JSC$EXPR_TYPEOF			= 24;
JSC$EXPR_PREFIX			= 25;
JSC$EXPR_POSTFIX		= 26;
JSC$EXPR_UNARY			= 27;
JSC$EXPR_REGEXP			= 28;
JSC$EXPR_ARRAY_INITIALIZER	= 29;
JSC$EXPR_OBJECT_INITIALIZER	= 30;

/* Statements */

JSC$STMT_BLOCK			= 0;
JSC$STMT_FUNCTION_DECLARATION	= 1;
JSC$STMT_VARIABLE		= 2;
JSC$STMT_EMPTY			= 3;
JSC$STMT_EXPR			= 4;
JSC$STMT_IF			= 5;
JSC$STMT_WHILE			= 6;
JSC$STMT_FOR			= 7;
JSC$STMT_FOR_IN			= 8;
JSC$STMT_CONTINUE		= 9;
JSC$STMT_BREAK			= 10;
JSC$STMT_RETURN			= 11;
JSC$STMT_WITH			= 12;
JSC$STMT_TRY			= 13;
JSC$STMT_THROW			= 14;
JSC$STMT_DO_WHILE		= 15;
JSC$STMT_SWITCH			= 16;
JSC$STMT_LABELED_STMT		= 17;

/* JavaScript types. */

JSC$JS_UNDEFINED	= 0;
JSC$JS_NULL		= 1;
JSC$JS_BOOLEAN		= 2;
JSC$JS_INTEGER		= 3;
JSC$JS_STRING		= 4;
JSC$JS_FLOAT		= 5;
JSC$JS_ARRAY		= 6;
JSC$JS_OBJECT		= 7;
JSC$JS_BUILTIN		= 11;


/*
Local variables:
mode: c
End:
*/
/*
 * Lexer.
 * Copyright (c) 1998-1999 New Generation Software (NGS) Oy
 *
 * Author: Markku Rossi <mtr@ngs.fi>
 */

/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA
 */

/*
 * $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/jsc/compiler.js,v $
 * $Id: compiler.js 21681 2006-04-21 15:00:24Z peterw $
 */

/*
 * Global functions.
 */

function JSC$lexer (stream)
{
  var ch, ch2;

  JSC$token_value = null;

  while ((ch = stream.readByte ()) != -1)
    {
      if (ch == #'\n')
	{
	  JSC$linenum++;
	  continue;
	}

      if (JSC$lexer_is_white_space (ch))
	continue;

      JSC$token_linenum = JSC$linenum;

      if (ch == #'/' && JSC$lexer_peek_char (stream) == #'*')
	{
	  /* Multi line comment. */
	  stream.readByte ();
	  while ((ch = stream.readByte ()) != -1
		 && (ch != #'*' || JSC$lexer_peek_char (stream) != #'/'))
	    if (ch == #'\n')
	      JSC$linenum++;

	  /* Consume the peeked #'/' character. */
	  stream.readByte ();
	}
      else if ((ch == #'/' && JSC$lexer_peek_char (stream) == #'/')
	       || (ch == #'#' && JSC$lexer_peek_char (stream) == #'!'))
	{
	  /* Single line comment. */
	  while ((ch = stream.readByte ()) != -1 && ch != #'\n')
	    ;
	  if (ch == #'\n')
	    JSC$linenum++;
	}
      else if (ch == #'"' || ch == #'\'')
	{
	  /* String constant. */
	  JSC$token_value = JSC$lexer_read_string (stream, "string", ch);
	  return JSC$tSTRING;
	}

      /* Literals. */
      else if (ch == #'=' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  if (JSC$lexer_peek_char (stream) == #'=')
	    {
	      stream.readByte ();
	      return JSC$tSEQUAL;
	    }
	  return JSC$tEQUAL;
	}
      else if (ch == #'!' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  if (JSC$lexer_peek_char (stream) == #'=')
	    {
	      stream.readByte ();
	      return JSC$tSNEQUAL;
	    }
	  return JSC$tNEQUAL;
	}
      else if (ch == #'<' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tLE;
	}
      else if (ch == #'>' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tGE;
	}
      else if (ch == #'&' && JSC$lexer_peek_char (stream) == #'&')
	{
	  stream.readByte ();
	  return JSC$tAND;
	}
      else if (ch == #'|' && JSC$lexer_peek_char (stream) == #'|')
	{
	  stream.readByte ();
	  return JSC$tOR;
	}
      else if (ch == #'+' && JSC$lexer_peek_char (stream) == #'+')
	{
	  stream.readByte ();
	  return JSC$tPLUSPLUS;
	}
      else if (ch == #'-' && JSC$lexer_peek_char (stream) == #'-')
	{
	  stream.readByte ();
	  return JSC$tMINUSMINUS;
	}
      else if (ch == #'*' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tMULA;
	}
      else if (ch == #'/' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tDIVA;
	}
      else if (ch == #'%' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tMODA;
	}
      else if (ch == #'+' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tADDA;
	}
      else if (ch == #'-' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tSUBA;
	}
      else if (ch == #'&' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tANDA;
	}
      else if (ch == #'^' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tXORA;
	}
      else if (ch == #'|' && JSC$lexer_peek_char (stream) == #'=')
	{
	  stream.readByte ();
	  return JSC$tORA;
	}
      else if (ch == #'<' && JSC$lexer_peek_char (stream) == #'<')
	{
	  stream.readByte ();
	  if (JSC$lexer_peek_char (stream) == #'=')
	    {
	      stream.readByte ();
	      return JSC$tLSIA;
	    }
	  else
	    return JSC$tLSHIFT;
	}
      else if (ch == #'>' && JSC$lexer_peek_char (stream) == #'>')
	{
	  stream.readByte ();
	  ch2 = JSC$lexer_peek_char (stream);
	  if (ch2 == #'=')
	    {
	      stream.readByte ();
	      return JSC$tRSIA;
	    }
	  else if (ch2 == #'>')
	    {
	      stream.readByte ();
	      if (JSC$lexer_peek_char (stream) == #'=')
		{
		  stream.readByte ();
		  return JSC$tRRSA;
		}
	      else
		return JSC$tRRSHIFT;
	    }
	  else
	    return JSC$tRSHIFT;
	}

      /* Identifiers and keywords. */
      else if (JSC$lexer_is_identifier_letter (ch))
	{
	  /* An identifier. */
	  var id = String.fromCharCode (ch);

	  while ((ch = stream.readByte ()) != -1
		 && (JSC$lexer_is_identifier_letter (ch)
		     || JSC$lexer_is_decimal_digit (ch)))
	    id.append (File.byteToString (ch));
	  stream.ungetByte (ch);

	  /* Keywords. */
	  if (id == "break")
	    return JSC$tBREAK;
	  else if (id == "continue")
	    return JSC$tCONTINUE;
	  else if (id == "delete")
	    return JSC$tDELETE;
	  else if (id == "else")
	    return JSC$tELSE;
	  else if (id == "for")
	    return JSC$tFOR;
	  else if (id == "function")
	    return JSC$tFUNCTION;
	  else if (id == "if")
	    return JSC$tIF;
	  else if (id == "in")
	    return JSC$tIN;
	  else if (id == "new")
	    return JSC$tNEW;
	  else if (id == "return")
	    return JSC$tRETURN;
	  else if (id == "this")
	    return JSC$tTHIS;
	  else if (id == "typeof")
	    return JSC$tTYPEOF;
	  else if (id == "var")
	    return JSC$tVAR;
	  else if (id == "void")
	    return JSC$tVOID;
	  else if (id == "while")
	    return JSC$tWHILE;
	  else if (id == "with")
	    return JSC$tWITH;

	  /*
	   * Future reserved keywords (some of these is already in use
	   * in this implementation).
	   */
	  else if (id == "case")
	    return JSC$tCASE;
	  else if (id == "catch")
	    return JSC$tCATCH;
	  else if (id == "class")
	    return JSC$tCLASS;
	  else if (id == "const")
	    return JSC$tCONST;
	  else if (id == "debugger")
	    return JSC$tDEBUGGER;
	  else if (id == "default")
	    return JSC$tDEFAULT;
	  else if (id == "do")
	    return JSC$tDO;
	  else if (id == "enum")
	    return JSC$tENUM;
	  else if (id == "export")
	    return JSC$tEXPORT;
	  else if (id == "extends")
	    return JSC$tEXTENDS;
	  else if (id == "finally")
	    return JSC$tFINALLY;
	  else if (id == "import")
	    return JSC$tIMPORT;
	  else if (id == "super")
	    return JSC$tSUPER;
	  else if (id == "switch")
	    return JSC$tSWITCH;
	  else if (id == "throw")
	    return JSC$tTHROW;
	  else if (id == "try")
	    return JSC$tTRY;

	  /* Null and boolean literals. */
	  else if (id == "null")
	    return JSC$tNULL;
	  else if (id == "true")
	    return JSC$tTRUE;
	  else if (id == "false")
	    return JSC$tFALSE;
	  else
	    {
	      /* It really is an identifier. */
	      JSC$token_value = id;
	      return JSC$tIDENTIFIER;
	    }
	}

      /* Character constants. */
      else if (ch == #'#' && JSC$lexer_peek_char (stream) == #'\'')
	{
	  /* Skip the starting #'\'' and read more. */
	  stream.readByte ();

	  ch = stream.readByte ();
	  if (ch == #'\\')
	    {
	      JSC$token_value
		= JSC$lexer_read_backslash_escape (stream, 0, "character");

	      if (stream.readByte () != #'\'')
		error (JSC$filename + ":" + JSC$linenum.toString ()
		       + ": malformed character constant");
	    }
	  else if (JSC$lexer_peek_char (stream) == #'\'')
	    {
	      stream.readByte ();
	      JSC$token_value = ch;
	    }
	  else
	    error (JSC$filename + ":" + JSC$linenum.toString ()
		   + ": malformed character constant");

	  return JSC$tINTEGER;
	}

      /* Octal and hex numbers. */
      else if (ch == #'0'
	       && JSC$lexer_peek_char (stream) != #'.'
	       && JSC$lexer_peek_char (stream) != #'e'
	       && JSC$lexer_peek_char (stream) != #'E')
	{
	  JSC$token_value = 0;
	  ch = stream.readByte ();
	  if (ch == #'x' || ch == #'X')
	    {
	      ch = stream.readByte ();
	      while (JSC$lexer_is_hex_digit (ch))
		{
		  JSC$token_value *= 16;
		  JSC$token_value += JSC$lexer_hex_to_dec (ch);
		  ch = stream.readByte ();
		}
	      stream.ungetByte (ch);
	    }
	  else
	    {
	      while (JSC$lexer_is_octal_digit (ch))
		{
		  JSC$token_value *= 8;
		  JSC$token_value += ch - #'0';

⌨️ 快捷键说明

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