📄 compiler.js
字号:
ch = stream.readByte ();
}
stream.ungetByte (ch);
}
return JSC$tINTEGER;
}
/* Decimal numbers. */
else if (JSC$lexer_is_decimal_digit (ch)
|| (ch == #'.'
&& JSC$lexer_is_decimal_digit (
JSC$lexer_peek_char (stream))))
{
var is_float = false;
var buf = new String (File.byteToString (ch));
var accept_dot = true;
if (ch == #'.')
{
/*
* We started with #'.' and we know that the next character
* is a decimal digit (we peeked it).
*/
is_float = true;
ch = stream.readByte ();
while (JSC$lexer_is_decimal_digit (ch))
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
}
accept_dot = false;
}
else
{
/* We did start with a decimal digit. */
ch = stream.readByte ();
while (JSC$lexer_is_decimal_digit (ch))
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
}
}
if ((accept_dot && ch == #'.')
|| ch == #'e' || ch == #'E')
{
is_float = true;
if (ch == #'.')
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
while (JSC$lexer_is_decimal_digit (ch))
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
}
}
if (ch == #'e' || ch == #'E')
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
if (ch == #'+' || ch == #'-')
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
}
if (!JSC$lexer_is_decimal_digit (ch))
error (JSC$filename + ":" + JSC$linenum.toString ()
+ ": malformed exponent part in a decimal literal");
while (JSC$lexer_is_decimal_digit (ch))
{
buf.append (File.byteToString (ch));
ch = stream.readByte ();
}
}
}
/* Finally, we put the last character pack to the stream. */
stream.ungetByte (ch);
if (is_float)
{
JSC$token_value = parseFloat (buf);
return JSC$tFLOAT;
}
JSC$token_value = parseInt (buf);
return JSC$tINTEGER;
}
/* Just return the character as-is. */
else
return ch;
}
/* EOF reached. */
return JSC$tEOF;
}
/*
* Help functions.
*/
function JSC$lexer_peek_char (stream)
{
var ch2 = stream.readByte ();
stream.ungetByte (ch2);
return ch2;
}
function JSC$lexer_is_identifier_letter (ch)
{
return ((#'a' <= ch && ch <= #'z') || (#'A' <= ch && ch <= #'Z')
|| ch == #'$' || ch == #'_');
}
function JSC$lexer_is_octal_digit (ch)
{
return (#'0' <= ch && ch <= #'7');
}
function JSC$lexer_is_decimal_digit (ch)
{
return #'0' <= ch && ch <= #'9';
}
function JSC$lexer_is_hex_digit (ch)
{
return ((#'0' <= ch && ch <= #'9')
|| (#'a' <= ch && ch <= #'f')
|| (#'A' <= ch && ch <= #'F'));
}
function JSC$lexer_is_white_space (ch)
{
return (ch == #' ' || ch == #'\t' || ch == #'\v' || ch == #'\r'
|| ch == #'\f' || ch == #'\n');
}
function JSC$lexer_hex_to_dec (ch)
{
return ((#'0' <= ch && ch <= #'9')
? ch - #'0'
: ((#'a' <= ch && ch <= #'f')
? 10 + ch - #'a'
: 10 + ch - #'A'));
}
function JSC$lexer_read_backslash_escape (stream, possible_start, name)
{
var ch = stream.readByte ();
if (ch == #'n')
ch = #'\n';
else if (ch == #'t')
ch = #'\t';
else if (ch == #'v')
ch = #'\v';
else if (ch == #'b')
ch = #'\b';
else if (ch == #'r')
ch = #'\r';
else if (ch == #'f')
ch = #'\f';
else if (ch == #'a')
ch = #'\a';
else if (ch == #'\\')
ch = #'\\';
else if (ch == #'?')
ch = #'?';
else if (ch == #'\'')
ch = #'\'';
else if (ch == #'"')
ch = #'"';
else if (ch == #'x')
{
/* HexEscapeSequence. */
var c1, c2;
c1 = stream.readByte ();
c2 = stream.readByte ();
if (c1 == -1 || c2 == -1)
JSC$lexer_eof_in_constant (possible_start, name);
if (!JSC$lexer_is_hex_digit (c1) || !JSC$lexer_is_hex_digit (c2))
error (JSC$filename + ":" + JSC$linenum.toString ()
+ ": \\x used with no following hex digits");
ch = (JSC$lexer_hex_to_dec (c1) << 4) + JSC$lexer_hex_to_dec (c2);
}
else if (ch == #'u')
{
/* UnicodeEscapeSequence. */
var c1, c2, c3, c4;
c1 = stream.readByte ();
c2 = stream.readByte ();
c3 = stream.readByte ();
c4 = stream.readByte ();
if (c1 == -1 || c2 == -1 || c3 == -1 || c4 == -1)
JSC$lexer_eof_in_constant (possible_start, name);
if (!JSC$lexer_is_hex_digit (c1) || !JSC$lexer_is_hex_digit (c2)
|| !JSC$lexer_is_hex_digit (c3) || !JSC$lexer_is_hex_digit (c4))
error (JSC$filename + ":" + JSC$linenum.toString ()
+ ": \\u used with no following hex digits");
ch = ((JSC$lexer_hex_to_dec (c1) << 12)
+ (JSC$lexer_hex_to_dec (c2) << 8)
+ (JSC$lexer_hex_to_dec (c3) << 4)
+ JSC$lexer_hex_to_dec (c4));
}
else if (JSC$lexer_is_octal_digit (ch))
{
var result = ch - #'0';
var i = 1;
if (ch == #'0')
/* Allow three octal digits after '0'. */
i = 0;
ch = stream.readByte ();
while (i < 3 && JSC$lexer_is_octal_digit (ch))
{
result *= 8;
result += ch - #'0';
ch = stream.readByte ();
i++;
}
stream.ungetByte (ch);
ch = result;
}
else
{
if (ch == -1)
error (JSC$filename + ":" + JSC$linenum.toString ()
+ ": unterminated " + name);
JSC$warning (JSC$filename + ":" + JSC$linenum.toString ()
+ ": warning: unknown escape sequence `\\"
+ File.byteToString (ch) + "'");
}
return ch;
}
function JSC$lexer_read_string (stream, name, ender)
{
var str = new String ("");
var done = false, ch;
var possible_start_ln = JSC$linenum;
var warned_line_terminator = false;
while (!done)
{
ch = stream.readByte ();
if (ch == #'\n')
{
if (JSC$warn_strict_ecma && !warned_line_terminator)
{
JSC$warning (JSC$filename + ":" + JSC$linenum.toString ()
+ ": warning: ECMAScript don't allow line terminators in "
+ name + " constants");
warned_line_terminator = true;
}
JSC$linenum++;
}
if (ch == -1)
JSC$lexer_eof_in_constant (possible_start_ln, name);
else if (ch == ender)
done = true;
else
{
if (ch == #'\\')
{
if (JSC$lexer_peek_char (stream) == #'\n')
{
/*
* Backslash followed by a newline character. Ignore
* them both.
*/
stream.readByte ();
JSC$linenum++;
continue;
}
ch = JSC$lexer_read_backslash_escape (stream, possible_start_ln,
name);
}
str.append (ch);
}
}
return str;
}
function JSC$lexer_read_regexp_constant (stream)
{
/* Regexp literal. */
var source = JSC$lexer_read_regexp_source (stream);
/* Check the possible flags. */
var flags = new String ("");
while ((ch = JSC$lexer_peek_char (stream)) == #'g' || ch == #'i')
{
stream.readByte ();
flags.append (File.byteToString (ch));
}
/* Try to compile it. */
var msg = false;
var result;
try
{
result = new RegExp (source, flags);
}
catch (msg)
{
var start = msg.lastIndexOf (":");
msg = (JSC$filename + ":" + JSC$token_linenum.toString ()
+ ": malformed regular expression constant:"
+ msg.substr (start + 1));
}
if (msg)
error (msg);
/* Success. */
return result;
}
function JSC$lexer_read_regexp_source (stream)
{
var str = new String ("");
var done = false, ch;
var possible_start_ln = JSC$linenum;
var warned_line_terminator = false;
var name = "regular expression";
while (!done)
{
ch = stream.readByte ();
if (ch == #'\n')
{
if (JSC$warn_strict_ecma && !warned_line_terminator)
{
JSC$warning (JSC$filename + ":" + JSC$linenum.toString ()
+ ": warning: ECMAScript don't allow line "
+ "terminators in " + name + " constants");
warned_line_terminator = true;
}
JSC$linenum++;
}
if (ch == -1)
JSC$lexer_eof_in_constant (possible_start_ln, name);
else if (ch == #'/')
done = true;
else
{
if (ch == #'\\')
{
ch = stream.readByte ();
if (ch == #'\n')
{
/*
* Backslash followed by a newline character. Ignore
* them both.
*/
JSC$linenum++;
continue;
}
if (ch == -1)
JSC$lexer_eof_in_constant (possible_start_ln, name);
/* Handle the backslash escapes. */
if (ch == #'f')
ch = #'\f';
else if (ch == #'n')
ch = #'\n';
else if (ch == #'r')
ch = #'\r';
else if (ch == #'t')
ch = #'\t';
else if (ch == #'v')
ch == #'\v';
else if (ch == #'c')
{
/* SourceCharacter. */
ch = stream.readByte ();
if (ch == -1)
JSC$lexer_eof_in_constant (possible_start_ln, name);
if (ch == #'\n' && JSC$warn_strict_ecma)
JSC$warning (JSC$filename + ":" + JSC$linenum.toString ()
+ ": warning: ECMAScript don't allow line termiantor after \\c in regular expression constants");
/*
* Append the source-character escape start. The ch
* will be appended later.
*/
str.append ("\\c");
}
else if (ch == #'u' || ch == #'x' || ch == #'0')
{
/* These can be handled with the read_backslash_escape(). */
stream.ungetByte (ch);
ch = JSC$lexer_read_backslash_escape (stream);
}
else
{
/*
* Nothing special. Leave it to the result as-is.
* The regular expression backage will handle it.
*/
stream.ungetByte (ch);
ch = #'\\';
}
}
str.append (File.byteToString (ch));
}
}
return str;
}
function JSC$lexer_eof_in_constant (possible_start, name)
{
var msg = (JSC$filename + ":" + JSC$linenum.toString ()
+ ": unterminated " + name + " constant");
if (possible_start > 0)
msg += (System.lineBreakSequence
+ JSC$filename + ":" + possible_start.toString ()
+ ": possible real start of unterminated " + name + " constant");
error (msg);
}
/*
Local variables:
mode: c
End:
*/
/*
* Parser.
* 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 $
*/
/*
* Global functions.
*/
function JSC$parser_reset ()
{
JSC$function = null;
JSC$global_stmts = null;
JSC$nested_function_declarations = null;
}
function JSC$parser_parse (stream)
{
JSC$linenum = 1;
JSC$filename = stream.name;
JSC$functions = new Array ();
JSC$global_stmts = new Array ();
JSC$nested_function_declarations = new Array ();
JSC$anonymous_function_count = 0;
JSC$parser_peek_token_valid = false;
JSC$num_tokens = 0;
JSC$num_arguments_identifiers = 0;
JSC$num_missing_semicolons = 0;
if (JSC$verbose)
JSC$message ("jsc: parsing");
while (JSC$parser_peek_token (stream) != JSC$tEOF)
if (!JSC$parser_parse_source_element (stream))
JSC$parser_syntax_error ();
if (JSC$verbose)
{
var msg = ("jsc: input stream had " + (JSC$linenum - 1).toString ()
+ " lines, " + JSC$num_tokens.toString () + " tokens");
if (JSC$num_missing_semicolons > 0)
msg += (", " + JSC$num_missing_semicolons.toString ()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -