Changeset adc6383 in git


Ignore:
Timestamp:
Mar 22, 2000, 11:23:58 AM (24 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '648d28f488f6ff08f5607ff229b9ad9e4a5b93c2')
Children:
607cfdb23678e0c010fe9a6d3ccf2ee5f3d62736
Parents:
0146cecb1a3707a7b3ebc3149e2710be6a42f53d
Message:
	* grammar.y,misc.cc,modgen.h:
	  check for commands within procedure-declaration
	* proc.cc: Added some testoutput for singular-commands
	* scanner.l: some work on the comment part recognition


git-svn-id: file:///usr/local/Singular/svn/trunk@4214 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/modgen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/grammar.y

    r0146ce radc6383  
    11/*
    2  * $Id: grammar.y,v 1.7 2000-02-18 13:33:47 krueger Exp $
     2 * $Id: grammar.y,v 1.8 2000-03-22 10:23:56 krueger Exp $
    33 */
    44
     
    7676
    7777%type <i>    '='
     78%type <name> identifier
    7879
    7980%nonassoc '='
     
    406407          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    407408         
    408           if( (vt=checkcmd($2, &write_cmd, 0)) ) {
    409             write_cmd(&module_def, &procedure_decl);
    410           }
    411           else {
    412             myyyerror("Line %d: Unknown command '%s' in section %d\n",
    413                       yylineno, $2, sectnum);
     409          switch(vt=checkcmd($2, &write_cmd, CMDT_SINGLE, 0)) {
     410              case CMD_NONE:
     411                myyyerror("Line %d: Unknown command '%s' in section %d\n",
     412                          yylineno, $2, sectnum);
     413                break;
     414              case CMD_BADSYNTAX:
     415                myyyerror("Line %d: bad syntax of command '%s' in section %d\n",
     416                          yylineno, $2, sectnum);
     417                break;
     418              default:
     419                write_cmd(&module_def, &procedure_decl);
    414420          }
    415421          free($2);
     
    420426          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    421427         
    422           if( (vt=checkcmd($2, &write_cmd, 1)) ) {
    423             write_cmd(&module_def, &procedure_decl, procedure_decl.procname);
    424           }
    425           else {
    426             myyyerror("Line %d: Unknown command '%s' in section %d\n",
    427                       yylineno, $2, sectnum);
     428          switch(vt=checkcmd($2, &write_cmd, CMDT_0, 1)) {
     429              case CMD_NONE:
     430                myyyerror("Line %d: Unknown command '%s' in section %d\n",
     431                          yylineno, $2, sectnum);
     432                break;
     433              case CMD_BADSYNTAX:
     434                myyyerror("Line %d: bad syntax of command '%s' in section %d\n",
     435                          yylineno, $2, sectnum);
     436                break;
     437              default:
     438                write_cmd(&module_def, &procedure_decl,
     439                          procedure_decl.procname);
    428440          }
    429441          free($2);
     
    434446          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    435447         
    436           if( (vt=checkcmd($2, &write_cmd, 1)) ) {
    437             write_cmd(&module_def, &procedure_decl, $4);
    438           }
    439           else {
    440             myyyerror("Line %d: Unknown command '%s' in section %d\n",
    441                       yylineno, $2, sectnum);
     448          switch(vt=checkcmd($2, &write_cmd, CMDT_ANY, 1)) {
     449              case CMD_NONE:
     450                myyyerror("Line %d: Unknown command '%s' in section %d\n",
     451                          yylineno, $2, sectnum);
     452                break;
     453              case CMD_BADSYNTAX:
     454                myyyerror("Line %d: bad syntax of command '%s' in section %d\n",
     455                          yylineno, $2, sectnum);
     456                break;
     457              default:
     458                write_cmd(&module_def, &procedure_decl, $4);
    442459          }
    443460          free($2); free($4);
     
    448465          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    449466         
    450           if( (vt=checkcmd($2, &write_cmd, 1)) ) {
    451             //write_cmd(&module_def, &procedure_decl, $4);
    452           }
    453           else {
    454             myyyerror("Line %d: Unknown command '%s' in section %d\n",
    455                       yylineno, $2, sectnum);
     467          switch(vt=checkcmd($2, &write_cmd, CMDT_ANY, 1)) {
     468              case CMD_NONE:
     469                myyyerror("Line %d: Unknown command '%s' in section %d\n",
     470                          yylineno, $2, sectnum);
     471                break;
     472              case CMD_BADSYNTAX:
     473                myyyerror("Line %d: bad syntax of command '%s' in section %d\n",
     474                          yylineno, $2, sectnum);
     475                break;
     476              default:
     477                write_cmd(&module_def, &procedure_decl, $4);
    456478          }
    457479          free($2);
     
    460482identifier: NAME
    461483        {
    462           printf("### Name %s\n", $1);
     484          printf("### ID ### Name %s\n", $1);
     485          $$ = $1;
    463486        }
    464487        | identifier MCOLONCOLON NAME
    465488        {
    466           printf("### Name %s\n", $3);
     489          int len = strlen($$) + strlen($3) + 2;
     490          printf("### ID ### Name %s\n", $3);
     491          $$ = (char *)realloc($$, len);
     492          strcat($$, "::");
     493          strcat($$, $3);
    467494        };
    468495
  • modules/modgen/misc.cc

    r0146ce radc6383  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.6 2000-02-14 21:44:04 krueger Exp $ */
     4/* $Id: misc.cc,v 1.7 2000-03-22 10:23:57 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    205205  void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    206206  cmd_token id;
     207  cmd_type  type;
    207208  int args;
    208209} valid_cmds[] = {
    209   { "declaration",  write_function_declaration, CMD_DECL,   0 },
    210   { "typecheck",    write_function_typecheck,   CMD_CHECK,  0 },
    211   { "return",       write_function_return,      CMD_RETURN, 1 },
    212   { "singularcmd",  0,      CMD_SINGULAR, 1 },
     210  { "declaration",  write_function_declaration, CMD_DECL,   CMDT_SINGLE, 0 },
     211  { "typecheck",    write_function_typecheck,   CMD_CHECK,  CMDT_SINGLE, 0 },
     212  { "return",       write_function_return,      CMD_RETURN, CMDT_SINGLE, 1 },
     213  { "return",       write_function_return,      CMD_RETURN, CMDT_0,     1 },
     214  { "return",       write_function_return,      CMD_RETURN, CMDT_ANY,   1 },
     215  { "singularcmd",  write_function_singularcmd, CMD_SINGULAR, CMDT_ANY, 1 },
    213216  { NULL,           0, CMD_NONE, 0 }
    214217};
     
    217220  char *cmdname,
    218221  void (**write_cmd)(moddefv module, procdefv pi, void *arg),
     222  cmd_type  type,
    219223  int args
    220224  )
    221225{
    222226  int i;
     227  cmd_token rc = CMD_NONE;
     228 
    223229  for(i=0; valid_cmds[i].name!=NULL; i++)
    224230    if(strcmp(valid_cmds[i].name, cmdname)==0) {
    225       *write_cmd = valid_cmds[i].write_cmd;
    226       return valid_cmds[i].id;
    227     }
    228   return CMD_NONE;
     231      rc = CMD_BADSYNTAX;
     232      if(valid_cmds[i].type == type) {
     233        *write_cmd = valid_cmds[i].write_cmd;
     234        return valid_cmds[i].id;
     235      }
     236    }
     237  return rc;
    229238}
    230239 
  • modules/modgen/modgen.h

    r0146ce radc6383  
    11/*
    2  *  $Id: modgen.h,v 1.7 2000-02-18 13:33:48 krueger Exp $
     2 *  $Id: modgen.h,v 1.8 2000-03-22 10:23:57 krueger Exp $
    33 *
    44 */
     
    9999} var_type;
    100100
    101 typedef enum { CMD_NONE, CMD_DECL, CMD_CHECK, CMD_RETURN,
     101typedef enum { CMD_NONE, CMD_BADSYNTAX, CMD_DECL, CMD_CHECK, CMD_RETURN,
    102102               CMD_SINGULAR
    103103} cmd_token;
     104
     105typedef enum { CMDT_SINGLE, CMDT_0, CMDT_ANY
     106} cmd_type;
     107
    104108
    105109typedef enum { VAR_NONE, VAR_MODULE, VAR_HELP, VAR_INFO, VAR_VERSION,
     
    161165extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL);
    162166extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
     167extern void write_function_singularcmd(moddefv module, procdefv pi, void *arg = NULL);
    163168extern void write_function_errorhandling(moddefv module, procdefv pi);
    164169extern void write_help(moddefv module, procdefv pi);
     
    174179  char *cmdname,
    175180  void(**write_cmd)(moddefv module, procdefv pi, void *arg),
     181  cmd_type  type,
    176182  int args);
    177183extern var_token checkvar(
  • modules/modgen/proc.cc

    r0146ce radc6383  
    11/*
    2  * $Id: proc.cc,v 1.7 2000-02-18 13:33:48 krueger Exp $
     2 * $Id: proc.cc,v 1.8 2000-03-22 10:23:57 krueger Exp $
    33 */
    44
     
    185185}
    186186
     187void write_function_singularcmd(
     188  moddefv module,
     189  procdefv pi,
     190  void *arg
     191)
     192{
     193  int i;
     194 
     195  printf("\nWriting return-block\n");
     196  fprintf(module->fmtfp, "/* code for running singular commands */\n");
     197  fprintf(module->fmtfp, "/*\n");
     198  fprintf(module->fmtfp, " *\n");
     199  fprintf(module->fmtfp, " * get idhdl for '%s'\n", arg);
     200  fprintf(module->fmtfp, " * building leftv of arguments\n");
     201  fprintf(module->fmtfp, " * sleftv cmdret = iiMake_proc(cmd, ???, sl)\n");
     202  fprintf(module->fmtfp, " *\n");
     203  fprintf(module->fmtfp, "### SINGULAR command: '%s'\n", arg);
     204  fprintf(module->fmtfp, "*/\n");
     205}
    187206
    188207/*========================================================================*/
     
    352371    }
    353372}
     373
     374/*========================================================================*/
    354375
    355376/*========================================================================*/
  • modules/modgen/scanner.l

    r0146ce radc6383  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.7 2000-02-18 13:33:49 krueger Exp $ */
     5/* $Id: scanner.l,v 1.8 2000-03-22 10:23:58 krueger Exp $ */
    66#include <stdio.h>
    77#include <string.h>
     
    145145
    146146<INITIAL>{
    147         ^{WS}        push_state(YYSTATE, CODEBLOCK, "CODEBLOCK");
    148         ^"/*"       ACTION_ECHO; push_state(YYSTATE, COMMENT, "COMMENT");
    149         ^"//".*{NL}  ++yylineno; ACTION_ECHO;
     147        ^{WS}      push_state(YYSTATE, CODEBLOCK, "CODEBLOCK");
     148        ^"/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
     149        "//".*{NL} ++yylineno; ACTION_ECHO;
    150150        {BOOL}  { if(yyleng == 1) sscanf(yytext, "%d", &lvalp->i);
    151151                  else {
     
    232232<COMMENT>{
    233233        "*/"            ACTION_ECHO; pop_state(); yymore();
    234         "*"             ACTION_ECHO; yymore();
     234        "*"           yymore();
    235235        {NL}          { yylineno++; yymore(); }
    236236        .             { yymore(); }
     
    251251        {WS}    /* ignore */
    252252        ;       /* ignore */
    253         "/*"       ACTION_ECHO; push_state(YYSTATE, COMMENT, "COMMENT");
     253        "/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
    254254        "//".*{NL}  ++yylineno; ACTION_ECHO;
    255255        proc+{WS} {
     
    322322                   return '{';
    323323                 }
    324          "/*"       ACTION_ECHO; push_state(YYSTATE, COMMENT, "COMMENT");
     324         "/*"       push_state(YYSTATE, COMMENT, "COMMENT");yymore();
    325325         "//".*{NL}  ++yylineno; ACTION_ECHO;
    326326         "\""    { do_return++; push_state(YYSTATE, STRING, "string"); /*yymore();*/}
     
    490490  switch(sectnum) {
    491491    case 1:
    492       printf("1>%s", new_text);
     492      printf("1>%s<#\n", new_text);
    493493      break;
    494494    case 2:
    495       printf("2>%s", new_text);
     495      printf("2>%s<#\n", new_text);
    496496      break;
    497497    case 3:
    498       printf("3>%s", new_text);
     498      printf("3>%s<#\n", new_text);
    499499      break;
    500500  }
Note: See TracChangeset for help on using the changeset viewer.