output.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/* output.c, output generator for dlg
*
* Output Notes:
*
* DfaStates == number of dfa nodes in automaton (just a #define)
* DfaState == type large enough to index every node in automaton
* <256 unsigned char, <65536 unsigned short, etc.
*
* Thus, the elements in each of the automaton states (st%d) are type DfaState
* and are size appropriately, since they must be able to index the next
* automaton state.
*
* dfa[] == a linear array that points to all the automaton states (st%d)
* (dfa_base[] should be the same, but isn't right now)
*
* accepts[] == Taking a closer look at this one, it probably shouldn't be type
* DfaState because there is no real requirement that the number of
* accepts states is less than the number of dfa state. However, if
* the number of accept states was more than the number of DFA states
* then the lexical specification would be really ambiguous.
*
* Another note. Is that is should be possible to fold accepts[] and
* actions[] together. If this is done, I would suggest get rid of
* accept[] and make actions[] have an entry for each state (st%d) in
* the automaton.
*
* dfa_base[] == starting location for each lexical mode. This should be
* Dfastate type (but isn't right now), since it points to the states
* in the automaton.
*
* dfa_class_no[] == indicates the number of columns each lexical mode has.
*
* b_class_no[] == pointer to the start of the translation array used to
* convert from input character to character class. This could cause
* problems if there are more than 256 classes
*
* shift%d[] == the actual translation arrays that convert the input character
* into the character class. These will have to change if there are
* more than 256 character classes.
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* DLG 1.33
* Will Cohen
* With mods by Terence Parr; AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include <string.h>
#include "dlg.h"
#ifdef MEMCHK
#include "trax.h"
#else
#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif /* __STDC__ */
#endif
#ifdef VBOX
#endif /* VBOX */
static int mode_number[MAX_MODES];
static int cur_mode=0;
int operation_no = 0; /* used to mark nodes so that infinite loops avoided */
/* NOTE: This section is MACHINE DEPENDENT */
#define DIF_SIZE 4
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
#else
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
#endif
/* Added by TJP August 1994 */
/* Take in MyLexer and return MyLexer_h */
static char *
#ifdef __USE_PROTOS
gate_symbol(char *name)
#else
char *name;
#endif
{
static char buf[100];
return buf;
}
/* Added by TJP August 1994 */
static char *
#ifdef __USE_PROTOS
mystrdup(char *s)
#else
mystrdup(s)
char *s;
#endif
{
strcpy(p, s);
return p;
}
#ifdef __USE_PROTOS
void p_class_hdr(void)
#else
void p_class_hdr()
#endif
{
if ( class_stream == NULL ) return;
}
/* MR1 */
/* MR1 16-Apr-97 Split printing of class header up into several parts */
/* MR1 so that #lexprefix <<...>>and #lexmember <<...>> */
/* MR1 can be inserted in the appropriate spots */
/* MR1 */
#ifdef __USE_PROTOS
void p_class_def1(void)
#else
void p_class_def1()
#endif
{
if ( class_stream == NULL ) return;
}
#ifdef __USE_PROTOS
void p_class_def2(void)
#else
void p_class_def2()
#endif
{
int i, m;
if ( class_stream == NULL ) return;
for (i=0; i<cur_mode; i++) {
}
for (i=1; i<=action_no; ++i) {
}
for(m=0; m<(mode_counter-1); ++m){
}
for(i=dfa_basep[m]; i<=dfa_allocated; ++i)
/* fprintf(class_stream, "\tstatic int dfa_base_no[];\n"); */
/* WARNING: should be ANTLRTokenType for action table, but g++ 2.5.6 is hosed */
fprintf(class_stream, "\tstatic ANTLRTokenType (%s::*actions[%d])();\n", ClassName(""), action_no+1);
for(m=0; m<mode_counter; ++m) {
m, CHAR_RANGE);
}
if (comp_level)
else
/* MR1 */
/* MR1 11-APr-97 Kludge to allow inclusion of user-defined code in */
/* MR1 DLGLexer class header */
/* MR1 Deprecated in favor of 133MR1 addition #lexmember <<>> */
/* MR1 */
/* MR1 */ "// 133MR1 Deprecated feature to allow inclusion of ");
/* MR1 */ "user-defined code in DLG class header\n");
/* MR1 */
}
/* generate required header on output */
#ifdef __USE_PROTOS
void p_head(void)
#else
void p_head()
#endif
{
}
#ifdef __USE_PROTOS
void p_includes(void)
#else
void p_includes()
#endif
{
}
/* generate code to tie up any loose ends */
#ifdef __USE_PROTOS
void p_tail(void) /* MR1 */
#else
void p_tail() /* MR1 */
#endif
{
if ( gen_cpp ) {
return;
}
if (comp_level)
else
}
/* output the table of DFA for general use */
#ifdef __USE_PROTOS
void p_tables()
#else
void p_tables()
#endif
{
if ( !gen_cpp ) {
}
if ( gen_cpp ) {
int i;
ClassName(""),
ClassName(""),
for (i=0; i<cur_mode; i++) {
}
}
p_node_table();
p_dfa_table();
p_base_table();
if (comp_level)
if (interactive || gen_cpp )
}
/* figures out the smallest variable type that will hold the transitions
*/
#ifdef __USE_PROTOS
#else
int elements;
#endif
{
int i = 0;
++i;
return typevar[i];
}
#ifdef __USE_PROTOS
void p_node_table(void)
#else
void p_node_table()
#endif
{
register int i;
register int m = 0;
for(m=0; m<(mode_counter-1); ++m){
p_single_node(i,dfa_class_nop[m]);
}
for(i=dfa_basep[m]; i<=dfa_allocated; ++i)
p_single_node(i,dfa_class_nop[m]);
}
#ifdef __USE_PROTOS
void p_single_node(int i,int classes)
#else
void p_single_node(i,classes)
int i,classes;
#endif
{
register int j;
register int trans, items_on_line;
#if 1
/* extra state (classes+1) for invalid characters */
#else
#endif
for(j=0; j<classes; ++j){
/* all of DFA moved down one in array */
if (!(--items_on_line)){
}
}
#if 1
/* put in jump to error state */
#else
#endif
}
#ifdef __USE_PROTOS
void p_dfa_table(void)
#else
void p_dfa_table()
#endif
{
register int i;
for (i=0; i<(dfa_allocated-1); ++i){
}
}
#ifdef __USE_PROTOS
void p_accept_table(void)
#else
void p_accept_table()
#endif
{
register int i = 1;
register int items_on_line = 0;
int true_interactive = TRUE;
/* make sure element for one past (zzerraction) -WEC 12/16/92 */
dfa_allocated+1);
/* don't do anything if no dfa nodes */
if (i>dfa_allocated) goto skip_accepts;
for (;;) {
int accept=0; /* MR14a - Manuel Kessler (mlkessle@cip.physik.uni-wuerzburg.de) */
unsigned int *t, *nfa_i;
unsigned int *q, *regular_expr;
accept_set = empty;
/* NOTE: picks lowest accept because accepts monotonic */
/* with respect to nfa node numbers and set_pdq */
/* returns in that order */
nfa_i++;
}
/* figure out if more than one accept state there */
if (warn_ambig ){
nfa_i++;
}
/* remove error action from consideration */
set_rm(0, accept_set);
while(*regular_expr != nil){
++regular_expr;
}
free(q);
}
}
}
/* free up memory before we "break" below -ATG 4/6/95 */
free(t);
if ((++i)>dfa_allocated)
break;
if ((++items_on_line)>=MAX_ON_LINE){
items_on_line = 0;
}
/*
free(t);
set_free(accept_set);
*/
}
/* make sure element for one past (zzerraction) -WEC 12/16/92 */
}
#ifdef __USE_PROTOS
void p_action_table(void)
#else
void p_action_table()
#endif
{
register int i;
if ( gen_cpp )
else
if ( gen_cpp )
/* fprintf(OUT, "\t(Ptr%sMemberFunc)&%s::erraction,\n", theClassName, theClassName);*/
else
for (i=1; i<action_no; ++i) {
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d,\n", theClassName, theClassName, i);*/
else
}
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d\n", theClassName, theClassName, i);*/
else
}
#ifdef __USE_PROTOS
void p_shift_table(int m) /* MR1 */
#else
void p_shift_table(m) /* MR1 */
int m;
#endif
{
register int i = 0, j;
register int items_on_line = 0;
for (;;) {
/* find which partition character i is in */
for (j=0; j<dfa_class_nop[mode_counter]; ++j){
if (set_el(i,class_sets[j]))
break;
}
if ((++i)>=CHAR_RANGE)
break;
if ((++items_on_line)>=MAX_ON_LINE){
items_on_line = 0;
}
}
}
#ifdef __USE_PROTOS
void p_base_table(void)
#else
void p_base_table()
#endif
{
register int m;
for(m=0; m<(mode_counter-1); ++m)
}
#ifdef __USE_PROTOS
void p_class_table(void) /* MR1 */
#else
void p_class_table() /* MR1 */
#endif
{
#if 0
register int m;
for(m=0; m<(mode_counter-1); ++m)
#endif
}
#ifdef __USE_PROTOS
void p_bshift_table(void) /* MR1 */
#else
void p_bshift_table() /* MR1 */
#endif
{
register int m;
for(m=0; m<(mode_counter-1); ++m)
}
#ifdef __USE_PROTOS
void p_alternative_table(void) /* MR1 */
#else
void p_alternative_table() /* MR1 */
#endif
{
register int i;
if ( gen_cpp )
ClassName("::"),
else
for(i=1; i<=dfa_allocated; ++i)
}
#ifdef __USE_PROTOS
void p_mode_def(char *s,int m) /* MR1 */
#else
void p_mode_def(s,m) /* MR1 */
char *s;
int m;
#endif
{
if ( gen_cpp )
{
mode_number[cur_mode] = m;
cur_mode++;
}
else
}
#ifdef __USE_PROTOS
#else
char *suffix;
#endif
{
static char buf[200];
extern char *class_name;
return buf;
}
#ifdef DEBUG
/* print out a particular nfa node that is pointed to by p */
#ifdef __USE_PROTOS
void p_nfa_node(nfa_node *p)
#else
void p_nfa_node(p)
nfa_node *p;
#endif
{
#ifndef VBOX
register nfa_node *t;
#endif
if (p != NIL_INDEX){
printf("NFA state : %d\naccept state : %d\n",
printf("\n");
}
else
printf("trans[0] => nil\n");
printf("trans[1] => %d on epsilon\n",
else
printf("trans[1] => nil\n");
printf("\n");
}
}
#endif
#ifdef DEBUG
/* code to print out special structures when using a debugger */
#ifdef __USE_PROTOS
# ifdef VBOX
# else
void p_nfa(p)
# endif
#else
nfa_node *p; /* state number also index into array */
#endif
{
/* each node has a marker on it so it only gets printed once */
operation_no++; /* get new number */
s_p_nfa(p);
}
#ifdef __USE_PROTOS
#else
void s_p_nfa(p)
nfa_node *p; /* state number also index into array */
#endif
{
/* so it is only printed once */
p->nfa_set = operation_no;
p_nfa_node(p);
}
}
#ifdef __USE_PROTOS
void p_dfa_node(dfa_node *p)
#else
void p_dfa_node(p)
dfa_node *p;
#endif
{
int i;
if (p != NIL_INDEX){
if (p->done)
printf("done\n");
else
printf("undone\n");
printf("from nfa states : ");
p_set(p->nfa_states);
printf("\n");
/* NOTE: trans arcs stored as ints rather than pointer*/
for (i=0; i<class_no; i++){
}
printf("\n\n");
}
}
#ifdef __USE_PROTOS
void p_dfa(void)
#else
void p_dfa()
#endif
{
/* prints out all the dfa nodes actually allocated */
int i;
for (i = 1; i<=dfa_allocated; i++)
#ifdef VBOX
p_dfa_node(DFA(i));
#else
p_dfa_node(NFA(i));
#endif
}
/* print out numbers in the set label */
#ifdef __USE_PROTOS
#else
#endif
{
unsigned *t, *e;
printf("epsilon\n");
}else{
while(*e != nil){
e++;
}
printf("\n");
free(t);
}
}
#endif