# error BSIZE must be greater than YYMAXFILL
#endif
-#define PSI_T(n) \
-(n) == PSI_T_NAME ? "NAME" : \
-(n) == PSI_T_PLUS ? "PLUS" : \
-(n) == PSI_T_MINUS ? "MINUS" : \
-(n) == PSI_T_SLASH ? "SLASH" : \
-(n) == PSI_T_ASTERISK ? "ASTERISK" : \
-(n) == PSI_T_TEMP ? "TEMP" : \
-(n) == PSI_T_FREE ? "FREE" : \
-(n) == PSI_T_SET ? "SET" : \
-(n) == PSI_T_LET ? "LET" : \
-(n) == PSI_T_RETURN ? "RETURN" : \
-(n) == PSI_T_LIB ? "LIB" : \
-(n) == PSI_T_INT ? "INT" : \
-(n) == PSI_T_UNSIGNED ? "UNSIGNED" : \
-(n) == PSI_T_EOF ? "EOF" : \
-(n) == PSI_T_QUOTED_STRING ? "QUOTED_STRING" : \
-(n) == PSI_T_EOS ? "EOS" : \
-(n) == PSI_T_STRUCT ? "STRUCT" : \
-(n) == PSI_T_LBRACE ? "LBRACE" : \
-(n) == PSI_T_RBRACE ? "RBRACE" : \
-(n) == PSI_T_COLON ? "COLON" : \
-(n) == PSI_T_LPAREN ? "LPAREN" : \
-(n) == PSI_T_NUMBER ? "NUMBER" : \
-(n) == PSI_T_RPAREN ? "RPAREN" : \
-(n) == PSI_T_BOOL ? "BOOL" : \
-(n) == PSI_T_FLOAT ? "FLOAT" : \
-(n) == PSI_T_STRING ? "STRING" : \
-(n) == PSI_T_CONST ? "CONST" : \
-(n) == PSI_T_NSNAME ? "NSNAME" : \
-(n) == PSI_T_EQUALS ? "EQUALS" : \
-(n) == PSI_T_TYPEDEF ? "TYPEDEF" : \
-(n) == PSI_T_VOID ? "VOID" : \
-(n) == PSI_T_LBRACKET ? "LBRACKET" : \
-(n) == PSI_T_RBRACKET ? "RBRACKET" : \
-(n) == PSI_T_COMMA ? "COMMA" : \
-(n) == PSI_T_ELLIPSIS ? "ELLIPSIS" : \
-(n) == PSI_T_DOUBLE ? "DOUBLE" : \
-(n) == PSI_T_INT8 ? "INT8" : \
-(n) == PSI_T_UINT8 ? "UINT8" : \
-(n) == PSI_T_INT16 ? "INT16" : \
-(n) == PSI_T_UINT16 ? "UINT16" : \
-(n) == PSI_T_INT32 ? "INT32" : \
-(n) == PSI_T_UINT32 ? "UINT32" : \
-(n) == PSI_T_INT64 ? "INT64" : \
-(n) == PSI_T_UINT64 ? "UINT64" : \
-(n) == PSI_T_FUNCTION ? "FUNCTION" : \
-(n) == PSI_T_NULL ? "NULL" : \
-(n) == PSI_T_TRUE ? "TRUE" : \
-(n) == PSI_T_FALSE ? "FALSE" : \
-(n) == PSI_T_DOLLAR ? "DOLLAR" : \
-(n) == PSI_T_CALLOC ? "CALLOC" : \
-(n) == PSI_T_OBJVAL ? "OBJVAL" : \
-(n) == PSI_T_ARRVAL ? "ARRVAL" : \
-(n) == PSI_T_PATHVAL ? "PATHVAL" : \
-(n) == PSI_T_STRLEN ? "STRLEN" : \
-(n) == PSI_T_STRVAL ? "STRVAL" : \
-(n) == PSI_T_FLOATVAL ? "FLOATVAL" : \
-(n) == PSI_T_INTVAL ? "INTVAL" : \
-(n) == PSI_T_BOOLVAL ? "BOOLVAL" : \
-(n) == PSI_T_TO_OBJECT ? "TO_OBJECT" : \
-(n) == PSI_T_TO_ARRAY ? "TO_ARRAY" : \
-(n) == PSI_T_TO_STRING ? "TO_STRING" : \
-(n) == PSI_T_TO_INT ? "TO_INT" : \
-(n) == PSI_T_TO_FLOAT ? "TO_FLOAT" : \
-(n) == PSI_T_TO_BOOL ? "TO_BOOL" : \
-(n) == PSI_T_MIXED ? "MIXED" : \
-(n) == PSI_T_ARRAY ? "ARRAY" : \
-(n) == PSI_T_OBJECT ? "OBJECT" : \
-(n) == PSI_T_AMPERSAND ? "AMPERSAND" : \
-<UNKNOWN>
-
#define RETURN(t) do { \
P->num = t; \
if (P->flags & PSI_PARSER_DEBUG) { \
W = [a-zA-Z0-9_];
NAME = [a-zA-Z_]W*;
NSNAME = (NAME)? ("\\" NAME)+;
+ DOLLAR_NAME = '$' NAME;
QUOTED_STRING = "\"" ([^\"])+ "\"";
NUMBER = [+-]? [0-9]* "."? [0-9]+ ([eE] [+-]? [0-9]+)?;
"[" {RETURN(PSI_T_LBRACKET);}
"]" {RETURN(PSI_T_RBRACKET);}
"=" {RETURN(PSI_T_EQUALS);}
- "$" {RETURN(PSI_T_DOLLAR);}
"*" {RETURN(PSI_T_ASTERISK);}
"&" {RETURN(PSI_T_AMPERSAND);}
"+" {RETURN(PSI_T_PLUS);}
'FALSE' {RETURN(PSI_T_FALSE);}
'NULL' {RETURN(PSI_T_NULL);}
'MIXED' {RETURN(PSI_T_MIXED);}
+ 'CALLABLE' {RETURN(PSI_T_CALLABLE);}
'VOID' {RETURN(PSI_T_VOID);}
'BOOL' {RETURN(PSI_T_BOOL);}
'CHAR' {RETURN(PSI_T_CHAR);}
NUMBER {RETURN(PSI_T_NUMBER);}
NAME {RETURN(PSI_T_NAME);}
NSNAME {RETURN(PSI_T_NSNAME);}
+ DOLLAR_NAME {RETURN(PSI_T_DOLLAR_NAME);}
QUOTED_STRING {RETURN(PSI_T_QUOTED_STRING);}
[^] {break;}
*/
decl_typedef_body(def) ::= decl_typedef_body_ex(def_). {
def = def_;
}
-decl_typedef_body(def) ::= decl_func(func_) LPAREN decl_args(args) RPAREN. {
+%type decl_typedef_body_fn_args {decl_args *}
+%destructor decl_typedef_body_fn_args {free_decl_args($$);}
+decl_typedef_body_fn_args(args) ::= LPAREN decl_args(args_) RPAREN. {
+ args = args_;
+}
+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->func = init_decl(init_decl_abi("default"), func_, args);
func->var->token = N;
func->token = N;
}
+decl_typedef_body(def) ::= VOID(T) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
+ decl_arg *func_ = init_decl_arg(
+ init_decl_type(T->type, T->text),
+ init_decl_var(N->text, i, 0)
+ );
+ func_->type->token = T;
+ func_->var->token = N;
+ func_->token = N;
+ 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->func = init_decl(init_decl_abi("default"), func_, args);
+}
+decl_typedef_body(def) ::= CONST VOID(T) pointers(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
+ decl_arg *func_ = init_decl_arg(
+ init_decl_type(T->type, T->text),
+ init_decl_var(N->text, i, 0)
+ );
+ func_->type->token = T;
+ func_->var->token = N;
+ func_->token = N;
+ 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->func = init_decl(init_decl_abi("default"), func_, args);
+}
%type decl_abi {decl_abi*}
%destructor decl_abi {free_decl_abi($$);}
decl_arg(arg_) ::= const_decl_type(type) decl_var(var). {
arg_ = init_decl_arg(type, var);
}
+decl_typedef_body(def) ::= const_decl_type(type_) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). {
+ decl_arg *func_ = init_decl_arg(
+ type_,
+ init_decl_var(N->text, i, 0)
+ );
+ func_->var->token = N;
+ func_->token = N;
+ 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->func = init_decl(init_decl_abi("default"), func_, args);
+}
+
/* void pointers need a specific rule */
decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). {
arg_ = init_decl_arg(
%type impl_var {impl_var*}
%destructor impl_var {free_impl_var($$);}
-impl_var(var) ::= reference(r) DOLLAR NAME(T). {
+impl_var(var) ::= reference(r) DOLLAR_NAME(T). {
var = init_impl_var(T->text, r);
var->token = T;
}
%type impl_vararg {impl_arg*}
%destructor impl_vararg {free_impl_arg($$);}
-impl_vararg(va) ::= impl_type(type) reference(r) ELLIPSIS DOLLAR NAME(T). {
+impl_vararg(va) ::= impl_type(type) reference(r) ELLIPSIS DOLLAR_NAME(T). {
va = init_impl_arg(type, init_impl_var(T->text, r), NULL);
free(T);
}
call->token = F;
}
-%token_class impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT.
+%token_class impl_type_token VOID MIXED BOOL INT FLOAT STRING ARRAY OBJECT CALLABLE.
%type impl_type {impl_type*}
%destructor impl_type {free_impl_type($$);}
impl_type(type_) ::= impl_type_token(T). {