Subversion Repositories wimsdev

Rev

Rev 15177 | Rev 16599 | Go to most recent revision | 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 {
1107
  char *s1 = wims_mathml_copy13("<mtable columnspacing=\"0.3ex\" columnalign=\"left\" columnlines=\"none\" rowlines=\"none\" rowalign=\"center\"><mtr><mtd><mstyle mathsize=\"70%\"><munderover><mphantom></mphantom><mrow><mo mathsize=\"120%\">",$3,
1108
  "</mo></mrow><mrow><mo mathsize=\"120%\">",$4,
1109
  "</mo></mrow></munderover></style></mtd><mtd><munderover>",$2,"<mrow><mo>",$10,
1110
  "</mo><mo>",$9,"</mo></mrow><mrow><mo>",$5,"</mo><mo>");
1111
  $$ = wims_mathml_copy13 (s1,$6,"</mo></mrow></munderover></mtd><mtd><mstyle mathsize=\"70%\"><munderover><mphantom></mphantom><mrow><mo mathsize=\"120%\">",$8,
1112
  "</mo></mrow><mrow><mo mathsize=\"120%\">",$7,
1113
  "</mo></mrow></munderover></mstyle></mtd></mtr></mtable>",0,0,0,0,0,0);
1114
  wims_mathml_free_string(s1);
1115
  wims_mathml_free_string($2);
1116
  wims_mathml_free_string($3);
1117
  wims_mathml_free_string($4);
1118
  wims_mathml_free_string($5);
1119
  wims_mathml_free_string($6);
1120
  wims_mathml_free_string($7);
1121
  wims_mathml_free_string($8);
1122
  wims_mathml_free_string($9);
1123
  wims_mathml_free_string($10);
1124
};
1125
 
5520 bpr 1126
special: SPECIAL ATTRLIST compoundTermList {
1127
  char * s1 = wims_mathml_copy3("<mstyle mathcolor=", $2, ">");
1128
  $$ = wims_mathml_copy3(s1, $3, "</mstyle>");
1129
  wims_mathml_free_string(s1);
1130
  wims_mathml_free_string($2);
1131
  wims_mathml_free_string($3);
1132
};
1133
 
1134
mathrlap: RLAP closedTerm {
1135
  $$ = wims_mathml_copy3("<mpadded width=\"0\">", $2, "</mpadded>");
1136
  wims_mathml_free_string($2);
1137
};
1138
 
1139
mathllap: LLAP closedTerm {
1140
  $$ = wims_mathml_copy3("<mpadded width=\"0\" lspace=\"-100%width\">", $2, "</mpadded>");
1141
  wims_mathml_free_string($2);
1142
};
1143
 
1144
mathclap: CLAP closedTerm {
1145
  $$ = wims_mathml_copy3("<mpadded width=\"0\" lspace=\"-50%width\">", $2, "</mpadded>");
1146
  wims_mathml_free_string($2);
1147
};
1148
 
1149
textstring: TEXTBOX TEXTSTRING {
1150
  $$ = wims_mathml_copy3("<mtext>", $2, "</mtext>");
1151
  wims_mathml_free_string($2);
1152
};
1153
 
1154
displaystyle: DISPLAY compoundTermList {
1155
  $$ = wims_mathml_copy3("<mstyle displaystyle=\"true\">", $2, "</mstyle>");
1156
  wims_mathml_free_string($2);
1157
};
1158
 
1159
textstyle: TEXTSTY compoundTermList {
1160
  $$ = wims_mathml_copy3("<mstyle displaystyle=\"false\">", $2, "</mstyle>");
1161
  wims_mathml_free_string($2);
1162
};
1163
 
1164
textsize: TEXTSIZE compoundTermList {
1165
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"0\">", $2, "</mstyle>");
1166
  wims_mathml_free_string($2);
1167
};
1168
 
1169
scriptsize: SCSIZE compoundTermList {
1170
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"1\">", $2, "</mstyle>");
1171
  wims_mathml_free_string($2);
1172
};
1173
 
1174
scriptscriptsize: SCSCSIZE compoundTermList {
1175
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"2\">", $2, "</mstyle>");
1176
  wims_mathml_free_string($2);
1177
};
1178
 
1179
italics: ITALICS closedTerm {
1180
  $$ = wims_mathml_copy3("<mstyle mathvariant=\"italic\">", $2, "</mstyle>");
1181
  wims_mathml_free_string($2);
1182
};
1183
 
1184
 
1185
slashed: SLASHED closedTerm {
1186
  $$ = wims_mathml_copy3("<menclose notation=\"updiagonalstrike\">", $2, "</menclose>");
1187
  wims_mathml_free_string($2);
1188
};
1189
 
1190
boxed: BOXED closedTerm {
1191
  $$ = wims_mathml_copy3("<menclose notation=\"box\">", $2, "</menclose>");
1192
  wims_mathml_free_string($2);
1193
};
1194
 
1195
bold: BOLD closedTerm {
1196
  $$ = wims_mathml_copy3("<mstyle mathvariant=\"bold\">", $2, "</mstyle>");
1197
  wims_mathml_free_string($2);
1198
};
1199
 
1200
roman: RM ST rmchars END {
1201
  $$ = wims_mathml_copy3("<mi mathvariant=\"normal\">", $3, "</mi>");
1202
  wims_mathml_free_string($3);
1203
};
1204
 
1205
roman: WIMSROMAN closedTerm{
1206
  $$ = wims_mathml_copy3("<mi mathvariant=\"normal\">", $2, "</mi>");
1207
  wims_mathml_free_string($2);
1208
};
1209
 
1210
rmchars: RMCHAR {
1211
  $$ = wims_mathml_copy_string($1);
1212
  wims_mathml_free_string($1);
1213
}
1214
| rmchars RMCHAR {
1215
  $$ = wims_mathml_copy2($1, $2);
1216
  wims_mathml_free_string($1);
1217
  wims_mathml_free_string($2);
1218
};
1219
 
1220
bbold: BB ST bbchars END {
1221
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1222
  wims_mathml_free_string($3);
1223
};
1224
 
1225
bbchars: bbchar {
1226
  $$ = wims_mathml_copy_string($1);
1227
  wims_mathml_free_string($1);
1228
}
1229
| bbchars bbchar {
1230
  $$ = wims_mathml_copy2($1, $2);
1231
  wims_mathml_free_string($1);
1232
  wims_mathml_free_string($2);
1233
};
1234
 
1235
bbchar: BBLOWERCHAR {
1236
  $$ = wims_mathml_copy3("&", $1, "opf;");
1237
  wims_mathml_free_string($1);
1238
}
1239
| BBUPPERCHAR {
1240
  $$ = wims_mathml_copy3("&", $1, "opf;");
1241
  wims_mathml_free_string($1);
1242
}
1243
| BBDIGIT {
1244
  /* Blackboard digits 0-9 correspond to Unicode characters 0x1D7D8-0x1D7E1 */
1245
  char * end = $1 + 1;
1246
  int code = 0x1D7D8 + strtoul($1, &end, 10);
1247
  $$ = wims_mathml_character_reference(code);
1248
  wims_mathml_free_string($1);
1249
};
1250
 
1251
frak: FRAK ST frakletters END {
1252
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1253
  wims_mathml_free_string($3);
1254
};
1255
 
1256
frakletters: frakletter {
1257
  $$ = wims_mathml_copy_string($1);
1258
  wims_mathml_free_string($1);
1259
}
1260
| frakletters frakletter {
1261
  $$ = wims_mathml_copy2($1, $2);
1262
  wims_mathml_free_string($1);
1263
  wims_mathml_free_string($2);
1264
};
1265
 
1266
frakletter: FRAKCHAR {
1267
  $$ = wims_mathml_copy3("&", $1, "fr;");
1268
  wims_mathml_free_string($1);
1269
};
1270
 
1271
cal: CAL ST calletters END {
1272
  $$ = wims_mathml_copy3("<mi>", $3, "</mi>");
1273
  wims_mathml_free_string($3);
1274
};
1275
 
1276
calletters: calletter {
1277
  $$ = wims_mathml_copy_string($1);
1278
  wims_mathml_free_string($1);
1279
}
1280
| calletters calletter {
1281
  $$ = wims_mathml_copy2($1, $2);
1282
  wims_mathml_free_string($1);
1283
  wims_mathml_free_string($2);
1284
};
1285
 
1286
calletter: CALCHAR {
9540 bpr 1287
  $$ = wims_mathml_copy3("&",$1,"scr;");
5520 bpr 1288
  wims_mathml_free_string($1);
1289
};
1290
 
1291
thinspace: THINSPACE {
1292
  $$ = wims_mathml_copy_string("<mspace width=\"thinmathspace\"></mspace>");
1293
};
1294
 
1295
medspace: MEDSPACE {
1296
  $$ = wims_mathml_copy_string("<mspace width=\"mediummathspace\"></mspace>");
1297
};
1298
 
1299
thickspace: THICKSPACE {
1300
  $$ = wims_mathml_copy_string("<mspace width=\"thickmathspace\"></mspace>");
1301
};
1302
 
1303
quad: QUAD {
1304
  $$ = wims_mathml_copy_string("<mspace width=\"1em\"></mspace>");
1305
};
1306
 
1307
qquad: QQUAD {
1308
  $$ = wims_mathml_copy_string("<mspace width=\"2em\"></mspace>");
1309
};
1310
 
1311
negspace: NEGSPACE {
1312
  $$ = wims_mathml_copy_string("<mspace width=\"-0.1667 em\"></mspace>");
1313
};
1314
 
1315
phantom: PHANTOM closedTerm {
1316
  $$ = wims_mathml_copy3("<mphantom>", $2, "</mphantom>");
1317
  wims_mathml_free_string($2);
1318
};
1319
 
1320
href: HREF TEXTSTRING closedTerm {
1321
  char * s1 = wims_mathml_copy3("<mrow href=\"", $2, "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
1322
  char * s2 = wims_mathml_copy3(s1, $2, "\">");
1323
  $$ = wims_mathml_copy3(s2, $3, "</mrow>");
1324
  wims_mathml_free_string(s1);
1325
  wims_mathml_free_string(s2);
1326
  wims_mathml_free_string($2);
1327
  wims_mathml_free_string($3);
1328
};
1329
 
1330
tensor: TENSOR closedTerm MROWOPEN subsupList MROWCLOSE {
1331
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $2, $4);
1332
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1333
  wims_mathml_free_string(s1);
1334
  wims_mathml_free_string($2);
1335
  wims_mathml_free_string($4);
1336
}
1337
| TENSOR closedTerm subsupList {
1338
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $2, $3);
1339
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1340
  wims_mathml_free_string(s1);
1341
  wims_mathml_free_string($2);
1342
  wims_mathml_free_string($3);
1343
};
1344
 
1345
multi: MULTI MROWOPEN subsupList MROWCLOSE closedTerm MROWOPEN subsupList MROWCLOSE {
1346
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $5, $7);
1347
  char * s2 = wims_mathml_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1348
  $$ = wims_mathml_copy2(s1, s2);
1349
  wims_mathml_free_string(s1);
1350
  wims_mathml_free_string(s2);
1351
  wims_mathml_free_string($3);
1352
  wims_mathml_free_string($5);
1353
  wims_mathml_free_string($7);
1354
}
1355
| MULTI MROWOPEN subsupList MROWCLOSE closedTerm EMPTYMROW {
1356
  char * s1 = wims_mathml_copy2("<mmultiscripts>", $5);
1357
  char * s2 = wims_mathml_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1358
  $$ = wims_mathml_copy2(s1, s2);
1359
  wims_mathml_free_string(s1);
1360
  wims_mathml_free_string(s2);
1361
  wims_mathml_free_string($3);
1362
  wims_mathml_free_string($5);
1363
}
1364
| MULTI EMPTYMROW closedTerm MROWOPEN subsupList MROWCLOSE {
1365
  char * s1 = wims_mathml_copy3("<mmultiscripts>", $3, $5);
1366
  $$ = wims_mathml_copy2(s1, "</mmultiscripts>");
1367
  wims_mathml_free_string(s1);
1368
  wims_mathml_free_string($3);
8910 bpr 1369
  wims_mathml_free_string($5);
5520 bpr 1370
};
1371
 
1372
subsupList: subsupTerm {
1373
  $$ = wims_mathml_copy_string($1);
1374
  wims_mathml_free_string($1);
1375
}
1376
| subsupList subsupTerm {
1377
  $$ = wims_mathml_copy3($1, " ", $2);
1378
  wims_mathml_free_string($1);
1379
  wims_mathml_free_string($2);
1380
};
1381
 
1382
subsupTerm: SUB closedTerm SUP closedTerm {
1383
  $$ = wims_mathml_copy3($2, " ", $4);
1384
  wims_mathml_free_string($2);
1385
  wims_mathml_free_string($4);
1386
}
1387
| SUB closedTerm {
1388
  $$ = wims_mathml_copy2($2, " <none></none>");
1389
  wims_mathml_free_string($2);
1390
}
1391
| SUP closedTerm {
1392
  $$ = wims_mathml_copy2("<none></none> ", $2);
1393
  wims_mathml_free_string($2);
1394
}
1395
| SUB SUP closedTerm {
1396
  $$ = wims_mathml_copy2("<none></none> ", $3);
1397
  wims_mathml_free_string($3);
1398
};
1399
 
1400
mfrac: DFRAC closedTerm closedTerm {
1401
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\" fontsize=\"120%\"><mfrac>", $2, $3);
1402
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1403
  wims_mathml_free_string(s1);
1404
  wims_mathml_free_string($2);
1405
  wims_mathml_free_string($3);
1406
}
1407
| FRAC closedTerm closedTerm {
1408
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\"><mfrac>", $2, $3);
1409
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1410
  wims_mathml_free_string(s1);
1411
  wims_mathml_free_string($2);
1412
  wims_mathml_free_string($3);
1413
}
1414
| TFRAC closedTerm closedTerm {
1415
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"false\"><mfrac>", $2, $3);
1416
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle>");
1417
  wims_mathml_free_string(s1);
1418
  wims_mathml_free_string($2);
1419
  wims_mathml_free_string($3);
1420
}
1421
| SFRAC closedTerm closedTerm{
1422
  $$ = wims_mathml_copy5("<mstyle scriptlevel=\"1\"><msup><mrow/>",$2,"</msup><msub><mo lspace=\"verythinmathspace\" stretchy=\"true\">&#x2571;</mo>",$3,"</msub></mstyle>");
1423
  wims_mathml_free_string($2);
1424
  wims_mathml_free_string($3);
1425
};
1426
 
1427
 
1428
pmod: PMOD closedTerm {
1429
  $$ = wims_mathml_copy3( "<mo lspace=\"mediummathspace\">(</mo><mo rspace=\"thinmathspace\">mod</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo>");
1430
  wims_mathml_free_string($2);
5996 schaersvoo 1431
};
5520 bpr 1432
 
14226 schaersvoo 1433
brack:
1434
MROWOPEN compoundTermList BRACK compoundTermList MROWCLOSE {
1435
 char *s1;
1436
 switch( wims_mathml_shortcut ){
1437
  case 0: s1 = wims_mathml_copy3("<mrow><mo>[</mo><mfrac linethickness=\"0\">", $2, $4);
15175 obado 1438
    $$ = wims_mathml_copy2(s1,"</mfrac><mo>]</mo></mrow>");break;
14226 schaersvoo 1439
  case 1: s1 = wims_mathml_copy3("<mrow><mo>{</mo><mfrac linethickness=\"0\">", $2, $4);
15175 obado 1440
    $$ = wims_mathml_copy2(s1,"</mfrac><mo>}</mo></mrow>");
14226 schaersvoo 1441
          break;
1442
  default: break;
1443
  }
1444
  wims_mathml_free_string(s1);
1445
  wims_mathml_free_string($2);
1446
  wims_mathml_free_string($4);
1447
};
1448
 
1449
 
5520 bpr 1450
texover: MROWOPEN compoundTermList BINOM2 compoundTermList MROWCLOSE {
5613 schaersvoo 1451
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $4);
5520 bpr 1452
  $$ = wims_mathml_copy2(s1,"</mfrac><mo>)</mo></mrow>");
1453
  wims_mathml_free_string(s1);
1454
  wims_mathml_free_string($2);
5613 schaersvoo 1455
  wims_mathml_free_string($4);
5520 bpr 1456
}
5996 schaersvoo 1457
| MROWOPEN compoundTermList TEXOVER compoundTermList MROWCLOSE {
6185 schaersvoo 1458
  char * s1 = wims_mathml_copy3("<mstyle displaystyle=\"true\"><mfrac><mrow>", $2, "</mrow><mrow>");
1459
  $$ = wims_mathml_copy3(s1, $4, "</mrow></mfrac></mstyle>");
5520 bpr 1460
  wims_mathml_free_string(s1);
1461
  wims_mathml_free_string($2);
1462
  wims_mathml_free_string($4);
1463
}
1464
| left compoundTermList TEXOVER compoundTermList right {
6185 schaersvoo 1465
  char * s1 = wims_mathml_copy3("<mrow>", $1, "<mstyle displaystyle=\"true\"><mfrac><mrow>");
5520 bpr 1466
  char * s2 = wims_mathml_copy3($2, "</mrow><mrow>", $4);
6185 schaersvoo 1467
  char * s3 = wims_mathml_copy3("</mrow></mfrac></mstyle>", $5, "</mrow>");
5520 bpr 1468
  $$ = wims_mathml_copy3(s1, s2, s3);
1469
  wims_mathml_free_string(s1);
1470
  wims_mathml_free_string(s2);
1471
  wims_mathml_free_string(s3);
1472
  wims_mathml_free_string($1);
1473
  wims_mathml_free_string($2);
1474
  wims_mathml_free_string($4);
1475
  wims_mathml_free_string($5);
1476
};
1477
 
1478
texatop: MROWOPEN compoundTermList TEXATOP compoundTermList MROWCLOSE {
1479
  char * s1 = wims_mathml_copy3("<mfrac linethickness=\"0\"><mrow>", $2, "</mrow><mrow>");
1480
  $$ = wims_mathml_copy3(s1, $4, "</mrow></mfrac>");
1481
  wims_mathml_free_string(s1);
1482
  wims_mathml_free_string($2);
1483
  wims_mathml_free_string($4);
1484
}
1485
| left compoundTermList TEXATOP compoundTermList right {
1486
  char * s1 = wims_mathml_copy3("<mrow>", $1, "<mfrac linethickness=\"0\"><mrow>");
1487
  char * s2 = wims_mathml_copy3($2, "</mrow><mrow>", $4);
1488
  char * s3 = wims_mathml_copy3("</mrow></mfrac>", $5, "</mrow>");
1489
  $$ = wims_mathml_copy3(s1, s2, s3);
1490
  wims_mathml_free_string(s1);
1491
  wims_mathml_free_string(s2);
1492
  wims_mathml_free_string(s3);
1493
  wims_mathml_free_string($1);
1494
  wims_mathml_free_string($2);
1495
  wims_mathml_free_string($4);
1496
  wims_mathml_free_string($5);
1497
};
1498
 
1499
binom: BINOM closedTerm closedTerm {
1500
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $3);
1501
  $$ = wims_mathml_copy2(s1, "</mfrac><mo>)</mo></mrow>");
1502
  wims_mathml_free_string(s1);
1503
  wims_mathml_free_string($2);
1504
  wims_mathml_free_string($3);
1505
}
1506
| TBINOM closedTerm closedTerm {
1507
  char * s1 = wims_mathml_copy3("<mrow><mo>(</mo><mstyle displaystyle=\"false\"><mfrac linethickness=\"0\">", $2, $3);
1508
  $$ = wims_mathml_copy2(s1, "</mfrac></mstyle><mo>)</mo></mrow>");
1509
  wims_mathml_free_string(s1);
1510
  wims_mathml_free_string($2);
1511
  wims_mathml_free_string($3);
1512
};
1513
 
1514
munderbrace: UNDERBRACE closedTerm {
1515
  $$ = wims_mathml_copy3("<munder>", $2, "<mo>&UnderBrace;</mo></munder>");
1516
  wims_mathml_free_string($2);
1517
};
1518
 
1519
munderline: UNDERLINE closedTerm {
1520
  $$ = wims_mathml_copy3("<munder>", $2, "<mo>&#x00332;</mo></munder>");
1521
  wims_mathml_free_string($2);
1522
};
1523
 
1524
moverbrace: OVERBRACE closedTerm {
1525
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&OverBrace;</mo></mover>");
1526
  wims_mathml_free_string($2);
1527
};
1528
 
1529
bar: BAR closedTerm {
1530
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x000AF;</mo></mover>");
1531
  wims_mathml_free_string($2);
1532
}
1533
| WIDEBAR closedTerm {
12086 schaersvoo 1534
  $$ = wims_mathml_copy3("<mover>", $2, "<mo> &#x000AF; </mo></mover>");
5520 bpr 1535
  wims_mathml_free_string($2);
1536
};
1537
 
1538
vec: VEC closedTerm {
1539
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&RightVector;</mo></mover>");
1540
  wims_mathml_free_string($2);
1541
}
1542
| WIDEVEC closedTerm {
1543
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&RightVector;</mo></mover>");
1544
  wims_mathml_free_string($2);
1545
};
1546
 
7225 schaersvoo 1547
overarrow: OVERARROW closedTerm {
1548
  $$ = wims_mathml_copy5("<mover>", $2, "<mo stretchy=\"true\">", $1 ,"</mo></mover>");
1549
  wims_mathml_free_string($1);
7224 schaersvoo 1550
  wims_mathml_free_string($2);
7219 schaersvoo 1551
};
1552
 
7225 schaersvoo 1553
underarrow: UNDERARROW closedTerm {
1554
  $$ = wims_mathml_copy5("<munder>", $2, "<mo stretchy=\"true\">", $1 ,"</mo></munder>");
1555
  wims_mathml_free_string($1);
7224 schaersvoo 1556
  wims_mathml_free_string($2);
7219 schaersvoo 1557
};
1558
 
5520 bpr 1559
dot: DOT closedTerm {
1560
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&dot;</mo></mover>");
1561
  wims_mathml_free_string($2);
1562
};
1563
 
1564
ddot: DDOT closedTerm {
1565
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&Dot;</mo></mover>");
1566
  wims_mathml_free_string($2);
1567
};
1568
 
1569
dddot: DDDOT closedTerm {
1570
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&tdot;</mo></mover>");
1571
  wims_mathml_free_string($2);
1572
};
1573
 
1574
ddddot: DDDDOT closedTerm {
1575
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&DotDot;</mo></mover>");
1576
  wims_mathml_free_string($2);
1577
};
1578
 
12073 bpr 1579
accents: ACCENTS closedTerm {
11727 schaersvoo 1580
/*
12073 bpr 1581
 see https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes
1582
 jm.evers 29/6/2017
11727 schaersvoo 1583
*/
1584
 int pos=1;char *s1 = " ";
11715 schaersvoo 1585
 if( strstr($1,"\"") != NULL ){s1 = wims_mathml_copy_string( "&uml;");}
11708 schaersvoo 1586
 else
11715 schaersvoo 1587
 if( strstr($1,"'") != NULL ){s1 = wims_mathml_copy_string( "&acute;");}
11708 schaersvoo 1588
 else
11715 schaersvoo 1589
 if( strstr($1,"`") != NULL ){s1 = wims_mathml_copy_string( "&grave;");}
11708 schaersvoo 1590
 else
11721 schaersvoo 1591
 if( strstr($1,"~") != NULL ){s1 = wims_mathml_copy_string( "&tilde;");}
1592
 else
11715 schaersvoo 1593
 if( strstr($1,".") != NULL ){s1 = wims_mathml_copy_string( "&dot;");}
11708 schaersvoo 1594
 else
11715 schaersvoo 1595
 if( strstr($1,"r") != NULL ){s1 = wims_mathml_copy_string( "&ring;");}
11708 schaersvoo 1596
 else
11715 schaersvoo 1597
 if( strstr($1,"c") != NULL ){s1 = wims_mathml_copy_string( "&cedil;");pos = 2;}
11708 schaersvoo 1598
 else
11715 schaersvoo 1599
 if( strstr($1,"=") != NULL ){s1 = wims_mathml_copy_string( "&macr;");}
11708 schaersvoo 1600
 else
11715 schaersvoo 1601
 if( strstr($1,"k") != NULL ){s1 = wims_mathml_copy_string( "&ogon;");pos = 2;}
11708 schaersvoo 1602
 else
11715 schaersvoo 1603
 if( strstr($1,"^") != NULL ){s1 = wims_mathml_copy_string( "&#x0005E;");}
11708 schaersvoo 1604
 else
11715 schaersvoo 1605
 if( strstr($1,"b") != NULL ){s1 = wims_mathml_copy_string( "&macr;");pos = 2;}
11708 schaersvoo 1606
 else
11715 schaersvoo 1607
 if( strstr($1,"v") != NULL ){s1 = wims_mathml_copy_string( "&#x2c7;");}
11708 schaersvoo 1608
 else
11715 schaersvoo 1609
 if( strstr($1,"d") != NULL ){s1 = wims_mathml_copy_string( "&dot;");pos = 2;}
11708 schaersvoo 1610
 else
11715 schaersvoo 1611
 if( strstr($1,"l") != NULL ){s1 = wims_mathml_copy_string( "&#x142;");pos = 3;}
11708 schaersvoo 1612
 else
11715 schaersvoo 1613
 if( strstr($1,"o") != NULL ){s1 = wims_mathml_copy_string( "&oslash;");pos = 3;}
11708 schaersvoo 1614
 else
11715 schaersvoo 1615
 if( strstr($1,"O") != NULL ){s1 = wims_mathml_copy_string( "&Oslash;");pos = 3;}
11708 schaersvoo 1616
 else
11715 schaersvoo 1617
 if( strstr($1,"H") != NULL ){s1 = wims_mathml_copy_string( "&#733;");}
11708 schaersvoo 1618
 else
11715 schaersvoo 1619
 if( strstr($1,"t") != NULL ){s1 = wims_mathml_copy_string( "&#8256;");}
11727 schaersvoo 1620
 else
1621
 if( strstr($1,"u") != NULL ){s1 = wims_mathml_copy_string( "&breve;");}
11708 schaersvoo 1622
 
11715 schaersvoo 1623
 if( pos == 1 ){ $$ = wims_mathml_copy5("<mover>",$2,"<mo stretchy=\"false\">",s1,"</mo></mover>");}
11708 schaersvoo 1624
 else
11715 schaersvoo 1625
 if( pos == 2 ){ $$ = wims_mathml_copy5("<munder>",$2,"<mo stretchy=\"false\">",s1,"</mo></munder>");}
1626
 else
1627
 if( pos == 3 ){ $$ = wims_mathml_copy3("<mo stretchy=\"false\">",s1,"</mo>");}
1628
 wims_mathml_free_string(s1);
1629
 wims_mathml_free_string($2);
11708 schaersvoo 1630
}
5520 bpr 1631
tilde: TILDE closedTerm {
1632
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&tilde;</mo></mover>");
1633
  wims_mathml_free_string($2);
1634
}
1635
| WIDETILDE closedTerm {
1636
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&tilde;</mo></mover>");
1637
  wims_mathml_free_string($2);
1638
};
1639
 
1640
check: CHECK closedTerm {
1641
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2c7;</mo></mover>");
1642
  wims_mathml_free_string($2);
1643
}
1644
| WIDECHECK closedTerm {
1645
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&#x2c7;</mo></mover>");
1646
  wims_mathml_free_string($2);
1647
};
1648
 
1649
hat: HAT closedTerm {
1650
  $$ = wims_mathml_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x5E;</mo></mover>");
1651
  wims_mathml_free_string($2);
1652
}
1653
| WIDEHAT closedTerm {
1654
  $$ = wims_mathml_copy3("<mover>", $2, "<mo>&#x5E;</mo></mover>");
1655
  wims_mathml_free_string($2);
1656
};
1657
 
1658
msqrt: SQRT closedTerm {
1659
  $$ = wims_mathml_copy3("<msqrt>", $2, "</msqrt>");
1660
  wims_mathml_free_string($2);
1661
};
1662
 
1663
mroot: SQRT OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1664
  char * s1 = wims_mathml_copy3("<mroot>", $5, $3);
1665
  $$ = wims_mathml_copy2(s1, "</mroot>");
1666
  wims_mathml_free_string(s1);
1667
  wims_mathml_free_string($3);
1668
  wims_mathml_free_string($5);
1669
}
1670
| ROOT closedTerm closedTerm {
1671
  char * s1 = wims_mathml_copy3("<mroot>", $3, $2);
1672
  $$ = wims_mathml_copy2(s1, "</mroot>");
1673
  wims_mathml_free_string(s1);
1674
  wims_mathml_free_string($2);
1675
  wims_mathml_free_string($3);
1676
};
1677
 
1678
raisebox: RAISEBOX TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1679
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"");
1680
  char * s2 = wims_mathml_copy3(s1, $3, "\" depth=\"");
1681
  char * s3 = wims_mathml_copy3(s2, $4, "\">");
1682
  $$ = wims_mathml_copy3(s3, $5, "</mpadded>");
1683
  wims_mathml_free_string(s1);
1684
  wims_mathml_free_string(s2);
1685
  wims_mathml_free_string(s3);
1686
  wims_mathml_free_string($2);
1687
  wims_mathml_free_string($3);
1688
  wims_mathml_free_string($4);
1689
  wims_mathml_free_string($5);
1690
}
1691
| RAISEBOX NEG TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1692
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"");
1693
  char * s2 = wims_mathml_copy3(s1, $4, "\" depth=\"");
1694
  char * s3 = wims_mathml_copy3(s2, $5, "\">");
1695
  $$ = wims_mathml_copy3(s3, $6, "</mpadded>");
1696
  wims_mathml_free_string(s1);
1697
  wims_mathml_free_string(s2);
1698
  wims_mathml_free_string(s3);
1699
  wims_mathml_free_string($3);
1700
  wims_mathml_free_string($4);
1701
  wims_mathml_free_string($5);
1702
  wims_mathml_free_string($6);
1703
}
1704
| RAISEBOX TEXTSTRING TEXTSTRING closedTerm {
1705
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"");
1706
  char * s2 = wims_mathml_copy3(s1, $3, "\" depth=\"depth\">");
1707
  $$ = wims_mathml_copy3(s2, $4, "</mpadded>");
1708
  wims_mathml_free_string(s1);
1709
  wims_mathml_free_string(s2);
1710
  wims_mathml_free_string($2);
1711
  wims_mathml_free_string($3);
1712
  wims_mathml_free_string($4);
1713
}
1714
| RAISEBOX NEG TEXTSTRING TEXTSTRING closedTerm {
1715
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"");
1716
  char * s2 = wims_mathml_copy3(s1, $4, "\" depth=\"+");
1717
  char * s3 = wims_mathml_copy3(s2, $3, "\">");
1718
  $$ = wims_mathml_copy3(s3, $5, "</mpadded>");
1719
  wims_mathml_free_string(s1);
1720
  wims_mathml_free_string(s2);
1721
  wims_mathml_free_string(s3);
1722
  wims_mathml_free_string($3);
1723
  wims_mathml_free_string($4);
1724
  wims_mathml_free_string($5);
1725
}
1726
| RAISEBOX TEXTSTRING closedTerm {
1727
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"", $2, "\" height=\"+");
1728
  char * s2 = wims_mathml_copy3(s1, $2, "\" depth=\"depth\">");
1729
  $$ = wims_mathml_copy3(s2, $3, "</mpadded>");
1730
  wims_mathml_free_string(s1);
1731
  wims_mathml_free_string(s2);
1732
  wims_mathml_free_string($2);
1733
  wims_mathml_free_string($3);
1734
}
1735
| RAISEBOX NEG TEXTSTRING closedTerm {
1736
  char * s1 = wims_mathml_copy3("<mpadded voffset=\"-", $3, "\" height=\"0pt\" depth=\"+");
1737
  char * s2 = wims_mathml_copy3(s1, $3, "\">");
1738
  $$ = wims_mathml_copy3(s2, $4, "</mpadded>");
1739
  wims_mathml_free_string(s1);
1740
  wims_mathml_free_string(s2);
1741
  wims_mathml_free_string($3);
1742
  wims_mathml_free_string($4);
1743
};
1744
 
1745
munder: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE EMPTYMROW {
1746
  char * s1 = wims_mathml_copy3("<munder><mo>", $1, "</mo><mrow>");
1747
  $$ = wims_mathml_copy3(s1, $3, "</mrow></munder>");
1748
  wims_mathml_free_string(s1);
1749
  wims_mathml_free_string($1);
1750
  wims_mathml_free_string($3);
1751
}
1752
| UNDER closedTerm closedTerm {
1753
  char * s1 = wims_mathml_copy3("<munder>", $3, $2);
1754
  $$ = wims_mathml_copy2(s1, "</munder>");
1755
  wims_mathml_free_string(s1);
1756
  wims_mathml_free_string($2);
1757
  wims_mathml_free_string($3);
1758
};
1759
 
1760
mover: XARROW closedTerm {
1761
  char * s1 = wims_mathml_copy3("<mover><mo>", $1, "</mo>");
1762
  $$ =  wims_mathml_copy3(s1, $2, "</mover>");
1763
  wims_mathml_free_string(s1);
1764
  wims_mathml_free_string($1);
1765
  wims_mathml_free_string($2);
1766
}
1767
| OVER closedTerm closedTerm {
1768
  char * s1 = wims_mathml_copy3("<mover>", $3, $2);
1769
  $$ = wims_mathml_copy2(s1, "</mover>");
1770
  wims_mathml_free_string(s1);
1771
  wims_mathml_free_string($2);
1772
  wims_mathml_free_string($3);
1773
};
1774
 
1775
munderover: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1776
  char * s1 = wims_mathml_copy3("<munderover><mo>", $1, "</mo><mrow>");
1777
  char * s2 = wims_mathml_copy3(s1, $3, "</mrow>");
1778
  $$ = wims_mathml_copy3(s2, $5, "</munderover>");
1779
  wims_mathml_free_string(s1);
1780
  wims_mathml_free_string(s2);
1781
  wims_mathml_free_string($1);
1782
  wims_mathml_free_string($3);
1783
  wims_mathml_free_string($5);
1784
}
1785
| UNDEROVER closedTerm closedTerm closedTerm {
1786
  char * s1 = wims_mathml_copy3("<munderover>", $4, $2);
1787
  $$ = wims_mathml_copy3(s1, $3, "</munderover>");
1788
  wims_mathml_free_string(s1);
1789
  wims_mathml_free_string($2);
1790
  wims_mathml_free_string($3);
1791
  wims_mathml_free_string($4);
1792
};
1793
 
1794
emptymrow: EMPTYMROW {
1795
  $$ = wims_mathml_copy_string("<mrow></mrow>");
1796
};
1797
 
1798
mathenv: BEGINENV MATRIX tableRowList ENDENV MATRIX {
1799
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1800
  wims_mathml_free_string($3);
1801
}
1802
|  BEGINENV EQUATION tableRowList ENDENV EQUATION {
1803
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"0.8ex\">", $3, "</mtable></mrow>");
1804
  wims_mathml_free_string($3);
1805
}
1806
|  BEGINENV GATHERED tableRowList ENDENV GATHERED {
1807
  $$ = wims_mathml_copy3("<mrow><mtable rowspacing=\"1.0ex\">", $3, "</mtable></mrow>");
1808
  wims_mathml_free_string($3);
1809
}
1810
| BEGINENV PMATRIX tableRowList ENDENV PMATRIX {
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 BMATRIX tableRowList ENDENV BMATRIX {
1815
  $$ = wims_mathml_copy3("<mrow><mo>[</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>]</mo></mrow>");
1816
  wims_mathml_free_string($3);
1817
}
1818
| BEGINENV VMATRIX tableRowList ENDENV VMATRIX {
1819
  $$ = wims_mathml_copy3("<mrow><mo>&VerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
1820
  wims_mathml_free_string($3);
1821
}
1822
| BEGINENV BBMATRIX tableRowList ENDENV BBMATRIX {
1823
  $$ = wims_mathml_copy3("<mrow><mo>{</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>}</mo></mrow>");
1824
  wims_mathml_free_string($3);
1825
}
1826
| BEGINENV VVMATRIX tableRowList ENDENV VVMATRIX {
1827
  $$ = wims_mathml_copy3("<mrow><mo>&DoubleVerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
1828
  wims_mathml_free_string($3);
1829
}
1830
| BEGINENV SMALLMATRIX tableRowList ENDENV SMALLMATRIX {
1831
  $$ = wims_mathml_copy3("<mstyle scriptlevel=\"2\"><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow></mstyle>");
1832
  wims_mathml_free_string($3);
1833
}
1834
| BEGINENV CASES tableRowList ENDENV CASES {
1835
  $$ = wims_mathml_copy3("<mrow><mo>{</mo><mrow><mtable columnalign=\"left left\">", $3, "</mtable></mrow></mrow>");
1836
  wims_mathml_free_string($3);
1837
}
1838
| BEGINENV ALIGNED tableRowList ENDENV ALIGNED {
1839
  $$ = wims_mathml_copy3("<mrow><mtable columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\">", $3, "</mtable></mrow>");
1840
  wims_mathml_free_string($3);
1841
}
1842
| BEGINENV ARRAY ARRAYALIGN ST TEX_OPTIONS END tableRowList ENDENV ARRAY {
1843
  $$= wims_mathml_copy7("<mtable rowspacing=\"0.5ex\" align=\"", $3 ,"\"", $5 ," >",$7,"</mtable>");
1844
  wims_mathml_free_string($3);
1845
  wims_mathml_free_string($5);
1846
  wims_mathml_free_string($7);
1847
}
1848
| BEGINENV ARRAY ST TEX_OPTIONS END tableRowList ENDENV ARRAY {
1849
    $$= wims_mathml_copy5("<mtable rowspacing=\"0.5ex\" ",$4," >", $6 ,"</mtable>");
1850
    wims_mathml_free_string($4);
1851
    wims_mathml_free_string($6);
1852
}
1853
| BEGINENV SVG XMLSTRING ENDSVG {
1854
  $$ = wims_mathml_copy3("<semantics><annotation-xml encoding=\"SVG1.1\">", $3, "</annotation-xml></semantics>");
1855
  wims_mathml_free_string($3);
1856
}
1857
| BEGINENV SVG ENDSVG {
1858
  $$ = wims_mathml_copy_string(" ");
7333 schaersvoo 1859
}
7332 schaersvoo 1860
| BEGINENV HTML XMLSTRING ENDHTML {
1861
  $$ = wims_mathml_copy3("<semantics><annotation-xml encoding=\"application/xhtml+xml\">", $3, "</annotation-xml></semantics>");
1862
  wims_mathml_free_string($3);
1863
}
1864
| BEGINENV HTML ENDHTML {
1865
  $$ = wims_mathml_copy_string(" ");
1866
};
5520 bpr 1867
 
1868
substack: SUBSTACK MROWOPEN tableRowList MROWCLOSE {
1869
  $$ = wims_mathml_copy3("<mrow><mtable columnalign=\"center\" rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1870
  wims_mathml_free_string($3);
1871
};
1872
 
14226 schaersvoo 1873
shortarray: SHORTARRAY MROWOPEN tableRowList MROWCLOSE {
1874
char *s1;char *s2;
1875
/*
1876
 
1877
1 = \Bmatrix{}
1878
2 = \pmatrix{}
1879
3 = \vmatrix{}
1880
4 = \Vmatrix{}
1881
5 = \aligned{}
1882
*/
1883
switch(wims_mathml_shortcut){
1884
 case 0: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">{</mo>");s2=wims_mathml_copy_string("<mo></mo>");break;
1885
 case 1: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">{</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">}</mo>");break;
1886
 case 2: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">(</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">)</mo>");break;
1887
 case 3: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">&vert;</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">&vert;</mo>");break;
1888
 case 4: s1 = wims_mathml_copy_string("<mo stretchy=\"true\">&Vert;</mo>");s2=wims_mathml_copy_string("<mo stretchy=\"true\">&Vert;</mo>");break;
1889
 case 5: s1 = wims_mathml_copy_string(" ");s2=wims_mathml_copy_string(" ");break;
1890
 default: s1 = wims_mathml_copy_string(" ");s2 = wims_mathml_copy_string(" "); break;
1891
}
1892
  $$ = wims_mathml_copy5( s1 ,"<mrow><mtable>", $3, "</mtable></mrow>", s2);
1893
  wims_mathml_free_string($3);
1894
  wims_mathml_free_string(s1);
1895
  wims_mathml_free_string(s2);
1896
};
1897
 
1898
 
5520 bpr 1899
array: ARRAY MROWOPEN tableRowList MROWCLOSE {
1900
  $$ = wims_mathml_copy3("<mrow><mtable>", $3, "</mtable></mrow>");
1901
  wims_mathml_free_string($3);
1902
}
1903
| ARRAY MROWOPEN ARRAYOPTS MROWOPEN arrayopts MROWCLOSE tableRowList MROWCLOSE {
1904
  char * s1 = wims_mathml_copy3("<mrow><mtable ", $5, ">");
1905
  $$ = wims_mathml_copy3(s1, $7, "</mtable></mrow>");
1906
  wims_mathml_free_string(s1);
1907
  wims_mathml_free_string($5);
1908
  wims_mathml_free_string($7);
1909
};
1910
 
1911
arrayopts: anarrayopt {
1912
  $$ = wims_mathml_copy_string($1);
1913
  wims_mathml_free_string($1);
1914
}
1915
| arrayopts anarrayopt {
1916
  $$ = wims_mathml_copy3($1, " ", $2);
1917
  wims_mathml_free_string($1);
1918
  wims_mathml_free_string($2);
1919
};
1920
 
1921
anarrayopt: collayout {
1922
  $$ = wims_mathml_copy_string($1);
1923
  wims_mathml_free_string($1);
1924
}
1925
| colalign {
1926
  $$ = wims_mathml_copy_string($1);
1927
  wims_mathml_free_string($1);
1928
}
1929
| rowalign {
1930
  $$ = wims_mathml_copy_string($1);
1931
  wims_mathml_free_string($1);
1932
}
1933
| align {
1934
  $$ = wims_mathml_copy_string($1);
1935
  wims_mathml_free_string($1);
1936
}
1937
| eqrows {
1938
  $$ = wims_mathml_copy_string($1);
1939
  wims_mathml_free_string($1);
1940
}
1941
| eqcols {
1942
  $$ = wims_mathml_copy_string($1);
1943
  wims_mathml_free_string($1);
1944
}
1945
| rowlines {
1946
  $$ = wims_mathml_copy_string($1);
1947
  wims_mathml_free_string($1);
1948
}
1949
| collines {
1950
  $$ = wims_mathml_copy_string($1);
1951
  wims_mathml_free_string($1);
1952
}
1953
| frame {
1954
  $$ = wims_mathml_copy_string($1);
1955
  wims_mathml_free_string($1);
1956
}
1957
| padding {
1958
  $$ = wims_mathml_copy_string($1);
1959
  wims_mathml_free_string($1);
1960
};
1961
 
1962
collayout: COLLAYOUT ATTRLIST {
1963
  $$ = wims_mathml_copy2("columnalign=", $2);
1964
  wims_mathml_free_string($2);
1965
};
1966
 
1967
colalign: COLALIGN ATTRLIST {
1968
  $$ = wims_mathml_copy2("columnalign=", $2);
1969
  wims_mathml_free_string($2);
1970
};
1971
 
1972
rowalign: ROWALIGN ATTRLIST {
1973
  $$ = wims_mathml_copy2("rowalign=", $2);
1974
  wims_mathml_free_string($2);
1975
};
1976
 
1977
align: ALIGN ATTRLIST {
1978
  $$ = wims_mathml_copy2("align=", $2);
1979
  wims_mathml_free_string($2);
1980
};
1981
 
1982
eqrows: EQROWS ATTRLIST {
1983
  $$ = wims_mathml_copy2("equalrows=", $2);
1984
  wims_mathml_free_string($2);
1985
};
1986
 
1987
eqcols: EQCOLS ATTRLIST {
1988
  $$ = wims_mathml_copy2("equalcolumns=", $2);
1989
  wims_mathml_free_string($2);
1990
};
1991
 
1992
rowlines: ROWLINES ATTRLIST {
1993
  $$ = wims_mathml_copy2("rowlines=", $2);
1994
  wims_mathml_free_string($2);
1995
};
1996
 
1997
collines: COLLINES ATTRLIST {
1998
  $$ = wims_mathml_copy2("columnlines=", $2);
1999
  wims_mathml_free_string($2);
2000
};
2001
 
2002
frame: FRAME ATTRLIST {
2003
  $$ = wims_mathml_copy2("frame=", $2);
2004
  wims_mathml_free_string($2);
2005
};
2006
 
2007
padding: PADDING ATTRLIST {
2008
  char * s1 = wims_mathml_copy3("rowspacing=", $2, " columnspacing=");
2009
  $$ = wims_mathml_copy2(s1, $2);
2010
  wims_mathml_free_string(s1);
2011
  wims_mathml_free_string($2);
2012
};
2013
 
2014
tableRowList: tableRow {
2015
  $$ = wims_mathml_copy_string($1);
2016
  wims_mathml_free_string($1);
2017
}
2018
| tableRowList ROWSEP tableRow {
2019
  $$ = wims_mathml_copy3($1, " ", $3);
2020
  wims_mathml_free_string($1);
2021
  wims_mathml_free_string($3);
2022
};
2023
 
2024
tableRow: simpleTableRow {
2025
  $$ = wims_mathml_copy3("<mtr>", $1, "</mtr>");
2026
  wims_mathml_free_string($1);
2027
}
2028
| optsTableRow {
2029
  $$ = wims_mathml_copy_string($1);
2030
  wims_mathml_free_string($1);
2031
};
2032
 
2033
simpleTableRow: tableCell {
2034
  $$ = wims_mathml_copy_string($1);
2035
  wims_mathml_free_string($1);
2036
}
2037
| simpleTableRow COLSEP tableCell {
2038
  $$ = wims_mathml_copy3($1, " ", $3);
2039
  wims_mathml_free_string($1);
2040
  wims_mathml_free_string($3);
2041
};
2042
 
2043
optsTableRow: ROWOPTS MROWOPEN rowopts MROWCLOSE simpleTableRow {
2044
  char * s1 = wims_mathml_copy3("<mtr ", $3, ">");
2045
  $$ = wims_mathml_copy3(s1, $5, "</mtr>");
2046
  wims_mathml_free_string(s1);
2047
  wims_mathml_free_string($3);
2048
  wims_mathml_free_string($5);
2049
};
2050
 
2051
rowopts: arowopt {
2052
  $$ = wims_mathml_copy_string($1);
2053
  wims_mathml_free_string($1);
2054
}
2055
| rowopts arowopt {
2056
  $$ = wims_mathml_copy3($1, " ", $2);
2057
  wims_mathml_free_string($1);
2058
  wims_mathml_free_string($2);
2059
};
2060
 
2061
arowopt: colalign {
2062
  $$ = wims_mathml_copy_string($1);
2063
  wims_mathml_free_string($1);
2064
}
2065
| rowalign {
2066
  $$ = wims_mathml_copy_string($1);
2067
  wims_mathml_free_string($1);
2068
};
2069
 
2070
tableCell:   {
2071
  $$ = wims_mathml_copy_string("<mtd></mtd>");
2072
}
2073
| compoundTermList {
2074
  $$ = wims_mathml_copy3("<mtd>", $1, "</mtd>");
2075
  wims_mathml_free_string($1);
2076
}
2077
| CELLOPTS MROWOPEN cellopts MROWCLOSE compoundTermList {
2078
  char * s1 = wims_mathml_copy3("<mtd ", $3, ">");
2079
  $$ = wims_mathml_copy3(s1, $5, "</mtd>");
2080
  wims_mathml_free_string(s1);
2081
  wims_mathml_free_string($3);
2082
  wims_mathml_free_string($5);
2083
};
2084
 
2085
cellopts: acellopt {
2086
  $$ = wims_mathml_copy_string($1);
2087
  wims_mathml_free_string($1);
2088
}
2089
| cellopts acellopt {
2090
  $$ = wims_mathml_copy3($1, " ", $2);
2091
  wims_mathml_free_string($1);
2092
  wims_mathml_free_string($2);
2093
};
2094
 
2095
acellopt: colalign {
2096
  $$ = wims_mathml_copy_string($1);
2097
  wims_mathml_free_string($1);
2098
}
2099
| rowalign {
2100
  $$ = wims_mathml_copy_string($1);
2101
  wims_mathml_free_string($1);
2102
}
2103
| rowspan {
2104
  $$ = wims_mathml_copy_string($1);
2105
  wims_mathml_free_string($1);
2106
}
2107
| colspan {
2108
  $$ = wims_mathml_copy_string($1);
2109
  wims_mathml_free_string($1);
2110
};
2111
 
2112
rowspan: ROWSPAN ATTRLIST {
2113
  $$ = wims_mathml_copy2("rowspan=", $2);
2114
  wims_mathml_free_string($2);
2115
};
2116
 
2117
colspan: COLSPAN ATTRLIST {
2118
  $$ = wims_mathml_copy2("columnspan=", $2);
2119
  wims_mathml_free_string($2);
2120
};
2121
 
2122
%%
2123
 
2124
char * wims_mathml_parse (const char * buffer, unsigned long length)
2125
{
2126
  char * mathml = 0;
2127
 
2128
  int result;
2129
 
2130
  wims_mathml_setup (buffer, length);
2131
  wims_mathml_restart ();
2132
 
2133
  result = wims_mathml_yyparse (&mathml);
2134
 
2135
  if (result && mathml) /* shouldn't happen? */
2136
    {
2137
      wims_mathml_free_string (mathml);
2138
      mathml = 0;
2139
    }
2140
  return mathml;
2141
}
2142
 
2143
int wims_mathml_filter (const char * buffer, unsigned long length)
2144
{
2145
  wims_mathml_setup (buffer, length);
2146
  wims_mathml_restart ();
2147
 
2148
  return wims_mathml_yyparse (0);
2149
}
2150
 
2151
#define ITEX_DELIMITER_DOLLAR 0
2152
#define ITEX_DELIMITER_DOUBLE 1
2153
#define ITEX_DELIMITER_SQUARE 2
2154
 
2155
static char * wims_mathml_last_error = 0;
2156
 
2157
static void wims_mathml_keep_error (const char * msg)
2158
{
2159
  if (wims_mathml_last_error)
2160
    {
2161
      wims_mathml_free_string (wims_mathml_last_error);
2162
      wims_mathml_last_error = 0;
2163
    }
2164
  wims_mathml_last_error = wims_mathml_copy_escaped (msg);
2165
}
2166
 
2167
int wims_mathml_html_filter (const char * buffer, unsigned long length)
2168
{
7396 schaersvoo 2169
 return wims_mathml_do_html_filter (buffer, length, 0);
5520 bpr 2170
}
2171
 
2172
int wims_mathml_strict_html_filter (const char * buffer, unsigned long length)
2173
{
7396 schaersvoo 2174
  return wims_mathml_do_html_filter (buffer, length, 1);
5520 bpr 2175
}
2176
 
2177
int wims_mathml_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
2178
{
2179
  int result = 0;
2180
 
2181
  int type = 0;
2182
  int skip = 0;
2183
  int match = 0;
2184
 
2185
  const char * ptr1 = buffer;
2186
  const char * ptr2 = 0;
2187
 
2188
  const char * end = buffer + length;
2189
 
2190
  char * mathml = 0;
2191
 
2192
  void (*save_error_fn) (const char * msg) = wims_mathml_error;
2193
 
2194
  wims_mathml_error = wims_mathml_keep_error;
2195
 
7076 obado 2196
  _until_math:
5520 bpr 2197
  ptr2 = ptr1;
2198
 
2199
  while (ptr2 < end)
7076 obado 2200
  {
2201
    if (*ptr2 == '$') break;
2202
    if ((*ptr2 == '\\') && (ptr2 + 1 < end))
5520 bpr 2203
    {
7076 obado 2204
      if (*(ptr2+1) == '[') break;
5520 bpr 2205
    }
7076 obado 2206
    ++ptr2;
2207
  }
5520 bpr 2208
  if (wims_mathml_write && ptr2 > ptr1)
2209
    (*wims_mathml_write) (ptr1, ptr2 - ptr1);
2210
 
2211
  if (ptr2 == end) goto _finish;
2212
 
7076 obado 2213
  _until_html:
5520 bpr 2214
  ptr1 = ptr2;
2215
 
2216
  if (ptr2 + 1 < end)
7076 obado 2217
  {
2218
    if ((*ptr2 == '\\') && (*(ptr2+1) == '['))
5520 bpr 2219
    {
7076 obado 2220
      type = ITEX_DELIMITER_SQUARE;
2221
      ptr2 += 2;
5520 bpr 2222
    }
7076 obado 2223
    else if ((*ptr2 == '$') && (*(ptr2+1) == '$'))
2224
    {
2225
      type = ITEX_DELIMITER_DOUBLE;
2226
      ptr2 += 2;
2227
    }
2228
    else
2229
    {
2230
      type = ITEX_DELIMITER_DOLLAR;
2231
      ptr2 += 2;
2232
    }
2233
  }
5520 bpr 2234
  else goto _finish;
2235
 
2236
  skip = 0;
2237
  match = 0;
2238
 
2239
  while (ptr2 < end)
7076 obado 2240
  {
2241
    switch (*ptr2)
5520 bpr 2242
    {
7076 obado 2243
    case '<':
2244
    case '>':
2245
      if (forbid_markup == 1) skip = 1;
2246
      break;
5520 bpr 2247
 
7076 obado 2248
    case '\\':
2249
      if (ptr2 + 1 < end)
2250
      {
2251
        if (*(ptr2 + 1) == '[')
2252
        {
2253
          skip = 1;
2254
        }
2255
        else if (*(ptr2 + 1) == ']')
2256
        {
2257
          if (type == ITEX_DELIMITER_SQUARE)
2258
          {
2259
            ptr2 += 2;
2260
            match = 1;
2261
          }
2262
          else
2263
          {
2264
            skip = 1;
2265
          }
2266
        }
2267
      }
2268
      break;
5520 bpr 2269
 
7076 obado 2270
    case '$':
2271
      if (type == ITEX_DELIMITER_SQUARE)
2272
      {
2273
        skip = 1;
2274
      }
2275
      else if (ptr2 + 1 < end)
2276
      {
2277
        if (*(ptr2 + 1) == '$')
2278
        {
2279
          if (type == ITEX_DELIMITER_DOLLAR)
2280
          {
2281
            ptr2++;
2282
            match = 1;
2283
          }
2284
          else
2285
          {
2286
            ptr2 += 2;
2287
            match = 1;
2288
          }
2289
        }
2290
        else
2291
        {
2292
          if (type == ITEX_DELIMITER_DOLLAR)
2293
          {
2294
            ptr2++;
2295
            match = 1;
2296
          }
2297
          else
2298
          {
2299
            skip = 1;
2300
          }
2301
        }
2302
      }
2303
      else
2304
      {
2305
        if (type == ITEX_DELIMITER_DOLLAR)
2306
        {
2307
          ptr2++;
2308
          match = 1;
2309
        }
2310
        else
2311
        {
2312
          skip = 1;
2313
        }
2314
      }
2315
      break;
5520 bpr 2316
 
7076 obado 2317
    default:
2318
      break;
2319
    }
2320
    if (skip || match) break;
5520 bpr 2321
 
7076 obado 2322
    ++ptr2;
2323
  }
5520 bpr 2324
  if (skip)
7076 obado 2325
  {
2326
    if (type == ITEX_DELIMITER_DOLLAR)
5520 bpr 2327
    {
7076 obado 2328
      if (wims_mathml_write)
2329
        (*wims_mathml_write) (ptr1, 1);
2330
      ptr1++;
5520 bpr 2331
    }
7076 obado 2332
    else
2333
    {
2334
      if (wims_mathml_write)
2335
        (*wims_mathml_write) (ptr1, 2);
2336
      ptr1 += 2;
2337
    }
2338
    goto _until_math;
2339
  }
5520 bpr 2340
  if (match)
7076 obado 2341
  {
2342
    mathml = wims_mathml_parse (ptr1, ptr2 - ptr1);
2343
    if (mathml)
5520 bpr 2344
    {
7076 obado 2345
      if (wims_mathml_write_mathml)
2346
        (*wims_mathml_write_mathml) (mathml);
2347
      wims_mathml_free_string (mathml);
2348
      mathml = 0;
2349
    }
2350
    else
2351
    {
2352
      ++result;
2353
      if (wims_mathml_write)
2354
      {
2355
        if (type == ITEX_DELIMITER_DOLLAR)
9568 schaersvoo 2356
          (*wims_mathml_write) ("<span style=\"font-size:1em;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><merror><mtext>", 0);
7076 obado 2357
        else
9568 schaersvoo 2358
          (*wims_mathml_write) ("<span style=\"font-size:1em;\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><merror><mtext>", 0);
7076 obado 2359
          (*wims_mathml_write) (wims_mathml_last_error, 0);
9568 schaersvoo 2360
          (*wims_mathml_write) ("</mtext></merror></math></span>", 0);
7076 obado 2361
        }
2362
    }
2363
    ptr1 = ptr2;
5520 bpr 2364
 
7076 obado 2365
    goto _until_math;
2366
  }
5520 bpr 2367
  if (wims_mathml_write)
2368
    (*wims_mathml_write) (ptr1, ptr2 - ptr1);
2369
 
7076 obado 2370
  _finish:
5520 bpr 2371
  if (wims_mathml_last_error)
7076 obado 2372
  {
2373
    wims_mathml_free_string (wims_mathml_last_error);
2374
    wims_mathml_last_error = 0;
2375
  }
5520 bpr 2376
  wims_mathml_error = save_error_fn;
2377
 
2378
  return result;
2379
}
7332 schaersvoo 2380
 
2381
 
2382
void replace_str(const char *str, const char *old, const char *new){
2383
/* http://creativeandcritical.net/str-replace-c/ */
2384
    char *ret, *r;
2385
    const char *p, *q;
2386
    size_t oldlen = strlen(old);
2387
    size_t count, retlen, newlen = strlen(new);
2388
 
2389
    if (oldlen != newlen){
15175 obado 2390
  for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
2391
      count++;
2392
      retlen = p - str + strlen(p) + count * (newlen - oldlen);
2393
  }
8910 bpr 2394
    }
7332 schaersvoo 2395
    else
2396
    {
15175 obado 2397
  retlen = strlen(str);
7332 schaersvoo 2398
    }
8910 bpr 2399
 
7332 schaersvoo 2400
    if ((ret = malloc(retlen + 1)) == NULL){
15175 obado 2401
  ret = NULL;
7332 schaersvoo 2402
    }
2403
    else
2404
    {
15175 obado 2405
  for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
2406
      size_t l = q - p;
2407
      memcpy(r, p, l);
2408
      r += l;
2409
      memcpy(r, new, newlen);
2410
      r += newlen;
2411
  }
2412
  strcpy(r, p);
7332 schaersvoo 2413
    }
2414
    yylval = ret;
2415
}