/*
   File: rtscode.h
   Interface to code generated by code.k3

   Copyright 2005 Radboud University of Nijmegen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Library General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   CVS ID: "$Id: rtscode.h,v 1.42 2006/09/27 16:01:15 marcs Exp $"
*/

#ifndef rtscode_h
#define rtscode_h

#ifdef  __cplusplus
extern "C" {
#endif

/*------------------------------------------------------
// BITS_PER_WORD is the number of bits per machine word,
// as assumed by the agfl compiler.
//----------------------------------------------------*/
#define BITS_PER_WORD	32

/* Code */
typedef void (*func)(void);

/* Constants */
extern long segment_mode;
extern long generate_option;

extern long nr_lexicon_nonterminals;
extern long nr_terminals;
extern long nr_match_regexps;
extern long nr_skip_regexps;
extern long nr_memos;
extern long nr_choices;
extern long nr_positions;
extern long nr_syntax_nonterminals;
extern long eos_terminal;
extern long rel_penallowance;

extern char agfl_version[];
extern long gra_version;

#ifdef PROFILING
extern char fingerprint[];
#endif /* PROFILING */

extern unsigned char *alphabet_file;
extern unsigned char *invisible_chars;
extern unsigned char *word_terminator_chars;

/* Options */
#define allow_multiple_single_token_parts 0
/* TODO should become:
extern int allow_multiple_single_token_parts;
*/
extern int left_recursion;
extern int use_lexicon;
extern int neg_memo_option;
extern int pos_memo_option;
extern int directors_option;
extern int log_option;
extern int counters_option;
extern int trace_option;
extern int profile_option;
#define WORD_LEXING	'w'
#define PREFIX_LEXING	'p'
#define TRELLIS_LEXING	't'
extern int lexing_method; /* for now defined in rtsopt.c, see also option -m */
#define G_OUT_FORMAT_STANDARD	   's'
#define G_OUT_FORMAT_TRELLIS_INPUT 't'
extern int lex_out_format; /* for now defined in rtsopt.c, see also option -m */
extern int transduce_option;
extern int echo_unparsed_option;

extern int verbose;
extern int no_output;
extern int graph_option;
extern int label_bracket;

extern int list_option;
extern int client_option;

#ifdef PROFILING
extern int prof_count;
extern int profiles;
extern int reset_profile;
extern int update_profile;
extern int new_profile;
#endif /* PROFILING */

/*
 * XXX
 * FIXME
 * ALERT
 *
 * TESTING OPTION:
 */
extern int text_tracing_option;

/* Tables */
extern void* match_comp_regexps[];
extern void* skip_comp_regexps[];

/*---------------------------------------------------------------------
// nont_domains[] is an array of pointers to nonterminal domains,
// indexed by nonterminal numbers. Each domain pointer points to
// an array of domains. Each domain is either INT_TYPE, TEXT_TYPE
// or an affix number >= 0 in case of a set domain.
// affix_domains[] is an array of affix domains, indexed by affix
// numbers, containing a set value, or a respesentation of TEXT or INT.
//
// NOTE: if TOP_{INT,TEXT} get changed, changes to lexgen are needed
// too.
//-------------------------------------------------------------------*/
#define INT_TYPE	-1
#define TEXT_TYPE	-2
#define TOP_INT		0x80000000
#define TOP_TEXT	NULL

extern long affix_domains[];
extern long *affix_weights[];
extern long *nont_domains[];

extern char *affix_names[];
extern char *term_names[];
extern char *nonterm_names[];
extern char *alternatives_profile_table[];

extern char *match_regexp_names[];
extern char *skip_regexp_names[];

extern unsigned long *term_memo_dir[];
extern unsigned long *skip_memo_dir[];
extern unsigned long *match_memo_dir[];
extern unsigned long *lex_memo_dir[];
extern unsigned long memo_enable_table[];

#ifdef PROFILING
extern struct
{
  char *id;
  int arity;
  int altno;
} prof_table[];
#endif /* PROFILING */

void print_set_affix (unsigned long val, long domain, int in_tranduction);
void print_text_affix (char* val, int in_tranduction);
void print_integer_affix (int val, int in_tranduction);
void current_parse_add_match_regexp (long termnr);
void current_parse_add_skip_regexp (long termnr);
long affix_get_top (unsigned nont_nr, unsigned affix_nr);

extern long get_nr_choices();

#ifdef  __cplusplus
}
#endif
#endif /* rtscode_h */
