X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=rpcgen_parse.y;fp=rpcgen_parse.y;h=04b073aea38b8013106a874d513316f4e1fbd0ce;hb=e9558f1dd242f2eb6a528c5509f1f8911fffe5d7;hp=0000000000000000000000000000000000000000;hpb=0fb3d920a44476495cd4537d22dc2debd0c4512f;p=portablexdr.git diff --git a/rpcgen_parse.y b/rpcgen_parse.y new file mode 100644 index 0000000..04b073a --- /dev/null +++ b/rpcgen_parse.y @@ -0,0 +1,170 @@ +/* rpcgen - Generate XDR bindings automatically. -*- text -*- + * Copyright (C) 2008 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +%{ +#include +#include +#include +#include "rpcgen_int.h" + +extern void yyerror (const char *str); +%} + +%union { + char *str; +} + +%type const + +%token STRUCT +%token ENUM +%token CONST +%token TYPEDEF +%token UNION +%token SWITCH +%token CASE +%token DEFAULT +%token PROGRAM + +%token UNSIGNED +%token SIGNED +%token CHAR +%token SHORT +%token INT +%token HYPER +%token DOUBLE +%token STRING +%token OPAQUE + +/* This is sometimes lumped together with the other types, but + * the special keyword void can only occur after "default:" in + * union statements. + */ +%token VOID + +%token IDENT +%token INTLIT +%token STRLIT + +%% + +file : /* empty */ + | stmts + ; + +/* Statements. */ +stmts : stmt ';' + | stmts stmt ';' + ; + +stmt : ENUM IDENT '{' enum_values '}' + | STRUCT IDENT '{' decls '}' + | UNION IDENT SWITCH '(' decl ')' '{' union_cases '}' + | TYPEDEF decl + | CONST IDENT '=' const + | PROGRAM + ; + +/* Declarations used inside structs and unions. eg. "int foo;" */ +decls : decl ';' + | decls decl ';' + ; + +decl : simple_decl + | fixed_array_decl + | variable_array_decl + | pointer_decl + ; + +simple_decl + : type_ident IDENT + ; + +fixed_array_decl + : type_ident IDENT '[' const ']' + ; + +variable_array_decl + : type_ident IDENT '<' const '>' + | type_ident IDENT '<' '>' + ; + +pointer_decl + : type_ident '*' IDENT + ; + +/* Enumerations. */ +enum_values + : enum_value + | enum_values ',' enum_value + ; + +enum_value + : IDENT + | IDENT '=' const + ; + +/* Case list inside a union. */ +union_cases + : union_case ';' + | union_cases union_case ';' + ; + +union_case + : CASE const ':' decl + | DEFAULT ':' VOID + | DEFAULT ':' decl + ; + +/* Constants, which may be integer literals or refer to previously + * defined constants (using "const" keyword). + * XXX In future we should probably allow computed constants. + */ +const : INTLIT + | IDENT + ; + +/* Types. */ +type_ident + : CHAR + | SIGNED CHAR + | UNSIGNED CHAR + | SHORT + | SIGNED SHORT + | UNSIGNED SHORT + | INT + | SIGNED INT + | UNSIGNED INT + | HYPER + | SIGNED HYPER + | UNSIGNED HYPER + | SIGNED + | UNSIGNED + | DOUBLE + | STRING + | OPAQUE + | IDENT + ; + +%% + +void +yyerror (const char *str) +{ + error ("%s", str); +}