Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

yacc_out_ebnf.c

00001 
00002 /*  A Bison parser, made from ebnf.c.y
00003     by GNU Bison version 1.28  */
00004 
00005 #define YYBISON 1  /* Identify Bison output.  */
00006 
00007 #define yyparse ebnf_parse
00008 #define yylex ebnf_lex
00009 #define yyerror ebnf_error
00010 #define yylval ebnf_lval
00011 #define yychar ebnf_char
00012 #define yydebug ebnf_debug
00013 #define yynerrs ebnf_nerrs
00014 #define NEW 257
00015 #define POST_NAMING_FUNCTION    258
00016 #define FUNCTION_NAME   259
00017 #define XML_FUNCTION    260
00018 #define XMLNS_FUNCTION  261
00019 #define EXTERNAL_FUNCTION   262
00020 #define WORD    263
00021 #define WORD_FOR_CONTENT    264
00022 #define WORD_FOR_TEXT   265
00023 #define PRODUCES    266
00024 #define LABEL   267
00025 #define CHARACTER_SET   268
00026 #define DQSTRING    269
00027 #define SQSTRING    270
00028 #define SENDTO  271
00029 #define IF  272
00030 #define THEN    273
00031 #define END 274
00032 #define DEFINE  275
00033 #define ADDTO   276
00034 #define INCLUDEIN   277
00035 #define INFER   278
00036 #define WHEN    279
00037 #define SPAWN   280
00038 #define CONTAINS    281
00039 #define NOT 282
00040 #define APPENDTOTEXT    283
00041 #define OUTPUT  284
00042 #define ADD 285
00043 #define INCLUDE 286
00044 #define IN  287
00045 #define TEXTBUFFER  288
00046 #define CLEARTEXT   289
00047 #define INTEGER 290
00048 #define REPEAT_FUNCTION 291
00049 #define PREFIXCOMMAND   292
00050 
00051 #line 2 "ebnf.c.y"
00052 
00053 
00054   /*
00055 
00056     There's an odd tension in using yacc -- do you build the
00057     output on yacc's stack or in some global space...?  Which approach
00058     seems best seems to vary a lot. 
00059     
00060 
00061     This grammar is funny in that rules and expressions are
00062     treated as different things, but I don't think they need
00063     to be.  If they are not, then we need the regexp postfix 
00064     operators in normal code, but I think that's fine.
00065 
00066     Oh -- and that darned " " omitted operator.  Foo.  That should be
00067     a comma to make everything beautiful.   It clears up any
00068     ambiguity on * + and ?, too.
00069 
00070     also, we have XML_FUNCTION and XMLNS_FUNCTION as tokens which 
00071     is probably also not necessary, when I have the model clear
00072     enough.
00073 
00074 
00075     The meaning of ::= ?
00076     It turns into SOMETHING about some input.....
00077 
00078    */
00079 
00080 #ifndef lint
00081 static char id[] = "$Id: yacc__out__ebnf_8c-source.html,v 1.9 2001/10/10 20:41:00 sandro Exp $";
00082 #endif
00083 
00084 #include <stdio.h>
00085 #include <assert.h>
00086 #include <string.h>
00087 #include <malloc.h>
00088 #include <stdlib.h>   /* for atoi */
00089 #include "hashmap.h"
00090 
00091 #define NOT_IMPLEMENTED if (1) { fprintf(stderr, "Feature not yet implemented (%s:%d).\n", __FILE__, __LINE__); abort(); }
00092 
00093 /* ****************************************************************
00094 
00095        LEXER STUFF  (input)
00096 
00097 **************************************************************** */
00098 
00099 #include "ebnf.h"
00100 extern int yylex();
00101 
00102 extern FILE *yyin;
00103 extern char *lexer_source_begin;
00104 extern char *lexer_source_end;
00105 extern char *yytext;
00106 extern int lineno;
00107 extern char linebuf[];
00108 
00109 int lineno=0;
00110 
00111 char* lexer_source_begin;
00112 char* lexer_source_end;
00113 
00114 /* ****************************************************************
00115 
00116        GRAMMAR STUFF   (output)
00117 
00118 **************************************************************** */
00119 
00120 #define UNLIM -1
00121 
00122 #include "abstract_grammar.h"
00123 
00124 Grammar *grammar;
00125 Rule* current_rule;
00126 Branch* current_branch;
00127 
00128 int stack_pointer=0;
00129 #define STACK_SIZE 2   /* maximum nesting of parens and such */
00130 Rule *rule_stack[STACK_SIZE];
00131 Branch *branch_stack[STACK_SIZE];
00132 void push();
00133 void pop();
00134 void repeated(int min, int max);
00135 void charset();
00136 
00137 struct defined_word {
00138     char* string; 
00139     enum part part;
00140 };
00141 
00142 static void new_word(char *);
00143 static void clear_words();
00144 static int defined_word_search(char *);
00145 
00146 static Hashmap prefixMap;
00147 
00148 static struct value* new_current_content();
00149 static void add_prefix(char*, char*);
00150 static char* with_prefix(char*, char*, char*);
00151 
00152 // Only do deletes if they are POINTERS on the stack
00153 //#define YYDELETEVAL(x,y) delete x
00154 //#define YYDELETEPOSN(x,y) delete x
00155 #define YYDELETEVAL(x,y) 
00156 #define YYDELETEPOSN(x,y)
00157 
00158 
00159 #line 135 "ebnf.c.y"
00160 typedef union {
00161   char *as_c_string;
00162   int as_integer;
00163   struct action *as_action;
00164   struct condition *as_condition;
00165   struct value *as_value;
00166   struct defined_word *as_defined_word;
00167 } YYSTYPE;
00168 #include <stdio.h>
00169 
00170 #ifndef __cplusplus
00171 #ifndef __STDC__
00172 #define const
00173 #endif
00174 #endif
00175 
00176 
00177 
00178 #define YYFINAL     157
00179 #define YYFLAG      -32768
00180 #define YYNTBASE    53
00181 
00182 #define YYTRANSLATE(x) ((unsigned)(x) <= 292 ? yytranslate[x] : 90)
00183 
00184 static const char yytranslate[] = {     0,
00185      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00186      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00187      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00188      2,     2,     2,     2,     2,     2,     2,     2,     2,    45,
00189     44,    49,    50,    42,    48,     2,     2,     2,     2,     2,
00190      2,     2,     2,     2,     2,     2,     2,    52,    39,     2,
00191     43,     2,    51,    47,     2,     2,     2,     2,     2,     2,
00192      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00193      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00194      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00195      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00196      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00197      2,     2,    40,    46,    41,     2,     2,     2,     2,     2,
00198      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00199      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00200      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00201      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00202      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00203      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00204      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00205      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00206      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00207      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00208      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00209      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00210      2,     2,     2,     2,     2,     1,     3,     4,     5,     6,
00211      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
00212     17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
00213     27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
00214     37,    38
00215 };
00216 
00217 #if YYDEBUG != 0
00218 static const short yyprhs[] = {     0,
00219      0,     2,     4,     7,     8,    10,    16,    20,    21,    23,
00220     25,    27,    28,    30,    34,    38,    42,    45,    48,    52,
00221     55,    59,    62,    65,    67,    74,    79,    84,    89,    94,
00222     97,   101,   106,   109,   111,   113,   115,   119,   123,   125,
00223    127,   131,   133,   135,   137,   139,   143,   145,   147,   149,
00224    151,   153,   154,   156,   158,   162,   164,   166,   167,   172,
00225    174,   177,   179,   181,   185,   189,   192,   195,   198,   204,
00226    212,   213,   219,   220,   225,   227,   229,   231,   237,   243,
00227    247,   251,   253,   255,   257,   259,   261
00228 };
00229 
00230 static const short yyrhs[] = {    54,
00231      0,    56,     0,    56,    54,     0,     0,    39,     0,    57,
00232     58,    12,    59,    55,     0,    57,    61,    39,     0,     0,
00233     13,     0,    86,     0,    75,     0,     0,    61,     0,    61,
00234     39,    60,     0,    40,    60,    41,     0,    38,    86,    87,
00235      0,     3,    86,     0,    30,    86,     0,    22,    66,    66,
00236      0,    31,    66,     0,    23,    66,    66,     0,    32,    66,
00237      0,    29,    66,     0,    35,     0,    33,    66,    25,    64,
00238     24,    61,     0,    24,    64,    25,    61,     0,    25,    64,
00239     24,    61,     0,    26,    62,    42,    63,     0,    17,    62,
00240     42,    66,     0,    21,     1,     0,    21,    86,     1,     0,
00241     21,    86,    43,     1,     0,    22,     1,     0,     9,     0,
00242      9,     0,    65,     0,    65,    39,    64,     0,    86,    27,
00243     66,     0,    67,     0,    69,     0,    68,    72,    44,     0,
00244      5,     0,    70,     0,    71,     0,    84,     0,    45,    66,
00245     44,     0,    87,     0,    34,     0,    86,     0,    10,     0,
00246     11,     0,     0,    73,     0,    74,     0,    74,    42,    73,
00247      0,    66,     0,    77,     0,     0,    77,    46,    76,    75,
00248      0,    79,     0,    77,    79,     0,    47,     0,    81,     0,
00249     79,    78,    61,     0,    81,    48,    81,     0,    81,    49,
00250      0,    81,    50,     0,    81,    51,     0,    37,    81,    42,
00251     89,    44,     0,    37,    81,    42,    89,    42,    89,    44,
00252      0,     0,    81,     4,    86,    80,    44,     0,     0,    45,
00253     82,    75,    44,     0,    87,     0,    86,     0,    85,     0,
00254      6,    83,    42,    75,    44,     0,     8,    86,    42,    87,
00255     44,     0,    86,    52,    86,     0,    86,    52,    86,     0,
00256     14,     0,     9,     0,    88,     0,    16,     0,    15,     0,
00257     36,     0
00258 };
00259 
00260 #endif
00261 
00262 #if YYDEBUG != 0
00263 static const short yyrline[] = { 0,
00264    159,   162,   163,   166,   166,   168,   172,   184,   185,   188,
00265    195,   202,   206,   207,   218,   220,   225,   231,   238,   245,
00266    252,   259,   266,   272,   277,   278,   279,   280,   281,   283,
00267    284,   285,   286,   288,   289,   307,   308,   315,   327,   336,
00268    337,   358,   365,   368,   385,   386,   388,   394,   401,   408,
00269    415,   424,   426,   429,   430,   437,   447,   448,   450,   451,
00270    452,   455,   458,   459,   464,   465,   466,   467,   468,   472,
00271    476,   481,   482,   486,   496,   525,   533,   534,   535,   538,
00272    542,   550,   556,   560,   566,   567,   570
00273 };
00274 #endif
00275 
00276 
00277 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
00278 
00279 static const char * const yytname[] = {   "$","error","$undefined.","NEW","POST_NAMING_FUNCTION",
00280 "FUNCTION_NAME","XML_FUNCTION","XMLNS_FUNCTION","EXTERNAL_FUNCTION","WORD","WORD_FOR_CONTENT",
00281 "WORD_FOR_TEXT","PRODUCES","LABEL","CHARACTER_SET","DQSTRING","SQSTRING","SENDTO",
00282 "IF","THEN","END","DEFINE","ADDTO","INCLUDEIN","INFER","WHEN","SPAWN","CONTAINS",
00283 "NOT","APPENDTOTEXT","OUTPUT","ADD","INCLUDE","IN","TEXTBUFFER","CLEARTEXT",
00284 "INTEGER","REPEAT_FUNCTION","PREFIXCOMMAND","';'","'{'","'}'","','","'='","')'",
00285 "'('","'|'","'@'","'-'","'*'","'+'","'?'","':'","grammar","clauses","optional_semi",
00286 "clause","optional_label","left","right","actions","action","portname","production",
00287 "compound_boolean_expression","boolean_expression","expr","expr10","function_name",
00288 "expr20","expr90","defined_word","parameters","non_empty_parameters","parameter",
00289 "pattern","@1","branch","annotation_flag","term_expr","@2","term","@3","xmlqname",
00290 "rdfqname","charset","word","string","quoted_string","integer", NULL
00291 };
00292 #endif
00293 
00294 static const short yyr1[] = {     0,
00295     53,    54,    54,    55,    55,    56,    56,    57,    57,    58,
00296     59,    60,    60,    60,    61,    61,    61,    61,    61,    61,
00297     61,    61,    61,    61,    61,    61,    61,    61,    61,    61,
00298     61,    61,    61,    62,    63,    64,    64,    65,    66,    67,
00299     67,    68,    69,    70,    70,    70,    70,    70,    71,    71,
00300     71,    72,    72,    73,    73,    74,    75,    76,    75,    77,
00301     77,    78,    79,    79,    79,    79,    79,    79,    79,    79,
00302     80,    79,    82,    81,    81,    81,    81,    81,    81,    83,
00303     84,    85,    86,    87,    88,    88,    89
00304 };
00305 
00306 static const short yyr2[] = {     0,
00307      1,     1,     2,     0,     1,     5,     3,     0,     1,     1,
00308      1,     0,     1,     3,     3,     3,     2,     2,     3,     2,
00309      3,     2,     2,     1,     6,     4,     4,     4,     4,     2,
00310      3,     4,     2,     1,     1,     1,     3,     3,     1,     1,
00311      3,     1,     1,     1,     1,     3,     1,     1,     1,     1,
00312      1,     0,     1,     1,     3,     1,     1,     0,     4,     1,
00313      2,     1,     1,     3,     3,     2,     2,     2,     5,     7,
00314      0,     5,     0,     4,     1,     1,     1,     5,     5,     3,
00315      3,     1,     1,     1,     1,     1,     1
00316 };
00317 
00318 static const short yydefact[] = {     8,
00319      9,     1,     8,     0,     3,     0,    83,     0,     0,     0,
00320      0,     0,     0,     0,     0,     0,     0,     0,     0,    24,
00321      0,    12,     0,     0,    10,    17,    34,     0,    30,     0,
00322     33,    42,    50,    51,    86,    85,    48,     0,     0,    39,
00323     52,    40,    43,    44,    45,    49,    47,    84,     0,     0,
00324     36,     0,     0,     0,    23,    18,    20,    22,     0,     0,
00325      0,    13,     0,     7,     0,    31,     0,     0,    19,    56,
00326      0,    53,    54,     0,    21,     0,     0,     0,     0,     0,
00327      0,    16,    15,    12,     0,     0,    82,     0,    73,     4,
00328     11,    57,    60,    63,    77,    76,    75,    29,    32,    46,
00329     41,     0,    81,    26,    37,    38,    27,    35,    28,     0,
00330     14,     0,     0,     0,     0,     0,     5,     6,    58,    61,
00331     62,     0,     0,     0,    66,    67,    68,    55,     0,     0,
00332      0,     0,     0,     0,     0,    64,    71,    65,    25,     0,
00333     80,     0,    87,     0,    74,    59,     0,    78,    79,     0,
00334     69,    72,     0,    70,     0,     0,     0
00335 };
00336 
00337 static const short yydefgoto[] = {   155,
00338      2,   118,     3,     4,    23,    90,    61,    62,    28,   109,
00339     50,    51,    70,    40,    41,    42,    43,    44,    71,    72,
00340     73,    91,   135,    92,   122,    93,   147,    94,   116,   112,
00341     45,    95,    46,    47,    48,   144
00342 };
00343 
00344 static const short yypact[] = {     3,
00345 -32768,-32768,    22,   157,-32768,    19,-32768,    24,    29,     9,
00346    100,    19,    19,    24,   100,    19,   100,   100,   100,-32768,
00347     19,   181,    25,    -8,-32768,-32768,-32768,    -3,-32768,    12,
00348 -32768,-32768,-32768,-32768,-32768,-32768,-32768,   100,   100,-32768,
00349    100,-32768,-32768,-32768,-32768,   -11,-32768,-32768,   100,    15,
00350      5,    18,    32,     0,-32768,-32768,-32768,-32768,    21,    11,
00351      7,    10,   127,-32768,   100,-32768,    56,    14,-32768,-32768,
00352     17,-32768,    20,    19,-32768,   181,    19,   100,   181,    54,
00353     19,-32768,-32768,   181,    19,    19,-32768,   140,-32768,    27,
00354 -32768,    92,    33,     2,-32768,-32768,-32768,-32768,-32768,-32768,
00355 -32768,   100,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    40,
00356 -32768,    30,    31,    45,    47,   127,-32768,-32768,-32768,    33,
00357 -32768,   181,    19,   140,-32768,-32768,-32768,-32768,   181,   127,
00358     19,    11,    35,    23,   127,-32768,-32768,-32768,-32768,    51,
00359 -32768,    52,-32768,   -21,-32768,-32768,    53,-32768,-32768,    35,
00360 -32768,-32768,    55,-32768,    91,   102,-32768
00361 };
00362 
00363 static const short yypgoto[] = {-32768,
00364    101,-32768,-32768,-32768,-32768,-32768,    34,    -1,    89,-32768,
00365    -12,-32768,    75,-32768,-32768,-32768,-32768,-32768,-32768,    28,
00366 -32768,  -101,-32768,-32768,-32768,    58,-32768,   -77,-32768,-32768,
00367 -32768,-32768,    -4,   -56,-32768,   -33
00368 };
00369 
00370 
00371 #define YYLAST      221
00372 
00373 
00374 static const short yytable[] = {    25,
00375     53,    26,    24,    82,    30,   123,    97,    52,    52,    31,
00376    115,    56,    66,    32,   134,     1,    60,     7,    33,    34,
00377    150,    -2,   151,    35,    36,    35,    36,     7,   140,    29,
00378     64,    97,    27,   146,     1,    97,    63,     7,    65,    76,
00379     74,    80,    37,    77,    78,    81,   138,    83,    84,   124,
00380    125,   126,   127,    38,    67,    79,    99,   100,    96,    97,
00381    101,   102,   108,   129,   105,   117,   145,    97,   110,   103,
00382    143,   130,    52,    97,   104,   142,    52,   107,    97,   121,
00383    113,   114,   131,    96,    39,    49,   132,    96,   133,    55,
00384    156,    57,    58,    59,   148,   149,   152,    85,   154,    86,
00385      7,   157,    54,     5,    32,    87,    35,    36,     7,    33,
00386     34,    96,    68,    69,    35,    36,   153,   111,   137,    96,
00387    136,     0,     0,    75,     0,    96,   141,   139,    88,   128,
00388     96,     0,    85,    37,    86,     7,    89,   119,     0,    98,
00389     87,    35,    36,     0,    38,    85,     0,    86,     7,   120,
00390      0,     0,   106,    87,    35,    36,     0,     0,     0,     6,
00391      0,     0,     0,    88,     0,     7,     0,     0,     0,     0,
00392      0,    89,     0,     8,     0,     0,     0,     9,    10,    11,
00393     12,    13,    14,     6,    89,    15,    16,    17,    18,    19,
00394      0,    20,     0,     0,    21,     0,    22,     8,     0,     0,
00395      0,     9,    10,    11,    12,    13,    14,     0,     0,    15,
00396     16,    17,    18,    19,     0,    20,     0,     0,    21,     0,
00397     22
00398 };
00399 
00400 static const short yycheck[] = {     4,
00401     13,     6,     4,    60,     9,     4,    63,    12,    13,     1,
00402     88,    16,     1,     5,   116,    13,    21,     9,    10,    11,
00403     42,     0,    44,    15,    16,    15,    16,     9,   130,     1,
00404     39,    88,     9,   135,    13,    92,    12,     9,    42,    25,
00405     52,    42,    34,    39,    27,    25,   124,    41,    39,    48,
00406     49,    50,    51,    45,    43,    24,     1,    44,    63,   116,
00407     44,    42,     9,    24,    77,    39,    44,   124,    81,    74,
00408     36,    42,    77,   130,    76,   132,    81,    79,   135,    47,
00409     85,    86,    52,    88,    10,    11,    42,    92,    42,    15,
00410      0,    17,    18,    19,    44,    44,    44,     6,    44,     8,
00411      9,     0,    14,     3,     5,    14,    15,    16,     9,    10,
00412     11,   116,    38,    39,    15,    16,   150,    84,   123,   124,
00413    122,    -1,    -1,    49,    -1,   130,   131,   129,    37,   102,
00414    135,    -1,     6,    34,     8,     9,    45,    46,    -1,    65,
00415     14,    15,    16,    -1,    45,     6,    -1,     8,     9,    92,
00416     -1,    -1,    78,    14,    15,    16,    -1,    -1,    -1,     3,
00417     -1,    -1,    -1,    37,    -1,     9,    -1,    -1,    -1,    -1,
00418     -1,    45,    -1,    17,    -1,    -1,    -1,    21,    22,    23,
00419     24,    25,    26,     3,    45,    29,    30,    31,    32,    33,
00420     -1,    35,    -1,    -1,    38,    -1,    40,    17,    -1,    -1,
00421     -1,    21,    22,    23,    24,    25,    26,    -1,    -1,    29,
00422     30,    31,    32,    33,    -1,    35,    -1,    -1,    38,    -1,
00423     40
00424 };
00425 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
00426 #line 3 "/usr/share/misc/bison.simple"
00427 /* This file comes from bison-1.28.  */
00428 
00429 /* Skeleton output parser for bison,
00430    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
00431 
00432    This program is free software; you can redistribute it and/or modify
00433    it under the terms of the GNU General Public License as published by
00434    the Free Software Foundation; either version 2, or (at your option)
00435    any later version.
00436 
00437    This program is distributed in the hope that it will be useful,
00438    but WITHOUT ANY WARRANTY; without even the implied warranty of
00439    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00440    GNU General Public License for more details.
00441 
00442    You should have received a copy of the GNU General Public License
00443    along with this program; if not, write to the Free Software
00444    Foundation, Inc., 59 Temple Place - Suite 330,
00445    Boston, MA 02111-1307, USA.  */
00446 
00447 /* As a special exception, when this file is copied by Bison into a
00448    Bison output file, you may use that output file without restriction.
00449    This special exception was added by the Free Software Foundation
00450    in version 1.24 of Bison.  */
00451 
00452 /* This is the parser code that is written into each bison parser
00453   when the %semantic_parser declaration is not specified in the grammar.
00454   It was written by Richard Stallman by simplifying the hairy parser
00455   used when %semantic_parser is specified.  */
00456 
00457 #ifndef YYSTACK_USE_ALLOCA
00458 #ifdef alloca
00459 #define YYSTACK_USE_ALLOCA
00460 #else /* alloca not defined */
00461 #ifdef __GNUC__
00462 #define YYSTACK_USE_ALLOCA
00463 #define alloca __builtin_alloca
00464 #else /* not GNU C.  */
00465 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
00466 #define YYSTACK_USE_ALLOCA
00467 #include <alloca.h>
00468 #else /* not sparc */
00469 /* We think this test detects Watcom and Microsoft C.  */
00470 /* This used to test MSDOS, but that is a bad idea
00471    since that symbol is in the user namespace.  */
00472 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
00473 #if 0 /* No need for malloc.h, which pollutes the namespace;
00474      instead, just don't use alloca.  */
00475 #include <malloc.h>
00476 #endif
00477 #else /* not MSDOS, or __TURBOC__ */
00478 #if defined(_AIX)
00479 /* I don't know what this was needed for, but it pollutes the namespace.
00480    So I turned it off.   rms, 2 May 1997.  */
00481 /* #include <malloc.h>  */
00482  #pragma alloca
00483 #define YYSTACK_USE_ALLOCA
00484 #else /* not MSDOS, or __TURBOC__, or _AIX */
00485 #if 0
00486 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
00487          and on HPUX 10.  Eventually we can turn this on.  */
00488 #define YYSTACK_USE_ALLOCA
00489 #define alloca __builtin_alloca
00490 #endif /* __hpux */
00491 #endif
00492 #endif /* not _AIX */
00493 #endif /* not MSDOS, or __TURBOC__ */
00494 #endif /* not sparc */
00495 #endif /* not GNU C */
00496 #endif /* alloca not defined */
00497 #endif /* YYSTACK_USE_ALLOCA not defined */
00498 
00499 #ifdef YYSTACK_USE_ALLOCA
00500 #define YYSTACK_ALLOC alloca
00501 #else
00502 #define YYSTACK_ALLOC malloc
00503 #endif
00504 
00505 /* Note: there must be only one dollar sign in this file.
00506    It is replaced by the list of actions, each action
00507    as one case of the switch.  */
00508 
00509 #define yyerrok     (yyerrstatus = 0)
00510 #define yyclearin   (yychar = YYEMPTY)
00511 #define YYEMPTY     -2
00512 #define YYEOF       0
00513 #define YYACCEPT    goto yyacceptlab
00514 #define YYABORT     goto yyabortlab
00515 #define YYERROR     goto yyerrlab1
00516 /* Like YYERROR except do call yyerror.
00517    This remains here temporarily to ease the
00518    transition to the new meaning of YYERROR, for GCC.
00519    Once GCC version 2 has supplanted version 1, this can go.  */
00520 #define YYFAIL      goto yyerrlab
00521 #define YYRECOVERING()  (!!yyerrstatus)
00522 #define YYBACKUP(token, value) \
00523 do                              \
00524   if (yychar == YYEMPTY && yylen == 1)              \
00525     { yychar = (token), yylval = (value);           \
00526       yychar1 = YYTRANSLATE (yychar);               \
00527       YYPOPSTACK;                       \
00528       goto yybackup;                        \
00529     }                               \
00530   else                              \
00531     { yyerror ("syntax error: cannot back up"); YYERROR; }  \
00532 while (0)
00533 
00534 #define YYTERROR    1
00535 #define YYERRCODE   256
00536 
00537 #ifndef YYPURE
00538 #define YYLEX       yylex()
00539 #endif
00540 
00541 #ifdef YYPURE
00542 #ifdef YYLSP_NEEDED
00543 #ifdef YYLEX_PARAM
00544 #define YYLEX       yylex(&yylval, &yylloc, YYLEX_PARAM)
00545 #else
00546 #define YYLEX       yylex(&yylval, &yylloc)
00547 #endif
00548 #else /* not YYLSP_NEEDED */
00549 #ifdef YYLEX_PARAM
00550 #define YYLEX       yylex(&yylval, YYLEX_PARAM)
00551 #else
00552 #define YYLEX       yylex(&yylval)
00553 #endif
00554 #endif /* not YYLSP_NEEDED */
00555 #endif
00556 
00557 /* If nonreentrant, generate the variables here */
00558 
00559 #ifndef YYPURE
00560 
00561 int yychar;         /*  the lookahead symbol        */
00562 YYSTYPE yylval;         /*  the semantic value of the       */
00563                 /*  lookahead symbol            */
00564 
00565 #ifdef YYLSP_NEEDED
00566 YYLTYPE yylloc;         /*  location data for the lookahead */
00567                 /*  symbol              */
00568 #endif
00569 
00570 int yynerrs;            /*  number of parse errors so far       */
00571 #endif  /* not YYPURE */
00572 
00573 #if YYDEBUG != 0
00574 int yydebug;            /*  nonzero means print parse trace */
00575 /* Since this is uninitialized, it does not stop multiple parsers
00576    from coexisting.  */
00577 #endif
00578 
00579 /*  YYINITDEPTH indicates the initial size of the parser's stacks   */
00580 
00581 #ifndef YYINITDEPTH
00582 #define YYINITDEPTH 200
00583 #endif
00584 
00585 /*  YYMAXDEPTH is the maximum size the stacks can grow to
00586     (effective only if the built-in stack extension method is used).  */
00587 
00588 #if YYMAXDEPTH == 0
00589 #undef YYMAXDEPTH
00590 #endif
00591 
00592 #ifndef YYMAXDEPTH
00593 #define YYMAXDEPTH 10000
00594 #endif
00595 
00596 /* Define __yy_memcpy.  Note that the size argument
00597    should be passed with type unsigned int, because that is what the non-GCC
00598    definitions require.  With GCC, __builtin_memcpy takes an arg
00599    of type size_t, but it can handle unsigned int.  */
00600 
00601 #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
00602 #define __yy_memcpy(TO,FROM,COUNT)  __builtin_memcpy(TO,FROM,COUNT)
00603 #else               /* not GNU C or C++ */
00604 #ifndef __cplusplus
00605 
00606 /* This is the most reliable way to avoid incompatibilities
00607    in available built-in functions on various systems.  */
00608 static void
00609 __yy_memcpy (to, from, count)
00610      char *to;
00611      char *from;
00612      unsigned int count;
00613 {
00614   register char *f = from;
00615   register char *t = to;
00616   register int i = count;
00617 
00618   while (i-- > 0)
00619     *t++ = *f++;
00620 }
00621 
00622 #else /* __cplusplus */
00623 
00624 /* This is the most reliable way to avoid incompatibilities
00625    in available built-in functions on various systems.  */
00626 static void
00627 __yy_memcpy (char *to, char *from, unsigned int count)
00628 {
00629   register char *t = to;
00630   register char *f = from;
00631   register int i = count;
00632 
00633   while (i-- > 0)
00634     *t++ = *f++;
00635 }
00636 
00637 #endif
00638 #endif
00639 
00640 #line 217 "/usr/share/misc/bison.simple"
00641 
00642 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
00643    into yyparse.  The argument should have type void *.
00644    It should actually point to an object.
00645    Grammar actions can access the variable by casting it
00646    to the proper pointer type.  */
00647 
00648 #ifdef YYPARSE_PARAM
00649 #ifdef __cplusplus
00650 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
00651 #define YYPARSE_PARAM_DECL
00652 #else /* not __cplusplus */
00653 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
00654 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
00655 #endif /* not __cplusplus */
00656 #else /* not YYPARSE_PARAM */
00657 #define YYPARSE_PARAM_ARG
00658 #define YYPARSE_PARAM_DECL
00659 #endif /* not YYPARSE_PARAM */
00660 
00661 /* Prevent warning if -Wstrict-prototypes.  */
00662 #ifdef __GNUC__
00663 #ifdef YYPARSE_PARAM
00664 int yyparse (void *);
00665 #else
00666 int yyparse (void);
00667 #endif
00668 #endif
00669 
00670 int
00671 yyparse(YYPARSE_PARAM_ARG)
00672      YYPARSE_PARAM_DECL
00673 {
00674   register int yystate;
00675   register int yyn;
00676   register short *yyssp;
00677   register YYSTYPE *yyvsp;
00678   int yyerrstatus;  /*  number of tokens to shift before error messages enabled */
00679   int yychar1 = 0;      /*  lookahead token as an internal (translated) token number */
00680 
00681   short yyssa[YYINITDEPTH]; /*  the state stack         */
00682   YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack        */
00683 
00684   short *yyss = yyssa;      /*  refer to the stacks thru separate pointers */
00685   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
00686 
00687 #ifdef YYLSP_NEEDED
00688   YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack          */
00689   YYLTYPE *yyls = yylsa;
00690   YYLTYPE *yylsp;
00691 
00692 #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
00693 #else
00694 #define YYPOPSTACK   (yyvsp--, yyssp--)
00695 #endif
00696 
00697   int yystacksize = YYINITDEPTH;
00698   int yyfree_stacks = 0;
00699 
00700 #ifdef YYPURE
00701   int yychar;
00702   YYSTYPE yylval;
00703   int yynerrs;
00704 #ifdef YYLSP_NEEDED
00705   YYLTYPE yylloc;
00706 #endif
00707 #endif
00708 
00709   YYSTYPE yyval;        /*  the variable used to return     */
00710                 /*  semantic values from the action */
00711                 /*  routines                */
00712 
00713   int yylen;
00714 
00715 #if YYDEBUG != 0
00716   if (yydebug)
00717     fprintf(stderr, "Starting parse\n");
00718 #endif
00719 
00720   yystate = 0;
00721   yyerrstatus = 0;
00722   yynerrs = 0;
00723   yychar = YYEMPTY;     /* Cause a token to be read.  */
00724 
00725   /* Initialize stack pointers.
00726      Waste one element of value and location stack
00727      so that they stay on the same level as the state stack.
00728      The wasted elements are never initialized.  */
00729 
00730   yyssp = yyss - 1;
00731   yyvsp = yyvs;
00732 #ifdef YYLSP_NEEDED
00733   yylsp = yyls;
00734 #endif
00735 
00736 /* Push a new state, which is found in  yystate  .  */
00737 /* In all cases, when you get here, the value and location stacks
00738    have just been pushed. so pushing a state here evens the stacks.  */
00739 yynewstate:
00740 
00741   *++yyssp = yystate;
00742 
00743   if (yyssp >= yyss + yystacksize - 1)
00744     {
00745       /* Give user a chance to reallocate the stack */
00746       /* Use copies of these so that the &'s don't force the real ones into memory. */
00747       YYSTYPE *yyvs1 = yyvs;
00748       short *yyss1 = yyss;
00749 #ifdef YYLSP_NEEDED
00750       YYLTYPE *yyls1 = yyls;
00751 #endif
00752 
00753       /* Get the current used size of the three stacks, in elements.  */
00754       int size = yyssp - yyss + 1;
00755 
00756 #ifdef yyoverflow
00757       /* Each stack pointer address is followed by the size of
00758      the data in use in that stack, in bytes.  */
00759 #ifdef YYLSP_NEEDED
00760       /* This used to be a conditional around just the two extra args,
00761      but that might be undefined if yyoverflow is a macro.  */
00762       yyoverflow("parser stack overflow",
00763          &yyss1, size * sizeof (*yyssp),
00764          &yyvs1, size * sizeof (*yyvsp),
00765          &yyls1, size * sizeof (*yylsp),
00766          &yystacksize);
00767 #else
00768       yyoverflow("parser stack overflow",
00769          &yyss1, size * sizeof (*yyssp),
00770          &yyvs1, size * sizeof (*yyvsp),
00771          &yystacksize);
00772 #endif
00773 
00774       yyss = yyss1; yyvs = yyvs1;
00775 #ifdef YYLSP_NEEDED
00776       yyls = yyls1;
00777 #endif
00778 #else /* no yyoverflow */
00779       /* Extend the stack our own way.  */
00780       if (yystacksize >= YYMAXDEPTH)
00781     {
00782       yyerror("parser stack overflow");
00783       if (yyfree_stacks)
00784         {
00785           free (yyss);
00786           free (yyvs);
00787 #ifdef YYLSP_NEEDED
00788           free (yyls);
00789 #endif
00790         }
00791       return 2;
00792     }
00793       yystacksize *= 2;
00794       if (yystacksize > YYMAXDEPTH)
00795     yystacksize = YYMAXDEPTH;
00796 #ifndef YYSTACK_USE_ALLOCA
00797       yyfree_stacks = 1;
00798 #endif
00799       yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
00800       __yy_memcpy ((char *)yyss, (char *)yyss1,
00801            size * (unsigned int) sizeof (*yyssp));
00802       yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
00803       __yy_memcpy ((char *)yyvs, (char *)yyvs1,
00804            size * (unsigned int) sizeof (*yyvsp));
00805 #ifdef YYLSP_NEEDED
00806       yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
00807       __yy_memcpy ((char *)yyls, (char *)yyls1,
00808            size * (unsigned int) sizeof (*yylsp));
00809 #endif
00810 #endif /* no yyoverflow */
00811 
00812       yyssp = yyss + size - 1;
00813       yyvsp = yyvs + size - 1;
00814 #ifdef YYLSP_NEEDED
00815       yylsp = yyls + size - 1;
00816 #endif
00817 
00818 #if YYDEBUG != 0
00819       if (yydebug)
00820     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
00821 #endif
00822 
00823       if (yyssp >= yyss + yystacksize - 1)
00824     YYABORT;
00825     }
00826 
00827 #if YYDEBUG != 0
00828   if (yydebug)
00829     fprintf(stderr, "Entering state %d\n", yystate);
00830 #endif
00831 
00832   goto yybackup;
00833  yybackup:
00834 
00835 /* Do appropriate processing given the current state.  */
00836 /* Read a lookahead token if we need one and don't already have one.  */
00837 /* yyresume: */
00838 
00839   /* First try to decide what to do without reference to lookahead token.  */
00840 
00841   yyn = yypact[yystate];
00842   if (yyn == YYFLAG)
00843     goto yydefault;
00844 
00845   /* Not known => get a lookahead token if don't already have one.  */
00846 
00847   /* yychar is either YYEMPTY or YYEOF
00848      or a valid token in external form.  */
00849 
00850   if (yychar == YYEMPTY)
00851     {
00852 #if YYDEBUG != 0
00853       if (yydebug)
00854     fprintf(stderr, "Reading a token: ");
00855 #endif
00856       yychar = YYLEX;
00857     }
00858 
00859   /* Convert token to internal form (in yychar1) for indexing tables with */
00860 
00861   if (yychar <= 0)      /* This means end of input. */
00862     {
00863       yychar1 = 0;
00864       yychar = YYEOF;       /* Don't call YYLEX any more */
00865 
00866 #if YYDEBUG != 0
00867       if (yydebug)
00868     fprintf(stderr, "Now at end of input.\n");
00869 #endif
00870     }
00871   else
00872     {
00873       yychar1 = YYTRANSLATE(yychar);
00874 
00875 #if YYDEBUG != 0
00876       if (yydebug)
00877     {
00878       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
00879       /* Give the individual parser a way to print the precise meaning
00880          of a token, for further debugging info.  */
00881 #ifdef YYPRINT
00882       YYPRINT (stderr, yychar, yylval);
00883 #endif
00884       fprintf (stderr, ")\n");
00885     }
00886 #endif
00887     }
00888 
00889   yyn += yychar1;
00890   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
00891     goto yydefault;
00892 
00893   yyn = yytable[yyn];
00894 
00895   /* yyn is what to do for this token type in this state.
00896      Negative => reduce, -yyn is rule number.
00897      Positive => shift, yyn is new state.
00898        New state is final state => don't bother to shift,
00899        just return success.
00900      0, or most negative number => error.  */
00901 
00902   if (yyn < 0)
00903     {
00904       if (yyn == YYFLAG)
00905     goto yyerrlab;
00906       yyn = -yyn;
00907       goto yyreduce;
00908     }
00909   else if (yyn == 0)
00910     goto yyerrlab;
00911 
00912   if (yyn == YYFINAL)
00913     YYACCEPT;
00914 
00915   /* Shift the lookahead token.  */
00916 
00917 #if YYDEBUG != 0
00918   if (yydebug)
00919     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
00920 #endif
00921 
00922   /* Discard the token being shifted unless it is eof.  */
00923   if (yychar != YYEOF)
00924     yychar = YYEMPTY;
00925 
00926   *++yyvsp = yylval;
00927 #ifdef YYLSP_NEEDED
00928   *++yylsp = yylloc;
00929 #endif
00930 
00931   /* count tokens shifted since error; after three, turn off error status.  */
00932   if (yyerrstatus) yyerrstatus--;
00933 
00934   yystate = yyn;
00935   goto yynewstate;
00936 
00937 /* Do the default action for the current state.  */
00938 yydefault:
00939 
00940   yyn = yydefact[yystate];
00941   if (yyn == 0)
00942     goto yyerrlab;
00943 
00944 /* Do a reduction.  yyn is the number of a rule to reduce with.  */
00945 yyreduce:
00946   yylen = yyr2[yyn];
00947   if (yylen > 0)
00948     yyval = yyvsp[1-yylen]; /* implement default value of the action */
00949 
00950 #if YYDEBUG != 0
00951   if (yydebug)
00952     {
00953       int i;
00954 
00955       fprintf (stderr, "Reducing via rule %d (line %d), ",
00956            yyn, yyrline[yyn]);
00957 
00958       /* Print the symbols being reduced, and their result.  */
00959       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
00960     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
00961       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
00962     }
00963 #endif
00964 
00965 
00966   switch (yyn) {
00967 
00968 case 6:
00969 #line 169 "ebnf.c.y"
00970 { 
00971        current_rule = 0; 
00972      ;
00973     break;}
00974 case 7:
00975 #line 173 "ebnf.c.y"
00976 { /* add this action to the end of the grammar's general list of actions */
00977       if (grammar->actions == 0) {
00978         grammar->actions = yyvsp[-1].as_action;
00979     grammar->last_action = yyvsp[-1].as_action;
00980       } else {
00981         grammar->last_action->next = yyvsp[-1].as_action;
00982     grammar->last_action = yyvsp[-1].as_action;
00983       }
00984     ;
00985     break;}
00986 case 10:
00987 #line 189 "ebnf.c.y"
00988 { current_rule = add_rule(grammar, yyvsp[0].as_c_string);
00989       current_branch = add_branch(current_rule);
00990       free(yyvsp[0].as_c_string);
00991     ;
00992     break;}
00993 case 12:
00994 #line 203 "ebnf.c.y"
00995 {
00996         yyval.as_action = 0;
00997       ;
00998     break;}
00999 case 14:
01000 #line 208 "ebnf.c.y"
01001 { 
01002       if (yyvsp[-2].as_action) {
01003           yyval.as_action = yyvsp[-2].as_action;
01004           yyvsp[-2].as_action->next = yyvsp[0].as_action;
01005       } else {
01006           yyval.as_action = 0;
01007       }
01008       ;
01009     break;}
01010 case 15:
01011 #line 218 "ebnf.c.y"
01012 {   yyval.as_action = yyvsp[-1].as_action;  ;
01013     break;}
01014 case 16:
01015 #line 221 "ebnf.c.y"
01016 {
01017       add_prefix(yyvsp[-1].as_c_string, yyvsp[0].as_c_string);
01018       yyval.as_action = 0;
01019       ;
01020     break;}
01021 case 17:
01022 #line 226 "ebnf.c.y"
01023 {
01024       new_word(yyvsp[0].as_c_string);
01025       free(yyvsp[0].as_c_string);
01026       yyval.as_action = 0;
01027       ;
01028     break;}
01029 case 18:
01030 #line 232 "ebnf.c.y"
01031 {
01032       new_word(yyvsp[0].as_c_string);
01033           grammar->output_name=strdup(yytext);
01034       free(yyvsp[0].as_c_string);
01035       yyval.as_action = 0;
01036       ;
01037     break;}
01038 case 19:
01039 #line 239 "ebnf.c.y"
01040 {
01041         yyval.as_action = (Action*) calloc(1, sizeof(Action));
01042     yyval.as_action->type = addto;
01043     yyval.as_action->as.addto.set = yyvsp[-1].as_value;
01044     yyval.as_action->as.addto.object = yyvsp[0].as_value;
01045       ;
01046     break;}
01047 case 20:
01048 #line 246 "ebnf.c.y"
01049 {
01050         yyval.as_action = (Action*) calloc(1, sizeof(Action));
01051     yyval.as_action->type = addto;
01052     yyval.as_action->as.addto.set = new_current_content();
01053     yyval.as_action->as.addto.object = yyvsp[0].as_value;
01054       ;
01055     break;}
01056 case 21:
01057 #line 253 "ebnf.c.y"
01058 {
01059     yyval.as_action = (Action*) calloc(1, sizeof(Action));
01060     yyval.as_action->type = includein;
01061     yyval.as_action->as.includein.outer = yyvsp[-1].as_value;
01062     yyval.as_action->as.includein.inner = yyvsp[0].as_value;
01063       ;
01064     break;}
01065 case 22:
01066 #line 260 "ebnf.c.y"
01067 {
01068     yyval.as_action = (Action*) calloc(1, sizeof(Action));
01069     yyval.as_action->type = includein;
01070     yyval.as_action->as.includein.outer = new_current_content();
01071     yyval.as_action->as.includein.inner = yyvsp[0].as_value;
01072       ;
01073     break;}
01074 case 23:
01075 #line 267 "ebnf.c.y"
01076 {
01077         yyval.as_action = (Action*) calloc(1, sizeof(Action));
01078     yyval.as_action->type = appendtotext;
01079     yyval.as_action->as.appendtotext.text = yyvsp[0].as_value;
01080       ;
01081     break;}
01082 case 24:
01083 #line 273 "ebnf.c.y"
01084 {
01085         yyval.as_action = (Action*) calloc(1, sizeof(Action));
01086     yyval.as_action->type = cleartext;
01087       ;
01088     break;}
01089 case 25:
01090 #line 277 "ebnf.c.y"
01091 { NOT_IMPLEMENTED; ;
01092     break;}
01093 case 26:
01094 #line 278 "ebnf.c.y"
01095 { NOT_IMPLEMENTED; ;
01096     break;}
01097 case 27:
01098 #line 279 "ebnf.c.y"
01099 { NOT_IMPLEMENTED; ;
01100     break;}
01101 case 28:
01102 #line 280 "ebnf.c.y"
01103 { NOT_IMPLEMENTED; ;
01104     break;}
01105 case 29:
01106 #line 281 "ebnf.c.y"
01107 { NOT_IMPLEMENTED; ;
01108     break;}
01109 case 30:
01110 #line 283 "ebnf.c.y"
01111 { fprintf(stderr, "define not followed by word\n"); ;
01112     break;}
01113 case 31:
01114 #line 284 "ebnf.c.y"
01115 { fprintf(stderr, "define word not followed by =\n"); ;
01116     break;}
01117 case 32:
01118 #line 285 "ebnf.c.y"
01119 { fprintf(stderr, "define word = not followed by expr\n"); ;
01120     break;}
01121 case 33:
01122 #line 286 "ebnf.c.y"
01123 { fprintf(stderr, "usage: addto <word> <tuple>\n"); ;
01124     break;}
01125 case 38:
01126 #line 316 "ebnf.c.y"
01127 {
01128         yyval.as_condition = (Condition*) calloc(1, sizeof(Condition));
01129     yyval.as_condition->type=contains;
01130     yyval.as_condition->as.contains.container=yyvsp[-2].as_c_string;
01131     yyval.as_condition->as.contains.object=yyvsp[0].as_value;
01132       ;
01133     break;}
01134 case 39:
01135 #line 328 "ebnf.c.y"
01136 {
01137     yyval.as_value = yyvsp[0].as_value;
01138     fprintf(stderr, "value is of type %d\n", yyvsp[0].as_value->type);
01139     ;
01140     break;}
01141 case 41:
01142 #line 338 "ebnf.c.y"
01143 {
01144        if (!strcmp(yyvsp[-2].as_c_string, "rdfid")) {
01145           if (yyvsp[-1].as_value->next) {
01146         fprintf(stderr, "rdfid() takes only one parameter\n");
01147         abort();
01148           }
01149           yyval.as_value = (Value*) calloc(1, sizeof(Value));
01150           yyval.as_value->type=rdfid;
01151       yyval.as_value->as.rdfid.id=yyvsp[-1].as_value->as.literal_string.string;
01152        } else if (!strcmp(yyvsp[-2].as_c_string, "tuple")) {
01153           yyval.as_value = (Value*) calloc(1, sizeof(Value));
01154           yyval.as_value->type=tuple;
01155       yyval.as_value->as.tuple.first=yyvsp[-1].as_value;
01156        } else {
01157          fprintf(stderr, "Function \"%s\" not defined.\n", yyvsp[-2].as_c_string);
01158      abort();
01159        }             
01160      ;
01161     break;}
01162 case 42:
01163 #line 359 "ebnf.c.y"
01164 {
01165       yytext[strlen(yytext)] = '\0';
01166       yyval.as_c_string = strdup(yytext);
01167     ;
01168     break;}
01169 case 44:
01170 #line 369 "ebnf.c.y"
01171 {
01172           fprintf(stderr, "got a 'defined_word', \"%s\", \"%s\"\n", yytext, yyvsp[0].as_defined_word->string);
01173       {
01174       int pos = defined_word_search(yyvsp[0].as_defined_word->string);
01175       if (pos== -1) {
01176           yyval.as_value = (Value*) calloc(1, sizeof(Value));
01177           yyval.as_value->type=local_name;
01178           yyval.as_value->as.local_name.name=yyvsp[0].as_defined_word->string;
01179       } else {
01180           yyval.as_value = (Value*) calloc(1, sizeof(Value));
01181           yyval.as_value->type=subst;
01182           yyval.as_value->as.subst.position=pos;
01183           yyval.as_value->as.subst.part = yyvsp[0].as_defined_word->part;
01184       }
01185       free(yyvsp[0].as_defined_word);
01186       };
01187     break;}
01188 case 46:
01189 #line 387 "ebnf.c.y"
01190 { yyval.as_value = yyvsp[-1].as_value; ;
01191     break;}
01192 case 47:
01193 #line 389 "ebnf.c.y"
01194 {    
01195         yyval.as_value = (Value*) calloc(1, sizeof(Value));
01196     yyval.as_value->type=literal_string;
01197     yyval.as_value->as.literal_string.string=yyvsp[0].as_c_string;
01198      ;
01199     break;}
01200 case 48:
01201 #line 395 "ebnf.c.y"
01202 {
01203         yyval.as_value = (Value*) calloc(1, sizeof(Value));
01204     yyval.as_value->type=text_buffer;
01205      ;
01206     break;}
01207 case 49:
01208 #line 402 "ebnf.c.y"
01209 {    
01210      fprintf(stderr, "<WORD: %s>", yyvsp[0].as_c_string);
01211      yyval.as_defined_word = (struct defined_word *) calloc(1, sizeof(struct defined_word));
01212      yyval.as_defined_word->string = yyvsp[0].as_c_string;
01213      yyval.as_defined_word->part=value_part;
01214      ;
01215     break;}
01216 case 50:
01217 #line 409 "ebnf.c.y"
01218 {    
01219      fprintf(stderr, "<WORD FOR CONTENT>");
01220      yyval.as_defined_word = (struct defined_word *) calloc(1, sizeof(struct defined_word));
01221      yyval.as_defined_word->string = strdup(yytext);
01222      yyval.as_defined_word->part=content_part;
01223      ;
01224     break;}
01225 case 51:
01226 #line 416 "ebnf.c.y"
01227 {    
01228      fprintf(stderr, "<WORD FOR TEXT>");
01229      yyval.as_defined_word = (struct defined_word *) calloc(1, sizeof(struct defined_word));
01230      yyval.as_defined_word->string = strdup(yytext);
01231      yyval.as_defined_word->part=text_part;
01232      ;
01233     break;}
01234 case 52:
01235 #line 425 "ebnf.c.y"
01236 { yyval.as_value = 0; ;
01237     break;}
01238 case 55:
01239 #line 431 "ebnf.c.y"
01240 { 
01241         yyval.as_value = yyvsp[-2].as_value;
01242         yyvsp[-2].as_value->next = yyvsp[0].as_value;
01243       ;
01244     break;}
01245 case 56:
01246 #line 438 "ebnf.c.y"
01247 {
01248      fprintf(stderr, "got parameter\n");
01249       ;
01250     break;}
01251 case 58:
01252 #line 448 "ebnf.c.y"
01253 { current_branch = add_branch(current_rule); ;
01254     break;}
01255 case 64:
01256 #line 460 "ebnf.c.y"
01257 {
01258         ((Term *)current_branch->tree.last)->actions = yyvsp[0].as_action;
01259     clear_words();
01260       ;
01261     break;}
01262 case 65:
01263 #line 464 "ebnf.c.y"
01264 { NOT_IMPLEMENTED; ;
01265     break;}
01266 case 66:
01267 #line 465 "ebnf.c.y"
01268 { repeated(0,UNLIM); ;
01269     break;}
01270 case 67:
01271 #line 466 "ebnf.c.y"
01272 { repeated(1,UNLIM); ;
01273     break;}
01274 case 68:
01275 #line 467 "ebnf.c.y"
01276 { repeated(0,1); ;
01277     break;}
01278 case 69:
01279 #line 469 "ebnf.c.y"
01280 { 
01281         repeated(yyvsp[-1].as_integer, UNLIM);
01282       ;
01283     break;}
01284 case 70:
01285 #line 473 "ebnf.c.y"
01286 { 
01287         repeated(yyvsp[-3].as_integer, yyvsp[-1].as_integer);
01288       ;
01289     break;}
01290 case 71:
01291 #line 476 "ebnf.c.y"
01292 {
01293       free(((Term *)current_branch->tree.last)->name);
01294       ((Term *)current_branch->tree.last)->name = yyvsp[0].as_c_string;
01295     ;
01296     break;}
01297 case 73:
01298 #line 482 "ebnf.c.y"
01299 {
01300           push();
01301           current_rule = add_anonymous_rule(grammar);
01302           current_branch = add_branch(current_rule);
01303         ;
01304     break;}
01305 case 74:
01306 #line 487 "ebnf.c.y"
01307 { Rule *r = current_rule;
01308        Term *t;
01309 
01310        pop();
01311        t = add_term(current_branch);
01312        t->type = rule_pointer;
01313        t->data.rule_pointer = r;
01314        t->name = strdup("_parens");
01315       ;
01316     break;}
01317 case 75:
01318 #line 497 "ebnf.c.y"
01319 { 
01320     char *p = yyvsp[0].as_c_string;
01321     while (*p) {
01322         Term *t = add_term(current_branch);
01323         char c = *p++;
01324         t->type = literal;
01325         if (c == '\\') {
01326         switch (*p++) {
01327         case '\0': 
01328             yyerror("backslash as last char inside quotes"); 
01329             break;
01330         case 'n':
01331             c = '\n';
01332             break;
01333         case 'r':
01334             c = '\r';
01335             break;
01336         case '\\':
01337             c = '\\';
01338             break;
01339         default:
01340             yyerror("unknown backslash-escape");
01341         }
01342         }
01343         t->data.literal = c;
01344         t->name = strdup("_literal");
01345     }
01346     ;
01347     break;}
01348 case 76:
01349 #line 526 "ebnf.c.y"
01350 {
01351        Term *t;
01352        t = add_term(current_branch);
01353        t->type = rule_name;
01354        t->data.rule_name = yyvsp[0].as_c_string;
01355        t->name = strdup(yyvsp[0].as_c_string);
01356     ;
01357     break;}
01358 case 78:
01359 #line 534 "ebnf.c.y"
01360 { NOT_IMPLEMENTED; ;
01361     break;}
01362 case 79:
01363 #line 535 "ebnf.c.y"
01364 { NOT_IMPLEMENTED; ;
01365     break;}
01366 case 80:
01367 #line 539 "ebnf.c.y"
01368 { NOT_IMPLEMENTED; ;
01369     break;}
01370 case 81:
01371 #line 543 "ebnf.c.y"
01372 { 
01373           yyval.as_value = (Value*) calloc(1, sizeof(Value));
01374           yyval.as_value->type=rdfid;
01375       yyval.as_value->as.rdfid.id=with_prefix(yyvsp[-2].as_c_string, "", yyvsp[0].as_c_string);
01376       ;
01377     break;}
01378 case 82:
01379 #line 551 "ebnf.c.y"
01380 {
01381     charset();
01382     ;
01383     break;}
01384 case 83:
01385 #line 557 "ebnf.c.y"
01386 { yyval.as_c_string = strdup(yytext); ;
01387     break;}
01388 case 84:
01389 #line 561 "ebnf.c.y"
01390 {
01391       yytext[strlen(yytext)-1] = '\0';
01392       yyval.as_c_string = strdup(yytext+1);
01393     ;
01394     break;}
01395 case 87:
01396 #line 571 "ebnf.c.y"
01397 {
01398       yyval.as_integer = atoi(yytext);
01399     ;
01400     break;}
01401 }
01402    /* the action file gets copied in in place of this dollarsign */
01403 #line 543 "/usr/share/misc/bison.simple"
01404 
01405   yyvsp -= yylen;
01406   yyssp -= yylen;
01407 #ifdef YYLSP_NEEDED
01408   yylsp -= yylen;
01409 #endif
01410 
01411 #if YYDEBUG != 0
01412   if (yydebug)
01413     {
01414       short *ssp1 = yyss - 1;
01415       fprintf (stderr, "state stack now");
01416       while (ssp1 != yyssp)
01417     fprintf (stderr, " %d", *++ssp1);
01418       fprintf (stderr, "\n");
01419     }
01420 #endif
01421 
01422   *++yyvsp = yyval;
01423 
01424 #ifdef YYLSP_NEEDED
01425   yylsp++;
01426   if (yylen == 0)
01427     {
01428       yylsp->first_line = yylloc.first_line;
01429       yylsp->first_column = yylloc.first_column;
01430       yylsp->last_line = (yylsp-1)->last_line;
01431       yylsp->last_column = (yylsp-1)->last_column;
01432       yylsp->text = 0;
01433     }
01434   else
01435     {
01436       yylsp->last_line = (yylsp+yylen-1)->last_line;
01437       yylsp->last_column = (yylsp+yylen-1)->last_column;
01438     }
01439 #endif
01440 
01441   /* Now "shift" the result of the reduction.
01442      Determine what state that goes to,
01443      based on the state we popped back to
01444      and the rule number reduced by.  */
01445 
01446   yyn = yyr1[yyn];
01447 
01448   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
01449   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
01450     yystate = yytable[yystate];
01451   else
01452     yystate = yydefgoto[yyn - YYNTBASE];
01453 
01454   goto yynewstate;
01455 
01456 yyerrlab:   /* here on detecting error */
01457 
01458   if (! yyerrstatus)
01459     /* If not already recovering from an error, report this error.  */
01460     {
01461       ++yynerrs;
01462 
01463 #ifdef YYERROR_VERBOSE
01464       yyn = yypact[yystate];
01465 
01466       if (yyn > YYFLAG && yyn < YYLAST)
01467     {
01468       int size = 0;
01469       char *msg;
01470       int x, count;
01471 
01472       count = 0;
01473       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
01474       for (x = (yyn < 0 ? -yyn : 0);
01475            x < (sizeof(yytname) / sizeof(char *)); x++)
01476         if (yycheck[x + yyn] == x)
01477           size += strlen(yytname[x]) + 15, count++;
01478       msg = (char *) malloc(size + 15);
01479       if (msg != 0)
01480         {
01481           strcpy(msg, "parse error");
01482 
01483           if (count < 5)
01484         {
01485           count = 0;
01486           for (x = (yyn < 0 ? -yyn : 0);
01487                x < (sizeof(yytname) / sizeof(char *)); x++)
01488             if (yycheck[x + yyn] == x)
01489               {
01490             strcat(msg, count == 0 ? ", expecting `" : " or `");
01491             strcat(msg, yytname[x]);
01492             strcat(msg, "'");
01493             count++;
01494               }
01495         }
01496           yyerror(msg);
01497           free(msg);
01498         }
01499       else
01500         yyerror ("parse error; also virtual memory exceeded");
01501     }
01502       else
01503 #endif /* YYERROR_VERBOSE */
01504     yyerror("parse error");
01505     }
01506 
01507   goto yyerrlab1;
01508 yyerrlab1:   /* here on error raised explicitly by an action */
01509 
01510   if (yyerrstatus == 3)
01511     {
01512       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
01513 
01514       /* return failure if at end of input */
01515       if (yychar == YYEOF)
01516     YYABORT;
01517 
01518 #if YYDEBUG != 0
01519       if (yydebug)
01520     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
01521 #endif
01522 
01523       yychar = YYEMPTY;
01524     }
01525 
01526   /* Else will try to reuse lookahead token
01527      after shifting the error token.  */
01528 
01529   yyerrstatus = 3;      /* Each real token shifted decrements this */
01530 
01531   goto yyerrhandle;
01532 
01533 yyerrdefault:  /* current state does not do anything special for the error token. */
01534 
01535 #if 0
01536   /* This is wrong; only states that explicitly want error tokens
01537      should shift them.  */
01538   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
01539   if (yyn) goto yydefault;
01540 #endif
01541 
01542 yyerrpop:   /* pop the current state because it cannot handle the error token */
01543 
01544   if (yyssp == yyss) YYABORT;
01545   yyvsp--;
01546   yystate = *--yyssp;
01547 #ifdef YYLSP_NEEDED
01548   yylsp--;
01549 #endif
01550 
01551 #if YYDEBUG != 0
01552   if (yydebug)
01553     {
01554       short *ssp1 = yyss - 1;
01555       fprintf (stderr, "Error: state stack now");
01556       while (ssp1 != yyssp)
01557     fprintf (stderr, " %d", *++ssp1);
01558       fprintf (stderr, "\n");
01559     }
01560 #endif
01561 
01562 yyerrhandle:
01563 
01564   yyn = yypact[yystate];
01565   if (yyn == YYFLAG)
01566     goto yyerrdefault;
01567 
01568   yyn += YYTERROR;
01569   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
01570     goto yyerrdefault;
01571 
01572   yyn = yytable[yyn];
01573   if (yyn < 0)
01574     {
01575       if (yyn == YYFLAG)
01576     goto yyerrpop;
01577       yyn = -yyn;
01578       goto yyreduce;
01579     }
01580   else if (yyn == 0)
01581     goto yyerrpop;
01582 
01583   if (yyn == YYFINAL)
01584     YYACCEPT;
01585 
01586 #if YYDEBUG != 0
01587   if (yydebug)
01588     fprintf(stderr, "Shifting error token, ");
01589 #endif
01590 
01591   *++yyvsp = yylval;
01592 #ifdef YYLSP_NEEDED
01593   *++yylsp = yylloc;
01594 #endif
01595 
01596   yystate = yyn;
01597   goto yynewstate;
01598 
01599  yyacceptlab:
01600   /* YYACCEPT comes here.  */
01601   if (yyfree_stacks)
01602     {
01603       free (yyss);
01604       free (yyvs);
01605 #ifdef YYLSP_NEEDED
01606       free (yyls);
01607 #endif
01608     }
01609   return 0;
01610 
01611  yyabortlab:
01612   /* YYABORT comes here.  */
01613   if (yyfree_stacks)
01614     {
01615       free (yyss);
01616       free (yyvs);
01617 #ifdef YYLSP_NEEDED
01618       free (yyls);
01619 #endif
01620     }
01621   return 1;
01622 }
01623 #line 575 "ebnf.c.y"
01624 
01625 
01626 void yyerror(char *errmsg) {
01627   fprintf(stderr, "%s near \"%s\" (line %d)\nbad line: %s\n", 
01628           errmsg, yytext, lineno, linebuf);     
01629 }
01630 
01631 int yyparse(void);
01632 
01633 void do_parse() {
01634   grammar = new_grammar();
01635   hashmap_open(&prefixMap, 5);
01636   yyparse();
01637   /* print_grammar(stdout, grammar); */
01638 }
01639 
01640 
01641 void parse(char* expr) 
01642 {
01643   lexer_source_begin = expr;
01644   lexer_source_end = lexer_source_begin+strlen(expr);
01645   do_parse();
01646 }
01647 
01648 void parse_stdin() 
01649 {
01650   do_parse();
01651 }
01652 
01653 Grammar* parse_file(const char* filename) 
01654 {
01655   if (filename[0] == '-' && filename[1] == '\0') { 
01656       parse_stdin(); return grammar; 
01657   }
01658   yyin = fopen(filename, "r");
01659   if (!yyin) {
01660     fprintf(stderr, "file \"%s\":", filename);
01661     perror("can't open");
01662     return 0;
01663   }
01664   do_parse();
01665   return grammar;
01666 }
01667 
01668 void push() {
01669    if (stack_pointer >= STACK_SIZE) {
01670      fprintf(stderr, "overflow of metagrammar stack: nesting is more than %d levels\n", STACK_SIZE);
01671      exit(1);
01672    }
01673    rule_stack[stack_pointer] = current_rule;
01674    branch_stack[stack_pointer] = current_branch;
01675    stack_pointer++;
01676 }
01677 void pop() {
01678   assert(stack_pointer > 0);
01679   stack_pointer--;
01680   current_rule = rule_stack[stack_pointer];
01681   current_branch = branch_stack[stack_pointer];
01682 }
01683 
01684 /*
01685   change the most recently added term into a rule which says that term
01686   can be appear at least min and at most max times.
01687 
01688   a ::= b?              a  ::= _1
01689                         _1 ::= | b
01690 
01691   a ::= b*              a  ::= _1
01692                         _1 ::=  | b | b _1
01693 
01694   a ::= b+              a  ::= _1
01695                         _1 ::= b | b _1
01696 
01697 
01698   */
01699 void repeated(int min, int max) {
01700   Rule *r = add_anonymous_rule(grammar);
01701   Term *t = dltree_unlink_last_child(current_branch);   /* aka $1 */
01702   int i;
01703   int do_unlim = 0;
01704 
01705   if (max == UNLIM) {
01706     do_unlim = 1;
01707     max = min;
01708     if (max == 0) max = 1;
01709   }
01710 
01711   for (i=min; i<=max; i++) {
01712     /* add a branch with i occurances of t */
01713     Branch *b = add_branch(r);    
01714     int j;
01715     for (j=0; j<i; j++) {
01716       Term *tt = add_term(b);
01717       printf("adding bit %d %d\n", i, j);
01718       grammar_copy_term(t, tt);
01719     }
01720     if (do_unlim && i>0) {
01721       /* add a repeat (right-recursion) to this rule */
01722       Rule *rr = add_anonymous_rule(grammar);
01723       Branch *bb1 = add_branch(rr);
01724       Branch *bb2 = add_branch(rr);
01725       Term *t1 = add_term(bb2);
01726       Term *t2 = add_term(bb2);
01727       Term *tt;
01728       grammar_copy_term(t, t1);
01729       t2->type = rule_pointer;
01730       t2->data.rule_pointer = rr;
01731       t2->name = strdup("_repeat_self");
01732       tt = add_term(b);
01733       tt->type = rule_pointer;
01734       tt->data.rule_pointer = rr;
01735       tt->name = strdup("_repeat_unlim");
01736       do_unlim = 0;
01737     }
01738   } 
01739 
01740   t = add_term(current_branch);
01741   t->type = rule_pointer;
01742   t->data.rule_pointer = r;
01743   t->name = strdup("_repeat");
01744 }
01745 
01746 static struct word_list_entry {
01747     char *word;
01748     struct word_list_entry *next;
01749 } *words = 0;
01750 
01751 void new_word(char *new_word) 
01752 {
01753     struct word_list_entry *old_words = words;
01754     words = (struct word_list_entry *) calloc(1, sizeof(struct word_list_entry));
01755     words->word = strdup(new_word);
01756     words->next = old_words;
01757 }
01758 
01759 void clear_words()
01760 {
01761     /* BUG: SHOULD FREE THEM ALL */
01762     words = 0;
01763 }
01764 
01765 int defined_word_search(char *word) 
01766 {
01767     struct word_list_entry *wp;
01768     /* check "local" variables */
01769     for (wp = words; wp; wp=wp->next) {
01770     if (!strcmp(wp->word, word)) {
01771         return -1;  /* found local term */
01772     }
01773     }
01774 
01775     if (current_rule) {
01776     if (!strcmp(current_rule->name, word)) {
01777         return 0;  /* it's the left-hand term */
01778     }
01779     
01780     {
01781         int pos = 1;
01782         Term *t = (Term *)current_branch->tree.first;
01783         
01784         while (t) {
01785         if (t->name && !strcmp(t->name, word)) {
01786             return pos;
01787         }
01788         pos++;
01789         t = (Term*)((DLTreeNode*)t)->next;
01790         }
01791     }
01792     }
01793 
01794     fprintf(stderr, "Undefined term \"%s\" on line %d\nLine %d: %s\n", 
01795         word, lineno, lineno, linebuf);     
01796     exit(1);
01797 }
01798 
01799 
01800 void charset()
01801 {
01802     Term *t = add_term(current_branch);
01803     t->type = rule_pointer;
01804     t->data.rule_pointer = add_charset(grammar, ebnf_charset);
01805     t->name = strdup("_charset");
01806 }
01807  
01808 struct value* new_current_content()
01809 {
01810     Value* v = (Value*) calloc(1, sizeof(Value));
01811     v->type=current_content;
01812     return v;
01813 }
01814 
01815 
01816 void add_prefix(char* prefix, char* expansion)
01817 {
01818     hashmap_put(&prefixMap, prefix, 0, expansion, 0);
01819     fprintf(stderr, "Added prefix: %s => %s\n", prefix, expansion);
01820 }
01821 
01822 /* return malloc'd expanded version of name */
01823 char* with_prefix(char *prefix, char *sep, char *suffix) 
01824 {
01825     char *result;
01826     char *expansion = hashmap_get(&prefixMap, prefix, 0);
01827     if (!expansion) {
01828     yyerror("defined xml/rdf prefix used");
01829     expansion = "_unknown_";
01830     }
01831     if (!sep) sep="";
01832     result = (char*)malloc(strlen(expansion)+strlen(sep)+strlen(suffix)+1);
01833     if (result) sprintf(result, "%s%s%s", expansion, sep, suffix);
01834     return result;
01835 }

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.