Subversion Repositories wimsdev

Rev

Rev 16599 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15177 obado 1
/**            wims_mathml 1.4.11
2
 *   wims_mathml.y last modified 06/22/2020 (r.15175)
3
 **/
5520 bpr 4
 
7369 georgesk 5
%parse-param {char **ret_str}
6
 
5520 bpr 7
%{
15175 obado 8
  #include <stdio.h>
9
  #include <string.h>
10
  #include <stdlib.h>
5520 bpr 11
 
15175 obado 12
  #include "wims_mathml.h"
5520 bpr 13
 
15175 obado 14
  #define YYSTYPE char *
5520 bpr 15
 
15175 obado 16
  #define yytext wims_mathml_yytext
17
   extern int yylex ();
18
   extern char * yytext;
5520 bpr 19
 
15175 obado 20
  static void wims_mathml_default_error (const char * msg)
7076 obado 21
  {
15175 obado 22
    //   if (msg){ fprintf(stderr, "Line: %d Error: %s\n", wims_mathml_lineno, msg);}
7076 obado 23
  }
5520 bpr 24
 
15175 obado 25
  void (*wims_mathml_error) (const char * msg) = wims_mathml_default_error;
5520 bpr 26
 
15175 obado 27
  static void yyerror (char ** ret_str, char * s)
28
  {
29
  //    char * msg = wims_mathml_copy3 (s, " at token ", yytext);
7076 obado 30
    if (wims_mathml_error)
31
      (*wims_mathml_error) ("ERROR");
15175 obado 32
  //     wims_mathml_free_string (msg);
7076 obado 33
  }
5520 bpr 34
 
15175 obado 35
  /* Note: If length is 0, then buffer is treated like a string; otherwise only length bytes are written.
36
   */
37
  static void wims_mathml_default_write (const char * buffer, unsigned long length)
38
  {
39
    if (buffer)
40
    {
41
      if (length)
42
        fwrite (buffer, 1, length, stdout);
43
      else
44
        fputs (buffer, stdout);
45
    }
46
  }
5520 bpr 47
 
15175 obado 48
  static void wims_mathml_default_write_mathml (const char * mathml)
49
  {
50
    if (wims_mathml_write)
51
      (*wims_mathml_write) (mathml, 0);
52
  }
5520 bpr 53
 
15175 obado 54
  #ifdef wims_mathml_CAPTURE
5520 bpr 55
    static char * wims_mathml_output_string = "" ;
56
 
57
    const char * wims_mathml_output ()
58
    {
15175 obado 59
      char * copy = (char *) malloc((wims_mathml_output_string ? strlen(wims_mathml_output_string) : 0) + 1);
60
      if (copy)
61
      {
62
        if (wims_mathml_output_string)
63
        {
64
          strcpy(copy, wims_mathml_output_string);
65
          if (*wims_mathml_output_string != '\0')
66
            free(wims_mathml_output_string);
67
        }
68
        else
69
          copy[0] = 0;
70
        wims_mathml_output_string = "";
71
      }
72
      return copy;
5520 bpr 73
    }
74
 
15175 obado 75
    static void wims_mathml_capture (const char * buffer, unsigned long length)
5520 bpr 76
    {
15175 obado 77
      if (buffer)
78
      {
79
        if (length)
80
        {
81
          unsigned long first_length = wims_mathml_output_string ? strlen(wims_mathml_output_string) : 0;
82
          char * copy  = (char *) malloc(first_length + length + 1);
83
          if (copy)
84
          {
85
            if (wims_mathml_output_string)
5520 bpr 86
            {
15175 obado 87
              strcpy(copy, wims_mathml_output_string);
5520 bpr 88
              if (*wims_mathml_output_string != '\0')
15175 obado 89
                free(wims_mathml_output_string);
5520 bpr 90
            }
15175 obado 91
            else
92
              copy[0] = 0;
93
            strncat(copy, buffer, length);
94
            wims_mathml_output_string = copy;
95
          }
96
        } else {
97
          char * copy = wims_mathml_copy2(wims_mathml_output_string, buffer);
98
          if (*wims_mathml_output_string != '\0')
99
            free(wims_mathml_output_string);
100
            wims_mathml_output_string = copy;
5520 bpr 101
        }
15175 obado 102
      }
5520 bpr 103
    }
104
 
105
    static void wims_mathml_capture_mathml (const char * buffer)
106
    {
15175 obado 107
      char * temp = wims_mathml_copy2(wims_mathml_output_string, buffer);
108
      if (*wims_mathml_output_string != '\0')
109
        free(wims_mathml_output_string);
110
      wims_mathml_output_string = temp;
5520 bpr 111
    }
112
    void (*wims_mathml_write) (const char * buffer, unsigned long length) = wims_mathml_capture;
113
    void (*wims_mathml_write_mathml) (const char * mathml) = wims_mathml_capture_mathml;
15175 obado 114
  #else
5520 bpr 115
    void (*wims_mathml_write) (const char * buffer, unsigned long length) = wims_mathml_default_write;
116
    void (*wims_mathml_write_mathml) (const char * mathml) = wims_mathml_default_write_mathml;
15175 obado 117
  #endif
5520 bpr 118
 
15175 obado 119
  char * wims_mathml_empty_string = "";
5520 bpr 120
 
15175 obado 121
  /* Create a copy of a string, adding space for extra chars
122
   */
123
  char * wims_mathml_copy_string_extra (const char * str, unsigned extra)
124
  {
125
    char * copy = (char *) malloc(extra + (str ? strlen (str) : 0) + 1);
126
    if (copy)
127
    {
128
      if (str)
129
        strcpy(copy, str);
130
      else
131
        copy[0] = 0;
132
    }
133
    return copy ? copy : wims_mathml_empty_string;
134
  }
5520 bpr 135
 
15175 obado 136
  /* Create a copy of a string, appending two strings
137
   */
138
  char * wims_mathml_copy3 (const char * first, const char * second, const char * third)
139
  {
140
    int  first_length =  first ? strlen( first) : 0;
141
    int second_length = second ? strlen(second) : 0;
142
    int  third_length =  third ? strlen( third) : 0;
5520 bpr 143
 
15175 obado 144
    char * copy = (char *) malloc(first_length + second_length + third_length + 1);
5520 bpr 145
 
15175 obado 146
    if (copy)
147
    {
148
      if (first)
149
        strcpy(copy, first);
150
      else
151
        copy[0] = 0;
5520 bpr 152
 
15175 obado 153
      if (second) strcat(copy, second);
154
      if ( third) strcat(copy,  third);
155
    }
156
    return copy ? copy : wims_mathml_empty_string;
157
  }
5520 bpr 158
 
15175 obado 159
  /**
160
   * Create a copy of a string, appending 4 strings
161
   */
162
  char * wims_mathml_copy5 (const char * first, const char * second, const char * third ,const char * forth,const char * fifth)
163
  {
164
    int  first_length =  first ? strlen( first) : 0;
165
    int second_length = second ? strlen(second) : 0;
166
    int  third_length =  third ? strlen( third) : 0;
167
    int  forth_length =  forth ? strlen( forth) : 0;
168
    int  fifth_length =  fifth ? strlen( fifth) : 0;
5520 bpr 169
 
15175 obado 170
    char * copy = (char *) malloc(first_length + second_length + third_length + forth_length + fifth_length + 1);
5520 bpr 171
 
15175 obado 172
    if (copy)
173
    {
174
      if (first)
175
        strcpy(copy, first);
176
      else
177
        copy[0] = 0;
5520 bpr 178
 
15175 obado 179
      if (second) strcat(copy, second);
180
      if ( third) strcat(copy,  third);
181
      if ( forth) strcat(copy,  forth);
182
      if ( fifth) strcat(copy,  fifth);
183
    }
184
    return copy ? copy : wims_mathml_empty_string;
185
  }
5520 bpr 186
 
15175 obado 187
  /**
188
   * Create a copy of a string, appending 6 strings
189
   */
190
  char * wims_mathml_copy7 (const char * first, const char * second, const char * third ,const char * forth,const char * fifth , const char * six , const char * seven)
191
  {
192
    int  first_length =  first ? strlen( first) : 0;
193
    int second_length = second ? strlen(second) : 0;
194
    int  third_length =  third ? strlen( third) : 0;
195
    int  forth_length =  forth ? strlen( forth) : 0;
196
    int  fifth_length =  fifth ? strlen( fifth) : 0;
197
    int  six_length =  six ? strlen( six ) : 0;
198
    int  seven_length =  seven ? strlen( seven ) : 0;
5520 bpr 199
 
15175 obado 200
    char * copy = (char *) malloc(first_length + second_length + third_length + forth_length + fifth_length + six_length + seven_length + 1);
5520 bpr 201
 
15175 obado 202
    if (copy)
203
    {
204
      if (first)
205
        strcpy(copy, first);
206
      else
207
        copy[0] = 0;
5520 bpr 208
 
15175 obado 209
      if (second) strcat(copy, second);
210
      if ( third) strcat(copy,  third);
211
      if ( forth) strcat(copy,  forth);
212
      if ( fifth) strcat(copy,  fifth);
213
      if ( six) strcat(copy,  six);
214
      if ( seven) strcat(copy,  seven);
215
    }
216
    return copy ? copy : wims_mathml_empty_string;
217
  }
5520 bpr 218
 
15175 obado 219
  /**
220
   * Create a copy of a string, appending 12 strings
221
   */
222
  char * wims_mathml_copy13( const char * A , const char * B , const char * C , const char * D , const char * E , const char * F , const char * G , const char * H,  const char * I,  const char * J,  const char * K,  const char * L,  const char * M){
223
    int  A_length =  A ? strlen( A ) : 0;
224
    int  B_length =  B ? strlen( B ) : 0;
225
    int  C_length =  C ? strlen( C ) : 0;
226
    int  D_length =  D ? strlen( D ) : 0;
227
    int  E_length =  E ? strlen( E ) : 0;
228
    int  F_length =  F ? strlen( F ) : 0;
229
    int  G_length =  G ? strlen( G ) : 0;
230
    int  H_length =  H ? strlen( H ) : 0;
231
    int  I_length =  I ? strlen( I ) : 0;
232
    int  J_length =  J ? strlen( J ) : 0;
233
    int  K_length =  K ? strlen( K ) : 0;
234
    int  L_length =  L ? strlen( L ) : 0;
235
    int  M_length =  M ? strlen( M ) : 0;
5520 bpr 236
 
15175 obado 237
    char * copy = (char *) malloc(A_length + B_length +   C_length +   D_length +   E_length +   F_length +   G_length +   H_length +   I_length +   J_length +   K_length +   L_length +   M_length + 1 );
5520 bpr 238
 
15175 obado 239
    if (copy)
240
    {
241
      if (A)
242
        strcpy(copy, A);
243
      else
244
        copy[0] = 0;
5520 bpr 245
 
15175 obado 246
      if (B) strcat(copy, B);
247
      if (C) strcat(copy, C);
248
      if (D) strcat(copy, D);
249
      if (E) strcat(copy, E);
250
      if (F) strcat(copy, F);
251
      if (G) strcat(copy, G);
252
      if (H) strcat(copy, H);
253
      if (I) strcat(copy, I);
254
      if (J) strcat(copy, J);
255
      if (K) strcat(copy, K);
256
      if (L) strcat(copy, L);
257
      if (M) strcat(copy, M);
258
    }
259
    return copy ? copy : wims_mathml_empty_string;
260
  }
5520 bpr 261
 
262
 
15175 obado 263
  /* Create a copy of a string, appending a second string
264
   */
265
  char * wims_mathml_copy2 (const char * first, const char * second)
266
  {
267
    return wims_mathml_copy3(first, second, 0);
268
  }
5520 bpr 269
 
15175 obado 270
  /* Create a copy of a string
271
   */
272
  char * wims_mathml_copy_string (const char * str)
273
  {
274
    return wims_mathml_copy3(str, 0, 0);
275
  }
5520 bpr 276
 
15175 obado 277
  /* Create a copy of a string, escaping unsafe characters for XML
278
   */
279
  char * wims_mathml_copy_escaped (const char * str)
280
  {
281
    unsigned long length = 0;
5520 bpr 282
 
15175 obado 283
    const char * ptr1 = str;
5520 bpr 284
 
15175 obado 285
    char * ptr2 = 0;
286
    char * copy = 0;
5520 bpr 287
 
15175 obado 288
    if ( str == 0) return wims_mathml_empty_string;
289
    if (*str == 0) return wims_mathml_empty_string;
5520 bpr 290
 
15175 obado 291
    while (*ptr1)
292
    {
293
      switch (*ptr1)
294
      {
295
        case '<':  /* &lt;   */
296
        case '>':  /* &gt;   */
297
          length += 4;
298
          break;
299
        case '&':  /* &amp;  */
300
          length += 5;
301
          break;
302
        case '\'': /* &apos; */
303
        case '"':  /* &quot; */
304
        case '-':  /* &#x2d; */
305
          length += 6;
306
          break;
307
        default:
308
          length += 1;
309
          break;
310
      }
311
      ++ptr1;
312
    }
5520 bpr 313
 
15175 obado 314
    copy = (char *) malloc (length + 1);
5520 bpr 315
 
15175 obado 316
    if (copy)
317
    {
318
      ptr1 = str;
319
      ptr2 = copy;
5520 bpr 320
 
15175 obado 321
      while (*ptr1)
322
      {
323
        switch (*ptr1)
324
        {
325
          case '<':
326
            strcpy (ptr2, "&lt;");
327
            ptr2 += 4;
328
            break;
329
          case '>':
330
            strcpy (ptr2, "&gt;");
331
            ptr2 += 4;
332
            break;
333
          case '&':  /* &amp;  */
334
            strcpy (ptr2, "&amp;");
335
            ptr2 += 5;
336
            break;
337
          case '\'': /* &apos; */
338
            strcpy (ptr2, "&apos;");
339
            ptr2 += 6;
340
            break;
341
          case '"':  /* &quot; */
342
            strcpy (ptr2, "&quot;");
343
            ptr2 += 6;
344
            break;
345
          case '-':  /* &#x2d; */
346
            strcpy (ptr2, "&#x2d;");
347
            ptr2 += 6;
348
            break;
349
          default:
350
            *ptr2++ = *ptr1;
351
            break;
352
        }
353
        ++ptr1;
354
      }
355
      *ptr2 = 0;
356
    }
357
    return copy ? copy : wims_mathml_empty_string;
358
  }
5520 bpr 359
 
15175 obado 360
  /* Create a hex character reference string corresponding to code
361
   */
362
  char * wims_mathml_character_reference (unsigned long int code)
363
  {
364
    #define ENTITY_LENGTH 10
365
    char * entity = (char *) malloc(ENTITY_LENGTH);
366
    sprintf(entity, "&#x%05lx;", code);
367
    return entity;
368
  }
5520 bpr 369
 
15175 obado 370
  void wims_mathml_free_string (char * str)
371
  {
372
    if (str && str != wims_mathml_empty_string)
373
      free(str);
374
  }
5520 bpr 375
 
376
%}
377
 
378
%left TEXOVER TEXATOP
16596 bpr 379
%token TMP_FONTSIZE LARGERINT BIGINT BIGGINT BIGGGINT CHAR STARTMATH STARTDMATH ENDMATH MI MIB MN MO SUP SUB MROWOPEN MROWCLOSE LEFT RIGHT BIG BBIG BIGG BBIGG BIGL BBIGL BIGGL BBIGGL DFRAC FRAC TFRAC SFRAC OPERATORNAME MATHOP MATHBIN MATHREL MOP MOL MOLL MOF MOR PERIODDELIM OTHERDELIM LEFTDELIM RIGHTDELIM MOS MOB SQRT ROOT BINOM BINOM2 TBINOM UNDER OVER OVERBRACE UNDERLINE UNDERBRACE UNDEROVER TENSOR MULTI ARRAYALIGN TEX_OPTIONS ARRAY COLSEP ROWSEP ARRAYOPTS COLLAYOUT COLALIGN ROWALIGN ALIGN EQROWS EQCOLS ROWLINES COLLINES FRAME PADDING ATTRLIST ITALICS BOLD BOXED SLASHED RM WIMSROMAN BB ST END BBLOWERCHAR BBUPPERCHAR BBDIGIT CALCHAR FRAKCHAR CAL FRAK CLAP LLAP RLAP ROWOPTS TEXTSIZE SCSIZE SCSCSIZE DISPLAY TEXTSTY TEXTBOX TEXTSTRING XMLSTRING CELLOPTS ROWSPAN COLSPAN THINSPACE MEDSPACE THICKSPACE QUAD QQUAD NEGSPACE PHANTOM HREF UNKNOWNCHAR EMPTYMROW STATLINE TOOLTIP TOGGLE FGHIGHLIGHT BGHIGHLIGHT SPACE INTONE INTTWO INTTHREE BAR WIDEBAR VEC WIDEVEC OVERARROW UNDERARROW HAT WIDEHAT CHECK WIDECHECK TILDE WIDETILDE ACCENTS DOT DDOT DDDOT DDDDOT UNARYMINUS UNARYPLUS BEGINENV ENDENV EQUATION MATRIX PMATRIX BMATRIX BBMATRIX VMATRIX VVMATRIX SVG ENDSVG HTML ENDHTML SMALLMATRIX CASES ALIGNED GATHERED SUBSTACK PMOD RMCHAR COLOR SPECIAL INPUT LEWIS BGCOLOR XARROW OPTARGOPEN OPTARGCLOSE ITEXNUM RAISEBOX NEG BRACK SHORTARRAY
5520 bpr 380
 
381
%%
382
 
383
doc:  xmlmmlTermList {/* all processing done in body*/};
384
 
385
xmlmmlTermList:
386
{/* nothing - do nothing*/}
387
| char {/* proc done in body*/}
388
| expression {/* all proc. in body*/}
389
| xmlmmlTermList char {/* all proc. in body*/}
390
| xmlmmlTermList expression {/* all proc. in body*/};
391
 
392
char: CHAR {printf("%s", $1);};
393
 
394
expression: STARTMATH ENDMATH {/* empty math group - ignore*/}
395
| STARTDMATH ENDMATH {/* ditto */}
396
| STARTMATH compoundTermList ENDMATH {
397
  char ** r = (char **) ret_str;
9618 schaersvoo 398
  char *s;
5520 bpr 399
  if( set_javascript() == 1){
12112 obado 400
   s = wims_mathml_copy7("<span class=\"wims_mathml\" onclick=\"javascript:wims_mathml_zoom('",read_mathml_id(),"')\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mstyle id=\"", read_mathml_id() ,"\" mathsize=\"100%%\">", $2, "</mstyle></math></span>");
5520 bpr 401
  }
9618 schaersvoo 402
  else
403
  {
12112 obado 404
    s = wims_mathml_copy7("<span class=\"wims_mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mstyle id=\"", read_mathml_id() ,"\" mathsize=\"",read_fontsize(),"\">", $2, "</mstyle></math></span>");
9618 schaersvoo 405
  }
5520 bpr 406
  wims_mathml_free_string($2);
407
  if (r) {
408
    (*r) = (s == wims_mathml_empty_string) ? 0 : s;
409
  }
12073 bpr 410
  else
9618 schaersvoo 411
  {
5520 bpr 412
    if (wims_mathml_write_mathml)
413
      (*wims_mathml_write_mathml) (s);
414
    wims_mathml_free_string(s);
415
  }
416
}
417
| STARTDMATH compoundTermList ENDMATH {
418
  char ** r = (char **) ret_str;
9618 schaersvoo 419
  char *s;
5520 bpr 420
  if( set_javascript() == 1){
9618 schaersvoo 421
   s = wims_mathml_copy7("<span style=\"font-size:1em;\" onclick=\"javascript:wims_mathml_zoom('",read_mathml_id(),"')\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><mstyle id=\"", read_mathml_id() ,"\" mathsize=\"100%%\">", $2, "</mstyle></math></span>");
5520 bpr 422
  }
9618 schaersvoo 423
  else
424
  {
12073 bpr 425
    s = wims_mathml_copy7("<span style=\"font-size:1em;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><mstyle id=\"", read_mathml_id() ,"\" mathsize=\"",read_fontsize(),"\">", $2, "</mstyle></math></span>");
9618 schaersvoo 426
  }
5520 bpr 427
  wims_mathml_free_string($2);
428
  if (r) {
429
    (*r) = (s == wims_mathml_empty_string) ? 0 : s;
430
  }
431
  else {
432
    if (wims_mathml_write_mathml)
433
      (*wims_mathml_write_mathml) (s);
434
    wims_mathml_free_string(s);
435
  }
436
};
437
 
438
compoundTermList: compoundTerm {
439
  $$ = wims_mathml_copy_string($1);
440
  wims_mathml_free_string($1);
441
}
442
| compoundTermList compoundTerm {
443
  $$ = wims_mathml_copy2($1, $2);
444
  wims_mathml_free_string($1);
445
  wims_mathml_free_string($2);
446
};
447
 
448
compoundTerm: mob SUB closedTerm SUP closedTerm {
449
  if (wims_mathml_displaymode == 1) {
450
    char * s1 = wims_mathml_copy3("<munderover>", $1, " ");
451
    char * s2 = wims_mathml_copy3($3, " ", $5);
452
    $$ = wims_mathml_copy3(s1, s2, "</munderover>");
453
    wims_mathml_free_string(s1);
454
    wims_mathml_free_string(s2);
455
  }
456
  else {
457
    char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
458
    char * s2 = wims_mathml_copy3($3, " ", $5);
459
    $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
460
    wims_mathml_free_string(s1);
461
    wims_mathml_free_string(s2);
462
  }
463
  wims_mathml_free_string($1);
464
  wims_mathml_free_string($3);
465
  wims_mathml_free_string($5);
466
}
467
| mob SUB closedTerm {
468
  if (wims_mathml_displaymode == 1) {
469
    char * s1 = wims_mathml_copy3("<munder>", $1, " ");
470
    $$ = wims_mathml_copy3(s1, $3, "</munder>");
471
    wims_mathml_free_string(s1);
472
  }
473
  else {
474
    char * s1 = wims_mathml_copy3("<msub>", $1, " ");
475
    $$ = wims_mathml_copy3(s1, $3, "</msub>");
476
    wims_mathml_free_string(s1);
477
  }
478
  wims_mathml_free_string($1);
479
  wims_mathml_free_string($3);
480
}
481
| mob SUP closedTerm SUB closedTerm {
482
  if (wims_mathml_displaymode == 1) {
483
    char * s1 = wims_mathml_copy3("<munderover>", $1, " ");
484
    char * s2 = wims_mathml_copy3($5, " ", $3);
485
    $$ = wims_mathml_copy3(s1, s2, "</munderover>");
486
    wims_mathml_free_string(s1);
487
    wims_mathml_free_string(s2);
488
  }
489
  else {
490
    char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
491
    char * s2 = wims_mathml_copy3($5, " ", $3);
492
    $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
493
    wims_mathml_free_string(s1);
494
    wims_mathml_free_string(s2);
495
  }
496
  wims_mathml_free_string($1);
497
  wims_mathml_free_string($3);
498
  wims_mathml_free_string($5);
499
}
500
| mob SUP closedTerm {
501
  if (wims_mathml_displaymode == 1) {
502
    char * s1 = wims_mathml_copy3("<mover>", $1, " ");
503
    $$ = wims_mathml_copy3(s1, $3, "</mover>");
504
    wims_mathml_free_string(s1);
505
  }
506
  else {
507
    char * s1 = wims_mathml_copy3("<msup>", $1, " ");
508
    $$ = wims_mathml_copy3(s1, $3, "</msup>");
509
    wims_mathml_free_string(s1);
510
  }
511
  wims_mathml_free_string($1);
512
  wims_mathml_free_string($3);
513
}
514
|mib SUB closedTerm SUP closedTerm {
515
  if (wims_mathml_displaymode == 1) {
516
    char * s1 = wims_mathml_copy3("<munderover>", $1, " ");
517
    char * s2 = wims_mathml_copy3($3, " ", $5);
518
    $$ = wims_mathml_copy3(s1, s2, "</munderover>");
519
    wims_mathml_free_string(s1);
520
    wims_mathml_free_string(s2);
521
  }
522
  else {
523
    char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
524
    char * s2 = wims_mathml_copy3($3, " ", $5);
525
    $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
526
    wims_mathml_free_string(s1);
527
    wims_mathml_free_string(s2);
528
  }
529
  wims_mathml_free_string($1);
530
  wims_mathml_free_string($3);
531
  wims_mathml_free_string($5);
532
}
533
| mib SUB closedTerm {
534
  if (wims_mathml_displaymode == 1) {
535
    char * s1 = wims_mathml_copy3("<munder>", $1, " ");
536
    $$ = wims_mathml_copy3(s1, $3, "</munder>");
537
    wims_mathml_free_string(s1);
538
  }
539
  else {
540
    char * s1 = wims_mathml_copy3("<msub>", $1, " ");
541
    $$ = wims_mathml_copy3(s1, $3, "</msub>");
542
    wims_mathml_free_string(s1);
543
  }
544
  wims_mathml_free_string($1);
545
  wims_mathml_free_string($3);
546
}
547
| mib SUP closedTerm SUB closedTerm {
548
  if (wims_mathml_displaymode == 1) {
549
    char * s1 = wims_mathml_copy3("<munderover>", $1, " ");
550
    char * s2 = wims_mathml_copy3($5, " ", $3);
551
    $$ = wims_mathml_copy3(s1, s2, "</munderover>");
552
    wims_mathml_free_string(s1);
553
    wims_mathml_free_string(s2);
554
  }
555
  else {
556
    char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
557
    char * s2 = wims_mathml_copy3($5, " ", $3);
558
    $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
559
    wims_mathml_free_string(s1);
560
    wims_mathml_free_string(s2);
561
  }
562
  wims_mathml_free_string($1);
563
  wims_mathml_free_string($3);
564
  wims_mathml_free_string($5);
565
}
566
| mib SUP closedTerm {
567
  if (wims_mathml_displaymode == 1) {
568
    char * s1 = wims_mathml_copy3("<mover>", $1, " ");
569
    $$ = wims_mathml_copy3(s1, $3, "</mover>");
570
    wims_mathml_free_string(s1);
571
  }
572
  else {
573
    char * s1 = wims_mathml_copy3("<msup>", $1, " ");
574
    $$ = wims_mathml_copy3(s1, $3, "</msup>");
575
    wims_mathml_free_string(s1);
576
  }
577
  wims_mathml_free_string($1);
578
  wims_mathml_free_string($3);
579
}
580
| closedTerm SUB closedTerm SUP closedTerm {
581
  char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
582
  char * s2 = wims_mathml_copy3($3, " ", $5);
583
  $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
584
  wims_mathml_free_string(s1);
585
  wims_mathml_free_string(s2);
586
  wims_mathml_free_string($1);
587
  wims_mathml_free_string($3);
588
  wims_mathml_free_string($5);
589
}
590
| closedTerm SUP closedTerm SUB closedTerm {
591
  char * s1 = wims_mathml_copy3("<msubsup>", $1, " ");
592
  char * s2 = wims_mathml_copy3($5, " ", $3);
593
  $$ = wims_mathml_copy3(s1, s2, "</msubsup>");
594
  wims_mathml_free_string(s1);
595
  wims_mathml_free_string(s2);
596
  wims_mathml_free_string($1);
597
  wims_mathml_free_string($3);
598
  wims_mathml_free_string($5);
599
}
600
| closedTerm SUB closedTerm {
601
  char * s1 = wims_mathml_copy3("<msub>", $1, " ");
602
  $$ = wims_mathml_copy3(s1, $3, "</msub>");
603
  wims_mathml_free_string(s1);
604
  wims_mathml_free_string($1);
605
  wims_mathml_free_string($3);
606
}
607
| closedTerm SUP closedTerm {
608
  char * s1 = wims_mathml_copy3("<msup>", $1, " ");
609
  $$ = wims_mathml_copy3(s1, $3, "</msup>");
610
  wims_mathml_free_string(s1);
611
  wims_mathml_free_string($1);
612
  wims_mathml_free_string($3);
613
}
614
| SUB closedTerm {
615
  $$ = wims_mathml_copy3("<msub><mo></mo>", $2, "</msub>");
616
  wims_mathml_free_string($2);
617
}
618
| SUP closedTerm {
619
  $$ = wims_mathml_copy3("<msup><mo></mo>", $2, "</msup>");
620
  wims_mathml_free_string($2);
621
}
622
| TMP_FONTSIZE compoundTerm {
623
  $$ = wims_mathml_copy5("<mstyle mathsize=\"",$1,"\">",$2,"</mstyle>");
624
  wims_mathml_free_string($1);
625
  wims_mathml_free_string($2);
626
}
627
| closedTerm {
628
  $$ = wims_mathml_copy_string($1);
629
  wims_mathml_free_string($1);
630
};
631
 
632
 
633
closedTerm: array
14226 schaersvoo 634
| shortarray
5520 bpr 635
| unaryminus
636
| unaryplus
637
| mib
638
| mi {
639
  $$ = wims_mathml_copy3("<mi>", $1, "</mi>");
640
  wims_mathml_free_string($1);
641
}
642
| mn {
643
  $$ = wims_mathml_copy3("<mn>", $1, "</mn>");
644
  wims_mathml_free_string($1);
645
}
8910 bpr 646
| mo
5520 bpr 647
| tensor
648
| multi
649
| mfrac
650
| binom
8910 bpr 651
| msqrt
5520 bpr 652
| mroot
653
| raisebox
654
| munder
655
| mover
656
| bar
657
| vec
7225 schaersvoo 658
| overarrow
659
| underarrow
5520 bpr 660
| hat
661
| dot
662
| ddot
663
| dddot
664
| ddddot
665
| check
666
| tilde
11708 schaersvoo 667
| accents
5520 bpr 668
| moverbrace
669
| munderbrace
670
| munderline
671
| munderover
672
| emptymrow
673
| mathclap
674
| mathllap
675
| mathrlap
676
| displaystyle
677
| textstyle
678
| textsize
679
| scriptsize
680
| scriptscriptsize
681
| italics
682
| bold
683
| roman
684
| rmchars
685
| bbold
686
| frak
687
| slashed
688
| boxed
689
| cal
690
| space
691
| textstring
692
| thinspace
693
| medspace
694
| thickspace
695
| quad
696
| qquad
697
| negspace
698
| phantom
699
| href
700
| statusline
701
| tooltip
702
| toggle
703
| fghighlight
704
| bghighlight
705
| color
706
| special
707
| input
16596 bpr 708
| lewis
5520 bpr 709
| bigint
710
| texover
711
| texatop
14226 schaersvoo 712
| brack
5520 bpr 713
| MROWOPEN closedTerm MROWCLOSE {
714
  $$ = wims_mathml_copy_string($2);
715
  wims_mathml_free_string($2);
716
}
717
| MROWOPEN compoundTermList MROWCLOSE {
718
  $$ = wims_mathml_copy3("<mrow>", $2, "</mrow>");
719
  wims_mathml_free_string($2);
720
}
721
| left compoundTermList right {
722
  char * s1 = wims_mathml_copy3("<mrow>", $1, $2);
723
  $$ = wims_mathml_copy3(s1, $3, "</mrow>");
724
  wims_mathml_free_string(s1);
725
  wims_mathml_free_string($1);
726
  wims_mathml_free_string($2);
727
  wims_mathml_free_string($3);
728
}
729
| mathenv
730
| substack
731
| pmod
11579 schaersvoo 732
| unrecognized;
5520 bpr 733
 
734
left: LEFT LEFTDELIM {
735
  wims_mathml_rowposn = 2;
7347 schaersvoo 736
  $$ = wims_mathml_copy3("<mo stretchy=\"true\">", $2, "</mo>");
5520 bpr 737
  wims_mathml_free_string($2);
738
}
739
| LEFT OTHERDELIM {
740
  wims_mathml_rowposn = 2;
7347 schaersvoo 741
  $$ = wims_mathml_copy3("<mo stretchy=\"true\">", $2, "</mo>");
5520 bpr 742
  wims_mathml_free_string($2);
743
}
744
| LEFT PERIODDELIM {
745
  wims_mathml_rowposn = 2;
746
  $$ = wims_mathml_copy_string("");
747
  wims_mathml_free_string($2);
748
};
749
 
750
right: RIGHT RIGHTDELIM {
7347 schaersvoo 751
  $$ = wims_mathml_copy3("<mo stretchy=\"true\">", $2, "</mo>");
5520 bpr 752
  wims_mathml_free_string($2);
753
}
754
| RIGHT OTHERDELIM {
7347 schaersvoo 755
  $$ = wims_mathml_copy3("<mo stretchy=\"true\">", $2, "</mo>");
5520 bpr 756
  wims_mathml_free_string($2);
757
}
758
| RIGHT PERIODDELIM {
759
  $$ = wims_mathml_copy_string("");
760
  wims_mathml_free_string($2);
761
};
762
 
763
 
764
bigint:  BIGGGINT {
765
  wims_mathml_rowposn = 2;
766
  $$ = wims_mathml_copy_string("<mtable columnalign=\"center\" rowspacing=\"0.5ex\"><mtr><mtd><mo symmetric=\"true\"  stretchy=\"true\"  maxsize=\"600%\" minsize=\"400%\">&Integral;</mo></mtd></mtr></mtable>");
767
}
5996 schaersvoo 768
| BIGGINT {
5520 bpr 769
  wims_mathml_rowposn = 2;
770
  $$ = wims_mathml_copy_string("<mtable columnalign=\"center\" rowspacing=\"0.5ex\"><mtr><mtd><mo symmetric=\"true\"  stretchy=\"true\"  maxsize=\"400%\" minsize=\"30%\">&Integral;</mo></mtd></mtr></mtable>");
771
}
5996 schaersvoo 772
| BIGINT {
5520 bpr 773
  wims_mathml_rowposn = 2;
774
  $$ = wims_mathml_copy_string("<mtable columnalign=\"center\" rowspacing=\"0.5ex\"><mtr><mtd><mo symmetric=\"true\"  stretchy=\"true\"  maxsize=\"300%\" minsize=\"200%\">&Integral;</mo></mtd></mtr></mtable>");
8910 bpr 775
}
5996 schaersvoo 776
| LARGERINT {
5520 bpr 777
  wims_mathml_rowposn = 2;
778
  $$ = wims_mathml_copy_string("<mtable columnalign=\"center\" rowspacing=\"0.5ex\"><mtr><mtd><mo symmetric=\"true\"  stretchy=\"true\"  maxsize=\"260%\" minsize=\"160%\">&Integral;</mo></mtd></mtr></mtable>");
8910 bpr 779
};
5520 bpr 780
 
781
bigdelim: BIG LEFTDELIM {
782
  wims_mathml_rowposn = 2;
783
  $$ = wims_mathml_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
784
  wims_mathml_free_string($2);
8910 bpr 785
}
5520 bpr 786
| BIG RIGHTDELIM {
787
  $$ = wims_mathml_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
788
  wims_mathml_free_string($2);
789
}
790
| BIG OTHERDELIM {
791
  $$ = wims_mathml_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
792
  wims_mathml_free_string($2);
793
}
794
| BBIG LEFTDELIM {
795
  wims_mathml_rowposn = 2;
796
  $$ = wims_mathml_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
797
  wims_mathml_free_string($2);
798
}
799
| BBIG RIGHTDELIM {
800
  $$ = wims_mathml_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
801
  wims_mathml_free_string($2);
802
}
803
| BBIG OTHERDELIM {
804
  $$ = wims_mathml_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
805
  wims_mathml_free_string($2);
806
}
807
| BIGG LEFTDELIM {
808
  wims_mathml_rowposn = 2;
809
  $$ = wims_mathml_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
810
  wims_mathml_free_string($2);
8910 bpr 811
}
5520 bpr 812
| BIGG RIGHTDELIM {
813
  $$ = wims_mathml_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
814
  wims_mathml_free_string($2);
815
}
816
| BIGG OTHERDELIM {
817
  $$ = wims_mathml_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
818
  wims_mathml_free_string($2);
819
}
820
| BBIGG LEFTDELIM {
821
  wims_mathml_rowposn = 2;
822
  $$ = wims_mathml_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
823
  wims_mathml_free_string($2);
824
}
825
| BBIGG RIGHTDELIM {
826
  $$ = wims_mathml_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
827
  wims_mathml_free_string($2);
828
}
829
| BBIGG OTHERDELIM {
830
  $$ = wims_mathml_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
831
  wims_mathml_free_string($2);
832
}
833
|BIGL LEFTDELIM {
834
  wims_mathml_rowposn = 2;
835
  $$ = wims_mathml_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
836
  wims_mathml_free_string($2);
837
}
838
| BIGL OTHERDELIM {
839
  wims_mathml_rowposn = 2;
840
  $$ = wims_mathml_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
841
  wims_mathml_free_string($2);
842
}
843
| BBIGL LEFTDELIM {
844
  wims_mathml_rowposn = 2;
845
  $$ = wims_mathml_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
846
  wims_mathml_free_string($2);
847
}
848
| BBIGL OTHERDELIM {
849
  wims_mathml_rowposn = 2;
850
  $$ = wims_mathml_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
851
  wims_mathml_free_string($2);
852
}
853
| BIGGL LEFTDELIM {
854
  wims_mathml_rowposn = 2;
855
  $$ = wims_mathml_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
856
  wims_mathml_free_string($2);
8910 bpr 857
}
5520 bpr 858
| BIGGL OTHERDELIM {
859
  wims_mathml_rowposn = 2;
860
  $$ = wims_mathml_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
861
  wims_mathml_free_string($2);
862
}
863
| BBIGGL LEFTDELIM {
864
  wims_mathml_rowposn = 2;
865
  $$ = wims_mathml_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
866
  wims_mathml_free_string($2);
867
}
868
| BBIGGL OTHERDELIM {
869
  wims_mathml_rowposn = 2;
870
  $$ = wims_mathml_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
871
  wims_mathml_free_string($2);
872
};
873
 
874
unrecognized: UNKNOWNCHAR {
875
  $$ = wims_mathml_copy_string("<merror><mtext>Unknown character</mtext></merror>");
876
};
877
 
878
unaryminus: UNARYMINUS {
879
  $$ = wims_mathml_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">&minus;</mo>");
880
};
881
 
882
unaryplus: UNARYPLUS {
883
  $$ = wims_mathml_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">+</mo>");
884
};
885
 
886
mi: MI;
887
 
888
mib: MIB {
889
  wims_mathml_rowposn=2;
890
  $$ = wims_mathml_copy3("<mi>", $1, "</mi>");
891
  wims_mathml_free_string($1);
892
};
893
 
894
mn: MN
895
| ITEXNUM TEXTSTRING {
896
  wims_mathml_rowposn = 2;
897
  $$ = wims_mathml_copy_string($2);
898
  wims_mathml_free_string($2);
899
};
900
 
901
mob: MOB {
902
  wims_mathml_rowposn = 2;
903
  $$ = wims_mathml_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $1, "</mo>");
904
  wims_mathml_free_string($1);
905
};
906
 
907
mo: mob
908
| bigdelim
909
| MO {
910
  wims_mathml_rowposn = 2;
911
  $$ = wims_mathml_copy3("<mo>", $1, "</mo>");
912
  wims_mathml_free_string($1);
913
}
914
| MOL {
915
  wims_mathml_rowposn = 2;
916
  $$ = wims_mathml_copy3("<mo>", $1, "</mo>");
917
  wims_mathml_free_string($1);
918
}
919
| MOLL {
920
  wims_mathml_rowposn = 2;
921
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"0\"><mo>", $1, "</mo></mstyle>");
922
  wims_mathml_free_string($1);
923
}
924
| RIGHTDELIM {
925
  $$ = wims_mathml_copy3("<mo stretchy=\"false\">", $1, "</mo>");
926
  wims_mathml_free_string($1);
927
}
928
| LEFTDELIM {
929
  wims_mathml_rowposn = 2;
930
  $$ = wims_mathml_copy3("<mo stretchy=\"false\">", $1, "</mo>");
931
  wims_mathml_free_string($1);
932
}
933
| OTHERDELIM {
934
  $$ = wims_mathml_copy3("<mo stretchy=\"false\">", $1, "</mo>");
935
  wims_mathml_free_string($1);
936
}
937
| MOF {
938
  $$ = wims_mathml_copy3("<mo stretchy=\"false\">", $1, "</mo>");
939
  wims_mathml_free_string($1);
940
}
941
| PERIODDELIM {
942
  $$ = wims_mathml_copy3("<mo>", $1, "</mo>");
943
  wims_mathml_free_string($1);
944
}
945
| MOS {
946
  wims_mathml_rowposn=2;
947
  $$ = wims_mathml_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $1, "</mo>");
948
  wims_mathml_free_string($1);
949
}
950
| MOP {
951
  wims_mathml_rowposn = 2;
952
  $$ = wims_mathml_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $1, "</mo>");
953
  wims_mathml_free_string($1);
954
}
955
| MOR {
956
  wims_mathml_rowposn = 2;
957
  $$ = wims_mathml_copy3("<mo lspace=\"verythinmathspace\">", $1, "</mo>");
958
  wims_mathml_free_string($1);
959
}
960
| OPERATORNAME TEXTSTRING {
961
  wims_mathml_rowposn = 2;
962
  $$ = wims_mathml_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $2, "</mo>");
963
  wims_mathml_free_string($2);
964
}
965
| MATHOP TEXTSTRING {
966
  wims_mathml_rowposn = 2;
967
  $$ = wims_mathml_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $2, "</mo>");
968
  wims_mathml_free_string($2);
969
}
970
| MATHBIN TEXTSTRING {
971
  wims_mathml_rowposn = 2;
972
  $$ = wims_mathml_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $2, "</mo>");
973
  wims_mathml_free_string($2);
974
}
975
| MATHREL TEXTSTRING {
976
  wims_mathml_rowposn = 2;
977
  $$ = wims_mathml_copy3("<mo lspace=\"thickmathspace\" rspace=\"thickmathspace\">", $2, "</mo>");
978
  wims_mathml_free_string($2);
979
};
980
 
981
space: SPACE ST INTONE END ST INTTWO END ST INTTHREE END {
982
  char * s1 = wims_mathml_copy3("<mspace height=\"", $3, "ex\" depth=\"");
983
  char * s2 = wims_mathml_copy3($6, "ex\" width=\"", $9);
984
  $$ = wims_mathml_copy3(s1, s2, "em\"></mspace>");
985
  wims_mathml_free_string(s1);
986
  wims_mathml_free_string(s2);
987
  wims_mathml_free_string($3);
988
  wims_mathml_free_string($6);
989
  wims_mathml_free_string($9);
990
};
991
 
992
statusline: STATLINE TEXTSTRING closedTerm {
993
  char * s1 = wims_mathml_copy3("<maction actiontype=\"statusline\">", $3, "<mtext>");
994
  $$ = wims_mathml_copy3(s1, $2, "</mtext></maction>");
995
  wims_mathml_free_string(s1);
996
  wims_mathml_free_string($2);
997
  wims_mathml_free_string($3);
998
};
999
 
1000
tooltip: TOOLTIP TEXTSTRING closedTerm {
1001
  char * s1 = wims_mathml_copy3("<maction actiontype=\"tooltip\">", $3, "<mtext>");
1002
  $$ = wims_mathml_copy3(s1, $2, "</mtext></maction>");
1003
  wims_mathml_free_string(s1);
1004
  wims_mathml_free_string($2);
1005
  wims_mathml_free_string($3);
1006
};
1007
 
1008
toggle: TOGGLE closedTerm closedTerm {
1009
  char * s1 = wims_mathml_copy3("<maction actiontype=\"toggle\" selection=\"2\">", $2, " ");
1010
  $$ = wims_mathml_copy3(s1, $3, "</maction>");
1011
  wims_mathml_free_string(s1);
1012
  wims_mathml_free_string($2);
1013
  wims_mathml_free_string($3);
1014
};
1015
 
1016
fghighlight: FGHIGHLIGHT ATTRLIST closedTerm {
1017
  char * s1 = wims_mathml_copy3("<maction actiontype=\"highlight\" other=\"color=", $2, "\">");
1018
  $$ = wims_mathml_copy3(s1, $3, "</maction>");
1019
  wims_mathml_free_string(s1);
1020
  wims_mathml_free_string($2);
1021
  wims_mathml_free_string($3);
1022
};
1023
 
1024
bghighlight: BGHIGHLIGHT ATTRLIST closedTerm {
1025
  char * s1 = wims_mathml_copy3("<maction actiontype=\"highlight\" other=\"background=", $2, "\">");
1026
  $$ = wims_mathml_copy3(s1, $3, "</maction>");
1027
  wims_mathml_free_string(s1);
1028
  wims_mathml_free_string($2);
1029
  wims_mathml_free_string($3);
1030
};
1031
 
1032
color: COLOR ATTRLIST compoundTermList {
1033
  char * s1 = wims_mathml_copy3("<mstyle mathcolor=", $2, ">");
1034
  $$ = wims_mathml_copy3(s1, $3, "</mstyle>");
1035
  wims_mathml_free_string(s1);
1036
  wims_mathml_free_string($2);
1037
  wims_mathml_free_string($3);
1038
}
1039
| BGCOLOR ATTRLIST compoundTermList {
1040
  char * s1 = wims_mathml_copy3("<mstyle mathbackground=", $2, ">");
1041
  $$ = wims_mathml_copy3(s1, $3, "</mstyle>");
1042
  wims_mathml_free_string(s1);
1043
  wims_mathml_free_string($2);
1044
  wims_mathml_free_string($3);
1045
};
1046
 
1047
 
1048
input: INPUT {
15175 obado 1049
  int len = strlen(yylval);
1050
  char size[len];
1051
  char id[len];
1052
  char style[len];
1053
  char value[len];
1054
  char readonly[len];
1055
  memset(size,'\0',len);
1056
  memset(id,'\0',len);
1057
  memset(value,'\0',len);
1058
  memset(style,'\0',len);
1059
  memset(readonly,'\0',len);
1060
  int found_left = 0;
1061
  int found_right = 0;
1062
  int cnt=0;
1063
  char tmp[2];
1064
  int i;
1065
  for(i = 0 ; i < len ; i++){
1066
    if( yylval[i] == '{' ){
1067
      found_left=1;found_right=0;
1068
    } else {
1069
      if( yylval[i] == '}' ){
1070
        cnt++;found_left=0;found_right=1;
1071
      } else {
1072
        if(found_left == 1 && found_right == 0){
1073
          tmp[0] = yylval[i];
1074
          tmp[1] = '\0';
1075
          switch (cnt){
1076
            case 0 : strncat(size,tmp,1);break;
1077
            case 1 : strncat(id,tmp,1);break;
1078
            case 2 : strncat(style,tmp,1);break;
1079
            case 3 : strncat(value,tmp,1);break;
1080
            case 4 : strncat(readonly,tmp,1);break;
1081
            default : break;
1082
          }
1083
        }
1084
      }
5520 bpr 1085
    }
15175 obado 1086
  }
1087
  char * s1 = "<semantics><annotation-xml encoding=\"application/xhtml+xml\"><textarea xmlns=\"http://www.w3.org/1999/xhtml\"  onkeydown=\"return (event.keyCode!=13);\"";
1088
  $1 = wims_mathml_copy_string(id);
1089
  s1 = wims_mathml_copy5(s1, " rows=\"1\" id=\"mathml",$1,"\"",0);
1090
  $1 = wims_mathml_copy_string(size);
1091
  s1 = wims_mathml_copy3(s1," style=\"width:",$1);
1092
  $1 = wims_mathml_copy_string(style);
1093
  s1 = wims_mathml_copy5(s1,"em;",$1,"\"",0);
1094
  if( strstr(readonly,"1") != NULL){
1095
    s1 = wims_mathml_copy2(s1," readonly=\"readonly\">");
1096
  } else {
1097
    s1 = wims_mathml_copy2(s1,">");
1098
  }
1099
  $1 = wims_mathml_copy_string(value);
1100
  s1 = wims_mathml_copy3(s1,$1,"</textarea></annotation-xml></semantics>");
1101
  $$ = wims_mathml_copy_string(s1);
1102
  wims_mathml_free_string(s1);
1103
  wims_mathml_free_string($1);
5520 bpr 1104
};
1105
 
16596 bpr 1106
lewis: LEWIS closedTerm closedTerm closedTerm closedTerm closedTerm closedTerm closedTerm closedTerm closedTerm {
16678 bpr 1107
  char *s1 = wims_mathml_copy13("<mtable columnspacing=\"0.3ex\" columnalign=\"left\" columnlines=\"none\" rowlines=\"none\" rowalign=\"center\" displaystyle=\"true\"><mtr><mtd><mstyle mathsize=\"70%\"><munderover><mrow mathsize=\"110%\">",$3,"</mrow><mphantom></mphantom><mrow mathsize=\"110%\">",$4,"</mrow></munderover></mstyle></mtd><mtd><munderover>",$2,"<mrow>",$10,$9,"</mrow><mrow>",$5,$6,"</mrow></munderover></mtd><mtd><mstyle mathsize=\"70%\"><munderover><mrow mathsize=\"110%\">");
16599 bpr 1108
  $$ = wims_mathml_copy5 (s1,$8,"</mrow><mphantom></mphantom><mrow mathsize=\"110%\">",$7,
1109
"</mrow></munderover></mstyle></mtd></mtr></mtable>");
16596 bpr 1110
  wims_mathml_free_string(s1);
1111
  wims_mathml_free_string($2);
1112
  wims_mathml_free_string($3);
1113
  wims_mathml_free_string($4);
1114
  wims_mathml_free_string($5);
1115
  wims_mathml_free_string($6);
1116
  wims_mathml_free_string($7);
1117
  wims_mathml_free_string($8);
1118
  wims_mathml_free_string($9);
1119
  wims_mathml_free_string($10);
1120
};
1121
 
5520 bpr 1122
special: SPECIAL ATTRLIST compoundTermList {
1123
  char * s1 = wims_mathml_copy3("<mstyle mathcolor=", $2, ">");
1124
  $$ = wims_mathml_copy3(s1, $3, "</mstyle>");
1125
  wims_mathml_free_string(s1);
1126
  wims_mathml_free_string($2);
1127
  wims_mathml_free_string($3);
1128
};
1129
 
1130
mathrlap: RLAP closedTerm {
1131
  $$ = wims_mathml_copy3("<mpadded width=\"0\">", $2, "</mpadded>");
1132
  wims_mathml_free_string($2);
1133
};
1134
 
1135
mathllap: LLAP closedTerm {
1136
  $$ = wims_mathml_copy3("<mpadded width=\"0\" lspace=\"-100%width\">", $2, "</mpadded>");
1137
  wims_mathml_free_string($2);
1138
};
1139
 
1140
mathclap: CLAP closedTerm {
1141
  $$ = wims_mathml_copy3("<mpadded width=\"0\" lspace=\"-50%width\">", $2, "</mpadded>");
1142
  wims_mathml_free_string($2);
1143
};
1144
 
1145
textstring: TEXTBOX TEXTSTRING {
1146
  $$ = wims_mathml_copy3("<mtext>", $2, "</mtext>");
1147
  wims_mathml_free_string($2);
1148
};
1149
 
1150
displaystyle: DISPLAY compoundTermList {
1151
  $$ = wims_mathml_copy3("<mstyle displaystyle=\"true\">", $2, "</mstyle>");
1152
  wims_mathml_free_string($2);
1153
};
1154
 
1155
textstyle: TEXTSTY compoundTermList {
1156
  $$ = wims_mathml_copy3("<mstyle displaystyle=\"false\">", $2, "</mstyle>");
1157
  wims_mathml_free_string($2);
1158
};
1159
 
1160
textsize: TEXTSIZE compoundTermList {
1161
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"0\">", $2, "</mstyle>");
1162
  wims_mathml_free_string($2);
1163
};
1164
 
1165
scriptsize: SCSIZE compoundTermList {
1166
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"1\">", $2, "</mstyle>");
1167
  wims_mathml_free_string($2);
1168
};
1169
 
1170
scriptscriptsize: SCSCSIZE compoundTermList {
1171
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"2\">", $2, "</mstyle>");
1172
  wims_mathml_free_string($2);
1173
};
1174
 
1175
italics: ITALICS closedTerm {
1176
  $$ = wims_mathml_copy3("<mstyle mathvariant=\"italic\">", $2, "</mstyle>");
1177
  wims_mathml_free_string($2);
1178
};
1179
 
1180
 
1181
slashed: SLASHED closedTerm {
1182
  $$ = wims_mathml_copy3("<menclose notation=\"updiagonalstrike\">", $2, "</menclose>");
1183
  wims_mathml_free_string($2);
1184
};
1185
 
1186
boxed: BOXED closedTerm {
1187
  $$ = wims_mathml_copy3("<menclose notation=\"box\">", $2, "</menclose>");
1188
  wims_mathml_free_string($2);
1189
};
1190
 
1191
bold: BOLD closedTerm {
1192
  $$ = wims_mathml_copy3("<mstyle mathvariant=\"bold\">", $2, "</mstyle>");
1193
  wims_mathml_free_string($2);
1194
};
1195
 
1196
roman: RM ST rmchars END {
1197
  $$ = wims_mathml_copy3("<mi mathvariant=\"normal\">", $3, "</mi>");
1198
  wims_mathml_free_string($3);
1199
};
1200
 
1201
roman: WIMSROMAN closedTerm{
1202
  $$ = wims_mathml_copy3("<mi mathvariant=\"normal\">", $2, "</mi>");
1203
  wims_mathml_free_string($2);
1204
};
1205
 
1206
rmchars: RMCHAR {
1207
  $$ = wims_mathml_copy_string($1);
1208
  wims_mathml_free_string($1);
1209
}
1210
| rmchars RMCHAR {
1211
  $$ = wims_mathml_copy2($1, $2);
1212
  wims_mathml_free_string($1);
1213
  wims_mathml_free_string($2);
1214
};
1215
 
1216
bbold: BB ST bbchars END {
1217
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1218
  wims_mathml_free_string($3);
1219
};
1220
 
1221
bbchars: bbchar {
1222
  $$ = wims_mathml_copy_string($1);
1223
  wims_mathml_free_string($1);
1224
}
1225
| bbchars bbchar {
1226
  $$ = wims_mathml_copy2($1, $2);
1227
  wims_mathml_free_string($1);
1228
  wims_mathml_free_string($2);
1229
};
1230
 
1231
bbchar: BBLOWERCHAR {
1232
  $$ = wims_mathml_copy3("&", $1, "opf;");
1233
  wims_mathml_free_string($1);
1234
}
1235
| BBUPPERCHAR {
1236
  $$ = wims_mathml_copy3("&", $1, "opf;");
1237
  wims_mathml_free_string($1);
1238
}
1239
| BBDIGIT {
1240
  /* Blackboard digits 0-9 correspond to Unicode characters 0x1D7D8-0x1D7E1 */
1241
  char * end = $1 + 1;
1242
  int code = 0x1D7D8 + strtoul($1, &end, 10);
1243
  $$ = wims_mathml_character_reference(code);
1244
  wims_mathml_free_string($1);
1245
};
1246
 
1247
frak: FRAK ST frakletters END {
1248
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1249
  wims_mathml_free_string($3);
1250
};
1251
 
1252
frakletters: frakletter {
1253
  $$ = wims_mathml_copy_string($1);
1254
  wims_mathml_free_string($1);
1255
}
1256
| frakletters frakletter {
1257
  $$ = wims_mathml_copy2($1, $2);
1258
  wims_mathml_free_string($1);
1259
  wims_mathml_free_string($2);
1260
};
1261
 
1262
frakletter: FRAKCHAR {
1263
  $$ = wims_mathml_copy3("&", $1, "fr;");
1264
  wims_mathml_free_string($1);
1265
};
1266
 
1267
cal: CAL ST calletters END {
1268
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1269
  wims_mathml_free_string($3);
1270
};
1271
 
1272
calletters: calletter {
1273
  $$ = wims_mathml_copy_string($1);
1274
  wims_mathml_free_string($1);
1275
}
1276
| calletters calletter {
1277
  $$ = wims_mathml_copy2($1, $2);
1278
  wims_mathml_free_string($1);
1279
  wims_mathml_free_string($2);
1280
};
1281
 
1282
calletter: CALCHAR {
9540 bpr 1283
  $$ = wims_mathml_copy3("&",$1,"scr;");
5520 bpr 1284
  wims_mathml_free_string($1);
1285
};
1286
 
1287
thinspace: THINSPACE {
1288
  $$ = wims_mathml_copy_string("<mspace width=\"thinmathspace\"></mspace>");
1289
};
1290
 
1291
medspace: MEDSPACE {
1292
  $$ = wims_mathml_copy_string("<mspace width=\"mediummathspace\"></mspace>");
1293
};
1294
 
1295
thickspace: THICKSPACE {
1296
  $$ = wims_mathml_copy_string("<mspace width=\"thickmathspace\"></mspace>");
1297
};
1298
 
1299
quad: QUAD {
1300
  $$ = wims_mathml_copy_string("<mspace width=\"1em\"></mspace>");
1301
};
1302
 
1303
qquad: QQUAD {
1304
  $$ = wims_mathml_copy_string("<mspace width=\"2em\"></mspace>");
1305
};
1306
 
1307
negspace: NEGSPACE {
1308
  $$ = wims_mathml_copy_string("<mspace width=\"-0.1667 em\"></mspace>");
1309
};
1310
 
1311
phantom: PHANTOM closedTerm {
1312
  $$ = wims_mathml_copy3("<mphantom>", $2, "</mphantom>");
1313
  wims_mathml_free_string($2);
1314
};
1315
 
1316
href: HREF TEXTSTRING closedTerm {
1317
  char * s1 = wims_mathml_copy3("<mrow href=\"", $2, "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
1318
  char * s2 = wims_mathml_copy3(s1, $2, "\">");
1319
  $$ = wims_mathml_copy3(s2, $3, "</mrow>");
1320
  wims_mathml_free_string(s1);
1321
  wims_mathml_free_string(s2);
1322
  wims_mathml_free_string($2);
1323
  wims_mathml_free_string($3);
1324
};
1325
 
1326
tensor: TENSOR closedTerm MROWOPEN subsupList MROWCLOSE {
1327
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $2, $4);
1328
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1329
  wims_mathml_free_string(s1);
1330
  wims_mathml_free_string($2);
1331
  wims_mathml_free_string($4);
1332
}
1333
| TENSOR closedTerm subsupList {
1334
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $2, $3);
1335
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1336
  wims_mathml_free_string(s1);
1337
  wims_mathml_free_string($2);
1338
  wims_mathml_free_string($3);
1339
};
1340
 
1341
multi: MULTI MROWOPEN subsupList MROWCLOSE closedTerm MROWOPEN subsupList MROWCLOSE {
1342
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $5, $7);
1343
  char * s2 = wims_mathml_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1344
  $$ = wims_mathml_copy2(s1, s2);
1345
  wims_mathml_free_string(s1);
1346
  wims_mathml_free_string(s2);
1347
  wims_mathml_free_string($3);
1348
  wims_mathml_free_string($5);
1349
  wims_mathml_free_string($7);
1350
}
1351
| MULTI MROWOPEN subsupList MROWCLOSE closedTerm EMPTYMROW {
1352
  char * s1 = wims_mathml_copy2("<mmultiscripts>", $5);
1353
  char * s2 = wims_mathml_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1354
  $$ = wims_mathml_copy2(s1, s2);
1355
  wims_mathml_free_string(s1);
1356
  wims_mathml_free_string(s2);
1357
  wims_mathml_free_string($3);
1358
  wims_mathml_free_string($5);
1359
}
1360
| MULTI EMPTYMROW closedTerm MROWOPEN subsupList MROWCLOSE {
1361
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $3, $5);
1362
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1363
  wims_mathml_free_string(s1);
1364
  wims_mathml_free_string($3);
8910 bpr 1365
  wims_mathml_free_string($5);
5520 bpr 1366
};
1367
 
1368
subsupList: subsupTerm {
1369
  $$ = wims_mathml_copy_string($1);
1370
  wims_mathml_free_string($1);
1371
}
1372
| subsupList subsupTerm {
1373
  $$ = wims_mathml_copy3($1, " ", $2);
1374
  wims_mathml_free_string($1);
1375
  wims_mathml_free_string($2);
1376
};
1377
 
1378
subsupTerm: SUB closedTerm SUP closedTerm {
1379
  $$ = wims_mathml_copy3($2, " ", $4);
1380
  wims_mathml_free_string($2);
1381
  wims_mathml_free_string($4);
1382
}
1383
| SUB closedTerm {
1384
  $$ = wims_mathml_copy2($2, " <none></none>");
1385
  wims_mathml_free_string($2);
1386
}
1387
| SUP closedTerm {
1388
  $$ = wims_mathml_copy2("<none></none> ", $2);
1389
  wims_mathml_free_string($2);
1390
}
1391
| SUB SUP closedTerm {
1392
  $$ = wims_mathml_copy2("<none></none> ", $3);
1393
  wims_mathml_free_string($3);
1394
};
1395
 
1396
mfrac: DFRAC closedTerm closedTerm {
1397
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\" fontsize=\"120%\"><mfrac>", $2, $3);
1398
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1399
  wims_mathml_free_string(s1);
1400
  wims_mathml_free_string($2);
1401
  wims_mathml_free_string($3);
1402
}
1403
| FRAC closedTerm closedTerm {
1404
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\"><mfrac>", $2, $3);
1405
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1406
  wims_mathml_free_string(s1);
1407
  wims_mathml_free_string($2);
1408
  wims_mathml_free_string($3);
1409
}
1410
| TFRAC closedTerm closedTerm {
1411
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"false\"><mfrac>", $2, $3);
1412
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1413
  wims_mathml_free_string(s1);
1414
  wims_mathml_free_string($2);
1415
  wims_mathml_free_string($3);
1416
}
1417
| SFRAC closedTerm closedTerm{
1418
  $$ = wims_mathml_copy5("<mstyle scriptlevel=\"1\"><msup><mrow/>",$2,"</msup><msub><mo lspace=\"verythinmathspace\" stretchy=\"true\">&#x2571;</mo>",$3,"</msub></mstyle>");
1419
  wims_mathml_free_string($2);
1420
  wims_mathml_free_string($3);
1421
};
1422
 
1423
 
1424
pmod: PMOD closedTerm {
1425
  $$ = wims_mathml_copy3( "<mo lspace=\"mediummathspace\">(</mo><mo rspace=\"thinmathspace\">mod</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo>");
1426
  wims_mathml_free_string($2);
5996 schaersvoo 1427
};
5520 bpr 1428
 
14226 schaersvoo 1429
brack:
1430
MROWOPEN compoundTermList BRACK compoundTermList MROWCLOSE {
1431
 char *s1;
1432
 switch( wims_mathml_shortcut ){
1433
  case 0: s1 = wims_mathml_copy3("<mrow><mo>[</mo><mfrac linethickness=\"0\">", $2, $4);
15175 obado 1434
    $$ = wims_mathml_copy2(s1,"</mfrac><mo>]</mo></mrow>");break;
14226 schaersvoo 1435
  case 1: s1 = wims_mathml_copy3("<mrow><mo>{</mo><mfrac linethickness=\"0\">", $2, $4);
15175 obado 1436
    $$ = wims_mathml_copy2(s1,"</mfrac><mo>}</mo></mrow>");
14226 schaersvoo 1437
          break;
1438
  default: break;
1439
  }
1440
  wims_mathml_free_string(s1);
1441
  wims_mathml_free_string($2);
1442
  wims_mathml_free_string($4);
1443
};
1444
 
1445
 
5520 bpr 1446
texover: MROWOPEN compoundTermList BINOM2 compoundTermList MROWCLOSE {
5613 schaersvoo 1447
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $4);
5520 bpr 1448
  $$ = wims_mathml_copy2(s1,"</mfrac><mo>)</mo></mrow>");
1449
  wims_mathml_free_string(s1);
1450
  wims_mathml_free_string($2);
5613 schaersvoo 1451
  wims_mathml_free_string($4);
5520 bpr 1452
}
5996 schaersvoo 1453
| MROWOPEN compoundTermList TEXOVER compoundTermList MROWCLOSE {
6185 schaersvoo 1454
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\"><mfrac><mrow>", $2, "</mrow><mrow>");
1455
  $$ = wims_mathml_copy3(s1, $4, "</mrow></mfrac></mstyle>");
5520 bpr 1456
  wims_mathml_free_string(s1);
1457
  wims_mathml_free_string($2);
1458
  wims_mathml_free_string($4);
1459
}
1460
| left compoundTermList TEXOVER compoundTermList right {
6185 schaersvoo 1461
  char * s1 = wims_mathml_copy3("<mrow>", $1, "<mstyle displaystyle=\"true\"><mfrac><mrow>");
5520 bpr 1462
  char * s2 = wims_mathml_copy3($2, "</mrow><mrow>", $4);
6185 schaersvoo 1463
  char * s3 = wims_mathml_copy3("</mrow></mfrac></mstyle>", $5, "</mrow>");
5520 bpr 1464
  $$ = wims_mathml_copy3(s1, s2, s3);
1465
  wims_mathml_free_string(s1);
1466
  wims_mathml_free_string(s2);
1467
  wims_mathml_free_string(s3);
1468
  wims_mathml_free_string($1);
1469
  wims_mathml_free_string($2);
1470
  wims_mathml_free_string($4);
1471
  wims_mathml_free_string($5);
1472
};
1473
 
1474
texatop: MROWOPEN compoundTermList TEXATOP compoundTermList MROWCLOSE {
1475
  char * s1 = wims_mathml_copy3("<mfrac linethickness=\"0\"><mrow>", $2, "</mrow><mrow>");
1476
  $$ = wims_mathml_copy3(s1, $4, "</mrow></mfrac>");
1477
  wims_mathml_free_string(s1);
1478
  wims_mathml_free_string($2);
1479
  wims_mathml_free_string($4);
1480
}
1481
| left compoundTermList TEXATOP compoundTermList right {
1482
  char * s1 = wims_mathml_copy3("<mrow>", $1, "<mfrac linethickness=\"0\"><mrow>");
1483
  char * s2 = wims_mathml_copy3($2, "</mrow><mrow>", $4);
1484
  char * s3 = wims_mathml_copy3("</mrow></mfrac>", $5, "</mrow>");
1485
  $$ = wims_mathml_copy3(s1, s2, s3);
1486
  wims_mathml_free_string(s1);
1487
  wims_mathml_free_string(s2);
1488
  wims_mathml_free_string(s3);
1489
  wims_mathml_free_string($1);
1490
  wims_mathml_free_string($2);
1491
  wims_mathml_free_string($4);
1492
  wims_mathml_free_string($5);
1493
};
1494
 
1495
binom: BINOM closedTerm closedTerm {
1496
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $3);
1497
  $$ = wims_mathml_copy2(s1, "</mfrac><mo>)</mo></mrow>");
1498
  wims_mathml_free_string(s1);
1499
  wims_mathml_free_string($2);
1500
  wims_mathml_free_string($3);
1501
}
1502
| TBINOM closedTerm closedTerm {
1503
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mstyle displaystyle=\"false\"><mfrac linethickness=\"0\">", $2, $3);
1504
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle><mo>)</mo></mrow>");
1505
  wims_mathml_free_string(s1);
1506
  wims_mathml_free_string($2);
1507
  wims_mathml_free_string($3);
1508
};
1509
 
1510
munderbrace: UNDERBRACE closedTerm {
1511
  $$ = wims_mathml_copy3("<munder>", $2, "<mo>&UnderBrace;</mo></munder>");
1512
  wims_mathml_free_string($2);
1513
};
1514
 
1515
munderline: UNDERLINE closedTerm {
1516
  $$ = wims_mathml_copy3("<munder>", $2, "<mo>&#x00332;</mo></munder>");
1517
  wims_mathml_free_string($2);
1518
};
1519
 
1520
moverbrace: OVERBRACE closedTerm {
1521
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&OverBrace;</mo></mover>");
1522
  wims_mathml_free_string($2);
1523
};
1524
 
1525
bar: BAR closedTerm {
1526
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x000AF;</mo></mover>");
1527
  wims_mathml_free_string($2);
1528
}
1529
| WIDEBAR closedTerm {
12086 schaersvoo 1530
  $$ = wims_mathml_copy3("<mover>", $2, "<mo> &#x000AF; </mo></mover>");
5520 bpr 1531
  wims_mathml_free_string($2);
1532
};
1533
 
1534
vec: VEC closedTerm {
1535
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&RightVector;</mo></mover>");
1536
  wims_mathml_free_string($2);
1537
}
1538
| WIDEVEC closedTerm {
1539
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&RightVector;</mo></mover>");
1540
  wims_mathml_free_string($2);
1541
};
1542
 
7225 schaersvoo 1543
overarrow: OVERARROW closedTerm {
1544
  $$ = wims_mathml_copy5("<mover>", $2, "<mo stretchy=\"true\">", $1 ,"</mo></mover>");
1545
  wims_mathml_free_string($1);
7224 schaersvoo 1546
  wims_mathml_free_string($2);
7219 schaersvoo 1547
};
1548
 
7225 schaersvoo 1549
underarrow: UNDERARROW closedTerm {
1550
  $$ = wims_mathml_copy5("<munder>", $2, "<mo stretchy=\"true\">", $1 ,"</mo></munder>");
1551
  wims_mathml_free_string($1);
7224 schaersvoo 1552
  wims_mathml_free_string($2);
7219 schaersvoo 1553
};
1554
 
5520 bpr 1555
dot: DOT closedTerm {
1556
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&dot;</mo></mover>");
1557
  wims_mathml_free_string($2);
1558
};
1559
 
1560
ddot: DDOT closedTerm {
1561
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&Dot;</mo></mover>");
1562
  wims_mathml_free_string($2);
1563
};
1564
 
1565
dddot: DDDOT closedTerm {
1566
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&tdot;</mo></mover>");
1567
  wims_mathml_free_string($2);
1568
};
1569
 
1570
ddddot: DDDDOT closedTerm {
1571
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&DotDot;</mo></mover>");
1572
  wims_mathml_free_string($2);
1573
};
1574
 
12073 bpr 1575
accents: ACCENTS closedTerm {
11727 schaersvoo 1576
/*
12073 bpr 1577
 see https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes
1578
 jm.evers 29/6/2017
11727 schaersvoo 1579
*/
1580
 int pos=1;char *s1 = " ";
11715 schaersvoo 1581
 if( strstr($1,"\"") != NULL ){s1 = wims_mathml_copy_string( "&uml;");}
11708 schaersvoo 1582
 else
11715 schaersvoo 1583
 if( strstr($1,"'") != NULL ){s1 = wims_mathml_copy_string( "&acute;");}
11708 schaersvoo 1584
 else
11715 schaersvoo 1585
 if( strstr($1,"`") != NULL ){s1 = wims_mathml_copy_string( "&grave;");}
11708 schaersvoo 1586
 else
11721 schaersvoo 1587
 if( strstr($1,"~") != NULL ){s1 = wims_mathml_copy_string( "&tilde;");}
1588
 else
11715 schaersvoo 1589
 if( strstr($1,".") != NULL ){s1 = wims_mathml_copy_string( "&dot;");}
11708 schaersvoo 1590
 else
11715 schaersvoo 1591
 if( strstr($1,"r") != NULL ){s1 = wims_mathml_copy_string( "&ring;");}
11708 schaersvoo 1592
 else
11715 schaersvoo 1593
 if( strstr($1,"c") != NULL ){s1 = wims_mathml_copy_string( "&cedil;");pos = 2;}
11708 schaersvoo 1594
 else
11715 schaersvoo 1595
 if( strstr($1,"=") != NULL ){s1 = wims_mathml_copy_string( "&macr;");}
11708 schaersvoo 1596
 else
11715 schaersvoo 1597
 if( strstr($1,"k") != NULL ){s1 = wims_mathml_copy_string( "&ogon;");pos = 2;}
11708 schaersvoo 1598
 else
11715 schaersvoo 1599
 if( strstr($1,"^") != NULL ){s1 = wims_mathml_copy_string( "&#x0005E;");}
11708 schaersvoo 1600
 else
11715 schaersvoo 1601
 if( strstr($1,"b") != NULL ){s1 = wims_mathml_copy_string( "&macr;");pos = 2;}
11708 schaersvoo 1602
 else
11715 schaersvoo 1603
 if( strstr($1,"v") != NULL ){s1 = wims_mathml_copy_string( "&#x2c7;");}
11708 schaersvoo 1604
 else
11715 schaersvoo 1605
 if( strstr($1,"d") != NULL ){s1 = wims_mathml_copy_string( "&dot;");pos = 2;}
11708 schaersvoo 1606
 else
11715 schaersvoo 1607
 if( strstr($1,"l") != NULL ){s1 = wims_mathml_copy_string( "&#x142;");pos = 3;}
11708 schaersvoo 1608
 else
11715 schaersvoo 1609
 if( strstr($1,"o") != NULL ){s1 = wims_mathml_copy_string( "&oslash;");pos = 3;}
11708 schaersvoo 1610
 else
11715 schaersvoo 1611
 if( strstr($1,"O") != NULL ){s1 = wims_mathml_copy_string( "&Oslash;");pos = 3;}
11708 schaersvoo 1612
 else
11715 schaersvoo 1613
 if( strstr($1,"H") != NULL ){s1 = wims_mathml_copy_string( "&#733;");}
11708 schaersvoo 1614
 else
11715 schaersvoo 1615
 if( strstr($1,"t") != NULL ){s1 = wims_mathml_copy_string( "&#8256;");}
11727 schaersvoo 1616
 else
1617
 if( strstr($1,"u") != NULL ){s1 = wims_mathml_copy_string( "&breve;");}
11708 schaersvoo 1618
 
11715 schaersvoo 1619
 if( pos == 1 ){ $$ = wims_mathml_copy5("<mover>",$2,"<mo stretchy=\"false\">",s1,"</mo></mover>");}
11708 schaersvoo 1620
 else
11715 schaersvoo 1621
 if( pos == 2 ){ $$ = wims_mathml_copy5("<munder>",$2,"<mo stretchy=\"false\">",s1,"</mo></munder>");}
1622
 else
1623
 if( pos == 3 ){ $$ = wims_mathml_copy3("<mo stretchy=\"false\">",s1,"</mo>");}
1624
 wims_mathml_free_string(s1);
1625
 wims_mathml_free_string($2);
11708 schaersvoo 1626
}
5520 bpr 1627
tilde: TILDE closedTerm {
1628
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&tilde;</mo></mover>");
1629
  wims_mathml_free_string($2);
1630
}
1631
| WIDETILDE closedTerm {
1632
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&tilde;</mo></mover>");
1633
  wims_mathml_free_string($2);
1634
};
1635
 
1636
check: CHECK closedTerm {
1637
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2c7;</mo></mover>");
1638
  wims_mathml_free_string($2);
1639
}
1640
| WIDECHECK closedTerm {
1641
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&#x2c7;</mo></mover>");
1642
  wims_mathml_free_string($2);
1643
};
1644
 
1645
hat: HAT closedTerm {
1646
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x5E;</mo></mover>");
1647
  wims_mathml_free_string($2);
1648
}
1649
| WIDEHAT closedTerm {
1650
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&#x5E;</mo></mover>");
1651
  wims_mathml_free_string($2);
1652
};
1653
 
1654
msqrt: SQRT closedTerm {
1655
  $$ = wims_mathml_copy3("<msqrt>", $2, "</msqrt>");
1656
  wims_mathml_free_string($2);
1657
};
1658
 
1659
mroot: SQRT OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1660
  char * s1 = wims_mathml_copy3("<mroot>", $5, $3);
1661
  $$ = wims_mathml_copy2(s1, "</mroot>");
1662
  wims_mathml_free_string(s1);
1663
  wims_mathml_free_string($3);
1664
  wims_mathml_free_string($5);
1665
}
1666
| ROOT closedTerm closedTerm {
1667
  char * s1 = wims_mathml_copy3("<mroot>", $3, $2);
1668
  $$ = wims_mathml_copy2(s1, "</mroot>");
1669
  wims_mathml_free_string(s1);
1670
  wims_mathml_free_string($2);
1671
  wims_mathml_free_string($3);
1672
};
1673
 
1674
raisebox: RAISEBOX TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1675
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"");
1676
  char * s2 = wims_mathml_copy3(s1, $3, "\" depth=\"");
1677
  char * s3 = wims_mathml_copy3(s2, $4, "\">");
1678
  $$ = wims_mathml_copy3(s3, $5, "</mpadded>");
1679
  wims_mathml_free_string(s1);
1680
  wims_mathml_free_string(s2);
1681
  wims_mathml_free_string(s3);
1682
  wims_mathml_free_string($2);
1683
  wims_mathml_free_string($3);
1684
  wims_mathml_free_string($4);
1685
  wims_mathml_free_string($5);
1686
}
1687
| RAISEBOX NEG TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1688
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"");
1689
  char * s2 = wims_mathml_copy3(s1, $4, "\" depth=\"");
1690
  char * s3 = wims_mathml_copy3(s2, $5, "\">");
1691
  $$ = wims_mathml_copy3(s3, $6, "</mpadded>");
1692
  wims_mathml_free_string(s1);
1693
  wims_mathml_free_string(s2);
1694
  wims_mathml_free_string(s3);
1695
  wims_mathml_free_string($3);
1696
  wims_mathml_free_string($4);
1697
  wims_mathml_free_string($5);
1698
  wims_mathml_free_string($6);
1699
}
1700
| RAISEBOX TEXTSTRING TEXTSTRING closedTerm {
1701
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"");
1702
  char * s2 = wims_mathml_copy3(s1, $3, "\" depth=\"depth\">");
1703
  $$ = wims_mathml_copy3(s2, $4, "</mpadded>");
1704
  wims_mathml_free_string(s1);
1705
  wims_mathml_free_string(s2);
1706
  wims_mathml_free_string($2);
1707
  wims_mathml_free_string($3);
1708
  wims_mathml_free_string($4);
1709
}
1710
| RAISEBOX NEG TEXTSTRING TEXTSTRING closedTerm {
1711
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"");
1712
  char * s2 = wims_mathml_copy3(s1, $4, "\" depth=\"+");
1713
  char * s3 = wims_mathml_copy3(s2, $3, "\">");
1714
  $$ = wims_mathml_copy3(s3, $5, "</mpadded>");
1715
  wims_mathml_free_string(s1);
1716
  wims_mathml_free_string(s2);
1717
  wims_mathml_free_string(s3);
1718
  wims_mathml_free_string($3);
1719
  wims_mathml_free_string($4);
1720
  wims_mathml_free_string($5);
1721
}
1722
| RAISEBOX TEXTSTRING closedTerm {
1723
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"+");
1724
  char * s2 = wims_mathml_copy3(s1, $2, "\" depth=\"depth\">");
1725
  $$ = wims_mathml_copy3(s2, $3, "</mpadded>");
1726
  wims_mathml_free_string(s1);
1727
  wims_mathml_free_string(s2);
1728
  wims_mathml_free_string($2);
1729
  wims_mathml_free_string($3);
1730
}
1731
| RAISEBOX NEG TEXTSTRING closedTerm {
1732
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"0pt\" depth=\"+");
1733
  char * s2 = wims_mathml_copy3(s1, $3, "\">");
1734
  $$ = wims_mathml_copy3(s2, $4, "</mpadded>");
1735
  wims_mathml_free_string(s1);
1736
  wims_mathml_free_string(s2);
1737
  wims_mathml_free_string($3);
1738
  wims_mathml_free_string($4);
1739
};
1740
 
1741
munder: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE EMPTYMROW {
1742
  char * s1 = wims_mathml_copy3("<munder><mo>", $1, "</mo><mrow>");
1743
  $$ = wims_mathml_copy3(s1, $3, "</mrow></munder>");
1744
  wims_mathml_free_string(s1);
1745
  wims_mathml_free_string($1);
1746
  wims_mathml_free_string($3);
1747
}
1748
| UNDER closedTerm closedTerm {
1749
  char * s1 = wims_mathml_copy3("<munder>", $3, $2);
1750
  $$ = wims_mathml_copy2(s1, "</munder>");
1751
  wims_mathml_free_string(s1);
1752
  wims_mathml_free_string($2);
1753
  wims_mathml_free_string($3);
1754
};
1755
 
1756
mover: XARROW closedTerm {
1757
  char * s1 = wims_mathml_copy3("<mover><mo>", $1, "</mo>");
1758
  $$ =  wims_mathml_copy3(s1, $2, "</mover>");
1759
  wims_mathml_free_string(s1);
1760
  wims_mathml_free_string($1);
1761
  wims_mathml_free_string($2);
1762
}
1763
| OVER closedTerm closedTerm {
1764
  char * s1 = wims_mathml_copy3("<mover>", $3, $2);
1765
  $$ = wims_mathml_copy2(s1, "</mover>");
1766
  wims_mathml_free_string(s1);
1767
  wims_mathml_free_string($2);
1768
  wims_mathml_free_string($3);
1769
};
1770
 
1771
munderover: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1772
  char * s1 = wims_mathml_copy3("<munderover><mo>", $1, "</mo><mrow>");
1773
  char * s2 = wims_mathml_copy3(s1, $3, "</mrow>");
1774
  $$ = wims_mathml_copy3(s2, $5, "</munderover>");
1775
  wims_mathml_free_string(s1);
1776
  wims_mathml_free_string(s2);
1777
  wims_mathml_free_string($1);
1778
  wims_mathml_free_string($3);
1779
  wims_mathml_free_string($5);
1780
}
1781
| UNDEROVER closedTerm closedTerm closedTerm {
1782
  char * s1 = wims_mathml_copy3("<munderover>", $4, $2);
1783
  $$ = wims_mathml_copy3(s1, $3, "</munderover>");
1784
  wims_mathml_free_string(s1);
1785
  wims_mathml_free_string($2);
1786
  wims_mathml_free_string($3);
1787
  wims_mathml_free_string($4);
1788
};
1789
 
1790
emptymrow: EMPTYMROW {
1791
  $$ = wims_mathml_copy_string("<mrow></mrow>");
1792
};
1793
 
1794
mathenv: BEGINENV MATRIX tableRowList ENDENV MATRIX {
1795
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1796
  wims_mathml_free_string($3);
1797
}
1798
|  BEGINENV EQUATION tableRowList ENDENV EQUATION {
1799
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"0.8ex\">", $3, "</mtable></mrow>");
1800
  wims_mathml_free_string($3);
1801
}
1802
|  BEGINENV GATHERED tableRowList ENDENV GATHERED {
1803
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"1.0ex\">", $3, "</mtable></mrow>");
1804
  wims_mathml_free_string($3);
1805
}
1806
| BEGINENV PMATRIX tableRowList ENDENV PMATRIX {
1807
  $$ = wims_mathml_copy3("<mrow><mo>(</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>)</mo></mrow>");
1808
  wims_mathml_free_string($3);
1809
}
1810
| BEGINENV BMATRIX tableRowList ENDENV BMATRIX {
1811
  $$ = wims_mathml_copy3("<mrow><mo>[</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>]</mo></mrow>");
1812
  wims_mathml_free_string($3);
1813
}
1814
| BEGINENV VMATRIX tableRowList ENDENV VMATRIX {
1815
  $$ = wims_mathml_copy3("<mrow><mo>&VerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
1816
  wims_mathml_free_string($3);
1817
}
1818
| BEGINENV BBMATRIX tableRowList ENDENV BBMATRIX {
1819
  $$ = wims_mathml_copy3("<mrow><mo>{</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>}</mo></mrow>");
1820
  wims_mathml_free_string($3);
1821
}
1822
| BEGINENV VVMATRIX tableRowList ENDENV VVMATRIX {
1823
  $$ = wims_mathml_copy3("<mrow><mo>&DoubleVerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
1824
  wims_mathml_free_string($3);
1825
}
1826
| BEGINENV SMALLMATRIX tableRowList ENDENV SMALLMATRIX {
1827
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"2\"><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow></mstyle>");
1828
  wims_mathml_free_string($3);
1829
}
1830
| BEGINENV CASES tableRowList ENDENV CASES {
1831
  $$ = wims_mathml_copy3("<mrow><mo>{</mo><mrow><mtable columnalign=\"left left\">", $3, "</mtable></mrow></mrow>");
1832
  wims_mathml_free_string($3);
1833
}
1834
| BEGINENV ALIGNED tableRowList ENDENV ALIGNED {
1835
  $$ = wims_mathml_copy3("<mrow><mtable columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\">", $3, "</mtable></mrow>");
1836
  wims_mathml_free_string($3);
1837
}
1838
| BEGINENV ARRAY ARRAYALIGN ST TEX_OPTIONS END tableRowList ENDENV ARRAY {
1839
  $$= wims_mathml_copy7("<mtable rowspacing=\"0.5ex\" align=\"", $3 ,"\"", $5 ," >",$7,"</mtable>");
1840
  wims_mathml_free_string($3);
1841
  wims_mathml_free_string($5);
1842
  wims_mathml_free_string($7);
1843
}
1844
| BEGINENV ARRAY ST TEX_OPTIONS END tableRowList ENDENV ARRAY {
1845
    $$= wims_mathml_copy5("<mtable rowspacing=\"0.5ex\" ",$4," >", $6 ,"</mtable>");
1846
    wims_mathml_free_string($4);
1847
    wims_mathml_free_string($6);
1848
}
1849
| BEGINENV SVG XMLSTRING ENDSVG {
1850
  $$ = wims_mathml_copy3("<semantics><annotation-xml encoding=\"SVG1.1\">", $3, "</annotation-xml></semantics>");
1851
  wims_mathml_free_string($3);
1852
}
1853
| BEGINENV SVG ENDSVG {
1854
  $$ = wims_mathml_copy_string(" ");
7333 schaersvoo 1855
}
7332 schaersvoo 1856
| BEGINENV HTML XMLSTRING ENDHTML {
1857
  $$ = wims_mathml_copy3("<semantics><annotation-xml encoding=\"application/xhtml+xml\">", $3, "</annotation-xml></semantics>");
1858
  wims_mathml_free_string($3);
1859
}
1860
| BEGINENV HTML ENDHTML {
1861
  $$ = wims_mathml_copy_string(" ");
1862
};
5520 bpr 1863
 
1864
substack: SUBSTACK MROWOPEN tableRowList MROWCLOSE {
1865
  $$ = wims_mathml_copy3("<mrow><mtable columnalign=\"center\" rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1866
  wims_mathml_free_string($3);
1867
};
1868
 
14226 schaersvoo 1869
shortarray: SHORTARRAY MROWOPEN tableRowList MROWCLOSE {
1870
char *s1;char *s2;
1871
/*
1872
 
1873
1 = \Bmatrix{}
1874
2 = \pmatrix{}
1875
3 = \vmatrix{}
1876
4 = \Vmatrix{}
1877
5 = \aligned{}
1878
*/
1879
switch(wims_mathml_shortcut){
1880
 case 0: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">{</mo>");s2=wims_mathml_copy_string("<mo></mo>");break;
1881
 case 1: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">{</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">}</mo>");break;
1882
 case 2: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">(</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">)</mo>");break;
1883
 case 3: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">&vert;</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">&vert;</mo>");break;
1884
 case 4: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">&Vert;</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">&Vert;</mo>");break;
1885
 case 5: s1 = wims_mathml_copy_string(" ");s2=wims_mathml_copy_string(" ");break;
1886
 default: s1 = wims_mathml_copy_string(" ");s2 = wims_mathml_copy_string(" "); break;
1887
}
1888
  $$ = wims_mathml_copy5( s1 ,"<mrow><mtable>", $3, "</mtable></mrow>", s2);
1889
  wims_mathml_free_string($3);
1890
  wims_mathml_free_string(s1);
1891
  wims_mathml_free_string(s2);
1892
};
1893
 
1894
 
5520 bpr 1895
array: ARRAY MROWOPEN tableRowList MROWCLOSE {
1896
  $$ = wims_mathml_copy3("<mrow><mtable>", $3, "</mtable></mrow>");
1897
  wims_mathml_free_string($3);
1898
}
1899
| ARRAY MROWOPEN ARRAYOPTS MROWOPEN arrayopts MROWCLOSE tableRowList MROWCLOSE {
1900
  char * s1 = wims_mathml_copy3("<mrow><mtable ", $5, ">");
1901
  $$ = wims_mathml_copy3(s1, $7, "</mtable></mrow>");
1902
  wims_mathml_free_string(s1);
1903
  wims_mathml_free_string($5);
1904
  wims_mathml_free_string($7);
1905
};
1906
 
1907
arrayopts: anarrayopt {
1908
  $$ = wims_mathml_copy_string($1);
1909
  wims_mathml_free_string($1);
1910
}
1911
| arrayopts anarrayopt {
1912
  $$ = wims_mathml_copy3($1, " ", $2);
1913
  wims_mathml_free_string($1);
1914
  wims_mathml_free_string($2);
1915
};
1916
 
1917
anarrayopt: collayout {
1918
  $$ = wims_mathml_copy_string($1);
1919
  wims_mathml_free_string($1);
1920
}
1921
| colalign {
1922
  $$ = wims_mathml_copy_string($1);
1923
  wims_mathml_free_string($1);
1924
}
1925
| rowalign {
1926
  $$ = wims_mathml_copy_string($1);
1927
  wims_mathml_free_string($1);
1928
}
1929
| align {
1930
  $$ = wims_mathml_copy_string($1);
1931
  wims_mathml_free_string($1);
1932
}
1933
| eqrows {
1934
  $$ = wims_mathml_copy_string($1);
1935
  wims_mathml_free_string($1);
1936
}
1937
| eqcols {
1938
  $$ = wims_mathml_copy_string($1);
1939
  wims_mathml_free_string($1);
1940
}
1941
| rowlines {
1942
  $$ = wims_mathml_copy_string($1);
1943
  wims_mathml_free_string($1);
1944
}
1945
| collines {
1946
  $$ = wims_mathml_copy_string($1);
1947
  wims_mathml_free_string($1);
1948
}
1949
| frame {
1950
  $$ = wims_mathml_copy_string($1);
1951
  wims_mathml_free_string($1);
1952
}
1953
| padding {
1954
  $$ = wims_mathml_copy_string($1);
1955
  wims_mathml_free_string($1);
1956
};
1957
 
1958
collayout: COLLAYOUT ATTRLIST {
1959
  $$ = wims_mathml_copy2("columnalign=", $2);
1960
  wims_mathml_free_string($2);
1961
};
1962
 
1963
colalign: COLALIGN ATTRLIST {
1964
  $$ = wims_mathml_copy2("columnalign=", $2);
1965
  wims_mathml_free_string($2);
1966
};
1967
 
1968
rowalign: ROWALIGN ATTRLIST {
1969
  $$ = wims_mathml_copy2("rowalign=", $2);
1970
  wims_mathml_free_string($2);
1971
};
1972
 
1973
align: ALIGN ATTRLIST {
1974
  $$ = wims_mathml_copy2("align=", $2);
1975
  wims_mathml_free_string($2);
1976
};
1977
 
1978
eqrows: EQROWS ATTRLIST {
1979
  $$ = wims_mathml_copy2("equalrows=", $2);
1980
  wims_mathml_free_string($2);
1981
};
1982
 
1983
eqcols: EQCOLS ATTRLIST {
1984
  $$ = wims_mathml_copy2("equalcolumns=", $2);
1985
  wims_mathml_free_string($2);
1986
};
1987
 
1988
rowlines: ROWLINES ATTRLIST {
1989
  $$ = wims_mathml_copy2("rowlines=", $2);
1990
  wims_mathml_free_string($2);
1991
};
1992
 
1993
collines: COLLINES ATTRLIST {
1994
  $$ = wims_mathml_copy2("columnlines=", $2);
1995
  wims_mathml_free_string($2);
1996
};
1997
 
1998
frame: FRAME ATTRLIST {
1999
  $$ = wims_mathml_copy2("frame=", $2);
2000
  wims_mathml_free_string($2);
2001
};
2002
 
2003
padding: PADDING ATTRLIST {
2004
  char * s1 = wims_mathml_copy3("rowspacing=", $2, " columnspacing=");
2005
  $$ = wims_mathml_copy2(s1, $2);
2006
  wims_mathml_free_string(s1);
2007
  wims_mathml_free_string($2);
2008
};
2009
 
2010
tableRowList: tableRow {
2011
  $$ = wims_mathml_copy_string($1);
2012
  wims_mathml_free_string($1);
2013
}
2014
| tableRowList ROWSEP tableRow {
2015
  $$ = wims_mathml_copy3($1, " ", $3);
2016
  wims_mathml_free_string($1);
2017
  wims_mathml_free_string($3);
2018
};
2019
 
2020
tableRow: simpleTableRow {
2021
  $$ = wims_mathml_copy3("<mtr>", $1, "</mtr>");
2022
  wims_mathml_free_string($1);
2023
}
2024
| optsTableRow {
2025
  $$ = wims_mathml_copy_string($1);
2026
  wims_mathml_free_string($1);
2027
};
2028
 
2029
simpleTableRow: tableCell {
2030
  $$ = wims_mathml_copy_string($1);
2031
  wims_mathml_free_string($1);
2032
}
2033
| simpleTableRow COLSEP tableCell {
2034
  $$ = wims_mathml_copy3($1, " ", $3);
2035
  wims_mathml_free_string($1);
2036
  wims_mathml_free_string($3);
2037
};
2038
 
2039
optsTableRow: ROWOPTS MROWOPEN rowopts MROWCLOSE simpleTableRow {
2040
  char * s1 = wims_mathml_copy3("<mtr ", $3, ">");
2041
  $$ = wims_mathml_copy3(s1, $5, "</mtr>");
2042
  wims_mathml_free_string(s1);
2043
  wims_mathml_free_string($3);
2044
  wims_mathml_free_string($5);
2045
};
2046
 
2047
rowopts: arowopt {
2048
  $$ = wims_mathml_copy_string($1);
2049
  wims_mathml_free_string($1);
2050
}
2051
| rowopts arowopt {
2052
  $$ = wims_mathml_copy3($1, " ", $2);
2053
  wims_mathml_free_string($1);
2054
  wims_mathml_free_string($2);
2055
};
2056
 
2057
arowopt: colalign {
2058
  $$ = wims_mathml_copy_string($1);
2059
  wims_mathml_free_string($1);
2060
}
2061
| rowalign {
2062
  $$ = wims_mathml_copy_string($1);
2063
  wims_mathml_free_string($1);
2064
};
2065
 
2066
tableCell:   {
2067
  $$ = wims_mathml_copy_string("<mtd></mtd>");
2068
}
2069
| compoundTermList {
2070
  $$ = wims_mathml_copy3("<mtd>", $1, "</mtd>");
2071
  wims_mathml_free_string($1);
2072
}
2073
| CELLOPTS MROWOPEN cellopts MROWCLOSE compoundTermList {
2074
  char * s1 = wims_mathml_copy3("<mtd ", $3, ">");
2075
  $$ = wims_mathml_copy3(s1, $5, "</mtd>");
2076
  wims_mathml_free_string(s1);
2077
  wims_mathml_free_string($3);
2078
  wims_mathml_free_string($5);
2079
};
2080
 
2081
cellopts: acellopt {
2082
  $$ = wims_mathml_copy_string($1);
2083
  wims_mathml_free_string($1);
2084
}
2085
| cellopts acellopt {
2086
  $$ = wims_mathml_copy3($1, " ", $2);
2087
  wims_mathml_free_string($1);
2088
  wims_mathml_free_string($2);
2089
};
2090
 
2091
acellopt: colalign {
2092
  $$ = wims_mathml_copy_string($1);
2093
  wims_mathml_free_string($1);
2094
}
2095
| rowalign {
2096
  $$ = wims_mathml_copy_string($1);
2097
  wims_mathml_free_string($1);
2098
}
2099
| rowspan {
2100
  $$ = wims_mathml_copy_string($1);
2101
  wims_mathml_free_string($1);
2102
}
2103
| colspan {
2104
  $$ = wims_mathml_copy_string($1);
2105
  wims_mathml_free_string($1);
2106
};
2107
 
2108
rowspan: ROWSPAN ATTRLIST {
2109
  $$ = wims_mathml_copy2("rowspan=", $2);
2110
  wims_mathml_free_string($2);
2111
};
2112
 
2113
colspan: COLSPAN ATTRLIST {
2114
  $$ = wims_mathml_copy2("columnspan=", $2);
2115
  wims_mathml_free_string($2);
2116
};
2117
 
2118
%%
2119
 
2120
char * wims_mathml_parse (const char * buffer, unsigned long length)
2121
{
2122
  char * mathml = 0;
2123
 
2124
  int result;
2125
 
2126
  wims_mathml_setup (buffer, length);
2127
  wims_mathml_restart ();
2128
 
2129
  result = wims_mathml_yyparse (&mathml);
2130
 
2131
  if (result && mathml) /* shouldn't happen? */
2132
    {
2133
      wims_mathml_free_string (mathml);
2134
      mathml = 0;
2135
    }
2136
  return mathml;
2137
}
2138
 
2139
int wims_mathml_filter (const char * buffer, unsigned long length)
2140
{
2141
  wims_mathml_setup (buffer, length);
2142
  wims_mathml_restart ();
2143
 
2144
  return wims_mathml_yyparse (0);
2145
}
2146
 
2147
#define ITEX_DELIMITER_DOLLAR 0
2148
#define ITEX_DELIMITER_DOUBLE 1
2149
#define ITEX_DELIMITER_SQUARE 2
2150
 
2151
static char * wims_mathml_last_error = 0;
2152
 
2153
static void wims_mathml_keep_error (const char * msg)
2154
{
2155
  if (wims_mathml_last_error)
2156
    {
2157
      wims_mathml_free_string (wims_mathml_last_error);
2158
      wims_mathml_last_error = 0;
2159
    }
2160
  wims_mathml_last_error = wims_mathml_copy_escaped (msg);
2161
}
2162
 
2163
int wims_mathml_html_filter (const char * buffer, unsigned long length)
2164
{
7396 schaersvoo 2165
 return wims_mathml_do_html_filter (buffer, length, 0);
5520 bpr 2166
}
2167
 
2168
int wims_mathml_strict_html_filter (const char * buffer, unsigned long length)
2169
{
7396 schaersvoo 2170
  return wims_mathml_do_html_filter (buffer, length, 1);
5520 bpr 2171
}
2172
 
2173
int wims_mathml_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
2174
{
2175
  int result = 0;
2176
 
2177
  int type = 0;
2178
  int skip = 0;
2179
  int match = 0;
2180
 
2181
  const char * ptr1 = buffer;
2182
  const char * ptr2 = 0;
2183
 
2184
  const char * end = buffer + length;
2185
 
2186
  char * mathml = 0;
2187
 
2188
  void (*save_error_fn) (const char * msg) = wims_mathml_error;
2189
 
2190
  wims_mathml_error = wims_mathml_keep_error;
2191
 
7076 obado 2192
  _until_math:
5520 bpr 2193
  ptr2 = ptr1;
2194
 
2195
  while (ptr2 < end)
7076 obado 2196
  {
2197
    if (*ptr2 == '$') break;
2198
    if ((*ptr2 == '\\') && (ptr2 + 1 < end))
5520 bpr 2199
    {
7076 obado 2200
      if (*(ptr2+1) == '[') break;
5520 bpr 2201
    }
7076 obado 2202
    ++ptr2;
2203
  }
5520 bpr 2204
  if (wims_mathml_write && ptr2 > ptr1)
2205
    (*wims_mathml_write) (ptr1, ptr2 - ptr1);
2206
 
2207
  if (ptr2 == end) goto _finish;
2208
 
7076 obado 2209
  _until_html:
5520 bpr 2210
  ptr1 = ptr2;
2211
 
2212
  if (ptr2 + 1 < end)
7076 obado 2213
  {
2214
    if ((*ptr2 == '\\') && (*(ptr2+1) == '['))
5520 bpr 2215
    {
7076 obado 2216
      type = ITEX_DELIMITER_SQUARE;
2217
      ptr2 += 2;
5520 bpr 2218
    }
7076 obado 2219
    else if ((*ptr2 == '$') && (*(ptr2+1) == '$'))
2220
    {
2221
      type = ITEX_DELIMITER_DOUBLE;
2222
      ptr2 += 2;
2223
    }
2224
    else
2225
    {
2226
      type = ITEX_DELIMITER_DOLLAR;
2227
      ptr2 += 2;
2228
    }
2229
  }
5520 bpr 2230
  else goto _finish;
2231
 
2232
  skip = 0;
2233
  match = 0;
2234
 
2235
  while (ptr2 < end)
7076 obado 2236
  {
2237
    switch (*ptr2)
5520 bpr 2238
    {
7076 obado 2239
    case '<':
2240
    case '>':
2241
      if (forbid_markup == 1) skip = 1;
2242
      break;
5520 bpr 2243
 
7076 obado 2244
    case '\\':
2245
      if (ptr2 + 1 < end)
2246
      {
2247
        if (*(ptr2 + 1) == '[')
2248
        {
2249
          skip = 1;
2250
        }
2251
        else if (*(ptr2 + 1) == ']')
2252
        {
2253
          if (type == ITEX_DELIMITER_SQUARE)
2254
          {
2255
            ptr2 += 2;
2256
            match = 1;
2257
          }
2258
          else
2259
          {
2260
            skip = 1;
2261
          }
2262
        }
2263
      }
2264
      break;
5520 bpr 2265
 
7076 obado 2266
    case '$':
2267
      if (type == ITEX_DELIMITER_SQUARE)
2268
      {
2269
        skip = 1;
2270
      }
2271
      else if (ptr2 + 1 < end)
2272
      {
2273
        if (*(ptr2 + 1) == '$')
2274
        {
2275
          if (type == ITEX_DELIMITER_DOLLAR)
2276
          {
2277
            ptr2++;
2278
            match = 1;
2279
          }
2280
          else
2281
          {
2282
            ptr2 += 2;
2283
            match = 1;
2284
          }
2285
        }
2286
        else
2287
        {
2288
          if (type == ITEX_DELIMITER_DOLLAR)
2289
          {
2290
            ptr2++;
2291
            match = 1;
2292
          }
2293
          else
2294
          {
2295
            skip = 1;
2296
          }
2297
        }
2298
      }
2299
      else
2300
      {
2301
        if (type == ITEX_DELIMITER_DOLLAR)
2302
        {
2303
          ptr2++;
2304
          match = 1;
2305
        }
2306
        else
2307
        {
2308
          skip = 1;
2309
        }
2310
      }
2311
      break;
5520 bpr 2312
 
7076 obado 2313
    default:
2314
      break;
2315
    }
2316
    if (skip || match) break;
5520 bpr 2317
 
7076 obado 2318
    ++ptr2;
2319
  }
5520 bpr 2320
  if (skip)
7076 obado 2321
  {
2322
    if (type == ITEX_DELIMITER_DOLLAR)
5520 bpr 2323
    {
7076 obado 2324
      if (wims_mathml_write)
2325
        (*wims_mathml_write) (ptr1, 1);
2326
      ptr1++;
5520 bpr 2327
    }
7076 obado 2328
    else
2329
    {
2330
      if (wims_mathml_write)
2331
        (*wims_mathml_write) (ptr1, 2);
2332
      ptr1 += 2;
2333
    }
2334
    goto _until_math;
2335
  }
5520 bpr 2336
  if (match)
7076 obado 2337
  {
2338
    mathml = wims_mathml_parse (ptr1, ptr2 - ptr1);
2339
    if (mathml)
5520 bpr 2340
    {
7076 obado 2341
      if (wims_mathml_write_mathml)
2342
        (*wims_mathml_write_mathml) (mathml);
2343
      wims_mathml_free_string (mathml);
2344
      mathml = 0;
2345
    }
2346
    else
2347
    {
2348
      ++result;
2349
      if (wims_mathml_write)
2350
      {
2351
        if (type == ITEX_DELIMITER_DOLLAR)
9568 schaersvoo 2352
          (*wims_mathml_write) ("<span style=\"font-size:1em;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><merror><mtext>", 0);
7076 obado 2353
        else
9568 schaersvoo 2354
          (*wims_mathml_write) ("<span style=\"font-size:1em;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><merror><mtext>", 0);
7076 obado 2355
          (*wims_mathml_write) (wims_mathml_last_error, 0);
9568 schaersvoo 2356
          (*wims_mathml_write) ("</mtext></merror></math></span>", 0);
7076 obado 2357
        }
2358
    }
2359
    ptr1 = ptr2;
5520 bpr 2360
 
7076 obado 2361
    goto _until_math;
2362
  }
5520 bpr 2363
  if (wims_mathml_write)
2364
    (*wims_mathml_write) (ptr1, ptr2 - ptr1);
2365
 
7076 obado 2366
  _finish:
5520 bpr 2367
  if (wims_mathml_last_error)
7076 obado 2368
  {
2369
    wims_mathml_free_string (wims_mathml_last_error);
2370
    wims_mathml_last_error = 0;
2371
  }
5520 bpr 2372
  wims_mathml_error = save_error_fn;
2373
 
2374
  return result;
2375
}
7332 schaersvoo 2376
 
2377
 
2378
void replace_str(const char *str, const char *old, const char *new){
2379
/* http://creativeandcritical.net/str-replace-c/ */
2380
    char *ret, *r;
2381
    const char *p, *q;
2382
    size_t oldlen = strlen(old);
2383
    size_t count, retlen, newlen = strlen(new);
2384
 
2385
    if (oldlen != newlen){
15175 obado 2386
  for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
2387
      count++;
2388
      retlen = p - str + strlen(p) + count * (newlen - oldlen);
2389
  }
8910 bpr 2390
    }
7332 schaersvoo 2391
    else
2392
    {
15175 obado 2393
  retlen = strlen(str);
7332 schaersvoo 2394
    }
8910 bpr 2395
 
7332 schaersvoo 2396
    if ((ret = malloc(retlen + 1)) == NULL){
15175 obado 2397
  ret = NULL;
7332 schaersvoo 2398
    }
2399
    else
2400
    {
15175 obado 2401
  for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
2402
      size_t l = q - p;
2403
      memcpy(r, p, l);
2404
      r += l;
2405
      memcpy(r, new, newlen);
2406
      r += newlen;
2407
  }
2408
  strcpy(r, p);
7332 schaersvoo 2409
    }
2410
    yylval = ret;
2411
}