home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
p
/
pccts.zip
/
antlr
/
parser.dlg
< prev
next >
Wrap
Text File
|
1992-12-08
|
8KB
|
595 lines
<<
/* parser.dlg -- DLG Description of scanner
*
* Generated from: antlr.g
*
* Terence Parr, Hank Dietz and Will Cohen: 1989-1992
* Purdue University Electrical Engineering
* ANTLR Version 1.06
*/
#include <stdio.h>
#include "set.h"
#include <ctype.h>
#include "syn.h"
#include "hash.h"
#include "generic.h"
#define zzcr_attr(attr,tok,t)
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
LOOKAHEAD
void zzerraction()
{
(*zzerr)("invalid token");
zzadvance();
zzskip();
}
>>
%%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 ) return;
fclose( input );
input = new_input;
zzrdstream( input );
/*zzadvance(); /* Get 1st char of this file */
zzskip(); /* Skip the Eof (@) char i.e continue */
}
>>
[\t\ ]+
<<
NLA = 42;
zzskip();
>>
[\n\r]
<<
NLA = 43;
zzline++; zzskip();
>>
\[
<<
NLA = 44;
zzmode(ACTIONS); zzmore();
istackreset();
pushint(']');
>>
\<\<
<<
NLA = 45;
action_file=CurFile; action_line=zzline;
zzmode(ACTIONS); zzmore();
istackreset();
pushint('>');
>>
\"
<<
NLA = 46;
zzmode(STRINGS); zzmore();
>>
/\*
<<
NLA = 47;
zzmode(COMMENTS); zzskip();
>>
\*/
<<
NLA = 48;
warn("Missing /*; found dangling */"); zzskip();
>>
\>\>
<<
NLA = 49;
warn("Missing <<; found dangling \\>\\>"); zzskip();
>>
#header
<<
NLA = 50;
>>
!
<<
NLA = 52;
>>
\<
<<
NLA = 53;
>>
\>
<<
NLA = 54;
>>
:
<<
NLA = 55;
>>
;
<<
NLA = 56;
>>
#lexaction
<<
NLA = 57;
>>
#lexclass
<<
NLA = 58;
>>
#errclass
<<
NLA = 60;
>>
\{
<<
NLA = 61;
>>
\}
<<
NLA = 62;
>>
#token
<<
NLA = 63;
>>
\|
<<
NLA = 64;
>>
^
<<
NLA = 65;
>>
\(
<<
NLA = 66;
>>
\)
<<
NLA = 67;
>>
\*
<<
NLA = 68;
>>
\+
<<
NLA = 69;
>>
[a-z] [A-Za-z0-9_]*
<<
NLA = NonTerminal;
>>
[A-Z] [A-Za-z0-9_]*
<<
NLA = TokenTerm;
>>
#[A-Za-z0-9_]*
<<
NLA = 70;
warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip();
>>
%%STRINGS
@
<<
NLA = Eof;
>>
\"
<<
NLA = QuotedTerm;
zzmode(START);
>>
\\\"
<<
NLA = 3;
zzmore();
>>
\n
<<
NLA = 4;
zzline++;
warn("eoln found in string (in user action)");
zzskip();
>>
\\~[\"]
<<
NLA = 5;
zzmore();
>>
~[\n\"\\]+
<<
NLA = 6;
zzmore();
>>
%%COMMENTS
@
<<
NLA = Eof;
>>
\*/
<<
NLA = 7;
zzmode(START); zzskip();
>>
\*
<<
NLA = 8;
zzskip();
>>
\n
<<
NLA = 9;
zzline++; zzskip();
>>
~[\n\*]+
<<
NLA = 10;
zzskip();
>>
%%ACTIONS
@
<<
NLA = Eof;
>>
\>\>
<<
NLA = Action;
/* these do not nest */
zzmode(START);
NLATEXT[0] = ' ';
NLATEXT[1] = ' ';
zzbegexpr[0] = ' ';
zzbegexpr[1] = ' ';
if ( zzbufovf ) {
warn( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
}
>>
\>\>?
<<
NLA = Pred;
/* these do not nest */
zzmode(START);
NLATEXT[0] = ' ';
NLATEXT[1] = ' ';
zzbegexpr[0] = ' ';
zzbegexpr[1] = ' ';
zzbegexpr[2] = ' ';
if ( zzbufovf ) {
warn( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
}
>>
\]
<<
NLA = PassAction;
if ( topint() == ']' ) {
popint();
if ( istackempty() ) /* terminate action */
{
zzmode(START);
NLATEXT[0] = ' ';
zzbegexpr[0] = ' ';
if ( zzbufovf ) {
warn( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
}
}
else {
/* terminate zzconstr_attr(..) and zzmk_ast(zzastnew(),..) */
zzreplstr(")");
zzmore();
}
}
else if ( topint() == '|' ) { /* end of simple [...] */
popint();
zzmore();
}
else zzmore();
>>
\n
<<
NLA = 14;
zzline++; zzmore();
>>
\>
<<
NLA = 15;
zzmore();
>>
$
<<
NLA = 16;
zzmore();
>>
$$
<<
NLA = 17;
zzreplstr("zzaRet"); zzmore();
>>
$\[\]
<<
NLA = 18;
zzreplstr("zzempty_attr"); zzmore();
>>
$\[
<<
NLA = 19;
pushint(']');
zzreplstr("zzconstr_attr(");
zzmore();
>>
$[0-9]+
<<
NLA = 20;
{
static char buf[100];
if ( strlen(zzbegexpr)>85 )
fatal(" i attrib ref too big");
sprintf(buf,"zzaArg(zztasp%d,%s)",
BlkLevel-1,zzbegexpr+1);
zzreplstr(buf);
zzmore();
}
>>
$[0-9]+.
<<
NLA = 21;
{
static char buf[100];
if ( strlen(zzbegexpr)>85 )
fatal(" i.field attrib ref too big");
zzbegexpr[strlen(zzbegexpr)-1] = ' ';
sprintf(buf,"zzaArg(zztasp%d,%s).",
BlkLevel-1,zzbegexpr+1);
zzreplstr(buf);
zzmore();
}
>>
$[0-9]+.[0-9]+
<<
NLA = 22;
{
static char buf[100];
static char i[20], j[20];
char *p,*q;
if (strlen(zzbegexpr)>85) fatal(" i.j attrib ref too big");
for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
if ( q == &i[20] ) fatalFL("i of i.j attrib ref too big", FileStr[CurFile], zzline );
*q++ = *p;
}
*q = '\0';
for (p++, q= &j[0]; *p!='\0'; p++) {
if ( q == &j[20] ) fatalFL("j of i.j attrib ref too big", FileStr[CurFile], zzline );
*q++ = *p;
}
*q = '\0';
sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
zzreplstr(buf);
zzmore();
}
>>
$[_a-zA-Z][_a-zA-Z0-9]*
<<
NLA = 23;
{ static char buf[300];
zzbegexpr[0] = ' ';
if ( CurRule != NULL &&
strcmp(CurRule, &zzbegexpr[1])==0 ) {
zzreplstr("zzaRet");
}
else if ( CurRetDef != NULL ) {
if ( strmember(CurRetDef, &zzbegexpr[1]) ) {
if ( HasComma( CurRetDef ) ) {
require (strlen(zzbegexpr)<=285,
" retval attrib ref too big");
sprintf(buf,"_retv.%s",&zzbegexpr[1]);
zzreplstr(buf);
}
else zzreplstr("_retv");
}
else if ( CurParmDef != NULL ) {
if ( !strmember(CurParmDef, &zzbegexpr[1]) )
warn(eMsg1("$%s not parameter or return value",&zzbegexpr[1]));
}
else warn(eMsg1("$%s not parameter or return value",&zzbegexpr[1]));
}
}
zzmore();
>>
#0
<<
NLA = 24;
zzreplstr("(*_root)"); zzmore();
>>
#\[\]
<<
NLA = 25;
zzreplstr("zzastnew()"); zzmore();
>>
#\(\)
<<
NLA = 26;
zzreplstr("NULL"); zzmore();
>>
#[0-9]+
<<
NLA = 27;
{
static char buf[100];
if ( strlen(zzbegexpr)>85 )
fatal("#i AST ref too big");
sprintf(buf,"zzastArg(%s)",zzbegexpr+1);
zzreplstr(buf);
zzmore();
}
>>
#\[
<<
NLA = 28;
pushint(']');
zzreplstr("zzmk_ast(zzastnew(),");
zzmore();
>>
#\(
<<
NLA = 29;
pushint('}');
zzreplstr("zztmake(");
zzmore();
>>
#
<<
NLA = 30;
zzmore();
>>
\)
<<
NLA = 31;
if ( istackempty() )
zzmore();
else if ( topint()==')' ) {
popint();
}
else if ( topint()=='}' ) {
popint();
/* terminate zztmake(.., NULL) */
zzreplstr(", NULL)");
}
zzmore();
>>
\[
<<
NLA = 32;
pushint('|'); /* look for '|' to terminate simple [...] */
zzmore();
>>
\(
<<
NLA = 33;
pushint(')');
zzmore();
>>
\\\]
<<
NLA = 34;
zzreplstr("]"); zzmore();
>>
\\\)
<<
NLA = 35;
zzreplstr(")"); zzmore();
>>
\\>
<<
NLA = 36;
zzreplstr(">"); zzmore();
>>
\\$
<<
NLA = 37;
zzreplstr("$"); zzmore();
>>
\\#
<<
NLA = 38;
zzreplstr("#"); zzmore();
>>
\\\\
<<
NLA = 39;
zzmore();
>>
\\~[\]\)>$#\\]
<<
NLA = 40;
zzmore();
>>
~[\n\)\(\\$#\>\]\[]+
<<
NLA = 41;
zzmore();
>>
%%