本文整理汇总了C++中parse_expr函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_expr函数的具体用法?C++ parse_expr怎么用?C++ parse_expr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_expr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
}
示例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++;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}