/*
* Copyright (c) 2003
* David Leonard. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Mr Leonard nor the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DAVID LEONARD AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL DAVID LEONARD OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Id: parse.c 1126 2006-08-05 12:48:25Z d $ */
/*
* Combined parser and evaluator.
*
* This file contains two threads (storylines): the LL(2) recursive
* descent parser thread, and the semantic functions thread. The parsing and
* semantics stages are grouped together by their common productions in the
* grammar, to facilitate reference to the ECMA-262 standard.
*
* The input to the parser is an instance of the lexical analyser.
* The output of the parser is an abstract syntax tree (AST). The input to
* the evaluator is the AST, and the output of the evaluator is a SEE_value.
*
* For each production PROD in the grammar, the function PROD_parse()
* allocates and populates a 'node' structure, representing the root
* of the syntax tree that represents the parsed production. Each node
* holds a 'nodeclass' pointer to semantics information as well as
* production-specific information.
*
* Names of structures and functions have been chosen to correspond
* with the production names from the standard's grammar.
*
* The semantic functions in each node class are the following:
*
* - PROD_eval() functions are called at runtime to implement
* the behaviour of the program. They "evaluate" the program.
*
* - PROD_fproc() functions are called at execution time to generate
* the name/value bindings between container objects and included
* function objects. (It finds functions and assigns them to properties.)
* They provide a parallel, but independent, recusive semantic operation
* described in the standard as "process[ing] for function
* declarations".
*
* - PROD_print() functions are used to print the abstract syntax tree
* to stdout during debugging.
*
* TODO This file is far too big; need to split it up.
* TODO Compact/bytecode intermediate form
*
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if STDC_HEADERS
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
#endif
#include <see/mem.h>
#include <see/string.h>
#include <see/value.h>
#include <see/intern.h>
#include <see/object.h>
#include <see/cfunction.h>
#include <see/input.h>
#include <see/eval.h>
#include <see/try.h>
#include <see/error.h>
#include <see/debug.h>
#include <see/interpreter.h>
#include <see/context.h>
#include <see/system.h>
#include "lex.h"
#include "parse.h"
#include "scope.h"
#include "function.h"
#include "enumerate.h"
#include "tokens.h"
#include "stringdefs.h"
#include "dtoa.h"
#include "dprint.h"
#ifndef NDEBUG
int SEE_parse_debug = 0;
int SEE_eval_debug = 0;
#endif
/*------------------------------------------------------------
* structure types
*/
/*
* Abstract syntax tree basic structure
*/
struct node;
#if WITH_PARSER_PRINT
struct printer;
#endif
#if WITH_PARSER_VISIT
typedef void (*visitor_fn_t)(struct node *, void *);
#endif
struct nodeclass {
#ifndef NDEBUG
const char *decl_file; int decl_line;
struct nodeclass *superclass;
# define SUPERCLASS(cls) __FILE__, __LINE__, &cls##_nodeclass,
# define BASECLASS __FILE__, __LINE__, NULL,
#else
# define SUPERCLASS(cls)
# define BASECLASS
#endif
void (*eval)(struct node *, struct SEE_context *, struct SEE_value *);
void (*fproc)(struct node *, struct SEE_context *);
#if WITH_PARSER_PRINT
void (*print)(struct node *, struct printer *);
#endif
#if WITH_PARSER_VISIT
void (*visit)(struct node *, visitor_fn_t, void *);
#endif
int (*isconst)(struct node *, struct SEE_interpreter *);
};
#if WITH_PARSER_PRINT
# define PARSER_PRINT(fn) fn,
#else
# define PARSER_PRINT(fn) /* empty */
#endif
#if WITH_PARSER_VISIT
# define PARSER_VISIT(fn) fn,
#else
# define PARSER_VISIT(fn) /* empty */
#endif
struct node {
struct nodeclass *nodeclass;
struct SEE_throw_location location;
int isconst_valid : 1; /* true if isconst is valid */
int isconst : 1; /* true if node is a constant eval */
};
struct label {
struct SEE_string *name; /* interned */
struct SEE_string *labelset;
struct SEE_throw_location location;
struct label *next;
int continuable; /* can be target of continue */
};
#define COPY_LABELSET(dst, src) labelset_copy(dst, src);
#define UNGET_MAX 3
struct parser {
struct SEE_interpreter *interpreter;
struct lex *lex;
int unget, unget_end;
struct SEE_value unget_val[UNGET_MAX];
int unget_tok[UNGET_MAX];
int unget_lin[UNGET_MAX];
SEE_boolean_t unget_fnl[UNGET_MAX];
int noin; /* ignore 'in' in RelationalExpression */
int is_lhs; /* derived LeftHandSideExpression */
int funcdepth;
struct SEE_string*current_labelset;
struct label *labels;
struct var **vars; /* list of declared variables */
};
#if WITH_PARSER_PRINT
struct printerclass {
void (*print_string)(struct printer *, struct SEE_string *);
void (*print_char)(struct printer *, int);
void (*print_newline)(struct printer *, int);
void (*print_node)(struct printer *, struct node *);
};
struct printer {
struct printerclass *printerclass;
struct SEE_interpreter *interpreter;
int indent;
int bol;
};
#endif
struct Targetable_node {
struct node node;
void *target;
};
/*------------------------------------------------------------
* function prototypes
*/
struct Arguments_node;
struct ArrayLiteral_node;
struct AssignmentExpression_node;
struct Binary_node;
struct BreakStatement_node;
struct CallExpression_node;
struct ConditionalExpression_node;
struct ContinueStatement_node;
struct Function_node;
struct IfStatement_node;
struct IterationStatement_for_node;
struct IterationStatement_forin_node;
struct IterationStatement_while_node;
struct Literal_node;
struct MemberExpression_bracket_node;
struct MemberExpression_dot_node;
struct MemberExpression_new_node;
struct ObjectLiteral_node;
struct PrimaryExpression_ident_node;
struct RegularExpressionLiteral_node;
struct ReturnStatement_node;
struct SourceElements_node;
struct StringLiteral_node;
struct SwitchStatement_node;
struct TryStatement_node;
struct Unary_node;
struct VariableDeclaration_node;
static struct nodeclass Unary_nodeclass,
Binary_nodeclass,
Literal_nodeclass,
StringLiteral_nodeclass,
RegularExpressionLiteral_nodeclass,
PrimaryExpression_this_nodeclass,
PrimaryExpression_ident_nodeclass,
ArrayLiteral_nodeclass,
ObjectLiteral_nod
没有合适的资源?快使用搜索试试~ 我知道了~
see-2.0.1131.tar.gz_Run Time
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 113 浏览量
2022-09-21
05:42:41
上传
评论
收藏 926KB GZ 举报
温馨提示
共166个文件
c:55个
h:43个
in:15个
SEE is a library that provides an ECMAScript (JavaScript) run-time environment.
资源推荐
资源详情
资源评论
收起资源包目录
see-2.0.1131.tar.gz_Run Time (166个子文件)
configure.ac 13KB
configure.ac 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 884B
Makefile.am 798B
Makefile.am 763B
Makefile.am 697B
Makefile.am 133B
Makefile.am 123B
AUTHORS 147B
parse.c 243KB
ltdl.c 96KB
dtoa.c 67KB
obj_Date.c 55KB
regex.c 44KB
obj_String.c 34KB
obj_Array.c 33KB
obj_Function.c 32KB
obj_Global.c 26KB
lex.c 24KB
mod_File.c 20KB
obj_RegExp.c 20KB
debug.c 20KB
string.c 16KB
obj_Number.c 16KB
obj_Math.c 15KB
native.c 13KB
obj_Object.c 11KB
main.c 11KB
cfunction.c 10KB
input_file.c 10KB
obj_Error.c 10KB
value.c 10KB
intern.c 10KB
shell.c 9KB
printf.c 9KB
debug.c 8KB
system.c 7KB
tokens.c 7KB
obj_Boolean.c 7KB
enumerate.c 6KB
error.c 6KB
mem.c 5KB
platform_posix.c 5KB
function.c 5KB
try.c 4KB
input_utf8.c 4KB
object.c 4KB
interpreter.c 4KB
no.c 4KB
input_lookahead.c 4KB
scope.c 4KB
input_string.c 3KB
compat.c 3KB
getopt.c 3KB
module.c 3KB
unicase.c 3KB
dprint.c 2KB
module.c 2KB
version.c 2KB
memcmp.c 2KB
stringdefs.c 2KB
unicode.c 2KB
test1.c 1KB
readline.c 1KB
ChangeLog 41KB
compile 4KB
configure 895KB
configure 756KB
COPYING 3KB
string.defs 7KB
depcomp 16KB
config.guess 42KB
config.guess 42KB
ltdl.h 12KB
stringdefs.h 10KB
object.h 7KB
value.h 5KB
type.h 5KB
try.h 4KB
interpreter.h 4KB
error.h 3KB
string.h 3KB
native.h 3KB
input.h 2KB
lex.h 2KB
unicode.h 2KB
dtoa_config.h 2KB
mem.h 2KB
version.h 2KB
function.h 2KB
init.h 2KB
system.h 1KB
nmath.h 1KB
regex.h 1KB
intern.h 1KB
parse.h 1006B
no.h 1002B
共 166 条
- 1
- 2
资源评论
朱moyimi
- 粉丝: 64
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功