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

📄 parser.dlg

📁 SRI international 发布的OAA框架软件
💻 DLG
字号:
<<
/* parser.dlg -- DLG Description of scanner
 *
 * Generated from: sor.g
 *
 * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
 * Purdue University Electrical Engineering
 * With AHPCRC, University of Minnesota
 * ANTLR Version 1.33MR33
 */

#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
#include "antlr.h"
#include "ast.h"
#include "tokens.h"
#include "dlgdef.h"
LOOKAHEAD

void
#ifdef __USE_PROTOS
zzerraction(void)
#else
zzerraction()
#endif
{
	(*zzerr)("invalid token");
	zzadvance();
	zzskip();
}
>>

<<%%lexaction

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

int define_num = 0;

char *
#ifdef __USE_PROTOS
scarf_to_end_of_func_call(void)
#else
scarf_to_end_of_func_call()
#endif
{
  static char func_call_str[MaxAtom+1];
  char *p;
  
	p = &func_call_str[0];
  
more:
  if ( zzchar==')' ) { *p++ = zzchar; *p++ = '\0'; zzadvance(); return func_call_str; }
  if ( zzchar=='"' )
  {
    *p++ = zzchar; zzadvance();
    while ( zzchar!='"' )
    {
      if ( zzchar=='\\' ) { *p++ = zzchar; zzadvance(); }
      *p++ = zzchar; zzadvance();
    }
  }
  *p++ = zzchar; zzadvance();
  goto more;
}
>>


%%START

@
	<<
		NLA = Eof;
    /* L o o k  F o r  A n o t h e r  F i l e */
    {
      FILE *new_input;
      new_input = NextFile();
      if ( new_input != NULL ) {
        fclose( input );
        input = new_input;
        zzrdstream( input );
        /*zzadvance();	** Get 1st char of this file */
        zzskip();	/* Skip the Eof (@) char i.e continue */
      }
    }
	>>

[\t\ ]+
	<<
		NLA = 56;
    zzskip();   
	>>

\n|\r|\n\r
	<<
		NLA = 57;
    zzline++; zzskip();   
	>>

\[
	<<
		NLA = 58;
    zzmode(ACTIONS); zzmore();
    istackreset();
    pushint(']');   
	>>

\<\<
	<<
		NLA = 59;
    action_file=CurFile; action_line=zzline;
    zzmode(ACTIONS); zzmore();
    istackreset();
    pushint('>');   
	>>

\"
	<<
		NLA = 60;
    zzmode(STRINGS); zzmore();   
	>>

/\*
	<<
		NLA = 61;
    zzmode(COMMENTS); zzskip();   
	>>

\*/
	<<
		NLA = 62;
    err("Missing /*; found dangling */"); zzskip();   
	>>

//
	<<
		NLA = 63;
    zzmode(CPP_COMMENTS); zzskip();   
	>>

\>\>
	<<
		NLA = 64;
    err("Missing <<; found dangling \>\>"); zzskip();   
	>>

#header
	<<
		NLA = Header;
	>>

#tokdefs
	<<
		NLA = Tokdef;
	>>

:
	<<
		NLA = LABEL;
	>>

\{
	<<
		NLA = OPT;
	>>

\+
	<<
		NLA = POS_CLOSURE;
	>>

\*
	<<
		NLA = CLOSURE;
	>>

.
	<<
		NLA = WILD;
	>>

?
	<<
		NLA = PRED_OP;
	>>

#\(
	<<
		NLA = BT;
	>>

\}
	<<
		NLA = 80;
	>>

class
	<<
		NLA = 81;
	>>

!
	<<
		NLA = 84;
	>>

\<
	<<
		NLA = 85;
	>>

\>
	<<
		NLA = 86;
	>>

;
	<<
		NLA = 87;
	>>

\|
	<<
		NLA = 88;
	>>

\(
	<<
		NLA = 89;
	>>

\)
	<<
		NLA = 90;
	>>

..
	<<
		NLA = 91;
	>>

[a-z] [A-Za-z0-9_]*
	<<
		NLA = NonTerm;
	>>

[A-Z] [A-Za-z0-9_]*
	<<
		NLA = Token;
	>>

#[A-Za-z0-9_]*
	<<
		NLA = 92;
    warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip();   
	>>


%%STRINGS

@
	<<
		NLA = Eof;
	>>

\"
	<<
		NLA = RExpr;
    zzmode(START);   
	>>

\n|\r|\r\n
	<<
		NLA = 3;
    /* MR16a */
    zzline++;
    warn("eoln found in string");
    zzskip();
	>>

\\~[]
	<<
		NLA = 4;
    zzmore();   
	>>

~[\n\r\"\\]+
	<<
		NLA = 5;
    zzmore();   
	>>


%%ACTION_STRINGS

@
	<<
		NLA = Eof;
	>>

\"
	<<
		NLA = 6;
    zzmode(ACTIONS); zzmore();   
	>>

\n|\r|\r\n
	<<
		NLA = 7;
    /* MR16a */
    zzline++;
    warn("eoln found in string (in user action)");
    zzskip();
	>>

\\~[]
	<<
		NLA = 8;
    zzmore();   
	>>

~[\n\r\"\\]+
	<<
		NLA = 9;
    zzmore();   
	>>


%%ACTION_CHARS

@
	<<
		NLA = Eof;
	>>

'
	<<
		NLA = 10;
    zzmode(ACTIONS); zzmore();   
	>>

\n|\r|\r\n
	<<
		NLA = 11;
    /* MR16a */
    zzline++;
    warn("eoln found in char literal (in user action)");
    zzskip();
	>>

\\~[]
	<<
		NLA = 12;
    zzmore();   
	>>

~[\n\r'\\]+
	<<
		NLA = 13;
    zzmore();   
	>>


%%ACTION_COMMENTS

@
	<<
		NLA = Eof;
	>>

\*/
	<<
		NLA = 14;
    zzmode(ACTIONS); zzmore();   
	>>

\*
	<<
		NLA = 15;
    zzmore();   
	>>

\n|\r|\r\n
	<<
		NLA = 16;
    zzline++; zzmore();   
	>>

~[\n\r\*]+
	<<
		NLA = 17;
    zzmore();   
	>>


%%ACTION_CPP_COMMENTS

@
	<<
		NLA = Eof;
	>>

\n|\r|\r\n
	<<
		NLA = 18;
    zzline++; zzmode(ACTIONS); zzmore();   
	>>

~[\n\r]+
	<<
		NLA = 19;
    zzmore();   
	>>


%%CPP_COMMENTS

@
	<<
		NLA = Eof;
	>>

\n|\r|\r\n
	<<
		NLA = 20;
    zzline++; zzmode(START); zzskip();   
	>>

~[\n\r]+
	<<
		NLA = 21;
    zzskip();   
	>>


%%COMMENTS

@
	<<
		NLA = Eof;
	>>

\*/
	<<
		NLA = 22;
    zzmode(START); zzskip();   
	>>

\*
	<<
		NLA = 23;
    zzskip();   
	>>

\n|\r|\r\n
	<<
		NLA = 24;
    zzline++; zzskip();   
	>>

~[\n\r\*]+
	<<
		NLA = 25;
    zzskip();   
	>>


%%REFVAR_SCARF

@
	<<
		NLA = Eof;
	>>

~[\)]+ \)
	<<
		NLA = 26;
    {
      RefVarRec *rf;
      zzskip();
      zzbegexpr[strlen(zzbegexpr)-1] = '\0';
      rf=refVarRec(zzbegexpr);
      list_add(&AllRefVars, rf);
      list_add(&RefVars, rf);
      zzmode(ACTIONS); zzmore(); zzreplstr("");
    }  
	>>


%%ACTIONS

@
	<<
		NLA = Eof;
	>>

\>\>
	<<
		NLA = Action;
    /* these do not nest */
    zzmode(START);
    NLATEXT[0] = ' ';
    NLATEXT[1] = ' ';
    zzbegexpr[0] = ' ';
    zzbegexpr[1] = ' ';
    if ( zzbufovf ) {
      found_error = 1;
      err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
    }
	>>

\]
	<<
		NLA = PassAction;
    if ( topint() == ']' ) {
      popint();
      if ( istackempty() )	/* terminate action */
      {
        zzmode(START);
        NLATEXT[0] = ' ';
        zzbegexpr[0] = ' ';
        if ( zzbufovf ) {
          found_error = 1;
          err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
        }
      }
      else {
        /* terminate #[..] */
        zzreplstr(")");
        zzmore();
      }
    }
    else if ( topint() == '|' ) { /* end of simple [...] */
      popint();
      zzmore();
    }
    else zzmore();
	>>

\n|\r|\r\n
	<<
		NLA = 29;
    zzline++; zzmore();   
	>>

\>
	<<
		NLA = 30;
    zzmore();   
	>>

#[_a-zA-Z][_a-zA-Z0-9]*
	<<
		NLA = 31;
    
    if ( !(strcmp(zzbegexpr, "#ifdef")==0 ||
    strcmp(zzbegexpr, "#else")==0 ||
    strcmp(zzbegexpr, "#endif")==0 ||
    strcmp(zzbegexpr, "#ifndef")==0 ||
    strcmp(zzbegexpr, "#if")==0 ||
    strcmp(zzbegexpr, "#define")==0 ||
    strcmp(zzbegexpr, "#pragma")==0 ||
    strcmp(zzbegexpr, "#undef")==0 ||
    strcmp(zzbegexpr, "#import")==0 ||
    strcmp(zzbegexpr, "#line")==0 ||
    strcmp(zzbegexpr, "#include")==0 ||
    strcmp(zzbegexpr, "#error")==0) )
    {
      static char buf[100];
      if ( !transform ) {
        warn("#id used in nontransform mode; # ignored");
        sprintf(buf, "%s", zzbegexpr+1);
      }
      else {
        if ( CurRule==NULL )
        {warn("#id used in action outside of rule; ignored");}
        else if ( strcmp(zzbegexpr+1,CurRule)==0 )
        strcpy(buf, "(*_result)");
      }
      zzreplstr(buf);
    }
    zzmore();
	>>

#\[\]
	<<
		NLA = 32;
    
    if ( GenCPP ) zzreplstr("new SORAST");
    else zzreplstr("ast_empty_node()");
    zzmore();
	>>

#\(\)
	<<
		NLA = 33;
    zzreplstr("NULL"); zzmore();   
	>>

#\[
	<<
		NLA = 34;
    
    pushint(']');
    if ( GenCPP ) zzreplstr("new SORAST(");
    else zzreplstr("ast_node(");
    zzmore();
	>>

#\(
	<<
		NLA = 35;
    
    pushint('}');
    if ( GenCPP ) zzreplstr("PCCTS_AST::make(");
    else zzreplstr("ast_make(");
    zzmore();
	>>

#
	<<
		NLA = 36;
    zzmore();   
	>>

\)
	<<
		NLA = 37;
    
    if ( istackempty() )
    zzmore();
    else if ( topint()==')' ) {
      popint();
    }
    else if ( topint()=='}' ) {
      popint();
      /* terminate #(..) */
      zzreplstr(", NULL)");
    }
    zzmore();
	>>

\[
	<<
		NLA = 38;
    
    pushint('|');	/* look for '|' to terminate simple [...] */
    zzmore();
	>>

\(
	<<
		NLA = 39;
    
    pushint(')');
    zzmore();
	>>

\\\]
	<<
		NLA = 40;
    zzreplstr("]");  zzmore();   
	>>

\\\)
	<<
		NLA = 41;
    zzreplstr(")");  zzmore();   
	>>

\\>
	<<
		NLA = 42;
    zzreplstr(">");  zzmore();   
	>>

'
	<<
		NLA = 43;
    zzmode(ACTION_CHARS); zzmore();  
	>>

\"
	<<
		NLA = 44;
    zzmode(ACTION_STRINGS); zzmore();  
	>>

\\#
	<<
		NLA = 45;
    zzreplstr("#");  zzmore();   
	>>

\\~[\]\)>#]
	<<
		NLA = 46;
    zzmore();   
	>>

/
	<<
		NLA = 47;
    zzmore();   
	>>

/\*
	<<
		NLA = 48;
    zzmode(ACTION_COMMENTS); zzmore();   
	>>

\*/
	<<
		NLA = 49;
    err("Missing /*; found dangling */ in action"); zzmore();   
	>>

//
	<<
		NLA = 50;
    zzmode(ACTION_CPP_COMMENTS); zzmore();   
	>>

\@\(
	<<
		NLA = 51;
    zzmode(REFVAR_SCARF); zzmore(); zzreplstr("");  
	>>

\@
	<<
		NLA = 52;
    
    zzmore(); if ( !GenCPP ) zzreplstr("_parser->");
	>>

[a-zA-Z_]+\(
	<<
		NLA = 53;
    
    if ( (GenCPP && strcmp(zzbegexpr,"ast_scan(")==0) ||
    (!GenCPP && strcmp(zzbegexpr,"ast_scan(")==0) ) {
      char *args=scarf_to_end_of_func_call();
      zzreplstr(cvt_token_str(zzbegexpr, args));
      zzmore();
    }
    else { pushint(')'); zzmore(); }
	>>

[a-zA-Z_]+
	<<
		NLA = 54;
    zzmore();   
	>>

~[a-zA-Z_\n\r\)\(\\#\>\]\[\"'/\@]+
	<<
		NLA = 55;
    zzmore();   
	>>


%%TOK_DEF_COMMENTS

@
	<<
		NLA = Eof;
	>>

\*/
	<<
		NLA = 93;
    zzmode(PARSE_ENUM_FILE); zzmore();   
	>>

\*
	<<
		NLA = 94;
    zzmore();   
	>>

\n|\r|\r\n
	<<
		NLA = 95;
    zzline++; zzmore();   
	>>

~[\n\r\*]+
	<<
		NLA = 96;
    zzmore();   
	>>


%%TOK_DEF_CPP_COMMENTS

@
	<<
		NLA = Eof;
	>>

\n|\r|\r\n
	<<
		NLA = 97;
    zzline++; zzmode(PARSE_ENUM_FILE); zzskip();   
	>>

~[\n\r]+
	<<
		NLA = 98;
    zzskip();   
	>>


%%PARSE_ENUM_FILE

@
	<<
		NLA = Eof;
    /*zzmode(START); zzskip();*/   
	>>

[\t\ ]+
	<<
		NLA = 99;
    zzskip();   
	>>

\n|\r|\r\n
	<<
		NLA = 100;
    zzline++; zzskip();   
	>>

//
	<<
		NLA = 101;
    zzmode(TOK_DEF_CPP_COMMENTS); zzmore();   
	>>

/\*
	<<
		NLA = 102;
    zzmode(TOK_DEF_COMMENTS); zzmore();   
	>>

#ifndef
	<<
		NLA = 103;
    
	>>

#ifdef
	<<
		NLA = 104;
    zzmode(TOK_DEF_CPP_COMMENTS); zzskip();   
	>>

#else
	<<
		NLA = 105;
    zzmode(TOK_DEF_CPP_COMMENTS); zzskip();   
	>>

#define
	<<
		NLA = 106;
    
	>>

#endif
	<<
		NLA = 107;
    zzmode(TOK_DEF_CPP_COMMENTS); zzskip();   
	>>

enum
	<<
		NLA = 110;
	>>

\{
	<<
		NLA = 111;
	>>

=
	<<
		NLA = 112;
	>>

,
	<<
		NLA = 113;
	>>

DLGminToken
	<<
		NLA = 114;
	>>

DLGmaxToken
	<<
		NLA = 115;
	>>

\}
	<<
		NLA = 116;
	>>

;
	<<
		NLA = 117;
	>>

[0-9]+
	<<
		NLA = INT;
	>>

[a-zA-Z_][_a-zA-Z0-9]*
	<<
		NLA = ID;
	>>

%%

⌨️ 快捷键说明

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