Example #1
0
Type&
Parser::tuple_type()
{  
  Type_list types;
  match(lbrace_tok);
  if (lookahead() != rbrace_tok)
    types = type_list();
  match(rbrace_tok);
  return on_tuple_type(types);
}
Example #2
0
// Parse a function type.
//
//    function-type:
//      '(' [type-list] ')' type
//
// TODO: A function should not be able to return a pack type.
Type&
Parser::function_type()
{
  Type_list types;
  match(lparen_tok);
  if (lookahead() != rparen_tok)
    types = type_list();
  match(rparen_tok);
  match(arrow_tok);
  Type& ret = type();
  return on_function_type(types, ret);
}
Example #3
0
static void grammar_pre(struct s_node *n) {
    int i, r = 0;
    struct s_node *p;
    static int cooked = 0;

    g_node = n;
    if (arg_defines()) {
	c_str("#include \"");c_str(arg_defines());c_strln("\"");
	if (arg_feed() && cooked) {
	    c_strln("#undef PACC_NAME");
	    c_strln("#define PACC_NAME PACC_FEED_NAME");
	}
    } else
	c_defines();
    ++cooked;

    pre_decl();

    /* We slightly simplify both building & walking the tree and insist
     * that every grammar starts with a preamble, which may be null.
     * It's a bit odd to represent no preamble with an empty preamble
     * node. */
    p = n->first;
    assert(p->type == preamble);
    if (!arg_defines() && p->text) c_raw(p->text);
    p = p->next;

    for ( ; p; p = p->next) {
	assert(p->type == rule);
	++r;
    }
    c_str("static const int n_rules = "); c_int(r); c_semi();
    c_str("static const int start_rule_id = "); c_long(n->first->next->id);
    c_semi();
    g_name = n->text;
    /* type of start rule is always u0 */
    type_list(n->first->next->first->text);
    for (p = n->first; p; p = p->next)
	if (p->type == rule) type_list(p->first->text);
    c_str("union PACC_SYM(vals)"); c_open();
    for (i = 0; i < t_max; ++i) {
	c_str(t_list[i]); c_str(" u"); c_int(i); c_semi();
    }

    c_close(); c_semi();

    /* XXX just for debugging */
    c_str("#define TYPE_PRINTF ");
    if (strcmp(n->first->next->first->text, "int") == 0) c_str("\"%d\"");
    else if (strcmp(n->first->next->first->text, "char *") == 0) c_str("\"%s\"");
    else c_str("\"%p\"");
    c_strln("");

    c_str("#define PACC_TYPE "); c_strln(n->first->next->first->text);

    pre_engine();

    c_str("_st=");
    c_long(n->first->type == preamble ? n->first->next->id : n->first->id);
    c_semi();
    c_strln("goto top;");
    c_strln("contin:");
    c_strln("_st=_cont;");
    c_strln("PACC_TRACE fprintf(stderr, \"continuing in state %d\\n\", _cont);");
    c_strln("top:");
    c_strln("PACC_TRACE fprintf(stderr, \"switch to state %d\\n\", _st);");
    c_str("switch(_st)"); c_open();
}
Example #4
0
static int rule_u(struct s_node *r) {
    return type_list(r->first->text);
}