本文整理汇总了C++中parse_expr函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_expr函数的具体用法?C++ parse_expr怎么用?C++ parse_expr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_expr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_grouped_expr
// Parse a grouped expression.
//
// grouped-expr ::= '(' [comma-expr]? ')'s
//
// Note the this is only a grouped expression when the form
// is '(e)' where 'e' is some expression. If the expression
// is of the form '()' or '(e1, ..., en)', then this is a comma
// epxression.
Tree*
parse_grouped_expr(Parser& p) {
if (const Token* k = parse::accept(p, lparen_tok)) {
// This is a comma expression.
if (parse::accept(p, rparen_tok))
return new Comma_tree(k, new Tree_seq());
if (Tree* t = parse_expr(p)) {
// This is a grouped subexpression.
if (parse::accept(p, rparen_tok)) {
return t;
}
// This is a grouped sub-expression.
Tree_seq* ts = new Tree_seq {t};
while (parse::accept(p, comma_tok)) {
if (Tree* t = parse_expr(p))
ts->push_back(t);
else
return nullptr;
}
// Make sure we have a closing rparen.
if (parse::expect(p, rparen_tok)) {
return new Comma_tree(k, ts);
}
} else {
parse::parse_error(p) << "expected 'expr' after '('";
}
}
return nullptr;
}
开发者ID:rishi1234,项目名称:waffle,代码行数:40,代码来源:parser.cpp
示例2: alloc_v_memory
/* allocate stuff for volterra equations */
void alloc_v_memory(void) {
int i, len, formula[256], j;
/* First parse the kernels since these were deferred */
for (i = 0; i < NKernel; i++) {
kernel[i].k_n = 0.0;
if (parse_expr(kernel[i].expr, formula, &len)) {
plintf("Illegal kernel %s=%s\n", kernel[i].name, kernel[i].expr);
exit(0); /* fatal error ... */
}
kernel[i].formula = (int *)malloc((len + 2) * sizeof(int));
for (j = 0; j < len; j++) {
kernel[i].formula[j] = formula[j];
}
if (kernel[i].flag == CONV) {
if (parse_expr(kernel[i].kerexpr, formula, &len)) {
plintf("Illegal convolution %s=%s\n", kernel[i].name,
kernel[i].kerexpr);
exit(0); /* fatal error ... */
}
kernel[i].kerform = (int *)malloc((len + 2) * sizeof(int));
for (j = 0; j < len; j++) {
kernel[i].kerform[j] = formula[j];
}
}
}
allocate_volterra(MaxPoints, 0);
}
开发者ID:tommie,项目名称:xppaut,代码行数:30,代码来源:volterra2.c
示例3: parse_number_or_pair
pointer parse_number_or_pair(parser* parse)
{
char next = (*(parse->curr+1));
pointer ret_car;
pointer ret_cdr;
if(is_whitespace(next))
{
parse->curr++;
return parse_expr(parse);
}
else if(next >= '0' && next <= '9')
{
ret_car = parse_number(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
else
{
ret_car = parse_symbol(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
}
开发者ID:Arelius,项目名称:ploy,代码行数:25,代码来源:parser.cpp
示例4: parse_expr
pointer parse_expr(parser* parse)
{
eat_whitespace(parse);
pointer ret_car;
pointer ret_cdr;
switch(*parse->curr)
{
case '(':
parse->curr++;
ret_car = parse_expr(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '"':
ret_car = parse_string(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '\'':
parse->curr++;
ret_car = parse_quote(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case ')':
parse->curr++;
return NIL;
case '+': case '-': case 'b':
ret_car = parse_number_or_symbol(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '.':
return parse_number_or_pair(parse);
case '\\':
parse->curr++;
ret_car = create_char(*(parse->curr++));
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case ';':
while(!is_newline(*parse->curr) && *parse->curr != '\0')
parse->curr++;
return parse_expr(parse);
case 0:
return NIL;
default:
if(is_number_char(*parse->curr))
{
ret_car = parse_number(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
else if(is_symbol_char(*parse->curr))
{
ret_car = parse_symbol(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
else
return parser_error(parse, "Unexpected char in expression.");
}
parse->curr++;
}
开发者ID:Arelius,项目名称:ploy,代码行数:60,代码来源:parser.cpp
示例5: parse_operand
/* Does not do much useful parsing yet. */
int parse_operand(char *p,int len,operand *op,int requires)
{
p=skip(p);
if(len==2&&(p[0]=='r'||p[0]=='R')&&p[1]>='0'&&p[1]<='3'){
op->type=OP_REG;
op->basereg=p[1]-'0';
}else if(p[0]=='#'){
op->type=OP_IMM32;
p=skip(p+1);
op->offset=parse_expr(&p);
}else{
int parent=0;
expr *tree;
op->type=-1;
if(*p=='('){
parent=1;
p=skip(p+1);
}
tree=parse_expr(&p);
if(!tree)
return 0;
p=skip(p);
if(parent){
if(*p==','){
p=skip(p+1);
if((*p!='r'&&*p!='R')||p[1]<'0'||p[1]>'3'){
cpu_error(0);
return 0;
}
op->type=OP_REGIND;
op->basereg=p[1]-'0';
p=skip(p+2);
}
if(*p!=')'){
cpu_error(0);
return 0;
}else
p=skip(p+1);
}
if(op->type!=OP_REGIND)
op->type=OP_ABS;
op->offset=tree;
}
if(requires==op->type)
return 1;
if(requires==OP_ALL_DEST&&op->type!=OP_IMM32)
return 1;
if(requires==OP_MEM&&OP_ISMEM(op->type))
return 1;
if(requires==OP_ALL)
return 1;
return 0;
}
开发者ID:ezrec,项目名称:vasm,代码行数:54,代码来源:cpu.c
示例6: parse_arg_expr_list
expr_list_t parse_arg_expr_list(tokenizer_t t) {
expr_list_t l = mk_expr_list();
expr_t x;
if(cur_tok(t).kind != TOK_RPAREN) {
x = parse_expr(t);
expr_list_add(l, x);
while(cur_tok(t).kind != TOK_RPAREN) {
eat_it(t, TOK_COMMA);
x = parse_expr(t);
expr_list_add(l, x);
}
}
return l;
}
开发者ID:nukamu,项目名称:c0_compiler,代码行数:14,代码来源:parser.c
示例7: parse_bool
/*
parse_bool
Matches a valid boolean expression by looking ahead one token
Parameters: none
Return: none
*/
void parse_bool(Tree &cst){
cst.add_branch_node("boolean");
if(!(curr_token -> type).compare("open_paren")){
match_type("open_paren", cst);
parse_expr(cst);
match(boolop, cst);
parse_expr(cst);
match(")", cst);
}
else{
match(boolval, cst);
}
cst.kill_all_children();
}
开发者ID:jbancamper,项目名称:Bob-the-Compiler,代码行数:23,代码来源:parse.cpp
示例8: printf
/** Parse @c switch statement.
*
* @param parse Parser object.
* @return New syntax tree node.
*/
static stree_switch_t *parse_switch(parse_t *parse)
{
stree_switch_t *switch_s;
stree_when_t *when_c;
stree_expr_t *expr;
#ifdef DEBUG_PARSE_TRACE
printf("Parse 'switch' statement.\n");
#endif
lmatch(parse, lc_switch);
switch_s = stree_switch_new();
list_init(&switch_s->when_clauses);
switch_s->expr = parse_expr(parse);
lmatch(parse, lc_is);
/* Parse @c when clauses. */
while (lcur_lc(parse) == lc_when) {
lskip(parse);
when_c = stree_when_new();
list_init(&when_c->exprs);
while (b_true) {
expr = parse_expr(parse);
list_append(&when_c->exprs, expr);
if (lcur_lc(parse) != lc_comma)
break;
lskip(parse);
}
lmatch(parse, lc_do);
when_c->block = parse_block(parse);
list_append(&switch_s->when_clauses, when_c);
}
/* Parse @c else clause. */
if (lcur_lc(parse) == lc_else) {
lskip(parse);
lmatch(parse, lc_do);
switch_s->else_block = parse_block(parse);
} else {
switch_s->else_block = NULL;
}
lmatch(parse, lc_end);
return switch_s;
}
开发者ID:fhector,项目名称:helenOS-0.5-Hector,代码行数:53,代码来源:parse.c
示例9: parse_num_op
/******************************************************************************
num_op := num rest_num_op
( expr ) rest_num_op
*****************************************************************************/
void
parse_num_op( val_t* val )
{
printtab();
dprintf("parse_num_op()\n");
level++;
if ( match_num( val ) ) {
parse_rest_num_op( val );
} else if ( match_variable( val ) ) {
resolve_variable( val );
parse_rest_num_op( val );
} else if ( match_char( '(' ) ) {
parse_expr( val );
if ( !match_char( ')' ) ) {
buffer[bpos] = 0;
printf("Missing bracket: %s\n", buffer);
longjmp( env, 1 );
}
parse_rest_num_op( val );
} else {
buffer[bpos] = 0;
printf("Parse error: %s\n", buffer);
longjmp( env, 1 );
}
level--;
return;
}
开发者ID:michaeljteng,项目名称:regression-tester-calc,代码行数:34,代码来源:calc.c
示例10: parse_keyvalue
static variable_t*
parse_keyvalue(char **ptr, group_t *head) {
char *p = *ptr;
char name[MAXIDLEN];
variable_t* var;
parse_identifier(&p, name, sizeof(name));
skip_whitespace(&p);
if (*p != '=') {
fprintf(stderr, "%s:%d: No assignment detected!\n", __func__, lineno);
return NULL;
} else {
p++;
}
skip_whitespace(&p);
/* create variable, assume string */
var = new_variable(name, VT_STRING);
/* parse value of variable */
parse_expr(&p, var, head);
*ptr = p;
return var;
}
开发者ID:dpuyosa,项目名称:awutils,代码行数:25,代码来源:parsecfg.c
示例11: expect
/*
* let <id>
* let <id> = <expr>
* let <id1>, <id2>
* let <id1> = <expr1>, <id2>, <id3> = <expr3>
*/
static ASTNode *parse_let_expression(Parser *p)
{
expect(p, TOK_LET, "expected let-expresssion to begin with 'let' keyword");
int have_comma = 1;
while (peek_id(p) == TOK_IDENTIFIER) {
/* get identifier */
char *ident = strdup(peek(p)->sval); accept(p);
/* optional init expression */
ASTNode *init = NULL;
if (peek_id(p) == TOK_ASSIGN) {
accept(p);
init = parse_expr(p);
}
/* parse body */
ASTNode *body = NULL;
free(ident);
if (peek_id(p) == TOK_COMMA) {
have_comma = 1;
accept(p);
} else {
have_comma = 0;
}
}
}
开发者ID:gnar,项目名称:zombo,代码行数:37,代码来源:parser.c
示例12: main
int main(int argc,char **argv) {
struct postfix_expr_t expr;
signed long val;
if (argc < 2) {
fprintf(stderr,"Please enter an expression in argv[1]\n");
return 1;
}
if (parse_expr(&expr,argv[1]) < 0) {
fprintf(stderr,"Failure to parse\n");
return 1;
}
print_expr(&expr);
printf("\n");
val = eval_expr(&expr);
if (val == LONG_MAX) {
fprintf(stderr,"Failure to eval\n");
return 1;
}
printf("result = %ld\n",val);
return 0;
}
开发者ID:joncampbell123,项目名称:doslib,代码行数:26,代码来源:expr1.c
示例13: parse_stmt_return
stmt_t parse_stmt_return(tokenizer_t t)
{
eat_it(t, TOK_RETURN);
expr_t e = parse_expr(t);
eat_it(t, TOK_SEMICOLON);
return mk_stmt_return(t->filename, t->line, e);
}
开发者ID:sidestepism,项目名称:compiler,代码行数:7,代码来源:parse.c
示例14: while
bool parser::parse_list(utf8str::iterator& it, utf8str::iterator& it_end, shared_ptr<expr>& result)
{
if (it != it_end)
{
uint32_t ch = utf8::peek_next(it, it_end);
if (ch == '(')
{
utf8::unchecked::next(it);
vector<shared_ptr<expr> > list;
shared_ptr<expr> innerExpr;
bool exprParseRes = true;
while (exprParseRes)
{
exprParseRes = parse_expr(it, it_end, innerExpr);
if (exprParseRes)
{
list.push_back(innerExpr);
innerExpr.reset();
}
}
skip_whitespaces(it, it_end);
expect(')', it, it_end);
result = shared_ptr<expr>(new expr(list));
return true;
}
else
{
return false;
}
}
return false;
}
开发者ID:metadeus,项目名称:aerylisp,代码行数:32,代码来源:parser.cpp
示例15: get_next_token
PExprAST
Parser::parse_identifier_expr()
{
std::string identifier = lex.get_last_token_value<std::string>();
get_next_token(); // eat identifier
//If it's a simple identifier
if (current_tok != Token::StartArg)
return PExprAST(new VariableExprAST(identifier));
//It's a function call :
get_next_token(); // eat '<'
std::vector<PExprAST> args;
if (current_tok != Token::EndArg)
while (true)
{
PExprAST expr = parse_expr();
if (current_tok == Token::EndArg)
break;
if (current_tok != Token::ArgSep)
throw ParserException(ParserExceptionType::ExpectedEndOfArg);
get_next_token(); // eat ','
}
get_next_token(); // eat '>'
return PExprAST(new CallExprAST(identifier, args));
}
开发者ID:Zenol,项目名称:PiouPiou,代码行数:30,代码来源:Parser.cpp
示例16: parse_function_args
static int parse_function_args(ExprParseState *state)
{
if (!parse_next_token(state) || state->token != '(' || !parse_next_token(state)) {
return -1;
}
int arg_count = 0;
for (;;) {
if (!parse_expr(state)) {
return -1;
}
arg_count++;
switch (state->token) {
case ',':
if (!parse_next_token(state)) {
return -1;
}
break;
case ')':
if (!parse_next_token(state)) {
return -1;
}
return arg_count;
default:
return -1;
}
}
}
开发者ID:dfelinto,项目名称:blender,代码行数:33,代码来源:expr_pylike_eval.c
示例17: parse_assingment
/*
parse_assignment
Matches a valid assignment
Parameters: none
Return: none
*/
void parse_assingment(Tree &cst){
cst.add_branch_node("assignment");
parse_identifier(cst);
match("=", cst);
parse_expr(cst);
cst.kill_all_children();
}
开发者ID:jbancamper,项目名称:Bob-the-Compiler,代码行数:16,代码来源:parse.cpp
示例18: parse_primary
static RegExp *
parse_primary(void)
{
RegExp *e;
switch (curtok) {
case ID:
if (!yylval.symbol->re)
Scanner_fatal(in, "can't find symbol");
e = yylval.symbol->re;
get_next_token();
break;
case RANGE:
case STRING:
e = yylval.regexp;
get_next_token();
break;
case '(':
get_next_token();
e = parse_expr();
if (curtok != ')')
Scanner_fatal(in, "missing closing parenthesis");
get_next_token();
break;
default:
return NULL;
}
return e;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:28,代码来源:parser.c
示例19: stree_vdecl_new
/** Parse variable declaration statement.
*
* @param parse Parser object.
* @return New syntax tree node.
*/
static stree_vdecl_t *parse_vdecl(parse_t *parse)
{
stree_vdecl_t *vdecl;
vdecl = stree_vdecl_new();
lmatch(parse, lc_var);
vdecl->name = parse_ident(parse);
lmatch(parse, lc_colon);
vdecl->type = parse_texpr(parse);
if (lcur_lc(parse) == lc_assign) {
lskip(parse);
(void) parse_expr(parse);
}
lmatch(parse, lc_scolon);
#ifdef DEBUG_PARSE_TRACE
printf("Parsed vdecl for '%s'\n", strtab_get_str(vdecl->name->sid));
printf("vdecl = %p, vdecl->name = %p, sid=%d\n",
vdecl, vdecl->name, vdecl->name->sid);
#endif
return vdecl;
}
开发者ID:fhector,项目名称:helenOS-0.5-Hector,代码行数:30,代码来源:parse.c
示例20: parse_join
// Parse Join.
// stm t1 join t2
Tree*
parse_join(Parser& p, Tree* t1) {
if(const Token* s = parse::accept(p, join_tok)) {
if(Tree* t2 = parse_expr(p))
if(parse::expect(p, on_tok))
if(Tree* t3 = parse_expr(p))
return new Join_on_tree(s,t1,t2,t3);
else
parse::parse_error(p) << "expected 'expr' after 'on'";
else
parse::parse_error(p) << "expected 'expr' after 'join'";
else
parse::parse_error(p) << "expected 'expr' before 'join'";
}
return nullptr;
}
开发者ID:artju01,项目名称:waffle,代码行数:18,代码来源:parser.cpp
注:本文中的parse_expr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论