Exemple #1
0
static int mk_expr_placeholder(lua_State * L) {
    int nargs = lua_gettop(L);
    if (nargs == 0)
        return push_expr(L, mk_expr_placeholder());
    else
        return push_expr(L, mk_expr_placeholder(some_expr(to_expr(L, 1))));
}
Exemple #2
0
static int mk_choice(lua_State * L) {
    check_atleast_num_args(L, 1);
    int nargs = lua_gettop(L);
    buffer<expr> args;
    for (int i = 1; i <= nargs; i++)
        args.push_back(to_expr(L, i));
    return push_expr(L, mk_choice(args.size(), args.data()));
}
Exemple #3
0
static int get_choice(lua_State * L) {
    check_choice(L, 1);
    expr const & c = to_expr(L, 1);
    int i = lua_tointeger(L, 2);
    if (i < 0 || static_cast<unsigned>(i) >= get_num_choices(c))
        throw exception("arg #2 is an invalid choice index");
    return push_expr(L, get_choice(c, i));
}
Exemple #4
0
static int lambda_abstract(lua_State * L) {
    int nargs = lua_gettop(L);
    local_scope const & s = to_local_scope(L, 1);
    expr const & e = to_expr(L, 2);
    expr r;
    bool using_cache = false;
    if (nargs == 2)
        r = gparser.rec_save_pos(Fun(s->second.size(), s->second.data(), e, using_cache), gparser.pos_of(e));
    else
        r = gparser.rec_save_pos(Fun(s->second.size(), s->second.data(), e, using_cache), pos_info(lua_tointeger(L, 3), lua_tointeger(L, 4)));
    return push_expr(L, r);
}
Exemple #5
0
void read_prgm(FILE *f, int m) { char op;
  while(((op = fgetc(f)) != TERM||mn<0)&&op!=DONE) { switch(op) {
    case LABEL: { int x; fread(&x,sizeof(int),1,f); push_lbl_gen(x+m,esz); break; }
    case LINK: { Lit l; int i; fread(&i,sizeof(int),1,f); l.ca = getstr(i,f);
                 push_expr(op,l,m); break; }
    case LFUN: { Lit l; int i; fread(&i,sizeof(int),1,f); l.ca = getstr(i,f);
                 push_expr(op,l,m); break; }
    case LCALL: { Lit l; int i; fread(&i,sizeof(int),1,f); l.ca = getstr(i,f);
                  push_expr(op,l,m); break; }
    case IMPORT: { Lit l; int i; fread(&i,sizeof(int),1,f); l.ca = getstr(i,f);
                   push_expr(op,l,m); break; }
    case MAIN: { mn = esz; break; }
    default: { Lit l; switch(opcodes[(int)op]) {
      case CHR: { char i; fread(&i,sizeof(char),1,f); l.c = i; break; }
      case INT: { int i; fread(&i,sizeof(int),1,f); l.i = i; break; }
      case FLT: { double i; fread(&i,sizeof(double),1,f); l.f = i; break; }
      case LNG: { long i; fread(&i,sizeof(long),1,f); l.l = i; break; } }
    push_expr(op,l,m); } } }
  Lit q; push_expr(TERM,q,m); }
Exemple #6
0
token_t
primary(void)
{
    expr_t	*expr;
    entry_t	*entry;
    token_t	 token;
    int		 ch, lineno, column;

    if (ahead) {
        token = ahead->token;
        push_expr(ahead);
        ahead = NULL;
        return (token);
    }
    ch = skipws();
    lineno = parser.lineno;
    column = parser.column - 1;
    switch (ch) {
    case EOF:
        token = tok_eof;
        break;
    case '(':
        token = tok_oparen;
        break;
    case ')':
        token = tok_cparen;
        break;
    case '[':
        token = tok_obrack;
        break;
    case ']':
        token = tok_cbrack;
        break;
    case '{':
        token = tok_obrace;
        break;
    case '}':
        token = tok_cbrace;
        break;
    case ';':
        token = tok_semicollon;
        break;
    case ':':
        token = tok_collon;
        break;
    case ',':
        token = tok_comma;
        break;
    case '.':
        if ((ch = getch()) != '.') {
            ungetch(ch);
            token = tok_dot;
        }
        else if (getch() != '.')		error(NULL, "error near '..'");
        else				token = tok_ellipsis;
        break;
    case '=':
        if ((ch = getch()) == '=')		token = tok_eq;
        else {
            ungetch(ch);
            token = tok_set;
        }
        break;
    case '&':
        if ((ch = getch()) == '&')		token = tok_andand;
        else if (ch == '=')			token = tok_andset;
        else {
            ungetch(ch);
            token = tok_and;
        }
        break;
    case '|':
        if ((ch = getch()) == '|')		token = tok_oror;
        else if (ch == '=')			token = tok_orset;
        else {
            ungetch(ch);
            token = tok_or;
        }
        break;
    case '^':
        if ((ch = getch()) == '=')		token = tok_xorset;
        else {
            ungetch(ch);
            token = tok_xor;
        }
        break;
    case '<':
        if ((ch = getch()) == '=')		token = tok_le;
        else if (ch == '<') {
            if ((ch = getch()) == '=')	token = tok_lshset;
            else {
                ungetch(ch);
                token = tok_lsh;
            }
        }
        else {
            ungetch(ch);
            token = tok_lt;
        }
        break;
    case '>':
        if ((ch = getch()) == '=')		token = tok_ge;
        else if (ch == '>') {
            if ((ch = getch()) == '=')	token = tok_rshset;
            else {
                ungetch(ch);
                token = tok_rsh;
            }
        }
        else {
            ungetch(ch);
            token = tok_gt;
        }
        break;
    case '+':
        if ((ch = getch()) == '+')		token = tok_inc;
        else if (ch == '=')			token = tok_addset;
        else {
            ungetch(ch);
            token = tok_add;
        }
        break;
    case '-':
        if ((ch = getch()) == '-')		token = tok_dec;
        else if (ch == '=')			token = tok_subset;
        else if (ch == '>')			token = tok_arrow;
        else {
            ungetch(ch);
            token = tok_sub;
        }
        break;
    case '*':
        if ((ch = getch()) == '=')		token = tok_mulset;
        else {
            ungetch(ch);
            token = tok_mul;
        }
        break;
    case '/':
        if ((ch = getch()) == '=')		token = tok_divset;
        else {
            ungetch(ch);
            token = tok_div;
        }
        break;
    case '%':
        if ((ch = getch()) == '=')		token = tok_remset;
        else {
            ungetch(ch);
            token = tok_rem;
        }
        break;
    case '!':
        if ((ch = getch()) == '=')		token = tok_ne;
        else {
            ungetch(ch);
            token = tok_not;
        }
        break;
    case '~':
        token = tok_com;
        break;
    case '?':
        token = tok_question;
        break;
    case 'a' ... 'z':
    case 'A' ... 'Z':
    case '_':
        token = identifier(ch);
        break;
    case '0' ... '9':
        token = number(ch);
        break;
    case '"':
        token = string();
        break;
    case '\'':
        token = character();
        break;
    default:
        error(NULL, "syntax error");
    }

    parser.token = token;
    expr = new_expr(token, lineno, column);
    if (token == tok_string) {
        if ((entry = get_hash(strings, parser.string)) == NULL) {
            entry = (entry_t *)xmalloc(sizeof(entry_t));
            entry->name.string = xstrdup(parser.string);
            entry->value = entry->name.string;
            put_hash(strings, entry);
        }
        expr->data._unary.cp = entry->value;
    }
    else
        expr->data._unary = parser.value;
    push_expr(expr);

    return (token);
}
Exemple #7
0
static int rec(lua_State * L) {
    check_action(L, 1, { action_kind::Exprs, action_kind::ScopedExpr });
    return push_expr(L, to_notation_action(L, 1).get_rec());
}
Exemple #8
0
static int parse_scoped_expr(lua_State * L) {
    local_scope const & s = to_local_scope(L, 1);
    unsigned rbp    = to_rbp(L, 2);
    return push_expr(L, gparser.parse_scoped_expr(s->second.size(), s->second.data(), s->first, rbp));
}
Exemple #9
0
static int parse_led(lua_State * L) { return push_expr(L, gparser.parse_led(to_expr(L, 1))); }
Exemple #10
0
static int parse_expr(lua_State * L) { return push_expr(L, gparser.parse_expr(to_rbp(L, 1))); }
Exemple #11
0
static int save_pos(lua_State * L) {
    return push_expr(L, gparser.save_pos(to_expr(L, 1), pos_info(lua_tointeger(L, 2), lua_tointeger(L, 3))));
}