int PGCreateTables::CreateTables () { char* m; int Bi = 0; int Ti = 0, Tj = 0; int Ni = 0, Nj = 0; int Ri = 0; if (optn[PG_ANALYZEONLY]) return 0; m = " "; total0 = total1 = total2 = 0; if (optn [PG_MINIMIZE]) { if (optn[PG_VERBOSE]) prt_log (" rows cols matrix list vect total\n"); else prt_logonly (" rows cols matrix list vect total\n"); MIN_B (&Bi); MIN_T (&Ti, &Tj); MIN_N (&Ni, &Nj); MIN_R (&Ri); m = "*"; if (optn[PG_VERBOSE]) prt_log ("\n"); else prt_logonly ("\n"); } if (optn[PG_VERBOSE]) prt_log (" rows cols matrix list vect total\n"); else prt_logonly (" rows cols matrix list vect total\n"); BLD_B (Bi, m); BLD_T (Ti, Tj, m); BLD_N (Ni, Nj, m); BLD_R (Ri, m); char n1[16] = " "; char n2[16] = " "; char n3[16] = " "; number (total1, n1); number (total2, n2); number (total1+total2, n3); if (optn[PG_VERBOSE]) prt_log ("Total %9s +%9s =%9s\n\n", n1, n2, n3); else prt_logonly ("Total %9s +%9s =%9s\n\n", n1, n2, n3); FREE (tt_symb, n_ttran); FREE (tt_action, n_ttran); FREE (tt_start, n_states+1); FREE (ntt_start, n_states+1); FREE (ntt_symb, n_nttran); FREE (ntt_action, n_nttran); FREE (la_start, n_states+1); FREE (la_red, max_lookah); FREE (la_symb, max_lookah); // Reduce production length by 1, so no "-1" adjustment is required in skl file. for (int p = 0; p < N_prods; p++) prod_len[p]--; return (1); }
int PGCreateTables::BLD_N (int opt1, int opt2, char *mark) /* Build Nonterminal Matrix. */ { int **Matrix, p, r, multiplier, *n_col, org_size; if (optn[PG_VERBOSE]) prt_log ("N matrix"); else prt_logonly ("N matrix"); ALLOC (N_row, ntt_states); ALLOC (n_col, N_heads); ALLOC (Matrix, ntt_states); N_rows = MRG_ROWZ_N (Matrix, N_heads, N_row, ntt_states, opt1); if (optn[PG_VERBOSE]) prt_log (" %6d ", N_rows); else prt_logonly (" %6d ", N_rows); N_cols = MRG_COLZ (n_col, N_heads, N_rows, Matrix, opt2); org_size = N_rows * N_cols; if (N_prods > 32767 || ntt_states > 32767) multiplier = 4; // int else if (N_prods > 127 || ntt_states > 127) multiplier = 2; // short else multiplier = 1; // char N_total = multiplier*org_size; char num[12] = " "; number (N_total, num); // Gives 9 digits. if (optn[PG_VERBOSE]) prt_log ("x%5ld x %d =%10s", N_cols, multiplier, num); else prt_logonly ("x%5ld x %d =%10s", N_cols, multiplier, num); total0 += N_total; ALLOC (N_matrix, org_size); FASTINI (0, N_matrix, org_size); N_size = DISP_ZEQ (Matrix, N_matrix, N_row, N_rows, N_cols, ntt_states); for (r = 0; r < N_rows; r++) FREE (Matrix [r], N_heads); FREE (Matrix, ntt_states); REALLOC (N_matrix, org_size, N_size); ALLOC (N_col, N_prods); for (p = 0; p < N_prods; p++) { N_col[p] = n_col[head_sym[p]]; } FREE (n_col, N_heads); int vectors = 0; vectors += get_type (N_row, ntt_states) * ntt_states; // row vector vectors += get_type (N_col, N_prods) * N_prods; // column vector OUT_TOT (multiplier*N_size, vectors, mark); return (multiplier*N_size + vectors); }
int PGCreateTables::BLD_T (int opt1, int opt2, char *mark) /* Build Terminal Matrix. */ { int **Matrix, r, multiplier, org_size; if (optn[PG_VERBOSE]) prt_log ("T matrix"); else prt_logonly ("T matrix"); ALLOC (T_row, tt_states); ALLOC (T_col, N_terms); ALLOC (Matrix, tt_states); if (optn[PG_BOOLMATRIX] == 0) T_rows = MRG_ROWE2T (Matrix, N_terms, T_row, tt_states, opt1); else T_rows = MRG_ROWZ_T (Matrix, N_terms, T_row, tt_states, opt1); if (optn[PG_VERBOSE]) prt_log (" %6d ", T_rows); else prt_logonly (" %6d ", T_rows); if (optn[PG_BOOLMATRIX] == 0) T_cols = MRG_COLE2 (T_col, N_terms, T_rows, Matrix); else T_cols = MRG_COLZ (T_col, N_terms, T_rows, Matrix, opt2); org_size = T_rows * T_cols; if (N_prods > 32767 || tt_states > 32767) multiplier = 4; // int else if (N_prods > 127 || tt_states > 127) multiplier = 2; // short else multiplier = 1; // char T_total = multiplier*org_size; char num[12] = " "; number (T_total, num); // Gives 9 digits. if (optn[PG_VERBOSE]) prt_log ("x%5ld x %d =%10s", T_cols, multiplier, num); else prt_logonly ("x%5ld x %d =%10s", T_cols, multiplier, num); total0 += T_total; ALLOC (T_matrix, org_size); FASTINI (0, T_matrix, org_size); if (optn[PG_BOOLMATRIX] == 0) T_size = DISP_EQ2 (Matrix, T_matrix, T_row, T_rows, T_cols, tt_states, opt1); else T_size = DISP_ZEQ (Matrix, T_matrix, T_row, T_rows, T_cols, tt_states); for (r = 0; r < T_rows; r++) FREE (Matrix [r], N_terms); FREE (Matrix, tt_states); REALLOC (T_matrix, org_size, T_size); int vectors = 0; vectors += get_type (T_row, tt_states) * tt_states; // row vector vectors += get_type (T_col, N_terms) * N_terms; // column vector OUT_TOT (multiplier*T_size, vectors, mark); return (multiplier*T_size + vectors); }
int PGCreateTables::BLD_R (int opt1, char *mark) /* Build Reduction Matrix. */ { int **Matrix, s, r, multiplier, org_size; if (optn[PG_VERBOSE]) prt_log ("R matrix"); else prt_logonly ("R matrix"); ALLOC (R_row, n_states); ALLOC (R_col, N_terms); ALLOC (Matrix, n_states+1); R_rows = MRG_ROWE2R (Matrix, N_terms, R_row, n_states); if (optn[PG_VERBOSE]) prt_log (" %6d ", R_rows); else prt_logonly (" %6d ", R_rows); R_cols = MRG_COLE2 (R_col, N_terms, R_rows, Matrix); org_size = R_rows * R_cols; ALLOC (R_matrix, org_size); FASTINI (0, R_matrix, org_size); R_size = DISP_EQ2 (Matrix, R_matrix, R_row, R_rows, R_cols, n_states, opt1); for (r = 0; r < R_rows; r++) FREE (Matrix [r], N_terms); FREE (Matrix, n_states+1); REALLOC (R_matrix, org_size, R_size); if (optn[PG_DEFAULTRED]) { for (s = 0; s < n_states; s++) { if (D_red[s] > 0) R_row[s] = D_red[s]; else R_row[s] = -R_row[s]; } } multiplier = get_type (R_matrix, R_size); char num[12] = " "; number (multiplier*R_size, num); if (optn[PG_VERBOSE]) prt_log ("x%5ld x %d =%10s", R_cols, multiplier, num); else prt_logonly ("x%5ld x %d =%10s", R_cols, multiplier, num); total0 += multiplier*R_size; int vectors = 0; vectors += get_type (R_row, n_states) * n_states; // row vector vectors += get_type (R_col, N_terms) * N_terms; // column vector OUT_TOT (multiplier*R_size, vectors, mark); return (multiplier*R_size + vectors); }
int PGCreateTables::BLD_B (int opt1, char *mark) // Build Boolean Matrix. { char** Matrix; int r, org_size; if (optn[PG_BOOLMATRIX] == 0) return 0; if (optn[PG_VERBOSE]) prt_log ("B matrix"); else prt_logonly ("B matrix"); ALLOC (B_row, n_states); ALLOC (B_col, N_terms); ALLOC (Matrix, n_states+1); B_rows = MRG_ROWE1B (Matrix, N_terms, B_row, n_states); if (optn[PG_VERBOSE]) prt_log (" %6d ", B_rows); else prt_logonly (" %6d ", B_rows); B_cols = MRG_COLE1B (B_col, N_terms, B_rows, Matrix); B_size = B_rows * B_cols; total0 += B_size; char num[12] = " "; number (B_size, num); // Gives 9 digits. if (optn[PG_VERBOSE]) prt_log ("x%5ld x 1 =%10s", B_cols, num); else prt_logonly ("x%5ld x 1 =%10s", B_cols, num); org_size = (B_rows)*((B_cols+7)/8*8); ALLOC (B_matrix, org_size); memset (B_matrix, 0, org_size); B_size = DISP_EQ1B (Matrix, B_matrix, B_row, B_rows, B_cols, opt1); for (r = 0; r < B_rows; r++) FREE (Matrix[r], N_terms); FREE (Matrix, n_states+1); int vectors = 0; if (optn[PG_BOOLMATRIX] > 1) { vectors += N_terms; B_size = MAKE_PACKED (B_matrix, B_size); } REALLOC (B_matrix, org_size, B_size); vectors += get_type (B_row, n_states) * n_states; // row vector vectors += get_type (B_col, N_terms) * N_terms; // column vector OUT_TOT (B_size, vectors, mark); return (B_size + vectors); }
int LG::Terminate (int rc) { double dsec; int min, sec, thou, i; char num[14] = " "; if (n_states > org_states) org_states = n_states; if (n_prods > max_n_prods) max_n_prods = n_prods; // brute force fix. else max_n_prods++; // brute force fix again. if (n_prods < 0) n_prods = 0; // In case of early syntax error. if (optn[LG_VERBOSE] > 1) { optncount[MAX_SYM] = n_symbs; optncount[MAX_PRO] = n_prods; optncount[MAX_TAIL] = n_tails; optncount[MAX_EBNF] = amt_space; optncount[MAX_STA] = org_states; optncount[MAX_FIN] = n_finals; optncount[MAX_KER] = n_kernels; optncount[MAX_NTT] = n_nonttran; optncount[MAX_TT] = n_termtran; optncount[MAX_TTA] = n_ttas; optncount[MAX_LB] = n_lookbacks; optncount[MAX_LA] = n_lookah; optncount[MAX_INC] = n_includes; optncount[MAX_CH] = max_child_usage; optncount[MAX_ND] = 0; for (i = 0; *MAOption[i].name != 0; i++) { prt_num (MAOption[i].desc, optncount[MAOption[i].numb], MAOption[i].name, optn[MAOption[i].numb]); } prt_logonly ("\n"); } char* es = "s"; char* ws = "s"; if (n_errors == 1) es = ""; if (n_warnings == 1) ws = ""; time2 = clock (); dsec = (double)(time2-time1) / CLOCKS_PER_SEC; min = dsec/60; sec = dsec-min*60; thou = (dsec-min*60-sec)*1000; int x = memory_max/1024/1024; int y = memory_max/1024 - 1024*x; prt_log ("%1d min %1d.%03d sec, %d.%03d MB, %d warning%s, %d error%s.\n\n", min, sec, thou, x, y, n_warnings, ws, n_errors, es); close_con (); close_grm (); close_sta (); close_lst (); if (n_errors > 0) quit (n_errors); return 0; }
int PG::Terminate (int rc) { double dsec; int i, min, sec, thou; inputt (); if (optn[PG_VERBOSE] > 1) { optncount[MAX_SYM] = Symtab::n_symbols; optncount[MAX_PRO] = N_prods; optncount[MAX_TAIL] = N_tails; optncount[MAX_EBNF] = 0; optncount[MAX_STA] = org_states; optncount[MAX_FIN] = n_finals; optncount[MAX_KER] = n_kernels; optncount[MAX_NTT] = n_nttran; optncount[MAX_TT] = n_ttran; optncount[MAX_TTA] = n_ttas; optncount[MAX_LB] = n_lookbacks; optncount[MAX_LA] = n_lookah; optncount[MAX_INC] = n_includes; optncount[MAX_CH] = max_child_usage; optncount[MAX_ND] = n_nditems; for (i = 0; *MAOption[i].name != 0; i++) { prt_num (MAOption[i].desc, optncount[MAOption[i].numb], MAOption[i].name, optn[MAOption[i].numb]); } prt_logonly ("\n"); } PGParser::terminate (); char* es = "s"; char* ws = "s"; char* cs = "s"; if (n_errors == 1) es = ""; if (n_warnings == 1) ws = ""; if (c_states == 1) cs = ""; time2 = clock (); dsec = (double)(time2-time1) / CLOCKS_PER_SEC; min = dsec/60; sec = dsec-min*60; thou = (dsec-min*60-sec)*1000; int x = memory_max/1024/1024; int y = memory_max/1024 - 1024*x; prt_log ("%1d min %1d.%03d sec, %d.%03d MB, %d warning%s, %d error%s.\n\n", min, sec, thou, x, y, n_warnings, ws, n_errors, es); close_con (); close_grm (); // close_log (); close_sta (); close_lst (); if (n_errors > 0) quit (n_errors); return 0; }
void PGCreateTables::OUT_TOT (int size, int vectors, char *mark) { char n1[12] = " "; char n2[12] = " "; char n3[12] = " "; number (size, n1); number (vectors, n2); number (size+vectors, n3); if (optn[PG_VERBOSE]) prt_log (" ->%9s +%9s =%9s %s\n", n1, n2, n3, mark); else prt_logonly (" ->%9s +%9s =%9s %s\n", n1, n2, n3, mark); total1 += size; total2 += vectors; }