Annotation of 41BSD/cmd/cifplot/parser.y, revision 1.1.1.1

1.1       root        1: 
                      2: %{
                      3: /*******************************************************************
                      4: *                                                                  *
                      5: *    File: CIFPLOT/parser.y                                        *
                      6: *    Written by Dan Fitzpatrick                                    *
                      7: *    copyright 1980 -- Regents of the University of California     *
                      8: *                                                                  *
                      9: ********************************************************************/
                     10: 
                     11: /* This is a YACC description for the parser */
                     12: 
                     13: /* In the offical CIF language description SEMI = BLANKLIST ';' BLANKLIST
                     14:  * but this causes ambiguities for the LALR(1) parser so the scanner
                     15:  * returns ';' when it spots the pattern BLANKLIST ';'
                     16:  */
                     17: 
                     18: #include <stdio.h>
                     19: #include "defs.h"
                     20: #include "globals.h"
                     21: #include "structs.h"
                     22: #include "alloc.h"
                     23: 
                     24: #define yyparse parser
                     25: #define yylex scanner
                     26: 
                     27: #define null  Concat("",0);
                     28: int Definning=0;
                     29: int SendAll=0;         /* If set causes the lexical analyzer to return
                     30:                         * BLANKLIST and ';' seperately */
                     31: int A = 1;
                     32: int B = 1;
                     33: 
                     34: #define SCALE(x)       ( (((real) A) * ((real) x)) / ((real) B ))
                     35: 
                     36: %}
                     37: 
                     38: %start CIF_FILE
                     39: %token BLANK
                     40: %token OTHERCHAR
                     41: %token COMMENT_COMMAND
                     42: 
                     43: %%
                     44: CIF_FILE
                     45:        :       COMMANDLIST END_COMMAND BLANKLIST
                     46:        |       COMMANDLIST END_COMMAND error
                     47:                                        { Error("Improper Ending",FATAL); }
                     48:        |       COMMANDLIST END_COMMAND SEMI
                     49:                                        { Error("Semi-Colon found after End",
                     50:                                                        RECOVERABLE); }
                     51:        |       COMMANDLIST
                     52:                                        { Error("No End Statement",RECOVERABLE); }
                     53:        |       COMMANDLIST END_COMMAND BLANKLIST GARBAGE error 
                     54:                                        { Error("Garbage after End Statement",
                     55:                                                        RECOVERABLE); }
                     56:        ;
                     57: 
                     58: COMMANDLIST
                     59:        :       COMMANDLIST COMMAND SEMI
                     60:        |       COMMANDLIST SEMI
                     61:        |       BLANKLIST
                     62:        |       COMMANDLIST error 
                     63:                                        { Error("Unrecognizable Command",FATAL); }
                     64:                                 SEMI
                     65:        ;
                     66: 
                     67: COMMAND 
                     68:        :       FCOMMAND
                     69:        ;
                     70: 
                     71: FCOMMAND       
                     72:        :       PRIM_COMMAND
                     73:                                        { Execute($1);          }
                     74:        |       DEF_DELETE_COMMAND
                     75:        |       SYMB_LIST DEF_FINNISH_COMMAND
                     76:                                        { Execute($1);
                     77:                                          Definning = 0;
                     78:                                          A=1; B=1;             }
                     79:        |       ERROR_COMMAND
                     80:        ;
                     81: 
                     82: ERROR_COMMAND
                     83:        :       COMMENT_COMMAND 
                     84:                                        { Error("Comments must end with a semi-colon",
                     85:                                                        RECOVERABLE);           }
                     86:                        BLANKLIST FCOMMAND                      
                     87:                                        { $$ = $1; }
                     88:        |       DEF_FINNISH_COMMAND                             
                     89:                                        { Error("Define Finnished found outside of Definition",
                     90:                                                        FATAL); 
                     91:                                          $$ = $1;      }
                     92:        |       DEF_ERROR               
                     93:                                        { Error("Unrecognized Definition Command",
                     94:                                                        FATAL); }
                     95:        ;
                     96: 
                     97: SYMB_LIST
                     98:        :       SYMB_LIST SYMB_COMMAND
                     99:                                        { $$ = AddCmd($1,$2);   }
                    100:        |       SYMB_LIST SEMI
                    101:                                        { $$ = $1; }
                    102:        |       DEF_START_COMMAND SEMI
                    103:                                        { Definning = 1;
                    104:                                          A=(int) ((Command *) $1)->Ctype.Symbl.a;
                    105:                                          B=(int) ((Command *) $1)->Ctype.Symbl.b;
                    106:                                          $$ = $1;              }
                    107:        |       SYMB_LIST error                                 
                    108:                                        { $$ = $1;
                    109:                                          Error("Unrecognized or Illegal Command in Definition",
                    110:                                                        FATAL); }
                    111:                                 SEMI
                    112:        ;
                    113: 
                    114: SYMB_COMMAND
                    115:        :       PRIM_COMMAND SEMI
                    116:                                        { $$ = $1; }
                    117:        |       COMMENT_COMMAND
                    118:                                        { Error("Comments must end with a semi-colon",RECOVERABLE); }
                    119:                                BLANKLIST SYMB_COMMAND
                    120:                                        { $$ = $4;      }
                    121:        ;
                    122: 
                    123: PRIM_COMMAND
                    124:        :       POLYGON_COMMAND
                    125:        |       BOX_COMMAND
                    126:        |       ROUNDFLASH_COMMAND
                    127:        |       WIRE_COMMAND
                    128:        |       LAYER_COMMAND
                    129:        |       CALL_COMMAND
                    130:        |       USEREXTENSION_COMMAND
                    131:        |       COMMENT_COMMAND
                    132:        ;
                    133: 
                    134: POLYGON_COMMAND        
                    135:        :       'P' PATH                                        
                    136:                                        { /* Polygons must have more than two
                    137:                                           * vertices to be well defined */
                    138:                                          if( ((struct PathHeader *) $2)->PNo < 3)
                    139:                                                Error("Degenerate Polygon",WARNING);
                    140:                                          /* Polygons with less than two vertices are
                    141:                                            * useless   */
                    142:                                          if( ((struct PathHeader *) $2)->PNo < 2) {
                    143:                                                Error("Command Ignored",WARNING);
                    144:                                                $$ = MakeComment();
                    145:                                                }
                    146:                                              else
                    147:                                                $$ = MakePoly($2);      }
                    148:        |       'P' error       
                    149:                                        { Error("Bad Path Descriptor in Polygon",FATAL);                
                    150:                                          $$ = MakeComment();   }
                    151:        ;
                    152: 
                    153: BOX_COMMAND
                    154:        :       'B' INTEGER SEP INTEGER SEP POINT               
                    155:                                        { $$ = MakeBox(SCALE($2),SCALE($4),$6,
                    156:                                                        MakePoint(1.0,0.0)); 
                    157:                                          Free($6);             }
                    158:        |       'B' INTEGER SEP INTEGER SEP POINT SEP POINT     
                    159:                                        { if(!CheckPoint($8))
                    160:                                                Error("Bad Direction Vector in Box Command",FATAL);
                    161:                                          $$ = MakeBox(SCALE($2),SCALE($4),$6,$8);
                    162:                                          Free($6); Free($8);   }
                    163:        |       'B' error
                    164:                                        { Error("Illegal Box Description",FATAL);
                    165:                                          $$ = MakeComment();   }
                    166:        ;
                    167: 
                    168: ROUNDFLASH_COMMAND 
                    169:        :       'R' INTEGER SEP POINT                           
                    170:                                        { $$ = MakeFlash(SCALE($2),$4);}
                    171:        |       'R' error
                    172:                                        { Error("Illegal Round Flash Description",FATAL);
                    173:                                          $$ = MakeComment();   }
                    174:        ;
                    175: 
                    176: WIRE_COMMAND
                    177:        :       'W' INTEGER SEP PATH                            
                    178:                                        { if( ((struct PathHeader *) $4)->PNo < 2) 
                    179:                                                Error("Degenerate Wire",WARNING);
                    180:                                          $$ = MakeWire(SCALE($2),$4); }
                    181:        |       'W' error
                    182:                                        { Error("Illegal Wire Description",FATAL);
                    183:                                          $$ = MakeComment();   }
                    184:        ;
                    185: 
                    186: LAYER_COMMAND
                    187:        :       'L' BLANKLIST SHORTNAME                                 
                    188:                                        { $$ = MakeLayer($3);   }
                    189:        |       'L' error
                    190:                                        { Error("Illegal Layer Command",FATAL);
                    191:                                          $$ = MakeComment();   }
                    192:        ;
                    193: 
                    194: DEF_START_COMMAND
                    195:        :       'D' BLANKLIST 'S' INTEGER
                    196:                                        { $$ = MakeSymbol($4,1,1);}
                    197:        |       'D' BLANKLIST 'S' INTEGER SEP INTEGER SEP INTEGER
                    198:                                        { $$ = MakeSymbol($4,$6,$8);}
                    199:        ;
                    200: 
                    201: DEF_FINNISH_COMMAND 
                    202:        :       'D' BLANKLIST 'F'                               
                    203:                                        { $$ = 0; }
                    204:        ;
                    205: 
                    206: DEF_DELETE_COMMAND 
                    207:        :       'D' BLANKLIST 'D' INTEGER                       
                    208:                                        { DeleteDefintion($4);
                    209:                                          $$ = MakeComment();   }
                    210: 
                    211:        ;
                    212: 
                    213: DEF_ERROR
                    214:        :       'D' error
                    215:        ;
                    216: 
                    217: CALL_COMMAND
                    218:        :       'C' INTEGER TRANSFORMATION                      
                    219:                                        { $$ = MakeCall($2,$3); }
                    220:        |       'C' error
                    221:                                        { Error("Illegal Call Command",FATAL);          
                    222:                                          $$ = MakeComment();   }
                    223:        ;
                    224: 
                    225: USEREXTENSION_COMMAND 
                    226:        :       SENDALL '0' SP NAME
                    227:                                        { $$ = MakeComment();
                    228:                                          if(!standard)
                    229:                                             Include($4);
                    230:                                           else
                    231:                                             Error("User Extention Ignored\n",WARNING);
                    232:                                         SendAll = 0;
                    233:                                         Free($4);              }
                    234:        |       SENDALL '0' 'I' SP NAME
                    235:                                        { $$ = MakeComment();
                    236:                                          if(!standard)
                    237:                                             Include($4);
                    238:                                           else
                    239:                                             Error("User Extention Ignored\n",WARNING);
                    240:                                          SendAll = 0;
                    241:                                          Free($4);             }
                    242:        |       SENDALL '0' 'A' INTEGER SEP INTEGER SEP INTEGER SEP SINTEGER SEP SINTEGER BLANKLIST
                    243:                                        { if(!standard)
                    244:                                             $$ = MakeArray($4,$6,$8,SCALE($10),SCALE($12));
                    245:                                           else {
                    246:                                             Error("User Extention Ignored\n",WARNING);
                    247:                                             $$ = MakeComment();
                    248:                                             }
                    249:                                          SendAll = 0;          }
                    250:        |       SENDALL '1' BLANK USERLIST
                    251:                                        { $$ = MakeComment();
                    252:                                          if(!standard)
                    253:                                             fprintf(stderr,"%s\n",$4);
                    254:                                           else
                    255:                                             Error("User Extention Ignored\n",WARNING);
                    256:                                          SendAll = 0;
                    257:                                          Free($4);             }
                    258:        |       SENDALL '2' SP '"' TEXT '"' TRANSFORMATION
                    259:                                        { if(!standard)
                    260:                                             $$ = MakeText($5,$7,'l');
                    261:                                           else {
                    262:                                             Error("User Extention Ignored\n",WARNING);
                    263:                                             $$ = MakeComment();
                    264:                                             }
                    265:                                          SendAll = 0;          }
                    266:        |       SENDALL '2' 'C' SP '"' TEXT '"' TRANSFORMATION
                    267:                                        { if(!standard)
                    268:                                             $$ = MakeText($6,$8,'c');
                    269:                                           else {
                    270:                                             Error("User Extention Ignored\n",WARNING);
                    271:                                             $$ = MakeComment();
                    272:                                             }
                    273:                                          SendAll = 0;          }
                    274:        |       SENDALL '9' SP NAME
                    275:                                        { if(!standard)
                    276:                                             $$ = MakeName($4);
                    277:                                           else {
                    278:                                             Error("User Extention Ignored\n",WARNING);
                    279:                                             $$ = MakeComment();
                    280:                                             }
                    281:                                          SendAll = 0;          }
                    282:        |       SENDALL '9' '4' SP NAME BLANK POINT
                    283:                                        { if(!standard) {
                    284:                                            $$ = MakePointName($5,$7,"all");
                    285:                                            Free($7);
                    286:                                            }
                    287:                                          else {
                    288:                                             Error("User Extention Ignored\n",WARNING);
                    289:                                             $$ = MakeComment();
                    290:                                             }
                    291:                                          SendAll = 0;          }
                    292:        |       SENDALL '9' '4' SP NAME BLANK POINT SP SHORTNAME
                    293:                                        { if(!standard) {
                    294:                                            $$ = MakePointName($5,$7,$9);
                    295:                                            Free($7);
                    296:                                            }
                    297:                                          else {
                    298:                                             Error("User Extention Ignored\n",WARNING);
                    299:                                             $$ = MakeComment();
                    300:                                             }
                    301:                                          SendAll = 0;          }
                    302:        |       SENDALL EXTEN_DIGIT  error      
                    303:                                        { $$ = MakeComment();
                    304:                                          Error("Bad Syntax in Extension Command --- Command Ignored",
                    305:                                                                WARNING);
                    306:                                           SendAll = 0;   }
                    307:        |       SENDALL OTHER_DIGIT  error      
                    308:                                        { $$ = MakeComment();
                    309:                                          Error("Unimplemented User Extension",
                    310:                                                                WARNING);
                    311:                                          SendAll = 0;     }
                    312:        ;
                    313: 
                    314: EXTEN_DIGIT
                    315:        :       '0' | '1' | '2' | '9'
                    316:        ;
                    317: 
                    318: OTHER_DIGIT
                    319:        :       '3' | '4' | '5' | '6' | '7' | '8'
                    320:        ;
                    321: 
                    322: SENDALL
                    323:        :       EMPTY                   {SendAll = 1; }
                    324:        ;
                    325: 
                    326: END_COMMAND    
                    327:        :       'E'                                             
                    328:        ;
                    329: 
                    330: TRANSFORMATION
                    331:        :       BLANKLIST 'T' POINT TRANSFORMATION              
                    332:                                        { $$ = Translate($3,$4);        
                    333:                                          if(output == NOPLOT)
                    334:                                              Free(((transform *) $4)->TransString);
                    335:                                          Free($3);  FreeTransform($4); }
                    336:        |       BLANKLIST 'M' BLANKLIST 'X' TRANSFORMATION      
                    337:                                        { $$ = Mirror('x',$5);  
                    338:                                          if(output == NOPLOT)
                    339:                                              Free(((transform *) $5)->TransString);
                    340:                                          FreeTransform($5);            }
                    341:        |       BLANKLIST 'M' BLANKLIST 'Y' TRANSFORMATION      
                    342:                                        { $$ = Mirror('y',$5);  
                    343:                                          if(output == NOPLOT)
                    344:                                              Free(((transform *) $5)->TransString);
                    345:                                          FreeTransform($5);            }
                    346:        |       BLANKLIST 'R' POINT TRANSFORMATION              
                    347:                                        { if(!CheckPoint($3))
                    348:                                              Error("Bad Rotation Vector",FATAL);
                    349:                                          $$ = Rotate($3,$4);
                    350:                                          if(output == NOPLOT)
                    351:                                              Free(((transform *) $4)->TransString);
                    352:                                          Free($3);  FreeTransform($4); }
                    353:        |       EMPTY                                           
                    354:                                        { $$ = MakeTransform();         }
                    355:        ;
                    356: 
                    357: PATH   
                    358:        :       PATH SEP POINT                                  
                    359:                                        { $$ = AddPath($1,$3);
                    360:                                          Free($3);             }
                    361:        |       POINT
                    362:                                        { $$ = MakePath($1);            }
                    363:        ;
                    364: 
                    365: POINT  
                    366:        :       SINTEGER SEP SINTEGER                           
                    367:                                        { $$ = MakePoint(SCALE($1),SCALE($3));  }
                    368:        |       SINTEGER error                          
                    369:                                        { Error("Odd number of values encountered",
                    370:                                                        FATAL); 
                    371:                                          $$ = MakePoint(SCALE($1),0.0);}
                    372:        ;
                    373: 
                    374: SINTEGER
                    375:        :       SEPLIST INTEGERD                                
                    376:                                        { $$ = $2; }
                    377:        |       SEPLIST '-' INTEGERD                            
                    378:                                        { $$ = - $3;            }
                    379:        ;
                    380: 
                    381: INTEGER        
                    382:        :       SEPLIST INTEGERD                                
                    383:                                        { $$ = $2; }
                    384:        |       SEPLIST '-' INTEGERD
                    385:                                        { Error("Expected Positive Integer",FATAL);
                    386:                                          $$ = $3;                      }
                    387:        ;
                    388: 
                    389: INTEGERD
                    390:        :       INTEGERD DIGIT                                  
                    391:                                        { if ($1 > (0x800000 / 10)) {
                    392:                                                Error("Integers may not exceed 2**24",
                    393:                                                                FATAL);
                    394:                                                $$ = 0;
                    395:                                                }
                    396:                                            else
                    397:                                                $$ = ($1*10)+$2-'0';    }
                    398:        |       DIGIT                                           
                    399:                                        { $$ = $1 - '0';        }
                    400:        ;
                    401: 
                    402: SHORTNAME
                    403:        :       C
                    404:        |       C C                                             
                    405:                                        { $$ = Concat($1,$2,0);
                    406:                                          Free($1); Free($2);            }
                    407:        |       C C C                                           
                    408:                                        { $$ = Concat($1,$2,$3,0);
                    409:                                          Free($1); Free($2); Free($3); }
                    410:        |       C C C C                                         
                    411:                                        { $$ = Concat($1,$2,$3,$4,0);
                    412:                                          Free($1); Free($2);
                    413:                                          Free($3); Free($4);           }
                    414:        ;
                    415: 
                    416: C      
                    417:        :       DIGIT                                           
                    418:                                        { $$ = MakeString($1); }
                    419:        |       UPPERCHAR                                       
                    420:                                        { $$ = MakeString($1); }
                    421:        ;
                    422: 
                    423: SEPLIST                
                    424:        :       SEPLIST SEP                                     
                    425:        |       EMPTY
                    426:        ;
                    427: 
                    428: SEP    
                    429:        :       UPPERCHAR                                       
                    430:        |       BLANK
                    431:        |       OTHERCHAR
                    432:        ;
                    433: 
                    434: UPPERCHAR
                    435:        :       'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G'
                    436:        |       'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N'
                    437:        |       'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U'
                    438:        |       'V' | 'W' | 'X' | 'Y' | 'Z'
                    439:        ;
                    440: 
                    441: DIGIT
                    442:        :       '0' | '1' | '2' | '3' | '4'
                    443:        |       '5' | '6' | '7' | '8' | '9'
                    444:        ;
                    445: 
                    446: NAME
                    447:        :       NAME NAMECHAR
                    448:                                        { $$ = Concat($1,$2,0);
                    449:                                          Free($1); Free($2);           }
                    450:        |       NAMECHAR
                    451:        ;
                    452: 
                    453: NAMECHAR
                    454:        :       BASECHAR
                    455:        |        '"'                                            
                    456:                                        { $$ = MakeString('"'); }
                    457:        ;
                    458: 
                    459: TEXT
                    460:        :       TEXT TEXTCHAR                           
                    461:                                        { $$ = Concat($1,$2,0);
                    462:                                          Free($1); Free($2);           }
                    463:        |       EMPTY
                    464:                                        { $$ = null;            }
                    465:        ;
                    466:                
                    467: TEXTCHAR
                    468:        :       BLANK
                    469:                                        { $$ = MakeString($1); }
                    470:        |       BASECHAR                                                
                    471:        ;
                    472: 
                    473: USERLIST
                    474:        :       USERLIST USERCHAR                               
                    475:                                        { $$ = Concat($1,$2,0);
                    476:                                          Free($1); Free($2);           }
                    477:        |       EMPTY
                    478:                                        { $$ = null;            }
                    479:        ;
                    480:                
                    481: USERCHAR
                    482:        :       BLANK
                    483:                                        { $$ = MakeString($1); }
                    484:        |       BASECHAR                                                
                    485:        |       '"'
                    486:                                        { $$ = MakeString('"'); }
                    487:        ;
                    488: 
                    489: BASECHAR
                    490:        :       DIGIT                                           
                    491:                                        { $$ = MakeString($1); }
                    492:        |       UPPERCHAR                                       
                    493:                                        { $$ = MakeString($1); }
                    494:        |       OTHERCHAR                                       
                    495:                                        { $$ = MakeString($1); }
                    496:        |       '('                                             
                    497:                                        { $$ = MakeString('('); }
                    498:        |       ')'                                             
                    499:                                        { $$ = MakeString(')'); }
                    500:        |        '-'                                            
                    501:                                        { $$ = MakeString('-'); }
                    502:        ;
                    503: 
                    504: SP
                    505:        :       BLANK BLANKLIST
                    506:        ;
                    507: 
                    508: BLANKLIST
                    509:        :       BLANKLIST BLANK
                    510:        |       EMPTY
                    511:        ;
                    512: 
                    513: GARBAGE        
                    514:        :       DIGIT
                    515:        |       UPPERCHAR
                    516:        |       '-' | '(' | ')'
                    517:        ;
                    518: 
                    519: SEMI
                    520:        :       ';' BLANKLIST                                   
                    521:        ;
                    522: 
                    523: 
                    524: EMPTY  
                    525:        :       
                    526:        ;
                    527: %%
                    528: 
                    529: #include "scanner.c"
                    530: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.