%include {
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
+
#include <stddef.h>
#include <assert.h>
#include <stdlib.h>
#include "parser.h"
}
%include { void psi_error(int, const char *, int, const char *, ...); }
-%name PSI_ParserProc
+%name psi_parser_proc_
%token_prefix PSI_T_
-%token_type {PSI_Token *}
+%token_type {struct psi_token *}
%token_destructor {free($$);}
%default_destructor {(void)P;}
-%extra_argument {PSI_Parser *P}
-%syntax_error { ++P->errors; if (TOKEN && TOKEN->type != PSI_T_EOF) { psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s'", TOKEN->text); } else { psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input"); } }
+%extra_argument {struct psi_parser *P}
+%syntax_error { ++P->errors; if (TOKEN && TOKEN->type != PSI_T_EOF) { psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s' at pos %u", TOKEN->text, TOKEN->col); } else { psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input"); } }
%nonassoc NAME.
%left PLUS MINUS.
%left SLASH ASTERISK.
%destructor callback_args {free_set_values($$);}
%type let_val {let_val*}
%destructor let_val {free_let_val($$);}
+%type let_vals {let_vals*}
+%destructor let_vals {free_let_vals($$);}
%type set_stmt {set_stmt*}
%destructor set_stmt {free_set_stmt($$);}
%type set_value {set_value*}
free(E);
} else {
char digest[17];
- PSI_TokenHash(E, digest);
- n = PSI_TokenTranslit(PSI_TokenAppend(E, 1, digest), " ", "@");
+ psi_token_hash(E, digest);
+ n = psi_token_translit(psi_token_append(E, 1, digest), " ", "@");
}
}
decl_enum(e) ::= enum_name(N) LBRACE decl_enum_items(list) RBRACE. {
free(U);
} else {
char digest[17];
- PSI_TokenHash(U, digest);
- n = PSI_TokenTranslit(PSI_TokenAppend(U, 1, digest), " ", "@");
+ psi_token_hash(U, digest);
+ n = psi_token_translit(psi_token_append(U, 1, digest), " ", "@");
}
}
struct_name(n) ::= STRUCT(S) optional_name(N). {
free(S);
} else {
char digest[17];
- PSI_TokenHash(S, digest);
- n = PSI_TokenTranslit(PSI_TokenAppend(S, 1, digest), " ", "@");
+ psi_token_hash(S, digest);
+ n = psi_token_translit(psi_token_append(S, 1, digest), " ", "@");
}
}
decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. {
}
decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var);
- def->type->token = PSI_TokenCopy(N);
+ def->type->token = psi_token_copy(N);
def->type->real.strct = init_decl_struct(N->text, args);
def->type->real.strct->token = N;
def->type->real.strct->align = as.pos;
}
decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var);
- def->type->token = PSI_TokenCopy(N);
+ def->type->token = psi_token_copy(N);
def->type->real.unn = init_decl_union(N->text, args);
def->type->real.unn->token = N;
def->type->real.unn->align = as.pos;
decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). {
def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0));
def->var->token = ALIAS;
- def->type->token = PSI_TokenCopy(e->token);
+ def->type->token = psi_token_copy(e->token);
def->type->real.enm = e;
}
decl_typedef_body(def) ::= decl_typedef_body_ex(def_). {
}
decl_typedef_body(def) ::= decl_func(func_) decl_typedef_body_fn_args(args). {
def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var));
- def->type->token = PSI_TokenCopy(func_->token);
+ def->type->token = psi_token_copy(func_->token);
def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
}
decl_typedef_body(def) ::= decl_arg(arg). {
copy_decl_var(func_->var)
);
def->var->pointer_level = type_i;
- def->type->token = PSI_TokenCopy(func_->token);
+ def->type->token = psi_token_copy(func_->token);
def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
}
decl_typedef_body(def) ::= CONST VOID(T) pointers(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). {
copy_decl_var(func_->var)
);
def->var->pointer_level = type_i;
- def->type->token = PSI_TokenCopy(func_->token);
+ def->type->token = psi_token_copy(func_->token);
def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
}
decl_abi(abi) ::= NAME(T). {
copy_decl_var(func_->var)
);
def->var->pointer_level = type_i;
- def->type->token = PSI_TokenCopy(func_->token);
+ def->type->token = psi_token_copy(func_->token);
def->type->real.func = init_decl(init_decl_abi("default"), func_, args);
}
decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). {
}
decl_scalar_type(type_) ::= SHORT(S) decl_scalar_type_short(s). {
if (s) {
- type_ = PSI_TokenCat(2, S, s);
+ type_ = psi_token_cat(2, S, s);
free(S);
free(s);
} else {
}
decl_scalar_type(type_) ::= LONG(L) decl_scalar_type_long(l). {
if (l) {
- type_ = PSI_TokenCat(2, L, l);
+ type_ = psi_token_cat(2, L, l);
free(L);
free(l);
} else {
}
decl_scalar_type_long(l) ::= LONG(L) decl_scalar_type_long_long(ll). {
if (ll) {
- l = PSI_TokenCat(2, L, ll);
+ l = psi_token_cat(2, L, ll);
free(L);
free(ll);
} else {
ll = I;
}
decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). {
- PSI_Token *T = PSI_TokenCat(2, U, N);
+ struct psi_token *T = psi_token_cat(2, U, N);
type_ = init_decl_type(T->type, T->text);
type_->token = T;
free(U);
free(N);
}
decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). {
- PSI_Token *T = PSI_TokenCat(2, S, N);
+ struct psi_token *T = psi_token_cat(2, S, N);
type_ = init_decl_type(T->type, T->text);
type_->token = T;
free(S);
}
num_exp(exp) ::= decl_var(var). {
exp = init_num_exp(PSI_T_NAME, var);
- exp->token = PSI_TokenCopy(var->token);
+ exp->token = psi_token_copy(var->token);
}
num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). {
exp_->operator = operator_->type;
func = init_let_func(T->type, T->text, var);
free(T);
}
+let_vals(vals) ::= let_val(val). {
+ vals = init_let_vals(val);
+}
+let_vals(vals) ::= let_vals(vals_) COMMA let_val(val). {
+ vals = add_let_val(vals_, val);
+}
+let_func(func) ::= let_func_token(T) LPAREN impl_var(var) COMMA let_vals(vals) RPAREN. {
+ func = init_let_func(T->type, T->text, var);
+ func->inner = vals;
+ free(T);
+}
callback_arg_list ::= .
callback_arg_list(args) ::= callback_args(args_). {
args = args_;
callback_args(args) ::= callback_args(args_) COMMA set_value(val). {
args = add_set_value(args_, val);
}
+callback_rval(rval) ::= let_func_token(F). {
+ rval = F;
+}
+callback_rval(rval) ::= VOID(V). {
+ rval = V;
+}
let_val(val) ::= NULL. {
val = init_let_val(PSI_LET_NULL, NULL);
}
let_val(val) ::= CALLOC LPAREN let_calloc(alloc) RPAREN. {
val = init_let_val(PSI_LET_CALLOC, alloc);
}
-let_val(val) ::= let_func(func). {
- val = init_let_val(PSI_LET_FUNC, func);
+let_val(val) ::= let_func(func_). {
+ val = init_let_val(PSI_LET_FUNC, func_);
}
-let_val(val) ::= CALLBACK let_func_token(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. {
+let_val(val) ::= CALLBACK callback_rval(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. {
val = init_let_val(PSI_LET_CALLBACK, init_let_callback(
init_let_func(F->type, F->text, var), args_));
free(F);