⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sor.c

📁 SRI international 发布的OAA框架软件
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
 * A n t l r  T r a n s l a t i o n  H e a d e r
 *
 * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
 * Purdue University Electrical Engineering
 * With AHPCRC, University of Minnesota
 * ANTLR Version 1.33MR33
 *
 *   ..\bin\antlr -gh -k 2 -gt sor.g
 *
 */

#define ANTLR_VERSION	13333
#include "pcctscfg.h"
#include "pccts_stdio.h"

/*  23-Sep-97   thm     Accomodate user who needs to redefine ZZLEXBUFSIZE  */

#ifndef ZZLEXBUFSIZE
#define ZZLEXBUFSIZE	8000
#endif
#include "pcctscfg.h"    /* MR20 G. Hobbelt __USE_PROTOS #define */
#include "charbuf.h"
#include "hash.h"
#include "set.h"
#include "sor.h"
#define AST_FIELDS	\
int token; char text[MaxAtom+1], label[MaxRuleName+1]; \
char *action;		/* if action node, here is ptr to it */ \
char in,out; \
char init_action;	/* set if Action and 1st action of alt */ \
int file; int line; /* set for BLOCK, ALT, nonterm nodes */ \
int upper_range;	/* only if T1..T2 found */	\
GLA *start_state;	/* ptr into GLA for this block */ \
int no_copy;		/* copy input ptr to output ptr? */ \
ListNode *refvars;	/* any ref vars defined for this rule */ \
unsigned char is_root; /* this token is a root #( A ... ) */
#define zzcr_ast(node, cur, _tok, _text)	\
{(node)->token=_tok; strncpy((node)->text, _text,MaxAtom);}
#define USER_ZZSYN
#define zzAST_DOUBLE
extern int define_num;
#define LL_K 2
#define GENAST

#include "ast.h"

#define zzSET_SIZE 16
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "mode.h"

/* MR23 In order to remove calls to PURIFY use the antlr -nopurify option */

#ifndef PCCTS_PURIFY
#define PCCTS_PURIFY(r,s) memset((char *) &(r),'\0',(s));
#endif

#include "ast.c"
zzASTgvars

ANTLR_INFO

/* MR20 G. Hobbelt Fix for Borland C++ 4.x & 5.x compiling with ALL warnings enabled */
#if defined(__TURBOC__)
#pragma warn -aus  /* unused assignment of 'xxx' */
#endif


#include "sym.h"
#include "proto.h"

void    /* MR9 23-Sep-97 Eliminate complaint about no return value */
#ifdef __USE_PROTOS
lisp( AST *tree, FILE *output )
#else
lisp( tree, output )
AST *tree;
FILE *output;
#endif
{
  while ( tree != NULL )
  {
    if ( tree->down != NULL ) fprintf(output," (");
    if ( tree->text[0]!='\0' ) {
      fprintf(output, " \"");
      if ( tree->label[0]!='\0' ) fprintf(output, "%s:", tree->label);
      switch ( tree->token ) {
        case OPT :
        case POS_CLOSURE :
        case CLOSURE :
        case PRED_OP :
        fprintf(output, "%s", tree->text);
        break;
        default :
        fprintf(output, "%s[%s]", zztokens[tree->token], tree->text);
      }
      fprintf(output, "\"");
    }
    else {
      fprintf(output, " %s", zztokens[tree->token]);
    }
    lisp(tree->down, output);
    if ( tree->down != NULL ) fprintf(output," )");
    tree = tree->right;
  }
}

AST *
#ifdef __USE_PROTOS
zzmk_ast(AST *node, int token)
#else
zzmk_ast(node, token)
AST *node;
int token;
#endif
{
  node->token = token;
  return node;
}

AST *
#ifdef __USE_PROTOS
read_sor_desc(FILE *f)
#else
read_sor_desc(f)
FILE *f;
#endif
{
  AST *root = NULL;
  
	zzline = 1;
  ANTLR(sordesc(&root), f);
  
	if ( found_error ) return NULL;
  
	if ( print_guts ) {
    fprintf(stderr, "Internal Represenation of Tree Grammar:\n");
    lisp(root, stderr);
    fprintf(stderr, "\n");
  }
  
	last_valid_token = token_type;
  end_of_input = token_type++;/* end of input token type is 1 + last real token */
  epsilon = token_type++;		/* epsilon token type is 2 + last real token */
  wild_card = token_type++;	/* wild_card_token is 3 + last real token */
  token_association(end_of_input, "$");
  token_association(epsilon, "[Ep]");
  token_association(wild_card, ".");
  
	zzdouble_link(root, NULL, NULL);
  rules = root;
  if ( root!=NULL ) build_GLA(root);
  
	if ( print_guts ) {
    fprintf(stderr, "Internal Represenation of Grammar Lookahead Automaton:\n");
    dump_GLAs(root);
    fprintf(stderr, "\n");
  }
  return root;
}

void
#ifdef __USE_PROTOS
sordesc(AST**_root)
#else
sordesc(_root)
AST **_root;
#endif
{
  zzRULE;
  zzBLOCK(zztasp1);
  zzMake0;
  {
  int he=0,to=0;
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    for (;;) {
      if ( !((setwd1[LA(1)]&0x1))) break;
      if ( (LA(1)==Header) ) {
        header(zzSTR); zzlink(_root, &_sibling, &_tail);
        he++;
      }
      else {
        if ( (LA(1)==Tokdef) ) {
          tokdef(zzSTR); zzlink(_root, &_sibling, &_tail);
          to++;
        }
        else break; /* MR6 code for exiting loop "for sure" */
      }
      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  
  if ( he==0 && !Inline && !GenCPP ) warnNoFL("missing #header statement");
  if ( he>1 ) warnNoFL("extra #header statement");
  if ( to>1 ) warnNoFL("extra #tokdef statement");
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    while ( (LA(1)==Action) && (setwd1[LA(2)]&0x2) ) {
      zzmatch(Action); 
      list_add(&before_actions, actiondup(LATEXT(1)));
 zzCONSUME;

      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    if ( (LA(1)==81)
 ) {
      class_def(zzSTR); zzlink(_root, &_sibling, &_tail);
    }
    else {
      if ( (setwd1[LA(1)]&0x4) ) {
      }
      else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    while ( (LA(1)==Action) && (setwd1[LA(2)]&0x8) ) {
      zzmatch(Action); 
      
      if ( CurClassName[0]!='\0' )
      list_add(&class_actions, actiondup(LATEXT(1)));
      else
      list_add(&before_actions, actiondup(LATEXT(1)));
 zzCONSUME;

      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    while ( (LA(1)==NonTerm) ) {
      rule(zzSTR); zzlink(_root, &_sibling, &_tail);
      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    while ( (LA(1)==Action) && (setwd1[LA(2)]&0x10) ) {
      zzmatch(Action); 
      
      if ( CurClassName[0]!='\0' )
      list_add(&class_actions, actiondup(LATEXT(1)));
      else
      list_add(&before_actions, actiondup(LATEXT(1)));
 zzCONSUME;

      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    if ( (LA(1)==80)
 ) {
      zzmatch(80); 
      
      if ( CurClassName[0]=='\0' )
      err("missing class definition for trailing '}'");
 zzCONSUME;

    }
    else {
      if ( (setwd1[LA(1)]&0x20) ) {
      }
      else {zzFAIL(1,zzerr2,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
    }
    zzEXIT(zztasp2);
    }
  }
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    while ( (LA(1)==Action) ) {
      zzmatch(Action); 
      list_add(&after_actions, actiondup(LATEXT(1)));
 zzCONSUME;

      zzLOOP(zztasp2);
    }
    zzEXIT(zztasp2);
    }
  }
  zzmatch(Eof);  zzCONSUME;
  zzEXIT(zztasp1);
  return;
fail:
  zzEXIT(zztasp1);
  found_error=1;  
  zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  zzresynch(setwd1, 0x40);
  }
}

void
#ifdef __USE_PROTOS
header(AST**_root)
#else
header(_root)
AST **_root;
#endif
{
  zzRULE;
  zzBLOCK(zztasp1);
  zzMake0;
  {
  zzmatch(Header);  zzCONSUME;
  zzmatch(Action); 
  header_action = actiondup(LATEXT(1));
 zzCONSUME;

  zzEXIT(zztasp1);
  return;
fail:
  zzEXIT(zztasp1);
  found_error=1;  
  zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  zzresynch(setwd1, 0x80);
  }
}

void
#ifdef __USE_PROTOS
tokdef(AST**_root)
#else
tokdef(_root)
AST **_root;
#endif
{
  zzRULE;
  zzBLOCK(zztasp1);
  zzMake0;
  {
  zzmatch(Tokdef);  zzCONSUME;
  zzmatch(RExpr); 
  {
    AST *dumb = NULL;
    zzantlr_state st; FILE *f; struct zzdlg_state dst;
    strcpy(tokdefs_file, LATEXT(1));
    strcpy(tokdefs_file, tokdefs_file+1); /* remove quotes */
    tokdefs_file[strlen(tokdefs_file)-1] = '\0';
    zzsave_antlr_state(&st);
    zzsave_dlg_state(&dst);
    define_num=0;
    f = fopen(tokdefs_file, "r");
    if ( f==NULL ) {found_error=1; err(eMsg1("cannot open token defs file '%s'", tokdefs_file));}
    else {ANTLRm(enum_file(&dumb), f, PARSE_ENUM_FILE);}
    zzrestore_antlr_state(&st);
    zzrestore_dlg_state(&dst);
    UserDefdTokens = 1;
  }
 zzCONSUME;

  zzEXIT(zztasp1);
  return;
fail:
  zzEXIT(zztasp1);
  found_error=1;  
  zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  zzresynch(setwd2, 0x1);
  }
}

void
#ifdef __USE_PROTOS
class_def(AST**_root)
#else
class_def(_root)
AST **_root;
#endif
{
  zzRULE;
  zzBLOCK(zztasp1);
  zzMake0;
  {
  zzmatch(81); zzastDPush; zzCONSUME;
  {
    zzBLOCK(zztasp2);
    zzMake0;
    {
    if ( (LA(1)==NonTerm) ) {
      zzmatch(NonTerm); zzastDPush;
      strncpy(CurClassName,LATEXT(1),MaxAtom);
 zzCONSUME;

    }
    else {
      if ( (LA(1)==Token) ) {
        zzmatch(Token); zzastDPush;
        strncpy(CurClassName,LATEXT(1),MaxAtom);
 zzCONSUME;

      }
      else {zzFAIL(1,zzerr3,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
    }
    zzEXIT(zztasp2);
    }
  }
  if ( !GenCPP ) { err("class meta-op used without C++ option"); }
  zzmatch(OPT); zzastDPush; zzCONSUME;
  zzEXIT(zztasp1);
  return;
fail:
  zzEXIT(zztasp1);
  zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  zzresynch(setwd2, 0x2);
  }
}

void
#ifdef __USE_PROTOS
rule(AST**_root)
#else
rule(_root)
AST **_root;
#endif
{
  zzRULE;
  zzBLOCK(zztasp1);
  zzMake0;
  {
  SymEntry *p; int trouble=0, no_copy=0;
  zzmatch(NonTerm); zzsubroot(_root, &_sibling, &_tail);
  
  (*_root)->file = CurFile;
  (*_root)->line = zzline;
  CurRule = zzaArg(zztasp1,1 ).text;
  p = (SymEntry *) hash_get(symbols, zzaArg(zztasp1,1 ).text);
  if ( p==NULL ) {
    p = (SymEntry *) hash_add(symbols, zzaArg(zztasp1,1 ).text, (Entry *) newSymEntry(zzaArg(zztasp1,1 ).text));
    p->token = NonTerm;
    p->defined = 1;
    p->definition = (*_root);
  }
  else if ( p->token != NonTerm ) {
    err(eMsg2("rule definition clashes with %s definition: '%s'", zztokens[p->token], p->str));
    trouble = 1;
  }
  else {
    if ( p->defined ) {
      trouble = 1;
      err(eMsg1("rule multiply defined: '%s'", zzaArg(zztasp1,1 ).text));
    }
    else {
      p->defined = 1;
      p->definition = (*_root);
    }
  }
 zzCONSUME;

  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -