=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/parse.c,v retrieving revision 1.11 retrieving revision 1.15 diff -u -p -r1.11 -r1.15 --- OpenXM/src/ox_toolkit/parse.c 2003/03/23 20:17:35 1.11 +++ OpenXM/src/ox_toolkit/parse.c 2004/12/01 17:32:26 1.15 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/parse.c,v 1.10 2003/02/03 23:13:23 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/parse.c,v 1.14 2003/06/02 10:25:57 ohara Exp $ */ /* This module is a parser for OX/CMO expressions. @@ -52,9 +52,7 @@ static void parse_error(char *s); static void parse_right_parenthesis(); static void parse_left_parenthesis(); static void parse_comma(); -#if defined(WITH_GMP) static mpz_ptr parse_mpz_integer(); -#endif /* WITH_GMP */ static int parse_integer(); static char *parse_string(); static cmo *parse_cmo_null(); @@ -63,9 +61,7 @@ static cmo *parse_cmo_string(); static cmo *parse_cmo_mathcap(); static cmo *parse_cmo_list(); static cmo *parse_cmo_monomial32(); -#if defined(WITH_GMP) static cmo *parse_cmo_zz(); -#endif /* WITH_GMP */ static cmo *parse_cmo_zero(); static cmo *parse_cmo_dms_generic(); static cmo *parse_cmo_ring_by_name(); @@ -222,12 +218,10 @@ static cmo *parse_cmo() token = lex(); m = parse_cmo_monomial32(); break; -#if defined(WITH_GMP) case TOKEN(CMO_ZZ): token = lex(); m = parse_cmo_zz(); break; -#endif /* WITH_GMP */ case TOKEN(CMO_ZERO): token = lex(); m = parse_cmo_zero(); @@ -282,22 +276,18 @@ static void parse_comma() token = lex(); } -#if defined(WITH_GMP) static mpz_ptr new_mpz_set_str(char *s) { - mpz_ptr z = malloc(sizeof(mpz_t)); + mpz_ptr z = MALLOC(sizeof(mpz_t)); mpz_init_set_str(z, s, 10); return z; } static mpz_ptr my_mpz_neg(mpz_ptr src) { - mpz_ptr z = malloc(sizeof(mpz_t)); + mpz_ptr z = MALLOC(sizeof(mpz_t)); mpz_init(z); mpz_neg(z, src); -#ifdef DEBUG - free(src); -#endif return z; } @@ -320,20 +310,31 @@ static mpz_ptr parse_mpz_integer() if (sign == -1) { val = my_mpz_neg(val); } -#ifdef DEBUG - free(yylval.sym); -#endif token = lex(); return val; } -#endif /* WITH_GMP */ static int parse_integer() { -#if defined(WITH_GMP) +#if 0 return mpz_get_si(parse_mpz_integer()); #else - abort(); /* not implemented */ + int sign = 1; + int val; + + if (token == '+') { + token = lex(); + }else if (token == '-') { + sign = -1; + token = lex(); + } + + if (token != T_DIGIT) { + parse_error("no integer."); + } + val = sign*atoi(yylval.sym); + token = lex(); + return val; #endif } @@ -456,7 +457,6 @@ static cmo *parse_cmo_monomial32() return (cmo *)m; } -#if defined(WITH_GMP) /* the following function rewrite internal data of mpz/cmo_zz. */ static cmo *parse_cmo_zz() { @@ -485,7 +485,6 @@ static cmo *parse_cmo_zz() parse_right_parenthesis(); return (cmo *)m; } -#endif /* WITH_GMP */ static cmo *parse_cmo_zero() { @@ -604,14 +603,11 @@ static void init_lex(char *s) #define SIZE_BUFFER 8192 static char buffer[SIZE_BUFFER]; -static char *mkstr(char *src) +static char *new_string(char *s) { - int len; - char *s; - len = strlen(src); - s = malloc(len+1); - strcpy(s, src); - return s; + char *t = MALLOC(strlen(s)+1); + strcpy(t, s); + return t; } /* no measure for buffer overflow */ @@ -625,12 +621,12 @@ static char *lex_digit() buff[i] = c; }else { buff[i] = '\0'; - return mkstr(buff); + return new_string(buff); } c = mygetc(); } buff[SIZE_BUFFER-1] = '\0'; - return mkstr(buff); + return new_string(buff); } #define MK_KEY_CMO(x) { #x , x , TOKEN(x) , IS_CMO } @@ -722,7 +718,7 @@ static char *lex_quoted_string() if(c == '"') { c = mygetc(); buffer[i]='\0'; - return mkstr(buffer); + return new_string(buffer); }else if (c == '\\') { c0 = c; c = mygetc(); @@ -789,6 +785,7 @@ static int lex() yylval.sym = lex_quoted_string(); return T_STRING; default: + ; } if (isalpha(c)) {