More renames for Tool Packages

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1675 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lhauch
2006-10-05 23:16:50 +00:00
parent feccee87a7
commit 28305207ea
277 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,522 @@
CHANGES FROM 1.31
This file contains the migration of PCCTS from 1.31 in the order that
changes were made. 1.32b7 is the last beta before full 1.32.
Terence Parr, Parr Research Corporation 1995.
======================================================================
1.32b1
Added Russell Quong to banner, changed banner for output slightly
Fixed it so that you have before / after actions for C++ in class def
Fixed bug in optimizer that made it sometimes forget to set internal
token pointers. Only showed up when a {...} was in the "wrong spot".
======================================================================
1.32b2
Added fixes by Dave Seidel for PC compilers in 32 bit mode (config.h
and set.h).
======================================================================
1.32b3
Fixed hideous bug in code generator for wildcard and for ~token op.
from Dave Seidel
Added pcnames.bat
1. in antlr/main.c: change strcasecmp() to stricmp()
2. in dlg/output.c: use DLEXER_C instead on "DLexer.C"
3. in h/PBlackBox.h: use <iostream.h> instead of <stream.h>
======================================================================
1.32b4
When the -ft option was used, any path prefix screwed up
the gate on the .h files
Fixed yet another bug due to the optimizer.
The exception handling thing was a bit wacko:
a : ( A B )? A B
| A C
;
exception ...
caused an exception if "A C" was the input. In other words,
it found that A C didn't match the (A B)? pred and caused
an exception rather than trying the next alt. All I did
was to change the zzmatch_wsig() macros.
Fixed some problems in gen.c relating to the name of token
class bit sets in the output.
Added the tremendously cool generalized predicate. For the
moment, I'll give this bried description.
a : <<predicate>>? blah
| foo
;
This implies that (assuming blah and foo are syntactically
ambiguous) "predicate" indicates the semantic validity of
applying "blah". If "predicate" is false, "foo" is attempted.
Previously, you had to say:
a : <<LA(1)==ID ? predicate : 1>>? ID
| ID
;
Now, you can simply use "predicate" without the ?: operator
if you turn on ANTLR command line option: "-prc on". This
tells ANTLR to compute that all by itself. It computes n
tokens of lookahead where LT(n) or LATEXT(n) is the farthest
ahead you look.
If you give a predicate using "-prc on" that is followed
by a construct that can recognize more than one n-sequence,
you will get a warning from ANTLR. For example,
a : <<isTypeName(LT(1)->getText())>>? (ID|INT)
;
This is wrong because the predicate will be applied to INTs
as well as ID's. You should use this syntax to make
the predicate more specific:
a : (ID)? => <<isTypeName(LT(1)->getText())>>? (ID|INT)
;
which says "don't apply the predicate unless ID is the
current lookahead context".
You cannot currently have anything in the "(context)? =>"
except sequences such as:
( LPAREN ID | LPAREN SCOPE )? => <<pred>>?
I haven't tested this THAT much, but it does work for the
C++ grammar.
======================================================================
1.32b5
Added getLine() to the ANTLRTokenBase and DLGBasedToken classes
left line() for backward compatibility.
----
Removed SORCERER_TRANSFORM from the ast.h stuff.
-------
Fixed bug in code gen of ANTLR such that nested syn preds work more
efficiently now. The ANTLRTokenBuffer was getting very large
with nested predicates.
------
Memory leak is now gone from ANTLRTokenBuf; all tokens are deleted.
For backward compatibility reasons, you have to say parser->deleteTokens()
or mytokenbuffer->deleteTokens() but later it will be the default mode.
Say this after the parser is constructed. E.g.,
ParserBlackBox<DLGLexer, MyParser, ANTLRToken> p(stdin);
p.parser()->deleteTokens();
p.parser()->start_symbol();
==============================
1.32b6
Changed so that deleteTokens() will do a delete ((ANTLRTokenBase *))
on the ptr. This gets the virtual destructor.
Fixed some weird things in the C++ header files (a few return types).
Made the AST routines correspond to the book and SORCERER stuff.
New token stuff: See testcpp/14/test.g
ANTLR accepts a #pragma gc_tokens which says
[1] Generate label = copy(LT(1)) instead of label=LT(1) for
all labeled token references.
[2] User now has to define ANTLRTokenPtr (as a class or a typedef
to just a pointer) as well as the ANTLRToken class itself.
See the example.
To delete tokens in token buffer, use deleteTokens() message on parser.
All tokens that fall off the ANTLRTokenBuffer get deleted
which is what currently happens when deleteTokens() message
has been sent to token buffer.
We always generate ANTLRTokenPtr instead of 'ANTLRToken *' now.
Then if no pragma set, ANTLR generates a
class ANTLRToken;
typedef ANTLRToken *ANTLRTokenPtr;
in each file.
Made a warning for x:rule_ref <<$x>>; still no warning for $i's, however.
class BB {
a : x:b y:A <<$x
$y>>
;
b : B;
}
generates
Antlr parser generator Version 1.32b6 1989-1995
test.g, line 3: error: There are no token ptrs for rule references: '$x'
===================
1.32b7:
[With respect to token object garbage collection (GC), 1.32b7
backtracks from 1.32b6, but results in better and less intrusive GC.
This is the last beta version before full 1.32.]
BIGGEST CHANGES:
o The "#pragma gc_tokens" is no longer used.
o .C files are now .cpp files (hence, makefiles will have to
be changed; or you can rerun genmk). This is a good move,
but causes some backward incompatibility problems. You can
avoid this by changing CPP_FILE_SUFFIX to ".C" in pccts/h/config.h.
o The token object class hierarchy has been flattened to include
only three classes: ANTLRAbstractToken, ANTLRCommonToken, and
ANTLRCommonNoRefCountToken. The common token now does garbage
collection via ref counting.
o "Smart" pointers are now used for garbage collection. That is,
ANTLRTokenPtr is used instead of "ANTLRToken *".
o The antlr.1 man page has been cleaned up slightly.
o The SUN C++ compiler now complains less about C++ support code.
o Grammars which subclass ANTLRCommonToken must wrap all token
pointer references in mytoken(token_ptr). This is the only
serious backward incompatibility. See below.
MINOR CHANGES:
--------------------------------------------------------
1 deleteTokens()
The deleteTokens() message to the parser or token buffer has been changed
to one of:
void noGarbageCollectTokens() { inputTokens->noGarbageCollectTokens(); }
void garbageCollectTokens() { inputTokens->garbageCollectTokens(); }
The token buffer deletes all non-referenced tokens by default now.
--------------------------------------------------------
2 makeToken()
The makeToken() message returns a new type. The function should look
like:
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,
ANTLRChar *txt,
int line)
{
ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt);
t->setLine(line);
return t;
}
--------------------------------------------------------
3 TokenType
Changed TokenType-> ANTLRTokenType (often forces changes in AST defs due
to #[] constructor called to AST(tokentype, string)).
--------------------------------------------------------
4 AST()
You must define AST(ANTLRTokenPtr t) now in your AST class definition.
You might also have to include ATokPtr.h above the definition; e.g.,
if AST is defined in a separate file, such as AST.h, it's a good idea
to include ATOKPTR_H (ATokPtr.h). For example,
#include ATOKPTR_H
class AST : public ASTBase {
protected:
ANTLRTokenPtr token;
public:
AST(ANTLRTokenPtr t) { token = t; }
void preorder_action() {
char *s = token->getText();
printf(" %s", s);
}
};
Note the use of smart pointers rather than "ANTLRToken *".
--------------------------------------------------------
5 SUN C++
From robertb oakhill.sps.mot.com Bob Bailey. Changed ANTLR C++ output
to avoid an error in Sun C++ 3.0.1. Made "public" return value
structs created to hold multiple return values public.
--------------------------------------------------------
6 genmk
Fixed genmk so that target List.* is not included anymore. It's
called SList.* anyway.
--------------------------------------------------------
7 \r vs \n
Scott Vorthmann <vorth cmu.edu> fixed antlr.g in ANTLR so that \r
is allowed as the return character as well as \n.
--------------------------------------------------------
8 Exceptions
Bug in exceptions attached to labeled token/tokclass references. Didn't gen
code for exceptions. This didn't work:
a : "help" x:ID
;
exception[x]
catch MismatchedToken : <<printf("eh?\n");>>
Now ANTLR generates (which is kinda big, but necessary):
if ( !_match_wsig(ID) ) {
if ( guessing ) goto fail;
_signal=MismatchedToken;
switch ( _signal ) {
case MismatchedToken :
printf("eh?\n");
_signal = NoSignal;
break;
default :
goto _handler;
}
}
which implies that you can recover and continue parsing after a missing/bad
token reference.
--------------------------------------------------------
9 genmk
genmk now correctly uses config file for CPP_FILE_SUFFIX stuff.
--------------------------------------------------------
10 general cleanup / PURIFY
Anthony Green <green vizbiz.com> suggested a bunch of good general
clean up things for the code; he also suggested a few things to
help out the "PURIFY" memory allocation checker.
--------------------------------------------------------
11 $-variable references.
Manuel ORNATO indicated that a $-variable outside of a rule caused
ANTLR to crash. I fixed this.
12 Tom Moog suggestion
Fail action of semantic predicate needs "{}" envelope. FIXED.
13 references to LT(1).
I have enclosed all assignments such as:
_t22 = (ANTLRTokenPtr)LT(1);
in "if ( !guessing )" so that during backtracking the reference count
for token objects is not increased.
TOKEN OBJECT GARBAGE COLLECTION
1 INTRODUCTION
The class ANTLRCommonToken is now garbaged collected through a "smart"
pointer called ANTLRTokenPtr using reference counting. Any token
object not referenced by your grammar actions is destroyed by the
ANTLRTokenBuffer when it must make room for more token objects.
Referenced tokens are then destroyed in your parser when local
ANTLRTokenPtr objects are deleted. For example,
a : label:ID ;
would be converted to something like:
void yourclass::a(void)
{
zzRULE;
ANTLRTokenPtr label=NULL; // used to be ANTLRToken *label;
zzmatch(ID);
label = (ANTLRTokenPtr)LT(1);
consume();
...
}
When the "label" object is destroyed (it's just a pointer to your
input token object LT(1)), it decrements the reference count on the
object created for the ID. If the count goes to zero, the object
pointed by label is deleted.
To correctly manage the garbage collection, you should use
ANTLRTokenPtr instead of "ANTLRToken *". Most ANTLR support code
(visible to the user) has been modified to use the smart pointers.
***************************************************************
Remember that any local objects that you create are not deleted when a
lonjmp() is executed. Unfortunately, the syntactic predicates (...)?
use setjmp()/longjmp(). There are some situations when a few tokens
will "leak".
***************************************************************
2 DETAILS
o The default is to perform token object garbage collection.
You may use parser->noGarbageCollectTokens() to turn off
garbage collection.
o The type ANTLRTokenPtr is always defined now (automatically).
If you do not wish to use smart pointers, you will have to
redefined ANTLRTokenPtr by subclassing, changing the header
file or changing ANTLR's code generation (easy enough to
do in gen.c).
o If you don't use ParserBlackBox, the new initialization sequence is:
ANTLRTokenPtr aToken = new ANTLRToken;
scan.setToken(mytoken(aToken));
where mytoken(aToken) gets an ANTLRToken * from the smart pointer.
o Define C++ preprocessor symbol DBG_REFCOUNTTOKEN to see a bunch of
debugging stuff for reference counting if you suspect something.
3 WHY DO I HAVE TO TYPECAST ALL MY TOKEN POINTERS NOW??????
If you subclass ANTLRCommonToken and then attempt to refer to one of
your token members via a token pointer in your grammar actions, the
C++ compiler will complain that your token object does not have that
member. For example, if you used to do this
<<
class ANTLRToken : public ANTLRCommonToken {
int muck;
...
};
>>
class Foo {
a : t:ID << t->muck = ...; >> ;
}
Now, you must do change the t->muck reference to:
a : t:ID << mytoken(t)->muck = ...; >> ;
in order to downcast 't' to be an "ANTLRToken *" not the
"ANTLRAbstractToken *" resulting from ANTLRTokenPtr::operator->().
The macro is defined as:
/*
* Since you cannot redefine operator->() to return one of the user's
* token object types, we must down cast. This is a drag. Here's
* a macro that helps. template: "mytoken(a-smart-ptr)->myfield".
*/
#define mytoken(tp) ((ANTLRToken *)(tp.operator->()))
You have to use macro mytoken(grammar-label) now because smart
pointers are not specific to a parser's token objects. In other
words, the ANTLRTokenPtr class has a pointer to a generic
ANTLRAbstractToken not your ANTLRToken; the ANTLR support code must
use smart pointers too, but be able to work with any kind of
ANTLRToken. Sorry about this, but it's C++'s fault not mine. Some
nebulous future version of the C++ compilers should obviate the need
to downcast smart pointers with runtime type checking (and by allowing
different return type of overridden functions).
A way to have backward compatible code is to shut off the token object
garbage collection; i.e., use parser->noGarbageCollectTokens() and
change the definition of ANTLRTokenPtr (that's why you get source code
<wink>).
PARSER EXCEPTION HANDLING
I've noticed some weird stuff with the exception handling. I intend
to give this top priority for the "book release" of ANTLR.
==========
1.32 Full Release
o Changed Token class hierarchy to be (Thanks to Tom Moog):
ANTLRAbstractToken
ANTLRRefCountToken
ANTLRCommonToken
ANTLRNoRefCountCommonToken
o Added virtual panic() to ANTLRAbstractToken. Made ANTLRParser::panic()
virtual also.
o Cleaned up the dup() stuff in AST hierarchy to use shallowCopy() to
make node copies. John Farr at Medtronic suggested this. I.e.,
if you want to use dup() with either ANTLR or SORCERER or -transform
mode with SORCERER, you must defined shallowCopy() as:
virtual PCCTS_AST *shallowCopy()
{
return new AST;
p->setDown(NULL);
p->setRight(NULL);
return p;
}
or
virtual PCCTS_AST *shallowCopy()
{
return new AST(*this);
}
if you have defined a copy constructor such as
AST(const AST &t) // shallow copy constructor
{
token = t.token;
iconst = t.iconst;
setDown(NULL);
setRight(NULL);
}
o Added a warning with -CC and -gk are used together. This is broken,
hence a warning is appropriate.
o Added warning when #-stuff is used w/o -gt option.
o Updated MPW installation.
o "Miller, Philip W." <MILLERPW f1groups.fsd.jhuapl.edu> suggested
that genmk be use RENAME_OBJ_FLAG RENAME_EXE_FLAG instead of
hardcoding "-o" in genmk.c.
o made all exit() calls use EXIT_SUCCESS or EXIT_FAILURE.
===========================================================================
1.33
EXIT_FAILURE and EXIT_SUCCESS were not always defined. I had to modify
a bunch of files to use PCCTS_EXIT_XXX, which forces a new version. Sorry
about that.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,241 @@
=======================================================
Known Problems In PCCTS - Last revised 14 November 1998
=======================================================
#17. The dlg fix for handling characters up to 255 is incorrect.
See item #207.
Reported by Frank Hartmann.
#16. A note about "&&" predicates (Mike Dimmick)
Mike Dimmick has pointed out a potential pitfall in the use of the
"&&" style predicate. Consider:
r0: (g)? => <<P>>? r1
| ...
;
r1: A | B;
If the context guard g is not a subset of the lookahead context for r1
(in other words g is neither A nor B) then the code may execute r1
even when the lookahead context is not satisfied. This is an error
by the person coding the grammer, and the error should be reported to
the user, but it isn't. expect. Some examples I've run seem to
indicate that such an error actually results in the rule becoming
unreachable.
When g is properly coded the code is correct, the problem is when g
is not properly coded.
A second problem reported by Mike Dimmick is that the test for a
failed validation predicate is equivalent to a test on the predicate
along. In other words, if the "&&" has not been hoisted then it may
falsely report a validation error.
#15. (Changed in MR23) Warning for LT(i), LATEXT(i) in token match actions
An bug (or at least an oddity) is that a reference to LT(1), LA(1),
or LATEXT(1) in an action which immediately follows a token match
in a rule refers to the token matched, not the token which is in
the lookahead buffer. Consider:
r : abc <<action alpha>> D <<action beta>> E;
In this case LT(1) in action alpha will refer to the next token in
the lookahead buffer ("D"), but LT(1) in action beta will refer to
the token matched by D - the preceding token.
A warning has been added which warns users about this when an action
following a token match contains a reference to LT(1), LA(1), or LATEXT(1).
This behavior should be changed, but it appears in too many programs
now. Another problem, perhaps more significant, is that the obvious
fix (moving the consume() call to before the action) could change the
order in which input is requested and output appears in existing programs.
This problem was reported, along with a fix by Benjamin Mandel
(beny@sd.co.il). However, I felt that changing the behavior was too
dangerous for existing code.
#14. Parsing bug in dlg
THM: I have been unable to reproduce this problem.
Reported by Rick Howard Mijenix Corporation (rickh@mijenix.com).
The regular expression parser (in rexpr.c) fails while
trying to parse the following regular expression:
{[a-zA-Z]:}(\\\\[a-zA-Z0-9]*)+
See my comment in the following excerpt from rexpr.c:
/*
* <regExpr> ::= <andExpr> ( '|' {<andExpr>} )*
*
* Return -1 if syntax error
* Return 0 if none found
* Return 1 if a regExrp was found
*/
static
regExpr(g)
GraphPtr g;
{
Graph g1, g2;
if ( andExpr(&g1) == -1 )
{
return -1;
}
while ( token == '|' )
{
int a;
next();
a = andExpr(&g2);
if ( a == -1 ) return -1; /* syntax error below */
else if ( !a ) return 1; /* empty alternative */
g1 = BuildNFA_AorB(g1, g2);
}
if ( token!='\0' ) return -1;
*****
***** It appears to fail here becuause token is 125 - the closing '}'
***** If I change it to:
***** if ( token!='\0' && token!='}' && token!= ')' ) return -1;
*****
***** It succeeds, but I'm not sure this is the corrrect approach.
*****
*g = g1;
return 1;
}
#13. dlg reports an invalid range for: [\0x00-\0xff]
Diagnosed by Piotr Eljasiak (eljasiak@no-spam.zt.gdansk.tpsa.pl):
Fixed in MR16.
#12. Strings containing comment actions
Sequences that looked like C style comments appearing in string
literals are improperly parsed by antlr/dlg.
<< fprintf(out," /* obsolete */ ");
For this case use:
<< fprintf(out," \/\* obsolete \*\/ ");
Reported by K.J. Cummings (cummings@peritus.com).
#11. User hook for deallocation of variables on guess fail
The mechanism outlined in Item #108 works only for
heap allocated variables.
#10. Label re-initialization in ( X {y:Y} )*
If a label assignment is optional and appears in a
(...)* or (...)+ block it will not be reset to NULL
when it is skipped by a subsequent iteration.
Consider the example:
( X { y:Y })* Z
with input:
X Y X Z
The first time through the block Y will be matched and
y will be set to point to the token. On the second
iteration of the (...)* block there is no match for Y.
But y will not be reset to NULL, as the user might
expect, it will contain a reference to the Y that was
matched in the first iteration.
The work-around is to manually reset y:
( X << y = NULL; >> { y:Y } )* Z
or
( X ( y:Y | << y = NULL; >> /* epsilon */ ) )* Z
Reported by Jeff Vincent (JVincent@novell.com).
#9. PCCTAST.h PCCTSAST::setType() is a noop
#8. #tokdefs with ~Token and .
THM: I have been unable to reproduce this problem.
When antlr uses #tokdefs to define tokens the fields of
#errclass and #tokclass do not get properly defined.
When it subsequently attempts to take the complement of
the set of tokens (using ~Token or .) it can refer to
tokens which don't have names, generating a fatal error.
#7. DLG crashes on some invalid inputs
THM: In MR20 have fixed the most common cases.
The following token defintion will cause DLG to crash.
#token "()"
Reported by Mengue Olivier (dolmen@bigfoot.com).
#6. On MS systems \n\r is treated as two new lines
Fixed.
#5. Token expressions in #tokclass
#errclass does not support TOK1..TOK2 or ~TOK syntax.
#tokclass does not support ~TOKEN syntax
A workaround for #errclass TOK1..TOK2 is to use a
#tokclass.
Reported by Dave Watola (dwatola@amtsun.jpl.nasa.gov)
#4. A #tokdef must appear "early" in the grammar file.
The "early" section of the grammar file is the only
place where the following directives may appear:
#header
#first
#tokdefs
#parser
Any other kind of statement signifiies the end of the
"early" section.
#3. Use of PURIFY macro for C++ mode
Item #93 of the CHANGES_FROM_1.33 describes the use of
the PURIFY macro to zero arguments to be passed by
upward inheritance.
#define PURIFY(r, s) memset((char *) &(r), '\0', (s));
This may not be the right thing to do for C++ objects that
have constructors. Reported by Bonny Rais (bonny@werple.net.au).
For those cases one should #define PURIFY to be an empty macro
in the #header or #first actions.
#2. Fixed in 1.33MR10 - See CHANGES_FROM_1.33 Item #80.
#1. The quality of support for systems with 8.3 file names leaves
much to be desired. Since the kit is distributed using the
long file names and the make file uses long file names it requires
some effort to generate. This will probably not be changed due
to the large number of systems already written using the long
file names.

View File

@@ -0,0 +1,21 @@
1. You can control the creator type of generated files by changing a value of
#if control statement.
pccts:h:pcctscfg.h
line 225-231
#if 0
#define MAC_FILE_CREATOR 'MPS ' /* MPW Text files */
#endif
#if 0
#define MAC_FILE_CREATOR 'KAHL' /* THINK C/Symantec C++ Text files */
#endif
#if 0
#define MAC_FILE_CREATOR 'CWIE' /* Metrowerks C/C++ Text files */
#endif
2. If you want to build 68K version. You must convert all source files to Macintosh
format before compile.

View File

@@ -0,0 +1,184 @@
March 95
Version 1.32 of pccts
At the moment this file is available via anonymous FTP at
Node: marvin.ecn.purdue.edu
File: pub/pccts/1.32/NOTES.BCC
Mail corrections or additions to David Seidel <71333.1575@compuserve.com>
===============================================================================
Notes on Building PCCTS 1.32 with Borland C++
David Seidel, Innovative Data Concepts Incorporated
CompuServe: 71333,1575
Internet: 71333.1575@compuserve.com
dseidel@delphi.com
I have gotten ANTLR and DLG to succesfully build with BCC 4.0, but have found
from experience that ANTLR, in particular, is likely to run out of memory
with grammars over a certain size, or with larger values for the -k and -ck
options. Now that BCC 4.02 and the new Borland Power Pack for DOS is now
available, I feel that there is no excuse not to build these tools as
32-bit executables, as they ought to be.
For people without the Power Pack, the makefiles below should be fairly easily
modified to build 16-bit real-mode executables, but I don't really recommend
it. As an alternative, you might consider the highly regarded DJGPP compiler
(a DOS port of the Gnu GCC compiler, with a DOS extender included). Hopefully
some other PCCTS who has DJGPP can provode whatever advice is necessary. The
Watcom compiler is also an excellent possibility (albeit a commercial one),
and I hope to make available Watcom makefiles in the near future.
Here are the makefiles I am using. Both makefiles use a compiler configuration
file that contains compiler switches such as optimization settings. I call
this file bor32.cfg and keep a copy in both the ANTLR and DLG subdirectories.
==== File: bor32.cfg (cut here) ===============================================
-w-
-RT-
-x-
-N-
-k-
-d
-O2-e-l
-Z
-D__STDC__=1
==== End of file bor32.cfg (cut here) =========================================
==== File: antlr\bor32.mak (cut here) =========================================
#
# ANTLR 1.32 Makefile for Borland C++ 4.02 with DPMI 32-bit DOS extender by
# David Seidel
# Innovative Data Concepts Incorporated
# 71333.1575@compuserve.com (or) dseidel@delphi.com
#
# Notes: 1. Compiler switches (optimization etc.) are contained in the
# file bor32.cfg.
# 2. This makefile requires Borland C++ 4.02 or greater with
# the DOS Power Pack add-on package.
# 3. Change the BCCDIR macro below to the topmost directory in
# which BCC is installed on your system.
#
BCCDIR = d:\bc4
CC = bcc32
SET = ..\support\set
PCCTS_H = ..\h
ANTLR = ..\bin\antlr
DLG = ..\bin\dlg
CFLAGS = -I$(BCCDIR)\include -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN \
+bor32.cfg
LIBS = dpmi32 cw32
OBJ_EXT = obj
OBJS = antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj fset.obj \
gen.obj globals.obj hash.obj lex.obj main.obj misc.obj pred.obj dialog.obj \
set.obj
.c.obj:
$(CC) -c $(CFLAGS) {$&.c }
antlr.exe: $(OBJS)
tlink32 @&&|
-Tpe -ax -c -s -L$(BCCDIR)\lib +
$(BCCDIR)\lib\c0x32 $**
$@
$(LIBS)
;
|
copy *.exe ..\bin
# *********** Target list of PC machines ***********
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
# leave this commented out for initial build!
#antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
# $(ANTLR) antlr.g
antlr.$(OBJ_EXT): antlr.c mode.h tokens.h
scan.$(OBJ_EXT): scan.c mode.h tokens.h
# leave this commented out for initial build!
#scan.c mode.h: parser.dlg
# $(DLG) -C2 parser.dlg scan.c
set.$(OBJ_EXT): $(SET)\set.c
$(CC) -c $(CFLAGS) $(SET)\set.c
==== End of file antlr\bor32.mak (cut here) ===================================
==== File: dlg\bor32.mak (cut here) ===========================================
#
# DLG 1.32 Makefile for Borland C++ 4.02 with DPMI 32-bit DOS extender by
# David Seidel
# Innovative Data Concepts Incorporated
# 71333.1575@compuserve.com (or) dseidel@delphi.com
#
# Notes: 1. Compiler switches (optimization etc.) are contained in the
# file bor32.cfg.
# 2. This makefile requires Borland C++ 4.02 or greater with
# the DOS Power Pack add-on package.
# 3. Change the BCCDIR macro below to the topmost directory in
# which BCC is installed on your system.
#
BCCDIR = d:\bc4
CC = bcc32
SET = ..\support\set
PCCTS_H = ..\h
ANTLR = ..\bin\antlr
DLG = ..\bin\dlg
CFLAGS = -I$(BCCDIR)\include -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN \
+bor32.cfg
LIBS = dpmi32 cw32
OBJ_EXT = obj
OBJS = dlg_p.obj dlg_a.obj main.obj err.obj support.obj \
output.obj relabel.obj automata.obj set.obj
.c.obj:
$(CC) -c $(CFLAGS) {$&.c }
dlg.exe : $(OBJS)
tlink32 @&&|
-Tpe -ax -c -s -L$(BCCDIR)\lib +
c0x32 $**
$@
$(LIBS)
;
|
copy *.exe ..\bin
dlg_p.obj: dlg_p.c
dlg_a.obj: dlg_a.c
main.obj: main.c
err.obj: err.c
support.obj: support.c
output.obj: output.c
relabel.obj: relabel.c
automata.obj: automata.c
set.$(OBJ_EXT): $(SET)\set.c
$(CC) -c $(CFLAGS) $(SET)\set.c
==== End of file dlg\bor32.mak (cut here) =====================================

View File

@@ -0,0 +1,189 @@
Microsoft Visual C Stuff
[Tom Moog 2-Oct-98
Users of Microsoft Visual C++ should download a separate
ready-to-run zip file from my web site. It contains
binaries, static library, and a sample project.
]
[
Two notes added by Tom Moog 23-Sep-97. I believe the *.dsp and
*.mak files that were once at the end of this file are now obsolete.
The following MSVC .dsp and .mak files for pccts and sorcerer
were contributed by Stanislaw Bochnak (S.Bochnak@microtool.com.pl)
and Jeff Vincent (jvincent@novell.com)
PCCTS Distribution Kit
----------------------
pccts/antlr/AntlrMSVC50.dsp
pccts/antlr/AntlrMSVC50.mak
pccts/dlg/DlgMSVC50.dsp
pccts/dlg/DlgMSVC50.mak
pccts/support/genmk/watgenmk.mak
pccts/support/msvc.dsp
Sorcerer Distribution Kit
-------------------------
pccts/sorcerer/SorcererMSVC50.dsp
pccts/sorcerer/SorcererMSVC50.mak
pccts/sorcerer/lib/msvc.dsp
I do not have an MS based computer. If you discover problems
please report them so as to save trouble for others in the future.
]
[
Modified by Terence Parr (September 1995) to change .C to .cpp
]
[
This file contains notes on MSVC for Windows NT console execs by Dave
Seidel and an explanation of flags etc.. by John Hall; good luck,
Terence
]
===============================================================================
Date: Sat, 31 Dec 1994 11:40:36 -0500 (EST)
From: David Seidel <75342.2034@compuserve.com>
I've succesfully build 1.31b3 with djgpp for DOS and MSVC 2.0 for Windows
NT. The only (minor) problem I had was that GNU make (version 3.71, in the
djgpp port) complained about "multiple targets" in both the antlr and dlg
makefiles. I got around the error by, in each makefile, commenting out the
$(SRC) dependency, for example:
antlr: $(OBJ) #$(SRC)
I don't know why this is happenning, since you haven't changed that part of
the makefile at all, and I think this used to work ok...
Here are the makefiles I built from within the MSVC 2.0 environment for antlr
and dlg and Windows NT console executables. Please feel free to pass them
on. Of course, as soon as 1.31 "goes gold", I will send you nice new
binaries. I'm not going to bother to keep doing both Borland and djgpp for
DOS however. Instead, I'll just keep the djgpp version up to date and also
provide WinNT binaries.
Dave
===============================================================================
How to port PCCTS 1.10 (and 1.32 hopefully) to Visual C++
By
John Hall <jhall@ivy.wpi.edu>
Here is how to compile an ANTLR grammar in Visual C++. These steps
describe how to have your ANTLR grammar parse the input file the user
selects when they choose File Open in your Windows application. (Even
if you aren't using Visual C++, the steps should be portable enough to
other compilers.)
* Make sure that ANTLR and DLG generate ANSI code (use the -ga
switch).
* Set the following compiler flags in Visual C++ (these are in the
Memory Model category of the compiler options in the Project
Options menu):
FLAG MEANING
==== ==============================================================
/AL Large memory model (multiple data segments; data items must be
smaller than 64K).
/Gtn Allocates all items whose size is greater than or equal to n
in a new data segment. (I let n be 256: /Gt256.)
/Gx- All references to data items are done with far addressing in
case they are placed in a far segment.
* Add the following member variable to the attributes section of your
derived CDocument class (you will need to make sure you also
include stdio.h):
FILE *fp;
* Add the following method to your derived CDocument class:
BOOL CAppDoc::OnOpenDocument(const char* pszPathName)
{
// Call CDocument's OnOpenDocument to do housekeeping for us
// DON'T add anything to the loading section of Serialize
if (!CDocument::OnOpenDocument(pszPathName))
return FALSE;
// Open input file
if ((fp = fopen(pszPathName, "r")) == NULL)
return FALSE;
// Parse input file
ANTLR(start(), fp);
// Close input file
fclose(fp);
return TRUE;
}
(Note: additional code may be necessary, depending on your parser.
For example, if your parser uses PCCTS's symbol table library, you
will need to insert calls to zzs_init and zzs_done.)
* Compile the generated C files as C++ files. (I renamed the files
to have a .CPP extension to fool Visual C++ into thinking they were
C++ files. One might also use the /Tp switch, but that switch
requires you separately include the filename.) [I used this step
as an easy out for all the external linking errors I was getting
that I couldn't fix by declaring things extern "C".]
* Make sure the __STDC__ portion of the generated files gets
compiled. (Either define __STDC__ yourself or else change all
occurrences of __STDC__ to __cplusplus in the generated files. You
can define __STDC__ in the Preprocessor category of the compiler
options.)
================================================================
= Note 23-Sep-97: This is probably not necessary any more. =
= With 1.33MRxxx the use of __STDC__ was replaced with the =
= macro __USE_PROTOS to control the compilation of prototypes. =
================================================================
That last step is important for Visual C++, but may not apply to other
compilers. For C++ compilers, whether __STDC__ is defined is
implementation dependent (ARM, page 379). Apparently, Visual C++ does
not to define it; it also does not support "old style" C function
definitions (which is okay, according to page 404 of the ARM). Those
two things together caused problems when trying to port the code.
When it saw this:
#ifdef __STDC__
void
globals(AST **_root)
#else
globals(_root)
AST **_root;
#endif
it skipped the __STDC__ section and tried to process the "old style"
function definition, where it choked.
When you finally get your parser to compile and link without error,
you may get General Protection Fault errors at run time. The problem
I had was that a NULL was passed to a variable argument function
without an explicit cast. The function grabbed a pointer (32-bits)
off the stack using va_arg, but the NULL was passed silently as the
integer 0 (16 bits), making the resulting pointer was invalid. (This
was in PCCTS's sample C parser.)
There is one other thing I might suggest to help you avoid a run-time
error. Make sure you redefine the default error reporting function,
zzsyn. To do this, put "#define USER_ZZSYN" in your #header section
and put your own zzsyn somewhere. You can then pop up a MessageBox or
print the error to some output window.
===============================================================================

View File

@@ -0,0 +1,159 @@
Parr Research Corporation
with
Purdue University Electrical Engineering
and
University of Minnesota, AHPCRC
Terence Parr
Russell Quong
Will Cohen
Hank Dietz
A central place for information about PCCTS 1.33 is:
http://www.polhode.com/pccts.html
The maintenance release is available from:
http://www.polhode.com/pccts133mr.zip
There is a ready-to-run version for win32 for Microsoft Visual Studio
at the same site. It is available from:
http://www.polhode.com/win32.zip
New users should visit http://www.polhode.com/pccts.html in
order to get the following document:
"Notes For New Users of PCCTS"
This is a Postscript file of about 40 pages which is extremely
useful for someone starting out. It is a based on 1.33mr21
When you have a little more experience, be sure to review the
following documents in the distribution kit:
CHANGES_FROM_133.txt
CHANGES_FROM_133_BEFORE_MR13.txt
KNOWN_PROBLEMS.txt
-------------------------------------------------------------------------
INSTALLATION (Unix)
-------------------------------------------------------------------------
0. Download http://www.polhode.com/pccts133mr.zip
1. Unzip the distribution kit to your preferred location.
If there are newline problems try using zip -a ...
2. cd to the main pccts directory.
3. make
This will create:
antlr
dlg
sorcerer
genmk
4. Copy to /usr/local/bin or /usr/local/bin if you like. If you
don't wish to then add pccts/bin to your path.
5. To get an up-to-date list of program options execute the
program with no command line options. To get up-to-date
documentation read CHANGES_FROM_133*.txt and KNOWN_PROBLEMS.txt
at:
http://www.polhode.com/pccts.html
6. You need not create a library. The makefile created by genmk
assumes that the files are not part of a library.
If you wish to create a library from elements of pccts/h:
If the first letter of the filename is lowercase (uppercase) it is
related to the code generated using the pccts C mode (C++ mode).
Some of the .c and .cpp files in the h directory are not meant to
be placed in a library and will not compile because they are meant
to be #include in pccts generated files which are grammar specific.
For C++ users place the following elements in the library:
AParser.cpp
ASTBase.cpp
ATokenBuffer.cpp
BufFileInput.cpp (optional)
DLexerBase.cpp
PCCTSAST.cpp
SList.cpp
-------------------------------------------------------------------------
INSTALLATION (Win32)
-------------------------------------------------------------------------
I've tried to keep the win32 kit to the minimum necessary to get
up and running. The complete kit contains additional information
(some historical), source code, and DevStudio projects for
rebuilding pccts from the source code.
The kit is now distributed with both MSVC 5 and MSVC6 style projects.
0. Download http://www.polhode.com/win32.zip.
You may also wish to download:
http://www.polhode.com/CHANGES_FROM_133.txt
http://www.polhode.com/CHANGES_FROM_133_BEFORE_MR13.txt
http://www.polhode.com/KNOWN_PROBLEMS.txt
1. Unzip the distribution kit to your preferred location.
This will create:
a pccts directory tree
pccts/bin/*.exe
pccts/lib/*.lib
pccts/h/*
sorcerer/lib/*
sorcerer/h/*
an example directory tree
pccts\example\calcAST\*
pccts\example\simple\*
2. Define the environment variable PCCTS to point to the main
pccts directory.
3. Try building the simple project: pccts\example\simple\simple50.dsw
or simple60.dsw.
4. Try building the complex project: pccts\example\calcAST\calcAST50.dsw
or calcAST60.dsw.
-------------------------------------------------------------------------
INSTALLATION (DEC/VMS)
-------------------------------------------------------------------------
DEC/VMS support added by Pi<50>ronne Jean-Fran<61>ois (jfp@altavista.net)
0. Download http://www.polhode.com/pccts133mr.zip
1. Unzip the distribution kit to your preferred location.
2. set default to the main pccts directory.
3. @makefile.vms
This will create in directory [.bin]:
antlr.exe
dlg.exe
sorcerer.exe
genmk.exe
5. To get an up-to-date list of program options execute the
program with no command line options. To get up-to-date
documentation read CHANGES_FROM_133*.txt and KNOWN_PROBLEMS.txt
at http://www.polhode.com/pccts.html.

View File

@@ -0,0 +1,26 @@
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.
ANTLR 1.33
Terence Parr
Parr Research Corporation
with Purdue University and AHPCRC, University of Minnesota
1989-1995

View File

@@ -0,0 +1,233 @@
# PCCTS directory
# You will need to set the LIB variable similar to this.
# LIB="C:/Program Files/Microsoft Visual Studio .NET 2003/Vc7/lib;c:/Microsoft Visual Studio .NET 2003/Vc7/PlatformSDK/Lib"
# PCCTS_HOME=<your PCCTS_HOME>
PCCTS_HOME=$(WORKSPACE)\Tools\Source\TianoTools\Pccts
ANTLR_SRC=$(PCCTS_HOME)\antlr
PCCTS_H=$(PCCTS_HOME)\h
# Support directories
SET=$(PCCTS_HOME)\support\set
# Compiler stuff
CC = cl
CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
-D "ZZLEXBUFSIZE=65536" /D "LONGFILENAMES" /Zi /W3 -D__USE_PROTOS /wd4700
ANTLR_OBJS = antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
misc.obj pred.obj egman.obj mrhoist.obj fcache.obj
SUPPORT_OBJS = set.obj
# Dependencies
$(WORKSPACE)\Tools\bin\antlr.exe: $(ANTLR_OBJS) $(SUPPORT_OBJS)
$(CC) $(CFLAGS) -o antlr.exe $(ANTLR_OBJS) $(SUPPORT_OBJS)
del *.obj
move antlr.exe $(WORKSPACE)\Tools\bin
antlr.obj: $(ANTLR_SRC)\antlr.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\mode.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(ANTLR_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\antlr.c
scan.obj: $(ANTLR_SRC)\scan.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgauto.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\mode.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(ANTLR_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\scan.c
err.obj: $(ANTLR_SRC)\err.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(PCCTS_H)\err.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(ANTLR_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\err.c
bits.obj: $(ANTLR_SRC)\bits.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\bits.c
build.obj: $(ANTLR_SRC)\build.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\build.c
fset2.obj: $(ANTLR_SRC)\fset2.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\fset2.c
fset.obj: $(ANTLR_SRC)\fset.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\fset.c
gen.obj: $(ANTLR_SRC)\gen.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\gen.c
globals.obj: $(ANTLR_SRC)\globals.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\globals.c
hash.obj: $(ANTLR_SRC)\hash.c \
$(PCCTS_H)\config.h \
$(ANTLR_SRC)\hash.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\hash.c
lex.obj: $(ANTLR_SRC)\lex.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\lex.c
main.obj: $(ANTLR_SRC)\main.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\mode.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\stdpccts.h \
$(ANTLR_SRC)\syn.h \
$(ANTLR_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\main.c
misc.obj: $(ANTLR_SRC)\misc.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\misc.c
pred.obj: $(ANTLR_SRC)\pred.c \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\pred.c
egman.obj: $(ANTLR_SRC)\egman.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\egman.c
mrhoist.obj: $(ANTLR_SRC)\mrhoist.c \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\mrhoist.c
fcache.obj: $(ANTLR_SRC)\fcache.c \
$(ANTLR_SRC)\generic.h \
$(ANTLR_SRC)\hash.h \
$(ANTLR_SRC)\proto.h \
$(ANTLR_SRC)\syn.h \
$(CC) -c $(CFLAGS) $(ANTLR_SRC)\fcache.c
set.obj: $(SET)\set.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(CC) -c $(CFLAGS) $(SET)\set.c
clean:
del *.obj
distclean:
del *.obj
del $(WORKSPACE)\Tools\bin\antlr.exe

View File

@@ -0,0 +1,101 @@
# Target: antlrPPC
# Sources: ::support:set:set.c
# antlr.c
# bits.c
# build.c
# egman.c
# err.c
# fcache.c
# fset2.c
# fset.c
# gen.c
# globals.c
# hash.c
# lex.c
# main.c
# misc.c
# mrhoist.c
# pred.c
# scan.c
# Created: Sunday, May 17, 1998 10:24:53 PM
# Author: Kenji Tanaka
MAKEFILE = antlrPPC.make
<EFBFBD>MondoBuild<EFBFBD> = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified
Includes = <20>
-i "::h:" <20>
-i "::support:set:"
Sym<EFBFBD>PPC =
ObjDir<EFBFBD>PPC = :Obj:
PPCCOptions = {Includes} {Sym<EFBFBD>PPC} -w off -d MPW -d __STDC__=1 -d USER_ZZSYN
Objects<EFBFBD>PPC = <20>
"{ObjDir<69>PPC}set.c.x" <20>
"{ObjDir<69>PPC}antlr.c.x" <20>
"{ObjDir<69>PPC}bits.c.x" <20>
"{ObjDir<69>PPC}build.c.x" <20>
"{ObjDir<69>PPC}egman.c.x" <20>
"{ObjDir<69>PPC}err.c.x" <20>
"{ObjDir<69>PPC}fcache.c.x" <20>
"{ObjDir<69>PPC}fset2.c.x" <20>
"{ObjDir<69>PPC}fset.c.x" <20>
"{ObjDir<69>PPC}gen.c.x" <20>
"{ObjDir<69>PPC}globals.c.x" <20>
"{ObjDir<69>PPC}hash.c.x" <20>
"{ObjDir<69>PPC}lex.c.x" <20>
"{ObjDir<69>PPC}main.c.x" <20>
"{ObjDir<69>PPC}misc.c.x" <20>
"{ObjDir<69>PPC}mrhoist.c.x" <20>
"{ObjDir<69>PPC}pred.c.x" <20>
"{ObjDir<69>PPC}scan.c.x"
antlrPPC <EFBFBD><EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} {Objects<EFBFBD>PPC}
PPCLink <EFBFBD>
-o {Targ} {Sym<EFBFBD>PPC} <EFBFBD>
{Objects<EFBFBD>PPC} <EFBFBD>
-t 'MPST' <EFBFBD>
-c 'MPS ' <EFBFBD>
"{SharedLibraries}InterfaceLib" <EFBFBD>
"{SharedLibraries}StdCLib" <EFBFBD>
#"{SharedLibraries}MathLib" <20>
"{PPCLibraries}StdCRuntime.o" <20>
"{PPCLibraries}PPCCRuntime.o" <20>
"{PPCLibraries}PPCToolLibs.o"
"{ObjDir<69>PPC}set.c.x" <EFBFBD> {<7B>MondoBuild<6C>} "::support:set:set.c"
{PPCC} "::support:set:set.c" -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}antlr.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} antlr.c
{PPCC} antlr.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}bits.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} bits.c
{PPCC} bits.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}build.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} build.c
{PPCC} build.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}egman.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} egman.c
{PPCC} egman.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}err.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} err.c
{PPCC} err.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}fcache.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} fcache.c
{PPCC} fcache.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}fset2.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} fset2.c
{PPCC} fset2.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}fset.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} fset.c
{PPCC} fset.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}gen.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} gen.c
{PPCC} gen.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}globals.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} globals.c
{PPCC} globals.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}hash.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} hash.c
{PPCC} hash.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}lex.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} lex.c
{PPCC} lex.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}main.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} main.c
{PPCC} main.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}misc.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} misc.c
{PPCC} misc.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}mrhoist.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} mrhoist.c
{PPCC} mrhoist.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}pred.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} pred.c
{PPCC} pred.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}scan.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} scan.c
{PPCC} scan.c -o {Targ} {PPCCOptions}
antlrPPC <EFBFBD><EFBFBD> antlr.r
Rez antlr.r -o antlrPPC -a
Install <EFBFBD> antlrPPC
Duplicate -y antlrPPC "{MPW}"Tools:antlr

View File

@@ -0,0 +1,19 @@
ANTLR 1.33
This directory contains the files necessary to build ANTLR.
If you do a "make scrub", ANTLR will have to run on antlr.g and DLG
will have to run on parser.dlg. Either
(1) ANTLR uses the previous antlr in that directory to rebuild itself
(2) Needs to find antlr on the search path
You will find that running "antlr -gh antlr.g" will result in about
10 ambiguity warnings. These are normal. Don't worry.
If you do a "make clean" right after installation, ANTLR and DLG should
not need to run; only the C files will compile.
Don't forget to go into the makefile to uncomment the appropriate
definitions for your OS/architecture/compiler or see the appropriate
NOTES.?? file.

View File

@@ -0,0 +1,209 @@
.TH ANTLR 1 "September 1995" "ANTLR" "PCCTS Manual Pages"
.SH NAME
antlr \- ANother Tool for Language Recognition
.SH SYNTAX
.LP
\fBantlr\fR [\fIoptions\fR] \fIgrammar_files\fR
.SH DESCRIPTION
.PP
\fIAntlr\fP converts an extended form of context-free grammar into a
set of C functions which directly implement an efficient form of
deterministic recursive-descent LL(k) parser. Context-free grammars
may be augmented with predicates to allow semantics to influence
parsing; this allows a form of context-sensitive parsing. Selective
backtracking is also available to handle non-LL(k) and even
non-LALR(k) constructs. \fIAntlr\fP also produces a definition of a
lexer which can be automatically converted into C code for a DFA-based
lexer by \fIdlg\fR. Hence, \fIantlr\fR serves a function much like
that of \fIyacc\fR, however, it is notably more flexible and is more
integrated with a lexer generator (\fIantlr\fR directly generates
\fIdlg\fR code, whereas \fIyacc\fR and \fIlex\fR are given independent
descriptions). Unlike \fIyacc\fR which accepts LALR(1) grammars,
\fIantlr\fR accepts LL(k) grammars in an extended BNF notation \(em
which eliminates the need for precedence rules.
.PP
Like \fIyacc\fR grammars, \fIantlr\fR grammars can use
automatically-maintained symbol attribute values referenced as dollar
variables. Further, because \fIantlr\fR generates top-down parsers,
arbitrary values may be inherited from parent rules (passed like
function parameters). \fIAntlr\fP also has a mechanism for creating
and manipulating abstract-syntax-trees.
.PP
There are various other niceties in \fIantlr\fR, including the ability to
spread one grammar over multiple files or even multiple grammars in a single
file, the ability to generate a version of the grammar with actions stripped
out (for documentation purposes), and lots more.
.SH OPTIONS
.IP "\fB-ck \fIn\fR"
Use up to \fIn\fR symbols of lookahead when using compressed (linear
approximation) lookahead. This type of lookahead is very cheap to
compute and is attempted before full LL(k) lookahead, which is of
exponential complexity in the worst case. In general, the compressed
lookahead can be much deeper (e.g, \f(CW-ck 10\fP) than the full
lookahead (which usually must be less than 4).
.IP \fB-CC\fP
Generate C++ output from both ANTLR and DLG.
.IP \fB-cr\fP
Generate a cross-reference for all rules. For each rule, print a list
of all other rules that reference it.
.IP \fB-e1\fP
Ambiguities/errors shown in low detail (default).
.IP \fB-e2\fP
Ambiguities/errors shown in more detail.
.IP \fB-e3\fP
Ambiguities/errors shown in excruciating detail.
.IP "\fB-fe\fP file"
Rename \fBerr.c\fP to file.
.IP "\fB-fh\fP file"
Rename \fBstdpccts.h\fP header (turns on \fB-gh\fP) to file.
.IP "\fB-fl\fP file"
Rename lexical output, \fBparser.dlg\fP, to file.
.IP "\fB-fm\fP file"
Rename file with lexical mode definitions, \fBmode.h\fP, to file.
.IP "\fB-fr\fP file"
Rename file which remaps globally visible symbols, \fBremap.h\fP, to file.
.IP "\fB-ft\fP file"
Rename \fBtokens.h\fP to file.
.IP \fB-ga\fP
Generate ANSI-compatible code (default case). This has not been
rigorously tested to be ANSI XJ11 C compliant, but it is close. The
normal output of \fIantlr\fP is currently compilable under both K&R,
ANSI C, and C++\(emthis option does nothing because \fIantlr\fP
generates a bunch of #ifdef's to do the right thing depending on the
language.
.IP \fB-gc\fP
Indicates that \fIantlr\fP should generate no C code, i.e., only
perform analysis on the grammar.
.IP \fB-gd\fP
C code is inserted in each of the \fIantlr\fR generated parsing functions to
provide for user-defined handling of a detailed parse trace. The inserted
code consists of calls to the user-supplied macros or functions called
\fBzzTRACEIN\fR and \fBzzTRACEOUT\fP. The only argument is a
\fIchar *\fR pointing to a C-style string which is the grammar rule
recognized by the current parsing function. If no definition is given
for the trace functions, upon rule entry and exit, a message will be
printed indicating that a particular rule as been entered or exited.
.IP \fB-ge\fP
Generate an error class for each non-terminal.
.IP \fB-gh\fP
Generate \fBstdpccts.h\fP for non-ANTLR-generated files to include.
This file contains all defines needed to describe the type of parser
generated by \fIantlr\fP (e.g. how much lookahead is used and whether
or not trees are constructed) and contains the \fBheader\fP action
specified by the user.
.IP \fB-gk\fP
Generate parsers that delay lookahead fetches until needed. Without
this option, \fIantlr\fP generates parsers which always have \fIk\fP
tokens of lookahead available.
.IP \fB-gl\fP
Generate line info about grammar actions in C parser of the form
\fB#\ \fIline\fP\ "\fIfile\fP"\fR which makes error messages from
the C/C++ compiler make more sense as they will \*Qpoint\*U into the
grammar file not the resulting C file. Debugging is easier as well,
because you will step through the grammar not C file.
.IP \fB-gs\fR
Do not generate sets for token expression lists; instead generate a
\fB||\fP-separated sequence of \fBLA(1)==\fItoken_number\fR. The
default is to generate sets.
.IP \fB-gt\fP
Generate code for Abstract-Syntax Trees.
.IP \fB-gx\fP
Do not create the lexical analyzer files (dlg-related). This option
should be given when the user wishes to provide a customized lexical
analyzer. It may also be used in \fImake\fR scripts to cause only the
parser to be rebuilt when a change not affecting the lexical structure
is made to the input grammars.
.IP "\fB-k \fIn\fR"
Set k of LL(k) to \fIn\fR; i.e. set tokens of look-ahead (default==1).
.IP "\fB-o\fP dir
Directory where output files should go (default="."). This is very
nice for keeping the source directory clear of ANTLR and DLG spawn.
.IP \fB-p\fP
The complete grammar, collected from all input grammar files and
stripped of all comments and embedded actions, is listed to
\fBstdout\fP. This is intended to aid in viewing the entire grammar
as a whole and to eliminate the need to keep actions concisely stated
so that the grammar is easier to read. Hence, it is preferable to
embed even complex actions directly in the grammar, rather than to
call them as subroutines, since the subroutine call overhead will be
saved.
.IP \fB-pa\fP
This option is the same as \fB-p\fP except that the output is
annotated with the first sets determined from grammar analysis.
.IP "\fB-prc on\fR
Turn on the computation and hoisting of predicate context.
.IP "\fB-prc off\fR
Turn off the computation and hoisting of predicate context. This
option makes 1.10 behave like the 1.06 release with option \fB-pr\fR
on. Context computation is off by default.
.IP "\fB-rl \fIn\fR
Limit the maximum number of tree nodes used by grammar analysis to
\fIn\fP. Occasionally, \fIantlr\fP is unable to analyze a grammar
submitted by the user. This rare situation can only occur when the
grammar is large and the amount of lookahead is greater than one. A
nonlinear analysis algorithm is used by PCCTS to handle the general
case of LL(k) parsing. The average complexity of analysis, however, is
near linear due to some fancy footwork in the implementation which
reduces the number of calls to the full LL(k) algorithm. An error
message will be displayed, if this limit is reached, which indicates
the grammar construct being analyzed when \fIantlr\fP hit a
non-linearity. Use this option if \fIantlr\fP seems to go out to
lunch and your disk start thrashing; try \fIn\fP=10000 to start. Once
the offending construct has been identified, try to remove the
ambiguity that \fIantlr\fP was trying to overcome with large lookahead
analysis. The introduction of (...)? backtracking blocks eliminates
some of these problems\ \(em \fIantlr\fP does not analyze alternatives
that begin with (...)? (it simply backtracks, if necessary, at run
time).
.IP \fB-w1\fR
Set low warning level. Do not warn if semantic predicates and/or
(...)? blocks are assumed to cover ambiguous alternatives.
.IP \fB-w2\fR
Ambiguous parsing decisions yield warnings even if semantic predicates
or (...)? blocks are used. Warn if predicate context computed and
semantic predicates incompletely disambiguate alternative productions.
.IP \fB-\fR
Read grammar from standard input and generate \fBstdin.c\fP as the
parser file.
.SH "SPECIAL CONSIDERATIONS"
.PP
\fIAntlr\fP works... we think. There is no implicit guarantee of
anything. We reserve no \fBlegal\fP rights to the software known as
the Purdue Compiler Construction Tool Set (PCCTS) \(em 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
commercial 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. As long as these guidelines are followed,
we expect to continue enhancing this system and expect to make other
tools available as they are completed.
.SH FILES
.IP *.c
output C parser.
.IP *.cpp
output C++ parser when C++ mode is used.
.IP \fBparser.dlg\fP
output \fIdlg\fR lexical analyzer.
.IP \fBerr.c\fP
token string array, error sets and error support routines. Not used in
C++ mode.
.IP \fBremap.h\fP
file that redefines all globally visible parser symbols. The use of
the #parser directive creates this file. Not used in
C++ mode.
.IP \fBstdpccts.h\fP
list of definitions needed by C files, not generated by PCCTS, that
reference PCCTS objects. This is not generated by default. Not used in
C++ mode.
.IP \fBtokens.h\fP
output \fI#defines\fR for tokens used and function prototypes for
functions generated for rules.
.SH "SEE ALSO"
.LP
dlg(1), pccts(1)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,787 @@
/*
File: antlrMPW.r
Target: antlr 133MR
Created: Monday, June 15, 1998 4:41:11 AM
Author: Kenji Tanaka (kentar@osa.att.ne.jp)
*/
#include "cmdo.r"
resource 'cmdo' (128, "Antlr") {
{ /* array dialogs: 5 elements */
/* [1] */
295,
"ANTLR -- Purdue Compiler Construction To"
"ol Set (PCCTS) LL(k) parser generator.",
{ /* array itemArray: 12 elements */
/* [1] */
NotDependent {
},
CheckOption {
NotSet,
{18, 23, 33, 223},
"Read grammar from stdin",
"-",
"Read grammar from stdin."
},
/* [2] */
NotDependent {
},
CheckOption {
NotSet,
{38, 23, 53, 310},
"Send grammar.c/grammar.cpp to stdout",
"-stdout",
"Send grammar.c/grammar.cpp to stdout."
},
/* [3] */
NotDependent {
},
MultiFiles {
"Grammar File(s)<29>",
"Choose the grammar specification files y"
"ou wish to have ANTLR process.",
{79, 22, 98, 152},
"Grammar specification:",
"",
MultiInputFiles {
{ /* array MultiTypesArray: 1 elements */
/* [1] */
text
},
".g",
"Files ending in .g",
"All text files"
}
},
/* [4] */
NotDependent {
},
Files {
DirOnly,
OptionalFile {
{58, 168, 74, 298},
{79, 169, 98, 299},
"Output Directory",
":",
"-o",
"",
"Choose the directory where ANTLR will pu"
"t its output.",
dim,
"Output Directory<72>",
"",
""
},
NoMore {
}
},
/* [5] */
NotDependent {
},
Redirection {
StandardOutput,
{126, 27}
},
/* [6] */
NotDependent {
},
Redirection {
DiagnosticOutput,
{126, 178}
},
/* [7] */
NotDependent {
},
TextBox {
gray,
{117, 20, 167, 300},
"Redirection"
},
/* [8] */
NotDependent {
},
NestedDialog {
5,
{20, 324, 40, 460},
"Parse Options<6E>",
"Parse control options may be set with th"
"is button."
},
/* [9] */
NotDependent {
},
NestedDialog {
2,
{50, 324, 70, 460},
"Generate Options<6E>",
"Various command line options may be set "
"with this button."
},
/* [10] */
NotDependent {
},
NestedDialog {
3,
{78, 324, 98, 460},
"More Options<6E>",
"Antlr has ALOT of options. There are eve"
"n more to be found with this button."
},
/* [11] */
NotDependent {
},
NestedDialog {
4,
{106, 324, 126, 460},
"Rename Options<6E>",
"Options for renaming output files may be"
" set with this button."
},
/* [12] */
NotDependent {
},
VersionDialog {
VersionString {
"1.33MR"
},
"PCCTS was written by Terence Parr, Russe"
"ll Quong, Will Cohen, and Hank Dietz: 19"
"89-1998. MPW port by Scott Haney.",
noDialog
}
},
/* [2] */
295,
"Use this dialog to specify command line "
"Generate Options.",
{ /* array itemArray: 15 elements */
/* [1] */
NotDependent {
},
CheckOption {
NotSet,
{18, 25, 33, 225},
"Generate C++ code",
"-CC",
"Generate C++ output from both ANTLR and "
"DLG."
},
/* [2] */
NotDependent {
},
CheckOption {
NotSet,
{38, 25, 53, 225},
"Generate ASTs",
"-gt",
"Generate code for Abstract-Syntax-Trees "
"(ASTs)."
},
/* [3] */
NotDependent {
},
CheckOption {
NotSet,
{58, 25, 73, 225},
"Generate line info",
"-gl",
"If this option is checked, ANTLR will ge"
"nerate line info about grammaractions, t"
"hereby making debugging easier since com"
"pile errors will point to the grammar fi"
"le."
},
/* [4] */
NotDependent {
},
CheckOption {
NotSet,
{78, 25, 93, 225},
"Generate error classes",
"-ge",
"If this option is checked, ANTLR will ge"
"nerate an error class foreach non-termin"
"al."
},
/* [5] */
NotDependent {
},
CheckOption {
NotSet,
{98, 25, 113, 225},
"Don't generate Code",
"-gc",
"If this option is checked, ANTLR will ge"
"nerate no code, i.e. it will only perfor"
"m analysis on the grammar."
},
/* [6] */
NotDependent {
},
CheckOption {
NotSet,
{118, 25, 133, 225},
"Delay lookahead fetches",
"-gk",
"If this option is checked, ANTLR will ge"
"nerate a parser that delays lookahead fe"
"tches until needed."
},
/* [7] */
NotDependent {
},
CheckOption {
NotSet,
{138, 25, 153, 225},
"Use newAST(...)",
"-newAST",
"In C++ mode use \"newAST(...)\" rather tha"
"n \"new AST(...)\""
},
/* [8] */
NotDependent {
},
CheckOption {
NotSet,
{18, 235, 33, 435},
"Support parse traces",
"-gd",
"If this option is checked, ANTLR inserts"
" code in each parsing function to provid"
"e for user-defined handling of a detaile"
"d parse trace. The code consists of call"
"s to zzTRACEIN and zzTRACEOUT."
},
/* [9] */
NotDependent {
},
CheckOption {
NotSet,
{38, 235, 53, 435},
"Generate cross-references",
"-cr",
"If this option is checked, ANTLR will ge"
"nerate a cross reference for all rules. "
"For each rule it will print a list of al"
"l other rules that refrence it."
},
/* [10] */
NotDependent {
},
CheckOption {
NotSet,
{58, 235, 73, 435},
"Don't create Lexer files",
"-gx",
"If this option is checked, ANTLR will no"
"t generate DLG-related output files. Thi"
"s option should be used if one wants a c"
"ustom lexical analyzer or if one has mad"
"e changes to the grammar not affecting t"
"he lexical structure."
},
/* [11] */
NotDependent {
},
CheckOption {
NotSet,
{78, 235, 93, 460},
"Don't generate token expr sets",
"-gs",
"If this option is checked, ANTLR will no"
"t generate sets for token expression set"
"s; instead, it will generate a || separa"
"ted sequence of LA(1)==token #. "
},
/* [12] */
NotDependent {
},
CheckOption {
NotSet,
{98, 235, 113, 460},
"Generate ANSI-compatible",
"-ga",
"Generate ANSI-compatible code (default=F"
"ALSE)"
},
/* [13] */
NotDependent {
},
CheckOption {
NotSet,
{118, 235, 133, 460},
"Don't generate tokens.h",
"-gxt",
"Do not generate tokens.h (default=FALSE)"
},
/* [13] */
NotDependent {
},
CheckOption {
NotSet,
{138, 235, 153, 460},
"Provide \"(alpha)? beta\" info",
"-alpha",
"Provide additional information for \"(alpha)? beta\" error messages"
},
/* [14] */
NotDependent {
},
RegularEntry {
"Tabs(1 to 8):",
{162, 23, 177, 117},
{163, 125, 179, 196},
"",
keepCase,
"-tab",
"Width of tabs (1 to 8) for grammar.c/gra"
"mmar.cpp files."
},
/* [15] */
NotDependent {
},
RegularEntry {
"Function Prefix:",
{161, 236, 177, 342},
{162, 345, 177, 454},
"",
keepCase,
"-gp",
"Prefix all generated rule functions with"
" a string."
}
},
/* [3] */
295,
"Use this dialog to specify still more co"
"mmand line options.",
{ /* array itemArray: 12 elements */
/* [1] */
NotDependent {
},
RadioButtons {
{ /* array radioArray: 3 elements */
/* [1] */
{38, 25, 53, 85}, "None", "", Set, "When this option is selected, ANTLR will"
" not print the grammar to stdout.",
/* [2] */
{38, 100, 53, 160}, "Yes", "-p", NotSet, "When this option is selected, ANTLR will"
" print the grammar, stripped of all acti"
"ons and comments, to stdout.",
/* [3] */
{38, 175, 53, 235}, "More", "-pa", NotSet, "When this option is selected, ANTLR will"
" print the grammar, stripped of all acti"
"ons and comments, to stdout. It will als"
"o annotate the output with the first set"
"s determined from grammar analysis."
}
},
/* [2] */
NotDependent {
},
TextBox {
gray,
{28, 15, 60, 250},
"Grammar Printing"
},
/* [3] */
NotDependent {
},
RadioButtons {
{ /* array radioArray: 3 elements */
/* [1] */
{88, 25, 103, 85}, "Low", "", Set, "When this option is selected, ANTLR will"
" show ambiguities/errors in low detail.",
/* [2] */
{88, 100, 103, 160}, "Medium", "-e2", NotSet, "When this option is selected, ANTLR will"
" show ambiguities/errors in more detail.",
/* [3] */
{88, 175, 103, 235}, "High", "-e3", NotSet, "When this option is selected, ANTLR will"
" show ambiguities/errors in excruciating"
" detail."
}
},
/* [4] */
NotDependent {
},
TextBox {
gray,
{78, 15, 110, 250},
"Error reporting"
},
/* [5] */
NotDependent {
},
CheckOption {
NotSet,
{130, 22, 145, 222},
"More warnings",
"-w2",
"If this option is checked, ANTLR will wa"
"rn if semantic predicates and/or (<28>)? bl"
"ocks are assumed to cover ambiguous alte"
"rnatives."
},
/* [6] */
NotDependent {
},
RegularEntry {
"Report when tnode usage exceeds:",
{162, 23, 180, 253},
{162, 255, 178, 326},
"",
keepCase,
"-treport",
"Report when tnode usage exceeds value du"
"ring ambiguity resolution."
},
/* [7] */
NotDependent {
},
CheckOption {
NotSet,
{40, 292, 55, 431},
"Predicate",
"-info p",
"With the antlr \"-info p\" switch the user"
" will receive information about the pred"
"icate suppression in the generated file."
},
/* [8] */
NotDependent {
},
CheckOption {
NotSet,
{60, 292, 75, 430},
"Tree Nodes",
"-info t",
"Using \"-info t\" gives information about "
"the total number of tnodes created and t"
"he peak number of tnodes."
},
/* [9] */
NotDependent {
},
CheckOption {
NotSet,
{80, 292, 95, 425},
"First/follow",
"-info f",
"first/follow set information."
},
/* [10] */
NotDependent {
},
CheckOption {
NotSet,
{100, 292, 115, 425},
"Monitor progress",
"-info m",
"prints name of each rule as it is starte"
"d and flushes output at start of each rule."
},
/* [11] */
NotDependent {
},
CheckOption {
NotSet,
{120, 292, 135, 416},
"Orphan rules",
"-info o",
"If there is more than one rule which is "
"not referenced by any other rule then al"
"l such rules are listed."
},
/* [12] */
NotDependent {
},
TextBox {
gray,
{28, 279, 147, 451},
"Extra info"
}
},
/* [4] */
295,
"Use this dialog to specify command line "
"options relating to renaming output file"
"s.",
{ /* array itemArray: 7 elements */
/* [1] */
NotDependent {
},
RegularEntry {
"Errors file name:",
{35, 25, 50, 205},
{35, 205, 51, 300},
"err.c",
keepCase,
"-fe",
"This entry specifies the name ANTLR uses"
" for the errors file."
},
/* [2] */
NotDependent {
},
RegularEntry {
"Lexical output name:",
{60, 25, 75, 205},
{60, 205, 76, 300},
"parser.dlg",
keepCase,
"-fl",
"This entry specifies the name ANTLR uses"
" for the lexical output file."
},
/* [3] */
NotDependent {
},
RegularEntry {
"Lexical modes name:",
{85, 25, 100, 205},
{85, 205, 101, 300},
"mode.h",
keepCase,
"-fm",
"This entry specifies the name ANTLR uses"
" for the lexical mode definitions file."
},
/* [4] */
NotDependent {
},
RegularEntry {
"Remap file name:",
{110, 25, 125, 205},
{110, 205, 126, 300},
"remap.h",
keepCase,
"-fr",
"This entry specifies the name ANTLR uses"
" for the file that remaps globally visib"
"le symbols."
},
/* [5] */
NotDependent {
},
RegularEntry {
"Tokens file name:",
{135, 25, 150, 205},
{135, 205, 151, 300},
"tokens.h",
keepCase,
"-ft",
"This entry specifies the name ANTLR uses"
" for the tokens file."
},
/* [6] */
NotDependent {
},
CheckOption {
NotSet,
{160, 25, 175, 175},
"Create std header",
"-gh",
"If this option is checked, ANTLR will cr"
"eate a standard header file named, by de"
"fault 'stdpccts.h'. This name can be alt"
"ered using the entry right next door."
},
/* [7] */
Or {
{ /* array OrArray: 1 elements */
/* [1] */
6
}
},
RegularEntry {
"Std header file name:",
{160, 175, 175, 355},
{160, 355, 176, 450},
"stdpccts.h",
keepCase,
"-fh",
"This entry specifies the name ANTLR uses"
" for the standard header file."
}
},
/* [5] */
295,
"Use this dialog to specify parse options"
".",
{ /* array itemArray: 9 elements */
/* [1] */
NotDependent {
},
RegularEntry {
"Lookahead:",
{23, 27, 38, 152},
{46, 29, 62, 154},
"1",
keepCase,
"-k",
"This entry specifies the number of token"
"s of lookahead."
},
/* [2] */
NotDependent {
},
RegularEntry {
"Compr lookahead:",
{22, 167, 37, 292},
{46, 172, 62, 297},
"",
keepCase,
"-ck",
"This entry specifies the number of token"
"s of lookahead when using compressed (li"
"near approximation) lookahead. In genera"
"l, the compressed lookahead is much deep"
"er than the full lookahead."
},
/* [3] */
NotDependent {
},
RegularEntry {
"Max tree nodes:",
{22, 312, 37, 437},
{46, 315, 62, 445},
"",
keepCase,
"-rl",
"This entry specifies the maximum number "
"of tokens of tree nodes used by the gram"
"mar analysis."
},
/* [4] */
NotDependent {
},
CheckOption {
NotSet,
{76, 25, 91, 350},
"Maintenance Release style hoisting",
"-mrhoist",
"Turn on/off k=1 Maintenance Release styl"
"e hoisting."
},
/* [5] */
NotDependent {
},
CheckOption {
NotSet,
{96, 25, 111, 431},
"EXPERIMENTAL Maintenance Release style h"
"oisting",
"-mrhoistk",
"Turn on/off k>1 EXPERIMENTAL Maintenance"
" Release style hoisting."
},
/* [6] */
NotDependent {
},
CheckOption {
NotSet,
{116, 25, 131, 363},
"Compute context for hoisted predicates",
"-prc on",
"Turn on/off computation of context for h"
"oisted predicates."
},
/* [7] */
NotDependent {
},
RegularEntry {
"Ambiguity aid:",
{140, 27, 155, 125},
{141, 135, 155, 209},
"",
keepCase,
"-aa",
"Ambiguity aid for a rule (rule name or l"
"ine number)."
},
/* [8] */
NotDependent {
},
RegularEntry {
"Limits exp growth:",
{140, 236, 155, 361},
{139, 372, 155, 452},
"",
keepCase,
"-aad",
"Limits exp growth of -aa listing - defau"
"lt=1 (max=ck value)."
},
/* [9] */
NotDependent {
},
CheckOption {
NotSet,
{164, 26, 179, 366},
"Lookahead token may appear multiple time"
"s",
"-aam",
"Lookahead token may appear multiple time"
"s in -aa listing."
}
}
}
};

View File

@@ -0,0 +1,264 @@
ANTLR(1) PCCTS Manual Pages ANTLR(1)
NAME
antlr - ANother Tool for Language Recognition
SYNTAX
antlr [_o_p_t_i_o_n_s] _g_r_a_m_m_a_r__f_i_l_e_s
DESCRIPTION
_A_n_t_l_r converts an extended form of context-free grammar into
a set of C functions which directly implement an efficient
form of deterministic recursive-descent LL(k) parser.
Context-free grammars may be augmented with predicates to
allow semantics to influence parsing; this allows a form of
context-sensitive parsing. Selective backtracking is also
available to handle non-LL(k) and even non-LALR(k) con-
structs. _A_n_t_l_r also produces a definition of a lexer which
can be automatically converted into C code for a DFA-based
lexer by _d_l_g. Hence, _a_n_t_l_r serves a function much like that
of _y_a_c_c, however, it is notably more flexible and is more
integrated with a lexer generator (_a_n_t_l_r directly generates
_d_l_g code, whereas _y_a_c_c and _l_e_x are given independent
descriptions). Unlike _y_a_c_c which accepts LALR(1) grammars,
_a_n_t_l_r accepts LL(k) grammars in an extended BNF notation -
which eliminates the need for precedence rules.
Like _y_a_c_c grammars, _a_n_t_l_r grammars can use automatically-
maintained symbol attribute values referenced as dollar
variables. Further, because _a_n_t_l_r generates top-down
parsers, arbitrary values may be inherited from parent rules
(passed like function parameters). _A_n_t_l_r also has a mechan-
ism for creating and manipulating abstract-syntax-trees.
There are various other niceties in _a_n_t_l_r, including the
ability to spread one grammar over multiple files or even
multiple grammars in a single file, the ability to generate
a version of the grammar with actions stripped out (for
documentation purposes), and lots more.
OPTIONS
-ck _n
Use up to _n symbols of lookahead when using compressed
(linear approximation) lookahead. This type of looka-
head is very cheap to compute and is attempted before
full LL(k) lookahead, which is of exponential complex-
ity in the worst case. In general, the compressed loo-
kahead can be much deeper (e.g, -ck 10) _t_h_a_n _t_h_e _f_u_l_l
_l_o_o_k_a_h_e_a_d (_w_h_i_c_h _u_s_u_a_l_l_y _m_u_s_t _b_e _l_e_s_s _t_h_a_n _4).
-CC Generate C++ output from both ANTLR and DLG.
-cr Generate a cross-reference for all rules. For each
rule, print a list of all other rules that reference
it.
-e1 Ambiguities/errors shown in low detail (default).
-e2 Ambiguities/errors shown in more detail.
-e3 Ambiguities/errors shown in excruciating detail.
-fe file
Rename err.c to file.
-fh file
Rename stdpccts.h header (turns on -gh) to file.
-fl file
Rename lexical output, parser.dlg, to file.
-fm file
Rename file with lexical mode definitions, mode.h, to
file.
-fr file
Rename file which remaps globally visible symbols,
remap.h, to file.
-ft file
Rename tokens.h to file.
-ga Generate ANSI-compatible code (default case). This has
not been rigorously tested to be ANSI XJ11 C compliant,
but it is close. The normal output of _a_n_t_l_r is
currently compilable under both K&R, ANSI C, and C++-
this option does nothing because _a_n_t_l_r generates a
bunch of #ifdef's to do the right thing depending on
the language.
-gc Indicates that _a_n_t_l_r should generate no C code, i.e.,
only perform analysis on the grammar.
-gd C code is inserted in each of the _a_n_t_l_r generated pars-
ing functions to provide for user-defined handling of a
detailed parse trace. The inserted code consists of
calls to the user-supplied macros or functions called
zzTRACEIN and zzTRACEOUT. The only argument is a _c_h_a_r
* pointing to a C-style string which is the grammar
rule recognized by the current parsing function. If no
definition is given for the trace functions, upon rule
entry and exit, a message will be printed indicating
that a particular rule as been entered or exited.
-ge Generate an error class for each non-terminal.
-gh Generate stdpccts.h for non-ANTLR-generated files to
include. This file contains all defines needed to
describe the type of parser generated by _a_n_t_l_r (e.g.
how much lookahead is used and whether or not trees are
constructed) and contains the header action specified
by the user.
-gk Generate parsers that delay lookahead fetches until
needed. Without this option, _a_n_t_l_r generates parsers
which always have _k tokens of lookahead available.
-gl Generate line info about grammar actions in C parser of
the form # _l_i_n_e "_f_i_l_e" which makes error messages from
the C/C++ compiler make more sense as they will point
into the grammar file not the resulting C file.
Debugging is easier as well, because you will step
through the grammar not C file.
-gs Do not generate sets for token expression lists;
instead generate a ||-separated sequence of
LA(1)==_t_o_k_e_n__n_u_m_b_e_r. The default is to generate sets.
-gt Generate code for Abstract-Syntax Trees.
-gx Do not create the lexical analyzer files (dlg-related).
This option should be given when the user wishes to
provide a customized lexical analyzer. It may also be
used in _m_a_k_e scripts to cause only the parser to be
rebuilt when a change not affecting the lexical struc-
ture is made to the input grammars.
-k _n Set k of LL(k) to _n; i.e. set tokens of look-ahead
(default==1).
-o dir
Directory where output files should go (default=".").
This is very nice for keeping the source directory
clear of ANTLR and DLG spawn.
-p The complete grammar, collected from all input grammar
files and stripped of all comments and embedded
actions, is listed to stdout. This is intended to aid
in viewing the entire grammar as a whole and to elim-
inate the need to keep actions concisely stated so that
the grammar is easier to read. Hence, it is preferable
to embed even complex actions directly in the grammar,
rather than to call them as subroutines, since the sub-
routine call overhead will be saved.
-pa This option is the same as -p except that the output is
annotated with the first sets determined from grammar
analysis.
-prc on
Turn on the computation and hoisting of predicate con-
text.
-prc off
Turn off the computation and hoisting of predicate con-
text. This option makes 1.10 behave like the 1.06
release with option -pr on. Context computation is off
by default.
-rl _n
Limit the maximum number of tree nodes used by grammar
analysis to _n. Occasionally, _a_n_t_l_r is unable to
analyze a grammar submitted by the user. This rare
situation can only occur when the grammar is large and
the amount of lookahead is greater than one. A non-
linear analysis algorithm is used by PCCTS to handle
the general case of LL(k) parsing. The average com-
plexity of analysis, however, is near linear due to
some fancy footwork in the implementation which reduces
the number of calls to the full LL(k) algorithm. An
error message will be displayed, if this limit is
reached, which indicates the grammar construct being
analyzed when _a_n_t_l_r hit a non-linearity. Use this
option if _a_n_t_l_r seems to go out to lunch and your disk
start thrashing; try _n=10000 to start. Once the
offending construct has been identified, try to remove
the ambiguity that _a_n_t_l_r was trying to overcome with
large lookahead analysis. The introduction of (...)?
backtracking blocks eliminates some of these problems -
_a_n_t_l_r does not analyze alternatives that begin with
(...)? (it simply backtracks, if necessary, at run
time).
-w1 Set low warning level. Do not warn if semantic
predicates and/or (...)? blocks are assumed to cover
ambiguous alternatives.
-w2 Ambiguous parsing decisions yield warnings even if
semantic predicates or (...)? blocks are used. Warn if
predicate context computed and semantic predicates
incompletely disambiguate alternative productions.
- Read grammar from standard input and generate stdin.c
as the parser file.
SPECIAL CONSIDERATIONS
_A_n_t_l_r works... we think. There is no implicit guarantee of
anything. We reserve no legal rights to the software known
as 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 commercial 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 pro-
ject, 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. As long as these
guidelines are followed, we expect to continue enhancing
this system and expect to make other tools available as they
are completed.
FILES
*.c output C parser.
*.cpp
output C++ parser when C++ mode is used.
parser.dlg
output _d_l_g lexical analyzer.
err.c
token string array, error sets and error support rou-
tines. Not used in C++ mode.
remap.h
file that redefines all globally visible parser sym-
bols. The use of the #parser directive creates this
file. Not used in C++ mode.
stdpccts.h
list of definitions needed by C files, not generated by
PCCTS, that reference PCCTS objects. This is not gen-
erated by default. Not used in C++ mode.
tokens.h
output #_d_e_f_i_n_e_s for tokens used and function prototypes
for functions generated for rules.
SEE ALSO
dlg(1), pccts(1)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,813 @@
/*
* build.c -- functions associated with building syntax diagrams.
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#include "dlgdef.h"
#define SetBlk(g, t, approx, first_set_symbol) { \
((Junction *)g.left)->jtype = t; \
((Junction *)g.left)->approx = approx; \
((Junction *)g.left)->pFirstSetSymbol = first_set_symbol; \
((Junction *)g.left)->end = (Junction *) g.right; \
((Junction *)g.right)->jtype = EndBlk;}
/* Add the parameter string 'parm' to the parms field of a block-type junction
* g.left points to the sentinel node on a block. i.e. g.left->p1 points to
* the actual junction with its jtype == some block-type.
*/
void
#ifdef __USE_PROTOS
addParm( Node *p, char *parm )
#else
addParm( p, parm )
Node *p;
char *parm;
#endif
{
char *q = (char *) malloc( strlen(parm) + 1 );
require(p!=NULL, "addParm: NULL object\n");
require(q!=NULL, "addParm: unable to alloc parameter\n");
strcpy(q, parm);
if ( p->ntype == nRuleRef )
{
((RuleRefNode *)p)->parms = q;
}
else if ( p->ntype == nJunction )
{
((Junction *)p)->parm = q; /* only one parameter allowed on subrules */
}
else fatal_internal("addParm: invalid node for adding parm");
}
/*
* Build an action node for the syntax diagram
*
* buildAction(ACTION) ::= --o-->ACTION-->o--
*
* Where o is a junction node.
*/
Graph
#ifdef __USE_PROTOS
buildAction( char *action, int file, int line, int is_predicate )
#else
buildAction( action, file, line, is_predicate )
char *action;
int file;
int line;
int is_predicate;
#endif
{
Junction *j1, *j2;
Graph g;
ActionNode *a;
require(action!=NULL, "buildAction: invalid action");
j1 = newJunction();
j2 = newJunction();
a = newActionNode();
a->action = (char *) malloc( strlen(action)+1 );
require(a->action!=NULL, "buildAction: cannot alloc space for action\n");
strcpy(a->action, action);
j1->p1 = (Node *) a;
a->next = (Node *) j2;
a->is_predicate = is_predicate;
if (is_predicate) {
PredEntry *predEntry;
char *t;
char *key;
char *u;
int inverted=0;
t=key=(char *)calloc(1,strlen(a->action)+1);
for (u=a->action; *u != '\0' ; u++) {
if (*u != ' ') {
if (t==key && *u=='!') {
inverted=!inverted;
} else {
*t++=*u;
};
};
};
*t='\0';
predEntry=(PredEntry *)hash_get(Pname,key);
a->predEntry=predEntry;
if (predEntry != NULL) a->inverted=inverted;
} else {
/* MR12c */ char *strStart=a->action;
/* MR12c */ char *strEnd;
/* MR12c */ strEnd=strStart+strlen(strStart)-1;
/* MR12c */ for ( ; strEnd >= strStart && isspace(*strEnd); strEnd--) *strEnd=0;
/* MR12c */ while (*strStart != '\0' && isspace(*strStart)) strStart++;
/* MR12c */ if (ci_strequ(strStart,"nohoist")) {
/* MR12c */ a->noHoist=1;
/* MR12c */ }
}
g.left = (Node *) j1; g.right = (Node *) j2;
a->file = file;
a->line = line;
a->rname = CurRule; /* MR10 */
return g;
}
/*
* Build a token node for the syntax diagram
*
* buildToken(TOKEN) ::= --o-->TOKEN-->o--
*
* Where o is a junction node.
*/
Graph
#ifdef __USE_PROTOS
buildToken( char *text )
#else
buildToken( text )
char *text;
#endif
{
Junction *j1, *j2;
Graph g;
TokNode *t;
require(text!=NULL, "buildToken: invalid token name");
j1 = newJunction();
j2 = newJunction();
t = newTokNode();
t->altstart = CurAltStart;
if ( *text == '"' ) {t->label=FALSE; t->token = addTexpr( text );}
else {t->label=TRUE; t->token = addTname( text );}
j1->p1 = (Node *) t;
t->next = (Node *) j2;
g.left = (Node *) j1; g.right = (Node *) j2;
return g;
}
/*
* Build a wild-card node for the syntax diagram
*
* buildToken(TOKEN) ::= --o-->'.'-->o--
*
* Where o is a junction node.
*/
Graph
#ifdef __USE_PROTOS
buildWildCard( char *text )
#else
buildWildCard( text )
char *text;
#endif
{
Junction *j1, *j2;
Graph g;
TokNode *t;
TCnode *w;
TermEntry *p;
require(text!=NULL, "buildWildCard: invalid token name");
j1 = newJunction();
j2 = newJunction();
t = newTokNode();
/* If the ref a wild card, make a token class for it */
if ( Tnum(WildCardString) == 0 )
{
w = newTCnode;
w->tok = addTname( WildCardString );
set_orel(w->tok, &imag_tokens);
set_orel(w->tok, &tokclasses);
WildCardToken = w->tok;
require((p=(TermEntry *)hash_get(Tname, WildCardString)) != NULL,
"hash table mechanism is broken");
p->classname = 1; /* entry is class name, not token */
p->tclass = w; /* save ptr to this tclass def */
list_add(&tclasses, (char *)w);
}
else {
p=(TermEntry *)hash_get(Tname, WildCardString);
require( p!= NULL, "hash table mechanism is broken");
w = p->tclass;
}
t->token = w->tok;
t->wild_card = 1;
t->tclass = w;
t->altstart = CurAltStart;
j1->p1 = (Node *) t;
t->next = (Node *) j2;
g.left = (Node *) j1; g.right = (Node *) j2;
return g;
}
void
#ifdef __USE_PROTOS
setUpperRange(TokNode *t, char *text)
#else
setUpperRange(t, text)
TokNode *t;
char *text;
#endif
{
require(t!=NULL, "setUpperRange: NULL token node");
require(text!=NULL, "setUpperRange: NULL token string");
if ( *text == '"' ) {t->upper_range = addTexpr( text );}
else {t->upper_range = addTname( text );}
}
/*
* Build a rule reference node of the syntax diagram
*
* buildRuleRef(RULE) ::= --o-->RULE-->o--
*
* Where o is a junction node.
*
* If rule 'text' has been defined already, don't alloc new space to store string.
* Set r->text to point to old copy in string table.
*/
Graph
#ifdef __USE_PROTOS
buildRuleRef( char *text )
#else
buildRuleRef( text )
char *text;
#endif
{
Junction *j1, *j2;
Graph g;
RuleRefNode *r;
RuleEntry *p;
require(text!=NULL, "buildRuleRef: invalid rule name");
j1 = newJunction();
j2 = newJunction();
r = newRNode();
r->altstart = CurAltStart;
r->assign = NULL;
if ( (p=(RuleEntry *)hash_get(Rname, text)) != NULL ) r->text = p->str;
else r->text = mystrdup( text );
j1->p1 = (Node *) r;
r->next = (Node *) j2;
g.left = (Node *) j1; g.right = (Node *) j2;
return g;
}
/*
* Or two subgraphs into one graph via:
*
* Or(G1, G2) ::= --o-G1-o--
* | ^
* v |
* o-G2-o
*
* Set the altnum of junction starting G2 to 1 + altnum of junction starting G1.
* If, however, the G1 altnum is 0, make it 1 and then
* make G2 altnum = G1 altnum + 1.
*/
Graph
#ifdef __USE_PROTOS
Or( Graph g1, Graph g2 )
#else
Or( g1, g2 )
Graph g1;
Graph g2;
#endif
{
Graph g;
require(g1.left != NULL, "Or: invalid graph");
require(g2.left != NULL && g2.right != NULL, "Or: invalid graph");
((Junction *)g1.left)->p2 = g2.left;
((Junction *)g2.right)->p1 = g1.right;
/* set altnums */
if ( ((Junction *)g1.left)->altnum == 0 ) ((Junction *)g1.left)->altnum = 1;
((Junction *)g2.left)->altnum = ((Junction *)g1.left)->altnum + 1;
g.left = g2.left;
g.right = g1.right;
return g;
}
/*
* Catenate two subgraphs
*
* Cat(G1, G2) ::= --o-G1-o-->o-G2-o--
* Cat(NULL,G2)::= --o-G2-o--
* Cat(G1,NULL)::= --o-G1-o--
*/
Graph
#ifdef __USE_PROTOS
Cat( Graph g1, Graph g2 )
#else
Cat( g1, g2 )
Graph g1;
Graph g2;
#endif
{
Graph g;
if ( g1.left == NULL && g1.right == NULL ) return g2;
if ( g2.left == NULL && g2.right == NULL ) return g1;
((Junction *)g1.right)->p1 = g2.left;
g.left = g1.left;
g.right = g2.right;
return g;
}
/*
* Make a subgraph an optional block
*
* makeOpt(G) ::= --o-->o-G-o-->o--
* | ^
* v |
* o-------o
*
* Note that this constructs {A|B|...|Z} as if (A|B|...|Z|) was found.
*
* The node on the far right is added so that every block owns its own
* EndBlk node.
*/
Graph
#ifdef __USE_PROTOS
makeOpt( Graph g1, int approx, char * pFirstSetSymbol )
#else
makeOpt( g1, approx, pFirstSetSymbol )
Graph g1;
int approx;
char * pFirstSetSymbol;
#endif
{
Junction *j1,*j2,*p;
Graph g;
require(g1.left != NULL && g1.right != NULL, "makeOpt: invalid graph");
j1 = newJunction();
j2 = newJunction();
((Junction *)g1.right)->p1 = (Node *) j2; /* add node to G at end */
/* MR21
*
* There is code in genBlk which recognizes the node created
* by emptyAlt() as a special case and bypasses it. We don't
* want this to happen for the optBlk.
*/
g = emptyAlt3(); /* MR21 */
if ( ((Junction *)g1.left)->altnum == 0 ) ((Junction *)g1.left)->altnum = 1;
((Junction *)g.left)->altnum = ((Junction *)g1.left)->altnum + 1;
for(p=(Junction *)g1.left; p->p2!=NULL; p=(Junction *)p->p2)
{;} /* find last alt */
p->p2 = g.left; /* add optional alternative */
((Junction *)g.right)->p1 = (Node *)j2; /* opt alt points to EndBlk */
g1.right = (Node *)j2;
SetBlk(g1, aOptBlk, approx, pFirstSetSymbol);
j1->p1 = g1.left; /* add generic node in front */
g.left = (Node *) j1;
g.right = g1.right;
return g;
}
/*
* Make a graph into subblock
*
* makeBlk(G) ::= --o-->o-G-o-->o--
*
* The node on the far right is added so that every block owns its own
* EndBlk node.
*/
Graph
#ifdef __USE_PROTOS
makeBlk( Graph g1, int approx, char * pFirstSetSymbol )
#else
makeBlk( g1, approx, pFirstSetSymbol )
Graph g1;
int approx;
char * pFirstSetSymbol;
#endif
{
Junction *j,*j2;
Graph g;
require(g1.left != NULL && g1.right != NULL, "makeBlk: invalid graph");
j = newJunction();
j2 = newJunction();
((Junction *)g1.right)->p1 = (Node *) j2; /* add node to G at end */
g1.right = (Node *)j2;
SetBlk(g1, aSubBlk, approx, pFirstSetSymbol);
j->p1 = g1.left; /* add node in front */
g.left = (Node *) j;
g.right = g1.right;
return g;
}
/*
* Make a subgraph into a loop (closure) block -- (...)*
*
* makeLoop(G) ::= |---|
* v |
* --o-->o-->o-G-o-->o--
* | ^
* v |
* o-----------o
*
* After making loop, always place generic node out front. It becomes
* the start of enclosing block. The aLoopBlk is the target of the loop.
*
* Loop blks have TWO EndBlk nodes--the far right and the node that loops back
* to the aLoopBlk node. Node with which we can branch past loop == aLoopBegin and
* one which is loop target == aLoopBlk.
* The branch-past (initial) aLoopBegin node has end
* pointing to the last EndBlk node. The loop-target node has end==NULL.
*
* Loop blocks have a set of locks (from 1..CLL_k) on the aLoopBlk node.
*/
Graph
#ifdef __USE_PROTOS
makeLoop( Graph g1, int approx, char * pFirstSetSymbol )
#else
makeLoop( g1, approx, pFirstSetSymbol)
Graph g1;
int approx;
char * pFirstSetSymbol;
#endif
{
Junction *back, *front, *begin;
Graph g;
require(g1.left != NULL && g1.right != NULL, "makeLoop: invalid graph");
back = newJunction();
front = newJunction();
begin = newJunction();
g = emptyAlt3();
((Junction *)g1.right)->p2 = g1.left; /* add loop branch to G */
((Junction *)g1.right)->p1 = (Node *) back; /* add node to G at end */
((Junction *)g1.right)->jtype = EndBlk; /* mark 1st EndBlk node */
((Junction *)g1.left)->jtype = aLoopBlk; /* mark 2nd aLoopBlk node */
((Junction *)g1.left)->end = (Junction *) g1.right;
((Junction *)g1.left)->lock = makelocks();
((Junction *)g1.left)->pred_lock = makelocks();
g1.right = (Node *) back;
begin->p1 = (Node *) g1.left;
g1.left = (Node *) begin;
begin->p2 = (Node *) g.left; /* make bypass arc */
((Junction *)g.right)->p1 = (Node *) back;
SetBlk(g1, aLoopBegin, approx, pFirstSetSymbol);
front->p1 = g1.left; /* add node to front */
g1.left = (Node *) front;
return g1;
}
/*
* Make a subgraph into a plus block -- (...)+ -- 1 or more times
*
* makePlus(G) ::= |---|
* v |
* --o-->o-G-o-->o--
*
* After making loop, always place generic node out front. It becomes
* the start of enclosing block. The aPlusBlk is the target of the loop.
*
* Plus blks have TWO EndBlk nodes--the far right and the node that loops back
* to the aPlusBlk node.
*
* Plus blocks have a set of locks (from 1..CLL_k) on the aPlusBlk node.
*/
Graph
#ifdef __USE_PROTOS
makePlus( Graph g1, int approx, char * pFirstSetSymbol)
#else
makePlus( g1, approx, pFirstSetSymbol)
Graph g1;
int approx;
char * pFirstSetSymbol;
#endif
{
int has_empty_alt_already = 0;
Graph g;
Junction *j2, *j3, *first_alt;
Junction *last_alt=NULL, *p;
require(g1.left != NULL && g1.right != NULL, "makePlus: invalid graph");
first_alt = (Junction *)g1.left;
j2 = newJunction();
j3 = newJunction();
if ( ((Junction *)g1.left)->altnum == 0 ) ((Junction *)g1.left)->altnum = 1;
((Junction *)g1.right)->p2 = g1.left; /* add loop branch to G */
((Junction *)g1.right)->p1 = (Node *) j2; /* add node to G at end */
((Junction *)g1.right)->jtype = EndBlk; /* mark 1st EndBlk node */
g1.right = (Node *) j2;
SetBlk(g1, aPlusBlk, approx, pFirstSetSymbol);
((Junction *)g1.left)->lock = makelocks();
((Junction *)g1.left)->pred_lock = makelocks();
j3->p1 = g1.left; /* add node to front */
g1.left = (Node *) j3;
/* add an optional branch which is the "exit" branch of loop */
/* FIRST, check to ensure that there does not already exist
* an optional path.
*/
/* find last alt */
for(p=first_alt; p!=NULL; p=(Junction *)p->p2)
{
if ( p->p1->ntype == nJunction &&
p->p1!=NULL &&
((Junction *)p->p1)->jtype==Generic &&
((Junction *)p->p1)->p1!=NULL &&
((Junction *)((Junction *)p->p1)->p1)->jtype==EndBlk )
{
has_empty_alt_already = 1;
}
last_alt = p;
}
if ( !has_empty_alt_already )
{
require(last_alt!=NULL, "last_alt==NULL; bad (..)+");
g = emptyAlt();
last_alt->p2 = g.left;
((Junction *)g.right)->p1 = (Node *) j2;
/* make sure lookahead computation ignores this alt for
* FIRST("(..)+"); but it's still used for computing the FIRST
* of each alternative.
*/
((Junction *)g.left)->ignore = 1;
}
return g1;
}
/*
* Return an optional path: --o-->o--
*/
Graph
#ifdef __USE_PROTOS
emptyAlt( void )
#else
emptyAlt( )
#endif
{
Junction *j1, *j2;
Graph g;
j1 = newJunction();
j2 = newJunction();
j1->p1 = (Node *) j2;
g.left = (Node *) j1;
g.right = (Node *) j2;
return g;
}
/* MR21
*
* There is code in genBlk which recognizes the node created
* by emptyAlt() as a special case and bypasses it. We don't
* want this to happen for the optBlk.
*/
Graph
#ifdef __USE_PROTOS
emptyAlt3( void )
#else
emptyAlt3( )
#endif
{
Junction *j1, *j2, *j3;
Graph g;
j1 = newJunction();
j2 = newJunction();
j3 = newJunction();
j1->p1 = (Node *) j2;
j2->p1 = (Node *) j3;
g.left = (Node *) j1;
g.right = (Node *) j3;
return g;
}
/* N o d e A l l o c a t i o n */
TokNode *
#ifdef __USE_PROTOS
newTokNode( void )
#else
newTokNode( )
#endif
{
static TokNode *FreeList = NULL;
TokNode *p, *newblk;
if ( FreeList == NULL )
{
newblk = (TokNode *)calloc(TokenBlockAllocSize, sizeof(TokNode));
if ( newblk == NULL )
fatal_internal(eMsg1("out of memory while building rule '%s'",CurRule));
for (p=newblk; p<&(newblk[TokenBlockAllocSize]); p++)
{
p->next = (Node *)FreeList; /* add all new token nodes to FreeList */
FreeList = p;
}
}
p = FreeList;
FreeList = (TokNode *)FreeList->next;/* remove a TokNode node */
p->next = NULL; /* NULL the ptr we used */
memset( (char *) p, 0, sizeof(TokNode)); /* MR10 */
p->ntype = nToken;
p->rname = CurRule;
p->file = CurFile;
p->line = zzline;
p->altstart = NULL;
return p;
}
RuleRefNode *
#ifdef __USE_PROTOS
newRNode( void )
#else
newRNode( )
#endif
{
static RuleRefNode *FreeList = NULL;
RuleRefNode *p, *newblk;
if ( FreeList == NULL )
{
newblk = (RuleRefNode *)calloc(RRefBlockAllocSize, sizeof(RuleRefNode));
if ( newblk == NULL )
fatal_internal(eMsg1("out of memory while building rule '%s'",CurRule));
for (p=newblk; p<&(newblk[RRefBlockAllocSize]); p++)
{
p->next = (Node *)FreeList; /* add all new rref nodes to FreeList */
FreeList = p;
}
}
p = FreeList;
FreeList = (RuleRefNode *)FreeList->next;/* remove a Junction node */
p->next = NULL; /* NULL the ptr we used */
memset( (char *) p, 0, sizeof(RuleRefNode)); /* MR10 */
p->ntype = nRuleRef;
p->rname = CurRule;
p->file = CurFile;
p->line = zzline;
p->astnode = ASTinclude;
p->altstart = NULL;
return p;
}
static int junctionSeqNumber=0; /* MR10 */
Junction *
#ifdef __USE_PROTOS
newJunction( void )
#else
newJunction( )
#endif
{
static Junction *FreeList = NULL;
Junction *p, *newblk;
if ( FreeList == NULL )
{
newblk = (Junction *)calloc(JunctionBlockAllocSize, sizeof(Junction));
if ( newblk == NULL )
fatal_internal(eMsg1("out of memory while building rule '%s'",CurRule));
for (p=newblk; p<&(newblk[JunctionBlockAllocSize]); p++)
{
p->p1 = (Node *)FreeList; /* add all new Junction nodes to FreeList */
FreeList = p;
}
}
p = FreeList;
FreeList = (Junction *)FreeList->p1;/* remove a Junction node */
p->p1 = NULL; /* NULL the ptr we used */
memset( (char *) p, 0, sizeof(Junction)); /* MR10 */
p->ntype = nJunction;
p->visited = 0;
p->jtype = Generic;
p->rname = CurRule;
p->file = CurFile;
p->line = zzline;
p->exception_label = NULL;
p->fset = (set *) calloc(CLL_k+1, sizeof(set));
require(p->fset!=NULL, "cannot allocate fset in newJunction");
p->seq=++junctionSeqNumber; /* MR10 */
return p;
}
ActionNode *
#ifdef __USE_PROTOS
newActionNode( void )
#else
newActionNode( )
#endif
{
static ActionNode *FreeList = NULL;
ActionNode *p, *newblk;
if ( FreeList == NULL )
{
newblk = (ActionNode *)calloc(ActionBlockAllocSize, sizeof(ActionNode));
if ( newblk == NULL )
fatal_internal(eMsg1("out of memory while building rule '%s'",CurRule));
for (p=newblk; p<&(newblk[ActionBlockAllocSize]); p++)
{
p->next = (Node *)FreeList; /* add all new Action nodes to FreeList */
FreeList = p;
}
}
p = FreeList;
FreeList = (ActionNode *)FreeList->next;/* remove an Action node */
memset( (char *) p, 0, sizeof(ActionNode)); /* MR10 */
p->ntype = nAction;
p->next = NULL; /* NULL the ptr we used */
p->done = 0;
p->pred_fail = NULL;
p->guardpred = NULL;
p->ampersandPred = NULL;
return p;
}
/*
* allocate the array of locks (1..CLL_k) used to inhibit infinite recursion.
* Infinite recursion can occur in (..)* blocks, FIRST calcs and FOLLOW calcs.
* Therefore, we need locks on aLoopBlk, RuleBlk, EndRule nodes.
*
* if ( lock[k]==TRUE ) then we have been here before looking for k tokens
* of lookahead.
*/
char *
#ifdef __USE_PROTOS
makelocks( void )
#else
makelocks( )
#endif
{
char *p = (char *) calloc(CLL_k+1, sizeof(char));
require(p!=NULL, "cannot allocate lock array");
return p;
}
#if 0
** #ifdef __USE_PROTOS
** void my_memset(char *p,char value,int count)
** #else
** void my_memset(p,value,count)
** char *p;
** char value;
** int count;
** #endif
** {
** int i;
**
** for (i=0; i<count; i++) {
** p[i]=value;
** };
** }
#endif

View File

@@ -0,0 +1,129 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK antlr Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="antlr"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="init">
<condition property="CheckDepends">
<uptodate targetfile="${WORKSPACE}/Tools/bin/antlr.exe">
<srcfiles dir="." includes="*.c *.h *.g"/>
</uptodate>
</condition>
<if>
<equals arg1="${CheckDepends}" arg2="true"/>
<then>
<echo message="Executable, antlr.exe, is up to date."/>
</then>
<else>
<echo message="Building the EDK Pccts Tool: ${ToolName}"/>
</else>
</if>
</target>
<target name="GenTool" depends="init" unless="CheckDepends">
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="nmake" failonerror="TRUE">
<arg line="-f AntlrMS.mak"/>
</exec>
</then>
<elseif>
<istrue value="${cygwin}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="TRUE">
<arg line="-f makefile.cygwin"/>
</exec>
</then>
</elseif>
<elseif>
<istrue value="${gcc}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="TRUE">
<arg line="-f makefile BIN_DIR=${BIN_DIR}"/>
</exec>
</then>
</elseif>
</if>
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="nmake" failonerror="TRUE">
<arg line="-f AntlrMS.mak clean"/>
</exec>
</then>
<elseif>
<istrue value="${cygwin}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="TRUE">
<arg line="-f makefile.cygwin clean"/>
</exec>
</then>
</elseif>
<elseif>
<istrue value="${gcc}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="TRUE">
<arg line="-f makefile clean"/>
</exec>
</then>
</elseif>
</if>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="nmake" failonerror="FALSE">
<arg line="-f AntlrMS.mak clean"/>
</exec>
</then>
<elseif>
<istrue value="${cygwin}"/>
<then>
<echo message="Building antlr with cygwin gcc"/>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="FALSE">
<arg line="-f makefile.cygwin clean"/>
</exec>
</then>
</elseif>
<elseif>
<istrue value="${gcc}"/>
<then>
<echo message="Building antlr with gcc"/>
<exec dir="${PACKAGE_DIR}/Pccts/antlr" executable="make" failonerror="FALSE">
<arg line="-f makefile clean"/>
</exec>
</then>
</elseif>
</if>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,67 @@
#include <stdio.h>
#include <ctype.h>
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
void
#ifdef __USE_PROTOS
dumpcycles(void)
#else
dumpcycles()
#endif
{
Cycle *c;
CacheEntry *f;
ListNode *p;
int i=0;
int k;
int degree;
for (k=1; k <= CLL_k; k++) {
if (Cycles[k] == NULL) continue;
for (p = Cycles[k]->next; p!=NULL; p=p->next) {
c = (Cycle *) p->elem;
degree=set_deg(c->cyclicDep);
fprintf(stderr,"Cycle %d: (degree %d) %s -->\n", i++, degree, RulePtr[c->croot]->rname);
fprintf(stderr," *self*\n");
MR_dumpRuleSet(c->cyclicDep);
fprintf(stderr,"\n");
f = (CacheEntry *)
hash_get(Fcache,Fkey(RulePtr[c->croot]->rname,'o',k));
if (f == NULL) {
fprintf(stderr," *** FOLLOW(%s) must be in cache but isn't ***\n",
RulePtr[c->croot]->rname);
};
};
};
}
void
#ifdef __USE_PROTOS
dumpfostack(int k)
#else
dumpfostack(k)
int k;
#endif
{
int i=0;
int *pi;
fprintf(stderr,"\n");
if (FoStack[k] == NULL) {
fprintf(stderr,"FoStack[%d] is null\n",k);
};
if (FoTOS[k] == NULL) {
fprintf(stderr,"FoTOS[%d] is null\n",k);
}
if (FoTOS[k] != NULL && FoStack[k] != NULL) {
for (pi=FoStack[k]; pi <= FoTOS[k]; pi++) {
i++;
fprintf(stderr,"#%d rule %d %s\n",i,*pi,RulePtr[*pi]->rname);
}
}
}

View File

@@ -0,0 +1,423 @@
#include <stdio.h>
#include <ctype.h>
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#ifdef __USE_PROTOS
void dumpset1(set s)
#else
void dumpset1(s)
set s;
#endif
{
if (set_nil(s)) {
fprintf(stderr,"{}");
} else {
s_fprT(stderr,s);
};
}
#ifdef __USE_PROTOS
void dumpset(set s)
#else
void dumpset(s)
set s;
#endif
{
dumpset1(s);
fprintf(stderr,"\n");
}
#ifdef __USE_PROTOS
int isEndRule(Node * p)
#else
int isEndRule(p)
Node * p;
#endif
{
int result=0;
if ( p->ntype == nJunction &&
( (Junction *) p)->jtype == EndRule) {
result=1;
};
return result;
}
#ifdef __USE_PROTOS
void dumppred1(int depth,Predicate *p)
#else
void dumppred1(depth,p)
int depth;
Predicate *p;
#endif
{
int i;
int k;
for (i=0; i<depth ; i++) {
fprintf(stderr," ");
};
if (p->expr == PRED_AND_LIST ||
p->expr == PRED_OR_LIST) {
fprintf(stderr," %s", (p->expr == NULL ? "null expr" : p->expr));
if (p->inverted) fprintf(stderr," predicate inverted !");
if (p->redundant) {
fprintf(stderr," Redundant!");
};
if (p->isConst) fprintf(stderr," const %d !",p->constValue);
fprintf(stderr,"\n");
} else {
fprintf(stderr,"predicate k=%d",p->k);
k=set_int(p->completionSet);
if (k >= 0) {
fprintf(stderr," Incomplete Set=%d !",k);
};
k=set_int(p->completionTree);
if (k >= 0) {
fprintf(stderr," Incomplete Tree=%d !",k);
};
if (p->redundant) {
fprintf(stderr," Redundant!");
};
fprintf(stderr," \"%s\" (%x)", (p->expr == NULL ? "null expr" : p->expr) ,p);
if (p->source != NULL) {
fprintf(stderr,"line %d",p->source->line);
};
if (p->inverted) fprintf(stderr," predicate inverted !");
fprintf(stderr,"\n");
for (i=0; i<depth ; i++) {
fprintf(stderr," ");
};
fprintf(stderr,"scontext: ");
dumpset(p->scontext[1]);
for (i=0; i<depth ; i++) {
fprintf(stderr," ");
};
fprintf(stderr,"tcontext: ");
preorder(p->tcontext);
fprintf(stderr,"\n");
};
fprintf(stderr,"\n");
if (p->down != NULL) {
dumppred1(depth+1,p->down);
};
if (p->right != NULL) {
dumppred1(depth,p->right);
};
}
#ifdef __USE_PROTOS
void dumppred(Predicate *p)
#else
void dumppred(p)
Predicate *p;
#endif
{
fprintf(stderr,"---------------------------------\n");
dumppred1(0,p);
fprintf(stderr,"\n");
}
#ifdef __USE_PROTOS
void dumppredtree(Predicate *p)
#else
void dumppredtree(p)
Predicate *p;
#endif
{
fprintf(stderr,"predicate k=%d \"%s\" line %d\n",p->k,p->expr,p->source->line);
dumpset(p->scontext[1]);
}
#ifdef __USE_PROTOS
void dumppredexpr(Predicate *p)
#else
void dumppredexpr(p)
Predicate *p;
#endif
{
fprintf(stderr," pred expr \"%s\"\n",p->expr);
}
#ifdef __USE_PROTOS
void dt(Tree *t)
#else
void dt(t)
Tree *t;
#endif
{
MR_dumpTreeF(stderr,0,t,5);
}
#ifdef __USE_PROTOS
void d(Node * p)
#else
void d(p)
Node * p;
#endif
{
Junction *j;
RuleRefNode *r;
TokNode *t;
ActionNode *a;
if (p==NULL) {
fprintf(stderr,"dumpNode: Node is NULL");
return;
};
switch (p->ntype) {
case nJunction :
j = (Junction *) p;
fprintf(stderr, "Junction (#%d in rule %s line %d) ",j->seq,j->rname,j->line);
if (j->guess) fprintf(stderr,"guess block ");
switch (j->jtype ) {
case aSubBlk :
fprintf(stderr,"aSubBlk");
break;
case aOptBlk :
fprintf(stderr,"aOptBlk");
break;
case aLoopBegin :
fprintf(stderr,"aLoopBeginBlk");
break;
case aLoopBlk :
fprintf(stderr,"aLoopBlk");
break;
case aPlusBlk :
fprintf(stderr,"aPlusBlk");
break;
case EndBlk :
fprintf(stderr,"EndBlk");
break;
case RuleBlk :
fprintf(stderr,"RuleBlk");
break;
case Generic :
fprintf(stderr,"Generic");
break;
case EndRule :
fprintf(stderr,"EndRule");
break;
};
if (j->halt) fprintf(stderr," halt!");
if (j->p1) fprintf(stderr," p1 valid");
if (j->p2) {
if (j->p2->ntype == nJunction) {
fprintf(stderr," (p2=#%d)",( (Junction *) j->p2)->seq);
} else {
fprintf(stderr," (p2 valid)");
};
};
if (j->ignore) fprintf(stderr, " ignore/plus-block-bypass");
if (j->fset != NULL && set_deg(*j->fset) != 0) {
fprintf(stderr,"\nfset:\n");
dumpset(*j->fset);
};
if (j->ftree != NULL) {
fprintf(stderr,"\nftree:\n");
preorder(j->ftree);
};
fprintf(stderr,"\n");
break;
case nRuleRef :
r = (RuleRefNode *) p;
fprintf(stderr, "RuleRefNode (in rule %s line %d) to rule %s\n", r->rname,r->line,r->text);
break;
case nToken :
t = (TokNode *) p;
fprintf(stderr, "TokNode (in rule %s line %d) token %s\n",t->rname,t->line,TerminalString(t->token));
break;
case nAction :
a =(ActionNode *) p;
if (a->is_predicate) {
fprintf(stderr, "Predicate (in rule %s line %d) %s",a->rname,a->line,a->action);
if (a->inverted) fprintf(stderr," action inverted !");
if (a->guardpred != NULL) {
fprintf(stderr," guarded");
dumppredexpr(a->guardpred);
if (a->ampersandPred) {
fprintf(stderr," \"&&\" style");
} else {
fprintf(stderr," \"=>\" style");
};
};
if (a->predEntry != NULL) fprintf(stderr," predEntry \"%s\" ",a->predEntry->str);
fprintf(stderr,"\n");
} else if (a->init_action) {
fprintf(stderr, "Init-Action (in rule %s line %d) %s\n",a->rname,a->line,a->action);
} else {
fprintf(stderr, "Action (in rule %s line %d) %s\n",a->rname,a->line,a->action);
};
break;
};
}
#ifdef __USE_PROTOS
Node * dp1(Node * p)
#else
Node * dp1(p)
Node * p;
#endif
{
Node *result=NULL;
if (p->ntype == nJunction) {
result=( (Junction *) p )->p1;
d(result);
} else {
fprintf(stderr,"dp1: Not a Junction node");
};
return result;
}
#ifdef __USE_PROTOS
Node * dp2(Node * p)
#else
Node * dp2(p)
Node * p;
#endif
{
Node *result=NULL;
if (p->ntype == nJunction) {
result=( (Junction *) p )->p2;
d(result);
} else {
fprintf(stderr,"dp2: Not a Junction node");
};
return result;
}
#ifdef __USE_PROTOS
Node * dn(Node * p)
#else
Node * dn(p)
Node * p;
#endif
{
Node *result=NULL;
if (p->ntype == nRuleRef) {
result=( (RuleRefNode *)p )->next;
} else if (p->ntype == nAction) {
result=( (ActionNode *)p )->next;
} else if (p->ntype == nToken) {
result=( (TokNode *)p )->next;
} else {
fprintf(stderr,"No next field: Neither a RuleRefNode, ActionNode, nor TokNode");
};
if (result != NULL) d(result);
return result;
}
#ifdef __USE_PROTOS
void df(Node * p)
#else
void df(p)
Node * p;
#endif
{
int count=0;
Node *next;
fprintf(stderr,"\n#%d ",++count);
d(p);
for (next=p; next != NULL && !isEndRule(next) ; ) {
fprintf(stderr,"#%d ",++count);
if (next->ntype == nJunction) {
next=dp1(next);
} else {
next=dn(next);
};
};
}
#ifdef __USE_PROTOS
Node * dfn(Node * p,int target)
#else
Node * dfn(p,target)
Node * p;
int target;
#endif
{
Node *result=NULL;
int count=0;
Node *next;
fprintf(stderr,"#%d ",++count);
d(p);
for (next=p; next != NULL && !isEndRule(next) ; ) {
fprintf(stderr,"#%d ",++count);
if (next->ntype == nJunction) {
next=dp1(next);
} else {
next=dn(next);
};
if (count == target) {
result=next;
break;
};
};
return result;
}
static int findnodeMatch;
#ifdef __USE_PROTOS
Junction *findnode1(Node *n)
#else
Junction *findnode1(n)
Node *n;
#endif
{
Node *next;
Junction *j;
Junction *match;
if (n == NULL) return NULL;
if (n->ntype == nJunction) {
j=(Junction *) n;
if (j->seq == findnodeMatch) return j;
if (j->jtype == EndRule) return NULL;
if (j->jtype != RuleBlk && j->jtype != EndBlk) {
if (j->p2 != NULL && !j->ignore) {
match=findnode1(j->p2);
if (match != NULL) return match;
};
};
};
next=MR_advance(n);
return findnode1(next);
}
#ifdef __USE_PROTOS
Junction *findnode(int match)
#else
Junction *findnode(match)
int match;
#endif
{
Junction *j;
Junction *result=NULL;
findnodeMatch=match;
for (j=SynDiag; j != NULL; j=(Junction *)j->p2) {
require (j->ntype == nJunction && j->jtype == RuleBlk,"Not a rule block");
result=findnode1( (Node *) j);
if (result != NULL) break;
};
if (result != NULL) {
d( (Node *) result);
};
return result;
}

View File

@@ -0,0 +1,328 @@
/*
* egman.c
*
* 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.
*
* ANTLR 1.33MR10
* 2001
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#include "proto.h"
static ExceptionGroup **egArray=NULL; /* ExceptionGroup by BlkLevel */
static LabelEntry **leArray=NULL; /* LabelEntry by BlkLevel */
static Junction **altArray=NULL; /* start of alternates */
static int arraySize=0;
static int highWater=0;
static ExceptionGroup *lastEG=NULL; /* used in altFixup() */
static int lastBlkLevel=0; /* used in altFixup() */
#ifdef __USE_PROTOS
static void arrayCheck(void);
#else
static void arrayCheck();
#endif
/* Called to add an exception group for an alternative EG */
#ifdef __USE_PROTOS
void egAdd(ExceptionGroup * eg)
#else
void egAdd(eg)
ExceptionGroup *eg;
#endif
{
int i;
ExceptionGroup *nextEG;
ExceptionGroup *innerEG;
LabelEntry *nextLE;
LabelEntry *innerLE;
Junction *nextAlt;
Junction *innerAlt;
lastEG=eg;
lastBlkLevel=BlkLevel;
arrayCheck();
eg->pendingLink=egArray[BlkLevel];
egArray[BlkLevel]=eg;
/* EG for alternates already have their altID filled in */
for (i=BlkLevel+1; i<=highWater ; i++) {
for (innerEG=egArray[i]; innerEG != NULL ; innerEG=nextEG) {
nextEG=innerEG->pendingLink;
innerEG->pendingLink=NULL;
innerEG->outerEG=eg;
};
egArray[i]=NULL;
};
/*
* for patching up the LabelEntry you might use an EG for the
* current alternative - unlike patching up an alternative EG
* i.e. start the loop at BlkLevel rather than (BlkLevel+1)
* fill it in only if the EG and the LE are for the very
* same alternative if they're at the same BlkLevel
* it's easier to leave the LE on this list (filled in) rather than
* trying to selectively remove it. It will eventually be
* removed anyway when the BlkLevel gets small enough.
*/
for (i=BlkLevel; i<=highWater ; i++) {
for (innerLE=leArray[i]; innerLE != NULL ; innerLE=nextLE) {
nextLE=innerLE->pendingLink;
if (BlkLevel != i ||
innerLE->curAltNum == CurAltNum_array[BlkLevel]) {
if (innerLE->outerEG == NULL) {
innerLE->outerEG=eg;
};
};
};
if (BlkLevel != i) leArray[i]=NULL;
};
/*
* For the start of alternatives it is necessary to make a
* distinction between the exception group for the current
* alternative and the "fallback" EG for the block which
* contains the alternative
*
* The fallback outerEG is used to handle the case where
* no alternative of a block matches. In that case the
* signal is "NoViableAlt" (or "NoSemViableAlt" and the
* generator needs the EG of the block CONTAINING the
* current one.
*
* rule: ( ( ( a
* | b
* )
* | c
* )
* | d
* );
*/
for (i=BlkLevel; i <= highWater ; i++) {
for (innerAlt=altArray[i]; innerAlt != NULL ; innerAlt=nextAlt) {
nextAlt=innerAlt->pendingLink;
/* first fill in the EG for the current alternative */
/* but leave it on the list in order to get the fallback EG */
/* if the EG is at the same LEVEL as the alternative then */
/* fill it in only if in the very same alternative */
/* */
/* rule: ( a */
/* | b */
/* | c exception ... */
/* ) */
/* */
/* if the EG is outside the alternative (e.g. BlkLevel < i) */
/* then it doesn't matter about the alternative */
/* */
/* rule: ( a */
/* | b */
/* | c */
/* ) exception ... */
/* */
#if 0
printf("BlkLevel=%d i=%d altnum=%d CurAltNum=%d altID=%s\n",
BlkLevel,i,innerAlt->curAltNum,CurAltNum_array[BlkLevel],eg->altID);
#endif
if (BlkLevel != i ||
innerAlt->curAltNum == CurAltNum_array[BlkLevel]) {
if (innerAlt->exception_label == NULL) {
innerAlt->exception_label=eg->altID;
};
};
/* ocurs at a later pass then for the exception_label */
/* if an outerEG has been found then fill in the outer EG */
/* remove if from the list when the BlkLevel gets smaller */
if (BlkLevel != i) {
if (innerAlt->outerEG == NULL) {
innerAlt->outerEG=eg;
};
};
};
if (BlkLevel != i) altArray[i]=NULL;
};
}
#ifdef __USE_PROTOS
void leAdd(LabelEntry * le)
#else
void leAdd(le)
LabelEntry *le;
#endif
{
arrayCheck();
le->pendingLink=leArray[BlkLevel];
le->curAltNum=CurAltNum_array[BlkLevel];
leArray[BlkLevel]=le;
}
#ifdef __USE_PROTOS
void altAdd(Junction *alt)
#else
void altAdd(alt)
Junction *alt;
#endif
{
arrayCheck();
#if 0
printf("BlkLevel=%d CurAltNum=%d\n",
BlkLevel,CurAltNum_array[BlkLevel]);
#endif
alt->curAltNum=CurAltNum_array[BlkLevel];
alt->pendingLink=altArray[BlkLevel];
altArray[BlkLevel]=alt;
}
static void
#ifdef __USE_PROTOS
arrayCheck(void)
#else
arrayCheck()
#endif
{
ExceptionGroup **egArrayNew;
LabelEntry **leArrayNew;
Junction **altArrayNew;
int arraySizeNew;
int i;
if (BlkLevel > highWater) highWater=BlkLevel;
if (BlkLevel >= arraySize) {
arraySizeNew=BlkLevel+5; /* MR20 */
egArrayNew=(ExceptionGroup **)
calloc(arraySizeNew,sizeof(ExceptionGroup *));
leArrayNew=(LabelEntry **)
calloc(arraySizeNew,sizeof(LabelEntry *));
altArrayNew=(Junction **)
calloc(arraySizeNew,sizeof(Junction *));
for (i=0; i<arraySize ; i++) {
egArrayNew[i]=egArray[i];
leArrayNew[i]=leArray[i];
altArrayNew[i]=altArray[i];
};
arraySize=arraySizeNew;
if (egArray != NULL) free( (char *) egArray);
if (leArray != NULL) free( (char *) leArray);
if (altArray != NULL) free( (char *) altArray);
egArray=egArrayNew;
leArray=leArrayNew;
altArray=altArrayNew;
};
}
/* always call leFixup() BEFORE egFixup() */
void
#ifdef __USE_PROTOS
egFixup(void)
#else
egFixup()
#endif
{
int i;
ExceptionGroup *nextEG;
ExceptionGroup *innerEG;
for (i=1; i<=highWater ; i++) {
for (innerEG=egArray[i]; innerEG != NULL ; innerEG=nextEG) {
nextEG=innerEG->pendingLink;
innerEG->pendingLink=NULL;
};
egArray[i]=NULL;
};
lastEG=NULL;
lastBlkLevel=0;
}
/* always call leFixup() BEFORE egFixup() */
#ifdef __USE_PROTOS
void leFixup(void)
#else
void leFixup()
#endif
{
int i;
LabelEntry *nextLE;
LabelEntry *innerLE;
for (i=BlkLevel; i<=highWater ; i++) {
for (innerLE=leArray[i]; innerLE != NULL ; innerLE=nextLE) {
nextLE=innerLE->pendingLink;
innerLE->pendingLink=NULL;
};
leArray[i]=NULL;
};
}
/* always call altFixup() BEFORE egFixup() */
#ifdef __USE_PROTOS
void altFixup(void)
#else
void altFixup()
#endif
{
int i;
Junction *nextAlt;
Junction *innerAlt;
for (i=BlkLevel; i<=highWater ; i++) {
for (innerAlt=altArray[i]; innerAlt != NULL ; innerAlt=nextAlt) {
/* if an outerEG has been found then fill in the outer EG */
if (lastBlkLevel <= i) {
if (innerAlt->outerEG == NULL) {
innerAlt->outerEG=lastEG;
};
};
nextAlt=innerAlt->pendingLink;
innerAlt->pendingLink=NULL;
};
altArray[i]=NULL;
};
}

View File

@@ -0,0 +1,538 @@
/*
* A n t l r S e t s / E r r o r F i l e H e a d e r
*
* Generated from: antlr.g
*
* Terence Parr, Russell Quong, Will Cohen, and Hank Dietz: 1989-2001
* Parr Research Corporation
* with Purdue University Electrical Engineering
* With AHPCRC, University of Minnesota
* ANTLR Version 1.33MR33
*/
#define ANTLR_VERSION 13333
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pcctscfg.h"
#include "set.h"
#include <ctype.h>
#include "syn.h"
#include "hash.h"
#include "generic.h"
#define zzcr_attr(attr,tok,t)
#define zzSET_SIZE 20
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "err.h"
ANTLRChar *zztokens[157]={
/* 00 */ "Invalid",
/* 01 */ "Eof",
/* 02 */ "QuotedTerm",
/* 03 */ "\\n|\\r|\\r\\n",
/* 04 */ "\\(\\n|\\r|\\r\\n)",
/* 05 */ "\\~[]",
/* 06 */ "~[\\n\\r\"\\]+",
/* 07 */ "\"",
/* 08 */ "\\n|\\r|\\r\\n",
/* 09 */ "\\(\\n|\\r|\\r\\n)",
/* 10 */ "\\~[]",
/* 11 */ "~[\\n\\r\"\\]+",
/* 12 */ "'",
/* 13 */ "\\n|\\r|\\r\\n",
/* 14 */ "\\~[]",
/* 15 */ "~[\\n\\r'\\]+",
/* 16 */ "\\*/",
/* 17 */ "\\*",
/* 18 */ "\\n|\\r|\\r\\n",
/* 19 */ "~[\\n\\r\\*]+",
/* 20 */ "\\*/",
/* 21 */ "\\*",
/* 22 */ "\\n|\\r|\\r\\n",
/* 23 */ "~[\\n\\r\\*]+",
/* 24 */ "\\n|\\r|\\r\\n",
/* 25 */ "~[\\n\\r]+",
/* 26 */ "\\n|\\r|\\r\\n",
/* 27 */ "~[\\n\\r]+",
/* 28 */ "\\n|\\r|\\r\\n",
/* 29 */ "~[\\n\\r]+",
/* 30 */ "\\*/",
/* 31 */ "\\*",
/* 32 */ "\\n|\\r|\\r\\n",
/* 33 */ "~[\\n\\r\\*]+",
/* 34 */ "Action",
/* 35 */ "Pred",
/* 36 */ "PassAction",
/* 37 */ "consumeUntil\\( [\\ \\t]* \\{~[\\}]+\\} [\\ \\t]* \\)",
/* 38 */ "consumeUntil\\( ~[\\)]+ \\)",
/* 39 */ "\\n|\\r|\\r\\n",
/* 40 */ "\\>",
/* 41 */ "$",
/* 42 */ "$$",
/* 43 */ "$\\[\\]",
/* 44 */ "$\\[",
/* 45 */ "$[0-9]+",
/* 46 */ "$[0-9]+.",
/* 47 */ "$[0-9]+.[0-9]+",
/* 48 */ "$[_a-zA-Z][_a-zA-Z0-9]*",
/* 49 */ "#0",
/* 50 */ "#\\[\\]",
/* 51 */ "#\\(\\)",
/* 52 */ "#[0-9]+",
/* 53 */ "#line[\\ \\t]* [0-9]+ {[\\ \\t]* \"~[\"]+\" ([\\ \\t]* [0-9]*)* } (\\n|\\r|\\r\\n)",
/* 54 */ "#line ~[\\n\\r]* (\\n|\\r|\\r\\n)",
/* 55 */ "#[_a-zA-Z][_a-zA-Z0-9]*",
/* 56 */ "#\\[",
/* 57 */ "#\\(",
/* 58 */ "#",
/* 59 */ "\\)",
/* 60 */ "\\[",
/* 61 */ "\\(",
/* 62 */ "\\\\]",
/* 63 */ "\\\\)",
/* 64 */ "\\>",
/* 65 */ "'",
/* 66 */ "\"",
/* 67 */ "\\$",
/* 68 */ "\\#",
/* 69 */ "\\(\\n|\\r|\\r\\n)",
/* 70 */ "\\~[\\]\\)>$#]",
/* 71 */ "/",
/* 72 */ "/\\*",
/* 73 */ "\\*/",
/* 74 */ "//",
/* 75 */ "~[\\n\\r\\)\\(\\$#\\>\\]\\[\"'/]+",
/* 76 */ "[\\t\\ ]+",
/* 77 */ "\\n|\\r|\\r\\n",
/* 78 */ "\\[",
/* 79 */ "\\<\\<",
/* 80 */ "\"",
/* 81 */ "/\\*",
/* 82 */ "\\*/",
/* 83 */ "//",
/* 84 */ "#line[\\ \\t]* [0-9]+ {[\\ \\t]* \"~[\"]+\" ([\\ \\t]* [0-9]*)* } (\\n|\\r|\\r\\n)",
/* 85 */ "#line ~[\\n\\r]* (\\n|\\r|\\r\\n)",
/* 86 */ "\\>\\>",
/* 87 */ "WildCard",
/* 88 */ "\\@",
/* 89 */ "LABEL",
/* 90 */ "grammar-element",
/* 91 */ "meta-symbol",
/* 92 */ "Pragma",
/* 93 */ "FirstSetSymbol",
/* 94 */ "{\\}#header",
/* 95 */ "{\\}#first",
/* 96 */ "{\\}#parser",
/* 97 */ "{\\}#tokdefs",
/* 98 */ "\\}",
/* 99 */ "class",
/* 100 */ "NonTerminal",
/* 101 */ "TokenTerm",
/* 102 */ "\\{",
/* 103 */ "!",
/* 104 */ "\\<",
/* 105 */ "\\>",
/* 106 */ ":",
/* 107 */ ";",
/* 108 */ "{\\}#lexaction",
/* 109 */ "{\\}#lexmember",
/* 110 */ "{\\}#lexprefix",
/* 111 */ "{\\}#pred",
/* 112 */ "\\|\\|",
/* 113 */ "&&",
/* 114 */ "\\(",
/* 115 */ "\\)",
/* 116 */ "{\\}#lexclass",
/* 117 */ "{\\}#errclass",
/* 118 */ "{\\}#tokclass",
/* 119 */ "..",
/* 120 */ "{\\}#token",
/* 121 */ "=",
/* 122 */ "[0-9]+",
/* 123 */ "\\|",
/* 124 */ "\\~",
/* 125 */ "^",
/* 126 */ "approx",
/* 127 */ "LL\\(1\\)",
/* 128 */ "LL\\(2\\)",
/* 129 */ "\\*",
/* 130 */ "\\+",
/* 131 */ "?",
/* 132 */ "=>",
/* 133 */ "exception",
/* 134 */ "default",
/* 135 */ "catch",
/* 136 */ "{\\}#[A-Za-z0-9_]*",
/* 137 */ "[\\t\\ ]+",
/* 138 */ "\\n|\\r|\\r\\n",
/* 139 */ "//",
/* 140 */ "/\\*",
/* 141 */ "#ifdef",
/* 142 */ "#if",
/* 143 */ "#ifndef",
/* 144 */ "#else",
/* 145 */ "#endif",
/* 146 */ "#undef",
/* 147 */ "#import",
/* 148 */ "ID",
/* 149 */ "#define",
/* 150 */ "INT",
/* 151 */ "enum",
/* 152 */ "\\{",
/* 153 */ "=",
/* 154 */ ",",
/* 155 */ "\\}",
/* 156 */ ";"
};
SetWordType zzerr1[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr2[20] = {0xfc,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xf3,
0xbf,0xff,0xff,0xff, 0xff,0xff,0xff,0x1f};
SetWordType zzerr3[20] = {0xfc,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xfb,
0x3b,0xf7,0xf7,0xc7, 0xff,0xff,0xff,0x1f};
SetWordType zzerr4[20] = {0x4,0x0,0x0,0x0, 0x10,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x80,0x7,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType setwd1[157] = {0x0,0x50,0xa0,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x6a,0x20,0xa0,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x0,0x0,0x20,0x20,0x21,
0x21,0x21,0x21,0x6e,0x6e,0x64,0x20,0x0,
0x20,0xa0,0xa0,0xa0,0x20,0x6a,0x6a,0x6a,
0x6e,0x20,0x20,0x20,0x20,0x66,0x6e,0x6e,
0x20,0x66,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20};
SetWordType zzerr5[20] = {0x0,0x0,0x0,0x0, 0x10,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x1,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr6[20] = {0x4,0x0,0x0,0x0, 0x10,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x7,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr7[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x6,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr8[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x4,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr9[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf0,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType setwd2[157] = {0x0,0xf8,0x6,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xf8,0x0,0x1,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xf8,0xf8,0xf8,0x0,0x0,
0x0,0x1,0x2,0x6,0x0,0xf8,0xf8,0xf8,
0xf8,0x0,0x0,0x0,0x0,0xf8,0xf8,0xf8,
0x0,0xf8,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0xe8,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr10[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0xbc,0xf8,0x74,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr11[20] = {0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0xa0,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr12[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr13[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0xa0,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType setwd3[157] = {0x0,0xfa,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xfa,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xfa,0xfa,0xfa,0x5,0x0,
0x5,0x0,0x0,0x0,0xe2,0xfa,0xfa,0xfa,
0xfa,0xc0,0x80,0x5,0xe0,0xfa,0xfa,0xfa,
0x0,0xfa,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0xfa,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr14[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x20,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr15[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr16[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr17[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x40,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr18[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x24,0x0,0x80,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr19[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x20,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr20[20] = {0x6,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x74,0x3, 0x20,0x0,0x0,0x0};
SetWordType zzerr21[20] = {0x6,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x70,0x3, 0x20,0x0,0x0,0x0};
SetWordType setwd4[157] = {0x0,0xe5,0xda,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xe5,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xed,0xe5,0xe7,0x1a,0x0,
0x0,0x0,0x0,0x0,0xc0,0xe5,0xe5,0xe5,
0xe5,0x0,0x0,0x0,0x0,0xe5,0xe5,0xe5,
0x0,0xe5,0x40,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0xe5,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr22[20] = {0x6,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x3c,0xf8,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr23[20] = {0x6,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr24[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr25[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x70,0x1, 0x20,0x0,0x0,0x0};
SetWordType zzerr26[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x5,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType setwd5[157] = {0x0,0x1f,0xc1,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xdf,0xc0,0xc0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0xc0,0x0,0xc0,0x0,0x0,0xc0,0xc0,0x0,
0x0,0x0,0x0,0x7f,0x1f,0xdf,0xc0,0xc0,
0x0,0x0,0xc0,0x0,0x67,0x1f,0x1f,0x1f,
0x1f,0x0,0x0,0xc0,0x60,0x1f,0x1f,0x1f,
0x0,0x1f,0x0,0x0,0x40,0xc0,0x0,0x0,
0x0,0x0,0xc0,0xc0,0x0,0x0,0x5f,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr27[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x0,0x0,0x0,0x10, 0x0,0x0,0x0,0x0};
SetWordType zzerr28[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x80,0x2,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr29[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x20,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr30[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd,
0x0,0x0,0x80,0x0, 0x20,0x0,0x0,0x0};
SetWordType zzerr31[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd,
0x0,0x0,0x0,0x0, 0x20,0x0,0x0,0x0};
SetWordType zzerr32[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x5,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr33[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x20,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType setwd6[157] = {0x0,0x0,0xfd,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xe1,0xe1,0xe1,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0xfd,0x60,0xe9,0x0,0x0,0xe1,0xe1,0x0,
0x0,0x0,0x0,0xe2,0x0,0xfd,0xfd,0xe1,
0x20,0x0,0xe1,0x0,0xe2,0x0,0x0,0x0,
0x0,0x0,0x0,0xe1,0xe2,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0xe2,0xe0,0x20,0x0,
0x0,0x0,0xe1,0xe1,0x0,0x0,0xe2,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr34[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd,
0x0,0x0,0x80,0x0, 0x20,0x0,0x0,0x0};
SetWordType zzerr35[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd,
0x0,0x0,0x0,0x0, 0x20,0x0,0x0,0x0};
SetWordType zzerr36[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x5,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr37[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xc,
0x0,0x0,0x0,0x0, 0x20,0x0,0x0,0x0};
SetWordType zzerr38[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x84,0x9,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr39[20] = {0x0,0x0,0x0,0x0, 0x10,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x1,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr40[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x9,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr41[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr42[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x80,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType setwd7[157] = {0x0,0x0,0xdf,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xdf,0xdf,0xff,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0xdf,0x3,0xdf,0x0,0x0,0xdf,0xdf,0x0,
0x0,0x0,0x0,0xdf,0x0,0xdf,0xdf,0xdf,
0x1,0x30,0xdf,0x0,0xdf,0x0,0x0,0x0,
0x0,0x0,0x0,0xdf,0xdf,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0xdf,0xdf,0x1,0x0,
0x0,0x0,0xdf,0xdf,0x0,0x0,0xdf,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr43[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr44[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xc0, 0x1,0x0,0x0,0x0};
SetWordType zzerr45[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x30,
0x40,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr46[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr47[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x20,
0x40,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr48[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x2,0x0, 0x10,0x0,0x0,0x0};
SetWordType zzerr49[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x8,0x8,0x18, 0x20,0x0,0x0,0x0};
SetWordType zzerr50[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x8,0xa,0x18, 0x30,0x0,0x0,0x0};
SetWordType zzerr51[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x4,0x8,0x8,0x18, 0x28,0x0,0x0,0x0};
SetWordType zzerr52[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x40,0x0,0x4,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr53[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4,
0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType setwd8[157] = {0x0,0x0,0xe1,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0xe1,0xe1,0xe1,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0xe1,0x0,0xe1,0x0,0x0,0xe3,0xe7,0x0,
0x0,0x0,0x0,0xe1,0x0,0xe1,0xe1,0xef,
0x0,0x0,0xe1,0x0,0xe1,0x0,0x0,0x0,
0x0,0x0,0x10,0xef,0xe1,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0xe1,0xe1,0x0,0x0,
0x0,0x0,0xe1,0xe1,0x0,0x10,0xe1,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr54[20] = {0x2,0x0,0x0,0x0, 0x14,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x78,0x9, 0xe0,0x0,0x0,0x0};
SetWordType zzerr55[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x78,0x9, 0x60,0x0,0x0,0x0};
SetWordType zzerr56[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x30,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr57[20] = {0x2,0x0,0x0,0x0, 0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x1c,0xf8,0x78,0x9, 0xe0,0x0,0x0,0x0};
SetWordType setwd9[157] = {0x0,0x7c,0x1,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x7f,0x1,0x1,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x1,0x0,0x1,0x0,0x0,0x1,0x1,0x0,
0x0,0x0,0x0,0x7f,0x7e,0x7f,0x1,0x1,
0x0,0x0,0x1,0x0,0x7d,0x7e,0x7e,0x7e,
0x7e,0x0,0x0,0x1,0x7d,0x7e,0x7e,0x7e,
0x0,0x7e,0x0,0x0,0x7d,0x1,0x0,0x0,
0x0,0x0,0x1,0x1,0x0,0x0,0x7f,0x64,
0x64,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x80,0x0,0x0,0x0,0x0,0x0,0x80,0x0,
0x80,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr58[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0xa0,0x0};
SetWordType zzerr59[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x80,0xa0,0x0};
SetWordType zzerr60[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0xa0,0x0};
SetWordType zzerr61[20] = {0x2,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x80,0xa0,0x0};
SetWordType zzerr62[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xe};
SetWordType zzerr63[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xe};
SetWordType zzerr64[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xe};
SetWordType zzerr65[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0, 0x0,0x0,0x10,0xc};
SetWordType setwd10[157] = {0x0,0xc,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x0,
0x3,0x0,0x0,0xf0,0xf0,0x0};
SetWordType setwd11[157] = {0x0,0x1,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x1,0x0,0x0,0x0,0x0,0x0};

View File

@@ -0,0 +1,123 @@
/*
* fcache.c
*
* 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.
*
* ANTLR 1.33MR10
*
*/
#include <stdio.h>
#include <ctype.h>
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#ifdef __USE_PROTOS
CacheEntry *dumpFcache1(char *prev)
#else
CacheEntry *dumpFcache1(prev)
char *prev;
#endif
{
Entry **table=Fcache;
int low=0;
int hi=0;
CacheEntry *least=NULL;
Entry **p;
for (p=table; p<&(table[HashTableSize]); p++) {
CacheEntry *q =(CacheEntry *) *p;
if ( q != NULL && low==0 ) low = p-table;
while ( q != NULL ) {
if (strcmp(q->str,prev) > 0) {
if (least == NULL) {
least=q;
} else {
if (strcmp(q->str,least->str) < 0) {
least=q;
};
};
};
q = q->next;
};
if ( *p != NULL ) hi = p-table;
}
return least;
}
#ifdef __USE_PROTOS
void reportFcache(CacheEntry *q)
#else
void reportFcache(q)
CacheEntry *q;
#endif
{
char *qstr;
fprintf(stdout,"\nrule ");
for (qstr=q->str; *qstr != '*' ; qstr++) {
fprintf(stdout,"%c",*qstr);
};
qstr++;
if (*qstr == 'i') fprintf(stdout," First[");
if (*qstr == 'o') fprintf(stdout," Follow[");
qstr++;
fprintf(stdout,"%s]",qstr);
if (q->incomplete) fprintf(stdout," *** incomplete ***");
fprintf(stdout,"\n");
MR_dumpTokenSet(stdout,1,q->fset);
}
void
#ifdef __USE_PROTOS
DumpFcache(void)
#else
DumpFcache()
#endif
{
char *prev="";
int n=0;
CacheEntry *next;
fprintf(stdout,"\n\nDump of First/Follow Cache\n");
for(;;) {
next=dumpFcache1(prev);
if (next == NULL) break;
reportFcache(next);
++n;
prev=next->str;
};
fprintf(stdout,"\nEnd dump of First/Follow Cache\n");
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,286 @@
/*
* generic.h -- generic include stuff for new PCCTS ANTLR.
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#define StrSame 0
#define DefaultParserName "zzparser"
/* MR9 JVincent@novell.com Allow user to override default ZZLEXBUFSIZE */
/* MR11 thm Raise antlr's own default ZZLEXBUFSIZE to 8k */
/* MR22 thm Raise antlr's own default ZZLEXBUFSIZE to 32k */
#ifndef ZZLEXBUFSIZE
#define ZZLEXBUFSIZE 32000
#endif
/* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */
#define ALT TokenNum+1
#define SET TokenNum+2
#define TREE_REF TokenNum+3
/* E r r o r M a c r o s */
#define fatal(err) fatalFL(err, __FILE__, __LINE__)
#define fatal_internal(err) fatal_intern(err, __FILE__, __LINE__)
#define eMsg1(s,a) eMsg3(s,a,NULL,NULL)
#define eMsg2(s,a,b) eMsg3(s,a,b,NULL)
/* S a n i t y C h e c k i n g */
#ifndef require
#define require(expr, err) {if ( !(expr) ) fatal_internal(err);}
#endif
/* L i s t N o d e s */
typedef struct _ListNode {
void *elem; /* pointer to any kind of element */
struct _ListNode *next;
} ListNode;
/* Define a Cycle node which is used to track lists of cycles for later
* reconciliation by ResolveFoCycles().
*/
typedef struct _c {
int croot; /* cycle root */
set cyclicDep; /* cyclic dependents */
unsigned deg; /* degree of FOLLOW set of croot */
} Cycle;
typedef struct _e {
int tok; /* error class name == TokenStr[tok] */
ListNode *elist; /* linked list of elements in error set */
set eset;
int setdeg; /* how big is the set */
int lexclass; /* which lex class is it in? */
} ECnode;
typedef struct _TCnode {
int tok; /* token class name */
ListNode *tlist; /* linked list of elements in token set */
set tset;
int lexclass; /* which lex class is it in? */
unsigned char dumped; /* this def has been been dumped */
unsigned char dumpedComplement; /* this def has been been dumped */
unsigned setnum; /* which set number is this guy? (if dumped) */
unsigned setnumComplement; /* MR23 */
unsigned setnumErrSet; /* MR23 which set is this #tokclass error set (if dumped) */
unsigned setnumErrSetComplement; /* MR23 */
} TCnode;
typedef struct _ft {
char *token; /* id of token type to remap */
int tnum; /* move token type to which token position */
} ForcedToken;
typedef struct _ContextGuardPredicates { /* MR13 */
Predicate *pred; /* MR13 */
} ContextGuardPredicates; /* MR13 */
#define newListNode (ListNode *) calloc(1, sizeof(ListNode));
#define newCycle (Cycle *) calloc(1, sizeof(Cycle));
#define newECnode (ECnode *) calloc(1, sizeof(ECnode));
#define newTCnode (TCnode *) calloc(1, sizeof(TCnode));
/* H a s h T a b l e E n t r i e s */
typedef struct _t { /* Token name or expression */
char *str;
struct _t *next;
int token; /* token number */
unsigned char classname; /* is it a err/tok class name or token */
TCnode *tclass; /* ptr to token class */
char *action;
char *akaString;
} TermEntry;
typedef struct _r { /* Rule name and ptr to start of rule */
char *str;
struct _t *next;
int rulenum; /* RulePtr[rulenum]== ptr to RuleBlk junction */
unsigned char noAST;/* gen AST construction code? (def==gen code) */
char *egroup; /* which error group (err reporting stuff) */
#if 0
/* MR27 This appears to never be used. Delete this code later. */
ListNode *el_labels;/* list of element labels ref in all of rule */
#endif
ListNode *ast_labels_in_actions; /* MR27 */
unsigned char has_rule_exception;
char dontComputeErrorSet; /* MR14 - don't compute error set
special for rule in alpha part of
(alpha)? beta block */
} RuleEntry;
typedef struct _f { /* cache Fi/Fo set */
char *str; /* key == (rulename, computation, k) */
struct _f *next;
set fset; /* First/Follow of rule */
set rk; /* set of k's remaining to be done after ruleref */
int incomplete; /* only w/FOLLOW sets. Use only if complete */
} CacheEntry;
typedef struct _LabelEntry { /* element labels */
char *str;
struct _f *next;
Node *elem; /* which element does it point to? */
ExceptionGroup *ex_group;
/* Is there an exception attached to label? */
ExceptionGroup *outerEG; /* MR7 */
/* next EG if ex_group doesn't catch it MR7 */
struct _LabelEntry *pendingLink; /* MR7 */
/* too lazy to use ListNode ? MR7 */
int curAltNum; /* MR7 */
} LabelEntry;
typedef struct _SignalEntry {
char *str;
struct _f *next;
int signum; /* unique signal number */
} SignalEntry;
typedef struct _PredEntry { /* MR11 predicate name and ptr to string */
char *str;
struct _PredEntry *next;
int file;
int line;
Predicate *pred;
char *predLiteral;
} PredEntry;
typedef struct _PointerStack { /* MR10 */
int count;
int size;
void **data;
} PointerStack;
#define newTermEntry(s) (TermEntry *) newEntry(s, sizeof(TermEntry))
#define newRuleEntry(s) (RuleEntry *) newEntry(s, sizeof(RuleEntry))
#define newCacheEntry(s) (CacheEntry *) newEntry(s, sizeof(CacheEntry))
#define newLabelEntry(s) (LabelEntry *) newEntry(s, sizeof(LabelEntry))
#define newSignalEntry(s) (SignalEntry *) newEntry(s, sizeof(SignalEntry))
#define newPredEntry(s) (PredEntry *) newEntry(s,sizeof(PredEntry))
typedef struct _UserAction {
char *action;
int file, line;
} UserAction;
/* L e x i c a l C l a s s */
/* to switch lex classes, switch ExprStr and Texpr (hash table) */
typedef struct _lc {
char *classnum, **exprs;
Entry **htable;
} LClass;
typedef struct _exprOrder {
char *expr;
int lclass;
} Expr;
typedef Graph Attrib;
/* M a x i m u m s */
/* MR20 Note G. Hobbelt These values are superceded by values in hash.h */
#ifndef HashTableSize
#define HashTableSize 253
#endif
#ifndef StrTableSize
#define StrTableSize 15000 /* all tokens, nonterminals, rexprs stored here */
#endif
#define MaxLexClasses 50 /* how many automatons */
/* TokenStart and EofToken are ignored if #tokdefs meta-op is used */
#define TokenStart 2 /* MUST be in 1 + EofToken */
#define EofToken 1 /* Always predefined to be 1 */
#ifndef MaxNumFiles
#define MaxNumFiles 99
#endif
/**** MR9 JVincent@novell.com Move to pcctscfg.h */
/**** #define MaxFileName 300 ****/ /* MR9 Move to pcctscfg.h */ /* largest file name size */
#define MaxRuleName 100 /* largest rule name size */
#define TSChunk 100 /* how much to expand TokenStr/ExprStr each time */
#define TIChunk TSChunk /* expand TokenInd by same as TokenStr to mirror them */
#define FoStackSize 100 /* deepest FOLLOW recursion possible */
#define MaxClassDeclStuff 256 /* MR10 */
#define NumPredefinedSignals 3
/* S t a n d a r d S i g n a l s */
#define sigNoSignal 0
#define sigMismatchedToken 1
#define sigNoViableAlt 2
#define sigNoSemViableAlt 3
/* AST token types */
#define ASTexclude 0
#define ASTchild 1
#define ASTroot 2
#define ASTinclude 3 /* include subtree made by rule ref */
#define PredictionVariable "zzpr_expr"
#define PredictionLexClassSuffix "_zzpred"
#define WildCardString "WildCard"
#if 0
/* Removed in version 1.33MR19
Don't understand why this never caused problems before
*/
/*********************************************************
#ifndef ANTLRm
#define ANTLRm(st, f, _m) zzbufsize = ZZLEXBUFSIZE;\
zzmode(_m); \
zzenterANTLR(f); \
st; ++zzasp; \
zzleaveANTLR(f);
#endif
*********************************************************/
#endif
#include "proto.h"
#include "pcctscfg.h" /* MR14 */
#include <string.h>

View File

@@ -0,0 +1,484 @@
/*
* globals.c -- File containing all variables/tables visible to all files.
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
char Version[] = "1.33MR33" ; /* PCCTS version number */ /* MRXXX */
char VersionDef[] = "13333"; /* same (except int equiv for preproc symbol) */ /* MRXXX */
char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */
char *RemapFileName = "remap.h";
char *DlgFileName = "parser.dlg";
char *DefFileName = "tokens.h";
char *ErrFileName = "err.c";
char *ModeFileName = "mode.h";
char *StdMsgName = NULL;
char *ParserName = DefaultParserName;
/* list of PCCTS supplied support symbols; these are renamed when more than
* one ANTLR-generated parsers are linked together to avoid name conflicts.
* Can't use '##' ANSIC preprocessor concat operator with K&R and:
* #define zzskip zzparser ## skip
* will not work for ANSI/C++ as 'zzparserskip' is created w/o zzparser
* being substituted--ack!!!
*/
char *StandardSymbols[] = {
/* ANTLR stuff */
"zzStackOvfMsg",
"zzasp",
"zzaStack",
"inf_tokens",
"inf_text",
"inf_text_buffer",
"inf_text_buffer_ptr",
"inf_text_buffer_size",
"inf_labase",
"inf_last",
"inf_lap",
"zztokenLA",
"zztextLA",
"zzlap",
"zzlabase",
"zztoktext",
"zztoken",
"zzdirty",
"zzguessing",
"zzguess_start",
"zzresynch",
"zzinf_tokens",
"zzinf_text",
"zzinf_text_buffer",
"zzinf_labase",
"zzinf_last",
"zzfill_inf_look",
"zzFAIL",
"zzsave_antlr_state",
"zzrestore_antlr_state",
"zzsyn",
"zzset_el",
"zzset_deg",
"zzedecode",
"_zzsetmatch",
"_zzmatch",
"_inf_zzgettok",
"zzconsumeUntil",
"zzconsumeUntilToken",
"_zzmatch_wsig",
"_zzsetmatch_wsig",
"_zzmatch_wdfltsig",
"_zzsetmatch_wdfltsig",
"zzdflthandlers",
/* DLG stuff */
"zzreal_line",
"zzcharfull",
"zzerr",
"zzlextext",
"zzbegexpr",
"zzendexpr",
"zzbufsize",
"zzbegcol",
"zzendcol",
"zzline",
"zzchar",
"zzbufovf",
"zzrdstream",
"zzrdfunc",
"zzrdstr",
"zzclose_stream",
"zzsave_dlg_state",
"zzrestore_dlg_state",
"zzmode",
"zzskip",
"zzmore",
"zzreplchar",
"zzreplstr",
"zzgettok",
"zzadvance",
"zzerrstd",
"zzerr_in",
"zzconstr_attr",
"zzempty_attr",
"zzerraction",
"zztokens", /* list of token regular expressions */
"dfa",
"accepts",
"actions",
"zzTraceOptionValue", /* MR10 */
"zzTraceGuessOptionValue", /* MR10 */
"zzTraceCurrentRuleName", /* MR10 */
"zzTraceDepth", /* MR10 */
"zzGuessSeq", /* MR10 */
"zzSyntaxErrCount", /* MR11 */
"zzLexErrCount", /* MR11 */
"zzTraceGuessDone", /* MR13 - BJS */
"zzTraceGuessFail", /* MR13 - BJS */
"zzTraceGuessOption", /* MR13 - BJS */
"zzTraceIn", /* MR13 - BJS */
"zzTraceOption", /* MR13 - BJS */
"zzTraceOut", /* MR13 - BJS */
"zzTraceReset", /* MR13 - BJS */
NULL /* must be present */
};
/* list of PCCTS supplied support functions; these are renamed when more than
* one ANTLR-generated parsers are linked together to avoid name conflicts.
*/
char *ASTSymbols[] = {
"AST",
"zzast_sp",
"zzastStack",
"zzlink",
"zzastnew",
"zzsubchild",
"zzsubroot",
"zzpre_ast",
"zzfree_ast",
"zztmake",
"zzdup_ast",
"zztfree",
"zzdouble_link",
NULL /* must be present */
};
/* Current ambiguity examination information */
int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
char *CurAmbigbtype;
/* M e t h o d T a b l e s */
/*
* The following tables are used to fill syntax diagram nodes with the correct
* function pointers for computing FIRST sets and printing themselves.
*/
/* fpTraverse[node type] == pointer to function that calculates trees
* representing the FIRST sets for that node (maintains spatial info).
* We use 'struct _tree' not 'tree' due to a g++ 2.4.3 bug.
*/
#ifdef __cplusplus
struct _tree *(*fpTraverse[NumNodeTypes+1])(... /* Node *, int, set * */) = {
NULL,
(struct _tree *(*)(...)) tJunc,
(struct _tree *(*)(...)) tRuleRef,
(struct _tree *(*)(...)) tToken,
(struct _tree *(*)(...)) tAction
};
#else
Tree *(*fpTraverse[NumNodeTypes+1])() = {
NULL,
tJunc,
tRuleRef,
tToken,
tAction
};
#endif
/* fpReach[node type] == pointer to function that calculates FIRST set for
* that node. (r stands for reach). We use 'struct _set' not 'set'
* due to a g++ 2.4.3 bug.
*/
#ifdef __cplusplus
struct _set (*fpReach[NumNodeTypes+1])(... /* Node *, int, set * */) = {
NULL,
(struct _set (*)(...)) rJunc,
(struct _set (*)(...)) rRuleRef,
(struct _set (*)(...)) rToken,
(struct _set (*)(...)) rAction
};
#else
set (*fpReach[NumNodeTypes+1])() = {
NULL,
rJunc,
rRuleRef,
rToken,
rAction
};
#endif
/* fpPrint[node type] == pointer to function that knows how to print that node. */
#ifdef __cplusplus
void (*fpPrint[NumNodeTypes+1])(... /* Node * */) = {
NULL,
(void (*)(...)) pJunc,
(void (*)(...)) pRuleRef,
(void (*)(...)) pToken,
(void (*)(...)) pAction
};
#else
void (*fpPrint[NumNodeTypes+1])() = {
NULL,
pJunc,
pRuleRef,
pToken,
pAction
};
#endif
char *decodeJType[] = {
"invalid",
"aSubBlk",
"aOptBlk",
"aLoopBlk",
"EndBlk",
"RuleBlk",
"Generic",
"EndRule",
"aPlusBlk",
"aLoopBegin"
};
/* H a s h T a b l e s */
Entry **Tname, /* Table of all token names (maps name to tok num)*/
**Texpr, /* Table of all token expressions
(maps expr to tok num) */
**Rname, /* Table of all Rules (has ptr to start of rule) */
**Fcache, /* Cache of First/Follow Computations */
**Tcache; /* Tree cache; First/Follow for permute trees */
Entry **Elabel; /* Table of all element label names */
Entry **Sname; /* Signal names */
Entry **Pname; /* symbolic predicate names MR11 */
/* V a r i a b l e s */
int Save_argc; /* MR10 */
char **Save_argv; /* MR10 */
int EpToken=0; /* Imaginary Epsilon token number */
int WildCardToken=0;
int CurFile= -1; /* Index into FileStr table */
char *CurPredName=NULL; /* MR11 */
char *CurRule=NULL; /* Pointer to current rule name */
int CurRuleDebug=0; /* MR13 debug flag */
RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */
char *CurRetDef=NULL; /* Pointer to current return type definition */
char *CurParmDef=NULL; /* Pointer to current parameter definition */
Junction *CurRuleBlk=NULL; /* Pointer to current block node for enclosing block */
ListNode *CurExGroups=NULL; /* Current list of exception groups for rule/alts */
ListNode *CurElementLabels=NULL;
ListNode *CurAstLabelsInActions=NULL; /* MR27 */
/* MR10 used by <<>>? to set "label_used_in_semantic_pred" */
/* MR10 this will force LT(i) assignment even in guess mode */
ListNode *CurActionLabels=NULL; /* MR10 Element Labels appearing in last action */
int numericActionLabel=0 ; /* MR10 << ... $1 ... >> or << ... $1 ... >>? */
ListNode *NumericPredLabels=NULL; /* MR10 << ... $1 ... >>? ONLY */
ListNode *ContextGuardPredicateList=NULL; /* MR13 for re-evaluating predicates
after meta tokens are defined */
int CurBlockID=0; /* Unique int for each block */
int CurAltNum=0;
Junction *CurAltStart = NULL; /* Junction node that starts the alt */
Junction *OuterAltStart = NULL; /* For chaining exception groups MR7 */
int NumRules=0; /* Rules are from 1 to n */
FILE *output=NULL; /* current parser output file */
FILE *input=NULL; /* current grammar input file */
char *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */
int NumFiles=0; /* current grammar file number */
#ifdef __cplusplus
void (**fpTrans)(...), /* array of ptrs to funcs that translate nodes */
(**fpJTrans)(...); /* ... that translate junctions */
#else
void (**fpTrans)(), /* array of ptrs to funcs that translate nodes */
(**fpJTrans)(); /* ... that translate junctions */
#endif
int **FoStack; /* Array of LL_k ptrs to stacks of rule numbers */
int **FoTOS; /* FOLLOW stack top-of-stack pointers */
Junction *SynDiag = NULL; /* Pointer to start of syntax diagram */
int BlkLevel=1; /* Current block level. Set by antlr.g, used by
* scanner to translate $i.j attributes */
set reserved_positions; /* set of token positions reserved by '#token T=i' cmds */
set all_tokens; /* set of all token types */
set imag_tokens; /* set of all imaginary token types (EpToken, errclasses...) */
set tokclasses; /* set of all token class token types */
ListNode *ForcedTokens = 0; /* list of token_id/token_num pairs to remap */
ListNode *MetaTokenNodes=NULL; /* list of meta token refs such as token classes etc... */
int *TokenInd=NULL; /* an indirection level between token num and position
* of that token def in TokenStr and ExprStr */
int LastTokenCounted=0; /* ==TokenNum if no token renumbering (same as old TokenNum) */
int TokenNum=TokenStart;
char **TokenStr=NULL; /* map token # to token name */
char **ExprStr=NULL; /* map token # to expr */
Junction **RulePtr=NULL; /* map rule # to RuleBlk node of rule */
ListNode *ExprOrder=NULL; /* list of exprs as they are found in grammar */
ListNode *BeforeActions=NULL;/* list of grammar actions before rules */
ListNode *AfterActions=NULL;/* list of grammar actions after rules */
ListNode *LexActions=NULL; /* list of lexical actions */
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via #lexmember <<....>> */
/* MR1 via #lexprefix <<....>> */
/* MR1 */
ListNode *LexMemberActions=NULL;/* list of lexical header member decl MR1 */
ListNode *LexPrefixActions=NULL;/* list of lexical header #include decl MR1 */
ListNode **Cycles=NULL; /* list of cycles (for each k) found when
doing FOLLOWs */
ListNode *eclasses=NULL; /* list of error classes */
ListNode *tclasses=NULL; /* list of token classes */
LClass lclass[MaxLexClasses]; /* array of lex class definitions */
int CurrentLexClass; /* index into lclass */
int NumLexClasses=0; /* in range 1..MaxLexClasses (init 0) */
char *HdrAction=NULL; /* action defined with #header */
char *FirstAction=NULL; /* action defined with #first MR11 */
FILE *ErrFile; /* sets and error recovery stuff */
FILE *DefFile=NULL; /* list of tokens, return value structs, setwd defs */
FILE *MRinfoFile=NULL; /* MR10 information file */
int MRinfo=0; /* MR10 */
int MRinfoSeq=0; /* MR10 */
int InfoP=0; /* MR10 predicates */
int InfoT=0; /* MR10 tnodes */
int InfoF=0; /* MR10 first/follow sets */
int InfoM=0; /* MR10 monitor progress */
int InfoO=0; /* MR12 orphan rules */
int TnodesInUse=0; /* MR10 */
int TnodesPeak=0; /* MR10 */
int TnodesAllocated=0; /* MR10 */
int TnodesReportThreshold=0; /* MR11 */
int PotentialSuppression=0; /* MR10 */
int PotentialDummy=0; /* MR10 */
int CannotContinue=FALSE;
int OutputLL_k = 1; /* LL_k for parsing must be power of 2 */
int action_file; /* used to track start of action */
int action_line;
int FoundGuessBlk=0; /* there is a (...)? block somewhere in grammar */
int FoundException=0; /* there is an exception somewhere in grammar */
/* MR6 Distinguish between @ operator and real exception */
/* MR6 by keeping separate flags for @ operator and real exceptions */
int FoundAtOperator=0; /* MR6 */
int FoundExceptionGroup=0; /* MR6 */
int pLevel=0; /* print Level */
int pAlt1,pAlt2; /* print "==>" in front of these alts */
/* C++ output stuff */
FILE *Parser_h, /* where subclass of ANTLRParser goes */
*Parser_c; /* where code for subclass of ANTLRParser goes */
char Parser_h_Name[MaxFileName+1] = "";
char Parser_c_Name[MaxFileName+1] = "";
char MRinfoFile_Name[MaxFileName+1] = ""; /* MR10 */
char *ClassDeclStuff=NULL; /* MR10 */
char *BaseClassName=NULL; /* MR22 */
/* list of actions inside the #class {...} defs */
ListNode *class_before_actions=NULL;
ListNode *class_after_actions=NULL;
char CurrentClassName[MaxRuleName]="";
int no_classes_found=1;
char *UserTokenDefsFile;
int UserDefdTokens=0; /* found #tokdefs? */
char *OutputDirectory=TopDirectory;
ExceptionGroup *DefaultExGroup = NULL;
int NumSignals = NumPredefinedSignals;
int ContextGuardTRAV=0;
char *MR_AmbAidRule=NULL; /* MR11 */
int MR_AmbAidLine=0; /* MR11 */
int MR_AmbAidDepth=0; /* MR11 */
int MR_AmbAidMultiple=0; /* MR11 */
int MR_skipped_e3_report=0; /* MR11 */
int MR_usingPredNames=0; /* MR11 */
int MR_BadExprSets=0; /* MR13 */
int MR_Inhibit_Tokens_h_Gen=0; /* MR13 */
int NewAST=0; /* MR13 */
int tmakeInParser=0; /* MR23 */
int AlphaBetaTrace=0; /* MR14 */
int MR_BlkErr=0; /* MR21 */
int MR_AlphaBetaMessageCount=0; /* MR14 */
int MR_AlphaBetaWarning=0; /* MR14 */
int MR_ErrorSetComputationActive=0; /* MR14 */
int MR_MaintainBackTrace=0; /* MR14 */
set MR_CompromisedRules; /* MR14 */
Junction *MR_RuleBlkWithHalt; /* MR10 */
/* C m d - L i n e O p t i o n s */
int LL_k=1; /* how many tokens of full lookahead */
int CLL_k= -1; /* how many tokens of compressed lookahead */
int PrintOut = FALSE; /* print out the grammar */
int PrintAnnotate = FALSE;/* annotate printout with FIRST sets */
int CodeGen=TRUE; /* Generate output code? */
int LexGen=TRUE; /* Generate lexical files? (tokens.h, parser.dlg) */
int GenAST=FALSE; /* Generate AST's? */
int GenANSI=FALSE; /* Generate ANSI code where necessary */
int GenExprSetsOpt=TRUE;/* use sets not (LA(1)==tok) expression lists */
int GenCR=FALSE; /* Generate cross reference? */
int GenLineInfo=FALSE; /* Generate # line "file" stuff? */
int GenLineInfoMS=FALSE;/* Like -gl but replace "\" with "/" for MS C/C++ systems */
int TraceGen=FALSE; /* Generate code to trace rule invocation */
int elevel=1; /* error level for ambiguity messages */
int GenEClasseForRules=0;/* don't generate eclass for each rule */
int TreeResourceLimit= -1;/* don't limit tree resource */
int DemandLookahead = 0;/* demand/delayed lookahead or not */
char *RulePrefix = ""; /* prefix each generated rule with this */
char *stdpccts = "stdpccts.h";/* where to generate std pccts include file */
int GenStdPccts = 0; /* don't gen stdpccts.h? */
int ParseWithPredicates = 1;
int WarningLevel = 1;
int UseStdout = 0; /* MR6 */
int TabWidth = 2; /* MR6 */ /* MR27 */
int HoistPredicateContext = 0;
int MRhoisting = 0; /* MR9 */
int MRhoistingk = 0; /* MR13 */
int MR_debugGenRule=0; /* MR11 */
int GenCC = 0; /* Generate C++ output */
PointerStack MR_BackTraceStack={0,0,NULL}; /* MR10 */
PointerStack MR_PredRuleRefStack={0,0,NULL}; /* MR10 */
PointerStack MR_RuleBlkWithHaltStack={0,0,NULL}; /* MR10 */
/* DontCopyTokens and Pragma_DupLabeledTokens were a bad idea. I've just
turned them off rather than backpatching the code. Who knows? We
may need them in the future.
*/
int DontCopyTokens = 1; /* in C++, don't copy ANTLRToken passed to ANTLR */
/* Remember if LT(i), LA(i), or LATEXT(i) used in an action which is not
a predicate. If so, give a warning for novice users.
*/
int LTinTokenAction = 0; /* MR23 */
int PURIFY = 1; /* MR23 */
int CurBlockID_array[MAX_BLK_LEVEL]; /* MR23 */
int CurAltNum_array[MAX_BLK_LEVEL]; /* MR23 */

View File

@@ -0,0 +1,221 @@
/*
* hash.c
*
* Manage hash tables.
*
* The following functions are visible:
*
* char *mystrdup(char *); Make space and copy string
* Entry **newHashTable(); Create and return initialized hash table
* Entry *hash_add(Entry **, char *, Entry *)
* Entry *hash_get(Entry **, char *)
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include "pcctscfg.h"
#include "hash.h"
#ifdef __USE_PROTOS
#include <stdlib.h>
#else
#ifdef VAXC
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#endif
#include <string.h>
#define StrSame 0
#define fatal(err) \
{fprintf(stderr, "%s(%d):", __FILE__, __LINE__); \
fprintf(stderr, " %s\n", err); exit(PCCTS_EXIT_FAILURE);}
#define require(expr, err) {if ( !(expr) ) fatal(err);}
static unsigned size = HashTableSize;
static char *strings = NULL;
static char *strp;
static unsigned strsize = StrTableSize;
/* create the hash table and string table for terminals (string table only once) */
Entry **
#ifdef __USE_PROTOS
newHashTable( void )
#else
newHashTable( )
#endif
{
Entry **table;
table = (Entry **) calloc(size, sizeof(Entry *));
require( table != NULL, "cannot allocate hash table");
if ( strings == NULL )
{
strings = (char *) calloc(strsize, sizeof(char));
require( strings != NULL, "cannot allocate string table");
strp = strings;
}
return table;
}
void
#ifdef __USE_PROTOS
killHashTable( Entry **table )
#else
killHashTable( table )
Entry **table;
#endif
{
/* for now, just free table, forget entries */
free( (char *) table ); /* MR10 cast */
}
/* Given a table, add 'rec' with key 'key' (add to front of list). return ptr to entry */
Entry *
#ifdef __USE_PROTOS
hash_add( Entry **table, char *key, Entry *rec )
#else
hash_add( table, key, rec )
Entry **table;
char *key;
Entry *rec;
#endif
{
unsigned h=0;
char *p=key;
require(table!=NULL && key!=NULL && rec!=NULL, "add: invalid addition");
Hash(p,h,size);
rec->next = table[h]; /* Add to singly-linked list */
table[h] = rec;
return rec;
}
/* Return ptr to 1st entry found in table under key (return NULL if none found) */
Entry *
#ifdef __USE_PROTOS
hash_get( Entry **table, char *key )
#else
hash_get( table, key )
Entry **table;
char *key;
#endif
{
unsigned h=0;
char *p=key;
Entry *q;
/* require(table!=NULL && key!=NULL, "get: invalid table and/or key");*/
if ( !(table!=NULL && key!=NULL) ) *((char *) 34) = 3;
Hash(p,h,size);
for (q = table[h]; q != NULL; q = q->next)
{
if ( strcmp(key, q->str) == StrSame ) return( q );
}
return( NULL );
}
#ifdef DEBUG_HASH
void
#ifdef __USE_PROTOS
hashStat( Entry **table )
#else
hashStat( table )
Entry **table;
#endif
{
static unsigned short count[20];
int i,n=0,low=0, hi=0;
Entry **p;
float avg=0.0;
for (i=0; i<20; i++) count[i] = 0;
for (p=table; p<&(table[size]); p++)
{
Entry *q = *p;
int len;
if ( q != NULL && low==0 ) low = p-table;
len = 0;
if ( q != NULL ) fprintf(stderr, "[%d]", p-table);
while ( q != NULL )
{
len++;
n++;
fprintf(stderr, " %s", q->str);
q = q->next;
if ( q == NULL ) fprintf(stderr, "\n");
}
count[len]++;
if ( *p != NULL ) hi = p-table;
}
fprintf(stderr, "Storing %d recs used %d hash positions out of %d\n",
n, size-count[0], size);
fprintf(stderr, "%f %% utilization\n",
((float)(size-count[0]))/((float)size));
for (i=0; i<20; i++)
{
if ( count[i] != 0 )
{
avg += (((float)(i*count[i]))/((float)n)) * i;
fprintf(stderr, "Bucket len %d == %d (%f %% of recs)\n",
i, count[i], ((float)(i*count[i]))/((float)n));
}
}
fprintf(stderr, "Avg bucket length %f\n", avg);
fprintf(stderr, "Range of hash function: %d..%d\n", low, hi);
}
#endif
/* Add a string to the string table and return a pointer to it.
* Bump the pointer into the string table to next avail position.
*/
char *
#ifdef __USE_PROTOS
mystrdup( char *s )
#else
mystrdup( s )
char *s;
#endif
{
char *start=strp;
require(s!=NULL, "mystrdup: NULL string");
while ( *s != '\0' )
{
require( strp <= &(strings[strsize-2]),
"string table overflow\nIncrease StrTableSize in hash.h and recompile hash.c\n");
*strp++ = *s++;
}
*strp++ = '\0';
return( start );
}

View File

@@ -0,0 +1,73 @@
/*
* hash.h -- define hash table entries, sizes, hash function...
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
/* H a s h T a b l e S t u f f */
#ifndef HashTableSize
#define HashTableSize 553
#endif
#ifndef StrTableSize
#ifdef PC32
#define StrTableSize 1000000
#endif
#endif
#ifndef StrTableSize
#ifdef PC
#define StrTableSize 655200
#endif
#endif
#ifndef StrTableSize
#define StrTableSize 1000000
#endif
typedef struct _entry { /* Minimum hash table entry -- superclass */
char *str;
struct _entry *next;
} Entry;
/* Hash 's' using 'size', place into h (s is modified) */
#define Hash(s,h,size) \
{while ( *s != '\0' ) h = (h<<1) + *s++; \
h %= size;}
#ifdef __USE_PROTOS
Entry *hash_get(Entry **, char *),
**newHashTable(void),
*hash_add(Entry **, char *, Entry *);
void killHashTable(Entry **);
#else
Entry *hash_get(), **newHashTable(), *hash_add();
void killHashTable(); /* MR9 23-Sep-97 */
#endif

View File

@@ -0,0 +1,878 @@
/*
* lex.c -- Generate all of the lexical type files: parser.dlg tokens.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include <ctype.h>
/* MR1 */
/* MR1 10-Apr-97 MR1 Replace use of __STDC__ with __USE_PROTOS */
/* MR1 */
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#define DLGErrorString "invalid token"
/* Generate a complete lexical description of the lexemes found in the grammar */
void
#ifdef __USE_PROTOS
genLexDescr( void )
#else
genLexDescr( )
#endif
{
ListNode *p;
FILE *dlgFile = fopen(OutMetaName(DlgFileName), "w");
require(dlgFile!=NULL, eMsg1("genLexFile: cannot open %s", OutMetaName(DlgFileName)) );
#ifdef SPECIAL_FOPEN
special_fopen_actions(OutMetaName(DlgFileName)); /* MR1 */
#endif
fprintf(dlgFile, "<<\n");
fprintf(dlgFile, "/* %s -- DLG Description of scanner\n", DlgFileName);
fprintf(dlgFile, " *\n");
fprintf(dlgFile, " * Generated from:");
{int i; for (i=0; i<NumFiles; i++) fprintf(dlgFile, " %s", FileStr[i]);}
fprintf(dlgFile, "\n");
fprintf(dlgFile, " *\n");
fprintf(dlgFile, " * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001\n");
fprintf(dlgFile, " * Purdue University Electrical Engineering\n");
fprintf(dlgFile, " * With AHPCRC, University of Minnesota\n");
fprintf(dlgFile, " * ANTLR Version %s\n", Version);
fprintf(dlgFile, " */\n\n");
if (FirstAction != NULL ) dumpAction( FirstAction, dlgFile, 0, -1, 0, 1 ); /* MR11 MR15b */
fprintf(dlgFile, "#define ANTLR_VERSION %s\n", VersionDef);
if ( GenCC )
{
if ( !UserDefdTokens ) fprintf(dlgFile, "#include \"%s\"\n", DefFileName);
else fprintf(dlgFile, "#include %s\n", UserTokenDefsFile);
fprintf(dlgFile, "#include \"%s\"\n", ATOKEN_H);
if ( GenAST ) fprintf(dlgFile, "#include \"%s\"\n", ASTBASE_H);
if ( HdrAction != NULL ) dumpAction( HdrAction, dlgFile, 0, -1, 0, 1 );
}
else
{
fprintf(dlgFile, "#include \"pcctscfg.h\"\n");
fprintf(dlgFile, "#include \"pccts_stdio.h\"\n");
if ( strcmp(ParserName, DefaultParserName)!=0 )
fprintf(dlgFile, "#define %s %s\n", DefaultParserName, ParserName);
if ( strcmp(ParserName, DefaultParserName)!=0 )
fprintf(dlgFile, "#include \"%s\"\n", RemapFileName);
if ( HdrAction != NULL ) dumpAction( HdrAction, dlgFile, 0, -1, 0, 1 );
if ( FoundGuessBlk )
{
fprintf(dlgFile, "#define ZZCAN_GUESS\n");
fprintf(dlgFile, "#include \"pccts_setjmp.h\"\n");
}
if ( OutputLL_k > 1 ) fprintf(dlgFile, "#define LL_K %d\n", OutputLL_k);
if ( DemandLookahead ) fprintf(dlgFile, "#define DEMAND_LOOK\n");
if (TraceGen) {
fprintf(dlgFile,"#ifndef zzTRACE_RULES\n"); /* MR20 */
fprintf(dlgFile,"#define zzTRACE_RULES\n"); /* MR20 */
fprintf(dlgFile,"#endif\n"); /* MR22 */
};
fprintf(dlgFile, "#include \"antlr.h\"\n");
if ( GenAST ) {
fprintf(dlgFile, "#include \"ast.h\"\n");
}
if ( UserDefdTokens )
fprintf(dlgFile, "#include %s\n", UserTokenDefsFile);
/* still need this one as it has the func prototypes */
fprintf(dlgFile, "#include \"%s\"\n", DefFileName);
fprintf(dlgFile, "#include \"dlgdef.h\"\n");
fprintf(dlgFile, "LOOKAHEAD\n");
fprintf(dlgFile, "\n");
fprintf(dlgFile, "void\n");
fprintf(dlgFile, "#ifdef __USE_PROTOS\n");
fprintf(dlgFile, "zzerraction(void)\n");
fprintf(dlgFile, "#else\n");
fprintf(dlgFile, "zzerraction()\n");
fprintf(dlgFile, "#endif\n");
fprintf(dlgFile, "{\n");
fprintf(dlgFile, "\t(*zzerr)(\"%s\");\n", DLGErrorString);
fprintf(dlgFile, "\tzzadvance();\n");
fprintf(dlgFile, "\tzzskip();\n");
fprintf(dlgFile, "}\n");
}
fprintf(dlgFile, ">>\n\n");
/* dump all actions */
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via <<%%lexmember ....>> & <<%%lexprefix ...>> */
/* MR1 */
if (LexActions != NULL) {
for (p = LexActions->next; p!=NULL; p=p->next)
{
/* MR1 */ fprintf(dlgFile, "<<%%%%lexaction\n");
dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
fprintf(dlgFile, ">>\n\n");
}
};
/* MR1 */ if (GenCC) {
/* MR1 */ fprintf(dlgFile,"<<%%%%parserclass %s>>\n\n",CurrentClassName);
/* MR1 */ };
/* MR1 */ if (LexPrefixActions != NULL) {
/* MR1 */ for (p = LexPrefixActions->next; p!=NULL; p=p->next)
/* MR1 */ {
/* MR1 */ fprintf(dlgFile, "<<%%%%lexprefix\n");
/* MR1 */ dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
/* MR1 */ fprintf(dlgFile, ">>\n\n");
/* MR1 */ }
/* MR1 */ };
/* MR1 */ if (LexMemberActions != NULL) {
/* MR1 */ for (p = LexMemberActions->next; p!=NULL; p=p->next)
/* MR1 */ {
/* MR1 */ fprintf(dlgFile, "<<%%%%lexmember\n");
/* MR1 */ dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
/* MR1 */ fprintf(dlgFile, ">>\n\n");
/* MR1 */ }
/* MR1 */ };
/* dump all regular expression rules/actions (skip sentinel node) */
if ( ExprOrder == NULL ) {
warnNoFL("no regular expressions found in grammar");
}
else dumpLexClasses(dlgFile);
fprintf(dlgFile, "%%%%\n");
fclose( dlgFile );
}
/* For each lexical class, scan ExprOrder looking for expressions
* in that lexical class. Print out only those that match.
* Each element of the ExprOrder list has both an expr and an lclass
* field.
*/
void
#ifdef __USE_PROTOS
dumpLexClasses( FILE *dlgFile )
#else
dumpLexClasses( dlgFile )
FILE *dlgFile;
#endif
{
int i;
TermEntry *t;
ListNode *p;
Expr *q;
for (i=0; i<NumLexClasses; i++)
{
fprintf(dlgFile, "\n%%%%%s\n\n", lclass[i].classnum);
for (p=ExprOrder->next; p!=NULL; p=p->next)
{
q = (Expr *) p->elem;
if ( q->lclass != i ) continue;
lexmode(i);
t = (TermEntry *) hash_get(Texpr, q->expr);
require(t!=NULL, eMsg1("genLexDescr: rexpr %s not in hash table",q->expr) );
if ( t->token == EpToken ) continue;
fprintf(dlgFile, "%s\n\t<<\n", StripQuotes(q->expr));
/* replace " killed by StripQuotes() */
q->expr[ strlen(q->expr) ] = '"';
if ( !GenCC ) {
if ( TokenString(t->token) != NULL )
fprintf(dlgFile, "\t\tNLA = %s;\n", TokenString(t->token));
else
fprintf(dlgFile, "\t\tNLA = %d;\n", t->token);
}
if ( t->action != NULL ) dumpAction( t->action, dlgFile, 2,-1,0,1 );
if ( GenCC ) {
if ( TokenString(t->token) != NULL )
fprintf(dlgFile, "\t\treturn %s;\n", TokenString(t->token));
else
fprintf(dlgFile, "\t\treturn (ANTLRTokenType)%d;\n", t->token);
}
fprintf(dlgFile, "\t>>\n\n");
}
}
}
/* Strip the leading path (if any) from a filename */
char *
#ifdef __USE_PROTOS
StripPath( char *fileName )
#else
StripPath( fileName )
char *fileName;
#endif
{
char *p;
static char dirSym[2] = DirectorySymbol;
if(NULL != (p = strrchr(fileName, dirSym[0])))
p++;
else
p = fileName;
return(p);
}
/* Generate a list of #defines && list of struct definitions for
* aggregate retv's */
void
#ifdef __USE_PROTOS
genDefFile( void )
#else
genDefFile( )
#endif
{
int i;
/* If C++ mode and #tokdef used, then don't need anything in here since
* C++ puts all definitions in the class file name.
*/
if ( GenCC && UserTokenDefsFile ) return;
if ( MR_Inhibit_Tokens_h_Gen) return;
DefFile = fopen(OutMetaName(DefFileName), "w");
require(DefFile!=NULL, eMsg1("genDefFile: cannot open %s", OutMetaName(DefFileName)) );
#ifdef SPECIAL_FOPEN
special_fopen_actions(OutMetaName(DefFileName)); /* MR1 */
#endif
fprintf(DefFile, "#ifndef %s\n", StripPath(gate_symbol(DefFileName)));
fprintf(DefFile, "#define %s\n", StripPath(gate_symbol(DefFileName)));
fprintf(DefFile, "/* %s -- List of labelled tokens and stuff\n", DefFileName);
fprintf(DefFile, " *\n");
fprintf(DefFile, " * Generated from:");
for (i=0; i<NumFiles; i++) fprintf(DefFile, " %s", FileStr[i]);
fprintf(DefFile, "\n");
fprintf(DefFile, " *\n");
fprintf(DefFile, " * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001\n");
fprintf(DefFile, " * Purdue University Electrical Engineering\n");
fprintf(DefFile, " * ANTLR Version %s\n", Version);
fprintf(DefFile, " */\n");
if ( !GenCC && LexGen ) {
fprintf(DefFile,"#define zzEOF_TOKEN %d\n",
TokenInd!=NULL?TokenInd[EofToken]:EofToken);
}
if ( !UserDefdTokens )
{
int first=1;
if ( GenCC ) fprintf(DefFile, "enum ANTLRTokenType {\n");
for (i=1; i<TokenNum; i++)
{
/* Don't do EpToken or expr w/o labels */
if ( TokenString(i)!=NULL && i != EpToken )
{
TermEntry *p;
if ( WarningLevel>1 )
{
int j;
/* look in all lexclasses for the reg expr */
/* MR10 Derek Pappas */
/* MR10 A #tokclass doesn't have associated regular expressiones */
/* MR10 so don't warn user about it's omission */
p = (TermEntry *) hash_get(Tname, TokenString(i));
if (p != NULL && ! p->classname) {
for (j=0; j<NumLexClasses; j++)
{
lexmode(j);
if ( ExprString(i)!=NULL ) break;
}
if ( j>=NumLexClasses )
{
warnNoFL(eMsg1("token label has no associated rexpr: %s",TokenString(i)));
}
};
}
require((p=(TermEntry *)hash_get(Tname, TokenString(i))) != NULL,
"token not in sym tab when it should be");
if ( !p->classname )
{
if ( GenCC ) {
if ( !first ) fprintf(DefFile, ",\n");
first = 0;
fprintf(DefFile, "\t%s=%d", TokenString(i), i);
}
else
fprintf(DefFile, "#define %s %d\n", TokenString(i), i);
}
}
}
/* MR1 */
/* MR1 10-Apr-97 133MR1 Prevent use of varying sizes of integer */
/* MR1 for the enum ANTLRTokenType */
/* MR1 */
if ( GenCC ) { /* MR1 */
if ( !first ) fprintf(DefFile, ",\n"); /* MR14 */
fprintf(DefFile, "\tDLGminToken=0"); /* MR1 */
fprintf(DefFile, ",\n\tDLGmaxToken=9999};\n"); /* MR1 */
}; /* MR1 */
}
if ( !GenCC ) GenRulePrototypes(DefFile, SynDiag);
fprintf(DefFile, "\n#endif\n");
}
void
#ifdef __USE_PROTOS
GenRemapFile( void )
#else
GenRemapFile( )
#endif
{
if ( strcmp(ParserName, DefaultParserName)!=0 )
{
FILE *f;
int i;
f = fopen(OutMetaName(RemapFileName), "w");
require(f!=NULL, eMsg1("GenRemapFile: cannot open %s", OutMetaName(RemapFileName)) );
#ifdef SPECIAL_FOPEN
special_fopen_actions(OutMetaName(RemapFileName)); /* MR1 */
#endif
fprintf(f, "/* %s -- List of symbols to remap\n", RemapFileName);
fprintf(f, " *\n");
fprintf(f, " * Generated from:");
for (i=0; i<NumFiles; i++) fprintf(f, " %s", FileStr[i]);
fprintf(f, "\n");
fprintf(f, " *\n");
fprintf(f, " * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001\n");
fprintf(f, " * Purdue University Electrical Engineering\n");
fprintf(f, " * ANTLR Version %s\n", Version);
fprintf(f, " */\n");
GenRuleFuncRedefs(f, SynDiag);
GenPredefinedSymbolRedefs(f);
if ( GenAST ) GenASTSymbolRedefs(f);
GenSetRedefs(f);
fclose(f);
}
}
/* Generate a bunch of #defines that rename all functions to be "ParserName_func" */
void
#ifdef __USE_PROTOS
GenRuleFuncRedefs( FILE *f, Junction *p )
#else
GenRuleFuncRedefs( f, p )
FILE *f;
Junction *p;
#endif
{
fprintf(f, "\n/* rename rule functions to be 'ParserName_func' */\n");
while ( p!=NULL )
{
fprintf(f, "#define %s %s_%s\n", p->rname, ParserName, p->rname);
p = (Junction *)p->p2;
}
}
/* Generate a bunch of #defines that rename all standard symbols to be
* "ParserName_symbol". The list of standard symbols to change is in
* globals.c.
*/
void
#ifdef __USE_PROTOS
GenPredefinedSymbolRedefs( FILE *f )
#else
GenPredefinedSymbolRedefs( f )
FILE *f;
#endif
{
char **p;
fprintf(f, "\n/* rename PCCTS-supplied symbols to be 'ParserName_symbol' */\n");
for (p = &StandardSymbols[0]; *p!=NULL; p++)
{
fprintf(f, "#define %s %s_%s\n", *p, ParserName, *p);
}
}
/* Generate a bunch of #defines that rename all AST symbols to be
* "ParserName_symbol". The list of AST symbols to change is in
* globals.c.
*/
void
#ifdef __USE_PROTOS
GenASTSymbolRedefs( FILE *f )
#else
GenASTSymbolRedefs( f )
FILE *f;
#endif
{
char **p;
fprintf(f, "\n/* rename PCCTS-supplied AST symbols to be 'ParserName_symbol' */\n");
for (p = &ASTSymbols[0]; *p!=NULL; p++)
{
fprintf(f, "#define %s %s_%s\n", *p, ParserName, *p);
}
}
/* redefine all sets generated by ANTLR; WARNING: 'zzerr', 'setwd' must match
* use in bits.c (DumpSetWd() etc...)
*/
void
#ifdef __USE_PROTOS
GenSetRedefs( FILE *f )
#else
GenSetRedefs( f )
FILE *f;
#endif
{
int i;
for (i=1; i<=wordnum; i++)
{
fprintf(f, "#define setwd%d %s_setwd%d\n", i, ParserName, i);
}
for (i=1; i<=esetnum; i++)
{
fprintf(f, "#define zzerr%d %s_err%d\n", i, ParserName, i);
}
}
/* Find all return types/parameters that require structs and def
* all rules with ret types.
*
* This is for the declaration, not the definition.
*/
void
#ifdef __USE_PROTOS
GenRulePrototypes( FILE *f, Junction *p )
#else
GenRulePrototypes( f, p )
FILE *f;
Junction *p;
#endif
{
int i;
i = 1;
while ( p!=NULL )
{
if ( p->ret != NULL )
{
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
DumpRetValStruct(f, p->ret, i);
}
fprintf(f, "\n#ifdef __USE_PROTOS\n");
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
fprintf(f, "extern struct _rv%d", i);
}
else
{
fprintf(f, "extern ");
DumpType(p->ret, f);
}
fprintf(f, " %s%s(", RulePrefix, p->rname);
DumpANSIFunctionArgDef(f,p,1 /* emit initializers ? */);
fprintf(f, ";\n");
fprintf(f, "#else\n");
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
fprintf(f, "extern struct _rv%d", i);
}
else
{
fprintf(f, "extern ");
DumpType(p->ret, f);
}
fprintf(f, " %s%s();\n", RulePrefix, p->rname);
fprintf(f, "#endif\n");
}
else
{
fprintf(f, "\n#ifdef __USE_PROTOS\n");
fprintf(f, "void %s%s(", RulePrefix, p->rname);
DumpANSIFunctionArgDef(f,p, 1 /* emit initializers ? */ );
fprintf(f, ";\n");
#ifdef OLD
if ( p->pdecl != NULL || GenAST )
{
if ( GenAST ) {
fprintf(f, "AST **%s",(p->pdecl!=NULL)?",":"");
}
if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);
}
else fprintf(f, "void");
fprintf(f, ");\n");
#endif
fprintf(f, "#else\n");
fprintf(f, "extern void %s%s();\n", RulePrefix, p->rname);
fprintf(f, "#endif\n");
}
i++;
p = (Junction *)p->p2;
}
}
/* Define all rules in the class.h file; generate any required
* struct definitions first, however.
*/
void
#ifdef __USE_PROTOS
GenRuleMemberDeclarationsForCC( FILE *f, Junction *q )
#else
GenRuleMemberDeclarationsForCC( f, q )
FILE *f;
Junction *q;
#endif
{
Junction *p = q;
int i;
fprintf(f, "private:\n");
/* Dump dflt handler declaration */
fprintf(f, "\tvoid zzdflthandlers( int _signal, int *_retsignal );\n\n");
fprintf(f, "public:\n");
/* Dump return value structs */
i = 1;
while ( p!=NULL )
{
if ( p->ret != NULL )
{
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
DumpRetValStruct(f, p->ret, i);
}
}
i++;
p = (Junction *)p->p2;
}
/* Dump member func defs && CONSTRUCTOR */
fprintf(f, "\t%s(ANTLRTokenBuffer *input);\n", CurrentClassName);
/*
fprintf(f, "\t%s(ANTLRTokenBuffer *input, ANTLRTokenType eof);\n",
CurrentClassName);
*/
i = 1;
p = q;
while ( p!=NULL )
{
if ( p->ret != NULL )
{
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
fprintf(f, "\tstruct _rv%d", i);
}
else
{
fprintf(f, "\t");
DumpType(p->ret, f);
}
fprintf(f, " %s%s(",RulePrefix,p->rname);
DumpANSIFunctionArgDef(f,p, 1 /* emit initializers ? */ );
fprintf(f, ";\n");
#ifdef OLD
if ( p->pdecl != NULL || GenAST )
{
if ( GenAST ) fprintf(f, "ASTBase **%s",(p->pdecl!=NULL)?",":"");
if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);
}
fprintf(f, ");\n");
#endif
}
else
{
fprintf(f, "\tvoid %s%s(",RulePrefix,p->rname);
DumpANSIFunctionArgDef(f,p, 1 /* emit initializers ? */);
fprintf(f, ";\n");
#ifdef OLD
if ( p->pdecl != NULL || GenAST )
{
if ( GenAST ) fprintf(f, "ASTBase **%s",(p->pdecl!=NULL)?",":"");
if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);
}
fprintf(f, ");\n");
#endif
}
i++;
p = (Junction *)p->p2;
}
}
/* Given a list of ANSI-style parameter declarations, print out a
* comma-separated list of the symbols (w/o types).
* Basically, we look for a comma, then work backwards until start of
* the symbol name. Then print it out until 1st non-alnum char. Now,
* move on to next parameter.
*
*/
/* MR5 Jan Mikkelsen 26-May-97 - added initalComma parameter */
void
#ifdef __USE_PROTOS
DumpListOfParmNames(char *pdecl, FILE *output, int initialComma) /* MR5 */
#else
DumpListOfParmNames(pdecl, output, initialComma) /* MR5 */
char *pdecl; /* MR5 */
FILE *output; /* MR5 */
int initialComma; /* MR5 */
#endif
{
int firstTime = 1, done = 0;
require(output!=NULL, "DumpListOfParmNames: NULL parm");
if ( pdecl == NULL ) return;
while ( !done )
{
if ( !firstTime || initialComma ) putc(',', output); /* MR5 */
done = DumpNextNameInDef(&pdecl, output);
firstTime = 0;
}
}
/* given a list of parameters or return values, dump the next
* name to output. Return 1 if last one just printed, 0 if more to go.
*/
/* MR23 Total rewrite */
int
#ifdef __USE_PROTOS
DumpNextNameInDef( char **q, FILE *output )
#else
DumpNextNameInDef( q, output )
char **q;
FILE *output;
#endif
{
char *p;
char *t;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
p = endFormal(*q,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
/* MR26 Handle rule arguments such as: IIR_Bool (IIR_Decl::*contstraint)()
For this we need to strip off anything which follows the symbol.
*/
/* MR26 */ t = pSymbol;
/* MR26 */ if (t != NULL) {
/* MR26 */ for (t = pSymbol; *t != 0; t++) {
/* MR26 */ if (! (isalpha(*t) || isdigit(*t) || *t == '_' || *t == '$')) break;
/* MR26 */ }
/* MR26 */ }
/* MR26 */ fprintf(output,strBetween(pSymbol, t, pSeparator));
*q = p;
return (*pSeparator == 0);
}
/* Given a list of ANSI-style parameter declarations, dump K&R-style
* declarations, one per line for each parameter. Basically, convert
* comma to semi-colon, newline.
*/
void
#ifdef __USE_PROTOS
DumpOldStyleParms( char *pdecl, FILE *output )
#else
DumpOldStyleParms( pdecl, output )
char *pdecl;
FILE *output;
#endif
{
require(output!=NULL, "DumpOldStyleParms: NULL parm");
if ( pdecl == NULL ) return;
while ( *pdecl != '\0' )
{
if ( *pdecl == ',' )
{
pdecl++;
putc(';', output); putc('\n', output);
while ( *pdecl==' ' || *pdecl=='\t' || *pdecl=='\n' ) pdecl++;
}
else {putc(*pdecl, output); pdecl++;}
}
putc(';', output);
putc('\n', output);
}
/* Take in a type definition (type + symbol) and print out type only */
/* MR23 Total rewrite */
void
#ifdef __USE_PROTOS
DumpType( char *s, FILE *f )
#else
DumpType( s, f )
char *s;
FILE *f;
#endif
{
char *p;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
require(s!=NULL, "DumpType: invalid type string");
p = endFormal(s,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
fprintf(f,strBetween(pDataType, pSymbol, pSeparator));
}
/* check to see if string e is a word in string s */
int
#ifdef __USE_PROTOS
strmember( char *s, char *e )
#else
strmember( s, e )
char *s;
char *e;
#endif
{
register char *p;
require(s!=NULL&&e!=NULL, "strmember: NULL string");
if ( *e=='\0' ) return 1; /* empty string is always member */
do {
while ( *s!='\0' && !isalnum(*s) && *s!='_' )
++s;
p = e;
while ( *p!='\0' && *p==*s ) {p++; s++;}
if ( *p=='\0' ) {
if ( *s=='\0' ) return 1;
if ( !isalnum (*s) && *s != '_' ) return 1;
}
while ( isalnum(*s) || *s == '_' )
++s;
} while ( *s!='\0' );
return 0;
}
#if 0
/* MR23 Replaced by hasMultipleOperands() */
int
#ifdef __USE_PROTOS
HasComma( char *s )
#else
HasComma( s )
char *s;
#endif
{
while (*s!='\0')
if ( *s++ == ',' ) return 1;
return 0;
}
#endif
/* MR23 Total rewrite */
void
#ifdef __USE_PROTOS
DumpRetValStruct( FILE *f, char *ret, int i )
#else
DumpRetValStruct( f, ret, i )
FILE *f;
char *ret;
int i;
#endif
{
char *p = ret;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
fprintf(f, "\nstruct _rv%d {\n", i);
while (*p != 0 && nest == 0) {
p = endFormal(p,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
fprintf(f,"\t");
fprintf(f,strBetween(pDataType, pSymbol, pSeparator));
fprintf(f," ");
fprintf(f,strBetween(pSymbol, pEqualSign, pSeparator));
fprintf(f,";\n");
}
fprintf(f,"};\n");
}
/* given "s" yield s -- DESTRUCTIVE (we modify s if starts with " else return s) */
char *
#ifdef __USE_PROTOS
StripQuotes( char *s )
#else
StripQuotes( s )
char *s;
#endif
{
if ( *s == '"' )
{
s[ strlen(s)-1 ] = '\0'; /* remove last quote */
return( s+1 ); /* return address past initial quote */
}
return( s );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,218 @@
#
# Makefile for ANTLR 1.33
#
# 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.
#
# ANTLR 1.33
# Terence Parr
# Parr Research Corporation
# with Purdue University
# and AHPCRC, University of Minnesota
# 1989-1995
#
# Ported to Borland C++, IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
##
## Uncomment the appropriate section to build
## (both targets and 'make' variable definitions)
## Note that UNIX is the default
##
#
# OS/2 & DOS 16 bit using MSC 6.0
#
#CC=cl
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /AL /Za /W3 -DPC -DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=/NOD:LLIBCE LLIBCEP
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egamn.obj
# link @<<
#$** /NOI
#$@ /STACK:14336
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# bind $@ c:\os2\doscalls.lib
# copy *.exe ..\bin
#
#
# Borland C++ for DOS
#
#CC=bcc
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -ml -ff- -w- -DPC -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= emu mathl cl
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# tlink @&&|
#C0L $**
#$@ /Tde /c
#
#$(LIBS)
#$(DEF_FILE) $(LFLAGS) ;
#|
# copy *.exe ..\bin
#
#
# C-Set/2 for OS/2
#
#CC=icc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /Sa /W3 -DUSER_ZZSYN -D__STDC__
#OUT_OBJ = -Fo
#LIBS=
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# link386 @<<
#$** /NOI
#$@ /STACK:32768
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# copy *.exe ..\bin
#
#
# Borland C++ for OS/2
#
#CC=bcc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -w- -v -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= c2 os2
#
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# tlink @&&|
#c02 $** -c -v
#antlr.exe
#
#C2 os2
#
#|
# copy *.exe ..\bin
#
# *********** Target list of PC machines ***********
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
#antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
# $(ANTLR) antlr.g
#
#antlr.$(OBJ_EXT): antlr.c mode.h tokens.h
#
#scan.$(OBJ_EXT): scan.c mode.h tokens.h
#
#scan.c mode.h: parser.dlg
# $(DLG) -C2 parser.dlg scan.c
#
#set.$(OBJ_EXT): $(SET)/set.c
# $(CC) $(CFLAGS) -c $(OUT_OBJ)set.$(OBJ_EXT) $(SET)/set.c
#
# UNIX (default)
#
CC=gcc
COPT=-O
ANTLR=${BIN_DIR}/antlr
DLG=${BIN_DIR}/dlg
OBJ_EXT=o
OUT_OBJ = -o
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536
#
# SGI Users, use this CFLAGS
#
#CFLAGS= -O -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -woff 3262
OBJ=antlr.o scan.o err.o bits.o build.o fset2.o fset.o gen.o \
globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o
antlr : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o $(BIN_DIR)/antlr $(OBJ)
# what files does PCCTS generate (both ANTLR and DLG)
PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h
SRC=antlr.c scan.c err.c bits.c build.c fset2.c fset.c gen.c globals.c \
hash.c lex.c main.c misc.c $(SET)/set.c pred.c egman.c mrhoist.c fcache.c
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
#antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
# $(ANTLR) -gh antlr.g
antlr.o : antlr.c mode.h tokens.h
scan.o : scan.c mode.h tokens.h
#scan.c mode.h: parser.dlg
# $(DLG) -C2 parser.dlg scan.c
set.o : $(SET)/set.c
$(CC) $(CFLAGS) -c -o set.o $(SET)/set.c
#
# ****** These next targets are common to UNIX and PC world ********
#
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core
#remove everything in clean plus the PCCTS files generated
scrub:
rm -f $(PCCTS_GEN) *.$(OBJ_EXT) core

View File

@@ -0,0 +1,219 @@
#
# Makefile for ANTLR 1.33
#
# 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.
#
# ANTLR 1.33
# Terence Parr
# Parr Research Corporation
# with Purdue University
# and AHPCRC, University of Minnesota
# 1989-1995
#
# Ported to Borland C++, IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
##
## Uncomment the appropriate section to build
## (both targets and 'make' variable definitions)
## Note that UNIX is the default
##
#
# OS/2 & DOS 16 bit using MSC 6.0
#
#CC=cl
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /AL /Za /W3 -DPC -DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=/NOD:LLIBCE LLIBCEP
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egamn.obj
# link @<<
#$** /NOI
#$@ /STACK:14336
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# bind $@ c:\os2\doscalls.lib
# copy *.exe ..\bin
#
#
# Borland C++ for DOS
#
#CC=bcc
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -ml -ff- -w- -DPC -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= emu mathl cl
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# tlink @&&|
#C0L $**
#$@ /Tde /c
#
#$(LIBS)
#$(DEF_FILE) $(LFLAGS) ;
#|
# copy *.exe ..\bin
#
#
# C-Set/2 for OS/2
#
#CC=icc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /Sa /W3 -DUSER_ZZSYN -D__STDC__
#OUT_OBJ = -Fo
#LIBS=
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# link386 @<<
#$** /NOI
#$@ /STACK:32768
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# copy *.exe ..\bin
#
#
# Borland C++ for OS/2
#
#CC=bcc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -w- -v -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= c2 os2
#
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#antlr.exe: antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
# fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
# misc.obj set.obj pred.obj egman.obj mrhoist.obj fcache.obj
# tlink @&&|
#c02 $** -c -v
#antlr.exe
#
#C2 os2
#
#|
# copy *.exe ..\bin
#
# *********** Target list of PC machines ***********
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
#antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
# $(ANTLR) antlr.g
#
#antlr.$(OBJ_EXT): antlr.c mode.h tokens.h
#
#scan.$(OBJ_EXT): scan.c mode.h tokens.h
#
#scan.c mode.h: parser.dlg
# $(DLG) -C2 parser.dlg scan.c
#
#set.$(OBJ_EXT): $(SET)/set.c
# $(CC) $(CFLAGS) -c $(OUT_OBJ)set.$(OBJ_EXT) $(SET)/set.c
#
# UNIX (default)
#
BIN_DIR=../../../../bin
CC=gcc
COPT=-O
ANTLR=$(BIN_DIR)/antlr.exe
DLG=${BIN_DIR}/dlg.exe
OBJ_EXT=o
OUT_OBJ = -o
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536
#
# SGI Users, use this CFLAGS
#
#CFLAGS= -O -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -woff 3262
OBJ=antlr.o scan.o err.o bits.o build.o fset2.o fset.o gen.o \
globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o
antlr : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o $(BIN_DIR)/antlr.exe $(OBJ)
# what files does PCCTS generate (both ANTLR and DLG)
PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h
SRC=antlr.c scan.c err.c bits.c build.c fset2.c fset.c gen.c globals.c \
hash.c lex.c main.c misc.c $(SET)/set.c pred.c egman.c mrhoist.c fcache.c
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
#antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
# $(ANTLR) -gh antlr.g
antlr.o : antlr.c mode.h tokens.h
scan.o : scan.c mode.h tokens.h
#scan.c mode.h: parser.dlg
# $(DLG) -C2 parser.dlg scan.c
set.o : $(SET)/set.c
$(CC) $(CFLAGS) -c -o set.o $(SET)/set.c
#
# ****** These next targets are common to UNIX and PC world ********
#
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core
#remove everything in clean plus the PCCTS files generated
scrub:
rm -f $(PCCTS_GEN) *.$(OBJ_EXT) core

View File

@@ -0,0 +1,96 @@
#
# Makefile for ANTLR 1.33
#
# 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.
#
# ANTLR 1.33
# Terence Parr
# Parr Research Corporation
# with Purdue University
# and AHPCRC, University of Minnesota
# 1989-1995
#
# Ported to Borland C++, IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
#
# UNIX (default)
#
CC=cc
ANTLR=${WORKSPACE}/Tools/bin/antlr
DLG=${WORKSPACE}/Tools/bin/dlg
OBJ_EXT=o
OUT_OBJ = -o
ANSI=-ansi
AOTHER=
CFLAGS= -O0 -g -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) $(ANSI) -DZZLEXBUFSIZE=32000
#
# SGI Users, use this CFLAGS
#
#CFLAGS= -O -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -woff 3262
OBJ=antlr.o scan.o err.o bits.o build.o fset2.o fset.o gen.o \
globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o $(OBJOTHER)
antlr : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o antlr $(OBJ)
mv antlr ${WORKSPACE}/Tools/bin
# what files does PCCTS generate (both ANTLR and DLG)
PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h
SRC=antlr.c scan.c err.c bits.c build.c fset2.c fset.c gen.c globals.c \
hash.c lex.c main.c misc.c $(SET)/set.c pred.c egman.c mrhoist.c fcache.c
#
# Don't worry about the ambiguity messages coming from antlr
# for making antlr.c etc... [should be 10 of them, I think]
#
antlr.c stdpccts.h parser.dlg tokens.h err.c : antlr.g
$(ANTLR) -gh antlr.g $(AOTHER)
antlr.o : antlr.c mode.h tokens.h
scan.o : scan.c mode.h tokens.h
scan.c mode.h: parser.dlg
$(DLG) -C2 parser.dlg scan.c
set.o : $(SET)/set.c
$(CC) $(CFLAGS) -c -o set.o $(SET)/set.c
#
# ****** These next targets are common to UNIX and PC world ********
#
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core
#remove everything in clean plus the PCCTS files generated
scrub:
rm -f $(PCCTS_GEN) *.$(OBJ_EXT) core

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
#define START 0
#define STRINGS 1
#define ACTION_STRINGS 2
#define ACTION_CHARS 3
#define ACTION_COMMENTS 4
#define TOK_DEF_COMMENTS 5
#define TOK_DEF_CPP_COMMENTS 6
#define ACTION_CPP_COMMENTS 7
#define CPP_COMMENTS 8
#define COMMENTS 9
#define ACTIONS 10
#define PARSE_ENUM_FILE 11

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,821 @@
/*
* pred.c -- source for predicate detection, manipulation
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include "pcctscfg.h"
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#include "dlgdef.h"
#include <ctype.h>
#ifdef __USE_PROTOS
static void complete_context_sets(RuleRefNode *, Predicate *);
static void complete_context_trees(RuleRefNode *, Predicate *);
#else
static void complete_context_sets();
static void complete_context_trees();
#endif
char *PRED_AND_LIST = "AND";
char *PRED_OR_LIST = "OR";
/*
* In C mode, return the largest constant integer found as the
* sole argument to LATEXT(i).
*
* In C++ mode, return the largest constant integer found as the
* sole argument to LT(i) given that the char before is nonalpha.
*/
int
#ifdef __USE_PROTOS
predicateLookaheadDepth(ActionNode *a)
#else
predicateLookaheadDepth(a)
ActionNode *a;
#endif
{
int max_k=0;
if (a->predEntry != NULL) {
MR_pred_depth(a->predEntry->pred,&max_k);
goto PREDENTRY_EXIT;
}
if ( GenCC )
{
/* scan for LT(i) */
int k = 0;
char *p = a->action;
while ( p!=NULL )
{
p = strstr(p, "LT(");
if ( p!=NULL )
{
if ( p>=a->action && !isalpha(*(p-1)) )
{
k = atoi(p+strlen("LT("));
if ( k>max_k ) max_k=k;
}
p += strlen("LT(");
}
}
}
else {
/* scan for LATEXT(i) */
int k = 0;
char *p = a->action;
while ( p!=NULL )
{
p = strstr(p, "LATEXT(");
if ( p!=NULL )
{
p += strlen("LATEXT(");
k = atoi(p);
if ( k>max_k ) max_k=k;
}
}
}
if (max_k==0) {
max_k = 1; /* MR33 Badly designed if didn't set max_k when CLL_k = 1 */
if (CLL_k > 1) /* MR27 Don't warn if max(k,ck) == 1 */
{
if ( !a->frmwarned )
{
a->frmwarned = 1;
warnFL(eMsg1("predicate: %s missing, bad, or with i=0; assuming i=1",
GenCC?"LT(i)":"LATEXT(i)"),
FileStr[a->file], a->line);
}
}
}
/* MR10 */ if ( max_k > CLL_k) {
/* MR10 */ if ( !a->frmwarned )
/* MR10 */ {
/* MR10 */ a->frmwarned = 1;
/* MR11 */ errFL(eMsgd2("predicate refers to lookahead token %d. Semantic lookahead is limited to max(k,ck)==%d",
/* MR10 */ max_k,CLL_k),
/* MR10 */ FileStr[a->file],a->line);
/* MR10 */ if (max_k >= OutputLL_k) {
/* MR10 */ if (!GenCC) {
/* MR10 */ errFL(eMsgd(" the lookahead buffer size in C mode is %d token(s) (including the one just recognized)",
/* MR10 */ OutputLL_k),
/* MR10 */ FileStr[a->file],a->line);
/* MR10 */ };
/* MR10 */ };
/* MR10 */ };
/* MR10 */ max_k= CLL_k;
/* MR10 */ };
PREDENTRY_EXIT:
return max_k;
}
/* Find all predicates in a block of alternatives. DO NOT find predicates
* behind the block because that predicate could depend on things set in
* one of the nonoptional blocks
*/
Predicate *
#ifdef __USE_PROTOS
find_in_aSubBlk( Junction *alt )
#else
find_in_aSubBlk( alt )
Junction *alt;
#endif
{
Predicate *a, *head=NULL, *tail=NULL, *root=NULL;
Junction *p = alt;
if (MRhoisting) {
return MR_find_in_aSubBlk(alt);
};
for (; p!=NULL; p=(Junction *)p->p2)
{
/* ignore empty alts */
if ( p->p1->ntype != nJunction ||
((Junction *)p->p1)->jtype != EndBlk )
{
a = find_predicates(p->p1); /* get preds for this alt */
if ( a==NULL ) continue;
/* make an OR list of predicates */
if ( head==NULL )
{
root = new_pred();
root->expr = PRED_OR_LIST;
head = tail = a;
root->down = head;
}
else {
tail->right = a;
a->left = tail;
a->up = tail->up;
tail = a;
}
}
}
/* if just one pred, remove OR root */
if ( root!=NULL && root->down->right == NULL )
{
Predicate *d = root->down;
free( (char *) root);
return d;
}
return root;
}
Predicate *
#ifdef __USE_PROTOS
find_in_aOptBlk( Junction *alt )
#else
find_in_aOptBlk( alt )
Junction *alt;
#endif
{
return find_in_aSubBlk( alt );
}
Predicate *
#ifdef __USE_PROTOS
find_in_aLoopBegin( Junction *alt )
#else
find_in_aLoopBegin( alt )
Junction *alt;
#endif
{
return find_in_aSubBlk( (Junction *) alt->p1 ); /* get preds in alts */
}
Predicate *
#ifdef __USE_PROTOS
find_in_aPlusBlk( Junction *alt )
#else
find_in_aPlusBlk( alt )
Junction *alt;
#endif
{
require(alt!=NULL&&alt->p2!=NULL, "invalid aPlusBlk");
return find_in_aSubBlk( alt );
}
/* Look for a predicate;
*
* Do not pass anything but Junction nodes; no Actions, Tokens, RuleRefs.
* This means that a "hoisting distance" of zero is the only distance
* allowable. Init actions are ignored.
*
* WARNING:
* Assumes no (..)? block after predicate for the moment.
* Does not check to see if pred is in production that can generate
* a sequence contained in the set of ambiguous tuples.
*
* Return the predicate found if any.
*/
Predicate *
#ifdef __USE_PROTOS
find_predicates( Node *alt )
#else
find_predicates( alt )
Node *alt;
#endif
{
#ifdef DBG_PRED
Junction *j;
RuleRefNode *r;
TokNode *t;
#endif
Predicate *pred;
if ( alt==NULL ) return NULL;
#ifdef DBG_PRED
switch ( alt->ntype )
{
case nJunction :
j = (Junction *) alt;
fprintf(stderr, "Junction(in %s)", j->rname);
switch ( j->jtype )
{
case aSubBlk :
fprintf(stderr,"aSubBlk\n");
break;
case aOptBlk :
fprintf(stderr,"aOptBlk\n");
break;
case aLoopBegin :
fprintf(stderr,"aLoopBeginBlk\n");
break;
case aLoopBlk :
fprintf(stderr,"aLoopBlk\n");
break;
case aPlusBlk :
fprintf(stderr,"aPlusBlk\n");
break;
case EndBlk :
fprintf(stderr,"EndBlk\n");
break;
case RuleBlk :
fprintf(stderr,"RuleBlk\n");
break;
case Generic :
fprintf(stderr,"Generic\n");
break;
case EndRule :
fprintf(stderr,"EndRule\n");
break;
}
break;
case nRuleRef :
r = (RuleRefNode *) alt;
fprintf(stderr, "RuleRef(in %s)\n", r->rname);
break;
case nToken :
t = (TokNode *) alt;
fprintf(stderr, "TokenNode(in %s)%s\n", t->rname, TokenString(t->token));
break;
case nAction :
fprintf(stderr, "Action\n");
break;
}
#endif
switch ( alt->ntype )
{
case nJunction :
{
Predicate *a, *b;
Junction *p = (Junction *) alt;
/* lock nodes */
if ( p->jtype==aLoopBlk || p->jtype==RuleBlk ||
p->jtype==aPlusBlk || p->jtype==EndRule )
{
require(p->pred_lock!=NULL, "rJunc: lock array is NULL");
if ( p->pred_lock[1] )
{
return NULL;
}
p->pred_lock[1] = TRUE;
}
switch ( p->jtype )
{
case aSubBlk :
a = find_in_aSubBlk(p);
return a; /* nothing is visible past this guy */
case aOptBlk :
a = find_in_aOptBlk(p);
return a;
case aLoopBegin :
a = find_in_aLoopBegin(p);
return a;
case aLoopBlk :
a = find_in_aSubBlk(p);
p->pred_lock[1] = FALSE;
return a;
case aPlusBlk :
a = find_in_aPlusBlk(p);
p->pred_lock[1] = FALSE;
return a; /* nothing is visible past this guy */
case RuleBlk :
a = find_predicates(p->p1);
p->pred_lock[1] = FALSE;
return a;
case Generic :
a = find_predicates(p->p1);
b = find_predicates(p->p2);
if ( p->pred_lock!=NULL ) p->pred_lock[1] = FALSE;
if ( a==NULL ) return b;
if ( b==NULL ) return a;
/* otherwise OR the two preds together */
{
fatal_internal("hit unknown situation during predicate hoisting");
}
case EndBlk :
case EndRule : /* Find no predicates after a rule ref */
return NULL;
default:
fatal_internal("this cannot be printed\n");
break;
}
}
case nAction :
{
ActionNode *p = (ActionNode *) alt;
if ( p->noHoist) return NULL; /* MR12c */
if ( p->init_action ) return find_predicates(p->next);
if ( p->is_predicate )
{
Tree *t=NULL;
#ifdef DBG_PRED
fprintf(stderr, "predicate: <<%s>>?\n", p->action);
#endif
if ( p->guardpred!=NULL )
{
pred = predicate_dup(p->guardpred);
MR_guardPred_plainSet(p,pred); /* MR12c */
}
else
{
pred = new_pred();
pred->k = predicateLookaheadDepth(p);
pred->source = p;
pred->expr = p->action;
if ( HoistPredicateContext && pred->k > 1 )
{
/* MR30 No need to use first_item_is_guess_block_extra
since we know this is an action, not a (...)* or
(...)+ block.
*/
if ( first_item_is_guess_block((Junction *)p->next) )
{
warnFL("cannot compute context of predicate in front of (..)? block",
FileStr[p->file], p->line);
}
else
{
ConstrainSearch = 0;
/* MR11 */ if (p->ampersandPred != NULL) {
/* MR11 */ TRAV(p,
/* MR11 */ pred->k,
/* MR11 */ &(pred->completionTree), t);
/* MR11 */ } else {
TRAV(p->next,
pred->k,
&(pred->completionTree), t);
};
pred->tcontext = t;
MR_check_pred_too_long(pred,pred->completionTree);
#ifdef DBG_PRED
fprintf(stderr, "LL(%d) context:", pred->k);
preorder(t);
fprintf(stderr, "\n");
#endif
}
}
else if ( HoistPredicateContext && pred->k == 1 )
{
pred->scontext[1] = empty;
/* MR30 No need to use first_item_is_guess_block_extra
since we know this is an action.
*/
if ( first_item_is_guess_block((Junction *)p->next) )
{
warnFL("cannot compute context of predicate in front of (..)? block",
FileStr[p->file], p->line);
}
else
{
REACH((Junction *)p->next,
1,
&(pred->completionSet),
pred->scontext[1]);
MR_check_pred_too_long(pred,pred->completionSet);
#ifdef DBG_PRED
fprintf(stderr, "LL(1) context:");
s_fprT(stderr, pred->scontext[1]);
fprintf(stderr, "\n");
#endif
}
}
}
{
Predicate *d = find_predicates(p->next);
Predicate *root;
/* Warning: Doesn't seem like the up pointers will all be set correctly;
* TJP: that's ok, we're not using them now.
*/
if ( d!=NULL )
{
root = new_pred();
root->expr = PRED_AND_LIST;
root->down = pred;
pred->right = d;
pred->up = root;
d->left = pred;
d->up = pred->up;
return root;
}
}
return pred;
}
return NULL;
}
case nRuleRef :
{
Predicate *a;
RuleRefNode *p = (RuleRefNode *) alt;
Junction *r;
Junction *save_MR_RuleBlkWithHalt;
RuleEntry *q = (RuleEntry *) hash_get(Rname, p->text);
if ( q == NULL )
{
warnFL( eMsg1("rule %s not defined",p->text), FileStr[p->file], p->line );
return NULL;
}
r = RulePtr[q->rulenum];
if ( r->pred_lock[1] )
{
/* infinite left-recursion; ignore 'cause LL sup 1 (k) analysis
* must have seen it earlier.
*/
return NULL;
}
/* MR10 There should only be one halt set at a time. */
/* MR10 Life would have been easier with a global variable */
/* MR10 (at least for this particular need) */
/* MR10 Unset the old one and set the new one, later undo. */
require(r->end->halt == FALSE,"should only have one halt at a time");
/* MR10 */ require(MR_RuleBlkWithHalt == NULL ||
/* MR10 */ (MR_RuleBlkWithHalt->jtype == RuleBlk && MR_RuleBlkWithHalt->end->halt == TRUE),
/* MR10 */ "RuleBlkWithHalt->end not RuleBlk or does not have halt set");
/* MR10 */ if (MR_RuleBlkWithHalt != NULL) {
/* MR10 */ MR_RuleBlkWithHalt->end->halt=FALSE;
/* MR10 */ };
/*** fprintf(stderr,"\nSetting halt on junction #%d\n",r->end->seq); ***/
require(r->end->halt == FALSE,"rule->end->halt already set");
save_MR_RuleBlkWithHalt=MR_RuleBlkWithHalt;
/* MR10 */ MR_pointerStackPush(&MR_RuleBlkWithHaltStack,MR_RuleBlkWithHalt);
/* MR10 */ MR_pointerStackPush(&MR_PredRuleRefStack,p);
r->end->halt = TRUE;
/* MR10 */ MR_RuleBlkWithHalt=r;
a = find_predicates((Node *)r);
require(r->end->halt == TRUE,"rule->end->halt not set");
r->end->halt = FALSE;
/* MR10 */ MR_pointerStackPop(&MR_PredRuleRefStack);
/* MR10 */ MR_RuleBlkWithHalt=(Junction *) MR_pointerStackPop(&MR_RuleBlkWithHaltStack);
require (MR_RuleBlkWithHalt==save_MR_RuleBlkWithHalt,
"RuleBlkWithHaltStack not consistent");
/* MR10 */ require(MR_RuleBlkWithHalt == NULL ||
/* MR10 */ (MR_RuleBlkWithHalt->jtype == RuleBlk && MR_RuleBlkWithHalt->end->halt == FALSE),
/* MR10 */ "RuleBlkWithHalt->end not RuleBlk or has no halt set");
/* MR10 */ if (MR_RuleBlkWithHalt != NULL) {
/* MR10 */ MR_RuleBlkWithHalt->end->halt=TRUE;
/* MR10 */ };
/*** fprintf(stderr,"\nRestoring halt on junction #%d\n",r->end->seq); ***/
if ( a==NULL ) return NULL;
/* attempt to compute the "local" FOLLOW just like in normal lookahead
* computation if needed
*/
complete_context_sets(p,a);
complete_context_trees(p,a);
/* MR10 */ MR_cleanup_pred_trees(a);
return a;
}
case nToken :
break;
}
return NULL;
}
#ifdef __USE_PROTOS
Predicate *MR_find_predicates_and_supp(Node *alt)
#else
Predicate *MR_find_predicates_and_supp(alt)
Node *alt;
#endif
{
Predicate *p;
p=find_predicates(alt);
p=MR_suppressK(alt,p);
return p;
}
Predicate *
#ifdef __USE_PROTOS
new_pred( void )
#else
new_pred( )
#endif
{
Predicate *p = (Predicate *) calloc(1,sizeof(Predicate)); /* MR10 */
require(p!=NULL, "new_pred: cannot alloc predicate");
p->scontext[0]=empty;
p->scontext[1]=empty;
p->completionTree=empty;
p->completionSet=empty;
p->plainSet=empty;
return p;
}
static void
#ifdef __USE_PROTOS
complete_context_sets( RuleRefNode *p, Predicate *a )
#else
complete_context_sets( p, a )
RuleRefNode *p;
Predicate *a;
#endif
{
set rk2, b;
int k2;
#ifdef DBG_PRED
fprintf(stderr, "enter complete_context_sets\n");
#endif
for (; a!=NULL; a=a->right)
{
if ( a->expr == PRED_AND_LIST || a->expr == PRED_OR_LIST )
{
complete_context_sets(p,a->down);
continue;
}
rk2 = b = empty;
while ( !set_nil(a->completionSet) )
{
k2 = set_int(a->completionSet);
set_rm(k2, a->completionSet);
REACH(p->next, k2, &rk2, b);
set_orin(&(a->scontext[1]), b);
set_free(b);
}
set_orin(&(a->completionSet), rk2);/* remember what we couldn't do */
set_free(rk2);
#ifdef DBG_PRED
fprintf(stderr, "LL(1) context for %s(addr 0x%x) after ruleref:", a->expr, a);
s_fprT(stderr, a->scontext[1]);
fprintf(stderr, "\n");
#endif
/* complete_context_sets(p, a->down);*/
}
#ifdef DBG_PRED
fprintf(stderr, "exit complete_context_sets\n");
#endif
}
static void
#ifdef __USE_PROTOS
complete_context_trees( RuleRefNode *p, Predicate *a )
#else
complete_context_trees( p, a )
RuleRefNode *p;
Predicate *a;
#endif
{
set rk2;
int k2;
Tree *u;
#ifdef DBG_PRED
fprintf(stderr, "enter complete_context_trees\n");
#endif
for (; a!=NULL; a=a->right)
{
if ( a->expr == PRED_AND_LIST || a->expr == PRED_OR_LIST )
{
complete_context_trees(p, a->down);
continue;
}
rk2 = empty;
/* any k left to do? if so, link onto tree */
while ( !set_nil(a->completionTree) )
{
k2 = set_int(a->completionTree);
set_rm(k2, a->completionTree);
u = NULL;
TRAV(p->next, k2, &rk2, u);
/* any subtrees missing k2 tokens, add u onto end */
a->tcontext = tlink(a->tcontext, u, k2);
Tfree(u); /* MR10 */
}
set_orin(&(a->completionTree), rk2);/* remember what we couldn't do */
set_free(rk2);
#ifdef DBG_PRED
fprintf(stderr, "LL(i<%d) context after ruleref:", LL_k);
preorder(a->tcontext);
fprintf(stderr, "\n");
#endif
/* complete_context_trees(p, a->down);*/
}
#ifdef DBG_PRED
fprintf(stderr, "exit complete_context_trees\n");
#endif
}
/* Walk a list of predicates and return the set of all tokens in scontext[1]'s */
set
#ifdef __USE_PROTOS
covered_set( Predicate *p )
#else
covered_set( p )
Predicate *p;
#endif
{
set a;
a = empty;
for (; p!=NULL; p=p->right)
{
if ( p->expr == PRED_AND_LIST || p->expr == PRED_OR_LIST )
{
set_orin(&a, covered_set(p->down));
continue;
}
set_orin(&a, p->scontext[1]);
set_orin(&a, covered_set(p->down));
}
return a;
}
/* MR10 predicate_free()
MR10 Don't free the leaf nodes since they are part of the action node
*/
#ifdef __USE_PROTOS
void predicate_free(Predicate *p)
#else
void predicate_free(p)
Predicate *p;
#endif
{
if (p == NULL) return;
predicate_free(p->right);
predicate_free(p->down);
if (p->cloned ||
p->source == NULL ||
p->source->guardpred == NULL ||
p->expr == PRED_AND_LIST ||
p->expr == PRED_OR_LIST) {
set_free(p->scontext[1]);
set_free(p->completionSet);
set_free(p->completionTree);
set_free(p->plainSet);
Tfree(p->tcontext);
free( (char *) p);
} else {
p->right=NULL;
p->down=NULL; /* MR13 *** debug */
};
}
/* MR10 predicate_dup() */
#ifdef __USE_PROTOS
Predicate * predicate_dup_xxx(Predicate *p,int contextToo)
#else
Predicate * predicate_dup_xxx(p,contextToo)
Predicate *p;
int contextToo;
#endif
{
Predicate *q;
if (p == NULL) return NULL;
q=new_pred();
q->down=predicate_dup(p->down);
q->right=predicate_dup(p->right);
/*
don't replicate expr - it is read-only
and address comparison is used to look
for identical predicates.
*/
q->expr=p->expr;
q->k=p->k;
q->source=p->source;
q->cloned=1;
q->ampersandStyle=p->ampersandStyle;
q->inverted=p->inverted;
q->predEntry=p->predEntry;
q->plainSet=set_dup(p->plainSet);
if (contextToo) {
q->tcontext=tdup(p->tcontext);
q->scontext[0]=set_dup(p->scontext[0]);
q->scontext[1]=set_dup(p->scontext[1]);
q->completionTree=set_dup(p->completionTree);
q->completionSet=set_dup(p->completionSet);
};
/* don't need to dup "redundant" */
return q;
}
#ifdef __USE_PROTOS
Predicate * predicate_dup_without_context(Predicate *p)
#else
Predicate * predicate_dup_without_context(p)
Predicate *p;
#endif
{
return predicate_dup_xxx(p,0);
}
#ifdef __USE_PROTOS
Predicate * predicate_dup(Predicate *p)
#else
Predicate * predicate_dup(p)
Predicate *p;
#endif
{
return predicate_dup_xxx(p,1);
}

View File

@@ -0,0 +1,852 @@
/*
* proto.h -- function prototypes
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
/* V a r i a b l e s */
extern int tp;
extern Junction *SynDiag;
extern char Version[];
extern char VersionDef[];
#ifdef __cplusplus
extern void (*fpPrint[])(...);
#else
extern void (*fpPrint[])();
#endif
#ifdef __cplusplus
extern struct _set (*fpReach[])(...);
#else
extern struct _set (*fpReach[])();
#endif
#ifdef __cplusplus
extern struct _tree *(*fpTraverse[])(...);
#else
extern struct _tree *(*fpTraverse[])();
#endif
#ifdef __cplusplus
extern void (**fpTrans)(...);
#else
extern void (**fpTrans)();
#endif
#ifdef __cplusplus
extern void (**fpJTrans)(...);
#else
extern void (**fpJTrans)();
#endif
#ifdef __cplusplus
extern void (*C_Trans[NumNodeTypes+1])(...);
#else
extern void (*C_Trans[])();
#endif
#ifdef __cplusplus
extern void (*C_JTrans[NumJuncTypes+1])(...);
#else
extern void (*C_JTrans[])();
#endif
extern int BlkLevel;
extern int CurFile;
extern char *CurPredName;
extern char *CurRule;
extern int CurRuleDebug; /* MR13 */
extern Junction *CurRuleBlk;
extern RuleEntry *CurRuleNode;
extern ListNode *CurElementLabels;
extern ListNode *CurAstLabelsInActions; /* MR27 */
extern ListNode *ContextGuardPredicateList; /* MR13 */
extern ListNode *CurActionLabels;
extern int numericActionLabel; /* MR10 << ... $1 ... >> or << ... $1 ... >>? */
extern ListNode *NumericPredLabels; /* MR10 << ... $1 ... >>? ONLY */
extern char *FileStr[];
extern int NumFiles;
extern int EpToken;
extern int WildCardToken;
extern Entry **Tname,
**Texpr,
**Rname,
**Fcache,
**Tcache,
**Elabel,
**Sname,
**Pname; /* MR11 */
extern ListNode *ExprOrder;
extern ListNode **Cycles;
extern int TokenNum;
extern int LastTokenCounted;
extern ListNode *BeforeActions, *AfterActions, *LexActions;
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via #lexmember <<....>> & #lexprefix <<...>> */
/* MR1 */
extern ListNode *LexMemberActions; /* MR1 */
extern ListNode *LexPrefixActions; /* MR1 */
extern set *fset; /* for constrained search */ /* MR11 */
extern int maxk; /* for constrained search */ /* MR11 */
extern int Save_argc; /* MR10 */
extern char **Save_argv; /* MR10 */
extern ListNode *eclasses, *tclasses;
extern char *HdrAction;
extern char *FirstAction; /* MR11 */
extern FILE *ErrFile;
extern char *RemapFileName;
extern char *ErrFileName;
extern char *DlgFileName;
extern char *DefFileName;
extern char *ModeFileName;
extern char *StdMsgName;
extern int NumRules;
extern Junction **RulePtr;
extern int LL_k;
extern int CLL_k;
extern char *decodeJType[];
extern int PrintOut;
extern int PrintAnnotate;
extern int CodeGen;
extern int LexGen;
extern int esetnum;
extern int setnum;
extern int wordnum;
extern int GenAST;
extern int GenANSI;
extern int **FoStack;
extern int **FoTOS;
extern int GenExprSetsOpt;
extern FILE *DefFile;
extern int CannotContinue;
extern int GenCR;
extern int GenLineInfo;
extern int GenLineInfoMS;
extern int action_file, action_line;
extern int TraceGen;
extern int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
extern char *CurAmbigbtype;
extern int elevel;
extern int GenEClasseForRules;
extern FILE *input, *output;
extern char **TokenStr, **ExprStr;
extern int CurrentLexClass, NumLexClasses;
extern LClass lclass[];
extern char LexStartSymbol[];
extern char *CurRetDef;
extern char *CurParmDef;
extern int OutputLL_k;
extern int TreeResourceLimit;
extern int DemandLookahead;
extern char *RulePrefix;
extern int GenStdPccts;
extern char *stdpccts;
extern int ParseWithPredicates;
extern int ConstrainSearch;
extern int PURIFY; /* MR23 */
extern set MR_CompromisedRules; /* MR14 */
extern int MR_AmbSourceSearch; /* MR11 */
extern int MR_SuppressSearch; /* MR13 */
extern int MR_AmbSourceSearchGroup; /* MR11 */
extern int MR_AmbSourceSearchChoice; /* MR11 */
extern int MR_AmbSourceSearchLimit; /* MR11 */
extern int MR_usingPredNames; /* MR11 */
extern int MR_ErrorSetComputationActive; /* MR14 */
extern char *MR_AmbAidRule; /* MR11 */
extern int MR_AmbAidLine; /* MR11 */
extern int MR_AmbAidMultiple; /* MR11 */
extern int MR_AmbAidDepth; /* MR11 */
extern int MR_skipped_e3_report; /* MR11 */
extern int MR_matched_AmbAidRule; /* MR11 */
extern int MR_Inhibit_Tokens_h_Gen; /* MR13 */
extern int NewAST; /* MR13 */
extern int tmakeInParser; /* MR23 */
extern int AlphaBetaTrace; /* MR14 */
extern int MR_BlkErr; /* MR21 */
extern int MR_AlphaBetaWarning; /* MR14 */
extern int MR_AlphaBetaMessageCount; /* MR14 */
extern int MR_MaintainBackTrace; /* MR14 */
extern int MR_BadExprSets; /* MR13 */
extern int FoundGuessBlk;
extern int FoundException;
extern int FoundAtOperator; /* MR6 */
extern int FoundExceptionGroup; /* MR6 */
extern int WarningLevel;
extern int UseStdout; /* MR6 */
extern int TabWidth; /* MR6 */
extern int pLevel;
extern int pAlt1;
extern int pAlt2;
extern int AImode;
extern int HoistPredicateContext;
extern int MRhoisting; /* MR9 */
extern int MRhoistingk; /* MR13 */
extern int MR_debugGenRule; /* MR11 */
extern int GenCC;
extern char *ParserName;
extern char *StandardSymbols[];
extern char *ASTSymbols[];
extern set reserved_positions;
extern set all_tokens;
extern set imag_tokens;
extern set tokclasses;
extern ListNode *ForcedTokens;
extern int *TokenInd;
extern FILE *Parser_h, *Parser_c;
extern char CurrentClassName[];
extern int no_classes_found;
extern char Parser_h_Name[];
extern char Parser_c_Name[];
extern char MRinfoFile_Name[]; /* MR10 */
extern FILE *MRinfoFile; /* MR10 */
extern int MRinfo; /* MR10 */
extern int MRinfoSeq; /* MR10 */
extern int InfoP; /* MR10 */
extern int InfoT; /* MR10 */
extern int InfoF; /* MR10 */
extern int InfoM; /* MR10 */
extern int InfoO; /* MR12 */
extern int PotentialSuppression; /* MR10 */
extern int PotentialDummy; /* MR10 */
extern int TnodesInUse; /* MR10 */
extern int TnodesPeak; /* MR10 */
extern int TnodesReportThreshold; /* MR11 */
extern int TnodesAllocated; /* MR10 */
extern char *ClassDeclStuff; /* MR10 */
extern char *BaseClassName; /* MR22 */
extern ListNode *class_before_actions, *class_after_actions;
extern char *UserTokenDefsFile;
extern int UserDefdTokens;
extern ListNode *MetaTokenNodes;
extern char *OutputDirectory;
extern int DontCopyTokens;
extern int LTinTokenAction; /* MR23 */
extern set AST_nodes_refd_in_actions;
extern ListNode *CurExGroups;
extern int CurBlockID;
extern int CurAltNum;
extern Junction *CurAltStart;
extern Junction *OuterAltStart; /* chain exception groups MR7 */
extern ExceptionGroup *DefaultExGroup;
extern int NumSignals;
extern int ContextGuardTRAV;
extern Junction *MR_RuleBlkWithHalt; /* MR10 */
extern PointerStack MR_BackTraceStack; /* MR10 */
extern PointerStack MR_PredRuleRefStack; /* MR10 */
extern PointerStack MR_RuleBlkWithHaltStack; /* MR10 */
/* */
/* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
/* MR1 in DLG action */
/* */
extern int tokenActionActive; /* MR1 */
extern char *PRED_OR_LIST; /* MR10 */
extern char *PRED_AND_LIST; /* MR10 */
#ifdef __VMS
#define STRICMP strcasecmp /* MR21 */
#else
#define STRICMP stricmp /* MR21 */
#endif
/* MR26 */
#ifdef PCCTS_USE_STDARG
extern Tree *tmake(Tree *root, ...);
#else
extern Tree *tmake();
#endif
#ifdef __USE_PROTOS
extern int STRICMP(const char*, const char*);
extern void istackreset(void);
extern int istacksize(void);
extern void pushint(int);
extern int popint( void );
extern int istackempty( void );
extern int topint( void );
extern void NewSetWd( void );
extern void DumpSetWd( void );
extern void DumpSetWdForC( void );
extern void DumpSetWdForCC( void );
extern void NewSet( void );
extern void FillSet( set );
extern void ComputeErrorSets( void );
extern void ComputeTokSets( void );
extern void SubstErrorClass( set * );
extern int DefErrSet( set *, int, char * );
extern int DefErrSetForC( set *, int, char * );
extern int DefErrSetForCC( set *, int, char * );
extern int DefErrSet1(int, set *, int, char *); /* MR21 */
extern int DefErrSetForC1(int, set *, int, char *, const char* ); /* MR21 */
extern int DefErrSetForCC1(int, set *, int, char *, const char* ); /* MR21 */
extern int DefErrSetWithSuffix(int, set *, int, char *, const char *); /* MR21 */
extern void GenErrHdr( void );
extern void dumpExpr( FILE *, char * );
extern void addParm( Node *, char * );
extern Graph buildAction( char *, int, int, int );
extern Graph buildToken( char * );
extern Graph buildWildCard( char * );
extern Graph buildRuleRef( char * );
extern Graph Or( Graph, Graph );
extern Graph Cat( Graph, Graph );
extern Graph makeOpt( Graph, int, char *);
extern Graph makeBlk( Graph, int, char *);
extern Graph makeLoop( Graph, int, char *);
extern Graph makePlus( Graph, int, char *);
extern Graph emptyAlt( void );
extern Graph emptyAlt3( void );
extern TokNode * newTokNode( void );
extern RuleRefNode * newRNode( void );
extern Junction * newJunction( void );
extern ActionNode * newActionNode( void );
extern char * makelocks( void );
extern void preorder( Tree * );
extern Tree * tnode( int );
extern void _Tfree( Tree * );
extern Tree * tdup( Tree * );
extern int is_single_tuple( Tree * );
extern Tree * tappend( Tree *, Tree * );
extern void Tfree( Tree * );
extern Tree * tlink( Tree *, Tree *, int );
extern Tree * tshrink( Tree * );
extern Tree * tflatten( Tree * );
extern Tree * tJunc( Junction *, int, set * );
extern Tree * tRuleRef( RuleRefNode *, int, set * );
extern Tree * tToken( TokNode *, int, set * );
extern Tree * tAction( ActionNode *, int, set * );
extern int tmember( Tree *, Tree * );
extern int tmember_constrained( Tree *, Tree * );
extern Tree * tleft_factor( Tree * );
extern Tree * trm_perm( Tree *, Tree * );
extern void tcvt( set *, Tree * );
extern Tree * permute( int, int );
extern Tree * VerifyAmbig( Junction *, Junction *, unsigned **, set *, Tree **, Tree **, int * );
extern set rJunc( Junction *, int, set * );
extern set rRuleRef( RuleRefNode *, int, set * );
extern set rToken( TokNode *, int, set * );
extern set rAction( ActionNode *, int, set * );
extern void HandleAmbiguity( Junction *, Junction *, Junction *, int );
extern set First( Junction *, int, int, int * );
extern void freeBlkFsets( Junction * );
extern void genAction( ActionNode * );
extern void genRuleRef( RuleRefNode * );
extern void genToken( TokNode * );
extern void genOptBlk( Junction * );
extern void genLoopBlk( Junction *, Junction *, Junction *, int );
extern void genLoopBegin( Junction * );
extern void genPlusBlk( Junction * );
extern void genSubBlk( Junction * );
extern void genRule( Junction * );
extern void genJunction( Junction * );
extern void genEndBlk( Junction * );
extern void genEndRule( Junction * );
extern void genHdr( int );
extern void genHdr1( int );
extern void dumpAction( char *, FILE *, int, int, int, int );
extern void dumpActionPlus(ActionNode*, char *, FILE *, int, int, int, int ); /* MR21 */
extern Entry ** newHashTable( void );
extern Entry * hash_add( Entry **, char *, Entry * );
extern Entry * hash_get( Entry **, char * );
extern void hashStat( Entry ** );
extern char * mystrdup( char * );
extern void genLexDescr( void );
extern void dumpLexClasses( FILE * );
extern void genDefFile( void );
extern void DumpListOfParmNames( char *, FILE *, int ); /* MR5 janm 26-May-97 */
extern int DumpNextNameInDef( char **, FILE * );
extern void DumpOldStyleParms( char *, FILE * );
extern void DumpType( char *, FILE * );
extern int strmember( char *, char * );
/* extern int HasComma( char * ); MR23 Replaced by hasMultipleOperands() */
extern void DumpRetValStruct( FILE *, char *, int );
extern char * StripQuotes( char * );
extern int main( int, char *[] );
extern void readDescr( void );
extern FILE * NextFile( void );
extern char * outnameX( char *, char *);
extern char * outname( char * );
extern void fatalFL( char *, char *, int );
extern void fatal_intern( char *, char *, int );
extern void cleanUp( void );
extern char * eMsg3( char *, char *, char *, char * );
extern char * eMsgd( char *, int );
extern char * eMsgd2( char *, int, int );
extern void s_fprT( FILE *, set );
extern char * TerminalString( int );
extern void lexclass( char * );
extern void lexmode( int );
extern int LexClassIndex( char * );
extern int hasAction( char * );
extern void setHasAction( char *, char * );
extern int addTname( char * );
extern int addTexpr( char * );
extern int Tnum( char * );
extern void Tklink( char *, char * );
extern Entry * newEntry( char *, int );
extern void list_add( ListNode **, void * );
extern void list_free( ListNode **, int freeData ); /* MR10 */
extern void list_apply( ListNode *, void (*)(void *) );
extern int list_search_cstring (ListNode *, char *); /* MR27 */
extern char * Fkey( char *, int, int );
extern void FoPush( char *, int );
extern void FoPop( int );
extern void RegisterCycle( char *, int );
extern void ResolveFoCycles( int );
extern void pJunc( Junction * );
extern void pRuleRef( RuleRefNode * );
extern void pToken( TokNode * );
extern void pAction( ActionNode * );
extern void FoLink( Node * );
extern void addFoLink( Node *, char *, Junction * );
extern void GenCrossRef( Junction * );
extern void defErr( char *, long, long, long, long, long, long );
extern void genStdPCCTSIncludeFile(FILE *,char *); /* MR10 */
extern char * pcctsBaseName(char *); /* MR32 */
extern Predicate *find_predicates(Node *); /* MR10 */
extern Predicate *MR_find_predicates_and_supp(Node *); /* MR13 */
extern int predicateLookaheadDepth(ActionNode *); /* MR10 */
extern void predicate_free(Predicate *); /* MR10 */
extern Predicate * predicate_dup(Predicate *); /* MR10 */
extern Predicate * predicate_dup_without_context(Predicate *); /* MR11 */
extern void GenRulePrototypes(FILE *, Junction *);
extern Junction *first_item_is_guess_block(Junction *);
extern Junction *first_item_is_guess_block_extra(Junction * q); /* MR30 */
extern Junction *analysis_point(Junction *);
extern Tree *make_tree_from_sets(set *, set *);
extern Tree *tdup_chain(Tree *);
extern Tree *tdif(Tree *, Predicate *, set *, set *);
extern set covered_set(Predicate *);
extern void AmbiguityDialog(Junction *, int, Junction *, Junction *, int *, int *);
extern void dumpAmbigMsg(set *, FILE *, int);
extern void GenRuleFuncRedefs(FILE *, Junction *);
extern void GenPredefinedSymbolRedefs(FILE *);
extern void GenASTSymbolRedefs(FILE *);
extern void GenRemapFile(void);
extern void GenSetRedefs(FILE *);
extern ForcedToken *newForcedToken(char *, int);
extern void RemapForcedTokens(void);
extern char *TokenOrExpr(int);
extern void setUpperRange(TokNode *, char *);
extern void GenParser_c_Hdr(void);
extern void GenParser_h_Hdr(void);
extern void GenRuleMemberDeclarationsForCC(FILE *, Junction *);
extern int addForcedTname( char *, int );
extern char *OutMetaName(char *);
extern void OutFirstSetSymbol(Junction *q, char *); /* MR21 */
extern void warnNoFL(char *err);
extern void warnFL(char *err,char *f,int l);
extern void warn(char *err);
extern void warnNoCR( char *err );
extern void errNoFL(char *err);
extern void errFL(char *err,char *f,int l);
extern void err(char *err);
extern void errNoCR( char *err );
extern void genPredTree( Predicate *p, Node *j, int ,int);
extern UserAction *newUserAction(char *);
extern char *gate_symbol(char *name);
extern char *makeAltID(int blockid, int altnum);
extern void DumpRemainingTokSets(void);
extern void DumpANSIFunctionArgDef(FILE *f, Junction *q, int bInit); /* MR23 */
extern void DumpFormals(FILE *, char *, int bInit); /* MR23 */
extern char* hideDefaultArgs(const char* pdecl); /* MR22 VHS */
extern Predicate *computePredFromContextGuard(Graph,int *msgDone); /* MR21 */
extern void recomputeContextGuard(Predicate *); /* MR13 */
extern Predicate *new_pred(void);
extern void chkGTFlag(void);
extern void leAdd(LabelEntry *); /* MR7 */
extern void leFixup(void); /* MR7 */
extern void egAdd(ExceptionGroup *); /* MR7 */
extern void egFixup(void); /* MR7 */
extern void altAdd(Junction *); /* MR7 */
extern void altFixup(void); /* MR7 */
extern Predicate * MR_find_in_aSubBlk(Junction *alt); /* MR10 */
extern Predicate * MR_predFlatten(Predicate *p); /* MR10 */
extern Predicate * MR_predSimplifyALL(Predicate *p); /* MR10 */
extern Predicate * MR_predSimplifyALLX(Predicate *p,int skipPass3); /* MR10 */
extern int MR_allPredLeaves(Predicate *p); /* MR10 */
extern void MR_cleanup_pred_trees(Predicate *p); /* MR10 */
extern int MR_predicate_context_completed(Predicate *p); /* MR10 */
extern void MR_check_pred_too_long(Predicate *p,set completion); /* MR10 */
extern Tree * MR_remove_epsilon_from_tree(Tree *t); /* MR10 */
extern Tree * MR_computeTreeAND(Tree *l,Tree *r); /* MR10 */
extern int MR_tree_equ(Tree *big, Tree *small); /* MR10 */
extern set MR_First(int ck,Junction *j,set *incomplete); /* MR10 */
extern set MR_compute_pred_set(Predicate *p); /* MR10 */
extern Tree * MR_compute_pred_tree_context(Predicate *p); /* MR10 */
extern int MR_pointerStackPush(PointerStack *,void *); /* MR10 */
extern void * MR_pointerStackPop(PointerStack *); /* MR10 */
extern void * MR_pointerStackTop(PointerStack *); /* MR10 */
extern void MR_pointerStackReset(PointerStack *); /* MR10 */
extern void MR_backTraceReport(void); /* MR10 */
extern void MR_alphaBetaTraceReport(void); /* MR14 */
extern void MR_dumpRuleSet(set); /* MR14 */
extern void MR_predContextPresent(Predicate *p,int *,int *); /* MR10 */
extern void MR_dumpPred(Predicate *p,int withContext); /* MR10 */
extern void MR_dumpPred1(int,Predicate *p,int withContext); /* MR10 */
extern void MR_xxxIndent(FILE *f,int depth); /* MR11 */
extern void MR_outputIndent(int depth); /* MR11 */
extern void MR_stderrIndent(int depth); /* MR11 */
extern Junction * MR_ruleReferenced(RuleRefNode *rrn); /* MR10 */
extern Junction * MR_nameToRuleBlk(char *); /* MR10 */
extern void MR_releaseResourcesUsedInRule(Node *); /* MR10 */
extern void MR_dumpTreeX(int depth,Tree *t,int across); /* MR10 */
extern void MR_dumpTreeF(FILE *f,int depth,Tree *t,int across); /* MR10 */
extern void DumpFcache(void); /* MR10 */
extern void MR_dumpTokenSet(FILE *f,int depth,set s); /* MR10 */
extern void MR_traceAmbSource(set *,Junction *,Junction *); /* MR11 */
extern void MR_traceAmbSourceK(Tree *,Junction *a1,Junction *a2); /* MR11 */
extern void MR_traceAmbSourceKclient(void); /* MR20 */
extern Node *MR_advance(Node *); /* MR11 */
extern int MR_offsetFromRule(Node *); /* MR11 */
extern char *MR_ruleNamePlusOffset(Node *); /* MR11 */
extern int MR_max_height_of_tree(Tree *); /* MR11 */
extern int MR_all_leaves_same_height(Tree *,int); /* MR11 */
extern void MR_projectTreeOntoSet(Tree *t,int k,set *); /* MR11 */
extern Tree *MR_make_tree_from_set(set); /* MR11 */
extern Predicate *MR_removeRedundantPredPass3(Predicate *); /* MR11 */
extern void MR_pred_depth(Predicate *,int *); /* MR11 */
extern int MR_comparePredicates(Predicate *,Predicate *); /* MR11 */
extern Predicate * MR_unfold(Predicate *); /* MR11 */
extern void MR_simplifyInverted(Predicate *,int); /* MR11 */
extern int MR_secondPredicateUnreachable /* MR11 */
(Predicate *first,Predicate *second); /* MR11 */
extern void MR_clearPredEntry(Predicate *); /* MR11 */
extern void MR_orphanRules(FILE *); /* MR12 */
extern void MR_merge_contexts(Tree *); /* MR12 */
extern int ci_strequ(char *,char *); /* MR12 */
extern void MR_guardPred_plainSet(ActionNode *anode,Predicate *); /* MR12c */
extern void MR_suppressSearchReport(void); /* MR12c */
extern Predicate * MR_suppressK(Node *,Predicate *); /* MR13 */
extern void MR_backTraceDumpItem(FILE *,int skip,Node *n); /* MR13 */
extern void MR_backTraceDumpItemReset(void); /* MR13 */
extern Junction * MR_junctionWithoutP2(Junction *); /* MR13 */
extern void MR_setConstrainPointer(set *); /* MR18 */
extern void BlockPreambleOption(Junction *q, char * pSymbol); /* MR23 */
extern char* getInitializer(char *); /* MR23 */
extern char *endFormal(char *pStart, /* MR23 */
char **ppDataType, /* MR23 */
char **ppSymbol, /* MR23 */
char **ppEqualSign, /* MR23 */
char **ppValue, /* MR23 */
char **ppSeparator, /* MR23 */
int *pNext); /* MR23 */
extern char *strBetween(char *pStart, /* MR23 */
char *pNext, /* MR23 */
char *pStop); /* MR23 */
extern int hasMultipleOperands(char *); /* MR23 */
extern void DumpInitializers(FILE*, RuleEntry*, char*); /* MR23 */
extern int isTermEntryTokClass(TermEntry *); /* MR23 */
extern int isEmptyAlt(Node *, Node *); /* MR23 */
#else
extern int STRICMP();
extern void istackreset();
extern int istacksize();
extern void pushint();
extern int popint();
extern int istackempty();
extern int topint();
extern void NewSetWd();
extern void DumpSetWd();
extern void DumpSetWdForC();
extern void DumpSetWdForCC();
extern void NewSet();
extern void FillSet();
extern void ComputeErrorSets();
extern void ComputeTokSets();
extern void SubstErrorClass();
extern int DefErrSet();
extern int DefErrSetForC();
extern int DefErrSetForCC();
extern int DefErrSet1();
extern int DefErrSetForC1();
extern int DefErrSetForCC1();
extern int DefErrSetWithSuffix(); /* MR21 */
extern void GenErrHdr();
extern void dumpExpr();
extern void addParm();
extern Graph buildAction();
extern Graph buildToken();
extern Graph buildWildCard();
extern Graph buildRuleRef();
extern Graph Or();
extern Graph Cat();
extern Graph makeOpt();
extern Graph makeBlk();
extern Graph makeLoop();
extern Graph makePlus();
extern Graph emptyAlt();
extern Graph emptyAlt3();
extern TokNode * newTokNode();
extern RuleRefNode * newRNode();
extern Junction * newJunction();
extern ActionNode * newActionNode();
extern char * makelocks();
extern void preorder();
extern Tree * tnode();
extern void _Tfree();
extern Tree * tdup();
extern int is_single_tuple();
extern Tree * tappend();
extern void Tfree();
extern Tree * tlink();
extern Tree * tshrink();
extern Tree * tflatten();
extern Tree * tJunc();
extern Tree * tRuleRef();
extern Tree * tToken();
extern Tree * tAction();
extern int tmember();
extern int tmember_constrained();
extern Tree * tleft_factor();
extern Tree * trm_perm();
extern void tcvt();
extern Tree * permute();
extern Tree * VerifyAmbig();
extern set rJunc();
extern set rRuleRef();
extern set rToken();
extern set rAction();
extern void HandleAmbiguity();
extern set First();
extern void freeBlkFsets();
extern void genAction();
extern void genRuleRef();
extern void genToken();
extern void genOptBlk();
extern void genLoopBlk();
extern void genLoopBegin();
extern void genPlusBlk();
extern void genSubBlk();
extern void genRule();
extern void genJunction();
extern void genEndBlk();
extern void genEndRule();
extern void genHdr();
extern void genHdr1();
extern void dumpAction();
extern void dumpActionPlus(); /* MR21 */
extern Entry ** newHashTable();
extern Entry * hash_add();
extern Entry * hash_get();
extern void hashStat();
extern char * mystrdup();
extern void genLexDescr();
extern void dumpLexClasses();
extern void genDefFile();
extern void DumpListOfParmNames(); /* MR5 janm 26-May-97 */
extern int DumpNextNameInDef();
extern void DumpOldStyleParms();
extern void DumpType();
extern int strmember();
/* extern int HasComma(); MR23 Replaced by hasMultipleOperands() */
extern void DumpRetValStruct();
extern char * StripQuotes();
extern int main();
extern void readDescr();
extern FILE * NextFile();
extern char * outnameX();
extern char * outname();
extern void fatalFL();
extern void fatal_intern();
extern void cleanUp();
extern char * eMsg3();
extern char * eMsgd();
extern char * eMsgd2();
extern void s_fprT();
extern char * TerminalString();
extern void lexclass();
extern void lexmode();
extern int LexClassIndex();
extern int hasAction();
extern void setHasAction();
extern int addTname();
extern int addTexpr();
extern int Tnum();
extern void Tklink();
extern Entry * newEntry();
extern void list_add();
extern void list_free(); /* MR10 */
extern void list_apply();
extern int list_search_cstring (); /* MR27 */
extern char * Fkey();
extern void FoPush();
extern void FoPop();
extern void RegisterCycle();
extern void ResolveFoCycles();
extern void pJunc();
extern void pRuleRef();
extern void pToken();
extern void pAction();
extern void FoLink();
extern void addFoLink();
extern void GenCrossRef();
extern void defErr();
extern void genStdPCCTSIncludeFile();
extern char * pcctsBaseName(); /* MR32 */
extern Predicate *find_predicates();
extern Predicate *MR_find_predicates_and_supp(); /* MR13 */
extern int predicateLookaheadDepth(); /* MR10 */
extern void predicate_free(); /* MR10 */
extern Predicate * predicate_dup(); /* MR10 */
extern Predicate * predicate_dup_without_context(); /* MR11 */
extern void GenRulePrototypes();
extern Junction *first_item_is_guess_block();
extern Junction *first_item_is_guess_block_extra(); /* MR30 */
extern Junction *analysis_point();
extern Tree *make_tree_from_sets();
extern Tree *tdup_chain();
extern Tree *tdif();
extern set covered_set();
extern void AmbiguityDialog();
extern void dumpAmbigMsg();
extern void GenRuleFuncRedefs();
extern void GenPredefinedSymbolRedefs();
extern void GenASTSymbolRedefs();
extern void GenRemapFile();
extern void GenSetRedefs();
extern ForcedToken *newForcedToken();
extern void RemapForcedTokens();
extern char *TokenOrExpr();
extern void setUpperRange();
extern void GenParser_c_Hdr();
extern void GenParser_h_Hdr();
extern void GenRuleMemberDeclarationsForCC();
extern int addForcedTname();
extern char *OutMetaName();
extern void OutFirstSetSymbol(); /* MR21 */
extern void warnNoFL();
extern void warnFL();
extern void warn();
extern void warnNoCR();
extern void errNoFL();
extern void errFL();
extern void err();
extern void errNoCR();
extern void genPredTree();
extern UserAction *newUserAction();
extern char *gate_symbol();
extern char *makeAltID();
extern void DumpRemainingTokSets();
extern void DumpANSIFunctionArgDef();
extern void DumpFormals(); /* MR23 */
extern char* hideDefaultArgs(); /* MR22 VHS */
extern Predicate *computePredFromContextGuard();
extern void recomputeContextGuard(); /* MR13 */
extern Predicate *new_pred();
extern void chkGTFlag();
extern void leAdd(); /* MR7 */
extern void leFixup(); /* MR7 */
extern void egAdd(); /* MR7 */
extern void egFixup(); /* MR7 */
extern void altAdd(); /* MR7 */
extern void altFixup(); /* MR7 */
extern Predicate * MR_find_in_aSubBlk(); /* MR10 */
extern Predicate * MR_predFlatten(); /* MR10 */
extern Predicate * MR_predSimplifyALL(); /* MR10 */
extern Predicate * MR_predSimplifyALLX(); /* MR10 */
extern void MR_cleanup_pred_trees(); /* MR10 */
extern int MR_allPredLeaves(); /* MR10 */
extern int MR_predicate_context_completed(); /* MR10 */
extern void MR_check_pred_too_long(); /* MR10 */
extern Tree * MR_remove_epsilon_from_tree(); /* MR10 */
extern Tree * MR_computeTreeAND(); /* MR10 */
extern int MR_tree_equ(); /* MR10 */
extern set MR_First(); /* MR10 */
extern set MR_compute_pred_set(); /* MR10 */
extern Tree * MR_compute_pred_tree_context(); /* MR10 */
extern int MR_pointerStackPush(); /* MR10 */
extern void * MR_pointerStackPop(); /* MR10 */
extern void * MR_pointerStackTop(); /* MR10 */
extern void MR_pointerStackReset(); /* MR10 */
extern void MR_backTraceReport(); /* MR10 */
extern void MR_alphaBetaTraceReport(); /* MR14 */
extern void MR_dumpRuleSet(); /* MR14 */
extern void MR_predContextPresent(); /* MR10 */
extern void MR_dumpPred(); /* MR10 */
extern void MR_dumpPred1(); /* MR10 */
extern void MR_xxxIndent(); /* MR11 */
extern void MR_stderrIndent(); /* MR11 */
extern void MR_outputIndent(); /* MR11 */
extern Junction * MR_ruleReferenced(); /* MR10 */
extern void MR_releaseResourcesUsedInRule(); /* MR10 */
extern void MR_dumpTreeX(); /* MR10 */
extern void MR_dumpTreeF(); /* MR10 */
extern void DumpFcache(); /* MR10 */
extern void MR_dumpTokenSet(); /* MR10 */
extern void MR_traceAmbSource(); /* MR11 */
extern Node *MR_advance(); /* MR11 */
extern int MR_offsetFromRule(); /* MR11 */
extern char *MR_ruleNamePlusOffset(); /* MR11 */
extern void MR_traceAmbSourceK(); /* MR11 */
extern void MR_traceAmbSourceKclient(); /* [i_a] added */
extern int MR_max_height_of_tree(); /* MR11 */
extern int MR_all_leaves_same_height(); /* MR11 */
extern void MR_projectTreeOntoSet(); /* MR11 */
extern Tree *MR_make_tree_from_set(); /* MR11 */
extern Predicate *MR_removeRedundantPredPass3(); /* MR11 */
extern void MR_pred_depth(); /* MR11 */
extern int MR_comparePredicates(); /* MR11 */
extern Predicate * MR_unfold(); /* MR11 */
extern void MR_simplifyInverted(); /* MR11 */
extern int MR_secondPredicateUnreachable(); /* MR11 */
extern Junction * MR_nameToRuleBlk(); /* MR10 */
extern void MR_clearPredEntry(); /* MR11 */
extern void MR_orphanRules(); /* MR12 */
extern void MR_merge_contexts(); /* MR12 */
extern int ci_strequ(); /* MR12 */
extern void MR_guardPred_plainSet(); /* MR12c */
extern void MR_suppressSearchReport(); /* MR12c */
extern Predicate * MR_suppressK(); /* MR13 */
extern void MR_backTraceDumpItem(); /* MR13 */
extern void MR_backTraceDumpItemReset(); /* MR13 */
extern Junction * MR_junctionWithoutP2(); /* MR13 */
extern void MR_setConstrainPointer(); /* MR18 */
extern void BlockPreambleOption(); /* MR23 */
extern char* getInitializer(); /* MR23 */
extern int hasMultipleOperands(); /* MR23 */
extern char *endFormal(); /* MR23 */
extern char *strBetween(); /* MR23 */
extern void DumpInitializers(); /* MR23 */
extern int isTermEntryTokClass(); /* MR23 */
extern int isEmptyAlt();
#endif
#ifdef __USE_PROTOS
#include <stdlib.h>
#endif
/* MR20 G. Hobbelt Create proper externs for dlg variables */
extern set attribsRefdFromAction;
extern int inAlt;
extern int UsedOldStyleAttrib;
extern int UsedNewStyleLabel;
#define MAX_BLK_LEVEL 100 /* MR23 */
extern int CurBlockID_array[MAX_BLK_LEVEL]; /* MR23 */
extern int CurAltNum_array[MAX_BLK_LEVEL]; /* MR23 */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,31 @@
#ifndef STDPCCTS_H
#define STDPCCTS_H
/*
* stdpccts.h -- P C C T S I n c l u d e
*
* Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
* Purdue University Electrical Engineering
* With AHPCRC, University of Minnesota
* ANTLR Version 1.33MR33
*/
#ifndef ANTLR_VERSION
#define ANTLR_VERSION 13333
#endif
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pcctscfg.h"
#include "set.h"
#include <ctype.h>
#include "syn.h"
#include "hash.h"
#include "generic.h"
#define zzcr_attr(attr,tok,t)
#define zzSET_SIZE 20
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "mode.h"
#endif

View File

@@ -0,0 +1,390 @@
/*
* syn.h
*
* This file includes definitions and macros associated with syntax diagrams
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include "set.h"
#define NumNodeTypes 4
#define NumJuncTypes 9
/* List the different node types */
#define nJunction 1
#define nRuleRef 2
#define nToken 3
#define nAction 4
/* Different types of junctions */
#define aSubBlk 1
#define aOptBlk 2
#define aLoopBlk 3
#define EndBlk 4
#define RuleBlk 5
#define Generic 6 /* just a junction--no unusual characteristics */
#define EndRule 7
#define aPlusBlk 8
#define aLoopBegin 9
typedef int NodeType;
#define TreeBlockAllocSize 500
#define JunctionBlockAllocSize 200
#define ActionBlockAllocSize 50
#define RRefBlockAllocSize 100
#define TokenBlockAllocSize 100
#ifdef __cplusplus
class ActionNode;
class Junction;
#endif
/* note that 'right' is used by the tree node allocator as a ptr for linked list */
typedef struct _tree {
struct _tree *down, *right;
int token;
union {
int rk; /* if token==EpToken, => how many more tokens req'd */
struct _tree *tref; /* if token==TREE_REF */
set sref; /* if token==SET */
} v;
#ifdef TREE_DEBUG
int in_use;
int seq;
#endif
} Tree;
/* a predicate is defined to be a predicate action and a token tree with
* context info (if used); later, this struct may include the
* "hoisting distance" when we hoist past tokens.
*
* A tree is used to indicate && vs ||
*
* p
* |
* q--r
*
* indicates p && (q||r).
*
* If expr is PRED_AND_LIST or PRED_OR_LIST, then it's an operation node
* and indicates the start of an && or || list.
*/
typedef struct _Predicate {
struct _Predicate *down, *right; /* these have to be first */
struct _Predicate *up, *left; /* doubly-link me */
char *expr;
Tree *tcontext; /* used if lookahead depth of > one is needed (tree) */
int k; /* lookahead depth for this tcontext */
set scontext[2];/* used if lookahead depth of one is needed (set) */
/* scontext[0] is not used; only needed so genExprSets()
routine works (it expects an array)
*/
set completionTree; /* which lookahead depths are required to complete tcontext? */
set completionSet; /* MR10 separate completion set for sets and trees */
struct _PredEntry *predEntry; /* MR11 */
#ifdef __cplusplus
ActionNode *source; /* where did this predicate come from? */
#else
struct _anode *source; /* where did this predicate come from? */
#endif
char cloned; /* MR10 don't want to free original guard pred */
char redundant; /* MR10 predicate tree simplification */
char ampersandStyle; /* MR10 (g)? && <<p>>? */
char inverted; /* MR11 ! predName */
char isConst; /* MR11 */
char constValue; /* MR11 */
char conflictReported; /* MR11 */
set plainSet; /* MR12b */
/*** remember to change new_predicate() and predicate_dup() when changing this ***/
} Predicate;
typedef struct _ExceptionHandler {
char *signalname;
char *action;
} ExceptionHandler;
typedef struct _ExceptionGroup {
struct _ListNode *handlers; /* list of ExceptionHandler's */
char *label; /* label==""; implies not attached to any
* particular rule ref.
*/
char *altID; /* which alt did it come from (blk#:alt#) */
struct _ExceptionGroup *pendingLink; /* for alternative EG MR7 */
struct _ExceptionGroup *outerEG; /* for alternative EG MR7 */
struct _LabelEntry *labelEntry; /* for alternative EG MR7 */
int forRule; /* MR7 */
int used; /* MR7 */
} ExceptionGroup ;
#define TokenString(_i) ((TokenInd!=NULL)?TokenStr[TokenInd[_i]]:TokenStr[_i])
#define ExprString(_i) ((TokenInd!=NULL)?ExprStr[TokenInd[_i]]:ExprStr[_i])
/* M e s s a g e P a s s i n g T o N o d e s */
/*
* assumes a 'Junction *r' exists. This macro calls a function with
* the pointer to the node to operate on and a pointer to the rule
* in which it is enclosed.
*/
#define TRANS(p) {if ( (p)==NULL ) fatal("TRANS: NULL object"); \
if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\
else (*(fpTrans[(p)->ntype]))( p );}
#define PRINT(p) {if ( (p)==NULL ) fatal("PRINT: NULL object");\
(*(fpPrint[(p)->ntype]))( p );}
#define REACH(p,k,rk,a) {if ( (p)==NULL ) fatal("REACH: NULL object");\
(a) = (*(fpReach[(p)->ntype]))( p, k, rk );}
#define TRAV(p,k,rk,a) {if ( (p)==NULL ) {\
if ( ContextGuardTRAV ) (a)=NULL; \
else fatal("TRAV: NULL object");\
} \
else (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
/**
*** #define TRAV(p,k,rk,a) {if ( (p)==NULL ) fatal("TRAV: NULL object");\
*** (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
**/
/* All syntax diagram nodes derive from Node -- superclass
*/
#ifdef __cplusplus
class Node {
public:
NodeType ntype;
char *rname; /* what rule does this element live in? */
int file; /* index in FileStr */
int line; /* line number that element occurs on */
};
#else
typedef struct _node {
NodeType ntype;
char *rname; /* what rule does this element live in? */
int file; /* index in FileStr */
int line; /* line number that element occurs on */
} Node;
#endif
#ifdef __cplusplus
class ActionNode : public Node {
public:
#else
typedef struct _anode {
NodeType ntype;
char *rname; /* what rule does this action live in? */
int file; /* index in FileStr (name of file with action) */
int line; /* line number that action occurs on */
#endif
Node *next;
char *action;
int is_predicate; /* true if action is a <<...>>? predicate action */
int done; /* don't dump if action dumped (used for predicates) */
int init_action; /* is this the 1st action of 1st prod of block? */
char *pred_fail; /* what to do/print when predicate fails */
Predicate *guardpred; /* if '(context)? =>' was present, already done */
unsigned char frmwarned;/* have we dumped a warning for pred yet? */
unsigned char ctxwarned;/* have we dumped a warning for pred yet? */
unsigned char predTooLong; /* MR10 have we dumped warning for pred yet */
unsigned char noHoist; /* MR12 literally "noHoist" */
Predicate *ampersandPred; /* MR10 (g)? && <<p>>? expr */
#ifdef __cplusplus
Junction *guardNodes; /* MR11 */
#else
struct _junct *guardNodes; /* MR11 */
#endif
struct _PredEntry *predEntry; /* MR11 */
int inverted; /* MR11 <<!predSymbol>>? */
#ifdef __cplusplus
};
#else
} ActionNode;
#endif
#ifdef __cplusplus
class TokNode : public Node {
public:
#else
typedef struct _toknode {
NodeType ntype;
char *rname; /* name of rule it's in */
int file; /* index in FileStr (name of file with rule) */
int line; /* line number that token occurs on */
#endif
Node *next;
int token;
int astnode; /* leaf/root/excluded (used to build AST's) */
unsigned char label;/* token label or expression ? */
unsigned char remapped;
/* used if token id's are forced to certain positions;
* a function walks the tree reassigning token numbers */
int upper_range; /* MR13 - was char */
/* used only if Token is of type T1..T2; in this case,
* use token..upper_range as the range; else
* upper_range must be 0 */
unsigned char wild_card;
/* indicates that the token is the "." wild-card;
* field token is ignored if wild_card is set
*/
unsigned int elnum; /* element number within the alternative */
#ifdef __cplusplus
Junction *altstart; /* pointer to node that starts alt */
#else
struct _junct *altstart; /* pointer to node that starts alt */
#endif
struct _TCnode *tclass; /* token class if tokclass ref */
set tset; /* set of tokens represented by meta token */
char *el_label; /* el_label:toknode */
unsigned char complement; /* complement the set? */
ExceptionGroup *ex_group; /* any exception[el_label] attached? */
unsigned char use_def_MT_handler;
unsigned char label_used_in_semantic_pred; /* MR10 */
#ifdef __cplusplus
};
#else
} TokNode;
#endif
#ifdef __cplusplus
class RuleRefNode : public Node {
public:
#else
typedef struct _rrnode {
NodeType ntype;
char *rname; /* name of rule it's in */
int file; /* index in FileStr (name of file with rule)
it's in */
int line; /* line number that rule ref occurs on */
#endif
Node *next;
char *text; /* reference to which rule */
char *parms; /* point to parameters of rule invocation
(if present) */
char *assign; /* point to left-hand-side of assignment
(if any) */
int linked; /* Has a FoLink already been established? */
int astnode; /* excluded? (used to build AST's) */
unsigned int elnum; /* element number within the alternative */
#ifdef __cplusplus
Junction *altstart;
#else
struct _junct *altstart;
#endif
char *el_label; /* el_label:rrnode */
ExceptionGroup *ex_group; /* any exception[el_label] attached? */
#ifdef __cplusplus
};
#else
} RuleRefNode;
#endif
#ifdef __cplusplus
class Junction : public Node {
public:
#else
typedef struct _junct {
NodeType ntype;
char *rname; /* name of rule junction is in */
int file; /* index in FileStr (name of file with rule)
if blk == RuleBlk */
int line; /* line number that rule occurs on */
#endif
int seq; /* MR10 sequence number */
char ignore; /* used by FIRST computation to ignore
empty alt added for the (...)+ blks */
char visited; /* used by recursive routines to avoid
infinite recursion */
char pvisited; /* used by print routines to avoid
infinite recursion */
char fvisited; /* used by FoLink() to avoid
infinite recursion */
char *lock; /* used by REACH to track infinite recursion */
char *pred_lock; /* used by find_predicates to track infinite recursion */
int altnum; /* used in subblocks. altnum==0 means not an
alt of subrule */
int jtype; /* annotation for code-gen/FIRST/FOLLOW.
Junction type */
#ifdef __cplusplus
Junction *end; /* pointer to node with EndBlk in it
if blk == a block type */
#else
struct _junct *end; /* pointer to node with EndBlk in it
if blk == a block type */
#endif
Node *p1, *p2;
char halt; /* never move past a junction with halt==TRUE */ /* MR10 was int */
char *pdecl; /* point to declaration of parameters on rule
(if present) */
char *parm; /* point to parameter of block invocation
(if present) */
char predparm; /* indicates that the 'parm' is a predicate
* to be used in the while loop generated
* for blocks */ /* MR10 was int */
char *ret; /* point to return type of rule (if present) */
char *erraction; /* point to error action (if present) */
int blockid; /* this is a unique ID */
char *exception_label; /* goto label for this alt */
set *fset; /* used for code generation */
Tree *ftree; /* used for code generation */
Predicate *predicate;/* predicate that can be used to disambiguate */
char guess; /* true if (...)? block */
char alpha_beta_guess_end; /* MR14 1 => end block of guess sub block */
Node *guess_analysis_point; /* MR14 */
char approx; /* limit block to use linear approx lookahead? */
set tokrefs; /* if ith element of alt is tokref then i is member */
set rulerefs; /* if ith element of alt is rule ref then i is member */
struct _ListNode *exceptions; /* list of exceptions groups for rule */
struct _ListNode *el_labels; /* list of element labels for rule */
ExceptionGroup *outerEG; /* MR7 */
int curAltNum; /* MR7 */
char* pFirstSetSymbol; /* #pragma FirstSetSymbol(Foo) MR21 */
#ifdef __cplusplus
Junction *pendingLink; /* MR7 */
#else
struct _junct *pendingLink; /* MR7 */
#endif
char overlap_warning; /* MR10 */
#ifdef __cplusplus
};
#else
} Junction;
#endif
typedef struct { Node *left, *right;} Graph;

View File

@@ -0,0 +1,246 @@
#ifndef tokens_h
#define tokens_h
/* tokens.h -- List of labelled tokens and stuff
*
* Generated from: antlr.g
*
* Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
* Purdue University Electrical Engineering
* ANTLR Version 1.33MR33
*/
#define zzEOF_TOKEN 1
#define Eof 1
#define QuotedTerm 2
#define Action 34
#define Pred 35
#define PassAction 36
#define WildCard 87
#define LABEL 89
#define Pragma 92
#define FirstSetSymbol 93
#define NonTerminal 100
#define TokenTerm 101
#define ID 148
#define INT 150
#ifdef __USE_PROTOS
void grammar(void);
#else
extern void grammar();
#endif
#ifdef __USE_PROTOS
void class_def(void);
#else
extern void class_def();
#endif
#ifdef __USE_PROTOS
void rule(void);
#else
extern void rule();
#endif
#ifdef __USE_PROTOS
void laction(void);
#else
extern void laction();
#endif
#ifdef __USE_PROTOS
void lmember(void);
#else
extern void lmember();
#endif
#ifdef __USE_PROTOS
void lprefix(void);
#else
extern void lprefix();
#endif
#ifdef __USE_PROTOS
void aPred(void);
#else
extern void aPred();
#endif
#ifdef __USE_PROTOS
extern Predicate * predOrExpr(void);
#else
extern Predicate * predOrExpr();
#endif
#ifdef __USE_PROTOS
extern Predicate * predAndExpr(void);
#else
extern Predicate * predAndExpr();
#endif
#ifdef __USE_PROTOS
extern Predicate * predPrimary(void);
#else
extern Predicate * predPrimary();
#endif
#ifdef __USE_PROTOS
void aLexclass(void);
#else
extern void aLexclass();
#endif
#ifdef __USE_PROTOS
void error(void);
#else
extern void error();
#endif
#ifdef __USE_PROTOS
void tclass(void);
#else
extern void tclass();
#endif
#ifdef __USE_PROTOS
void token(void);
#else
extern void token();
#endif
#ifdef __USE_PROTOS
void block(set * toksrefd,set * rulesrefd);
#else
extern void block();
#endif
#ifdef __USE_PROTOS
void alt(set * toksrefd,set * rulesrefd);
#else
extern void alt();
#endif
#ifdef __USE_PROTOS
extern LabelEntry * element_label(void);
#else
extern LabelEntry * element_label();
#endif
#ifdef __USE_PROTOS
extern Node * element(int old_not,int first_on_line,int use_def_MT_handler);
#else
extern Node * element();
#endif
#ifdef __USE_PROTOS
void default_exception_handler(void);
#else
extern void default_exception_handler();
#endif
#ifdef __USE_PROTOS
extern ExceptionGroup * exception_group(void);
#else
extern ExceptionGroup * exception_group();
#endif
#ifdef __USE_PROTOS
extern ExceptionHandler * exception_handler(void);
#else
extern ExceptionHandler * exception_handler();
#endif
#ifdef __USE_PROTOS
void enum_file(char * fname);
#else
extern void enum_file();
#endif
#ifdef __USE_PROTOS
void defines(char * fname);
#else
extern void defines();
#endif
#ifdef __USE_PROTOS
void enum_def(char * fname);
#else
extern void enum_def();
#endif
#endif
extern SetWordType zzerr1[];
extern SetWordType zzerr2[];
extern SetWordType zzerr3[];
extern SetWordType zzerr4[];
extern SetWordType setwd1[];
extern SetWordType zzerr5[];
extern SetWordType zzerr6[];
extern SetWordType zzerr7[];
extern SetWordType zzerr8[];
extern SetWordType zzerr9[];
extern SetWordType setwd2[];
extern SetWordType zzerr10[];
extern SetWordType zzerr11[];
extern SetWordType zzerr12[];
extern SetWordType zzerr13[];
extern SetWordType setwd3[];
extern SetWordType zzerr14[];
extern SetWordType zzerr15[];
extern SetWordType zzerr16[];
extern SetWordType zzerr17[];
extern SetWordType zzerr18[];
extern SetWordType zzerr19[];
extern SetWordType zzerr20[];
extern SetWordType zzerr21[];
extern SetWordType setwd4[];
extern SetWordType zzerr22[];
extern SetWordType zzerr23[];
extern SetWordType zzerr24[];
extern SetWordType zzerr25[];
extern SetWordType zzerr26[];
extern SetWordType setwd5[];
extern SetWordType zzerr27[];
extern SetWordType zzerr28[];
extern SetWordType zzerr29[];
extern SetWordType zzerr30[];
extern SetWordType zzerr31[];
extern SetWordType zzerr32[];
extern SetWordType zzerr33[];
extern SetWordType setwd6[];
extern SetWordType zzerr34[];
extern SetWordType zzerr35[];
extern SetWordType zzerr36[];
extern SetWordType zzerr37[];
extern SetWordType zzerr38[];
extern SetWordType zzerr39[];
extern SetWordType zzerr40[];
extern SetWordType zzerr41[];
extern SetWordType zzerr42[];
extern SetWordType setwd7[];
extern SetWordType zzerr43[];
extern SetWordType zzerr44[];
extern SetWordType zzerr45[];
extern SetWordType zzerr46[];
extern SetWordType zzerr47[];
extern SetWordType zzerr48[];
extern SetWordType zzerr49[];
extern SetWordType zzerr50[];
extern SetWordType zzerr51[];
extern SetWordType zzerr52[];
extern SetWordType zzerr53[];
extern SetWordType setwd8[];
extern SetWordType zzerr54[];
extern SetWordType zzerr55[];
extern SetWordType zzerr56[];
extern SetWordType zzerr57[];
extern SetWordType setwd9[];
extern SetWordType zzerr58[];
extern SetWordType zzerr59[];
extern SetWordType zzerr60[];
extern SetWordType zzerr61[];
extern SetWordType zzerr62[];
extern SetWordType zzerr63[];
extern SetWordType zzerr64[];
extern SetWordType zzerr65[];
extern SetWordType setwd10[];
extern SetWordType setwd11[];

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK Pccts Tool
Copyright (c) 2006, Intel Corporation
<property name="ToolName" value="Pccts"/>
-->
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="init">
<echo message="Building the EDK Pccts Tools"/>
</target>
<target name="GenTool" depends="init, Pccts">
<echo message="The EDK Pccts Tools build has completed!"/>
</target>
<target name="Pccts" depends="init">
<subant target="" inheritall="true">
<fileset dir="${PACKAGE_DIR}/Pccts/antlr" includes="build.xml"/>
</subant>
<subant target="" inheritall="true">
<fileset dir="${PACKAGE_DIR}/Pccts/dlg" includes="build.xml"/>
</subant>
</target>
<target name="clean">
<ant dir="${PACKAGE_DIR}/Pccts/antlr" target="clean" inheritAll="true"/>
<ant dir="${PACKAGE_DIR}/Pccts/dlg" target="clean" inheritAll="true"/>
</target>
<target name="cleanall">
<ant dir="${PACKAGE_DIR}/Pccts/antlr" target="cleanall" inheritAll="true"/>
<ant dir="${PACKAGE_DIR}/Pccts/dlg" target="cleanall" inheritAll="true"/>
</target>
</project>

View File

@@ -0,0 +1,121 @@
# PCCTS directory
# You will need to set the LIB variable similar to this.
# LIB="C:/Program Files/Microsoft Visual Studio .NET 2003/Vc7/lib;c:/Microsoft Visual Studio .NET 2003/Vc7/PlatformSDK/Lib"
# PCCTS_HOME=<your PCCTS_HOME>
PCCTS_HOME=$(WORKSPACE)\Tools\Source\TianoTools\Pccts
DLG_SRC=$(PCCTS_HOME)\dlg
PCCTS_H=$(PCCTS_HOME)\h
# Support directories
SET=$(PCCTS_HOME)\support\set
# Compiler stuff
CC = cl
CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
-D "ZZLEXBUFSIZE=65536" /D "LONGFILENAMES" /W3 /Zi
DLG_OBJS = dlg_p.obj dlg_a.obj main.obj err.obj support.obj \
output.obj relabel.obj automata.obj
SUPPORT_OBJS = set.obj
# Dependencies
dlg.exe: $(DLG_OBJS) $(SUPPORT_OBJS)
$(CC) $(CFLAGS) -o dlg.exe $(DLG_OBJS) $(SUPPORT_OBJS)
del *.obj
del *.ilk
del *.pdb
move dlg.exe $(WORKSPACE)\Tools\bin\.
dlg_p.obj: $(DLG_SRC)\dlg_p.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(DLG_SRC)\mode.h \
$(DLG_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\dlg_p.c
dlg_a.obj: $(DLG_SRC)\dlg_a.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgauto.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(DLG_SRC)\mode.h \
$(DLG_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\dlg_a.c
main.obj: $(DLG_SRC)\main.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(DLG_SRC)\mode.h \
$(DLG_SRC)\stdpccts.h \
$(DLG_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\main.c
err.obj: $(DLG_SRC)\err.c \
$(PCCTS_H)\antlr.h \
$(PCCTS_H)\config.h \
$(PCCTS_H)\dlgdef.h \
$(PCCTS_H)\err.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(DLG_SRC)\tokens.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\err.c
support.obj: $(DLG_SRC)\support.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\support.c
output.obj: $(DLG_SRC)\output.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\output.c
relabel.obj: $(DLG_SRC)\relabel.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\relabel.c
automata.obj: $(DLG_SRC)\automata.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(DLG_SRC)\dlg.h \
$(CC) -c $(CFLAGS) $(DLG_SRC)\automata.c
set.obj: $(SET)\set.c \
$(PCCTS_H)\config.h \
$(SET)\set.h \
$(CC) -c $(CFLAGS) $(SET)\set.c
clean:
del *.obj
distclean:
del *.obj
del $(WORKSPACE)\Tools\bin\dlg.exe

View File

@@ -0,0 +1,84 @@
# File: dlgPPC.make
# Target: dlgPPC
# Sources: automata.c
# dlg_a.c
# dlg_p.c
# err.c
# main.c
# output.c
# relabel.c
# support.c
# ::support:set:set.c
# Created: Sunday, May 17, 1998 11:34:20 PM
# Author: Kenji Tanaka
MAKEFILE = dlgPPC.make
<EFBFBD>MondoBuild<EFBFBD> = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified
Includes = <20>
-i "::h:" <20>
-i "::support:set:"
Sym<EFBFBD>PPC =
ObjDir<EFBFBD>PPC = ":Obj:"
PPCCOptions = {Includes} {Sym<EFBFBD>PPC} -w off -d MPW -d __STDC__=1 -d USER_ZZSYN
Objects<EFBFBD>PPC = <20>
"{ObjDir<69>PPC}automata.c.x" <20>
"{ObjDir<69>PPC}dlg_a.c.x" <20>
"{ObjDir<69>PPC}dlg_p.c.x" <20>
"{ObjDir<69>PPC}err.c.x" <20>
"{ObjDir<69>PPC}main.c.x" <20>
"{ObjDir<69>PPC}output.c.x" <20>
"{ObjDir<69>PPC}relabel.c.x" <20>
"{ObjDir<69>PPC}support.c.x" <20>
"{ObjDir<69>PPC}set.c.x"
dlgPPC <EFBFBD><EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} {Objects<EFBFBD>PPC}
PPCLink <EFBFBD>
-o {Targ} {Sym<EFBFBD>PPC} <EFBFBD>
{Objects<EFBFBD>PPC} <EFBFBD>
-t 'MPST' <EFBFBD>
-c 'MPS ' <EFBFBD>
"{SharedLibraries}InterfaceLib" <EFBFBD>
"{SharedLibraries}StdCLib" <EFBFBD>
"{SharedLibraries}MathLib" <EFBFBD>
"{PPCLibraries}StdCRuntime.o" <EFBFBD>
"{PPCLibraries}PPCCRuntime.o" <EFBFBD>
"{PPCLibraries}PPCToolLibs.o"
"{ObjDir<69>PPC}automata.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} automata.c
{PPCC} automata.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}dlg_a.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} dlg_a.c
{PPCC} dlg_a.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}dlg_p.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} dlg_p.c
{PPCC} dlg_p.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}err.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} err.c
{PPCC} err.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}main.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} main.c
{PPCC} main.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}output.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} output.c
{PPCC} output.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}relabel.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} relabel.c
{PPCC} relabel.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}support.c.x" <EFBFBD> {<EFBFBD>MondoBuild<EFBFBD>} support.c
{PPCC} support.c -o {Targ} {PPCCOptions}
"{ObjDir<69>PPC}set.c.x" <EFBFBD> {<7B>MondoBuild<6C>} "::support:set:set.c"
{PPCC} "::support:set:set.c" -o {Targ} {PPCCOptions}
dlgPPC <EFBFBD><EFBFBD> dlg.r
Rez dlg.r -o dlgPPC -a
Install <EFBFBD> dlgPPC
Duplicate -y dlgPPC "{MPW}"Tools:dlg

View File

@@ -0,0 +1,353 @@
/* Automata conversion functions for DLG
*
* 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 "pcctscfg.h"
#include "dlg.h"
#ifdef MEMCHK
#include "trax.h"
#else
#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif /* __STDC__ */
#endif
#define hash_list struct _hash_list_
hash_list{
hash_list *next; /* next thing in list */
dfa_node *node;
};
int dfa_allocated = 0; /* keeps track of number of dfa nodes */
dfa_node **dfa_array; /* root of binary tree that stores dfa array */
dfa_node *dfa_model_node;
hash_list *dfa_hash[HASH_SIZE]; /* used to quickly find */
/* desired dfa node */
void
#ifdef __USE_PROTOS
make_dfa_model_node(int width)
#else
make_dfa_model_node(width)
int width;
#endif
{
register int i;
dfa_model_node = (dfa_node*) malloc(sizeof(dfa_node)
+ sizeof(int)*width);
dfa_model_node->node_no = -1; /* impossible value for real dfa node */
dfa_model_node->dfa_set = 0;
dfa_model_node->alternatives = FALSE;
dfa_model_node->done = FALSE;
dfa_model_node->nfa_states = empty;
for(i = 0; i<width; i++){
dfa_model_node->trans[i] = NIL_INDEX;
}
}
/* adds a new nfa to the binary tree and returns a pointer to it */
dfa_node *
#ifdef __USE_PROTOS
new_dfa_node(set nfa_states)
#else
new_dfa_node(nfa_states)
set nfa_states;
#endif
{
register int j;
register dfa_node *t;
static int dfa_size=0; /* elements dfa_array[] can hold */
++dfa_allocated;
if (dfa_size<=dfa_allocated){
/* need to redo array */
if (!dfa_array){
/* need some to do inital allocation */
dfa_size=dfa_allocated+DFA_MIN;
dfa_array=(dfa_node **) malloc(sizeof(dfa_node*)*
dfa_size);
}else{
/* need more space */
dfa_size=2*(dfa_allocated+1);
dfa_array=(dfa_node **) realloc(dfa_array,
sizeof(dfa_node*)*dfa_size);
}
}
/* fill out entry in array */
t = (dfa_node*) malloc(sizeof(nfa_node)+sizeof(int)*class_no);
*t = *dfa_model_node;
for (j=0; j<class_no; ++j)
t->trans[j] = NIL_INDEX;
t->node_no = dfa_allocated;
t->nfa_states = set_dup(nfa_states);
dfa_array[dfa_allocated] = t;
return t;
}
/* past a pointer to the start start of the nfa graph
* nfa_to_dfa convers this graph to dfa. The function returns
* a pointer to the first dfa state.
* NOTE: The function that prints out the table will have to figure out how
* to find the other dfa states given the first dfa_state and the number of dfa
* nodes allocated
*/
dfa_node **
#ifdef __USE_PROTOS
nfa_to_dfa(nfa_node *start)
#else
nfa_to_dfa(start)
nfa_node *start;
#endif
{
register dfa_node *d_state, *trans_d_state;
register int a;
set t;
int last_done;
unsigned *nfa_list;
unsigned *reach_list;
reach_list = (unsigned *) malloc((2+nfa_allocated)*sizeof(unsigned));
if (!start) return NULL;
t = set_of(NFA_NO(start));
_set_pdq(t,reach_list);
closure(&t,reach_list);
/* Make t a dfa state */
d_state = dfastate(t);
last_done = DFA_NO(d_state);
do {
/* Mark dfa state x as "done" */
d_state->done = TRUE;
nfa_list = set_pdq(d_state->nfa_states);
for (a = 0; a<class_no; ++a) {
/* Add NFA states reached by a from d_state */
reach(nfa_list,a,reach_list);
/* Were any states found? */
if ((*reach_list)!=nil) {
/* was t=empty; */
set_free(t);
/* yes, compute closure */
closure(&t,reach_list);
/* Make DFA state of it ... */
trans_d_state = dfastate(t);
/* And make transition x->t, labeled with a */
d_state->trans[a] = DFA_NO(trans_d_state);
d_state->alternatives = TRUE;
}
}
free(nfa_list);
++last_done; /* move forward in queue */
/* And so forth until nothing isn't done */
d_state = DFA(last_done);
} while (last_done<=dfa_allocated);
free(reach_list);
set_free(t);
/* returns pointer to the array that holds the automaton */
return dfa_array;
}
void
#ifdef __USE_PROTOS
clear_hash(void)
#else
clear_hash()
#endif
{
register int i;
for(i=0; i<HASH_SIZE; ++i)
dfa_hash[i] = 0;
}
#if HASH_STAT
void
#ifdef __USE_PROTOS
fprint_hash_stats(FILE *f)
#else
fprint_hash_stats(f)
FILE *f;
#endif
{
register hash_list *p;
register int i,j;
register total;
total=0;
for(i=0; i<HASH_SIZE; ++i){
j=0;
p = dfa_hash[i];
while(p){
++j;
p = p->next;
}
total+=j;
fprintf(f,"bin[%d] has %d\n",i,j);
}
fprintf(f,"total = %d\n",total);
}
#endif
/* Returns a pointer to a dfa node that has the same nfa nodes in it.
* This may or maynot be a newly created node.
*/
dfa_node *
#ifdef __USE_PROTOS
dfastate(set nfa_states)
#else
dfastate(nfa_states)
set nfa_states;
#endif
{
register hash_list *p;
int bin;
/* hash using set and see if it exists */
bin = set_hash(nfa_states,HASH_SIZE);
p = dfa_hash[bin];
while(p && !set_equ(nfa_states,(p->node)->nfa_states)){
p = p->next;
}
if(!p){
/* next state to add to hash table */
p = (hash_list*)malloc(sizeof(hash_list));
p->node = new_dfa_node(nfa_states);
p->next = dfa_hash[bin];
dfa_hash[bin] = p;
}
return (p->node);
}
/* this reach assumes the closure has been done already on set */
int
#ifdef __USE_PROTOS
reach(unsigned *nfa_list, register int a, unsigned *reach_list)
#else
reach(nfa_list, a, reach_list)
unsigned *nfa_list;
register int a;
unsigned *reach_list;
#endif
{
register unsigned *e;
register nfa_node *node;
int t=0;
e = nfa_list;
if (e){
while (*e != nil){
node = NFA(*e);
if (set_el(a,node->label)){
t=1;
*reach_list=NFA_NO(node->trans[0]);
++reach_list;
}
++e;
}
}
*reach_list=nil;
return t;
}
/* finds all the nodes that can be reached by epsilon transitions
from the set of a nodes and returns puts them back in set b */
set
#ifdef __USE_PROTOS
closure(set *b, unsigned *reach_list)
#else
closure(b, reach_list)
set *b;
unsigned *reach_list;
#endif
{
register nfa_node *node,*n; /* current node being examined */
register unsigned *e;
++operation_no;
#if 0
t = e = set_pdq(*b);
#else
e=reach_list;
#endif
while (*e != nil){
node = NFA(*e);
set_orel(NFA_NO(node),b);
/* mark it done */
node->nfa_set = operation_no;
if ((n=node->trans[0]) != NIL_INDEX && set_nil(node->label) &&
(n->nfa_set != operation_no)){
/* put in b */
set_orel(NFA_NO(n),b);
close1(n,operation_no,b);
}
if ((n=node->trans[1]) != NIL_INDEX &&
(n->nfa_set != operation_no)){
/* put in b */
set_orel(NFA_NO(node->trans[1]),b);
close1(n,operation_no,b);
}
++e;
}
#if 0
free(t);
#endif
return *b;
}
#ifdef __USE_PROTOS
void close1(nfa_node *node, int o, set *b)
#else
void close1(node,o,b)
nfa_node *node;
int o; /* marker to avoid cycles */
set *b;
#endif
{
register nfa_node *n; /* current node being examined */
/* mark it done */
node->nfa_set = o;
if ((n=node->trans[0]) != NIL_INDEX && set_nil(node->label) &&
(n->nfa_set != o)){
/* put in b */
set_orel(NFA_NO(n),b);
close1(n,o,b);
}
if ((n=node->trans[1]) != NIL_INDEX &&
(n->nfa_set != o)){
/* put in b */
set_orel(NFA_NO(node->trans[1]),b);
close1(n,o,b);
}
}

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK Pccts Tool: dlg
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="dlg"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="PACKAGE_DIR" value="${WORKSPACE}/Tools"/>
<target name="init">
<condition property="CheckDepends">
<uptodate targetfile="${WORKSPACE}/Tools/bin/dlg.exe">
<srcfiles dir="." includes="*.c *.h *.g"/>
</uptodate>
</condition>
<if>
<equals arg1="${CheckDepends}" arg2="true"/>
<then>
<echo message="Executable, dlg.exe, is up to date."/>
</then>
<else>
<echo message="Building the EDK Pccts Tool: ${ToolName}"/>
</else>
</if>
</target>
<target name="GenTool" depends="init" unless="CheckDepends">
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="nmake" failonerror="TRUE">
<arg line="-f DlgMS.mak"/>
</exec>
</then>
<elseif>
<istrue value="${cygwin}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="make" failonerror="TRUE">
<arg line="-f makefile.cygwin"/>
</exec>
</then>
</elseif>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="make" failonerror="TRUE">
<arg line="-f makefile BIN_DIR=${BIN_DIR}"/>
</exec>
</then>
</elseif>
</if>
<echo message="The EDK Tool: ${ToolName} build has completed!"/>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="nmake" failonerror="TRUE">
<arg line="-f DlgMS.mak clean"/>
</exec>
</then>
<elseif>
<istrue value="${cygwin}"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="make" failonerror="TRUE">
<arg line="-f makefile.cygwin clean"/>
</exec>
</then>
</elseif>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="make" failonerror="TRUE">
<arg line="-f makefile clean"/>
</exec>
</then>
</elseif>
</if>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="nmake" failonerror="FALSE">
<arg line="-f DlgMS.mak clean"/>
</exec>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<exec dir="${PACKAGE_DIR}/Pccts/dlg" executable="make" failonerror="FALSE">
<arg line="-f makefile clean"/>
</exec>
</then>
</elseif>
</if>
<delete failonerror="false" quiet="true" includeEmptyDirs="true">
<fileset file="${BIN_DIR}/${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,79 @@
.TH dlg 1 "April 1994" "DLG" "PCCTS Manual Pages"
.SH NAME
dlg \- DFA Lexical Analyzer Generator
.SH SYNTAX
.LP
\fBdlg\fR [\fIoptions\fR] \fIlexical_spec\fR [\fIoutput_file\fR]
.SH DESCRIPTION
.B dlg
is a tool that produces fast deterministic finite automata for recognizing
regular expressions in input.
.SH OPTIONS
.IP "\fB-CC\fR"
Generate C++ output. The \fIoutput_file\fP is not specified in this
case.
.IP "\fB-C\fR[\fP level\fR]
Where \fPlevel\fR is the compression level used. 0 indications no
compression, 1 removes all unused characters from the transition from table,
and 2 maps equivalent characters into the same character classes. It is
suggested that level -C2 is used, since it will significantly reduce the size
of the dfa produced for lexical analyzer.
.IP "\fB-m\fP
Produces the header file for the lexical mode with a name other than
the default name of "mode.h".
.IP \fB-i\fP
An interactive, or as interactive as possible, parser is produced. A character
is only obtained when required to decide which state to go to. Some care
must be taken to obtain accept states that do not require look ahead at the
next character to determine if that is the stop state. Any regular expression
with a Kleene closure at the end is guaranteed to require another character
of look ahead.
.IP "\fB-cl\fP class
Specify a class name for DLG to generate. The default is DLGLexer.
'class' will be a subclass of DLGLexerBase; only used for -CC.
.IP \fB-ci\fP
The automaton will treat upper and lower case characters identically.
This is accomplished in the automaton; the characters in the lexical
buffer are unmodified.
.IP \fB-cs\fP
Upper and lower case characters are treated as distinct. This is the
default.
.IP "\fB-o\fP dir
Directory where output files should go (default="."). This is very
nice for keeping the source directory clear of ANTLR and DLG spawn.
.IP \fB-Wambiguity\fP
Warns if more than one regular expression could match the same character
sequence. The warnings give the numbers of the expressions in the dlg
lexical specification file. The numbering of the expressions starts at one.
Multiple warnings may be print for the same expressions.
.IP \-
Used in place of file names to get input from standard in or send output
to standard out.
.SH "SPECIAL CONSIDERATIONS"
.PP
\fIDlg\fP works... we think. There is no implicit guarantee of
anything. We reserve no \fBlegal\fP rights to the software known as
the Purdue Compiler Construction Tool Set (PCCTS) \(em 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
commercial 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. As long as these guidelines are followed, we
expect to continue enhancing this system and expect to make other
tools available as they are completed.
.SH FILES
.B mode.h
,
.B dlgauto.h
,
.B dlgdef.h
.SH SEE ALSO
.BR antlr (1),
.BR pccts (1)
.SH BUGS

View File

@@ -0,0 +1,250 @@
/* dlg header file
*
* 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
*/
/* MR1 Move pcctscfg.h to top of file */
#include "pcctscfg.h"
/* turn off warnings for unreferenced labels */
#ifdef _MSC_VER
#pragma warning(disable:4102)
#endif
#include "set.h"
#define TRUE 1
#define FALSE 0
/***** output related stuff *******************/
#define IN input_stream
#define OUT output_stream
#define MAX_MODES 50 /* number of %%names allowed */
#define MAX_ON_LINE 10
#define NFA_MIN 64 /* minimum nfa_array size */
#define DFA_MIN 64 /* minimum dfa_array size */
#define DEFAULT_CLASSNAME "DLGLexer"
/* these macros allow the size of the character set to be easily changed */
/* NOTE: do NOT change MIN_CHAR since EOF is the lowest char, -1 */
#define MIN_CHAR (-1) /* lowest possible character possible on input */
#define MAX_CHAR 255 /* highest possible character possible on input */
#define CHAR_RANGE (1+(MAX_CHAR) - (MIN_CHAR))
/* indicates that the not an "array" reference */
#define NIL_INDEX 0
/* size of hash table used to find dfa_states quickly */
#define HASH_SIZE 211
#define nfa_node struct _nfa_node
nfa_node {
int node_no;
int nfa_set;
int accept; /* what case to use */
nfa_node *trans[2];
set label; /* one arc always labelled with epsilon */
};
#define dfa_node struct _dfa_node
dfa_node {
int node_no;
int dfa_set;
int alternatives; /* used for interactive mode */
/* are more characters needed */
int done;
set nfa_states;
int trans[1];/* size of transition table depends on
* number of classes required for automata.
*/
};
/******** macros for accessing the NFA and DFA nodes ****/
#define NFA(x) (nfa_array[x])
#define DFA(x) (dfa_array[x])
#define DFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
#define NFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
/******** wrapper for memory checking ***/
/*#define malloc(x) dlg_malloc((x),__FILE__,__LINE__)*/
/*#define calloc(x,y) dlg_calloc((x),(y),__FILE__,__LINE__)*/
/******** antlr attributes *************/
typedef struct {
unsigned char letter;
nfa_node *l,*r;
set label;
} Attrib;
#define zzcr_attr(attr, token, text) { \
(attr)->letter = text[0]; (attr)->l = NULL; \
(attr)->r = NULL; (attr)->label = empty; \
}
#define zzd_attr(a) set_free((a)->label);
/******************** Variable ******************************/
extern char program[]; /* tells what program this is */
extern char version[]; /* tells what version this is */
extern char *file_str[]; /* file names being used */
extern int err_found; /* flag to indicate error occured */
extern int action_no; /* last action function printed */
extern int func_action; /* should actions be turned into functions?*/
extern set used_chars; /* used to label trans. arcs */
extern set used_classes; /* classes or chars used to label trans. arcs */
extern int class_no; /* number of classes used */
extern set class_sets[]; /* shows char. in each class */
extern set normal_chars; /* mask off unused portion of set */
extern int comp_level; /* what compression level to use */
extern int interactive; /* interactive scanner (avoid lookahead)*/
extern int mode_counter; /* keeps track of the number of %%name */
extern int dfa_basep[]; /* start of each group of dfa */
extern int dfa_class_nop[];/* number of transistion arcs in */
/* each dfa in each mode */
extern int nfa_allocated;
extern int dfa_allocated;
extern nfa_node **nfa_array; /* start of nfa "array" */
extern dfa_node **dfa_array; /* start of dfa "array" */
extern int operation_no; /* unique number for each operation */
extern FILE *input_stream; /* where description read from */
extern FILE *output_stream; /* where to put the output */
extern FILE *mode_stream; /* where to put the mode output */
extern FILE *class_stream;
extern char *mode_file; /* name of file for mode output */
extern int gen_ansi; /* produce ansi compatible code */
extern int case_insensitive;/* ignore case of input spec. */
extern int warn_ambig; /* show if regular expressions ambiguous */
extern int gen_cpp;
extern char *cl_file_str;
extern int firstLexMember; /* MR1 */
extern char *OutputDirectory;
extern char *class_name;
/******************** Functions ******************************/
#ifdef __USE_PROTOS
extern char *dlg_malloc(int, char *, int); /* wrapper malloc */
extern char *dlg_calloc(int, int, char *, int); /* wrapper calloc */
extern int reach(unsigned *, register int, unsigned *);
extern set closure(set *, unsigned *);
extern dfa_node *new_dfa_node(set);
extern nfa_node *new_nfa_node(void);
extern dfa_node *dfastate(set);
extern dfa_node **nfa_to_dfa(nfa_node *);
extern void internal_error(char *, char *, int); /* MR9 23-Sep-97 */
extern FILE *read_stream(char *); /* opens file for reading */
extern FILE *write_stream(char *); /* opens file for writing */
extern void make_nfa_model_node(void);
extern void make_dfa_model_node(int);
extern char *ClassName(char *);
extern char *OutMetaName(char *);
extern void error(char*, int);
extern void warning(char*, int);
extern void p_head(void);
extern void p_class_hdr(void);
extern void p_includes(void);
extern void p_tables(void);
extern void p_tail(void); /* MR1 */
extern void p_class_def1(void); /* MR1 */
extern void new_automaton_mode(void); /* MR1 */
extern int relabel(nfa_node *,int); /* MR1 */
extern void p_shift_table(int); /* MR1 */
extern void p_bshift_table(void); /* MR1 */
extern void p_class_table(void); /* MR1 */
extern void p_mode_def(char *,int); /* MR1 */
extern void init(void); /* MR1 */
extern void p_class_def2(void); /* MR1 */
extern void clear_hash(void); /* MR1 */
extern void p_alternative_table(void); /* MR1 */
extern void p_node_table(void); /* MR1 */
extern void p_dfa_table(void); /* MR1 */
extern void p_accept_table(void); /* MR1 */
extern void p_action_table(void); /* MR1 */
extern void p_base_table(void); /* MR1 */
extern void p_single_node(int,int); /* MR1 */
extern char * minsize(int); /* MR1 */
extern void close1(nfa_node *,int,set *); /* MR1 */
extern void partition(nfa_node *,int); /* MR1 */
extern void intersect_nfa_labels(nfa_node *,set *); /* MR1 */
extern void r_intersect(nfa_node *,set *); /* MR1 */
extern void label_node(nfa_node *); /* MR1 */
extern void label_with_classes(nfa_node *); /* MR1 */
#else
extern char *dlg_malloc(); /* wrapper malloc */
extern char *dlg_calloc(); /* wrapper calloc */
extern int reach();
extern set closure();
extern dfa_node *new_dfa_node();
extern nfa_node *new_nfa_node();
extern dfa_node *dfastate();
extern dfa_node **nfa_to_dfa();
extern void internal_error(); /* MR9 23-Sep-97 */
extern FILE *read_stream(); /* opens file for reading */
extern FILE *write_stream(); /* opens file for writing */
extern void make_nfa_model_node();
extern void make_dfa_model_node();
extern char *ClassName();
extern char *OutMetaName();
extern void error();
extern void warning();
extern void p_head(); /* MR9 */
extern void p_class_hdr(); /* MR9 */
extern void p_includes(); /* MR9 */
extern void p_tables(); /* MR9 */
extern void p_tail(); /* MR1 */
extern void p_class_def1(); /* MR1 */
extern void new_automaton_mode(); /* MR1 */
extern int relabel(); /* MR1 */
extern void p_shift_table(); /* MR1 */
extern void p_bshift_table(); /* MR1 */
extern void p_class_table(); /* MR1 */
extern void p_mode_def(); /* MR1 */
extern void init(); /* MR1 */
extern void p_class_def2(); /* MR1 */
extern void clear_hash(); /* MR1 */
extern void p_alternative_table(); /* MR1 */
extern void p_node_table(); /* MR1 */
extern void p_dfa_table(); /* MR1 */
extern void p_accept_table(); /* MR1 */
extern void p_action_table(); /* MR1 */
extern void p_base_table(); /* MR1 */
extern void p_single_node(); /* MR1 */
extern char * minsize(); /* MR1 */
extern void close1(); /* MR1 */
extern void partition(); /* MR1 */
extern void intersect_nfa_labels(); /* MR1 */
extern void r_intersect(); /* MR1 */
extern void label_node(); /* MR1 */
extern void label_with_classes(); /* MR1 */
#endif

View File

@@ -0,0 +1,275 @@
/*
File: dlgMPW.r
Target: dlg 133MR
Created: Monday, June 15, 1998 4:44:11 AM
Author: Kenji Tanaka (kentar@osa.att.ne.jp)
*/
#include "cmdo.r"
resource 'cmdo' (128, "Dlg") {
{ /* array dialogs: 1 elements */
/* [1] */
295,
"DLG -- Purdue Compiler Construction Tool"
" Set (PCCTS) lexical analyzer generator.",
{ /* array itemArray: 18 elements */
/* [1] */
NotDependent {
},
CheckOption {
NotSet,
{35, 175, 50, 225},
"On",
"-CC",
"When this control is checked, DLG genera"
"tes a scanner using C++ classes rather t"
"han C functions."
},
/* [2] */
Or {
{ /* array OrArray: 1 elements */
/* [1] */
1
}
},
RegularEntry {
"Lexer Class Name:",
{35, 225, 50, 355},
{35, 355, 51, 450},
"DLGLexer",
keepCase,
"-cl",
"This entry specifies the name DLG uses f"
"or the C++ lexer class."
},
/* [3] */
NotDependent {
},
TextBox {
gray,
{25, 165, 60, 460},
"C++ Code Generation"
},
/* [4] */
NotDependent {
},
Files {
InputFile,
RequiredFile {
{37, 25, 56, 135},
"Input File",
"",
"Choose the lexical description file for "
"DLG to process."
},
Additional {
"",
"",
"",
"",
{ /* array TypesArray: 1 elements */
/* [1] */
text
}
}
},
/* [5] */
Or {
{ /* array OrArray: 1 elements */
/* [1] */
-1
}
},
Files {
OutputFile,
RequiredFile {
{66, 25, 85, 135},
"Output File",
"",
"Choose the name of the file that will ho"
"ld the DLG-produced scanner."
},
NoMore {
}
},
/* [6] */
Or {
{ /* array OrArray: 2 elements */
/* [1] */
1,
/* [2] */
5
}
},
Dummy {
},
/* [7] */
NotDependent {
},
Redirection {
DiagnosticOutput,
{90, 25}
},
/* [8] */
NotDependent {
},
TextBox {
gray,
{25, 20, 132, 145},
"Files"
},
/* [9] */
NotDependent {
},
Files {
DirOnly,
OptionalFile {
{68, 175, 84, 305},
{88, 175, 107, 305},
"Output Directory",
":",
"-o",
"",
"Choose the directory where DLG will put "
"its output.",
dim,
"Output DirectoryI",
"",
""
},
NoMore {
}
},
/* [10] */
NotDependent {
},
RegularEntry {
"Mode File Name:",
{68, 315, 83, 450},
{88, 315, 104, 450},
"mode.h",
keepCase,
"-m",
"This entry specifies the name DLG uses f"
"or its lexical mode output file."
},
/* [11] */
NotDependent {
},
RadioButtons {
{ /* array radioArray: 3 elements */
/* [1] */
{134, 175, 149, 255}, "None", "", Set, "When this option is selected, DLG will n"
"ot compress its tables.",
/* [2] */
{134, 265, 149, 345}, "Level 1", "-C1", NotSet, "When this option is selected, DLG will r"
"emove all unused characters from the tra"
"nsition-from table.",
/* [3] */
{134, 360, 149, 450}, "Level 2", "-C2", NotSet, "When this option is selected, DLG will p"
"erform level 1 compression plus it will "
"map equivalent characters into the same "
"character classes."
}
},
/* [12] */
NotDependent {
},
TextBox {
gray,
{124, 165, 156, 460},
"Table Compression"
},
/* [13] */
NotDependent {
},
CheckOption {
Set,
{165, 20, 180, 145},
"Case Sensitive",
"-ci",
"When this control is checked, the DLG au"
"tomaton will treat upper and lower case "
"characters identically."
},
/* [14] */
NotDependent {
},
CheckOption {
NotSet,
{165, 150, 180, 300},
"Interactive Scanner",
"-i",
"When this control is checked, DLG will g"
"enerate as interactive a scanner as poss"
"ible."
},
/* [15] */
NotDependent {
},
CheckOption {
NotSet,
{165, 310, 180, 460},
"Ambiguity Warnings",
"-Wambiguity",
"When this control is checked, DLG warns "
"if more than one regular expression coul"
"d match the same character sequence."
},
/* [16] */
NotDependent {
},
VersionDialog {
VersionString {
"1.33MR"
},
"PCCTS was written by Terence Parr, Russe"
"ll Quong, Will Cohen, and Hank Dietz: 19"
"89-1998. MPW port by Scott Haney.",
noDialog
},
/* [17] */
And {
{ /* array AndArray: 2 elements */
/* [1] */
4,
/* [2] */
6
}
},
DoItButton {
},
/* [18] */
NotDependent {
},
CheckOption {
NotSet,
{142, 20, 157, 148},
"Generate ANSI C",
"-ga",
"When this control is checked, DLG genera"
"tes ANSI C compatible code."
}
}
}
};

View File

@@ -0,0 +1,132 @@
dlg(1) PCCTS Manual Pages dlg(1)
NAME
dlg - DFA Lexical Analyzer Generator
SYNTAX
dlg [_o_p_t_i_o_n_s] _l_e_x_i_c_a_l__s_p_e_c [_o_u_t_p_u_t__f_i_l_e]
DESCRIPTION
dlg is a tool that produces fast deterministic finite auto-
mata for recognizing regular expressions in input.
OPTIONS
-CC Generate C++ output. The _o_u_t_p_u_t__f_i_l_e is not specified
in this case.
-C[ level]
Where level is the compression level used. 0 indica-
tions no compression, 1 removes all unused characters
from the transition from table, and 2 maps equivalent
characters into the same character classes. It is sug-
gested that level -C2 is used, since it will signifi-
cantly reduce the size of the dfa produced for lexical
analyzer.
-m Produces the header file for the lexical mode with a
name other than the default name of "mode.h".
-i An interactive, or as interactive as possible, parser
is produced. A character is only obtained when
required to decide which state to go to. Some care
must be taken to obtain accept states that do not
require look ahead at the next character to determine
if that is the stop state. Any regular expression with
a Kleene closure at the end is guaranteed to require
another character of look ahead.
-cl class
Specify a class name for DLG to generate. The default
is DLGLexer.
-ci The automaton will treat upper and lower case charac-
ters identically. This is accomplished in the automa-
ton; the characters in the lexical buffer are unmodi-
fied.
-cs Upper and lower case characters are treated as dis-
tinct. This is the default.
-o dir
Directory where output files should go (default=".").
This is very nice for keeping the source directory
clear of ANTLR and DLG spawn.
-Wambiguity
Warns if more than one regular expression could match
the same character sequence. The warnings give the
numbers of the expressions in the dlg lexical specifi-
cation file. The numbering of the expressions starts
at one. Multiple warnings may be print for the same
expressions.
- Used in place of file names to get input from standard
in or send output to standard out.
SPECIAL CONSIDERATIONS
_D_l_g works... we think. There is no implicit guarantee of
anything. We reserve no legal rights to the software known
as 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 commercial 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 pro-
ject, 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. As long as these
guidelines are followed, we expect to continue enhancing
this system and expect to make other tools available as they
are completed.
FILES
mode.h , dlgauto.h , dlgdef.h
SEE ALSO
antlr(1), pccts(1)
BUGS

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,959 @@
/*
* 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 dlg_p.g -gh
*
*/
#define ANTLR_VERSION 13333
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include <ctype.h>
#include "dlg.h"
#define zzSET_SIZE 8
#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
ANTLR_INFO
/* MR20 G. Hobbelt
Fix for Borland C++ 4.x & 5.x compiling with ALL warnings enabled
*/
#ifdef __TURBOC__
#pragma warn -aus /* unused assignment of 'xxx' */
#endif
int action_no = 0; /* keep track of actions outputed */
int nfa_allocated = 0; /* keeps track of number of nfa nodes */
nfa_node **nfa_array = NULL;/* root of binary tree that stores nfa array */
nfa_node nfa_model_node; /* model to initialize new nodes */
set used_chars; /* used to label trans. arcs */
set used_classes; /* classes or chars used to label trans. arcs */
set normal_chars; /* mask to get rid elements that aren't used
in set */
int flag_paren = FALSE;
int flag_brace = FALSE;
int mode_counter = 0; /* keep track of number of %%names */
void
#ifdef __USE_PROTOS
grammar(void)
#else
grammar()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
p_head(); p_class_hdr(); func_action = FALSE;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (setwd1[LA(1)]&0x1) ) {
{
zzBLOCK(zztasp3);
zzMake0;
{
if ( (LA(1)==LEXACTION) ) {
zzmatch(LEXACTION); zzCONSUME;
}
else {
if ( (LA(1)==LEXMEMBER) ) {
zzmatch(LEXMEMBER); zzCONSUME;
}
else {
if ( (LA(1)==LEXPREFIX) ) {
zzmatch(LEXPREFIX); zzCONSUME;
}
else {
if ( (LA(1)==PARSERCLASS) ) {
zzmatch(PARSERCLASS); zzCONSUME;
}
else {
if ( (LA(1)==ACTION) ) {
}
else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
}
}
}
zzEXIT(zztasp3);
}
}
zzmatch(ACTION); zzCONSUME;
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
if ( gen_cpp ) p_includes();
start_states();
func_action = FALSE; p_tables(); p_tail();
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (LA(1)==ACTION) ) {
zzmatch(ACTION); zzCONSUME;
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
zzmatch(1);
if (firstLexMember != 0) p_class_def1();
zzCONSUME;
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd1, 0x2);
}
}
void
#ifdef __USE_PROTOS
start_states(void)
#else
start_states()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==PER_PER) ) {
zzmatch(PER_PER); zzCONSUME;
do_conversion();
}
else {
if ( (LA(1)==NAME_PER_PER) ) {
zzmatch(NAME_PER_PER); zzCONSUME;
do_conversion();
{
zzBLOCK(zztasp3);
zzMake0;
{
while ( (LA(1)==NAME_PER_PER) ) {
zzmatch(NAME_PER_PER); zzCONSUME;
do_conversion();
zzLOOP(zztasp3);
}
zzEXIT(zztasp3);
}
}
}
else {zzFAIL(1,zzerr2,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
zzmatch(PER_PER); zzCONSUME;
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd1, 0x4);
}
}
void
#ifdef __USE_PROTOS
do_conversion(void)
#else
do_conversion()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
new_automaton_mode(); func_action = TRUE;
rule_list();
dfa_class_nop[mode_counter] =
relabel(zzaArg(zztasp1,1 ).l,comp_level);
if (comp_level)
p_shift_table(mode_counter);
dfa_basep[mode_counter] = dfa_allocated+1;
make_dfa_model_node(dfa_class_nop[mode_counter]);
nfa_to_dfa(zzaArg(zztasp1,1 ).l);
++mode_counter;
func_action = FALSE;
#ifdef HASH_STAT
fprint_hash_stats(stderr);
#endif
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd1, 0x8);
}
}
void
#ifdef __USE_PROTOS
rule_list(void)
#else
rule_list()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
if ( (setwd1[LA(1)]&0x10) ) {
rule();
zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (setwd1[LA(1)]&0x20) ) {
rule();
{nfa_node *t1;
t1 = new_nfa_node();
(t1)->trans[0]=zzaRet.l;
(t1)->trans[1]=zzaArg(zztasp2,1 ).l;
/* all accept nodes "dead ends" */
zzaRet.l=t1; zzaRet.r=NULL;
}
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
}
else {
if ( (setwd1[LA(1)]&0x40) ) {
zzaRet.l = new_nfa_node(); zzaRet.r = NULL;
warning("no regular expressions", zzline);
}
else {zzFAIL(1,zzerr3,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd1, 0x80);
}
}
void
#ifdef __USE_PROTOS
rule(void)
#else
rule()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
if ( (setwd2[LA(1)]&0x1) ) {
reg_expr();
zzmatch(ACTION);
if (zzaArg(zztasp1,1 ).r != NULL) {
zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r; (zzaArg(zztasp1,1 ).r)->accept=action_no;
}
zzCONSUME;
}
else {
if ( (LA(1)==ACTION) ) {
zzmatch(ACTION);
zzaRet.l = NULL; zzaRet.r = NULL;
error("no expression for action ", zzline);
zzCONSUME;
}
else {zzFAIL(1,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd2, 0x2);
}
}
void
#ifdef __USE_PROTOS
reg_expr(void)
#else
reg_expr()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
and_expr();
zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (LA(1)==OR) ) {
zzmatch(OR); zzCONSUME;
and_expr();
{nfa_node *t1, *t2;
t1 = new_nfa_node(); t2 = new_nfa_node();
(t1)->trans[0]=zzaRet.l;
(t1)->trans[1]=zzaArg(zztasp2,2 ).l;
/* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[1]=t2;
if (zzaArg(zztasp2,2 ).r) {
(zzaArg(zztasp2,2 ).r)->trans[1]=t2; /* MR20 */
}
zzaRet.l=t1; zzaRet.r=t2;
}
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd2, 0x4);
}
}
void
#ifdef __USE_PROTOS
and_expr(void)
#else
and_expr()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
repeat_expr();
zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r;
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (setwd2[LA(1)]&0x8) ) {
repeat_expr();
if (zzaRet.r != NULL) {
(zzaRet.r)->trans[1]=zzaArg(zztasp2,1 ).l;
zzaRet.r=zzaArg(zztasp2,1 ).r;
}
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd2, 0x10);
}
}
void
#ifdef __USE_PROTOS
repeat_expr(void)
#else
repeat_expr()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
if ( (setwd2[LA(1)]&0x20) ) {
expr();
zzaRet.l=zzaArg(zztasp1,1 ).l; zzaRet.r=zzaArg(zztasp1,1 ).r;
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==ZERO_MORE) ) {
zzmatch(ZERO_MORE);
{ nfa_node *t1,*t2;
/* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[0] = zzaRet.l;
t1 = new_nfa_node(); t2 = new_nfa_node();
t1->trans[0]=zzaRet.l;
t1->trans[1]=t2;
/* MR23 */ if (zzaRet.r != NULL) (zzaRet.r)->trans[1]=t2;
zzaRet.l=t1;zzaRet.r=t2;
}
zzCONSUME;
}
else {
if ( (LA(1)==ONE_MORE) ) {
zzmatch(ONE_MORE);
if (zzaRet.r != NULL) (zzaRet.r)->trans[0] = zzaRet.l;
zzCONSUME;
}
else {
if ( (setwd2[LA(1)]&0x40) ) {
}
else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
}
zzEXIT(zztasp2);
}
}
}
else {
if ( (LA(1)==ZERO_MORE) ) {
zzmatch(ZERO_MORE);
error("no expression for *", zzline);
zzCONSUME;
}
else {
if ( (LA(1)==ONE_MORE) ) {
zzmatch(ONE_MORE);
error("no expression for +", zzline);
zzCONSUME;
}
else {zzFAIL(1,zzerr6,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd2, 0x80);
}
}
void
#ifdef __USE_PROTOS
expr(void)
#else
expr()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
zzaRet.l = new_nfa_node();
zzaRet.r = new_nfa_node();
if ( (LA(1)==L_BRACK) ) {
zzmatch(L_BRACK); zzCONSUME;
atom_list();
zzmatch(R_BRACK);
/* MR23 */ if (zzaRet.l != NULL) {
(zzaRet.l)->trans[0] = zzaRet.r;
(zzaRet.l)->label = set_dup(zzaArg(zztasp1,2 ).label);
set_orin(&used_chars,(zzaRet.l)->label);
}
zzCONSUME;
}
else {
if ( (LA(1)==NOT) ) {
zzmatch(NOT); zzCONSUME;
zzmatch(L_BRACK); zzCONSUME;
atom_list();
zzmatch(R_BRACK);
/* MR23 */ if (zzaRet.l != NULL) {
(zzaRet.l)->trans[0] = zzaRet.r;
(zzaRet.l)->label = set_dif(normal_chars,zzaArg(zztasp1,3 ).label);
set_orin(&used_chars,(zzaRet.l)->label);
}
zzCONSUME;
}
else {
if ( (LA(1)==L_PAR) ) {
zzmatch(L_PAR); zzCONSUME;
reg_expr();
zzmatch(R_PAR);
/* MR23 */ if (zzaRet.l != NULL) {
(zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l;
if (zzaArg(zztasp1,2 ).r) {
(zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r; /* MR20 */
}
}
zzCONSUME;
}
else {
if ( (LA(1)==L_BRACE) ) {
zzmatch(L_BRACE); zzCONSUME;
reg_expr();
zzmatch(R_BRACE);
/* MR23 */ if (zzaRet.l != NULL) {
(zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l;
(zzaRet.l)->trans[1] = zzaRet.r;
if (zzaArg(zztasp1,2 ).r) {
(zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r; /* MR20 */
}
}
zzCONSUME;
}
else {
if ( (setwd3[LA(1)]&0x1) ) {
atom();
/* MR23 */ if (zzaRet.l != NULL) {
(zzaRet.l)->trans[0] = zzaRet.r;
(zzaRet.l)->label = set_dup(zzaArg(zztasp1,1 ).label);
set_orin(&used_chars,(zzaRet.l)->label);
}
}
else {zzFAIL(1,zzerr7,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
}
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd3, 0x2);
}
}
void
#ifdef __USE_PROTOS
atom_list(void)
#else
atom_list()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
set_free(zzaRet.label);
{
zzBLOCK(zztasp2);
zzMake0;
{
while ( (setwd3[LA(1)]&0x4) ) {
near_atom();
set_orin(&(zzaRet.label),zzaArg(zztasp2,1 ).label);
zzLOOP(zztasp2);
}
zzEXIT(zztasp2);
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd3, 0x8);
}
}
void
#ifdef __USE_PROTOS
near_atom(void)
#else
near_atom()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
register int i;
register int i_prime;
anychar();
zzaRet.letter=zzaArg(zztasp1,1 ).letter; zzaRet.label=set_of(zzaArg(zztasp1,1 ).letter);
i_prime = zzaArg(zztasp1,1 ).letter + MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&(zzaRet.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&(zzaRet.label));
{
zzBLOCK(zztasp2);
zzMake0;
{
if ( (LA(1)==RANGE) ) {
zzmatch(RANGE); zzCONSUME;
anychar();
if (case_insensitive){
i_prime = zzaRet.letter+MIN_CHAR;
zzaRet.letter = (islower(i_prime) ?
toupper(i_prime) : i_prime)-MIN_CHAR;
i_prime = zzaArg(zztasp2,2 ).letter+MIN_CHAR;
zzaArg(zztasp2,2 ).letter = (islower(i_prime) ?
toupper(i_prime) : i_prime)-MIN_CHAR;
}
/* check to see if range okay */
{
int debugLetter1 = zzaRet.letter;
int debugLetter2 = zzaArg(zztasp2,2 ).letter;
}
if (zzaRet.letter > zzaArg(zztasp2,2 ).letter
&& zzaArg(zztasp2,2 ).letter != 0xff){ /* MR16 */
error("invalid range ", zzline);
}
for (i=zzaRet.letter; i<= (int)zzaArg(zztasp2,2 ).letter; ++i){
set_orel(i,&(zzaRet.label));
i_prime = i+MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&(zzaRet.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&(zzaRet.label));
}
}
else {
if ( (setwd3[LA(1)]&0x10) ) {
}
else {zzFAIL(1,zzerr8,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
zzEXIT(zztasp2);
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd3, 0x20);
}
}
void
#ifdef __USE_PROTOS
atom(void)
#else
atom()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
register int i_prime;
anychar();
zzaRet.label = set_of(zzaArg(zztasp1,1 ).letter);
i_prime = zzaArg(zztasp1,1 ).letter + MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&(zzaRet.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&(zzaRet.label));
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd3, 0x40);
}
}
void
#ifdef __USE_PROTOS
anychar(void)
#else
anychar()
#endif
{
zzRULE;
zzBLOCK(zztasp1);
zzMake0;
{
if ( (LA(1)==REGCHAR) ) {
zzmatch(REGCHAR);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==OCTAL_VALUE) ) {
zzmatch(OCTAL_VALUE);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==HEX_VALUE) ) {
zzmatch(HEX_VALUE);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==DEC_VALUE) ) {
zzmatch(DEC_VALUE);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==TAB) ) {
zzmatch(TAB);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==NL) ) {
zzmatch(NL);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==CR) ) {
zzmatch(CR);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==BS) ) {
zzmatch(BS);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==LIT) ) {
zzmatch(LIT);
zzaRet.letter = zzaArg(zztasp1,1 ).letter - MIN_CHAR;
zzCONSUME;
}
else {
if ( (LA(1)==L_EOF) ) {
zzmatch(L_EOF);
zzaRet.letter = 0;
zzCONSUME;
}
else {zzFAIL(1,zzerr9,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
}
}
}
}
}
}
}
}
}
zzEXIT(zztasp1);
return;
fail:
zzEXIT(zztasp1);
/* empty action */
zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
zzresynch(setwd3, 0x80);
}
}
/* adds a new nfa to the binary tree and returns a pointer to it */
nfa_node *
#ifdef __USE_PROTOS
new_nfa_node(void)
#else
new_nfa_node()
#endif
{
register nfa_node *t;
static int nfa_size=0; /* elements nfa_array[] can hold */
++nfa_allocated;
if (nfa_size<=nfa_allocated){
/* need to redo array */
if (!nfa_array){
/* need some to do inital allocation */
nfa_size=nfa_allocated+NFA_MIN;
nfa_array=(nfa_node **) malloc(sizeof(nfa_node*)*
nfa_size);
}else{
/* need more space */
nfa_size=2*(nfa_allocated+1);
nfa_array=(nfa_node **) realloc(nfa_array,
sizeof(nfa_node*)*nfa_size);
}
}
/* fill out entry in array */
t = (nfa_node*) malloc(sizeof(nfa_node));
nfa_array[nfa_allocated] = t;
*t = nfa_model_node;
t->node_no = nfa_allocated;
return t;
}
/* initialize the model node used to fill in newly made nfa_nodes */
void
#ifdef __USE_PROTOS
make_nfa_model_node(void)
#else
make_nfa_model_node()
#endif
{
nfa_model_node.node_no = -1; /* impossible value for real nfa node */
nfa_model_node.nfa_set = 0;
nfa_model_node.accept = 0; /* error state default*/
nfa_model_node.trans[0] = NULL;
nfa_model_node.trans[1] = NULL;
nfa_model_node.label = empty;
}
#if defined(DEBUG) || defined(_DEBUG)
/* print out the pointer value and the node_number */
void
#ifdef __USE_PROTOS
fprint_dfa_pair(FILE *f, nfa_node *p)
#else
fprint_dfa_pair(f, p)
FILE *f;
nfa_node *p;
#endif
{
if (p){
fprintf(f, "%x (%d)", p, p->node_no);
}else{
fprintf(f, "(nil)");
}
}
/* print out interest information on a set */
void
#ifdef __USE_PROTOS
fprint_set(FILE *f, set s)
#else
fprint_set(f,s)
FILE *f;
set s;
#endif
{
unsigned int *x;
fprintf(f, "n = %d,", s.n);
if (s.setword){
fprintf(f, "setword = %x, ", s.setword);
/* print out all the elements in the set */
x = set_pdq(s);
while (*x!=nil){
fprintf(f, "%d ", *x);
++x;
}
}else{
fprintf(f, "setword = (nil)");
}
}
/* code to be able to dump out the nfas
return 0 if okay dump
return 1 if screwed up
*/
int
#ifdef __USE_PROTOS
dump_nfas(int first_node, int last_node)
#else
dump_nfas(first_node, last_node)
int first_node;
int last_node;
#endif
{
register int i;
nfa_node *t;
for (i=first_node; i<=last_node; ++i){
t = NFA(i);
if (!t) break;
fprintf(stderr, "nfa_node %d {\n", t->node_no);
fprintf(stderr, "\n\tnfa_set = %d\n", t->nfa_set);
fprintf(stderr, "\taccept\t=\t%d\n", t->accept);
fprintf(stderr, "\ttrans\t=\t(");
fprint_dfa_pair(stderr, t->trans[0]);
fprintf(stderr, ",");
fprint_dfa_pair(stderr, t->trans[1]);
fprintf(stderr, ")\n");
fprintf(stderr, "\tlabel\t=\t{ ");
fprint_set(stderr, t->label);
fprintf(stderr, "\t}\n");
fprintf(stderr, "}\n\n");
}
return 0;
}
#endif
/* DLG-specific syntax error message generator
* (define USER_ZZSYN when compiling so don't get 2 definitions)
*/
void
#ifdef __USE_PROTOS
zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok, int k, char *bad_text)
#else
zzsyn(text, tok, egroup, eset, etok, k, bad_text)
char *text, *egroup, *bad_text;
int tok;
int etok;
int k;
SetWordType *eset;
#endif
{
fprintf(stderr, ErrHdr, file_str[0]!=NULL?file_str[0]:"stdin", zzline);
fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
if ( k==1 ) fprintf(stderr, " missing");
else
{
fprintf(stderr, "; \"%s\" not", bad_text);
if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
}
if ( zzset_deg(eset)>0 ) zzedecode(eset);
else fprintf(stderr, " %s", zztokens[etok]);
if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
fprintf(stderr, "\n");
}

View File

@@ -0,0 +1,614 @@
/* This is the parser for the dlg
* This is a part of the Purdue Compiler Construction Tool Set
*
* 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-1995
*/
#header <<
#include <ctype.h>
#include "dlg.h"
>>
<<
/* MR20 G. Hobbelt
Fix for Borland C++ 4.x & 5.x compiling with ALL warnings enabled
*/
#ifdef __TURBOC__
#pragma warn -aus /* unused assignment of 'xxx' */
#endif
int action_no = 0; /* keep track of actions outputed */
int nfa_allocated = 0; /* keeps track of number of nfa nodes */
nfa_node **nfa_array = NULL;/* root of binary tree that stores nfa array */
nfa_node nfa_model_node; /* model to initialize new nodes */
set used_chars; /* used to label trans. arcs */
set used_classes; /* classes or chars used to label trans. arcs */
set normal_chars; /* mask to get rid elements that aren't used
in set */
int flag_paren = FALSE;
int flag_brace = FALSE;
int mode_counter = 0; /* keep track of number of %%names */
>>
#lexaction <<
int func_action; /* should actions be turned into functions?*/
int lex_mode_counter = 0; /* keeps track of the number of %%names */
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via <<%%lexmember...>> */
/* MR1 */
int lexMember = 0; /* <<%%lexmemeber ...>> MR1 */
int lexAction = 0; /* <<%%lexaction ...>> MR1 */
int parserClass = 0; /* <<%%parserclass ...>> MR1 */
int lexPrefix = 0; /* <<%%lexprefix ...>> MR1 */
char theClassName[100]; /* MR11 */
char *pClassName=theClassName; /* MR11 */
int firstLexMember=1; /* MR1 */
#ifdef __USE_PROTOS
void xxputc(int c) { /* MR1 */
#else
void xxputc(c) /* MR1 */
int c; /* MR1 */
{ /* MR1 */
#endif
if (parserClass) { /* MR1 */
*pClassName++=c; /* MR1 */
*pClassName=0; /* MR1 */
} else if (lexMember || lexPrefix) { /* MR1 */
if (class_stream != NULL) fputc(c,class_stream); /* MR1 */
} else { /* MR1 */
fputc(c,OUT); /* MR1 */
}; /* MR1 */
} /* MR1 */
#ifdef __USE_PROTOS
void xxprintf(char *format,char *string) { /* MR1 */
#else
void xxprintf(format,string) /* MR1 */
char *format; /* MR1 */
char *string; /* MR1 */
{ /* MR1 */
#endif
if (lexMember || lexPrefix || parserClass) { /* MR1 */
if (class_stream != NULL) /* MR1 */
fprintf(class_stream,format,string); /* MR1 */
} else { /* MR1 */
fprintf(OUT,format,string); /* MR1 */
}; /* MR1 */
} /* MR1 */
>>
#token "[\r\t\ ]+" << zzskip(); >> /* Ignore white */
#token "\n" << zzline++; zzskip(); DAWDLE; >> /* Track Line # */
#token L_EOF "\@"
#token PER_PER "\%\%"
#token NAME_PER_PER "\%\%[a-zA-Z_][a-zA-Z0-9_]*"
<< p_mode_def(&zzlextext[2],lex_mode_counter++); >>
#token LEXMEMBER "\<\<\%\%lexmember" /* MR1 */
<<lexMember=1; /* MR1 */
if (firstLexMember != 0) { /* MR1 */
firstLexMember=0; /* MR1 */
p_class_def1(); /* MR1 */
}; /* MR1 */
zzmode(ACT); /* MR1 */
>> /* MR1 */
#token LEXACTION "\<\<\%\%lexaction" /* MR1 */
<<lexAction=1;zzmode(ACT);>> /* MR1 */
#token PARSERCLASS "\<\<\%\%parserclass" /* MR1 */
<<parserClass=1; /* MR1 */
zzmode(ACT); /* MR1 */
>> /* MR1 */
#token LEXPREFIX "\<\<\%\%lexprefix" /* MR1 */
<<lexPrefix=1;zzmode(ACT);>> /* MR1 */
#token ACTION "\<\<"
<< if (func_action)
fprintf(OUT,"\n%s %sact%d()\n{ ",
gen_cpp?"ANTLRTokenType":"static void",
gen_cpp?ClassName("::"):"", ++action_no);
zzmode(ACT); zzskip();
>>
#token GREAT_GREAT "\>\>"
#token L_BRACE "\{"
#token R_BRACE "\}"
#token L_PAR "\("
#token R_PAR "\)"
#token L_BRACK "\["
#token R_BRACK "\]"
#token ZERO_MORE "\*"
#token ONE_MORE "\+"
#token OR "\|"
#token RANGE "\-"
#token NOT "\~"
#token OCTAL_VALUE "\\0[0-7]*"
<< {int t; sscanf(&zzlextext[1],"%o",&t); zzlextext[0] = t;}>>
#token HEX_VALUE "\\0[Xx][0-9a-fA-F]+"
<< {int t; sscanf(&zzlextext[3],"%x",&t); zzlextext[0] = t;}>>
#token DEC_VALUE "\\[1-9][0-9]*"
<< {int t; sscanf(&zzlextext[1],"%d",&t); zzlextext[0] = t;}>>
#token TAB "\\t" << zzlextext[0] = '\t';>>
#token NL "\\n" << zzlextext[0] = '\n';>>
#token CR "\\r" << zzlextext[0] = '\r';>>
#token BS "\\b" << zzlextext[0] = '\b';>>
/* MR1 */
/* MR1 10-Apr-97 MR1 Allow #token regular expressions to cross lines */
/* MR1 */
#token CONTINUATION "\\ \n" << zzline++; zzskip();>> /* MR1 */
/* NOTE: this takes ANYTHING after the \ */
#token LIT "\\~[tnrb]" << zzlextext[0] = zzlextext[1];>>
/* NOTE: this takes ANYTHING that doesn't match the other tokens */
#token REGCHAR "~[\\]"
grammar : << p_head(); p_class_hdr(); func_action = FALSE;>>
( {LEXACTION | LEXMEMBER | LEXPREFIX | PARSERCLASS } ACTION)* /* MR1 */
<<if ( gen_cpp ) p_includes();>>
start_states
<< func_action = FALSE; p_tables(); p_tail(); >>
(ACTION)* "@"
<< if (firstLexMember != 0) p_class_def1(); >> /* MR1 */
;
start_states : ( PER_PER do_conversion
| NAME_PER_PER do_conversion (NAME_PER_PER do_conversion)*)
PER_PER
;
do_conversion : <<new_automaton_mode(); func_action = TRUE;>>
rule_list
<<
dfa_class_nop[mode_counter] =
relabel($1.l,comp_level);
if (comp_level)
p_shift_table(mode_counter);
dfa_basep[mode_counter] = dfa_allocated+1;
make_dfa_model_node(dfa_class_nop[mode_counter]);
nfa_to_dfa($1.l);
++mode_counter;
func_action = FALSE;
#ifdef HASH_STAT
fprint_hash_stats(stderr);
#endif
>>
;
rule_list : rule <<$$.l=$1.l; $$.r=$1.r;>>
(rule
<<{nfa_node *t1;
t1 = new_nfa_node();
(t1)->trans[0]=$$.l;
(t1)->trans[1]=$1.l;
/* all accept nodes "dead ends" */
$$.l=t1; $$.r=NULL;
}
>>
)*
| /* empty */
<<$$.l = new_nfa_node(); $$.r = NULL;
warning("no regular expressions", zzline);
>>
;
rule : reg_expr ACTION
/* MR23 */ << if ($1.r != NULL) {
$$.l=$1.l; $$.r=$1.r; ($1.r)->accept=action_no;
}
>>
| ACTION
<<$$.l = NULL; $$.r = NULL;
error("no expression for action ", zzline);
>>
;
reg_expr : and_expr <<$$.l=$1.l; $$.r=$1.r;>>
(OR and_expr
<<{nfa_node *t1, *t2;
t1 = new_nfa_node(); t2 = new_nfa_node();
(t1)->trans[0]=$$.l;
(t1)->trans[1]=$2.l;
/* MR23 */ if ($$.r != NULL) ($$.r)->trans[1]=t2;
if ($2.r) {
($2.r)->trans[1]=t2; /* MR20 */
}
$$.l=t1; $$.r=t2;
}
>>
)*
;
and_expr : repeat_expr
<<
$$.l=$1.l; $$.r=$1.r;
>>
(repeat_expr
/* MR23 */ << if ($$.r != NULL) {
($$.r)->trans[1]=$1.l;
$$.r=$1.r;
}
>>
)*
;
repeat_expr : expr <<$$.l=$1.l; $$.r=$1.r;>>
{ ZERO_MORE
<<{ nfa_node *t1,*t2;
/* MR23 */ if ($$.r != NULL) ($$.r)->trans[0] = $$.l;
t1 = new_nfa_node(); t2 = new_nfa_node();
t1->trans[0]=$$.l;
t1->trans[1]=t2;
/* MR23 */ if ($$.r != NULL) ($$.r)->trans[1]=t2;
$$.l=t1;$$.r=t2;
}
>>
| ONE_MORE
/* MR23 */ <<if ($$.r != NULL) ($$.r)->trans[0] = $$.l;>>
}
| ZERO_MORE
<< error("no expression for *", zzline);>>
| ONE_MORE
<< error("no expression for +", zzline);>>
;
expr : << $$.l = new_nfa_node();
$$.r = new_nfa_node();
>>
L_BRACK atom_list R_BRACK
<<
/* MR23 */ if ($$.l != NULL) {
($$.l)->trans[0] = $$.r;
($$.l)->label = set_dup($2.label);
set_orin(&used_chars,($$.l)->label);
}
>>
| NOT L_BRACK atom_list R_BRACK
<<
/* MR23 */ if ($$.l != NULL) {
($$.l)->trans[0] = $$.r;
($$.l)->label = set_dif(normal_chars,$3.label);
set_orin(&used_chars,($$.l)->label);
}
>>
| L_PAR reg_expr R_PAR
<<
/* MR23 */ if ($$.l != NULL) {
($$.l)->trans[0] = $2.l;
if ($2.r) {
($2.r)->trans[1] = $$.r; /* MR20 */
}
}
>>
| L_BRACE reg_expr R_BRACE
<<
/* MR23 */ if ($$.l != NULL) {
($$.l)->trans[0] = $2.l;
($$.l)->trans[1] = $$.r;
if ($2.r) {
($2.r)->trans[1] = $$.r; /* MR20 */
}
}
>>
| atom
<<
/* MR23 */ if ($$.l != NULL) {
($$.l)->trans[0] = $$.r;
($$.l)->label = set_dup($1.label);
set_orin(&used_chars,($$.l)->label);
}
>>
;
atom_list : << set_free($$.label); >>
(near_atom <<set_orin(&($$.label),$1.label);>>)*
;
near_atom : << register int i;
register int i_prime;
>>
anychar
<<$$.letter=$1.letter; $$.label=set_of($1.letter);
i_prime = $1.letter + MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&($$.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&($$.label));
>>
{ RANGE anychar
<< if (case_insensitive){
i_prime = $$.letter+MIN_CHAR;
$$.letter = (islower(i_prime) ?
toupper(i_prime) : i_prime)-MIN_CHAR;
i_prime = $2.letter+MIN_CHAR;
$2.letter = (islower(i_prime) ?
toupper(i_prime) : i_prime)-MIN_CHAR;
}
/* check to see if range okay */
{
int debugLetter1 = $$.letter;
int debugLetter2 = $2.letter;
}
if ($$.letter > $2.letter
&& $2.letter != 0xff){ /* MR16 */
error("invalid range ", zzline);
}
for (i=$$.letter; i<= (int)$2.letter; ++i){
set_orel(i,&($$.label));
i_prime = i+MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&($$.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&($$.label));
}
>>
}
;
atom : << register int i_prime;>>
anychar
<<$$.label = set_of($1.letter);
i_prime = $1.letter + MIN_CHAR;
if (case_insensitive && islower(i_prime))
set_orel(toupper(i_prime)-MIN_CHAR,
&($$.label));
if (case_insensitive && isupper(i_prime))
set_orel(tolower(i_prime)-MIN_CHAR,
&($$.label));
>>
;
anychar : REGCHAR <<$$.letter = $1.letter - MIN_CHAR;>>
| OCTAL_VALUE <<$$.letter = $1.letter - MIN_CHAR;>>
| HEX_VALUE <<$$.letter = $1.letter - MIN_CHAR;>>
| DEC_VALUE <<$$.letter = $1.letter - MIN_CHAR;>>
| TAB <<$$.letter = $1.letter - MIN_CHAR;>>
| NL <<$$.letter = $1.letter - MIN_CHAR;>>
| CR <<$$.letter = $1.letter - MIN_CHAR;>>
| BS <<$$.letter = $1.letter - MIN_CHAR;>>
| LIT <<$$.letter = $1.letter - MIN_CHAR;>>
/* NOTE: LEX_EOF is ALWAYS shifted to 0 = MIN_CHAR - MIN_CHAR*/
| L_EOF <<$$.letter = 0;>>
;
<</* empty action */>>
#lexclass ACT
#token "@" << error("unterminated action", zzline); zzmode(START); >>
#token ACTION "\>\>"
<< if (func_action) fprintf(OUT,"}\n\n");
zzmode(START);
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via <<%%lexmember ...>> */
/* MR1 This is a consequence of not saving actions */
/* MR1 */
/* MR1 */ parserClass=0;
/* MR1 */ lexPrefix=0;
/* MR1 */ lexAction=0;
/* MR1 */ lexMember=0;
>>
#token "\>" << xxputc(zzlextext[0]); zzskip(); >> /* MR1 */
#token "\\\>" << xxputc('>'); zzskip(); >> /* MR1 */
#token "\\" << xxputc('\\'); zzskip(); >> /* MR1 */
#token "\n" << xxputc(zzlextext[0]); ++zzline; zzskip(); >> /* MR1 */
#token "/\*" << zzmode(ACTION_COMMENTS); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>> /* MR1 */
#token "//" << zzmode(ACTION_CPP_COMMENTS); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>> /* MR1 */
#token "~[]" << xxputc(zzlextext[0]); zzskip(); >> /* MR1 */
/* MR1 */
#lexclass ACTION_COMMENTS /* MR1 */
#token "\*/" << zzmode(ACT); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>> /* MR1 */
#token "[\n\r]" << zzline++; xxputc(zzlextext[0]); zzskip();>> /* MR1 */
#token "~[]" << xxputc(zzlextext[0]); zzskip();>> /* MR1 */
/* MR1 */
#lexclass ACTION_CPP_COMMENTS /* MR1 */
#token "[\n\r]" << zzmode(ACT); zzline++; /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>> /* MR1 */
#token "~[]" << xxputc(zzlextext[0]); zzskip();>> /* MR1 */
<<
/* adds a new nfa to the binary tree and returns a pointer to it */
nfa_node *
#ifdef __USE_PROTOS
new_nfa_node(void)
#else
new_nfa_node()
#endif
{
register nfa_node *t;
static int nfa_size=0; /* elements nfa_array[] can hold */
++nfa_allocated;
if (nfa_size<=nfa_allocated){
/* need to redo array */
if (!nfa_array){
/* need some to do inital allocation */
nfa_size=nfa_allocated+NFA_MIN;
nfa_array=(nfa_node **) malloc(sizeof(nfa_node*)*
nfa_size);
}else{
/* need more space */
nfa_size=2*(nfa_allocated+1);
nfa_array=(nfa_node **) realloc(nfa_array,
sizeof(nfa_node*)*nfa_size);
}
}
/* fill out entry in array */
t = (nfa_node*) malloc(sizeof(nfa_node));
nfa_array[nfa_allocated] = t;
*t = nfa_model_node;
t->node_no = nfa_allocated;
return t;
}
/* initialize the model node used to fill in newly made nfa_nodes */
void
#ifdef __USE_PROTOS
make_nfa_model_node(void)
#else
make_nfa_model_node()
#endif
{
nfa_model_node.node_no = -1; /* impossible value for real nfa node */
nfa_model_node.nfa_set = 0;
nfa_model_node.accept = 0; /* error state default*/
nfa_model_node.trans[0] = NULL;
nfa_model_node.trans[1] = NULL;
nfa_model_node.label = empty;
}
>>
<<
#if defined(DEBUG) || defined(_DEBUG)
/* print out the pointer value and the node_number */
void
#ifdef __USE_PROTOS
fprint_dfa_pair(FILE *f, nfa_node *p)
#else
fprint_dfa_pair(f, p)
FILE *f;
nfa_node *p;
#endif
{
if (p){
fprintf(f, "%x (%d)", p, p->node_no);
}else{
fprintf(f, "(nil)");
}
}
/* print out interest information on a set */
void
#ifdef __USE_PROTOS
fprint_set(FILE *f, set s)
#else
fprint_set(f,s)
FILE *f;
set s;
#endif
{
unsigned int *x;
fprintf(f, "n = %d,", s.n);
if (s.setword){
fprintf(f, "setword = %x, ", s.setword);
/* print out all the elements in the set */
x = set_pdq(s);
while (*x!=nil){
fprintf(f, "%d ", *x);
++x;
}
}else{
fprintf(f, "setword = (nil)");
}
}
/* code to be able to dump out the nfas
return 0 if okay dump
return 1 if screwed up
*/
int
#ifdef __USE_PROTOS
dump_nfas(int first_node, int last_node)
#else
dump_nfas(first_node, last_node)
int first_node;
int last_node;
#endif
{
register int i;
nfa_node *t;
for (i=first_node; i<=last_node; ++i){
t = NFA(i);
if (!t) break;
fprintf(stderr, "nfa_node %d {\n", t->node_no);
fprintf(stderr, "\n\tnfa_set = %d\n", t->nfa_set);
fprintf(stderr, "\taccept\t=\t%d\n", t->accept);
fprintf(stderr, "\ttrans\t=\t(");
fprint_dfa_pair(stderr, t->trans[0]);
fprintf(stderr, ",");
fprint_dfa_pair(stderr, t->trans[1]);
fprintf(stderr, ")\n");
fprintf(stderr, "\tlabel\t=\t{ ");
fprint_set(stderr, t->label);
fprintf(stderr, "\t}\n");
fprintf(stderr, "}\n\n");
}
return 0;
}
#endif
>>
<<
/* DLG-specific syntax error message generator
* (define USER_ZZSYN when compiling so don't get 2 definitions)
*/
void
#ifdef __USE_PROTOS
zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok, int k, char *bad_text)
#else
zzsyn(text, tok, egroup, eset, etok, k, bad_text)
char *text, *egroup, *bad_text;
int tok;
int etok;
int k;
SetWordType *eset;
#endif
{
fprintf(stderr, ErrHdr, file_str[0]!=NULL?file_str[0]:"stdin", zzline);
fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
if ( k==1 ) fprintf(stderr, " missing");
else
{
fprintf(stderr, "; \"%s\" not", bad_text);
if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
}
if ( zzset_deg(eset)>0 ) zzedecode(eset);
else fprintf(stderr, " %s", zztokens[etok]);
if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
fprintf(stderr, "\n");
}
>>

View File

@@ -0,0 +1,99 @@
/*
* A n t l r S e t s / E r r o r F i l e H e a d e r
*
* Generated from: dlg_p.g
*
* Terence Parr, Russell Quong, Will Cohen, and Hank Dietz: 1989-2001
* Parr Research Corporation
* with Purdue University Electrical Engineering
* With AHPCRC, University of Minnesota
* ANTLR Version 1.33MR33
*/
#define ANTLR_VERSION 13333
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include <ctype.h>
#include "dlg.h"
#define zzSET_SIZE 8
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "err.h"
ANTLRChar *zztokens[46]={
/* 00 */ "Invalid",
/* 01 */ "@",
/* 02 */ "[\\r\\t\\ ]+",
/* 03 */ "\\n",
/* 04 */ "L_EOF",
/* 05 */ "PER_PER",
/* 06 */ "NAME_PER_PER",
/* 07 */ "LEXMEMBER",
/* 08 */ "LEXACTION",
/* 09 */ "PARSERCLASS",
/* 10 */ "LEXPREFIX",
/* 11 */ "ACTION",
/* 12 */ "GREAT_GREAT",
/* 13 */ "L_BRACE",
/* 14 */ "R_BRACE",
/* 15 */ "L_PAR",
/* 16 */ "R_PAR",
/* 17 */ "L_BRACK",
/* 18 */ "R_BRACK",
/* 19 */ "ZERO_MORE",
/* 20 */ "ONE_MORE",
/* 21 */ "OR",
/* 22 */ "RANGE",
/* 23 */ "NOT",
/* 24 */ "OCTAL_VALUE",
/* 25 */ "HEX_VALUE",
/* 26 */ "DEC_VALUE",
/* 27 */ "TAB",
/* 28 */ "NL",
/* 29 */ "CR",
/* 30 */ "BS",
/* 31 */ "CONTINUATION",
/* 32 */ "LIT",
/* 33 */ "REGCHAR",
/* 34 */ "\\>",
/* 35 */ "\\\\>",
/* 36 */ "\\",
/* 37 */ "\\n",
/* 38 */ "/\\*",
/* 39 */ "//",
/* 40 */ "~[]",
/* 41 */ "\\*/",
/* 42 */ "[\\n\\r]",
/* 43 */ "~[]",
/* 44 */ "[\\n\\r]",
/* 45 */ "~[]"
};
SetWordType zzerr1[8] = {0x80,0xf,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr2[8] = {0x60,0x0,0x0,0x0, 0x0,0x0,0x0,0x0};
SetWordType zzerr3[8] = {0x70,0xa8,0x9a,0x7f, 0x3,0x0,0x0,0x0};
SetWordType setwd1[46] = {0x0,0x6,0x0,0x0,0x30,0xc8,0xc8,
0x1,0x1,0x1,0x1,0x35,0x0,0x30,0x0,
0x30,0x0,0x30,0x0,0x30,0x30,0x0,0x0,
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
0x0,0x30,0x30,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr4[8] = {0x10,0xa8,0x9a,0x7f, 0x3,0x0,0x0,0x0};
SetWordType zzerr5[8] = {0x10,0xe8,0xbb,0x7f, 0x3,0x0,0x0,0x0};
SetWordType zzerr6[8] = {0x10,0xa0,0x9a,0x7f, 0x3,0x0,0x0,0x0};
SetWordType setwd2[46] = {0x0,0x0,0x0,0x0,0xeb,0x2,0x2,
0x0,0x0,0x0,0x0,0xd6,0x0,0xeb,0xd4,
0xeb,0xd4,0xeb,0x0,0xcb,0xcb,0xd0,0x0,
0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,
0x0,0xeb,0xeb,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0};
SetWordType zzerr7[8] = {0x10,0xa0,0x82,0x7f, 0x3,0x0,0x0,0x0};
SetWordType zzerr8[8] = {0x10,0x0,0x44,0x7f, 0x3,0x0,0x0,0x0};
SetWordType zzerr9[8] = {0x10,0x0,0x0,0x7f, 0x3,0x0,0x0,0x0};
SetWordType setwd3[46] = {0x0,0x0,0x0,0x0,0xf7,0x0,0x0,
0x0,0x0,0x0,0x0,0xc2,0x0,0xc2,0xc2,
0xc2,0xc2,0xc2,0xb8,0xc2,0xc2,0xc2,0x80,
0xc2,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,
0x0,0xf7,0xf7,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0};

View File

@@ -0,0 +1,281 @@
/* Main function for dlg version
*
* 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 "stdpccts.h"
char program[] = "dlg";
char version[] = "1.33MR33"; /* MRXXX */
int numfiles = 0;
char *file_str[2] = {NULL, NULL};
char *mode_file = "mode.h";
char *class_name = DEFAULT_CLASSNAME;
char *OutputDirectory = TopDirectory;
/* Option variables */
int comp_level = 0;
int interactive = FALSE;
int case_insensitive = FALSE;
int warn_ambig = FALSE;
int gen_cpp = FALSE;
#ifdef __USE_PROTOS
static int ci_strequ(char *a,char *b)
#else
static int ci_strequ(a,b)
char *a;
char *b;
#endif
{
for ( ;*a != 0 && *b != 0; a++, b++) {
if (toupper(*a) != toupper(*b)) return 0;
}
return (*a == *b);
}
/* Option List Stuff */
#ifdef __USE_PROTOS
void p_comp0(void) {comp_level = 0;}
void p_comp1(void) {comp_level = 1;}
void p_comp2(void) {comp_level = 2;}
void p_stdio(void) { file_str[numfiles++] = NULL;}
void p_file(char *s) { file_str[numfiles++] = s;}
void p_cl_name(char *s, char *t)
{
if ( gen_cpp ) {
class_name = t;
}
else {
warning("-cl only valid in C++ mode; -cl ignored...",0);
}
}
void p_mode_file(char *s, char *t){mode_file=t;}
void p_outdir(char *s,char *t) {OutputDirectory=t;}
void p_ansi(void) {gen_ansi = TRUE;}
void p_interactive(void) {interactive = TRUE;}
void p_case_s(void) { case_insensitive = FALSE; }
void p_case_i(void) { case_insensitive = TRUE; }
void p_warn_ambig(void) { warn_ambig = TRUE; }
void p_cpp(void) { gen_cpp = TRUE; }
#else
void p_comp0() {comp_level = 0;}
void p_comp1() {comp_level = 1;}
void p_comp2() {comp_level = 2;}
void p_stdio() { file_str[numfiles++] = NULL;}
void p_file(s) char *s; { file_str[numfiles++] = s;}
void p_cl_name(s,t)
char *s, *t;
{
if ( gen_cpp ) {
class_name = t;
}
else {
warning("-cl only valid in C++ mode; -cl ignored...",0);
}
}
void p_mode_file(s,t) char *s,*t;{mode_file=t;}
void p_outdir(s,t) char *s,*t;{OutputDirectory=t;}
void p_ansi() {gen_ansi = TRUE;}
void p_interactive() {interactive = TRUE;}
void p_case_s() { case_insensitive = FALSE; }
void p_case_i() { case_insensitive = TRUE; }
void p_warn_ambig() { warn_ambig = TRUE; }
void p_cpp() { gen_cpp = TRUE; }
#endif
#ifdef __cplusplus
typedef void (*WildFunc)(...);
#else
typedef void (*WildFunc)();
#endif
typedef struct {
char *option;
int arg;
WildFunc process;
char *descr;
} Opt;
Opt options[] = {
{ "-CC", 0, (WildFunc)p_cpp, "Generate C++ output" },
{ "-C0", 0, (WildFunc)p_comp0, "No compression (default)" },
{ "-C1", 0, (WildFunc)p_comp1, "Compression level 1" },
{ "-C2", 0, (WildFunc)p_comp2, "Compression level 2" },
{ "-ga", 0, (WildFunc)p_ansi, "Generate ansi C"},
{ "-Wambiguity", 0, (WildFunc)p_warn_ambig, "Warn if expressions ambiguous"},
{ "-m", 1, (WildFunc)p_mode_file, "Rename lexical mode output file"},
{ "-i", 0, (WildFunc)p_interactive, "Build interactive scanner (not valid for C++ mode)"},
{ "-ci", 0, (WildFunc)p_case_i, "Make lexical analyzer case insensitive"},
{ "-cl", 1, (WildFunc)p_cl_name, "Rename lexer class (DLGLexer); only used for -CC"},
{ "-cs", 0, (WildFunc)p_case_s, "Make lexical analyzer case sensitive (default)"},
{ "-o", 1, (WildFunc)p_outdir, OutputDirectoryOption},
{ "-", 0, (WildFunc)p_stdio, "Use standard i/o rather than file"},
{ "*", 0, (WildFunc)p_file, ""}, /* anything else is a file */
{ NULL, 0, NULL }
};
#ifdef __USE_PROTOS
void ProcessArgs(int argc, char **argv, Opt *options)
#else
void ProcessArgs(argc, argv, options)
int argc;
char **argv;
Opt *options;
#endif
{
Opt *p;
while ( argc-- > 0 )
{
p = options;
while ( p->option != NULL )
{
if ( strcmp(p->option, "*") == 0 ||
ci_strequ(p->option,*argv) )
{
if ( p->arg )
{
(*p->process)( *argv, *(argv+1) );
argv++;
argc--;
}
else
(*p->process)( *argv );
break;
}
p++;
}
argv++;
}
}
#ifdef __USE_PROTOS
int main(int argc, char *argv[])
#else
int main(argc, argv)
int argc;
char *argv[];
#endif
{
init();
fprintf(stderr, "%s Version %s 1989-2001\n", &(program[0]),
&(version[0]));
if ( argc == 1 )
{
Opt *p = options;
fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);
while ( *(p->option) != '*' )
{
fprintf(stderr, "\t%s %s\t%s\n",
p->option,
(p->arg)?"___":" ",
p->descr);
p++;
}
}else{
ProcessArgs(argc-1, &(argv[1]), options);
if (interactive && gen_cpp) {
fprintf(stderr,"\n");
/*** MR21a This statement is wrong ! ***/
#if 0
*** fprintf(stderr,"Interactive lexer option (\"-i\") has no effect when in C++ mode\n");
*** fprintf(stderr,"because of extra buffering provided by ANTLRTokenBuffer class.\n");
*** fprintf(stderr,"\n");
#endif
}
input_stream = read_stream(file_str[0]);
if (input_stream) {
/* don't overwrite unless input okay */
if ( gen_cpp ) {
output_stream = write_stream(ClassName(CPP_FILE_SUFFIX));
if ( file_str[1]!=NULL ) {
warning("output file implicit in C++ mode; ignored...",0);
}
class_stream = write_stream(ClassName(".h"));
mode_stream = class_stream;
}
else {
output_stream = write_stream(file_str[1]);
mode_stream = write_stream(mode_file);
}
}
/* make sure that error reporting routines in grammar
know what the file really is */
/* make sure that reading and writing somewhere */
if (input_stream && output_stream && mode_stream){
ANTLR(grammar(), input_stream);
}
p_class_def2(); /* MR1 */
}
if ( output_stream!=NULL ) fclose(output_stream);
if ( !gen_cpp && mode_stream!=NULL ) fclose(mode_stream);
if ( class_stream!=NULL ) fclose(class_stream);
exit(PCCTS_EXIT_SUCCESS);
return 0; /* get rid of warning message MR1 */
}
/* initialize all the variables */
void
#ifdef __USE_PROTOS
init(void)
#else
init()
#endif
{
register int i;
#ifdef SPECIAL_INITS
special_inits(); /* MR1 */
#endif
used_chars = empty;
used_classes = empty;
/* make the valid character set */
normal_chars = empty;
/* NOTE: MIN_CHAR is EOF */
/* NOTE: EOF is not quite a valid char, it is special. Skip it*/
for (i = 1; i<CHAR_RANGE; ++i){
set_orel(i,&normal_chars);
}
make_nfa_model_node();
clear_hash();
/* NOTE: need to set this flag before the lexer starts getting */
/* tokens */
func_action = FALSE;
}
/* stuff that needs to be reset when a new automaton is being built */
void
#ifdef __USE_PROTOS
new_automaton_mode(void) /* MR1 */
#else
new_automaton_mode() /* MR1 */
#endif
{
set_free(used_chars);
clear_hash();
}

View File

@@ -0,0 +1,156 @@
#
# Makefile for DLG 1.33
# Terence Parr
# Purdue University, U of MN, Parr Research Corporation
# 1989-1994
#
# Ported to IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
##
## Uncomment the appropriate section to build
##
#
# OS/2 & DOS 16 bit using MSC 6.0
#
#CC=cl
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /AL /Za /W3 -DPC -DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=/NOD:LLIBCE LLIBCEP
#OBJ_EXT = obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# link @<<
#$** /NOI
#$@ /STACK:16384
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# bind $@ c:\os2\doscalls.lib
# copy *.exe ..\bin
#
#
# Borland C++ for DOS
#
#CC=bcc
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -ml -ff- -w- -DPC -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= emu mathl cl
#OBJ_EXT = obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# tlink @&&|
#C0L $**
#$@ /Tde /c
#
#$(LIBS)
#$(DEF_FILE) $(LFLAGS) ;
#|
# copy *.exe ..\bin
#
#
# C-Set/2 for OS/2
#
#CC=icc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /Sa /W3 /DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT=obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# link386 @<<
#$** /NOI
#$@ /STACK:32768
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# copy *.exe ..\bin
#
#
# Borland C++ for OS/2
#
#CC=bcc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -w- -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= c2 os2
#
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# tlink @&&|
#c02 $** -c
#dlg.exe
#
#C2 os2
#
#|
# copy *.exe ..\bin
#
#
# UNIX
#
CC=cc
COPT=-O
ANTLR=${BIN_DIR}/antlr
DLG=${BIN_DIR}/dlg
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536
OBJ_EXT=o
OUT_OBJ = -o
OBJ = dlg_p.o dlg_a.o main.o err.o set.o support.o output.o \
relabel.o automata.o
dlg : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o ${BIN_DIR}/dlg $(OBJ)
SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
relabel.c automata.c
#dlg_p.c parser.dlg err.c tokens.h : dlg_p.g
# $(ANTLR) dlg_p.g
#dlg_a.c mode.h : parser.dlg
# $(DLG) -C2 parser.dlg dlg_a.c
dlg_p.$(OBJ_EXT) : dlg_p.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_p.c
dlg_a.$(OBJ_EXT) : dlg_a.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_a.c
main.$(OBJ_EXT) : main.c dlg.h
$(CC) $(CFLAGS) -c main.c
set.$(OBJ_EXT) : $(SET)/set.c
$(CC) -c $(CFLAGS) $(SET)/set.c
lint:
lint *.c
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core

View File

@@ -0,0 +1,157 @@
#
# Makefile for DLG 1.33
# Terence Parr
# Purdue University, U of MN, Parr Research Corporation
# 1989-1994
#
# Ported to IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
##
## Uncomment the appropriate section to build
##
#
# OS/2 & DOS 16 bit using MSC 6.0
#
#CC=cl
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /AL /Za /W3 -DPC -DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=/NOD:LLIBCE LLIBCEP
#OBJ_EXT = obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# link @<<
#$** /NOI
#$@ /STACK:16384
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# bind $@ c:\os2\doscalls.lib
# copy *.exe ..\bin
#
#
# Borland C++ for DOS
#
#CC=bcc
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -ml -ff- -w- -DPC -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= emu mathl cl
#OBJ_EXT = obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# tlink @&&|
#C0L $**
#$@ /Tde /c
#
#$(LIBS)
#$(DEF_FILE) $(LFLAGS) ;
#|
# copy *.exe ..\bin
#
#
# C-Set/2 for OS/2
#
#CC=icc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) /Sa /W3 /DUSER_ZZSYN
#OUT_OBJ = -Fo
#LIBS=
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT=obj
#
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# link386 @<<
#$** /NOI
#$@ /STACK:32768
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#<<
# copy *.exe ..\bin
#
#
# Borland C++ for OS/2
#
#CC=bcc
#CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -w- -DUSER_ZZSYN
#OUT_OBJ = -o
#LIBS= c2 os2
#
#ANTLR=..\bin\antlr
#DLG=..\bin\dlg
#OBJ_EXT = obj
#dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj \
# output.obj relabel.obj automata.obj
# tlink @&&|
#c02 $** -c
#dlg.exe
#
#C2 os2
#
#|
# copy *.exe ..\bin
#
#
# UNIX
#
BIN_DIR=../../../../bin
CC=cc
COPT=-O
ANTLR=$(BIN_DIR)/antlr.exe
DLG=${BIN_DIR}/dlg.exe
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536
OBJ_EXT=o
OUT_OBJ = -o
OBJ = dlg_p.o dlg_a.o main.o err.o set.o support.o output.o \
relabel.o automata.o
dlg : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o $(BIN_DIR)/dlg.exe $(OBJ)
SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
relabel.c automata.c
#dlg_p.c parser.dlg err.c tokens.h : dlg_p.g
# $(ANTLR) dlg_p.g
#dlg_a.c mode.h : parser.dlg
# $(DLG) -C2 parser.dlg dlg_a.c
dlg_p.$(OBJ_EXT) : dlg_p.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_p.c
dlg_a.$(OBJ_EXT) : dlg_a.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_a.c
main.$(OBJ_EXT) : main.c dlg.h
$(CC) $(CFLAGS) -c main.c
set.$(OBJ_EXT) : $(SET)/set.c
$(CC) -c $(CFLAGS) $(SET)/set.c
lint:
lint *.c
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core

View File

@@ -0,0 +1,63 @@
#
# Makefile for DLG 1.33
# Terence Parr
# Purdue University, U of MN, Parr Research Corporation
# 1989-1994
#
# Ported to IBM C-Set/2 and Microsoft 6.0 by
# Ed Harfmann
# Micro Data Base Systems
# Lafayette, Indiana
#
SET=../support/set
PCCTS_H=../h
##
## Uncomment the appropriate section to build
##
#
# UNIX
#
CC=cc
ANTLR=../bin/antlr
DLG=../bin/dlg
ANSI=-ansi
CFLAGS= -O -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) $(ANSI) -DZZLEXBUFSIZE=32000
OBJ_EXT=o
OUT_OBJ = -o
OBJ = dlg_p.o dlg_a.o main.o err.o set.o support.o output.o \
relabel.o automata.o
dlg : $(OBJ) $(SRC)
$(CC) $(CFLAGS) -o dlg $(OBJ)
mv dlg ../bin
SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
relabel.c automata.c
dlg_p.c parser.dlg err.c tokens.h : dlg_p.g
$(ANTLR) dlg_p.g
dlg_a.c mode.h : parser.dlg
$(DLG) -C2 parser.dlg dlg_a.c
dlg_p.$(OBJ_EXT) : dlg_p.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_p.c
dlg_a.$(OBJ_EXT) : dlg_a.c dlg.h tokens.h mode.h
$(CC) $(CFLAGS) -c dlg_a.c
main.$(OBJ_EXT) : main.c dlg.h
$(CC) $(CFLAGS) -c main.c
set.$(OBJ_EXT) : $(SET)/set.c
$(CC) -c $(CFLAGS) $(SET)/set.c
lint:
lint *.c
#clean up all the intermediate files
clean:
rm -f *.$(OBJ_EXT) core

View File

@@ -0,0 +1,4 @@
#define START 0
#define ACT 1
#define ACTION_COMMENTS 2
#define ACTION_CPP_COMMENTS 3

View File

@@ -0,0 +1,850 @@
/* 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
static char *mode_name[MAX_MODES];
static int mode_number[MAX_MODES];
static int cur_mode=0;
int operation_no = 0; /* used to mark nodes so that infinite loops avoided */
int dfa_basep[MAX_MODES]; /* start of each group of states */
int dfa_class_nop[MAX_MODES]; /* number of elements in each group of states*/
int gen_ansi = FALSE; /* allows ansi code to be generated */
FILE *input_stream; /* where to read description from */
FILE *output_stream; /* where to put the output */
FILE *mode_stream; /* where to put the mode.h stuff */
FILE *class_stream; /* where to put the scan.h stuff (if gen_cpp) */
/* NOTE: This section is MACHINE DEPENDENT */
#define DIF_SIZE 4
#if defined(PC) && !defined(PC32)
unsigned long typesize[DIF_SIZE] = { 0x7f, 0x7fff, 0x7ffful, 0x7ffffffful }; /* MR20 */
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
char *typevar[DIF_SIZE] = { t0, t1, t2, t3};
#else
unsigned long typesize[DIF_SIZE] = { 0x7f, 0x7fff, 0x7ffffffful, 0x7ffffffful }; /* MR20 */
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
char *typevar[DIF_SIZE] = { t0, t1, t2, t3};
#endif
/* Added by TJP August 1994 */
/* Take in MyLexer and return MyLexer_h */
static char *
#ifdef __USE_PROTOS
gate_symbol(char *name)
#else
gate_symbol(name)
char *name;
#endif
{
static char buf[100];
sprintf(buf, "%s_h", name);
return buf;
}
/* Added by TJP August 1994 */
static char *
#ifdef __USE_PROTOS
mystrdup(char *s)
#else
mystrdup(s)
char *s;
#endif
{
char *p = (char *)malloc(strlen(s)+1);
strcpy(p, s);
return p;
}
#ifdef __USE_PROTOS
void p_class_hdr(void)
#else
void p_class_hdr()
#endif
{
if ( class_stream == NULL ) return;
fprintf(class_stream, "#ifndef %s\n", gate_symbol(ClassName("")));
fprintf(class_stream, "#define %s\n", gate_symbol(ClassName("")));
fprintf(class_stream, "/*\n");
fprintf(class_stream, " * D L G L e x e r C l a s s D e f i n i t i o n\n");
fprintf(class_stream, " *\n");
fprintf(class_stream, " * Generated from:");
fprintf(class_stream, " %s", file_str[0]);
fprintf(class_stream, "\n");
fprintf(class_stream, " *\n");
fprintf(class_stream, " * 1989-2001 by Will Cohen, Terence Parr, and Hank Dietz\n");
fprintf(class_stream, " * Purdue University Electrical Engineering\n");
fprintf(class_stream, " * DLG Version %s\n", version);
fprintf(class_stream, " */\n\n");
fprintf(class_stream, "\n");
fprintf(class_stream, "#include \"%s\"\n", DLEXERBASE_H);
}
/* 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;
fprintf(class_stream, "\nclass %s : public DLGLexerBase {\n", ClassName(""));
fprintf(class_stream, "public:\n");
}
#ifdef __USE_PROTOS
void p_class_def2(void)
#else
void p_class_def2()
#endif
{
int i, m;
if ( class_stream == NULL ) return;
fprintf(class_stream, "public:\n");
fprintf(class_stream, "\tstatic const int MAX_MODE;\n");
fprintf(class_stream, "\tstatic const int DfaStates;\n");
for (i=0; i<cur_mode; i++) {
fprintf(class_stream, "\tstatic const int %s;\n", mode_name[i]);
}
fprintf(class_stream, "\ttypedef %s DfaState;\n\n", minsize(dfa_allocated));
fprintf(class_stream, "\t%s(DLGInputStream *in,\n",ClassName(""));
fprintf(class_stream, "\t\tunsigned bufsize=2000)\n");
fprintf(class_stream, "\t\t: DLGLexerBase(in, bufsize, %d)\n", interactive);
fprintf(class_stream, "\t{\n");
fprintf(class_stream, "\t;\n");
fprintf(class_stream, "\t}\n");
fprintf(class_stream, "\tvoid mode(int);\n");
fprintf(class_stream, "\tANTLRTokenType nextTokenType(void);\n");
fprintf(class_stream, "\tvoid advance(void);\n");
fprintf(class_stream, "protected:\n");
for (i=1; i<=action_no; ++i) {
fprintf(class_stream, "\tANTLRTokenType act%d();\n", i);
}
for(m=0; m<(mode_counter-1); ++m){
for(i=dfa_basep[m]; i<dfa_basep[m+1]; ++i)
fprintf(class_stream, "\tstatic DfaState st%d[%d];\n", i-1, dfa_class_nop[m]+1);
}
for(i=dfa_basep[m]; i<=dfa_allocated; ++i)
fprintf(class_stream, "\tstatic DfaState st%d[%d];\n", i-1, dfa_class_nop[m]+1);
fprintf(class_stream, "\tstatic DfaState *dfa[%d];\n", dfa_allocated);
fprintf(class_stream, "\tstatic DfaState dfa_base[];\n");
/* fprintf(class_stream, "\tstatic int dfa_base_no[];\n"); */
fprintf(class_stream, "\tstatic unsigned char *b_class_no[];\n");
fprintf(class_stream, "\tstatic DfaState accepts[%d];\n",dfa_allocated+1);
fprintf(class_stream, "\tstatic DLGChar alternatives[%d];\n",dfa_allocated+1);
/* 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) {
fprintf(class_stream, "\tstatic unsigned char shift%d[%d];\n",
m, CHAR_RANGE);
}
if (comp_level)
fprintf(class_stream, "\tint ZZSHIFT(int c) { return b_class_no[automaton][1+c]; }\n");
else
fprintf(class_stream, "\tint ZZSHIFT(int c) { return 1+c; }\n");
/* 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 */ fprintf(class_stream,"//\n");
/* MR1 */ fprintf(class_stream,
/* MR1 */ "// 133MR1 Deprecated feature to allow inclusion of ");
/* MR1 */ fprintf(class_stream,
/* MR1 */ "user-defined code in DLG class header\n");
/* MR1 */ fprintf(class_stream,"//\n");
/* MR1 */
/* MR1 */ fprintf(class_stream,"#ifdef DLGLexerIncludeFile\n");
/* MR1 */ fprintf(class_stream,"#include DLGLexerIncludeFile\n");
/* MR1 */ fprintf(class_stream,"#endif\n");
fprintf(class_stream, "};\n");
fprintf(class_stream, "typedef ANTLRTokenType (%s::*Ptr%sMemberFunc)();\n",
ClassName(""), ClassName(""));
fprintf(class_stream, "#endif\n");
}
/* generate required header on output */
#ifdef __USE_PROTOS
void p_head(void)
#else
void p_head()
#endif
{
fprintf(OUT, "/*\n");
fprintf(OUT, " * D L G tables\n");
fprintf(OUT, " *\n");
fprintf(OUT, " * Generated from:");
fprintf(OUT, " %s", file_str[0]);
fprintf(OUT, "\n");
fprintf(OUT, " *\n");
fprintf(OUT, " * 1989-2001 by Will Cohen, Terence Parr, and Hank Dietz\n");
fprintf(OUT, " * Purdue University Electrical Engineering\n");
fprintf(OUT, " * DLG Version %s\n", version);
fprintf(OUT, " */\n\n");
if ( gen_cpp) fprintf(OUT, "#include \"pcctscfg.h\"\n");
if ( gen_cpp ) fprintf(OUT, "#include \"pccts_stdio.h\"\n");
if ( !gen_cpp ) fprintf(OUT, "#include \"%s\"\n\n", mode_file);
fprintf(OUT,"\n");
}
#ifdef __USE_PROTOS
void p_includes(void)
#else
void p_includes()
#endif
{
fprintf(OUT, "#include \"%s\"\n", APARSER_H);
fprintf(OUT, "#include \"%s\"\n", DLEXERBASE_H);
fprintf(OUT, "#include \"%s\"\n", ClassName(".h"));
}
/* 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 ) {
if ( strcmp(ClassName(""), DEFAULT_CLASSNAME)!=0 )
fprintf(OUT, "#define DLGLexer %s\n", ClassName(""));
fprintf(OUT, "#include \"%s\"\n", DLEXER_H); /* MR23 Rename DLexer.cpp to DLexer.h */
return;
}
fprintf(OUT, "\n");
fprintf(OUT, "\n");
if (comp_level)
fprintf(OUT, "#define ZZSHIFT(c) (b_class_no[zzauto][1+c])\n");
else
fprintf(OUT, "#define ZZSHIFT(c) (1+c)\n");
if ( !gen_cpp ) fprintf(OUT, "#define MAX_MODE %d\n",mode_counter);
fprintf(OUT, "#include \"dlgauto.h\"\n");
}
/* output the table of DFA for general use */
#ifdef __USE_PROTOS
void p_tables()
#else
void p_tables()
#endif
{
if ( !gen_cpp ) {
fprintf(OUT, "#define DfaStates\t%d\n", dfa_allocated);
fprintf(OUT, "typedef %s DfaState;\n\n", minsize(dfa_allocated));
}
if ( gen_cpp ) {
int i;
fprintf(OUT, "\n");
fprintf(OUT, "const int %s::MAX_MODE=%d;\n",
ClassName(""),
mode_counter);
fprintf(OUT, "const int %s::DfaStates=%d;\n",
ClassName(""),
dfa_allocated);
for (i=0; i<cur_mode; i++) {
fprintf(OUT, "const int %s::%s=%d;\n",
ClassName(""), mode_name[i], mode_number[i]);
}
fprintf(OUT, "\n");
}
p_node_table();
p_dfa_table();
p_accept_table();
p_action_table();
p_base_table();
p_class_table();
if (comp_level)
p_bshift_table();
if (interactive || gen_cpp )
p_alternative_table();
}
/* figures out the smallest variable type that will hold the transitions
*/
#ifdef __USE_PROTOS
char *minsize(int elements)
#else
char *minsize(elements)
int elements;
#endif
{
int i = 0;
while ((unsigned long) elements > typesize[i]) /* MR20 */
++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){
for(i=dfa_basep[m]; i<dfa_basep[m+1]; ++i)
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 */
fprintf(OUT, "%sDfaState %sst%d[%d] = {\n ",
gen_cpp?ClassName("::"):"static ",
gen_cpp?ClassName("::"):"",(i-1), (classes+1));
#else
fprintf(OUT, "static DfaState st%d[%d] = {\n ", (i-1), classes);
#endif
items_on_line = MAX_ON_LINE;
for(j=0; j<classes; ++j){
DAWDLE;
trans = DFA(i)->trans[j];
if (trans == NIL_INDEX)
trans = dfa_allocated+1;
/* all of DFA moved down one in array */
fprintf(OUT, "%d", trans-1);
fprintf(OUT, ", ");
if (!(--items_on_line)){
fprintf(OUT, "\n ");
items_on_line = MAX_ON_LINE;
}
}
#if 1
/* put in jump to error state */
fprintf(OUT, "%d\n};\n\n", dfa_allocated);
#else
fprintf(OUT, "\n};\n\n");
#endif
}
#ifdef __USE_PROTOS
void p_dfa_table(void)
#else
void p_dfa_table()
#endif
{
register int i;
fprintf(OUT, "\n%sDfaState *%sdfa[%d] = {\n",
gen_cpp?ClassName("::"):"",gen_cpp?ClassName("::"):"", dfa_allocated);
for (i=0; i<(dfa_allocated-1); ++i){
fprintf(OUT, "\tst%d,\n", i);
}
fprintf(OUT, "\tst%d\n", i);
fprintf(OUT, "};\n\n");
}
#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 */
fprintf(OUT,"\n%sDfaState %saccepts[%d] = {\n ",
gen_cpp?ClassName("::"):"",
gen_cpp?ClassName("::"):"",
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) */
set accept_set;
set nfa_states;
unsigned int *t, *nfa_i;
unsigned int *q, *regular_expr;
accept_set = empty;
nfa_states = DFA(i)->nfa_states;
t = nfa_i = set_pdq(nfa_states);
/* NOTE: picks lowest accept because accepts monotonic */
/* with respect to nfa node numbers and set_pdq */
/* returns in that order */
while((*nfa_i != nil) && (!(accept = NFA(*nfa_i)->accept))){
nfa_i++;
}
/* figure out if more than one accept state there */
if (warn_ambig ){
set_orel(accept, &accept_set);
while(*nfa_i != nil){
set_orel(NFA(*nfa_i)->accept, &accept_set);
nfa_i++;
}
/* remove error action from consideration */
set_rm(0, accept_set);
if( set_deg(accept_set)>1){
fprintf(stderr, "dlg warning: ambiguous regular expression ");
q = regular_expr = set_pdq(accept_set);
while(*regular_expr != nil){
fprintf(stderr," %d ", *regular_expr);
++regular_expr;
}
fprintf(stderr, "\n");
free(q);
}
}
if ((DFA(i)->alternatives) && (accept != 0)){
true_interactive = FALSE;
}
fprintf(OUT, "%d, ", accept);
/* free up memory before we "break" below -ATG 4/6/95 */
free(t);
set_free(accept_set);
if ((++i)>dfa_allocated)
break;
if ((++items_on_line)>=MAX_ON_LINE){
fprintf(OUT,"\n ");
items_on_line = 0;
}
/*
free(t);
set_free(accept_set);
*/
}
/* make sure element for one past (zzerraction) -WEC 12/16/92 */
skip_accepts:
fprintf(OUT, "0\n};\n\n");
}
#ifdef __USE_PROTOS
void p_action_table(void)
#else
void p_action_table()
#endif
{
register int i;
char* theClassName = ClassName("");
if ( gen_cpp )
fprintf(OUT, "Ptr%sMemberFunc %s::actions[%d] = {\n", theClassName,
theClassName, action_no+1);
else
fprintf(OUT, "void (*actions[%d])() = {\n", action_no+1);
if ( gen_cpp )
/* fprintf(OUT, "\t(Ptr%sMemberFunc)&%s::erraction,\n", theClassName, theClassName);*/
fprintf(OUT, "\t&%s::erraction,\n", theClassName);
else
fprintf(OUT, "\tzzerraction,\n");
for (i=1; i<action_no; ++i) {
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d,\n", theClassName, theClassName, i);*/
fprintf(OUT,"\t&%s::act%d,\n", theClassName, i);
else
fprintf(OUT,"\tact%d,\n", i);
DAWDLE;
}
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d\n", theClassName, theClassName, i);*/
fprintf(OUT,"\t&%s::act%d\n", theClassName, i);
else
fprintf(OUT,"\tact%d\n", i);
fprintf(OUT, "};\n\n");
}
#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;
fprintf(OUT, "%s unsigned char %sshift%d[%d] = {\n ",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"", m, CHAR_RANGE);
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;
}
fprintf(OUT,"%d",j);
if ((++i)>=CHAR_RANGE)
break;
fprintf(OUT,", ");
if ((++items_on_line)>=MAX_ON_LINE){
fprintf(OUT,"\n ");
items_on_line = 0;
}
}
fprintf(OUT, "\n};\n\n");
}
#ifdef __USE_PROTOS
void p_base_table(void)
#else
void p_base_table()
#endif
{
register int m;
fprintf(OUT, "%sDfaState %sdfa_base[] = {\n",
gen_cpp?ClassName("::"):"static ",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT, "\t%d,\n", dfa_basep[m]-1);
fprintf(OUT, "\t%d\n};\n\n", dfa_basep[m]-1);
}
#ifdef __USE_PROTOS
void p_class_table(void) /* MR1 */
#else
void p_class_table() /* MR1 */
#endif
{
#if 0
register int m;
fprintf(OUT,"%s int %sdfa_class_no[] = {\n",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT,"\t%d,\n", dfa_class_nop[m]);
fprintf(OUT,"\t%d\n};\n\n", dfa_class_nop[m]);
#endif
}
#ifdef __USE_PROTOS
void p_bshift_table(void) /* MR1 */
#else
void p_bshift_table() /* MR1 */
#endif
{
register int m;
fprintf(OUT,"%s unsigned char *%sb_class_no[] = {\n",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT, "\tshift%d,\n", m);
fprintf(OUT, "\tshift%d\n};\n\n", m);
}
#ifdef __USE_PROTOS
void p_alternative_table(void) /* MR1 */
#else
void p_alternative_table() /* MR1 */
#endif
{
register int i;
if ( !gen_cpp ) fprintf(OUT, "#define ZZINTERACTIVE\n\n");
if ( gen_cpp )
fprintf(OUT, "DLGChar %salternatives[%d] = {\n", /* mr23 vhs %sDfaStates+1 */
ClassName("::"),
dfa_allocated+1); /* vhs ClassName("::")); */
else
fprintf(OUT, "static %s zzalternatives[DfaStates+1] = {\n",
minsize(dfa_allocated));
for(i=1; i<=dfa_allocated; ++i)
fprintf(OUT, "\t%d,\n", DFA(i)->alternatives);
fprintf(OUT, "/* must have 0 for zzalternatives[DfaStates] */\n");
fprintf(OUT, "\t0\n};\n\n");
}
#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_name[cur_mode] = mystrdup(s);
mode_number[cur_mode] = m;
cur_mode++;
}
else
fprintf(mode_stream, "#define %s %d\n", s, m);
}
#ifdef __USE_PROTOS
char * ClassName(char *suffix)
#else
char * ClassName(suffix)
char *suffix;
#endif
{
static char buf[200];
extern char *class_name;
sprintf(buf, "%s%s", class_name, suffix);
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
{
register nfa_node *t;
if (p != NIL_INDEX){
printf("NFA state : %d\naccept state : %d\n",
NFA_NO(p),p->accept);
if (p->trans[0] != NIL_INDEX){
printf("trans[0] => %d on ", NFA_NO(p->trans[0]));
p_set(p->label);
printf("\n");
}
else
printf("trans[0] => nil\n");
if (p->trans[1] != NIL_INDEX)
printf("trans[1] => %d on epsilon\n",
NFA_NO(p->trans[1]));
else
printf("trans[1] => nil\n");
printf("\n");
}
}
#endif
#ifdef DEBUG
/* code to print out special structures when using a debugger */
#ifdef __USE_PROTOS
void p_nfa(p)
#else
void p_nfa(nfa_node *p)
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
void s_p_nfa(nfa_node *p)
#else
void s_p_nfa(p)
nfa_node *p; /* state number also index into array */
#endif
{
if ((p != NIL_INDEX) && (p->nfa_set != operation_no)){
/* so it is only printed once */
p->nfa_set = operation_no;
p_nfa_node(p);
s_p_nfa(p->trans[0]);
s_p_nfa(p->trans[1]);
}
}
#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){
printf("DFA state :%d\n",NFA_NO(p));
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("%d ",p->trans[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++)
p_dfa_node(NFA(i));
}
/* print out numbers in the set label */
#ifdef __USE_PROTOS
void p_set(set label)
#else
void p_set(label)
set label;
#endif
{
unsigned *t, *e;
if (set_nil(label)){
printf("epsilon\n");
}else{
t = e = set_pdq(label);
while(*e != nil){
printf("%d ", (*e+MIN_CHAR));
e++;
}
printf("\n");
free(t);
}
}
#endif

View File

@@ -0,0 +1,398 @@
<<
/* parser.dlg -- DLG Description of scanner
*
* Generated from: dlg_p.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"
#include <ctype.h>
#include "dlg.h"
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
LOOKAHEAD
void
#ifdef __USE_PROTOS
zzerraction(void)
#else
zzerraction()
#endif
{
(*zzerr)("invalid token");
zzadvance();
zzskip();
}
>>
<<%%lexaction
int func_action; /* should actions be turned into functions?*/
int lex_mode_counter = 0; /* keeps track of the number of %%names */
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via <<%%lexmember...>> */
/* MR1 */
int lexMember = 0; /* <<%%lexmemeber ...>> MR1 */
int lexAction = 0; /* <<%%lexaction ...>> MR1 */
int parserClass = 0; /* <<%%parserclass ...>> MR1 */
int lexPrefix = 0; /* <<%%lexprefix ...>> MR1 */
char theClassName[100]; /* MR11 */
char *pClassName=theClassName; /* MR11 */
int firstLexMember=1; /* MR1 */
#ifdef __USE_PROTOS
void xxputc(int c) { /* MR1 */
#else
void xxputc(c) /* MR1 */
int c; /* MR1 */
{ /* MR1 */
#endif
if (parserClass) { /* MR1 */
*pClassName++=c; /* MR1 */
*pClassName=0; /* MR1 */
} else if (lexMember || lexPrefix) { /* MR1 */
if (class_stream != NULL) fputc(c,class_stream); /* MR1 */
} else { /* MR1 */
fputc(c,OUT); /* MR1 */
}; /* MR1 */
} /* MR1 */
#ifdef __USE_PROTOS
void xxprintf(char *format,char *string) { /* MR1 */
#else
void xxprintf(format,string) /* MR1 */
char *format; /* MR1 */
char *string; /* MR1 */
{ /* MR1 */
#endif
if (lexMember || lexPrefix || parserClass) { /* MR1 */
if (class_stream != NULL) /* MR1 */
fprintf(class_stream,format,string); /* MR1 */
} else { /* MR1 */
fprintf(OUT,format,string); /* MR1 */
}; /* MR1 */
} /* MR1 */
>>
%%START
@
<<
NLA = 1;
>>
[\r\t\ ]+
<<
NLA = 2;
zzskip();
>>
\n
<<
NLA = 3;
zzline++; zzskip(); DAWDLE;
>>
\@
<<
NLA = L_EOF;
>>
\%\%
<<
NLA = PER_PER;
>>
\%\%[a-zA-Z_][a-zA-Z0-9_]*
<<
NLA = NAME_PER_PER;
p_mode_def(&zzlextext[2],lex_mode_counter++);
>>
\<\<\%\%lexmember
<<
NLA = LEXMEMBER;
lexMember=1; /* MR1 */
if (firstLexMember != 0) { /* MR1 */
firstLexMember=0; /* MR1 */
p_class_def1(); /* MR1 */
}; /* MR1 */
zzmode(ACT); /* MR1 */
>>
\<\<\%\%lexaction
<<
NLA = LEXACTION;
lexAction=1;zzmode(ACT);
>>
\<\<\%\%parserclass
<<
NLA = PARSERCLASS;
parserClass=1; /* MR1 */
zzmode(ACT); /* MR1 */
>>
\<\<\%\%lexprefix
<<
NLA = LEXPREFIX;
lexPrefix=1;zzmode(ACT);
>>
\<\<
<<
NLA = ACTION;
if (func_action)
fprintf(OUT,"\n%s %sact%d()\n{ ",
gen_cpp?"ANTLRTokenType":"static void",
gen_cpp?ClassName("::"):"", ++action_no);
zzmode(ACT); zzskip();
>>
\>\>
<<
NLA = GREAT_GREAT;
>>
\{
<<
NLA = L_BRACE;
>>
\}
<<
NLA = R_BRACE;
>>
\(
<<
NLA = L_PAR;
>>
\)
<<
NLA = R_PAR;
>>
\[
<<
NLA = L_BRACK;
>>
\]
<<
NLA = R_BRACK;
>>
\*
<<
NLA = ZERO_MORE;
>>
\+
<<
NLA = ONE_MORE;
>>
\|
<<
NLA = OR;
>>
\-
<<
NLA = RANGE;
>>
\~
<<
NLA = NOT;
>>
\\0[0-7]*
<<
NLA = OCTAL_VALUE;
{int t; sscanf(&zzlextext[1],"%o",&t); zzlextext[0] = t;}
>>
\\0[Xx][0-9a-fA-F]+
<<
NLA = HEX_VALUE;
{int t; sscanf(&zzlextext[3],"%x",&t); zzlextext[0] = t;}
>>
\\[1-9][0-9]*
<<
NLA = DEC_VALUE;
{int t; sscanf(&zzlextext[1],"%d",&t); zzlextext[0] = t;}
>>
\\t
<<
NLA = TAB;
zzlextext[0] = '\t';
>>
\\n
<<
NLA = NL;
zzlextext[0] = '\n';
>>
\\r
<<
NLA = CR;
zzlextext[0] = '\r';
>>
\\b
<<
NLA = BS;
zzlextext[0] = '\b';
>>
\\ \n
<<
NLA = CONTINUATION;
zzline++; zzskip();
>>
\\~[tnrb]
<<
NLA = LIT;
zzlextext[0] = zzlextext[1];
>>
~[\\]
<<
NLA = REGCHAR;
>>
%%ACT
@
<<
NLA = 1;
error("unterminated action", zzline); zzmode(START);
>>
\>\>
<<
NLA = ACTION;
if (func_action) fprintf(OUT,"}\n\n");
zzmode(START);
/* MR1 */
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
/* MR1 via <<%%lexmember ...>> */
/* MR1 This is a consequence of not saving actions */
/* MR1 */
/* MR1 */ parserClass=0;
/* MR1 */ lexPrefix=0;
/* MR1 */ lexAction=0;
/* MR1 */ lexMember=0;
>>
\>
<<
NLA = 34;
xxputc(zzlextext[0]); zzskip();
>>
\\\>
<<
NLA = 35;
xxputc('>'); zzskip();
>>
\\
<<
NLA = 36;
xxputc('\\'); zzskip();
>>
\n
<<
NLA = 37;
xxputc(zzlextext[0]); ++zzline; zzskip();
>>
/\*
<<
NLA = 38;
zzmode(ACTION_COMMENTS); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>>
//
<<
NLA = 39;
zzmode(ACTION_CPP_COMMENTS); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>>
~[]
<<
NLA = 40;
xxputc(zzlextext[0]); zzskip();
>>
%%ACTION_COMMENTS
@
<<
NLA = 1;
>>
\*/
<<
NLA = 41;
zzmode(ACT); /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>>
[\n\r]
<<
NLA = 42;
zzline++; xxputc(zzlextext[0]); zzskip();
>>
~[]
<<
NLA = 43;
xxputc(zzlextext[0]); zzskip();
>>
%%ACTION_CPP_COMMENTS
@
<<
NLA = 1;
>>
[\n\r]
<<
NLA = 44;
zzmode(ACT); zzline++; /* MR1 */
xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */
>>
~[]
<<
NLA = 45;
xxputc(zzlextext[0]); zzskip();
>>
%%

View File

@@ -0,0 +1,217 @@
/* This group of functions does the character class compression.
It goes over the dfa and relabels the arcs with the partitions
of characters in the NFA. The partitions are stored in the
array class.
*
* 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 "dlg.h"
#ifdef MEMCHK
#include "trax.h"
#else
#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif /* __STDC__ */
#endif
int class_no = CHAR_RANGE; /* number of classes for labels */
int first_el[CHAR_RANGE]; /* first element in each class partition */
set class_sets[CHAR_RANGE]; /* array holds partitions from class */
/* compression */
/* goes through labels on NFA graph and partitions the characters into
* character classes. This reduces the amount of space required for each
* dfa node, since only one arc is required each class instead of one arc
* for each character
* level:
* 0 no compression done
* 1 remove unused characters from classes
* 2 compress equivalent characters into same class
*
* returns the number of character classes required
*/
#ifdef __USE_PROTOS
int relabel(nfa_node* start,int level)
#else
int relabel(start,level)
int level;
nfa_node *start;
#endif
{
if (level){
set_free(used_classes);
partition(start,level);
label_with_classes(start);
}else{
/* classes equivalent to all characters in alphabet */
class_no = CHAR_RANGE;
}
return class_no;
}
/* makes character class sets for new labels */
#ifdef __USE_PROTOS
void partition(nfa_node* start,int level)
#else
void partition(start,level)
nfa_node *start; /* beginning of nfa graph */
int level; /* compression level to uses */
#endif
{
set current_class;
set unpart_chars;
set temp;
unpart_chars = set_dup(used_chars);
#if 0
/* EOF (-1+1) alway in class 0 */
class_sets[0] = set_of(0);
first_el[0] = 0;
used_classes = set_of(0);
temp = set_dif(unpart_chars, class_sets[0]);
set_free(unpart_chars);
unpart_chars = temp;
class_no = 1;
#else
class_no = 0;
#endif
while (!set_nil(unpart_chars)){
/* don't look for equivalent labels if c <= 1 */
if (level <= 1){
current_class = set_of(set_int(unpart_chars));
}else{
current_class = set_dup(unpart_chars);
intersect_nfa_labels(start,&current_class);
}
set_orel(class_no,&used_classes);
first_el[class_no] = set_int(current_class);
class_sets[class_no] = current_class;
temp = set_dif(unpart_chars,current_class);
set_free(unpart_chars);
unpart_chars = temp;
++class_no;
}
/* free unpart_chars -ATG 5/6/95 */
set_free(unpart_chars);
#if 0
/* group all the other unused characters into a class */
set_orel(class_no,&used_classes);
first_el[class_no] = set_int(current_class);
class_sets[class_no] = set_dif(normal_chars,used_chars);
++class_no;
#endif
}
/* given pointer to beginning of graph and recursively walks it trying
* to find a maximal partition. This partion in returned in maximal_class
*/
#ifdef __USE_PROTOS
void intersect_nfa_labels(nfa_node* start,set* maximal_class)
#else
void intersect_nfa_labels(start,maximal_class)
nfa_node *start;
set *maximal_class;
#endif
{
/* pick a new operation number */
++operation_no;
r_intersect(start,maximal_class);
}
#ifdef __USE_PROTOS
void r_intersect(nfa_node* start,set* maximal_class)
#else
void r_intersect(start,maximal_class)
nfa_node *start;
set * maximal_class;
#endif
{
set temp;
if(start && start->nfa_set != operation_no)
{
start->nfa_set = operation_no;
temp = set_and(*maximal_class,start->label);
if (!set_nil(temp))
{
set_free(*maximal_class);
*maximal_class = temp;
}else{
set_free(temp);
}
r_intersect(start->trans[0],maximal_class);
r_intersect(start->trans[1],maximal_class);
}
}
/* puts class labels in place of old character labels */
#ifdef __USE_PROTOS
void label_with_classes(nfa_node* start)
#else
void label_with_classes(start)
nfa_node *start;
#endif
{
++operation_no;
label_node(start);
}
#ifdef __USE_PROTOS
void label_node(nfa_node *start)
#else
void label_node(start)
nfa_node *start;
#endif
{
set new_label;
register int i;
/* only do node if it hasn't been done before */
if (start && start->nfa_set != operation_no){
start->nfa_set = operation_no;
new_label = empty;
for (i = 0; i<class_no; ++i){
/* if one element of class in old_label,
all elements are. */
if (set_el(first_el[i],start->label))
set_orel(i,&new_label);
}
set_free(start->label);
start->label = new_label;
/* do any nodes that can be reached from this one */
label_node(start->trans[0]);
label_node(start->trans[1]);
}
}

View File

@@ -0,0 +1,26 @@
#ifndef STDPCCTS_H
#define STDPCCTS_H
/*
* stdpccts.h -- P C C T S I n c l u d e
*
* Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
* Purdue University Electrical Engineering
* With AHPCRC, University of Minnesota
* ANTLR Version 1.33MR33
*/
#ifndef ANTLR_VERSION
#define ANTLR_VERSION 13333
#endif
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include <ctype.h>
#include "dlg.h"
#define zzSET_SIZE 8
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "mode.h"
#endif

View File

@@ -0,0 +1,240 @@
/*
* 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
int err_found = 0; /* indicates whether problem found */
#ifdef __USE_PROTOS
void internal_error(char *s, char *file,int line) /* MR9 23-Sep-97 */
#else
void internal_error(s,file,line) /* MR9 23-Sep-97 */
char *s,*file;
int line;
#endif
{
fprintf(stderr,s,file,line);
exit(PCCTS_EXIT_FAILURE);
}
#ifdef __USE_PROTOS
char *dlg_malloc(int bytes,char *file,int line)
#else
char *dlg_malloc(bytes,file,line)
int bytes;
char *file;
int line;
#endif
{
char *t;
t = (char *) malloc(bytes);
if (!t){
/* error */
internal_error("%s(%d): unable to allocate memory\n",
file,line);
}
return t;
}
#ifdef __USE_PROTOS
char *dlg_calloc(int n,int bytes,char *file,int line)
#else
char *dlg_calloc(n,bytes,file,line)
int n,bytes;
char *file;
int line;
#endif
{
char *t;
t = (char *) calloc(n,bytes);
if (!t){
/* error */
internal_error("%s(%d): unable to allocate memory\n",
file,line);
}
return t;
}
#ifdef __USE_PROTOS
FILE *read_stream(char *name)
#else
FILE *read_stream(name)
char *name;
#endif
{
FILE *f;
if (name){
if (name[0] == '-') {
fprintf(stderr, "dlg: invalid option: '%s'\n", name);
f = NULL;
}else{
f = fopen(name, "r");
if (f == NULL){
/* couldn't open file */
fprintf(stderr,
"dlg: Warning: Can't read file %s.\n",
name);
}
}
}else{
/* open stdin if nothing there */
f = stdin;
}
return f;
}
#ifdef __USE_PROTOS
FILE *write_stream(char *name)
#else
FILE *write_stream(name)
char *name;
#endif
{
FILE *f;
if (name){
if (name[0] == '-') {
fprintf(stderr, "dlg: invalid option: '%s'\n", name);
f = NULL;
}else{
f = fopen(OutMetaName(name), "w");
if (f == NULL){
/* couldn't open file */
fprintf(stderr,
"dlg: Warning: Can't write to file %s.\n",
name);
}
else
#ifdef SPECIAL_FOPEN
special_fopen_actions(OutMetaName(name)); /* MR1 */
#else
; /* MR1 */
#endif
}
}else{
/* open stdout if nothing there */
f = stdout;
}
return f;
}
#ifdef __USE_PROTOS
void fatal(char *message,int line_no)
#else
void fatal(message,line_no)
char *message;
int line_no;
#endif
{
fprintf(stderr,ErrHdr,
(file_str[0] ? file_str[0] : "stdin"), line_no);
fprintf(stderr, " Fatal: %s\n", message);
exit(PCCTS_EXIT_FAILURE);
}
#ifdef __USE_PROTOS
void error(char *message,int line_no)
#else
void error(message,line_no)
char *message;
int line_no;
#endif
{
fprintf(stderr,ErrHdr,
(file_str[0] ? file_str[0] : "stdin"), line_no);
fprintf(stderr, " Error: %s\n", message);
err_found = 1;
}
#ifdef __USE_PROTOS
void warning(char *message,int line_no)
#else
void warning(message,line_no)
char *message;
int line_no;
#endif
{
fprintf(stderr,ErrHdr,
(file_str[0] ? file_str[0] : "stdin"), line_no);
fprintf(stderr, " Warning: %s\n", message);
}
/* MR10: Jeff Vincent
MR10: Changed to remove directory information from n only if
MR10: if OutputDirectory was changed by user (-o option)
*/
#ifdef __USE_PROTOS
char *OutMetaName(char *n)
#else
char *OutMetaName(n)
char *n;
#endif
{
static char *dir_sym = DirectorySymbol;
static char newname[MaxFileName+1];
char *p;
/* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */
if (strcmp(OutputDirectory, TopDirectory) == 0)
return n;
/* p will point to filename without path information */
if ((p = strrchr(n, *dir_sym)) != NULL)
p++;
else
p = n;
/* Copy new output directory into newname[] */
strcpy(newname, OutputDirectory);
/* if new output directory does not have trailing dir_sym, add it! */
if (newname[strlen(newname)-1] != *dir_sym)
strcat(newname, dir_sym);
/* contatenate FILE NAME ONLY to new output directory */
strcat(newname, p);
return newname;
}

View File

@@ -0,0 +1,133 @@
#ifndef tokens_h
#define tokens_h
/* tokens.h -- List of labelled tokens and stuff
*
* Generated from: dlg_p.g
*
* Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
* Purdue University Electrical Engineering
* ANTLR Version 1.33MR33
*/
#define zzEOF_TOKEN 1
#define L_EOF 4
#define PER_PER 5
#define NAME_PER_PER 6
#define LEXMEMBER 7
#define LEXACTION 8
#define PARSERCLASS 9
#define LEXPREFIX 10
#define ACTION 11
#define GREAT_GREAT 12
#define L_BRACE 13
#define R_BRACE 14
#define L_PAR 15
#define R_PAR 16
#define L_BRACK 17
#define R_BRACK 18
#define ZERO_MORE 19
#define ONE_MORE 20
#define OR 21
#define RANGE 22
#define NOT 23
#define OCTAL_VALUE 24
#define HEX_VALUE 25
#define DEC_VALUE 26
#define TAB 27
#define NL 28
#define CR 29
#define BS 30
#define CONTINUATION 31
#define LIT 32
#define REGCHAR 33
#ifdef __USE_PROTOS
void grammar(void);
#else
extern void grammar();
#endif
#ifdef __USE_PROTOS
void start_states(void);
#else
extern void start_states();
#endif
#ifdef __USE_PROTOS
void do_conversion(void);
#else
extern void do_conversion();
#endif
#ifdef __USE_PROTOS
void rule_list(void);
#else
extern void rule_list();
#endif
#ifdef __USE_PROTOS
void rule(void);
#else
extern void rule();
#endif
#ifdef __USE_PROTOS
void reg_expr(void);
#else
extern void reg_expr();
#endif
#ifdef __USE_PROTOS
void and_expr(void);
#else
extern void and_expr();
#endif
#ifdef __USE_PROTOS
void repeat_expr(void);
#else
extern void repeat_expr();
#endif
#ifdef __USE_PROTOS
void expr(void);
#else
extern void expr();
#endif
#ifdef __USE_PROTOS
void atom_list(void);
#else
extern void atom_list();
#endif
#ifdef __USE_PROTOS
void near_atom(void);
#else
extern void near_atom();
#endif
#ifdef __USE_PROTOS
void atom(void);
#else
extern void atom();
#endif
#ifdef __USE_PROTOS
void anychar(void);
#else
extern void anychar();
#endif
#endif
extern SetWordType zzerr1[];
extern SetWordType zzerr2[];
extern SetWordType zzerr3[];
extern SetWordType setwd1[];
extern SetWordType zzerr4[];
extern SetWordType zzerr5[];
extern SetWordType zzerr6[];
extern SetWordType setwd2[];
extern SetWordType zzerr7[];
extern SetWordType zzerr8[];
extern SetWordType zzerr9[];
extern SetWordType setwd3[];

View File

@@ -0,0 +1,871 @@
/* ANTLRParser.C
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
#include "pccts_stdlib.h"
#include "pccts_stdarg.h"
#include "pccts_string.h"
#include "pccts_stdio.h"
PCCTS_NAMESPACE_STD
/* I have to put this here due to C++ limitation
* that you can't have a 'forward' decl for enums.
* I hate C++!!!!!!!!!!!!!!!
* Of course, if I could use real templates, this would go away.
*/
// MR1
// MR1 10-Apr-97 133MR1 Prevent use of varying sizes for the
// MR1 ANTLRTokenType enum
// MR1
enum ANTLRTokenType { TER_HATES_CPP=0, ITS_TOO_COMPLICATED=9999}; // MR1
#define ANTLR_SUPPORT_CODE
#include ATOKEN_H
#include ATOKENBUFFER_H
#include APARSER_H
static const int zzINF_DEF_TOKEN_BUFFER_SIZE = 2000; /* MR14 */
static const int zzINF_BUFFER_TOKEN_CHUNK_SIZE = 1000; /* MR14 */
/* L o o k a h e a d M a c r o s */
/* maximum of 32 bits/unsigned int and must be 8 bits/byte;
* we only use 8 bits of it.
*/
SetWordType ANTLRParser::bitmask[sizeof(SetWordType)*8] = {
0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080
};
char ANTLRParser::eMsgBuffer[500] = "";
ANTLRParser::
~ANTLRParser()
{
delete [] token_type;
delete [] zzFAILtext; // MR16 Manfred Kogler
}
ANTLRParser::
ANTLRParser(ANTLRTokenBuffer *_inputTokens,
int k,
int use_inf_look,
int dlook,
int ssize)
{
LLk = k;
can_use_inf_look = use_inf_look;
/* MR14 */ if (dlook != 0) {
/* MR14 */ panic("ANTLRParser::ANTLRParser - Demand lookahead not supported in C++ mode");
/* MR14 */
/* MR14 */ };
demand_look = 0; /* demand_look = dlook; */
bsetsize = ssize;
guessing = 0;
token_tbl = NULL;
eofToken = (ANTLRTokenType)1;
// allocate lookahead buffer
token_type = new ANTLRTokenType[LLk];
lap = 0;
labase = 0;
#ifdef ZZDEFER_FETCH
stillToFetch = 0; // MR19
#endif
dirty = 0;
inf_labase = 0; // MR7
inf_last = 0; // MR7
/* prime lookahead buffer, point to inputTokens */
this->inputTokens = _inputTokens;
this->inputTokens->setMinTokens(k);
_inputTokens->setParser(this); // MR1
resynchConsumed=1; // MR8
zzFAILtext=NULL; // MR9
traceOptionValueDefault=0; // MR10
traceReset(); // MR10
zzGuessSeq=0; // MR10
syntaxErrCount=0; // MR11
}
void ANTLRParser::init()
{
prime_lookahead();
resynchConsumed=1; // MR8
traceReset(); // MR10
}
void ANTLRParser::traceReset()
{
traceOptionValue=traceOptionValueDefault;
traceGuessOptionValue=1;
traceCurrentRuleName=NULL;
traceDepth=0;
}
#ifdef _MSC_VER // MR23
//Turn off warning:
//interaction between '_setjmp' and C++ object destruction is non-portable
#pragma warning(disable : 4611)
#endif
int ANTLRParser::
guess(ANTLRParserState *st)
{
saveState(st);
guessing = 1;
return setjmp(guess_start.state);
}
#ifdef _MSC_VER // MR23
#pragma warning(default: 4611)
#endif
void ANTLRParser::
saveState(ANTLRParserState *buf)
{
buf->guess_start = guess_start;
buf->guessing = guessing;
buf->inf_labase = inf_labase;
buf->inf_last = inf_last;
buf->dirty = dirty;
buf->traceOptionValue=traceOptionValue; /* MR10 */
buf->traceGuessOptionValue=traceGuessOptionValue; /* MR10 */
buf->traceCurrentRuleName=traceCurrentRuleName; /* MR10 */
buf->traceDepth=traceDepth; /* MR10 */
}
void ANTLRParser::
restoreState(ANTLRParserState *buf)
{
int i;
int prevTraceOptionValue;
guess_start = buf->guess_start;
guessing = buf->guessing;
inf_labase = buf->inf_labase;
inf_last = buf->inf_last;
dirty = buf->dirty;
// restore lookahead buffer from k tokens before restored TokenBuffer position
// if demand_look, then I guess we don't look backwards for these tokens.
for (i=1; i<=LLk; i++) token_type[i-1] =
inputTokens->bufferedToken(i-LLk)->getType();
lap = 0;
labase = 0;
/* MR10 */
prevTraceOptionValue=traceOptionValue;
traceOptionValue=buf->traceOptionValue;
if ( (prevTraceOptionValue > 0) !=
(traceOptionValue > 0)) {
if (traceCurrentRuleName != NULL) { /* MR21 */
if (traceOptionValue > 0) {
/* MR23 */ printMessage(stderr,
"trace enable restored in rule %s depth %d\n",
traceCurrentRuleName,
traceDepth);
};
if (traceOptionValue <= 0) {
/* MR23 */ printMessage(stderr,
"trace disable restored in rule %s depth %d\n",
traceCurrentRuleName, /* MR21 */
traceDepth);
};
}
};
traceGuessOptionValue=buf->traceGuessOptionValue;
traceCurrentRuleName=buf->traceCurrentRuleName;
traceDepth=buf->traceDepth;
traceGuessDone(buf);
}
/* Get the next symbol from the input stream; put it into lookahead buffer;
* fill token_type[] fast reference cache also. NLA is the next place where
* a lookahead ANTLRAbstractToken should go.
*/
void ANTLRParser::
consume()
{
#ifdef ZZDEBUG_CONSUME_ACTION
zzdebug_consume_action();
#endif
// MR19 V.H. Simonis
// Defer Fetch feature
// Moves action of consume() into LA() function
#ifdef ZZDEFER_FETCH
stillToFetch++;
#else
NLA = inputTokens->getToken()->getType();
dirty--;
lap = (lap+1)&(LLk-1);
#endif
}
_ANTLRTokenPtr ANTLRParser::
LT(int i)
{
// MR19 V.H. Simonis
// Defer Fetch feature
// Moves action of consume() into LA() function
#ifdef ZZDEFER_FETCH
undeferFetch();
#endif
#ifdef DEBUG_TOKENBUFFER
if ( i >= inputTokens->bufferSize() || inputTokens->minTokens() < LLk ) /* MR20 Was "<=" */
{
char buf[2000]; /* MR20 Was "static" */
sprintf(buf, "The minimum number of tokens you requested that the\nANTLRTokenBuffer buffer is not enough to satisfy your\nLT(%d) request; increase 'k' argument to constructor for ANTLRTokenBuffer\n", i);
panic(buf);
}
#endif
return inputTokens->bufferedToken(i-LLk);
}
void
ANTLRParser::
look(int k)
{
int i, c = k - (LLk-dirty);
for (i=1; i<=c; i++) consume();
}
/* fill the lookahead buffer up with k symbols (even if DEMAND_LOOK);
*/
void
ANTLRParser::
prime_lookahead()
{
int i;
for(i=1;i<=LLk; i++) consume();
dirty=0;
// lap = 0; // MR14 Sinan Karasu (sinan.karasu@boeing.com)
// labase = 0; // MR14
labase=lap; // MR14
}
/* check to see if the current input symbol matches '_t'.
* During NON demand lookahead mode, dirty will always be 0 and
* hence the extra code for consuming tokens in _match is never
* executed; the same routine can be used for both modes.
*/
int ANTLRParser::
_match(ANTLRTokenType _t, ANTLRChar **MissText,
ANTLRTokenType *MissTok, _ANTLRTokenPtr *BadTok,
SetWordType **MissSet)
{
if ( dirty==LLk ) {
consume();
}
if ( LA(1)!=_t ) {
*MissText=NULL;
*MissTok= _t;
*BadTok = LT(1);
*MissSet=NULL;
return 0;
}
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
return 1;
}
/* check to see if the current input symbol matches '_t'.
* Used during exception handling.
*/
int ANTLRParser::
_match_wsig(ANTLRTokenType _t)
{
if ( dirty==LLk ) {
consume();
}
if ( LA(1)!=_t ) return 0;
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
return 1;
}
/* check to see if the current input symbol matches any token in a set.
* During NON demand lookahead mode, dirty will always be 0 and
* hence the extra code for consuming tokens in _match is never
* executed; the same routine can be used for both modes.
*/
int ANTLRParser::
_setmatch(SetWordType *tset, ANTLRChar **MissText,
ANTLRTokenType *MissTok, _ANTLRTokenPtr *BadTok,
SetWordType **MissSet, SetWordType *tokclassErrset)
{
if ( dirty==LLk ) {
consume();
}
if ( !set_el(LA(1), tset) ) {
*MissText=NULL; /* MR23 */
*MissTok=(ANTLRTokenType) 0; /* MR23 */
*BadTok=LT(1); /* MR23 */
*MissSet=tokclassErrset; /* MR23 */
return 0;
}
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
return 1;
}
int ANTLRParser::
_setmatch_wsig(SetWordType *tset)
{
if ( dirty==LLk ) {
consume();
}
if ( !set_el(LA(1), tset) ) return 0;
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
return 1;
}
/* Exception handling routines */
//
// 7-Apr-97 133MR1
// Change suggested by Eli Sternheim (eli@interhdl.com)
//
void ANTLRParser::
consumeUntil(SetWordType *st)
{
ANTLRTokenType tmp; // MR1
const int Eof=1; // MR1
while ( !set_el( (tmp=LA(1)), st) && tmp!=Eof) { consume(); } // MR1
}
//
// 7-Apr-97 133MR1
// Change suggested by Eli Sternheim (eli@interhdl.com)
//
void ANTLRParser::
consumeUntilToken(int t)
{
int tmp; // MR1
const int Eof=1; // MR1
while ( (tmp=LA(1)) !=t && tmp!=Eof) { consume(); } // MR1
}
/* Old error stuff */
void ANTLRParser::
resynch(SetWordType *wd,SetWordType mask)
{
/* MR8 S.Bochnak@microtool.com.pl */
/* MR8 Change file scope static "consumed" to instance var */
/* if you enter here without having consumed a token from last resynch
* force a token consumption.
*/
/* MR8 */ if ( !resynchConsumed ) {consume(); resynchConsumed=1; return;}
/* if current token is in resynch set, we've got what we wanted */
/* MR8 */ if ( wd[LA(1)]&mask || LA(1) == eofToken ) {resynchConsumed=0; return;}
/* scan until we find something in the resynch set */
while ( !(wd[LA(1)]&mask) && LA(1) != eofToken ) {consume();}
/* MR8 */ resynchConsumed=1;
}
/* standard error reporting function that assumes DLG-based scanners;
* you should redefine in subclass to change it or if you use your
* own scanner.
*/
/* MR23 THM There appears to be a parameter "badText" passed to syn()
which is not present in the parameter list. This may be
because in C mode there is no attribute function which
returns the text, so the text representation of the token
must be passed explicitly. I think.
*/
void ANTLRParser::
syn(_ANTLRTokenPtr /*tok MR23*/, ANTLRChar *egroup, SetWordType *eset,
ANTLRTokenType etok, int k)
{
int line;
line = LT(1)->getLine();
syntaxErrCount++; /* MR11 */
/* MR23 If the token is not an EOF token, then use the ->getText() value.
If the token is the EOF token the text returned by ->getText()
may be garbage. If the text from the token table is "@" use
"<eof>" instead, because end-users don't know what "@" means.
If the text is not "@" then use that text, which must have been
supplied by the grammar writer.
*/
const char * errorAt = LT(1)->getText();
if (LA(1) == eofToken) {
errorAt = parserTokenName(LA(1));
if (errorAt[0] == '@') errorAt = "<eof>";
}
/* MR23 */ printMessage(stderr, "line %d: syntax error at \"%s\"",
line, errorAt);
if ( !etok && !eset ) {/* MR23 */ printMessage(stderr, "\n"); return;}
if ( k==1 ) /* MR23 */ printMessage(stderr, " missing");
else
{
/* MR23 */ printMessage(stderr, "; \"%s\" not", LT(k)->getText()); // MR23 use LT(k) since k>1
if ( set_deg(eset)>1 ) /* MR23 */ printMessage(stderr, " in");
}
if ( set_deg(eset)>0 ) edecode(eset);
else /* MR23 */ printMessage(stderr, " %s", token_tbl[etok]);
if ( strlen(egroup) > 0 ) /* MR23 */ printMessage(stderr, " in %s", egroup);
/* MR23 */ printMessage(stderr, "\n");
}
/* is b an element of set p? */
int ANTLRParser::
set_el(ANTLRTokenType b, SetWordType *p)
{
return( p[DIVWORD(b)] & bitmask[MODWORD(b)] );
}
int ANTLRParser::
set_deg(SetWordType *a)
{
/* Fast compute degree of a set... the number
of elements present in the set. Assumes
that all word bits are used in the set
*/
register SetWordType *p = a;
register SetWordType *endp = &(a[bsetsize]);
register int degree = 0;
if ( a == NULL ) return 0;
while ( p < endp )
{
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
if (t & *b) ++degree;
} while (++b < &(bitmask[sizeof(SetWordType)*8]));
p++;
}
return(degree);
}
void ANTLRParser::
edecode(SetWordType *a)
{
register SetWordType *p = a;
register SetWordType *endp = &(p[bsetsize]);
register unsigned e = 0;
if ( set_deg(a)>1 ) /* MR23 */ printMessage(stderr, " {");
do {
register SetWordType t = *p;
register SetWordType *b = &(bitmask[0]);
do {
if ( t & *b ) /* MR23 */ printMessage(stderr, " %s", token_tbl[e]);
e++;
} while (++b < &(bitmask[sizeof(SetWordType)*8]));
} while (++p < endp);
if ( set_deg(a)>1 ) /* MR23 */ printMessage(stderr, " }");
}
/* input looks like:
* zzFAIL(k, e1, e2, ...,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk)
* where the zzMiss stuff is set here to the token that did not match
* (and which set wasn't it a member of).
*/
// MR9 29-Sep-97 Stan Bochnak (S.Bochnak@microTool.com.pl)
// MR9 Original fix to static allocated text didn't
// MR9 work because a pointer to it was passed back
// MR9 to caller. Replace with instance variable.
const int SETWORDCOUNT=20;
void
ANTLRParser::FAIL(int k, ...)
{
//
// MR1 10-Apr-97
//
if (zzFAILtext == NULL) zzFAILtext=new char [1000]; // MR9
SetWordType **f=new SetWordType *[SETWORDCOUNT]; // MR1 // MR9
SetWordType **miss_set;
ANTLRChar **miss_text;
_ANTLRTokenPtr *bad_tok;
ANTLRChar **bad_text;
//
// 7-Apr-97 133MR1
// err_k is passed as a "int *", not "unsigned *"
//
int *err_k; // MR1
int i;
va_list ap;
va_start(ap, k);
zzFAILtext[0] = '\0';
if ( k > SETWORDCOUNT ) panic("FAIL: overflowed buffer");
for (i=1; i<=k; i++) /* collect all lookahead sets */
{
f[i-1] = va_arg(ap, SetWordType *);
}
for (i=1; i<=k; i++) /* look for offending token */
{
if ( i>1 ) strcat(zzFAILtext, " ");
strcat(zzFAILtext, LT(i)->getText());
if ( !set_el(LA(i), f[i-1]) ) break;
}
miss_set = va_arg(ap, SetWordType **);
miss_text = va_arg(ap, ANTLRChar **);
bad_tok = va_arg(ap, _ANTLRTokenPtr *);
bad_text = va_arg(ap, ANTLRChar **);
err_k = va_arg(ap, int *); // MR1
if ( i>k )
{
/* bad; lookahead is permutation that cannot be matched,
* but, the ith token of lookahead is valid at the ith position
* (The old LL sub 1 (k) versus LL(k) parsing technique)
*/
*miss_set = NULL;
*miss_text = LT(1)->getText();
*bad_tok = LT(1);
*bad_text = (*bad_tok)->getText();
*err_k = k;
//
// MR4 20-May-97 erroneously deleted contents of f[]
// MR4 reported by Bruce Guenter (bruceg@qcc.sk.ca)
// MR1 10-Apr-97 release temporary storage
//
delete [] f; // MR1
return; // MR1
}
/* MR23 printMessage(stderr, "%s not in %dth set\n", zztokens[LA(i)], i);*/
*miss_set = f[i-1];
*miss_text = zzFAILtext;
*bad_tok = LT(i);
*bad_text = (*bad_tok)->getText();
if ( i==1 ) *err_k = 1;
else *err_k = k;
//
// MR4 20-May-97 erroneously deleted contents of f[]
// MR4 reported by Bruce Guenter (bruceg@qcc.sk.ca)
// MR1 10-Apr-97 release temporary storage
//
delete [] f; // MR1
return; // MR1
}
int ANTLRParser::
_match_wdfltsig(ANTLRTokenType tokenWanted, SetWordType *whatFollows)
{
if ( dirty==LLk ) consume();
if ( LA(1)!=tokenWanted )
{
syntaxErrCount++; /* MR11 */
/* MR23 */ printMessage(stderr,
"line %d: syntax error at \"%s\" missing %s\n",
LT(1)->getLine(),
(LA(1)==eofToken && LT(1)->getText()[0] == '@')?"<eof>":LT(1)->getText(), /* MR21a */
token_tbl[tokenWanted]);
consumeUntil( whatFollows );
return 0;
}
else {
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
/* if ( !demand_look ) consume(); */
return 1;
}
}
int ANTLRParser::
_setmatch_wdfltsig(SetWordType *tokensWanted,
ANTLRTokenType tokenTypeOfSet,
SetWordType *whatFollows)
{
if ( dirty==LLk ) consume();
if ( !set_el(LA(1), tokensWanted) )
{
syntaxErrCount++; /* MR11 */
/* MR23 */ printMessage(stderr,
"line %d: syntax error at \"%s\" missing %s\n",
LT(1)->getLine(),
(LA(1)==eofToken && LT(1)->getText()[0] == '@')?"<eof>":LT(1)->getText(), /* MR21a */
token_tbl[tokenTypeOfSet]);
consumeUntil( whatFollows );
return 0;
}
else {
dirty++;
labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
/* if ( !demand_look ) consume(); */
return 1;
}
}
char *ANTLRParser::
eMsgd(char *err,int d)
{
sprintf(eMsgBuffer, err, d); // dangerous, but I don't care
return eMsgBuffer;
}
char *ANTLRParser::
eMsg(char *err, char *s)
{
sprintf(eMsgBuffer, err, s);
return eMsgBuffer;
}
char *ANTLRParser::
eMsg2(char *err,char *s, char *t)
{
sprintf(eMsgBuffer, err, s, t);
return eMsgBuffer;
}
void ANTLRParser::
panic(const char *msg) // MR20 const
{
/* MR23 */ printMessage(stderr, "ANTLR panic: %s\n", msg);
exit(PCCTS_EXIT_FAILURE); // MR1
}
const ANTLRChar *ANTLRParser:: // MR1
parserTokenName(int tok) { // MR1
return token_tbl[tok]; // MR1
} // MR1
void ANTLRParser::traceGuessDone(const ANTLRParserState *state) {
int doIt=0;
if (traceCurrentRuleName == NULL) return;
if (traceOptionValue <= 0) {
doIt=0;
} else if (traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
/* MR23 */ printMessage(stderr,"guess done - returning to rule %s {\"%s\"} at depth %d",
state->traceCurrentRuleName,
LT(1)->getType() == eofToken ? "@" : LT(1)->getText(),
state->traceDepth);
if (state->guessing != 0) {
/* MR23 */ printMessage(stderr," (guess mode continues - an enclosing guess is still active)");
} else {
/* MR23 */ printMessage(stderr," (guess mode ends)");
};
/* MR23 */ printMessage(stderr,"\n");
};
}
void ANTLRParser::traceGuessFail() {
int doIt=0;
if (traceCurrentRuleName == NULL) return; /* MR21 */
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
/* MR23 */ printMessage(stderr,"guess failed in %s\n",traceCurrentRuleName);
};
}
/* traceOption:
zero value turns off trace
*/
void ANTLRParser::tracein(const ANTLRChar * rule) {
int doIt=0;
traceDepth++;
traceCurrentRuleName=rule;
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
/* MR23 */ printMessage(stderr,"enter rule %s {\"%s\"} depth %d",
rule,
LT(1)->getType() == eofToken ? "@" : LT(1)->getText(),
traceDepth);
if (guessing) /* MR23 */ printMessage(stderr," guessing");
/* MR23 */ printMessage(stderr,"\n");
};
return;
}
void ANTLRParser::traceout(const ANTLRChar * rule) {
int doIt=0;
traceDepth--;
if (traceOptionValue <= 0) {
doIt=0;
} else if (guessing && traceGuessOptionValue <= 0) {
doIt=0;
} else {
doIt=1;
};
if (doIt) {
/* MR23 */ printMessage(stderr,"exit rule %s {\"%s\"} depth %d",
rule,
LT(1)->getType() == eofToken ? "@" : LT(1)->getText(),
traceDepth+1);
if (guessing) /* MR23 */ printMessage(stderr," guessing");
/* MR23 */ printMessage(stderr,"\n");
};
}
int ANTLRParser::traceOption(int delta) {
int prevValue=traceOptionValue;
traceOptionValue=traceOptionValue+delta;
if (traceCurrentRuleName != NULL) {
if (prevValue <= 0 && traceOptionValue > 0) {
/* MR23 */ printMessage(stderr,"trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
if (prevValue > 0 && traceOptionValue <= 0) {
/* MR23 */ printMessage(stderr,"trace disabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
};
return prevValue;
}
int ANTLRParser::traceGuessOption(int delta) {
int prevValue=traceGuessOptionValue;
traceGuessOptionValue=traceGuessOptionValue+delta;
if (traceCurrentRuleName != NULL) {
if (prevValue <= 0 && traceGuessOptionValue > 0) {
/* MR23 */ printMessage(stderr,"guess trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
if (prevValue > 0 && traceGuessOptionValue <= 0) {
/* MR23 */ printMessage(stderr,"guess trace disabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth);
};
};
return prevValue;
}
// MR19 V.H. Simonis Defer Fetch feature
void ANTLRParser::undeferFetch()
{
#ifdef ZZDEFER_FETCH
if (stillToFetch) {
for (int stillToFetch_x = 0; stillToFetch_x < stillToFetch; ++stillToFetch_x) {
NLA = inputTokens->getToken()->getType();
dirty--;
lap = (lap+1)&(LLk-1);
}
stillToFetch = 0;
}
#else
return;
#endif
}
int ANTLRParser::isDeferFetchEnabled()
{
#ifdef ZZDEFER_FETCH
return 1;
#else
return 0;
#endif
}
//MR23
int ANTLRParser::printMessage(FILE* pFile, const char* pFormat, ...)
{
va_list marker;
va_start( marker, pFormat );
int iRet = printMessageV(pFile, pFormat, marker);
va_end( marker );
return iRet;
}
int ANTLRParser::printMessageV(FILE* pFile, const char* pFormat, va_list arglist) // MR23
{
return vfprintf(pFile, pFormat, arglist);
}
// MR23 Move semantic predicate error handling from macro to virtual function
//
// Called by the zzfailed_pred
void ANTLRParser::failedSemanticPredicate(const char* predicate)
{
printMessage(stdout,"line %d: semantic error; failed predicate: '%s'\n",
LT(1)->getLine(), predicate);
}

View File

@@ -0,0 +1,376 @@
/* ANTLRParser.h
*
* Define the generic ANTLRParser superclass, which is subclassed to
* define an actual parser.
*
* Before entry into this file: ANTLRTokenType must be set.
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef APARSER_H_GATE
#define APARSER_H_GATE
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_setjmp.h"
PCCTS_NAMESPACE_STD
#include ATOKEN_H
#include ATOKENBUFFER_H
#ifdef ZZCAN_GUESS
#ifndef ZZINF_LOOK
#define ZZINF_LOOK
#endif
#endif
#define NLA (token_type[lap&(LLk-1)])/* --> next LA */
typedef unsigned char SetWordType;
/* Define external bit set stuff (for SetWordType) */
#define EXT_WORDSIZE (sizeof(char)*8)
#define EXT_LOGWORDSIZE 3
/* s y n t a c t i c p r e d i c a t e s t u f f */
#ifndef zzUSER_GUESS_HOOK
#define zzUSER_GUESS_HOOK(seqFrozen,zzrv)
#endif
#ifndef zzUSER_GUESS_DONE_HOOK
#define zzUSER_GUESS_DONE_HOOK(seqFrozen)
#endif
/* MR14 Add zzUSER_GUESS_FAIL_HOOK and related code */
#define zzUSER_GUESS_FAIL_HOOK_INTERNAL zzUSER_GUESS_FAIL_HOOK(SeqFrozen)
#ifndef zzUSER_GUESS_FAIL_HOOK
#define zzUSER_GUESS_FAIL_HOOK(zzGuessSeq)
#endif
typedef struct _zzjmp_buf {
jmp_buf state;
} zzjmp_buf;
/* these need to be macros not member functions */
#define zzGUESS_BLOCK ANTLRParserState zzst; int zzrv; int _marker; int zzGuessSeqFrozen;
#define zzNON_GUESS_MODE if ( !guessing )
#define zzGUESS_FAIL guess_fail();
/* Note: zzGUESS_DONE does not execute longjmp() */
#define zzGUESS_DONE {zzrv=1; inputTokens->rewind(_marker); guess_done(&zzst);zzUSER_GUESS_DONE_HOOK(zzGuessSeqFrozen) }
#define zzGUESS saveState(&zzst); \
guessing = 1; \
zzGuessSeqFrozen = ++zzGuessSeq; \
_marker = inputTokens->mark(); \
zzrv = setjmp(guess_start.state); \
zzUSER_GUESS_HOOK(zzGuessSeqFrozen,zzrv) \
if ( zzrv ) zzGUESS_DONE
#define zzTRACEdata const ANTLRChar *zzTracePrevRuleName = NULL;
#ifndef zzTRACEIN
#define zzTRACEIN(r) zzTracePrevRuleName=traceCurrentRuleName;tracein(r);
#endif
#ifndef zzTRACEOUT
#define zzTRACEOUT(r) traceout(r);traceCurrentRuleName=zzTracePrevRuleName;
#endif
/* a n t l r p a r s e r d e f */
struct ANTLRParserState {
/* class variables */
zzjmp_buf guess_start;
int guessing;
int inf_labase;
int inf_last;
int dirty;
int traceOptionValue; // MR10
int traceGuessOptionValue; // MR10
const ANTLRChar *traceCurrentRuleName; // MR10
int traceDepth; // MR10
};
/* notes:
*
* multiple inheritance is a cool way to include what stuff is needed
* in this structure (like guess stuff). however, i'm not convinced that
* multiple inheritance works correctly on all platforms. not that
* much space is used--just include all possibly useful members.
*
* the class should also be a template with arguments for the lookahead
* depth and so on. that way, more than one parser can be defined (as
* each will probably have different lookahead requirements). however,
* am i sure that templates work? no, i'm not sure.
*
* no attributes are maintained and, hence, the 'asp' variable is not
* needed. $i can still be referenced, but it refers to the token
* associated with that rule element. question: where are the token's
* stored if not on the software stack? in local variables created
* and assigned to by antlr.
*/
class ANTLRParser {
protected:
/* class variables */
static SetWordType bitmask[sizeof(SetWordType)*8];
static char eMsgBuffer[500];
protected:
int LLk; // number of lookahead symbols (old LL_K)
int demand_look;
ANTLRTokenType eofToken; // when do I stop during resynch()s
int bsetsize; // size of bitsets created by ANTLR in
// units of SetWordType
ANTLRTokenBuffer *inputTokens; //place to get input tokens
zzjmp_buf guess_start; // where to jump back to upon failure
int guessing; // if guessing (using (...)? predicate)
// infinite lookahead stuff
int can_use_inf_look; // set by subclass (generated by ANTLR)
int inf_lap;
int inf_labase;
int inf_last;
int *_inf_line;
const ANTLRChar **token_tbl; // pointer to table of token type strings MR20 const
int dirty; // used during demand lookahead
ANTLRTokenType *token_type; // fast reference cache of token.getType()
// ANTLRLightweightToken **token; // the token with all its attributes
int lap;
int labase;
#ifdef ZZDEFER_FETCH
int stillToFetch; // MR19 V.H. Simonis
#endif
private:
void fill_inf_look();
protected:
virtual void guess_fail() { // MR9 27-Sep-97 make virtual
traceGuessFail(); // MR10
longjmp(guess_start.state, 1); } // MR9
virtual void guess_done(ANTLRParserState *st) { // MR9 27-Sep-97 make virtual
restoreState(st); } // MR9
virtual int guess(ANTLRParserState *); // MR9 27-Sep-97 make virtual
void look(int);
int _match(ANTLRTokenType, ANTLRChar **, ANTLRTokenType *,
_ANTLRTokenPtr *, SetWordType **);
int _setmatch(SetWordType *, ANTLRChar **, ANTLRTokenType *,
_ANTLRTokenPtr *, SetWordType **,
SetWordType * tokclassErrset /* MR23 */);
int _match_wsig(ANTLRTokenType);
int _setmatch_wsig(SetWordType *);
virtual void consume();
virtual void resynch(SetWordType *wd,SetWordType mask); // MR21
void prime_lookahead();
virtual void tracein(const ANTLRChar *r); // MR10
virtual void traceout(const ANTLRChar *r); // MR10
static unsigned MODWORD(unsigned x) {return x & (EXT_WORDSIZE-1);} // x % EXT_WORDSIZE // MR9
static unsigned DIVWORD(unsigned x) {return x >> EXT_LOGWORDSIZE;} // x / EXT_WORDSIZE // MR9
int set_deg(SetWordType *);
int set_el(ANTLRTokenType, SetWordType *);
virtual void edecode(SetWordType *); // MR1
virtual void FAIL(int k, ...); // MR1
int traceOptionValue; // MR10
int traceGuessOptionValue; // MR10
const ANTLRChar *traceCurrentRuleName; // MR10
int traceDepth; // MR10
void traceReset(); // MR10
virtual void traceGuessFail(); // MR10
virtual void traceGuessDone(const ANTLRParserState *); // MR10
int zzGuessSeq; // MR10
public:
ANTLRParser(ANTLRTokenBuffer *,
int k=1,
int use_inf_look=0,
int demand_look=0,
int bsetsize=1);
virtual ~ANTLRParser();
virtual void init();
ANTLRTokenType LA(int i)
{
//
// MR14 demand look will always be 0 for C++ mode
//
//// return demand_look ? token_type[(labase+(i)-1)&(LLk-1)] :
//// token_type[(lap+(i)-1)&(LLk-1)];
// MR19 V.H. Simonis Defer fetch feature
#ifdef ZZDEFER_FETCH
undeferFetch();
#endif
return token_type[(lap+(i)-1)&(LLk-1)];
}
_ANTLRTokenPtr LT(int i);
void setEofToken(ANTLRTokenType t) { eofToken = t; }
ANTLRTokenType getEofToken() const { return eofToken; } // MR14
void noGarbageCollectTokens() { inputTokens->noGarbageCollectTokens(); }
void garbageCollectTokens() { inputTokens->garbageCollectTokens(); }
virtual void syn(_ANTLRTokenPtr tok, ANTLRChar *egroup,
SetWordType *eset, ANTLRTokenType etok, int k);
virtual void saveState(ANTLRParserState *); // MR9 27-Sep-97 make virtual
virtual void restoreState(ANTLRParserState *); // MR9 27-Sep-97 make virtual
virtual void panic(const char *msg); // MR20 const
static char *eMsgd(char *,int);
static char *eMsg(char *,char *);
static char *eMsg2(char *,char *,char *);
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
virtual int printMessageV(FILE* pFile, const char* pFormat, va_list arglist); // MR23
void consumeUntil(SetWordType *st);
void consumeUntilToken(int t);
virtual int _setmatch_wdfltsig(SetWordType *tokensWanted,
ANTLRTokenType tokenTypeOfSet,
SetWordType *whatFollows);
virtual int _match_wdfltsig(ANTLRTokenType tokenWanted,
SetWordType *whatFollows);
const ANTLRChar * parserTokenName(int tok); // MR1
int traceOptionValueDefault; // MR11
int traceOption(int delta); // MR11
int traceGuessOption(int delta); // MR11
// MR8 5-Aug-97 S.Bochnak@microtool.com.pl
// MR8 Move resynch static local variable
// MR8 to class instance
int syntaxErrCount; // MR12
ANTLRTokenStream *getLexer() const { // MR12
return inputTokens ? inputTokens->getLexer() : 0; } // MR12
protected: // MR8
int resynchConsumed; // MR8
char *zzFAILtext; // workarea required by zzFAIL // MR9
void undeferFetch(); // MR19 V.H. Simonis
int isDeferFetchEnabled(); // MR19 V.H. Simonis
virtual void failedSemanticPredicate(const char* predicate); /* MR23 */
};
#define zzmatch(_t) \
if ( !_match((ANTLRTokenType)_t, &zzMissText, &zzMissTok, \
(_ANTLRTokenPtr *) &zzBadTok, &zzMissSet) ) goto fail;
#define zzmatch_wsig(_t,handler) \
if ( !_match_wsig((ANTLRTokenType)_t) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}
#define zzsetmatch(_ts,_tokclassErrset) \
if ( !_setmatch(_ts, &zzMissText, &zzMissTok, \
(_ANTLRTokenPtr *) &zzBadTok, &zzMissSet, _tokclassErrset) ) goto fail;
#define zzsetmatch_wsig(_ts, handler) \
if ( !_setmatch_wsig(_ts) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}
/* For the dflt signal matchers, a FALSE indicates that an error occurred
* just like the other matchers, but in this case, the routine has already
* recovered--we do NOT want to consume another token. However, when
* the match was successful, we do want to consume hence _signal=0 so that
* a token is consumed by the "if (!_signal) consume(); _signal=NoSignal;"
* preamble.
*/
#define zzsetmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows) \
if ( !_setmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows) ) \
_signal = MismatchedToken;
#define zzmatch_wdfltsig(tokenWanted, whatFollows) \
if ( !_match_wdfltsig(tokenWanted, whatFollows) ) _signal = MismatchedToken;
// MR1 10-Apr-97 zzfailed_pred() macro does not backtrack in guess mode.
// MR1 Identification and correction due to J. Lilley
//
// MR23 Call virtual method to report error.
// MR23 Provide more control over failed predicate action
// without any need for user to worry about guessing internals.
#ifndef zzfailed_pred
#define zzfailed_pred(_p,_hasuseraction,_useraction) \
if (guessing) { \
zzGUESS_FAIL; \
} else { \
zzfailed_pred_action(_p,_hasuseraction,_useraction) \
}
#endif
// MR23 Provide more control over failed predicate action
// without any need for user to worry about guessing internals.
// _hasuseraction == 0 => no user specified error action
// _hasuseraction == 1 => user specified error action
#ifndef zzfailed_pred_action
#define zzfailed_pred_action(_p,_hasuseraction,_useraction) \
if (_hasuseraction) { _useraction } else { failedSemanticPredicate(_p); }
#endif
#define zzRULE \
SetWordType *zzMissSet=NULL; ANTLRTokenType zzMissTok=(ANTLRTokenType)0; \
_ANTLRTokenPtr zzBadTok=NULL; ANTLRChar *zzBadText=(ANTLRChar *)""; \
int zzErrk=1,zzpf=0; \
zzTRACEdata \
ANTLRChar *zzMissText=(ANTLRChar *)"";
#endif
/* S t a n d a r d E x c e p t i o n S i g n a l s */
#define NoSignal 0
#define MismatchedToken 1
#define NoViableAlt 2
#define NoSemViableAlt 3
/* MR7 Allow more control over signalling */
/* by adding "Unwind" and "SetSignal" */
#define Unwind 4
#define setSignal(newValue) *_retsignal=_signal=(newValue)
#define suppressSignal *_retsignal=_signal=0
#define exportSignal *_retsignal=_signal

View File

@@ -0,0 +1,256 @@
/* Abstract syntax tree manipulation functions
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_stdarg.h"
PCCTS_NAMESPACE_STD
#define ANTLR_SUPPORT_CODE
#include "ASTBase.h"
/* ensure that tree manipulation variables are current after a rule
* reference
*/
void
ASTBase::link(ASTBase **_root, ASTBase **_sibling, ASTBase **_tail)
{
if ( *_sibling == NULL ) return;
if ( *_root == NULL ) *_root = *_sibling;
else if ( *_root != *_sibling ) (*_root)->_down = *_sibling;
if ( *_tail==NULL ) *_tail = *_sibling;
while ( (*_tail)->_right != NULL ) *_tail = (*_tail)->_right;
}
/* add a child node to the current sibling list */
void
ASTBase::subchild(ASTBase **_root, ASTBase **_sibling, ASTBase **_tail)
{
if ( *_tail != NULL ) (*_tail)->_right = this;
else {
*_sibling = this;
if ( *_root != NULL ) (*_root)->_down = *_sibling;
}
*_tail = this;
if ( *_root == NULL ) *_root = *_sibling;
}
/* make a new AST node. Make the newly-created
* node the root for the current sibling list. If a root node already
* exists, make the newly-created node the root of the current root.
*/
void
ASTBase::subroot(ASTBase **_root, ASTBase **_sibling, ASTBase **_tail)
{
if ( *_root != NULL )
if ( (*_root)->_down == *_sibling ) *_sibling = *_tail = *_root;
*_root = this;
(*_root)->_down = *_sibling;
}
/* Apply preorder_action(), etc.. to root then each sibling */
//
// 7-Apr-97 133MR1
// Fix suggested by Ron House (house@helios.usq.edu.au)
//
void
ASTBase::preorder(void* pData /*= NULL*/ /* MR23 */)
{
ASTBase *tree = this;
while ( tree!= NULL )
{
if ( tree->_down != NULL ) {
tree->preorder_before_action(pData); // MR1
};
tree->preorder_action(pData);
if ( tree->_down!=NULL )
{
tree->_down->preorder(pData);
tree->preorder_after_action(pData); // MR1
}
tree = tree->_right;
}
}
/* free all AST nodes in tree; apply func to each before freeing */
void
ASTBase::destroy()
{
ASTBase* tree = this;
while (tree) {
if (tree->_down) tree->_down->destroy();
ASTBase* cur = tree;
tree = tree->_right;
delete cur;
}
}
/* build a tree (root child1 child2 ... NULL)
* If root is NULL, simply make the children siblings and return ptr
* to 1st sibling (child1). If root is not single node, return NULL.
*
* Siblings that are actually siblins lists themselves are handled
* correctly. For example #( NULL, #( NULL, A, B, C), D) results
* in the tree ( NULL A B C D ).
*
* Requires at least two parameters with the last one being NULL. If
* both are NULL, return NULL.
*/
ASTBase *
ASTBase::tmake(ASTBase *root, ...)
{
va_list ap;
register ASTBase *child, *sibling=NULL, *tail=NULL /*MR23*/, *w;
va_start(ap, root);
if ( root != NULL )
if ( root->_down != NULL ) {
root->reportOverwriteOfDownPointer(); /* MR21 Report problem which almost always an error */
return NULL;
}
child = va_arg(ap, ASTBase *);
while ( child != NULL )
{
for (w=child; w->_right!=NULL; w=w->_right) {;} /* find end of child */
if ( sibling == NULL ) {sibling = child; tail = w;}
else {tail->_right = child; tail = w;}
child = va_arg(ap, ASTBase *);
}
if ( root==NULL ) root = sibling;
else root->_down = sibling;
va_end(ap);
return root;
}
#ifndef PCCTS_NOT_USING_SOR
/* tree duplicate */
// forgot to check for NULL this (TJP July 23,1995)
ASTBase *
ASTBase::dup()
{
ASTBase *u, *t=this;
if ( t == NULL ) return NULL;
/*
u = new ASTBase;
*u = *t;
*/
u = (ASTBase *)this->shallowCopy();
if ( t->_right!=NULL ) u->_right = t->_right->dup();
else u->_right = NULL;
if ( t->_down!=NULL ) u->_down = t->_down->dup();
else u->_down = NULL;
return u;
}
#endif
//
// 7-Apr-97 133MR1
// Fix suggested by Asgeir Olafsson (olafsson@cstar.ac.com)
//
/* tree duplicate */
#ifndef PCCTS_NOT_USING_SOR
ASTBase *
ASTDoublyLinkedBase::dup()
{
ASTDoublyLinkedBase *u, *t=this;
if ( t == NULL ) return NULL;
u = (ASTDoublyLinkedBase *)this->shallowCopy();
u->_up = NULL; /* set by calling invocation */
u->_left = NULL;
if (t->_right!=NULL) { // MR1
u->_right=t->_right->dup(); // MR1
((ASTDoublyLinkedBase *)u->_right)->_left = u; // MR1
} else { // MR1
u->_right = NULL; // MR1
}; // MR1
if (t->_down!=NULL) { // MR1
u->_down = t->_down->dup(); // MR1
((ASTDoublyLinkedBase *)u->_down)->_up = u; // MR1
} else { // MR1
u->_down = NULL; // MR1
}; // MR1
return u;
}
#endif
/*
* Set the 'up', and 'left' pointers of all nodes in 't'.
* Initial call is double_link(your_tree, NULL, NULL).
*/
void
ASTDoublyLinkedBase::double_link(ASTBase *left, ASTBase *up)
{
ASTDoublyLinkedBase *t = this;
t->_left = (ASTDoublyLinkedBase *) left;
t->_up = (ASTDoublyLinkedBase *) up;
if (t->_down != NULL)
((ASTDoublyLinkedBase *)t->_down)->double_link(NULL, t);
if (t->_right != NULL)
((ASTDoublyLinkedBase *)t->_right)->double_link(t, up);
}
// MR21 ASTBase::reportOverwriteOfDownPointer
void ASTBase::reportOverwriteOfDownPointer()
{
panic("Attempt to overwrite down pointer in ASTBase::tmake");
}
// MR21 ASTBase::panic
void ASTBase::panic(const char *msg)
{
/* MR23 */ printMessage(stderr,"ASTBase panic: %s\n", msg);
exit(PCCTS_EXIT_FAILURE);
}
#ifdef PCCTS_NOT_USING_SOR
//MR23
int ASTBase::printMessage(FILE* pFile, const char* pFormat, ...)
{
va_list marker;
va_start( marker, pFormat );
int iRet = vfprintf(pFile, pFormat, marker);
va_end( marker );
return iRet;
}
#endif

View File

@@ -0,0 +1,122 @@
/* Abstract syntax tree
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ASTBase_H
#define ASTBase_H
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_stdlib.h"
PCCTS_NAMESPACE_STD
#ifndef PCCTS_NOT_USING_SOR
#include "PCCTSAST.h"
#endif
/*
* Notes:
*
* To specify a copy constructor, subclass one of these classes and
* give the copy constructor. To use dup(), you must define shallowCopy().
* shallowCopy() can use either a copy constructor or just copy the node
* itself.
*/
#ifdef PCCTS_NOT_USING_SOR
class DllExportPCCTS ASTBase {
#else
class DllExportPCCTS ASTBase : public PCCTS_AST {
#endif
protected:
ASTBase *_right, *_down;
public:
#ifdef PCCTS_NOT_USING_SOR
ASTBase *right() { return _right; }
ASTBase *down() { return _down; }
void setRight(ASTBase *t) { _right = (ASTBase *)t; }
void setDown(ASTBase *t) { _down = (ASTBase *)t; }
#else
PCCTS_AST *right() { return _right; } // define the SORCERER interface
PCCTS_AST *down() { return _down; }
void setRight(PCCTS_AST *t) { _right = (ASTBase *)t; }
void setDown(PCCTS_AST *t) { _down = (ASTBase *)t; }
#endif
ASTBase() { _right = _down = NULL; }
virtual ~ASTBase() { ; }
#ifndef PCCTS_NOT_USING_SOR
virtual ASTBase *dup();
#endif
void destroy();
void preorder(void* pData = NULL /* MR23 */);
static ASTBase *tmake(ASTBase *, ...);
static void link(ASTBase **, ASTBase **, ASTBase **);
void subchild(ASTBase **, ASTBase **, ASTBase **);
void subroot(ASTBase **, ASTBase **, ASTBase **);
virtual void preorder_action(void* /*pData*/ = NULL /* MR23 */) { ; }
virtual void preorder_before_action(void* /*pData*/ = NULL /* MR23 */) { /* MR23 */ printMessage(stdout, " ("); }
virtual void preorder_after_action(void* /*pData*/ = NULL /* MR23 */) { /* MR23 */ printMessage(stdout, " )"); }
virtual void panic(const char *msg); /* MR21 */
virtual void reportOverwriteOfDownPointer(); /* MR21 */
#ifdef PCCTS_NOT_USING_SOR
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
#endif
};
class DllExportPCCTS ASTDoublyLinkedBase : public ASTBase {
protected:
ASTDoublyLinkedBase *_left, *_up;
public:
void double_link(ASTBase *left, ASTBase *up);
#ifndef PCCTS_NOT_USING_SOR
virtual ASTBase *dup();
#endif
#ifdef PCCTS_NOT_USING_SOR
ASTBase *left() { return _left; }
ASTBase *up() { return _up; }
void setLeft(ASTBase *t) { _left = (ASTDoublyLinkedBase *)t; } // MR6
void setUp(ASTBase *t) { _up = (ASTDoublyLinkedBase *)t; } // MR6
#else
PCCTS_AST *left() { return _left; }
PCCTS_AST *up() { return _up; }
void setLeft(PCCTS_AST *t) { _left = (ASTDoublyLinkedBase *)t; } // MR6
void setUp(PCCTS_AST *t) { _up = (ASTDoublyLinkedBase *)t; } // MR6
#endif
};
class AST; // announce that this class will be coming along shortly
#endif

View File

@@ -0,0 +1,88 @@
/* ATokPtr.h
*
* 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.
*
* ANTLR 1.33
* Written by Russell Quong June 30, 1995
* Adapted by Terence Parr to ANTLR stuff
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ATokPtr_h
#define ATokPtr_h
#include "pcctscfg.h"
#include "pccts_stdio.h"
PCCTS_NAMESPACE_STD
// pointer to a reference counted object
// robust in that an unused ANTLRTokenPtr can point to NULL.
class ANTLRAbstractToken;
class DllExportPCCTS ANTLRTokenPtr {
public:
ANTLRTokenPtr(ANTLRAbstractToken *addr=NULL){ptr_ = addr; ref();}
ANTLRTokenPtr(const ANTLRTokenPtr &lhs) {ptr_ = lhs.ptr_; lhs.ref();}
~ANTLRTokenPtr();
// use ANTLRTokenPtr as a pointer to ANTLRToken
//
// 8-Apr-97 MR1 Make operator -> a const member function
// as well as some other member functions
//
ANTLRAbstractToken *operator-> () const { return ptr_; } // MR1
//
// 7-Apr-97 133MR1
// Fix suggested by Andreas Magnusson
// (Andreas.Magnusson@mailbox.swipnet.se)
void operator = (const ANTLRTokenPtr & lhs); // MR1
void operator = (ANTLRAbstractToken *addr);
int operator != (const ANTLRTokenPtr &q) const // MR1 // MR11 unsigned -> int
{ return this->ptr_ != q.ptr_; }
int operator == (const ANTLRTokenPtr &q) const // MR1 // MR11 unsigned -> int
{ return this->ptr_ == q.ptr_; }
int operator == (const ANTLRAbstractToken *addr) const // MR11
{ return this->ptr_ == addr; }
int operator != (const ANTLRAbstractToken *addr) const // MR11
{ return this->ptr_ != addr; }
void ref() const;
void deref();
protected:
ANTLRAbstractToken *ptr_;
};
//typedef ANTLRTokenPtr _ANTLRTokenPtr;
/*
* Since you cannot redefine operator->() to return one of the user's
* token object types, we must down cast. This is a drag. Here's
* a macro that helps. template: "mytoken(a-smart-ptr)->myfield".
*/
#define mytoken(tk) ((ANTLRToken *)(tk.operator->()))
#endif

View File

@@ -0,0 +1,88 @@
/*
* ATokPtrImpl.h (formerly ATokPtr.cpp)
*
* This is #included in ATokBuffer.cpp for historical reasons.
* It has been renamed because of problems with the .cpp extension
* when used with IDE.
*
*
* ANTLRToken MUST be defined before entry to this file.
*
* 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.
*
* ANTLR 1.33
* Written by Russell Quong June 30, 1995
* Adapted by Terence Parr to ANTLR stuff
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
PCCTS_NAMESPACE_STD
#include "ATokPtr.h"
void ANTLRTokenPtr::ref() const
{
if (ptr_ != NULL) {
ptr_->ref();
}
}
void ANTLRTokenPtr::deref()
{
if (ptr_ != NULL)
{
ptr_->deref();
if ( ptr_->nref()==0 )
{
delete ptr_;
ptr_ = NULL;
}
}
}
ANTLRTokenPtr::~ANTLRTokenPtr()
{
deref();
}
//
// 8-Apr-97 MR1 Make operator -> a const member function
// as weall as some other member functions
//
void ANTLRTokenPtr::operator = (const ANTLRTokenPtr & lhs) // MR1
{
lhs.ref(); // protect against "xp = xp"; ie same underlying object
deref();
ptr_ = lhs.ptr_;
}
void ANTLRTokenPtr::operator = (ANTLRAbstractToken *addr)
{
if (addr != NULL) {
addr->ref();
}
deref();
ptr_ = addr;
}

View File

@@ -0,0 +1,325 @@
/* ANTLRToken.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ATOKEN_H_GATE
#define ATOKEN_H_GATE
#include "pcctscfg.h"
#include "pccts_string.h"
#include "pccts_stdio.h"
#include "pccts_stdlib.h"
#include "pccts_stdarg.h" // MR23
PCCTS_NAMESPACE_STD
// MR9 RJV (JVincent@novell.com) Not needed for variable length strings
//// MR9 #ifndef ANTLRCommonTokenTEXTSIZE
//// MR9 #define ANTLRCommonTokenTEXTSIZE 100
//// MR9 #endif
/* must define what a char looks like; can make this a class too */
typedef char ANTLRChar;
/* D E F I N E S M A R T P O I N T E R S */
//#include ATOKPTR_H not tested yet, leave out
class ANTLRAbstractToken;
typedef ANTLRAbstractToken *_ANTLRTokenPtr;
class ANTLRAbstractToken {
public:
virtual ~ANTLRAbstractToken() {;}
virtual ANTLRTokenType getType() const = 0;
virtual void setType(ANTLRTokenType t) = 0;
virtual int getLine() const = 0;
virtual void setLine(int line) = 0;
virtual ANTLRChar *getText() const = 0;
virtual void setText(const ANTLRChar *) = 0;
/* This function will disappear when I can use templates */
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,
ANTLRChar *text,
int line) = 0;
/* define to satisfy ANTLRTokenBuffer's need to determine whether or
not a token object can be destroyed. If nref()==0, no one has
a reference, and the object may be destroyed. This function defaults
to 1, hence, if you use deleteTokens() message with a token object
not derived from ANTLRCommonRefCountToken, the parser will compile
but will not delete objects after they leave the token buffer.
*/
virtual unsigned nref() const { return 1; } // MR11
virtual void ref() {;}
virtual void deref() {;}
virtual void panic(const char *msg) // MR20 const
{
/* MR23 */ printMessage(stderr, "ANTLRAbstractToken panic: %s\n", msg);
exit(PCCTS_EXIT_FAILURE);
}
virtual int printMessage(FILE* pFile, const char* pFormat, ...) // MR23
{
va_list marker;
va_start( marker, pFormat );
int iRet = vfprintf(pFile, pFormat, marker);
va_end( marker );
return iRet;
}
};
/* This class should be subclassed. It cannot store token type or text */
class ANTLRRefCountToken : public ANTLRAbstractToken {
public:
#ifdef DBG_REFCOUNTTOKEN
static int ctor;
static int dtor;
#endif
protected:
unsigned refcnt_;
#ifdef DBG_REFCOUNTTOKEN
char object[200];
#endif
public:
// MR23 - No matter what you do, you're hammered.
// Don't give names to formals something breaks.
// Give names to formals and don't use them it breaks.
#ifndef DBG_REFCOUNTTOKEN
ANTLRRefCountToken(ANTLRTokenType /* t MR23 */, const ANTLRChar * /* s MR23 */)
#else
ANTLRRefCountToken(ANTLRTokenType t, const ANTLRChar * s)
#endif
#ifndef DBG_REFCOUNTTOKEN
{
refcnt_ = 0;
}
#else
{
ctor++;
refcnt_ = 0;
if ( t==1 ) sprintf(object,"tok_EOF");
else sprintf(object,"tok_%s",s);
/* MR23 */ printMessage(stderr, "ctor %s #%d\n",object,ctor);
}
#endif
ANTLRRefCountToken()
#ifndef DBG_REFCOUNTTOKEN
{ refcnt_ = 0; }
#else
{
ctor++;
refcnt_ = 0;
sprintf(object,"tok_blank");
/* MR23 */ printMessage(stderr, "ctor %s #%d\n",object,ctor);
}
virtual ~ANTLRRefCountToken()
{
dtor++;
if ( dtor>ctor ) /* MR23 */ printMessage(stderr, "WARNING: dtor>ctor\n");
/* MR23 */ printMessage(stderr, "dtor %s #%d\n", object, dtor);
object[0]='\0';
}
#endif
// reference counting stuff needed by ANTLRTokenPtr.
// User should not access these; for C++ language reasons, we had
// to make these public. Yuck.
void ref() { refcnt_++; }
void deref() { refcnt_--; }
unsigned nref() const { return refcnt_; } // MR11
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType /*tt MR23*/,
ANTLRChar * /*txt MR23*/,
int /*line MR23*/)
{
panic("call to ANTLRRefCountToken::makeToken()\n");
return NULL;
}
};
class ANTLRCommonNoRefCountToken : public ANTLRAbstractToken {
protected:
ANTLRTokenType _type;
int _line;
ANTLRChar *_text; // MR9 RJV
public:
ANTLRCommonNoRefCountToken(ANTLRTokenType t, const ANTLRChar *s)
{ setType(t); _line = 0; _text = NULL; setText(s); }
ANTLRCommonNoRefCountToken()
{ setType((ANTLRTokenType)0); _line = 0; _text = NULL; setText(""); }
~ANTLRCommonNoRefCountToken() { if (_text) delete [] _text; } // MR9 RJV: Added Destructor to remove string
ANTLRTokenType getType() const { return _type; }
void setType(ANTLRTokenType t) { _type = t; }
virtual int getLine() const { return _line; }
void setLine(int line) { _line = line; }
ANTLRChar *getText() const { return _text; }
int getLength() const { return strlen(getText()); } // MR11
// MR9 RJV: Added code for variable length strings to setText()
void setText(const ANTLRChar *s)
{ if (s != _text) {
if (_text) delete [] _text;
if (s != NULL) {
_text = new ANTLRChar[strlen(s)+1];
if (_text == NULL) panic("ANTLRCommonNoRefCountToken::setText new failed");
strcpy(_text,s);
} else {
_text = new ANTLRChar[1];
if (_text == NULL) panic("ANTLRCommonNoRefCountToken::setText new failed");
strcpy(_text,"");
};
};
}
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,
ANTLRChar *txt,
int line)
{
ANTLRAbstractToken *t = new ANTLRCommonNoRefCountToken;
t->setType(tt); t->setText(txt); t->setLine(line);
return t;
}
// MR9 THM Copy constructor required when heap allocated string is used with copy semantics
ANTLRCommonNoRefCountToken (const ANTLRCommonNoRefCountToken& from) :
ANTLRAbstractToken(from) {
setType(from._type);
setLine(from._line);
_text=NULL;
setText(from._text);
};
// MR9 THM operator =() required when heap allocated string is used with copy semantics
virtual ANTLRCommonNoRefCountToken& operator =(const ANTLRCommonNoRefCountToken& rhs) {
////// MR15 WatCom can't hack use of operator =()
////// Use this: *( (ANTRLAbstractToken *) this)=rhs;
*( (ANTLRAbstractToken *) this ) = rhs;
setType(rhs._type);
setLine(rhs._line);
setText(rhs._text);
return *this;
};
};
class ANTLRCommonToken : public ANTLRRefCountToken {
protected:
ANTLRTokenType _type;
int _line;
ANTLRChar *_text; // MR9 RJV:Added
public:
ANTLRCommonToken(ANTLRTokenType t, const ANTLRChar *s) : ANTLRRefCountToken(t,s)
{ setType(t); _line = 0; _text = NULL; setText(s); } // MR9
ANTLRCommonToken()
{ setType((ANTLRTokenType)0); _line = 0; _text = NULL; setText(""); } // MR9
virtual ~ANTLRCommonToken() { if (_text) delete [] _text; } // MR9 RJV: Added Destructor to remove string
ANTLRTokenType getType() const { return _type; }
void setType(ANTLRTokenType t) { _type = t; }
virtual int getLine() const { return _line; }
void setLine(int line) { _line = line; }
ANTLRChar *getText() const { return _text; }
int getLength() const { return strlen(getText()); } // MR11
// MR9 RJV: Added code for variable length strings to setText()
void setText(const ANTLRChar *s)
{ if (s != _text) {
if (_text) delete [] _text;
if (s != NULL) {
_text = new ANTLRChar[strlen(s)+1];
if (_text == NULL) panic("ANTLRCommonToken::setText new failed");
strcpy(_text,s);
} else {
_text = new ANTLRChar[1];
if (_text == NULL) panic("ANTLRCommonToken::setText new failed");
strcpy(_text,"");
};
};
}
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,
ANTLRChar *txt,
int line)
{
ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt);
t->setLine(line);
return t;
}
// MR9 THM Copy constructor required when heap allocated string is used with copy semantics
ANTLRCommonToken (const ANTLRCommonToken& from) :
ANTLRRefCountToken(from) {
setType(from._type);
setLine(from._line);
_text=NULL;
setText(from._text);
};
// MR9 THM operator =() required when heap allocated string is used with copy semantics
virtual ANTLRCommonToken& operator =(const ANTLRCommonToken& rhs) {
////// MR15 WatCom can't hack use of operator =()
////// Use this instead: *( (ANTRLRRefCountToken *) this)=rhs;
*( (ANTLRRefCountToken *) this) = rhs;
setType(rhs._type);
setLine(rhs._line);
setText(rhs._text);
return *this;
};
};
// used for backward compatibility
typedef ANTLRCommonToken ANTLRCommonBacktrackingToken;
#endif

View File

@@ -0,0 +1,374 @@
/* ANTLRTokenBuffer.cpp
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
typedef int ANTLRTokenType; // fool AToken.h into compiling
class ANTLRParser; /* MR1 */
#define ANTLR_SUPPORT_CODE
#include "pcctscfg.h"
#include ATOKENBUFFER_H
#include APARSER_H // MR23
typedef ANTLRAbstractToken *_ANTLRTokenPtr;
#if defined(DBG_TBUF)||defined(DBG_TBUF_MARK_REW)
static unsigned char test[1000];
#endif
#ifdef DBG_REFCOUNTTOKEN
int ANTLRRefCountToken::ctor = 0; /* MR23 */
int ANTLRRefCountToken::dtor = 0; /* MR23 */
#endif
ANTLRTokenBuffer::
ANTLRTokenBuffer(ANTLRTokenStream *_input, int _k, int _chunk_size_formal) /* MR14 */
{
this->input = _input;
this->k = _k;
buffer_size = chunk_size = _chunk_size_formal;
buffer = (_ANTLRTokenPtr *)
calloc(chunk_size+1,sizeof(_ANTLRTokenPtr ));
if ( buffer == NULL ) {
panic("cannot alloc token buffer");
}
buffer++; // leave the first elem empty so tp-1 is valid ptr
tp = &buffer[0];
last = tp-1;
next = &buffer[0];
num_markers = 0;
end_of_buffer = &buffer[buffer_size-1];
threshold = &buffer[(int)(buffer_size/2)]; // MR23 - Used to be 1.0/2.0 !
_deleteTokens = 1; // assume we delete tokens
parser=NULL; // MR5 - uninitialized reference
}
static void f() {;}
ANTLRTokenBuffer::
~ANTLRTokenBuffer()
{
f();
// Delete all remaining tokens (from 0..last inclusive)
if ( _deleteTokens )
{
_ANTLRTokenPtr *z;
for (z=buffer; z<=last; z++)
{
(*z)->deref();
// z->deref();
#ifdef DBG_REFCOUNTTOKEN
/* MR23 */ printMessage(stderr, "##########dtor: deleting token '%s' (ref %d)\n",
((ANTLRCommonToken *)*z)->getText(), (*z)->nref());
#endif
if ( (*z)->nref()==0 )
{
delete (*z);
}
}
}
if ( buffer!=NULL ) free((char *)(buffer-1));
}
#if defined(DBG_TBUF)||defined(DBG_TBUF_MARK_REW)
#include "pccts_stdio.h"
PCCTS_NAMESPACE_STD
#endif
_ANTLRTokenPtr ANTLRTokenBuffer::
getToken()
{
if ( tp <= last ) // is there any buffered lookahead still to be read?
{
return *tp++; // read buffered lookahead
}
// out of buffered lookahead, get some more "real"
// input from getANTLRToken()
if ( num_markers==0 )
{
if( next > threshold )
{
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr,"getToken: next > threshold (high water is %d)\n", threshold-buffer);
#endif
makeRoom();
}
}
else {
if ( next > end_of_buffer )
{
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr,"getToken: next > end_of_buffer (size is %d)\n", buffer_size);
#endif
extendBuffer();
}
}
*next = getANTLRToken();
(*next)->ref(); // say we have a copy of this pointer in buffer
last = next;
next++;
tp = last;
return *tp++;
}
void ANTLRTokenBuffer::
rewind(int pos)
{
#if defined(DBG_TBUF)||defined(DBG_TBUF_MARK_REW)
/* MR23 */ printMessage(stderr, "rewind(%d)[nm=%d,from=%d,%d.n=%d]\n", pos, num_markers, tp-buffer,pos,test[pos]);
test[pos]--;
#endif
tp = &buffer[pos];
num_markers--;
}
/*
* This function is used to specify that the token pointers read
* by the ANTLRTokenBuffer should be buffered up (to be reused later).
*/
int ANTLRTokenBuffer::
mark()
{
#if defined(DBG_TBUF)||defined(DBG_TBUF_MARK_REW)
test[tp-buffer]++;
/* MR23 */ printMessage(stderr,"mark(%d)[nm=%d,%d.n=%d]\n",tp-buffer,num_markers+1,tp-buffer,test[tp-buffer]);
#endif
num_markers++;
return tp - buffer;
}
/*
* returns the token pointer n positions ahead.
* This implies that bufferedToken(1) gets the NEXT symbol of lookahead.
* This is used in conjunction with the ANTLRParser lookahead buffer.
*
* No markers are set or anything. A bunch of input is buffered--that's all.
* The tp pointer is left alone as the lookahead has not been advanced
* with getToken(). The next call to getToken() will find a token
* in the buffer and won't have to call getANTLRToken().
*
* If this is called before a consume() is done, how_many_more_i_need is
* set to 'n'.
*/
_ANTLRTokenPtr ANTLRTokenBuffer::
bufferedToken(int n)
{
// int how_many_more_i_need = (last-tp < 0) ? n : n-(last-tp)-1;
int how_many_more_i_need = (tp > last) ? n : n-(last-tp)-1;
// Make sure that at least n tokens are available in the buffer
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, "bufferedToken(%d)\n", n);
#endif
for (int i=1; i<=how_many_more_i_need; i++)
{
if ( next > end_of_buffer ) // buffer overflow?
{
extendBuffer();
}
*next = getANTLRToken();
(*next)->ref(); // say we have a copy of this pointer in buffer
last = next;
next++;
}
return tp[n - 1];
}
/* If no markers are set, the none of the input needs to be saved (except
* for the lookahead Token pointers). We save only k-1 token pointers as
* we are guaranteed to do a getANTLRToken() right after this because otherwise
* we wouldn't have needed to extend the buffer.
*
* If there are markers in the buffer, we need to save things and so
* extendBuffer() is called.
*/
void ANTLRTokenBuffer::
makeRoom()
{
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, "in makeRoom.................\n");
/* MR23 */ printMessage(stderr, "num_markers==%d\n", num_markers);
#endif
/*
if ( num_markers == 0 )
{
*/
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, "moving lookahead and resetting next\n");
_ANTLRTokenPtr *r;
/* MR23 */ printMessage(stderr, "tbuf = [");
for (r=buffer; r<=last; r++)
{
if ( *r==NULL ) /* MR23 */ printMessage(stderr, " xxx");
else /* MR23 */ printMessage(stderr, " '%s'", ((ANTLRCommonToken *)*r)->getText());
}
/* MR23 */ printMessage(stderr, " ]\n");
/* MR23 */ printMessage(stderr,
"before: tp=%d, last=%d, next=%d, threshold=%d\n",tp-buffer,last-buffer,next-buffer,threshold-buffer);
#endif
// Delete all tokens from 0..last-(k-1) inclusive
if ( _deleteTokens )
{
_ANTLRTokenPtr *z;
for (z=buffer; z<=last-(k-1); z++)
{
(*z)->deref();
// z->deref();
#ifdef DBG_REFCOUNTTOKEN
/* MR23 */ printMessage(stderr, "##########makeRoom: deleting token '%s' (ref %d)\n",
((ANTLRCommonToken *)*z)->getText(), (*z)->nref());
#endif
if ( (*z)->nref()==0 )
{
delete (*z);
}
}
}
// reset the buffer to initial conditions, but move k-1 symbols
// to the beginning of buffer and put new input symbol at k
_ANTLRTokenPtr *p = buffer, *q = last-(k-1)+1;
// ANTLRAbstractToken **p = buffer, **q = end_of_buffer-(k-1)+1;
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, "lookahead buffer = [");
#endif
for (int i=1; i<=(k-1); i++)
{
*p++ = *q++;
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr,
" '%s'", ((ANTLRCommonToken *)buffer[i-1])->getText());
#endif
}
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, " ]\n");
#endif
next = &buffer[k-1];
tp = &buffer[k-1]; // tp points to what will be filled in next
last = tp-1;
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr,
"after: tp=%d, last=%d, next=%d\n",
tp-buffer, last-buffer, next-buffer);
#endif
/*
}
else {
extendBuffer();
}
*/
}
/* This function extends 'buffer' by chunk_size and returns with all
* pointers at the same relative positions in the buffer (the buffer base
* address could have changed in realloc()) except that 'next' comes
* back set to where the next token should be stored. All other pointers
* are untouched.
*/
void
ANTLRTokenBuffer::
extendBuffer()
{
int save_last = last-buffer, save_tp = tp-buffer, save_next = next-buffer;
#ifdef DBG_TBUF
/* MR23 */ printMessage(stderr, "extending physical buffer\n");
#endif
buffer_size += chunk_size;
buffer = (_ANTLRTokenPtr *)
realloc((char *)(buffer-1),
(buffer_size+1)*sizeof(_ANTLRTokenPtr ));
if ( buffer == NULL ) {
panic("cannot alloc token buffer");
}
buffer++; // leave the first elem empty so tp-1 is valid ptr
tp = buffer + save_tp; // put the pointers back to same relative position
last = buffer + save_last;
next = buffer + save_next;
end_of_buffer = &buffer[buffer_size-1];
threshold = &buffer[(int)(buffer_size*(1.0/2.0))];
/*
// zero out new token ptrs so we'll know if something to delete in buffer
ANTLRAbstractToken **p = end_of_buffer-chunk_size+1;
for (; p<=end_of_buffer; p++) *p = NULL;
*/
}
ANTLRParser * ANTLRTokenBuffer:: // MR1
setParser(ANTLRParser *p) { // MR1
ANTLRParser *old=parser; // MR1
parser=p; // MR1
input->setParser(p); // MR1
return old; // MR1
} // MR1
// MR1
ANTLRParser * ANTLRTokenBuffer:: // MR1
getParser() { // MR1
return parser; // MR1
} // MR1
void ANTLRTokenBuffer::panic(const char *msg) // MR23
{
if (parser) //MR23
parser->panic(msg); //MR23
else //MR23
exit(PCCTS_EXIT_FAILURE);
}
//MR23
int ANTLRTokenBuffer::printMessage(FILE* pFile, const char* pFormat, ...)
{
va_list marker;
va_start( marker, pFormat );
int iRet = 0;
if (parser)
parser->printMessageV(pFile, pFormat, marker);
else
iRet = vfprintf(pFile, pFormat, marker);
va_end( marker );
return iRet;
}
/* to avoid having to link in another file just for the smart token ptr
* stuff, we include it here. Ugh.
*
* MR23 This causes nothing but problems for IDEs.
* Change from .cpp to .h
*
*/
#include ATOKPTR_IMPL_H

View File

@@ -0,0 +1,109 @@
/* ANTLRTokenBuffer.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ATOKENBUFFER_H_GATE
#define ATOKENBUFFER_H_GATE
#include "pcctscfg.h"
#include "pccts_stdlib.h"
PCCTS_NAMESPACE_STD
#include ATOKEN_H
#include ATOKENSTREAM_H
/*
* The parser is "attached" to an ANTLRTokenBuffer via interface
* functions: getToken() and bufferedToken(). The object that actually
* consumes characters and constructs tokens is connected to the
* ANTLRTokenBuffer via interface function ANTLRTokenStream::getToken();
* where ANTLRTokenStream is really just a behavior (class with no data).
* C++ does not have this abstraction and hence we simply have come up
* with a fancy name for "void *". See the note in ANTLRTokenStream.h on
* the "behavior" of ANTLRTokenStream.
*/
class ANTLRParser; // MR1
class DllExportPCCTS ANTLRTokenBuffer {
protected:
ANTLRTokenStream *input; // where do I get tokens
int buffer_size;
int chunk_size;
int num_markers;
int k; // Need at least this many tokens in buffer
_ANTLRTokenPtr *buffer; // buffer used for arbitrary lookahead
_ANTLRTokenPtr *tp; // pts into buffer; current token ptr
_ANTLRTokenPtr *last; // pts to last valid token in buffer
_ANTLRTokenPtr *next; // place to put token from getANTLRToken()
_ANTLRTokenPtr *end_of_buffer;
/* when you try to write a token past this and there are no markers
set, then move k-1 tokens back to the beginning of the buffer.
We want to stay away from the end of the buffer because we have
to extend it if a marker is set and we reach the end (we cannot
move tokens to the beginning of the buffer in this case).
*/
_ANTLRTokenPtr *threshold;
unsigned char _deleteTokens;
// This function is filled in by the subclass; it initiates fetch of input
virtual _ANTLRTokenPtr getANTLRToken() { return input->getToken(); }
void makeRoom();
void extendBuffer();
public:
ANTLRTokenBuffer(ANTLRTokenStream *in, int k=1, int chksz=50);
virtual ~ANTLRTokenBuffer();
virtual _ANTLRTokenPtr getToken();
virtual void rewind(int pos);
virtual int mark();
virtual _ANTLRTokenPtr bufferedToken(int i);
void noGarbageCollectTokens() { _deleteTokens=0; }
void garbageCollectTokens() { _deleteTokens=1; }
virtual int bufferSize() { return buffer_size; }
virtual int minTokens() { return k; }
virtual void setMinTokens(int k_new) { k = k_new; }
virtual void panic(const char *msg); /* MR20 const */
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
protected: // MR1
ANTLRParser *parser; // MR1
public: // MR1
ANTLRParser *setParser(ANTLRParser *p); // MR1
ANTLRParser *getParser(); // MR1
ANTLRTokenStream *getLexer() const { // MR12
return input;} // MR12
};
#endif

View File

@@ -0,0 +1,51 @@
/* ANTLRTokenStream.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ATOKENSTREAM_H_GATE
#define ATOKENSTREAM_H_GATE
#include "pcctscfg.h"
/* This is really a behavior or protocol; it merely indicates the behavior
* required of the input and output of an ANTLRTokenBuffer. You could
* subclass it, but you can also just pass any old pointer to ANTLRTokenBuffer
* with a type cast (in which case, your getANTLRToken() would have to
* explicitly cast the input pointer to your REAL type (typically your lexer)).
*/
class ANTLRParser; // MR1
class DllExportPCCTS ANTLRTokenStream {
public:
virtual _ANTLRTokenPtr getToken() = 0;
virtual ANTLRParser * setParser(ANTLRParser * /*p MR23*/) {return 0; }; // MR12
virtual ANTLRParser * getParser() { return 0; }; // MR12
};
#endif

View File

@@ -0,0 +1,100 @@
// FILE: BufFileInput.cpp
// AUTHOR: Alexey Demakov (AVD) demakov@kazbek.ispras.ru
// CREATION: 26-JAN-1998
// DESCRIPTION: File Input Stream with lookahead for Scanner.
// See file BufFileInput.h for details
// Change History:
//
// 22-Jun-1998 assert.h -> PCCTS_ASSERT_H
// string.h -> PCCTS_STRING_H
//
// 28-May-1998 Add virtual destructor to release buffer.
//
// Add dummy definition for ANTLRTokenType
// to allow compilation without knowing
// token type codes.
//
// Manfred Kogler (km@cast.uni-linz.ac.at)
// (1.33MR14)
//
// 20-Jul-1998 MR14a - Reorder initialization list for ctor.
//
enum ANTLRTokenType {TER_HATES_CPP=0, SO_DO_OTHERS=9999 };
#include "pcctscfg.h"
#include "pccts_assert.h"
#include "pccts_string.h"
PCCTS_NAMESPACE_STD
#include "BufFileInput.h"
BufFileInput::BufFileInput( FILE *f, int buf_size )
: input( f ),
buf( new int[buf_size] ),
size( buf_size ),
start( 0 ),
len( 0 )
{
}
BufFileInput::~BufFileInput()
{
delete [] buf;
}
int BufFileInput::nextChar( void )
{
if( len > 0 )
{
// get char from buffer
int c = buf[start];
if( c != EOF )
{
start++; start %= size;
len--;
}
return c;
} else {
// get char from file
int c = getc( input );
if( c == EOF )
{
// if EOF - put it in the buffer as indicator
buf[start] = EOF;
len++;
}
return c;
}
}
int BufFileInput::lookahead( char* s )
{
int l = strlen( s );
assert( 0 < l && l <= size );
while( len < l )
{
int c = getc( input );
buf[ (start+len) % size ] = c;
len++;
if( c == EOF ) return 0;
}
for( int i = 0; i < l; i++ )
{
if( s[i] != buf[ (start+i) % size ] ) return 0;
}
return 1;
}
// End of file BufFileInput.cpp

View File

@@ -0,0 +1,53 @@
// FILE: BufFileInput.h
// AUTHOR: Alexey Demakov (AVD) demakov@kazbek.ispras.ru
// CREATION: 26-JAN-1998
// DESCRIPTION: File Input Stream with lookahead for Scanner
// Tested under Win32 with ANTLR 1.33 MR10 and MSVC 5.0
// Change History:
//
// 28-May-1998 Add virtual destructor to release buffer
// Manfred Kogler (km@cast.uni-linz.ac.at)
// (1.33MR14)
#ifndef BufFileInput_h
#define BufFileInput_h
#include "pcctscfg.h"
#include "pccts_stdio.h"
PCCTS_NAMESPACE_STD
#include "DLexerBase.h"
class DllExportPCCTS BufFileInput : public DLGInputStream
{
public:
// constructor
// f - input stream
// buf_size - size of buffer (maximal length for string in is_in)
BufFileInput(FILE *f, int buf_size = 8 );
virtual ~BufFileInput();
// gets next char from stream
virtual int nextChar( void );
// looks in stream and compares next l characters with s
// returns the result of comparision
int lookahead( char* s );
private:
FILE *input; // input stream;
int* buf; // buffer
int size; // size of buffer
int start; // position of the first symbol in buffer
int len; // count of characters in buffers
};
#endif
// end of file BufFileInput.h

View File

@@ -0,0 +1,98 @@
/************************************************************/
/* */
/* Predefined char stream: Input from (c++) stream. */
/* */
/* By Hubert Holin (Hubert.Holin@Bigfoot.com), 1998. */
/* */
/* This is completely free stuff, do whatever you want with */
/* it (but then, I will take no responsability for whatever */
/* may happen if you do either... caveat emptor!). */
/* */
/************************************************************/
#ifndef _DLG_STREAM_INPUT_H
#define _DLG_STREAM_INPUT_H
#include "pccts_istream.h"
PCCTS_NAMESPACE_STD
#ifndef DLGX_H
#include "DLexerBase.h"
#endif
// NOTES: The semantics of the copy constructor
// and the affectation operator may be unwaranted...
// and the stream may not be reset.
//
// It would have been so much nicer for nextChar()
// to throw (of for the DLGInputStream to change status)
// upon hiting EOF than to return an "int"...
template <
class E,
class T = ::std::char_traits<E>
>
class DLG_stream_input : public DLGInputStream
{
public:
DLG_stream_input(::std::basic_istream<E,T> * p_input_stream)
: input(p_input_stream)
{
// nothing to do!
};
DLG_stream_input(const DLG_stream_input & a_recopier)
: input(a_recopier.input)
{
// nothing to do!
};
virtual ~DLG_stream_input()
{
this->purge(); // bloody templarized lookup...
};
DLG_stream_input operator = (const DLG_stream_input & a_affecter)
{
if (this != &a_affecter)
{
input = a_affecter.input;
}
return(*this);
};
virtual int nextChar()
{
E extracted_stuff;
input->get(extracted_stuff);
if (*input)
{
return(int(extracted_stuff));
}
else
{
return(EOF);
}
};
protected:
::std::basic_istream<E,T> * input;
private:
void purge()
{
// nothing to do!
};
};
#endif /* _DLG_STREAM_INPUT_H */

View File

@@ -0,0 +1,191 @@
/* DLexer.h (formerly DLexer.cpp)
*
* This was renamed because the use of the .cpp extension caused problems
* with IDEs.
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#define ZZINC {if ( track_columns ) (++_endcol);}
#define ZZGETC {ch = input->nextChar(); cl = ZZSHIFT(ch);}
#define ZZNEWSTATE (newstate = dfa[state][cl])
#ifndef ZZCOPY
#define ZZCOPY \
/* Truncate matching buffer to size (not an error) */ \
if (nextpos < lastpos){ \
*(nextpos++) = ch; \
}else{ \
bufovf = 1; \
}
#endif
void DLGLexer::
mode( int m )
{
/* points to base of dfa table */
if (m<MAX_MODE){
automaton = m;
/* have to redo class since using different compression */
cl = ZZSHIFT(ch);
}else{
sprintf((char *)ebuf,"Invalid automaton mode = %d ",m);
errstd(ebuf);
}
}
ANTLRTokenType DLGLexer::
nextTokenType(void)
{
register int state, newstate;
/* last space reserved for the null char */
register DLGChar *lastpos;
ANTLRTokenType tk;
skip:
bufovf = 0;
lastpos = &_lextext[_bufsize-1];
nextpos = _lextext;
_begcol = _endcol+1;
more:
_begexpr = nextpos;
if ( interactive ) {
/* interactive version of automaton */
/* if there is something in ch, process it */
state = newstate = dfa_base[automaton];
if (charfull){
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
while (alternatives[newstate]){
state = newstate;
ZZGETC;
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
/* figure out if last character really part of token */
if ((state != dfa_base[automaton]) && (newstate == DfaStates)){
charfull = 1;
--nextpos;
}else{
charfull = 0;
state = newstate;
}
*(nextpos) = '\0';
/* Able to transition out of start state to some non err state?*/
if ( state == dfa_base[automaton] ){
/* make sure doesn't get stuck */
advance();
}
}
else { /* non-interactive version of automaton */
if (!charfull)
advance();
else
ZZINC;
state = dfa_base[automaton];
while (ZZNEWSTATE != DfaStates) {
state = newstate;
ZZCOPY;
ZZGETC;
ZZINC;
}
charfull = 1;
if ( state == dfa_base[automaton] ){
if (nextpos < lastpos){
*(nextpos++) = ch;
}else{
bufovf = 1;
}
*nextpos = '\0';
/* make sure doesn't get stuck */
advance();
}else{
*nextpos = '\0';
}
}
if ( track_columns ) _endcol -= charfull;
_endexpr = nextpos -1;
add_erase = 0;
#ifdef OLD
tk = (ANTLRTokenType)
(*actions[accepts[state]])(this); // must pass this manually
// actions is not a [] of pointers
// to member functions.
#endif
tk = (this->*actions[accepts[state]])();
// MR1
// MR1 11-Apr-97 Help for tracking DLG results
// MR1
#ifdef DEBUG_LEXER
/* MR1 */ if (debugLexerFlag) {
/* MR1 */ if (parser != NULL) {
/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken name=%s",parser->parserTokenName(tk));
/* MR1 */ } else {
/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken nnumber=%d",tk);
/* MR1 */ };
/* MR1 */ /* MR23 */ printMessage(stdout, " lextext=(%s) mode=%d",
/* MR1 */ (_lextext[0]=='\n' && _lextext[1]==0) ?
/* MR1 */ "newline" : _lextext,
/* MR1 */ automaton);
/* MR1 */ if (interactive && !charfull) {
/* MR1 */ /* MR23 */ printMessage(stdout, " char=empty");
/* MR1 */ } else {
/* MR1 */ if (ch=='\n') {
/* MR1 */ /* MR23 */ printMessage(stdout, " char=newline");
/* MR1 */ } else {
/* MR1 */ /* MR23 */ printMessage(stdout, " char=(%c)",ch);
/* MR1 */ };
/* MR1 */ };
/* MR1 */ /* MR23 */ printMessage(stdout, " %s\n",
/* MR1 */ (add_erase==1 ? "skip()" :
/* MR1 */ add_erase==2 ? "more()" :
/* MR1 */ ""));
/* MR1 */ };
#endif
switch (add_erase) {
case 1: goto skip;
case 2: goto more;
}
return tk;
}
void DLGLexer::
advance()
{
if ( input==NULL ) err_in();
ZZGETC; charfull = 1; ZZINC;
}

View File

@@ -0,0 +1,302 @@
/* DLGLexerBase.c
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_stdlib.h"
PCCTS_NAMESPACE_STD
/* I have to put this here due to C++ limitation
* that you can't have a 'forward' decl for enums.
* I hate C++!!!!!!!!!!!!!!!
*/
// MR1
// MR1 10-Apr-97 133MR1 Prevent use of varying sizes for the
// MR1 ANTLRTokenType enum
// MR1
enum ANTLRTokenType { TER_HATES_CPP=0, ITS_UTTER_GARBAGE, // MR1
WITH_SOME_GOOD_IDEAS=9999}; // MR1
#define ANTLR_SUPPORT_CODE
#include "pcctscfg.h"
#include DLEXERBASE_H
#include APARSER_H // MR23
DLGLexerBase::
DLGLexerBase(DLGInputStream *in,
unsigned bufsize,
int _interactive,
int _track_columns)
{
this->_bufsize = bufsize;
this->_lextext = new DLGChar[_bufsize];
if ( this->_lextext==NULL ) {
panic("text buffer is NULL");
}
this->_begexpr = this->_endexpr = NULL;
this->ch = this->bufovf = 0;
this->nextpos = NULL;
this->cl = 0;
this->add_erase = 0;
this->input = in;
this->_begcol = 0;
this->_endcol = 0;
this->_line = 1;
this->charfull = 0;
this->automaton = 0;
this->token_to_fill = NULL;
this->interactive = _interactive;
this->track_columns = _track_columns;
this->debugLexerFlag = 0; // MR1
this->parser = NULL; // MR1
this->lexErrCount=0; // MR11
}
// MR19 THM
void DLGLexerBase::reset()
{
this->charfull = 0;
this->_begcol = 0;
this->_endcol = 0;
this->automaton = 0;
this->_line=1;
this->lexErrCount=0;
}
void DLGLexerBase::
setInputStream( DLGInputStream *in )
{
this->input = in;
_line = 1;
charfull = 0;
}
/* saves dlg state, but not what feeds dlg (such as file position) */
void DLGLexerBase::
saveState(DLGState *state)
{
state->input = input;
state->interactive = interactive;
state->track_columns = track_columns;
state->auto_num = automaton;
state->add_erase = add_erase;
state->lookc = ch;
state->char_full = charfull;
state->begcol = _begcol;
state->endcol = _endcol;
state->line = _line;
state->lextext = _lextext;
state->begexpr = _begexpr;
state->endexpr = _endexpr;
state->bufsize = _bufsize;
state->bufovf = bufovf;
state->nextpos = nextpos;
state->class_num = cl;
state->debugLexerFlag = debugLexerFlag; // MR1
state->parser = parser; // MR1
}
void DLGLexerBase::
restoreState(DLGState *state)
{
input = state->input;
interactive = state->interactive;
track_columns = state->track_columns;
automaton = state->auto_num;
add_erase = state->add_erase;
ch = state->lookc;
charfull = state->char_full;
_begcol = state->begcol;
_endcol = state->endcol;
_line = state->line;
_lextext = state->lextext;
_begexpr = state->begexpr;
_endexpr = state->endexpr;
_bufsize = state->bufsize;
bufovf = state->bufovf;
nextpos = state->nextpos;
cl = state->class_num;
debugLexerFlag = state->debugLexerFlag; // MR1
parser = state->parser; // MR1
}
/* erase what is currently in the buffer, and get a new reg. expr */
void DLGLexerBase::
skip()
{
add_erase = 1;
}
/* don't erase what is in the lextext buffer, add on to it */
void DLGLexerBase::
more()
{
add_erase = 2;
}
/* substitute c for the reg. expr last matched and is in the buffer */
void DLGLexerBase::
replchar(DLGChar c)
{
/* can't allow overwriting null at end of string */
if (_begexpr < &_lextext[_bufsize-1]){
*_begexpr = c;
*(_begexpr+1) = '\0';
}
_endexpr = _begexpr;
if (c != '\0') {
nextpos = _begexpr + 1;
}
else {
nextpos = _begexpr; /* MR30 Zero terminates string. */
}
}
/* replace the string s for the reg. expr last matched and in the buffer */
#ifdef _MSC_VER // MR23
//Turn off "assignment within conditional expression" warning
#pragma warning(disable : 4706)
#endif
void DLGLexerBase::
replstr(const DLGChar *s) /* MR20 const */
{
register DLGChar *l= &_lextext[_bufsize -1];
nextpos = _begexpr;
if (s){
while ((nextpos <= l) && (*(nextpos++) = *(s++))){
/* empty */
}
/* correct for NULL at end of string */
nextpos--;
}
if ((nextpos <= l) && (*(--s) == 0)){
bufovf = 0;
}else{
bufovf = 1;
}
*(nextpos) = '\0';
_endexpr = nextpos - 1;
}
#ifdef _MSC_VER // MR23
#pragma warning(default: 4706)
#endif
void DLGLexerBase::
errstd(const char *s) /* MR20 const */
{
lexErrCount++; /* MR11 */
/* MR23 */ printMessage(stderr,
"%s near line %d (text was '%s')\n",
((s == NULL) ? "Lexical error" : s),
_line,_lextext);
}
int DLGLexerBase::
err_in()
{
/* MR23 */ printMessage(stderr,"No input stream, function, or string\n");
/* return eof to get out gracefully */
return EOF;
}
ANTLRTokenType DLGLexerBase::
erraction()
{
errstd("invalid token");
advance();
skip();
return (ANTLRTokenType) 0; // bogus, but satisfies compiler
}
_ANTLRTokenPtr DLGLexerBase::
getToken()
{
if ( token_to_fill==NULL ) panic("NULL token_to_fill");
ANTLRTokenType tt = nextTokenType();
_ANTLRTokenPtr tk = token_to_fill->makeToken(tt, _lextext,_line);
return tk;
}
void DLGLexerBase::
panic(const char *msg) /* MR20 const */
{
if (parser) //MR23
parser->panic(msg); //MR23
else //MR23
{
/* MR23 */ printMessage(stderr, "DLG panic: %s\n", msg);
//
// 7-Apr-97 133MR1
//
exit(PCCTS_EXIT_FAILURE); // MR1
}
}
ANTLRParser * DLGLexerBase:: // MR1
setParser(ANTLRParser *p) { // MR1
ANTLRParser *oldValue=parser; // MR1
parser=p; // MR1
return oldValue; // MR1
} // MR1
// MR1
ANTLRParser * DLGLexerBase:: // MR1
getParser() { // MR1
return parser; // MR1
} // MR1
// MR1
int DLGLexerBase:: // MR1
debugLexer(int newValue) { // MR1
int oldValue=debugLexerFlag; // MR1
debugLexerFlag=newValue; // MR1
return oldValue; // MR1
} // MR1
//MR23
int DLGLexerBase::printMessage(FILE* pFile, const char* pFormat, ...)
{
va_list marker;
va_start( marker, pFormat );
int iRet = 0;
if (parser)
parser->printMessageV(pFile, pFormat, marker);
else
iRet = vfprintf(pFile, pFormat, marker);
va_end( marker );
return iRet;
}

View File

@@ -0,0 +1,198 @@
/* DLGLexerBase.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef DLGX_H
#define DLGX_H
#include "pcctscfg.h"
#include "pccts_stdio.h"
PCCTS_NAMESPACE_STD
#include ATOKEN_H
#include ATOKENSTREAM_H
class ANTLRParser; // MR1
/* must define what a char looks like; can make this a class too */
typedef char DLGChar;
/* Can have it as a class too: (ack this looks weird; is it right?)
class DllExportPCCTS DLGChar {
private:
int c;
public:
DLGChar(int ch) { c = ch; }
int atom() { return c; }
};
*/
/* user must subclass this */
class DllExportPCCTS DLGInputStream {
public:
virtual int nextChar() = 0;
};
/* Predefined char stream: Input from FILE */
class DllExportPCCTS DLGFileInput : public DLGInputStream {
private:
int found_eof;
FILE *input;
public:
DLGFileInput(FILE *f) { input = f; found_eof = 0; }
int nextChar() {
int c;
if ( found_eof ) return EOF;
else {
c=getc(input);
if ( c==EOF ) found_eof = 1;
return c;
}
}
void DLGFileReset(FILE *f) {input=f; found_eof = 0; }; // MR11
};
// MR9 Suggested by Bruce Guenter (bruceg@qcc.sk.ca)
// MR9 Make DLGStringInput const correct
/* Predefined char stream: Input from string */
class DllExportPCCTS DLGStringInput : public DLGInputStream {
private:
const DLGChar *input; // MR9
const DLGChar *p; // MR9
public:
DLGStringInput(const DLGChar *s) { input = s; p = &input[0];} // MR9
int nextChar()
{
if (*p) return (int) (unsigned char) *p++; // MR14
else return EOF;
}
void DLGStringReset(const DLGChar *s) {input=s; p= &input[0]; }; // MR11 // MR16
};
class DllExportPCCTS DLGState {
public:
DLGInputStream *input;
int interactive;
int track_columns;
int auto_num;
int add_erase;
int lookc;
int char_full;
int begcol, endcol;
int line;
DLGChar *lextext, *begexpr, *endexpr;
int bufsize;
int bufovf;
DLGChar *nextpos;
int class_num;
int debugLexerFlag; // MR1
ANTLRParser *parser; // MR1
};
/* user must subclass this */
class DllExportPCCTS DLGLexerBase : public ANTLRTokenStream {
public:
virtual ANTLRTokenType erraction();
protected:
DLGInputStream *input;
int interactive;
int track_columns;
DLGChar *_lextext; /* text of most recently matched token */
DLGChar *_begexpr; /* beginning of last reg expr recogn. */
DLGChar *_endexpr; /* beginning of last reg expr recogn. */
int _bufsize; /* number of characters in lextext */
int _begcol; /* column that first character of token is in*/
int _endcol; /* column that last character of token is in */
int _line; /* line current token is on */
int ch; /* character to determine next state */
int bufovf; /* indicates that buffer too small for text */
int charfull;
DLGChar *nextpos; /* points to next available position in lextext*/
int cl;
int automaton;
int add_erase;
DLGChar ebuf[70];
_ANTLRTokenPtr token_to_fill;
int debugLexerFlag; // MR1
ANTLRParser *parser; // MR1
public:
virtual _ANTLRTokenPtr getToken(); // MR12 public
virtual void advance(void) = 0;
void skip(void); /* erase lextext, look for antoher token */
void more(void); /* keep lextext, look for another token */
void mode(int k); /* switch to automaton 'k' */
void saveState(DLGState *);
void restoreState(DLGState *);
virtual ANTLRTokenType nextTokenType(void)=0;/* get next token */
void replchar(DLGChar c); /* replace last recognized reg. expr. with
a character */
void replstr(const DLGChar *s); /* replace last recognized reg. expr. with
a string */ /* MR20 const */
virtual int err_in(); // MR1
virtual void errstd(const char *); // MR1 MR20 const
int line() { return _line; }
void set_line(int newValue) { _line=newValue; }; // MR1
virtual void newline() { _line++; }
DLGChar *lextext() { return _lextext; }
int begcol() { return _begcol; }
int endcol() { return _endcol; }
void set_begcol(int a) { _begcol=a; }
void set_endcol(int a) { _endcol=a; }
DLGChar *begexpr() { return _begexpr; }
DLGChar *endexpr() { return _endexpr; }
int bufsize() { return _bufsize; }
void setToken(ANTLRAbstractToken *t) { token_to_fill = t; }
void setInputStream(DLGInputStream *);
DLGLexerBase(DLGInputStream *in,
unsigned bufsize=2000,
int interactive=0,
int track_columns=0);
void reset(); // MR19
virtual ~DLGLexerBase() { delete [] _lextext; }
virtual void panic(const char *msg); // MR1 MR20 const
void trackColumns() {
track_columns = 1;
this->_begcol = 0;
this->_endcol = 0;
};
virtual ANTLRParser *setParser(ANTLRParser *p); // MR1
virtual ANTLRParser *getParser(); // MR1
virtual int debugLexer(int value); // MR1
int lexErrCount; // MR12
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
};
#endif

View File

@@ -0,0 +1,134 @@
#ifndef PBLACKBOX_H
#define PBLACKBOX_H
/*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
/* Completely rewritten by Chris Uzdavinis (chris@atdesk.com) for MR23 */
#include "pcctscfg.h"
#include "pccts_iostream.h"
PCCTS_NAMESPACE_STD
// MR20 Added #include for "DLexerBase.h"
#include "DLexerBase.h"
//
// The default buffer size of the lexer is given by the
// second argument of the lexer's ctor. It is optional
// and defaults to 2000
//
template<class Lexer, class Parser, class Token>
class DllExportPCCTS ParserBlackBox {
private:
// no copy construction allowed
ParserBlackBox(ParserBlackBox const &);
// no copy assignment allowed
ParserBlackBox & operator=(ParserBlackBox const &);
protected:
DLGFileInput *in;
Lexer *scan;
_ANTLRTokenPtr tok;
ANTLRTokenBuffer *pipe;
Parser *_parser;
FILE *file;
int openByBlackBox; /* MR21 Don't close what we haven't opened */
public:
ParserBlackBox(FILE *f)
: in(0)
, scan(0)
, tok(0)
, pipe(0)
, _parser(0)
, file(0)
, openByBlackBox(0)
{
if (f == NULL)
{
cerr << "invalid file pointer\n";
}
else
{
openByBlackBox = 0; /* MR21a */
file = f;
in = new DLGFileInput(f);
scan = new Lexer(in);
pipe = new ANTLRTokenBuffer(scan);
tok = new Token;
scan->setToken(tok);
_parser = new Parser(pipe);
_parser->init();
}
}
ParserBlackBox(char *fname)
: in(0)
, scan(0)
, tok(0)
, pipe(0)
, _parser(0)
, file(0)
, openByBlackBox(0)
{
FILE *f = fopen(fname, "r");
if ( f==NULL ) {
openByBlackBox = 0;
cerr << "cannot open " << fname << "\n"; return;
}
else {
openByBlackBox = 1;
file = f;
in = new DLGFileInput(f);
scan = new Lexer(in);
pipe = new ANTLRTokenBuffer(scan);
tok = new Token;
scan->setToken(tok);
_parser = new Parser(pipe);
_parser->init();
}
}
~ParserBlackBox()
{
delete in; delete scan; delete pipe; delete _parser; delete tok;
if (1 == openByBlackBox) {
fclose(file);
}
}
Parser *parser() { return _parser; }
Lexer *getLexer() { return scan; }
};
#endif

View File

@@ -0,0 +1,684 @@
/*
* PCCTSAST.C
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
* domain. An individual or company may do whatever they wish with
* source code distributed with SORCERER or the code generated by
* SORCERER, including the incorporation of SORCERER, or its output, into
* commerical software.
*
* We encourage users to develop software with SORCERER. However, we do
* ask that credit is given to us for developing SORCERER. 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 SORCERER and have developed a nice tool with the
* output, please mention that you developed it using SORCERER. 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.
*
* SORCERER 1.00B14 and ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* AHPCRC, University of Minnesota
* 1992-2000
*/
#define ANTLR_SUPPORT_CODE
#include "pcctscfg.h"
#include "PCCTSAST.h"
#include "pccts_stdarg.h"
PCCTS_NAMESPACE_STD
#include <ctype.h>
//#include "SList.h"
/* String Scanning/Parsing Stuff */
const char *PCCTS_AST::scan_token_tbl[] = { /* MR20 const */
"invalid", /* 0 */
"LPAREN", /* 1 */
"RPAREN", /* 2 */
"PERCENT", /* 3 */
"INT", /* 4 */
"COLON", /* 5 */
"POUND", /* 6 */
"PERIOD", /* 7 */
};
void PCCTS_AST::
addChild(PCCTS_AST *t)
{
if ( t==NULL ) return;
PCCTS_AST *s = down();
if ( s!=NULL )
{
while ( s->right()!=NULL ) s = s->right();
s->setRight(t);
}
else
this->setDown(t);
}
void PCCTS_AST::
lisp(FILE *f)
{
if ( down() != NULL ) /* MR23 */ printMessage(f," (");
lisp_action(f);
if ( down()!=NULL ) down()->lisp(f);
if ( down() != NULL ) /* MR23 */ printMessage(f," )");
if ( right()!=NULL ) right()->lisp(f);
}
/* build a tree (root child1 child2 ... NULL)
* If root is NULL, simply make the children siblings and return ptr
* to 1st sibling (child1). If root is not single node, return NULL.
*
* Siblings that are actually sibling lists themselves are handled
* correctly. For example #( NULL, #( NULL, A, B, C), D) results
* in the tree ( NULL A B C D ).
*
* Requires at least two parameters with the last one being NULL. If
* both are NULL, return NULL.
*
* The down() and right() down/right pointers are used to make the tree.
*/
PCCTS_AST *PCCTS_AST::
make(PCCTS_AST *rt, ...)
{
va_list ap;
register PCCTS_AST *child, *sibling=NULL, *tail=NULL /*MR23*/, *w;
PCCTS_AST *root;
va_start(ap, rt);
root = rt;
if ( root != NULL )
if ( root->down() != NULL ) return NULL;
child = va_arg(ap, PCCTS_AST *);
while ( child != NULL )
{
/* find end of child */
for (w=child; w->right()!=NULL; w=w->right()) {;}
if ( sibling == NULL ) {sibling = child; tail = w;}
else {tail->setRight(child); tail = w;}
child = va_arg(ap, PCCTS_AST *);
}
if ( root==NULL ) root = sibling;
else root->setDown(sibling);
va_end(ap);
return root;
}
/* The following push and pop routines are only used by ast_find_all() */
void PCCTS_AST::
_push(PCCTS_AST **st, int *sp, PCCTS_AST *e)
{
(*sp)--;
require((*sp)>=0, "stack overflow");
st[(*sp)] = e;
}
PCCTS_AST *PCCTS_AST::
_pop(PCCTS_AST **st, int *sp)
{
PCCTS_AST *e = st[*sp];
(*sp)++;
require((*sp)<=MaxTreeStackDepth, "stack underflow");
return e;
}
/* Find all occurrences of u in t.
* 'cursor' must be initialized to 't'. It eventually
* returns NULL when no more occurrences of 'u' are found.
*/
PCCTS_AST *PCCTS_AST::
ast_find_all(PCCTS_AST *u, PCCTS_AST **cursor)
{
PCCTS_AST *sib;
/*** static ***/ PCCTS_AST *template_stack[MaxTreeStackDepth]; /* MR23 Remove "static" */
/*** static ***/ int tsp = MaxTreeStackDepth; /* MR23 Remove "static" */
////static int nesting = 0; /* MR23 Not referenced */
if ( *cursor == NULL ) return NULL;
if ( *cursor!=this ) sib = *cursor;
else {
/* else, first time--start at top of template 't' */
tsp = MaxTreeStackDepth;
sib = this;
/* bottom of stack is always a NULL--"cookie" indicates "done" */
_push(template_stack, &tsp, NULL);
}
keep_looking:
if ( sib==NULL ) /* hit end of sibling list */
{
sib = _pop(template_stack, &tsp);
if ( sib == NULL ) { *cursor = NULL; return NULL; }
}
if ( sib->type() != u->type() )
{
/* look for another match */
if ( sib->down()!=NULL )
{
if ( sib->right()!=NULL ) _push(template_stack, &tsp, sib->right());
sib=sib->down();
goto keep_looking;
}
/* nothing below to try, try next sibling */
sib=sib->right();
goto keep_looking;
}
/* found a matching root node, try to match what's below */
if ( match_partial(sib, u) )
{
/* record sibling cursor so we can pick up next from there */
if ( sib->down()!=NULL )
{
if ( sib->right()!=NULL ) _push(template_stack, &tsp, sib->right());
*cursor = sib->down();
}
else if ( sib->right()!=NULL ) *cursor = sib->right();
else *cursor = _pop(template_stack, &tsp);
return sib;
}
/* no match, keep searching */
if ( sib->down()!=NULL )
{
if ( sib->right()!=NULL ) _push(template_stack, &tsp, sib->right());
sib=sib->down();
}
else sib = sib->right(); /* else, try to right if zip below */
goto keep_looking;
}
/* are two trees exactly alike? */
int PCCTS_AST::
match(PCCTS_AST *u)
{
PCCTS_AST *t = this;
PCCTS_AST *sib;
if ( u==NULL ) return 0;
for (sib=t; sib!=NULL&&u!=NULL; sib=sib->right(), u=u->right())
{
if ( sib->type() != u->type() ) return 0;
if ( sib->down()!=NULL )
if ( !sib->down()->match(u->down()) ) return 0;
}
return 1;
}
/* Is 'u' a subtree of 't' beginning at the root? */
int PCCTS_AST::
match_partial(PCCTS_AST *t, PCCTS_AST *u)
{
PCCTS_AST *sib;
if ( u==NULL ) return 1;
if ( t==NULL ) return 0; /* MR23 removed unreachable code */
for (sib=t; sib!=NULL&&u!=NULL; sib=sib->right(), u=u->right())
{
if ( sib->type() != u->type() ) return 0;
if ( sib->down()!=NULL )
if ( !match_partial(sib->down(), u->down()) ) return 0;
}
return 1;
}
#ifdef _MSC_VER // MR23
//Turn off "unreachable code" warning
#pragma warning(disable : 4702)
#endif
/* Walk the template tree 't' (matching against 'this'), filling in the
* 'labels' array, and setting 'n' according to how many labels were matched.
*/
int PCCTS_AST::
scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n)
{
ScanAST *sib;
PCCTS_AST *u = this;
if ( u==NULL ) return 0;
for (sib=t; sib!=NULL&&u!=NULL; sib=sib->right(), u=u->right())
{
/* make sure tokens match; token of '0' means wildcard match */
if ( sib->type() != u->type() && sib->type()!=0 ) return 0;
/* we have a matched token here; set label pointers if exists */
if ( sib->label_num>0 )
{
require(labels!=NULL, "label found in template, but no array of labels");
(*n)++;
*(labels[sib->label_num-1]) = u;
}
/* match what's below if something there and current node is not wildcard */
if ( sib->down()!=NULL && sib->type()!=0 )
{
if ( sib->down()==NULL )
{
if ( u->down()!=NULL )
return 0;
else
return 1;
}
if ( !u->down()->scanmatch(sib->down(), labels, n) ) return 0;
}
}
return 1;
}
#ifdef _MSC_VER // MR23
#pragma warning(default : 4702)
#endif
void PCCTS_AST::
insert_after(PCCTS_AST *b)
{
PCCTS_AST *end;
if ( b==NULL ) return;
/* find end of b's child list */
for (end=b; end->right()!=NULL; end=end->right()) {;}
end->setRight(this->right());
this->setRight(b);
}
void PCCTS_AST::
append(PCCTS_AST *b)
{
PCCTS_AST *end;
require(b!=NULL, "append: NULL input tree");
/* find end of child list */
for (end=this; end->right()!=NULL; end=end->right()) {;}
end->setRight(b);
}
PCCTS_AST *PCCTS_AST::
tail()
{
PCCTS_AST *end;
/* find end of child list */
for (end=this; end->right()!=NULL; end=end->right()) {;}
return end;
}
PCCTS_AST *PCCTS_AST::
bottom()
{
PCCTS_AST *end;
/* find end of child list */
for (end=this; end->down()!=NULL; end=end->down()) {;}
return end;
}
PCCTS_AST *PCCTS_AST::
cut_between(PCCTS_AST *a, PCCTS_AST *b)
{
PCCTS_AST *end, *ret;
if (a==NULL||b==NULL) return NULL;
/* find node pointing to b */
for (end=a; end->right()!=NULL&&end->right()!=b; end=end->right())
{;}
if (end->right()==NULL) return NULL; //ast_cut_between: a,b not connected
end->setRight(NULL); /* don't want it point to 'b' anymore */
ret = a->right();
a->setRight(b);
return ret;
}
#ifdef NOT_YET
SList *PCCTS_AST::
to_slist()
{
SList *list = new SList;
PCCTS_AST *p;
for (p=this; p!=NULL; p=p->right())
{
list->add(p);
}
return list;
}
#endif
void PCCTS_AST::
tfree()
{
PCCTS_AST *t = this;
if ( t->down()!=NULL ) t->down()->tfree();
if ( t->right()!=NULL ) t->right()->tfree();
delete t;
}
int PCCTS_AST::
nsiblings()
{
PCCTS_AST *t = this;
int n=0;
while ( t!=NULL )
{
n++;
t = t->right();
}
return n;
}
PCCTS_AST *PCCTS_AST::
sibling_index(int i)
{
PCCTS_AST *t = this;
int j=1;
require(i>0, "sibling_index: i<=0");
while ( t!=NULL )
{
if ( j==i ) return t;
j++;
t = t->right();
}
return NULL;
}
/* Assume this is a root node of a tree--
* duplicate that node and what's below; ignore siblings of root node.
*/
// MR9 23-Sep-97 RJV
// MR9
// MR9 RJV: Original version only duplicated the node and down elements.
// MR9 Made copies of the pointers to sibling.
// MR9 Changed call "down()->deepCopy()" to "down()->deepCopyBushy()"
// MR9
PCCTS_AST *PCCTS_AST::
deepCopy()
{
PCCTS_AST *u = this->shallowCopy();
if ( down()!=NULL ) u->setDown(down()->deepCopyBushy());
u->setRight(NULL);
return u;
}
/* Copy all nodes including siblings of root. */
PCCTS_AST *PCCTS_AST::
deepCopyBushy()
{
PCCTS_AST *u = this->shallowCopy();
/* copy the rest of the tree */
if ( down()!=NULL ) u->setDown(down()->deepCopyBushy());
if ( right()!=NULL ) u->setRight(right()->deepCopyBushy());
return u;
}
void PCCTS_AST::
scanast_free(ScanAST *t)
{
if ( t == NULL ) return;
scanast_free( t->down() );
scanast_free( t->right() );
free( (char *) t ); // MR1
}
/*
* scan
*
* This function is like scanf(): it attempts to match a template
* against an input tree. A variable number of tree pointers
* may be set according to the '%i' labels in the template string.
* For example:
*
* t->ast_scan("#( 6 #(5 %1:4 %2:3) #(1 %3:3 %4:3) )",
* &w, &x, &y, &z);
*
* Naturally, you'd want this converted from
*
* t->ast_scan("#( RangeOp #(Minus %1:IConst %2:Var) #(Plus %3:Var %4Var) )",
* &w, &x, &y, &z);
*
* by SORCERER.
*
* This function call must be done withing a SORCERER file because SORCERER
* must convert the token references to the associated token number.
*
* This functions parses the template and creates trees which are then
* matched against the input tree. The labels are set as they are
* encountered; hence, partial matches may leave some pointers set
* and some NULL. This routines initializes all argument pointers to NULL
* at the beginning.
*
* This function returns the number of labels matched.
*/
int PCCTS_AST::
ast_scan(char *templ, ...)
{
va_list ap;
ScanAST *tmpl;
int n, i, found=0;
PCCTS_AST ***label_ptrs=NULL;
va_start(ap, templ);
/* make a ScanAST tree out of the template */
tmpl = stringparser_parse_scanast(templ, &n);
/* make an array out of the labels */
if ( n>0 )
{
label_ptrs = (PCCTS_AST ***) calloc(n, sizeof(PCCTS_AST **));
require(label_ptrs!=NULL, "scan: out of memory");
for (i=1; i<=n; i++)
{
label_ptrs[i-1] = va_arg(ap, PCCTS_AST **);
*(label_ptrs[i-1]) = NULL;
}
}
/* match the input tree against the template */
scanmatch(tmpl, label_ptrs, &found);
scanast_free(tmpl);
free( (char *) label_ptrs); // MR1
return found;
}
ScanAST *PCCTS_AST::
new_scanast(int tok)
{
ScanAST *p = (ScanAST *) calloc(1, sizeof(ScanAST));
//
// 7-Apr-97 133MR1
//
if ( p == NULL )
panic("out of memory\n"); // MR23
p->_token = tok;
return p;
}
ScanAST *PCCTS_AST::
stringparser_parse_scanast(char *templ, int *num_labels)
{
StringLexer lex;
StringParser parser;
ScanAST *t;
stringlexer_init(&lex, templ);
stringparser_init(&parser, &lex);
t = stringparser_parse_tree(&parser);
*num_labels = parser.num_labels;
return t;
}
void PCCTS_AST::
stringparser_match(StringParser *parser, int token)
{
if ( parser->token != token ) panic("bad tree in scan()");
}
/*
* Match a tree of the form:
* (root child1 child2 ... childn)
* or,
* node
*
* where the elements are integers or labeled integers.
*/
ScanAST *PCCTS_AST::
stringparser_parse_tree(StringParser *parser)
{
ScanAST *t=NULL, *root, *child, *last=NULL /*MR23*/;
if ( parser->token != __POUND )
{
return stringparser_parse_element(parser);
}
stringparser_match(parser,__POUND);
parser->token = stringscan_gettok(parser->lexer);
stringparser_match(parser,__LPAREN);
parser->token = stringscan_gettok(parser->lexer);
root = stringparser_parse_element(parser);
while ( parser->token != __RPAREN )
{
child = stringparser_parse_element(parser);
if ( t==NULL ) { t = child; last = t; }
else { last->_right = child; last = child; }
}
stringparser_match(parser,__RPAREN);
parser->token = stringscan_gettok(parser->lexer);
root->_down = t;
return root;
}
ScanAST *PCCTS_AST::
stringparser_parse_element(StringParser *parser)
{
char ebuf[100];
int label = 0;
if ( parser->token == __POUND )
{
return stringparser_parse_tree(parser);
}
if ( parser->token == __PERCENT )
{
parser->token = stringscan_gettok(parser->lexer);
stringparser_match(parser,__INT);
label = atoi(parser->lexer->text);
parser->num_labels++;
if ( label==0 ) panic("%%0 is an invalid label");
parser->token = stringscan_gettok(parser->lexer);
stringparser_match(parser,__COLON);
parser->token = stringscan_gettok(parser->lexer);
/* can label tokens and wildcards */
if ( parser->token != __INT && parser->token != __PERIOD )
panic("can only label tokens");
}
if ( parser->token == __INT )
{
ScanAST *p = new_scanast(atoi(parser->lexer->text));
parser->token = stringscan_gettok(parser->lexer);
p->label_num = label;
return p;
}
if ( parser->token == __PERIOD )
{
ScanAST *p = new_scanast(0); /* token of 0 is wildcard */
parser->token = stringscan_gettok(parser->lexer);
p->label_num = label;
return p;
}
sprintf(ebuf, "mismatch token in scan(): %s", scan_token_str(parser->token));
panic(ebuf);
return NULL;
}
void PCCTS_AST::
stringparser_init(StringParser *parser, StringLexer *input)
{
parser->lexer = input;
parser->token = stringscan_gettok(parser->lexer);
parser->num_labels = 0;
}
void PCCTS_AST::
stringlexer_init(StringLexer *scanner, char *input)
{
scanner->text[0]='\0';
scanner->input = input;
scanner->p = input;
stringscan_advance(scanner);
}
void PCCTS_AST::
stringscan_advance(StringLexer *scanner)
{
if ( *(scanner->p) == '\0' ) scanner->c = __StringScanEOF;
scanner->c = *(scanner->p)++;
}
int PCCTS_AST::
stringscan_gettok(StringLexer *scanner)
{
char *index = &scanner->text[0];
char ebuf[100]; /* MR23 Remove static */
while ( isspace(scanner->c) ) { stringscan_advance(scanner); }
if ( isdigit(scanner->c) )
{
int tok = __INT;
while ( isdigit(scanner->c) ) {
*index++ = (char) /* static_cast<char> */ (scanner->c); // MR23
stringscan_advance(scanner);
}
*index = '\0';
return tok;
}
switch ( scanner->c )
{
case '#' : stringscan_advance(scanner); return __POUND;
case '(' : stringscan_advance(scanner); return __LPAREN;
case ')' : stringscan_advance(scanner); return __RPAREN;
case '%' : stringscan_advance(scanner); return __PERCENT;
case ':' : stringscan_advance(scanner); return __COLON;
case '.' : stringscan_advance(scanner); return __PERIOD;
case '\0' : return __StringScanEOF;
case __StringScanEOF : return __StringScanEOF;
default :
sprintf(ebuf, "invalid char in scan: '%c'", scanner->c);
panic(ebuf);
}
return __StringScanEOF; // never reached
}
const char *PCCTS_AST:: /* MR20 const */
scan_token_str(int t)
{
if ( VALID_SCAN_TOKEN(t) ) return scan_token_tbl[t];
else if ( t==__StringScanEOF ) return "<end-of-string>";
else return "<invalid-token>";
}
//MR23
int PCCTS_AST::printMessage(FILE* pFile, const char* pFormat, ...)
{
va_list marker;
va_start( marker, pFormat );
int iRet = vfprintf(pFile, pFormat, marker);
va_end( marker );
return iRet;
}

View File

@@ -0,0 +1,143 @@
/* Abstract syntax tree
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef PCCTSAST_H
#define PCCTSAST_H
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_stdlib.h"
PCCTS_NAMESPACE_STD
//class SList;
#define StringScanMaxText 50
#define MaxTreeStackDepth 400
//
// 7-Apr-97 133MR1 signed int not accepted by AT&T cfront
//
typedef struct stringlexer {
int c; // MR1
char *input;
char *p;
char text[StringScanMaxText];
} StringLexer;
/* Define the structures needed for ast_scan() */
typedef struct stringparser {
int token;
StringLexer *lexer;
int num_labels;
} StringParser;
typedef struct _scanast {
struct _scanast *_right, *_down;
int _token;
int label_num;
int type() { return _token; }
struct _scanast *right() { return _right; }
struct _scanast *down() { return _down; }
} ScanAST;
#define VALID_SCAN_TOKEN(t) (t>=__LPAREN && t<=__PERIOD)
class DllExportPCCTS PCCTS_AST {
protected:
static const char *scan_token_tbl[]; /* MR20 const */
enum {
__LPAREN=1,
__RPAREN=2,
__PERCENT=3,
__INT=4,
__COLON=5,
__POUND=6,
__PERIOD=7,
__StringScanEOF=-1};
protected:
const char *scan_token_str(int t); /* MR20 const */
void stringlexer_init(StringLexer *scanner, char *input);
void stringparser_init(StringParser *, StringLexer *);
ScanAST *stringparser_parse_scanast(char *templ, int *n);
ScanAST *stringparser_parse_tree(StringParser *parser);
ScanAST *stringparser_parse_element(StringParser *parser);
void stringscan_advance(StringLexer *scanner);
int stringscan_gettok(StringLexer *scanner);
void _push(PCCTS_AST **st, int *sp, PCCTS_AST *e);
PCCTS_AST *_pop(PCCTS_AST **st, int *sp);
int match_partial(PCCTS_AST *t, PCCTS_AST *u);
int scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n);
void scanast_free(ScanAST *t);
ScanAST *new_scanast(int tok);
void stringparser_match(StringParser *parser, int type);
virtual PCCTS_AST *deepCopyBushy();
public:
PCCTS_AST() {;}
virtual ~PCCTS_AST() {;}
/* This group must be defined for SORCERER to work correctly */
virtual PCCTS_AST *right() = 0;
virtual PCCTS_AST *down() = 0;
virtual void setRight(PCCTS_AST *t) = 0;
virtual void setDown(PCCTS_AST *t) = 0;
// we define these so ANTLR doesn't have to
virtual int type() { return 0; }
virtual void setType(int /*t MR23 */) {;}
virtual PCCTS_AST *shallowCopy() {panic("no shallowCopy() defined"); return NULL;}
/* These are not needed by ANTLR, but are support functions */
virtual PCCTS_AST *deepCopy(); // used by SORCERER in transform mode
virtual void addChild(PCCTS_AST *t);
virtual void lisp_action(FILE * /*f MR23 */) {;}
virtual void lisp(FILE *f);
static PCCTS_AST *make(PCCTS_AST *rt, ...);
virtual PCCTS_AST *ast_find_all(PCCTS_AST *u, PCCTS_AST **cursor);
virtual int match(PCCTS_AST *u);
virtual void insert_after(PCCTS_AST *b);
virtual void append(PCCTS_AST *b);
virtual PCCTS_AST *tail();
virtual PCCTS_AST *bottom();
static PCCTS_AST *cut_between(PCCTS_AST *a, PCCTS_AST *b);
// virtual SList *to_slist();
virtual void tfree();
int ast_scan(char *templ, ...);
virtual int nsiblings();
virtual PCCTS_AST *sibling_index(int i);
void require(int e,const char *err){ if ( !e ) panic(err); } /* MR20 const */
virtual void panic(const char *err) // MR20 const
{ /* MR23 */ printMessage(stderr, "PCCTS_AST: %s\n", err); exit(PCCTS_EXIT_FAILURE); }
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
};
#endif /* PCCTSAST_H */

View File

@@ -0,0 +1,72 @@
#ifndef SList_h
#define SList_h
/*
* SList.h
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
* domain. An individual or company may do whatever they wish with
* source code distributed with SORCERER or the code generated by
* SORCERER, including the incorporation of SORCERER, or its output, into
* commerical software.
*
* We encourage users to develop software with SORCERER. However, we do
* ask that credit is given to us for developing SORCERER. 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 SORCERER and have developed a nice tool with the
* output, please mention that you developed it using SORCERER. 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.
*
* PCCTS 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1992-2000
*/
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pccts_stdlib.h"
PCCTS_NAMESPACE_STD
#include "PCCTSAST.h"
class PCCTS_AST;
class SListNode {
protected:
void *_elem; /* pointer to any kind of element */
SListNode *_next;
public:
SListNode() {_elem=_next=NULL;}
virtual ~SListNode() {_elem=_next=NULL;}
void *elem() { return _elem; }
void setElem(void *e) { _elem = e; }
void setNext(SListNode *t) { _next = t; }
SListNode *next() { return _next; }
};
class SList {
SListNode *head, *tail;
public:
SList() {head=tail=NULL;}
virtual ~SList() {head=tail=NULL;}
virtual void *iterate(SListNode **);
virtual void add(void *e);
virtual void lfree();
virtual PCCTS_AST *to_ast(SList list);
virtual void require(int e,char *err){ if ( !e ) panic(err); }
virtual void panic(char *err){ /* MR23 */ printMessage(stderr, "SList panic: %s\n", err); exit(PCCTS_EXIT_FAILURE); }
virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
};
#endif

View File

@@ -0,0 +1,807 @@
/* antlr.h
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ANTLR_H
#define ANTLR_H
#include "pcctscfg.h"
#include "pccts_stdio.h"
/* turn off warnings for unreferenced labels */
#ifdef _MSC_VER
#pragma warning(disable:4102)
#endif
/*
* Define all of the stack setup and manipulation of $i, #i variables.
*
* Notes:
* The type 'Attrib' must be defined before entry into this .h file.
*/
#ifdef __USE_PROTOS
#include "pccts_stdlib.h"
#else
#ifdef VAXC
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#endif
#include "pccts_string.h"
#if 0
#include "set.h"
#endif
typedef int ANTLRTokenType;
typedef unsigned char SetWordType;
typedef char ANTLRChar;
/* G u e s s S t u f f */
#ifdef ZZCAN_GUESS
#ifndef ZZINF_LOOK
#define ZZINF_LOOK
#endif
#endif
#ifdef ZZCAN_GUESS
typedef struct _zzjmp_buf {
jmp_buf state;
} zzjmp_buf;
#endif
/* can make this a power of 2 for more efficient lookup */
#ifndef ZZLEXBUFSIZE
#define ZZLEXBUFSIZE 8000 /* MR22 raise from 2k to 8k */
#endif
#define zzOvfChk \
if ( zzasp <= 0 ) \
{ \
fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__); \
exit(PCCTS_EXIT_FAILURE); \
}
#ifndef ZZA_STACKSIZE
#define ZZA_STACKSIZE 400
#endif
#ifndef ZZAST_STACKSIZE
#define ZZAST_STACKSIZE 400
#endif
#ifndef zzfailed_pred
#ifdef ZZCAN_GUESS
#define zzfailed_pred(_p,_hasuseraction,_useraction) \
if (zzguessing) { \
zzGUESS_FAIL; \
} else { \
zzfailed_pred_action(_p,_hasuseraction,_useraction); \
}
#else
#define zzfailed_pred(_p,_hasuseraction,_useraction) \
zzfailed_pred_action(_p,_hasuseraction,_useraction);
#endif
#endif
/* MR23 Provide more control over failed predicate action
without any need for user to worry about guessing internals.
_hasuseraction == 0 => no user specified error action
_hasuseraction == 1 => user specified error action
*/
#ifndef zzfailed_pred_action
#define zzfailed_pred_action(_p,_hasuseraction,_useraction) \
if (_hasuseraction) { _useraction } \
else { fprintf(stderr, "semantic error; failed predicate: '%s'\n",_p); }
#endif
/* MR19 zzchar_t additions */
#ifdef LL_K
#define LOOKAHEAD \
int zztokenLA[LL_K]; \
zzchar_t zztextLA[LL_K][ZZLEXBUFSIZE]; \
int zzlap = 0, zzlabase=0; /* labase only used for DEMAND_LOOK */
#else
#define LOOKAHEAD \
int zztoken;
#endif
#ifndef zzcr_ast
#define zzcr_ast(ast,attr,tok,text)
#endif
#ifdef DEMAND_LOOK
#define DemandLookData int zzdirty=1;
#else
#define DemandLookData
#endif
#ifndef zzUSER_GUESS_HOOK
#define zzUSER_GUESS_HOOK(seqFrozen,zzrv)
#endif
#ifndef zzUSER_GUESS_DONE_HOOK
#define zzUSER_GUESS_DONE_HOOK(seqFrozen)
#endif
/* S t a t e S t u f f */
#ifdef ZZCAN_GUESS
#define zzGUESS_BLOCK zzantlr_state zzst; int zzrv; int zzGuessSeqFrozen;
/* MR10 change zzGUESS: do zzGUESS_DONE when zzrv==1 after longjmp as in C++ mode */
#define zzGUESS zzsave_antlr_state(&zzst); \
zzguessing = 1; \
zzGuessSeqFrozen=++zzGuessSeq; \
zzrv = setjmp(zzguess_start.state); \
zzUSER_GUESS_HOOK(zzGuessSeqFrozen,zzrv) \
if (zzrv) zzGUESS_DONE;
#ifdef zzTRACE_RULES
#define zzGUESS_FAIL { zzTraceGuessFail(); longjmp(zzguess_start.state, 1); }
#else
#define zzGUESS_FAIL longjmp(zzguess_start.state, 1)
#endif
/* MR10 change zzGUESS_DONE: zzrv=1 to simulate longjmp() return value as in C++ mode */
#define zzGUESS_DONE { zzrestore_antlr_state(&zzst); zzrv=1; zzUSER_GUESS_DONE_HOOK(zzGuessSeqFrozen) }
#define zzNON_GUESS_MODE if ( !zzguessing )
#define zzGuessData \
zzjmp_buf zzguess_start; \
int zzguessing;
#else
#define zzGUESS_BLOCK
#define zzGUESS
#define zzGUESS_FAIL
#define zzGUESS_DONE
#define zzNON_GUESS_MODE
#define zzGuessData
#endif
typedef struct _zzantlr_state {
#ifdef ZZCAN_GUESS
zzjmp_buf guess_start;
int guessing;
#endif
int asp;
int ast_sp;
#ifdef ZZINF_LOOK
int inf_lap; /* not sure we need to save this one */
int inf_labase;
int inf_last;
/* MR6 Gunnar Rxnning (gunnar@candleweb.no) */
/* MR6 Additional state needs to be saved/restored */
/* MR6 Matching changes in err.h */
int *inf_tokens; /* MR6 */
char **inf_text; /* MR6 */
char *inf_text_buffer; /* MR6 */
int *inf_line; /* MR6 */
#endif
#ifdef DEMAND_LOOK
int dirty;
#endif
#ifdef LL_K
int tokenLA[LL_K];
char textLA[LL_K][ZZLEXBUFSIZE];
int lap;
int labase;
#else
int token;
char text[ZZLEXBUFSIZE];
#endif
#ifdef zzTRACE_RULES
int traceOptionValue; /* MR10 */
int traceGuessOptionValue; /* MR10 */
char *traceCurrentRuleName; /* MR10 */
int traceDepth; /* MR10 */
#endif
} zzantlr_state;
#ifdef zzTRACE_RULES
extern int zzTraceOptionValueDefault;
extern int zzTraceOptionValue;
extern int zzTraceGuessOptionValue;
extern char *zzTraceCurrentRuleName;
extern int zzTraceDepth;
#endif
extern int zzGuessSeq; /* MR10 */
extern int zzSyntaxErrCount; /* MR11 */
extern int zzLexErrCount; /* MR11 */
/* I n f i n i t e L o o k a h e a d */
#ifdef ZZINF_LOOK
#define InfLookData \
int *zzinf_tokens; \
char **zzinf_text; \
char *zzinf_text_buffer; \
int *zzinf_line; \
int zzinf_labase; \
int zzinf_last;
#else
#define InfLookData
#endif
#ifdef ZZINF_LOOK
#ifndef ZZINF_DEF_TEXT_BUFFER_SIZE
#define ZZINF_DEF_TEXT_BUFFER_SIZE 20000
#endif
#ifndef ZZINF_DEF_TOKEN_BUFFER_SIZE
#define ZZINF_DEF_TOKEN_BUFFER_SIZE 2000
#endif
/* WARNING!!!!!!
* ZZINF_BUFFER_TEXT_CHUNK_SIZE must be > sizeof(text) largest possible token.
*/
#ifndef ZZINF_BUFFER_TEXT_CHUNK_SIZE
#define ZZINF_BUFFER_TEXT_CHUNK_SIZE 5000
#endif
#ifndef ZZINF_BUFFER_TOKEN_CHUNK_SIZE
#define ZZINF_BUFFER_TOKEN_CHUNK_SIZE 1000
#endif
#if ZZLEXBUFSIZE > ZZINF_BUFFER_TEXT_CHUNK_SIZE
#define ZZINF_BUFFER_TEXT_CHUNK_SIZE ZZLEXBUFSIZE+5
#endif
/* make inf_look user-access macros */
#ifdef LL_K
#define ZZINF_LA_VALID(i) (((zzinf_labase+i-1)-LL_K+1) <= zzinf_last)
#define ZZINF_LA(i) zzinf_tokens[(zzinf_labase+i-1)-LL_K+1]
#define ZZINF_LATEXT(i) zzinf_text[(zzinf_labase+i-1)-LL_K+1]
/* MR6 In 1.33 vanilla the #define ZZINF_LINE(i) is was commented out */
#define ZZINF_LINE(i) zzinf_line[(zzinf_labase+i-1)-LL_K+1]
#else
#define ZZINF_LA_VALID(i) (((zzinf_labase+i-1)) <= zzinf_last)
#define ZZINF_LA(i) zzinf_tokens[(zzinf_labase+i-1)]
#define ZZINF_LATEXT(i) zzinf_text[(zzinf_labase+i-1)]
#endif
#define inf_zzgettok _inf_zzgettok()
extern void _inf_zzgettok();
#endif /* ZZINF_LOOK */
#ifdef LL_K
#ifdef __USE_PROTOS
#define ANTLR_INFO \
Attrib zzempty_attr(void) {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text) \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text; \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#endif
#else
#ifdef __USE_PROTOS
#define ANTLR_INFO \
Attrib zzempty_attr(void) {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text) \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text; \
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; DemandLookData \
InfLookData \
zzGuessData
#endif
#endif /* LL_k */
#ifdef ZZINF_LOOK
#ifdef LL_K
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead {zzdirty=LL_K; zzlap = zzlabase = 0;}
#else
#define zzPrimeLookAhead {zzlap = zzlabase = 0; zzfill_inf_look();\
{int _i; for(_i=1;_i<=LL_K; _i++) \
{zzCONSUME;} zzlap = zzlabase = 0;}}
#endif
#else /* LL_K */
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead zzfill_inf_look(); zzdirty=1
#else
#define zzPrimeLookAhead zzfill_inf_look(); inf_zzgettok
#endif
#endif /* LL_K */
#else /* ZZINF_LOOK */
#ifdef LL_K
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead {zzdirty=LL_K; zzlap = zzlabase = 0;}
#else
#define zzPrimeLookAhead {int _i; zzlap = 0; for(_i=1;_i<=LL_K; _i++) \
{zzCONSUME;} zzlap = 0;}
#endif
#else
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead zzdirty=1
#else
#define zzPrimeLookAhead zzgettok()
#endif
#endif /* LL_K */
#endif /* ZZINF_LOOK */
#ifdef LL_K
#define zzenterANTLRs(s) \
zzlextext = &(zztextLA[0][0]); zzrdstr( s ); zzPrimeLookAhead;
#define zzenterANTLRf(f) \
zzlextext = &(zztextLA[0][0]); zzrdfunc( f ); zzPrimeLookAhead;
#define zzenterANTLR(f) \
zzlextext = &(zztextLA[0][0]); zzrdstream( f ); zzPrimeLookAhead;
#ifdef ZZINF_LOOK
#define zzleaveANTLR(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#define zzleaveANTLRf(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#define zzleaveANTLRs(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#else
#define zzleaveANTLR(f)
#define zzleaveANTLRf(f)
#define zzleaveANTLRs(f)
#endif
#else
#define zzenterANTLRs(s) \
{static char zztoktext[ZZLEXBUFSIZE]; \
zzlextext = zztoktext; zzrdstr( s ); zzPrimeLookAhead;}
#define zzenterANTLRf(f) \
{static char zztoktext[ZZLEXBUFSIZE]; \
zzlextext = zztoktext; zzrdfunc( f ); zzPrimeLookAhead;}
#define zzenterANTLR(f) \
{static char zztoktext[ZZLEXBUFSIZE]; \
zzlextext = zztoktext; zzrdstream( f ); zzPrimeLookAhead;}
#ifdef ZZINF_LOOK
#define zzleaveANTLR(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#define zzleaveANTLRf(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#define zzleaveANTLRs(f) free(zzinf_text_buffer); free(zzinf_text); free(zzinf_tokens); free(zzinf_line);
#else
#define zzleaveANTLR(f)
#define zzleaveANTLRf(f)
#define zzleaveANTLRs(f)
#endif
#endif
/* MR19 Paul D. Smith (psmith@baynetworks.com)
Need to adjust AST stack pointer at exit.
Referenced in ANTLRx macros.
*/
#ifdef GENAST
#define ZZAST_ADJUST ++zzast_sp;
#else
#define ZZAST_ADJUST
#endif
#define ANTLR(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLR(f); \
{ \
zzBLOCK(zztasp1); \
st; /* ++zzasp; Removed MR20 G. Hobbelt */ \
/* ZZAST_ADJUST Removed MR20 G. Hobbelt */ \
/* MR20 G. Hobbelt. Kill the top' attribute (+AST stack corr.) */ \
zzEXIT_ANTLR(zztasp1 + 1); \
} \
zzleaveANTLR(f);
#define ANTLRm(st, f, _m) zzbufsize = ZZLEXBUFSIZE; \
zzmode(_m); \
zzenterANTLR(f); \
{ \
zzBLOCK(zztasp1); \
st; /* ++zzasp; Removed MR20 G. Hobbelt */ \
/* ZZAST_ADJUST Removed MR20 G. Hobbelt */ \
/* MR20 G. Hobbelt. Kill the top' attribute (+AST stack corr.) */ \
zzEXIT_ANTLR(zztasp1 + 1); \
} \
zzleaveANTLR(f);
#define ANTLRf(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLRf(f); \
{ \
zzBLOCK(zztasp1); \
st; /* ++zzasp; Removed MR20 G. Hobbelt */ \
/* ZZAST_ADJUST Removed MR20 G. Hobbelt */ \
/* MR20 G. Hobbelt. Kill the top' attribute (+AST stack corr.) */ \
zzEXIT_ANTLR(zztasp1 + 1); \
} \
zzleaveANTLRf(f);
#define ANTLRs(st, s) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLRs(s); \
{ \
zzBLOCK(zztasp1); \
st; /* ++zzasp; Removed MR20 G. Hobbelt */ \
/* ZZAST_ADJUST Removed MR20 G. Hobbelt */ \
/* MR20 G. Hobbelt. Kill the top' attribute (+AST stack corr.) */ \
zzEXIT_ANTLR(zztasp1 + 1); \
} \
zzleaveANTLRs(s);
#ifdef LL_K
#define zztext (&(zztextLA[zzlap][0]))
#else
#define zztext zzlextext
#endif
/* A r g u m e n t A c c e s s */
#define zzaCur (zzaStack[zzasp])
#define zzaRet (*zzaRetPtr)
#define zzaArg(v,n) zzaStack[v-n]
#define zzMakeAttr { zzNON_GUESS_MODE {zzOvfChk; --zzasp; zzcr_attr(&(zzaStack[zzasp]),LA(1),LATEXT(1));}}
#ifdef zzdef0
#define zzMake0 { zzOvfChk; --zzasp; zzdef0(&(zzaStack[zzasp]));}
#else
#define zzMake0 { zzOvfChk; --zzasp;}
#endif
#define zzaPush(_v) { zzOvfChk; zzaStack[--zzasp] = _v;}
#ifndef zzd_attr
#define zzREL(t) zzasp=(t); /* Restore state of stack */
#else
#define zzREL(t) for (; zzasp<(t); zzasp++) \
{ zzd_attr(&(zzaStack[zzasp])); }
#endif
#define zzsetmatch(_es,_tokclassErrset) \
if ( !_zzsetmatch(_es, &zzBadText, &zzMissText, &zzMissTok, &zzBadTok, &zzMissSet, _tokclassErrset) ) goto fail; /* MR23 */
#ifdef ZZCAN_GUESS
#define zzsetmatch_wsig(_es, handler) \
if ( !_zzsetmatch_wsig(_es) ) if (zzguessing) { zzGUESS_FAIL; } else {_signal=MismatchedToken; goto handler;}
#else
#define zzsetmatch_wsig(_es, handler) \
if ( !_zzsetmatch_wsig(_es) ) {_signal=MismatchedToken; goto handler;}
#endif
#ifdef __USE_PROTOS
extern int _zzsetmatch(SetWordType *, char **, char **, int *, int *, SetWordType **, SetWordType * /* MR23 */);
extern int _zzsetmatch_wsig(SetWordType *);
#else
extern int _zzsetmatch();
extern int _zzsetmatch_wsig();
#endif
#define zzmatch(_t) \
if ( !_zzmatch(_t, &zzBadText, &zzMissText, &zzMissTok, &zzBadTok, &zzMissSet) ) goto fail;
#ifdef ZZCAN_GUESS
#define zzmatch_wsig(_t,handler) \
if ( !_zzmatch_wsig(_t) ) if (zzguessing) { zzGUESS_FAIL; } else {_signal=MismatchedToken; goto handler;}
#else
#define zzmatch_wsig(_t,handler) \
if ( !_zzmatch_wsig(_t) ) {_signal=MismatchedToken; goto handler;}
#endif
#ifdef __USE_PROTOS
extern int _zzmatch(int, char **, char **, int *, int *, SetWordType **);
extern int _zzmatch_wsig(int);
#else
extern int _zzmatch();
extern int _zzmatch_wsig();
#endif
#define zzmatch_wdfltsig(_t,_f) \
if ( !_zzmatch_wdfltsig(_t,_f) ) _signal=MismatchedToken;
#define zzsetmatch_wdfltsig(tw,tt,wf) \
if ( !_zzsetmatch_wdfltsig(tw,tt,wf) ) _signal=MismatchedToken;
#ifdef __USE_PROTOS
extern int _zzmatch_wdfltsig(int, SetWordType *);
extern int _zzsetmatch_wdfltsig(SetWordType *tokensWanted,
int tokenTypeOfSet,
SetWordType *whatFollows);
#else
extern int _zzmatch_wdfltsig();
extern int _zzsetmatch_wdfltsig();
#endif
#ifdef GENAST
#define zzRULE Attrib *zzaRetPtr = &(zzaStack[zzasp-1]); \
SetWordType *zzMissSet=NULL; int zzMissTok=0; \
int zzBadTok=0; char *zzBadText=""; \
int zzErrk=1,zzpf=0; \
zzTRACEdata \
char *zzMissText=""; zzASTVars
#else
#define zzRULE Attrib *zzaRetPtr = &(zzaStack[zzasp-1]); \
int zzBadTok=0; char *zzBadText=""; \
int zzErrk=1,zzpf=0; \
zzTRACEdata \
SetWordType *zzMissSet=NULL; int zzMissTok=0; char *zzMissText=""
#endif
#ifdef GENAST
#define zzBLOCK(i) int i = zzasp - 1; int zztsp = zzast_sp
#define zzEXIT(i) zzREL(i); zzastREL; zzNON_GUESS_MODE { zzastPush(*_root); }
#define zzEXIT_ANTLR(i) zzREL(i); zzastREL /* [i_a] added as we want this for the ANTLRx() macros */
#define zzLOOP(i) zzREL(i); zzastREL
#else
#define zzBLOCK(i) int i = zzasp - 1
#define zzEXIT(i) zzREL(i)
#define zzEXIT_ANTLR(i) zzREL(i) /* [i_a] added as we want this for the ANTLRx() macros */
#define zzLOOP(i) zzREL(i)
#endif
#ifdef LL_K
#ifdef DEMAND_LOOK
#define LOOK(_k) {int i,stop=_k-(LL_K-zzdirty); for (i=1; i<=stop; i++) \
zzCONSUME;}
#define zzCONSUME {zzgettok(); zzdirty--; \
zzlap = (zzlap+1)&(LL_K-1); \
zzlextext = &(zztextLA[zzlap][0]);}
#else
#ifdef ZZINF_LOOK
#define zzCONSUME {inf_zzgettok; \
zzlap = (zzlap+1)&(LL_K-1); \
zzlextext = &(zztextLA[zzlap][0]); \
}
#else
#define zzCONSUME {zzgettok(); \
zzlap = (zzlap+1)&(LL_K-1); \
zzlextext = &(zztextLA[zzlap][0]);}
#endif /* ZZINF_LOOK */
#endif /* DEMAND_LOOK */
#else /* LL_K */
#ifdef DEMAND_LOOK
#define LOOK(_k) if ( zzdirty) zzCONSUME;
#ifdef ZZINF_LOOK
#define zzCONSUME inf_zzgettok; zzdirty=0;
#else
#define zzCONSUME zzgettok(); zzdirty=0;
#endif /* ZZINF_LOOK */
#else /* DEMAND_LOOK */
#ifdef ZZINF_LOOK
#define zzCONSUME inf_zzgettok
#else
#define zzCONSUME zzgettok();
#endif
#endif /* DEMAND_LOOK */
#endif /* LL_K */
#ifdef LL_K
#define NLA zztokenLA[zzlap&(LL_K-1)] /* --> next LA */
#define NLATEXT zztextLA[zzlap&(LL_K-1)] /* --> next text of LA */
#ifdef DEMAND_LOOK
#define LA(i) zztokenLA[(zzlabase+(i)-1)&(LL_K-1)]
#define LATEXT(i) (&(zztextLA[(zzlabase+(i)-1)&(LL_K-1)][0]))
#else
#define LA(i) zztokenLA[(zzlap+(i)-1)&(LL_K-1)]
#define LATEXT(i) (&(zztextLA[(zzlap+(i)-1)&(LL_K-1)][0]))
#endif
#else
#define NLA zztoken
#define NLATEXT zztext
#define LA(i) zztoken
#define LATEXT(i) zztext
#endif
/* S t a n d a r d S i g n a l s */
#define NoSignal 0
#define MismatchedToken 1
#define NoViableAlt 2
#define NoSemViableAlt 3
/* MR7 Allow more control over signalling */
/* by adding "Unwind" and "zzsetSignal" */
#define Unwind 4
#define zzsetSignal(newValue) *_retsignal=_signal=(newValue)
#define zzsuppressSignal *_retsignal=_signal=0
#define zzexportSignal *_retsignal=_signal
/* F u n c t i o n T r a c i n g */
#ifndef zzTRACE_RULES
#define zzTRACEdata
#else
#ifndef zzTRACEdata
#define zzTRACEdata ANTLRChar *zzTracePrevRuleName = NULL;
#endif
#endif
#ifndef zzTRACEIN
#define zzTRACEIN(r) zzTracePrevRuleName=zzTraceCurrentRuleName;zzTraceIn(r);
#endif
#ifndef zzTRACEOUT
#define zzTRACEOUT(r) zzTraceOut(r);zzTraceCurrentRuleName=zzTracePrevRuleName;
#endif
/* MR19 zzchar_t additions */
#ifndef zzchar_t
#ifdef ZZWCHAR_T
#define zzchar_t wchar_t
#else
#define zzchar_t char
#endif
#endif
/* MR26 */
#ifdef PCCTS_USE_STDARG
extern void zzFAIL(int k, ...);
#else
extern void zzFAIL();
#endif
/* E x t e r n D e f s */
#ifdef __USE_PROTOS
extern Attrib zzempty_attr(void);
extern Attrib zzconstr_attr(int, char *);
extern void zzsyn(char *, int, char *, SetWordType *, int, int, char *);
extern int zzset_el(unsigned, SetWordType *);
extern int zzset_deg(SetWordType *);
extern void zzedecode(SetWordType *);
extern void zzresynch(SetWordType *, SetWordType);
extern void zzsave_antlr_state(zzantlr_state *);
extern void zzrestore_antlr_state(zzantlr_state *);
extern void zzfill_inf_look(void);
extern void zzconsumeUntil(SetWordType *st); /* MR7 */
extern void zzconsumeUntilToken(int t); /* MR7 */
extern void zzTraceIn(char * ruleName); /* MR10 */
extern void zzTraceOut(char * ruleName); /* MR10 */
extern int zzTraceOption(int delta); /* MR10 */
extern int zzTraceGuessOption(int delta); /* MR10 */
extern void zzTraceReset(void); /* MR10 */
extern void zzTraceGuessFail(void); /* MR10 */
#ifdef EXCEPTION_HANDLING
extern void zzdflthandlers(int, int *);
#endif
#else
extern Attrib zzempty_attr();
extern Attrib zzconstr_attr();
extern void zzsyn();
extern int zzset_el();
extern int zzset_deg();
extern void zzedecode();
extern void zzresynch();
extern void zzsave_antlr_state();
extern void zzrestore_antlr_state();
extern void zzfill_inf_look();
extern void zzconsumeUntil(); /* MR7 */
extern void zzconsumeUntilToken(); /* MR7 */
extern void zzTraceIn(); /* MR10 */
extern void zzTraceOut(); /* MR10 */
extern int zzTraceOption(); /* MR10 */
extern int zzTraceGuessOption(); /* MR10 */
extern void zzTraceReset(); /* MR10 */
extern void zzTraceGuessFail(); /* MR10 */
#ifdef EXCEPTION_HANDLING
extern void zzdflthandlers();
#endif
#endif
/* G l o b a l V a r i a b l e s */
/* Define a parser; user should do a "#parser myname" in their grammar file */
/*extern struct pccts_parser zzparser;*/
extern char *zztokens[];
#ifdef LL_K
extern int zztokenLA[];
extern zzchar_t zztextLA[][ZZLEXBUFSIZE];
extern int zzlap;
extern int zzlabase;
#else
extern int zztoken;
#endif
extern char zzStackOvfMsg[];
extern int zzasp;
extern Attrib zzaStack[];
#ifdef ZZINF_LOOK
extern int *zzinf_tokens;
extern char **zzinf_text;
extern char *zzinf_text_buffer;
extern int *zzinf_line;
extern int zzinf_labase;
extern int zzinf_last;
#endif
#ifdef DEMAND_LOOK
extern int zzdirty;
#endif
#ifdef ZZCAN_GUESS
extern int zzguessing;
extern zzjmp_buf zzguess_start;
#endif
/* Define global veriables that refer to values exported by the scanner.
* These declarations duplicate those in dlgdef.h, but are needed
* if ANTLR is not to generate a .dlg file (-gx); PS, this is a hack.
*/
extern zzchar_t *zzlextext; /* text of most recently matched token */
extern int zzbufsize; /* how long zzlextext is */
#endif

View File

@@ -0,0 +1,345 @@
/* Abstract syntax tree manipulation functions
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
#ifdef PCCTS_USE_STDARG
#include "pccts_stdarg.h"
#else
#include <varargs.h>
#endif
/* ensure that tree manipulation variables are current after a rule
* reference
*/
void
#ifdef __USE_PROTOS
zzlink(AST **_root, AST **_sibling, AST **_tail)
#else
zzlink(_root, _sibling, _tail)
AST **_root, **_sibling, **_tail;
#endif
{
if ( *_sibling == NULL ) return;
if ( *_root == NULL ) *_root = *_sibling;
else if ( *_root != *_sibling ) (*_root)->down = *_sibling;
if ( *_tail==NULL ) *_tail = *_sibling;
while ( (*_tail)->right != NULL ) *_tail = (*_tail)->right;
}
AST *
#ifdef __USE_PROTOS
zzastnew(void)
#else
zzastnew()
#endif
{
AST *p = (AST *) calloc(1, sizeof(AST));
if ( p == NULL ) fprintf(stderr,"%s(%d): cannot allocate AST node\n",__FILE__,__LINE__);
return p;
}
/* add a child node to the current sibling list */
void
#ifdef __USE_PROTOS
zzsubchild(AST **_root, AST **_sibling, AST **_tail)
#else
zzsubchild(_root, _sibling, _tail)
AST **_root, **_sibling, **_tail;
#endif
{
AST *n;
zzNON_GUESS_MODE {
n = zzastnew();
#ifdef DEMAND_LOOK
zzcr_ast(n, &(zzaCur), LA(0), LATEXT(0));
#else
zzcr_ast(n, &(zzaCur), LA(1), LATEXT(1));
#endif
zzastPush( n );
if ( *_tail != NULL ) (*_tail)->right = n;
else {
*_sibling = n;
if ( *_root != NULL ) (*_root)->down = *_sibling;
}
*_tail = n;
if ( *_root == NULL ) *_root = *_sibling;
}
}
/* make a new AST node. Make the newly-created
* node the root for the current sibling list. If a root node already
* exists, make the newly-created node the root of the current root.
*/
void
#ifdef __USE_PROTOS
zzsubroot(AST **_root, AST **_sibling, AST **_tail)
#else
zzsubroot(_root, _sibling, _tail)
AST **_root, **_sibling, **_tail;
#endif
{
AST *n;
zzNON_GUESS_MODE {
n = zzastnew();
#ifdef DEMAND_LOOK
zzcr_ast(n, &(zzaCur), LA(0), LATEXT(0));
#else
zzcr_ast(n, &(zzaCur), LA(1), LATEXT(1));
#endif
zzastPush( n );
if ( *_root != NULL )
if ( (*_root)->down == *_sibling ) *_sibling = *_tail = *_root;
*_root = n;
(*_root)->down = *_sibling;
}
}
/* Apply function to root then each sibling
* example: print tree in child-sibling LISP-format (AST has token field)
*
* void show(tree)
* AST *tree;
* {
* if ( tree == NULL ) return;
* printf(" %s", zztokens[tree->token]);
* }
*
* void before() { printf(" ("); }
* void after() { printf(" )"); }
*
* LISPdump() { zzpre_ast(tree, show, before, after); }
*
*/
void
#ifdef __USE_PROTOS
zzpre_ast(
AST *tree,
void (*func)(AST *), /* apply this to each tree node */
void (*before)(AST *), /* apply this to root of subtree before preordering it */
void (*after)(AST *)) /* apply this to root of subtree after preordering it */
#else
zzpre_ast(tree, func, before, after)
AST *tree;
void (*func)(), /* apply this to each tree node */
(*before)(), /* apply this to root of subtree before preordering it */
(*after)(); /* apply this to root of subtree after preordering it */
#endif
{
while ( tree!= NULL )
{
if ( tree->down != NULL ) (*before)(tree);
(*func)(tree);
zzpre_ast(tree->down, func, before, after);
if ( tree->down != NULL ) (*after)(tree);
tree = tree->right;
}
}
/* free all AST nodes in tree; apply func to each before freeing */
#if 0
////void
////#ifdef __USE_PROTOS
////zzfree_ast(AST *tree)
////#else
////zzfree_ast(tree)
////AST *tree;
////#endif
////{
//// if ( tree == NULL ) return;
//// zzfree_ast( tree->down );
//// zzfree_ast( tree->right );
//// zztfree( tree );
////}
#endif
/*
MR19 Optimize freeing of the following structure to limit recursion
SAKAI Kiyotaka (ksakai@isr.co.jp)
*/
/*
NULL o
/ \
NULL o
/ \
NULL NULL
*/
/*
MR21 Another refinement to replace recursion with iteration
NAKAJIMA Mutsuki (muc@isr.co.jp).
*/
void
#ifdef __USE_PROTOS
zzfree_ast(AST *tree)
#else
zzfree_ast(tree)
AST *tree;
#endif
{
AST *otree;
if (tree == NULL) return;
while (tree->down == NULL || tree->right == NULL) {
if (tree->down == NULL && tree->right == NULL) {
zztfree(tree);
return;
}
otree = tree;
if (tree->down == NULL) {
tree = tree->right;
} else {
tree = tree->down;
}
zztfree( otree );
}
while (tree != NULL) {
zzfree_ast(tree->down);
otree = tree;
tree = otree->right;
zztfree(otree);
}
}
/* build a tree (root child1 child2 ... NULL)
* If root is NULL, simply make the children siblings and return ptr
* to 1st sibling (child1). If root is not single node, return NULL.
*
* Siblings that are actually siblins lists themselves are handled
* correctly. For example #( NULL, #( NULL, A, B, C), D) results
* in the tree ( NULL A B C D ).
*
* Requires at least two parameters with the last one being NULL. If
* both are NULL, return NULL.
*/
#ifdef PCCTS_USE_STDARG
AST *zztmake(AST *rt, ...)
#else
AST *zztmake(va_alist)
va_dcl
#endif
{
va_list ap;
register AST *child, *sibling=NULL, *tail=NULL /* MR20 */, *w;
AST *root;
#ifdef PCCTS_USE_STDARG
va_start(ap, rt);
root = rt;
#else
va_start(ap);
root = va_arg(ap, AST *);
#endif
if ( root != NULL )
if ( root->down != NULL ) return NULL;
child = va_arg(ap, AST *);
while ( child != NULL )
{
for (w=child; w->right!=NULL; w=w->right) {;} /* find end of child */
if ( sibling == NULL ) {sibling = child; tail = w;}
else {tail->right = child; tail = w;}
child = va_arg(ap, AST *);
}
if ( root==NULL ) root = sibling;
else root->down = sibling;
va_end(ap);
return root;
}
/* tree duplicate */
AST *
#ifdef __USE_PROTOS
zzdup_ast(AST *t)
#else
zzdup_ast(t)
AST *t;
#endif
{
AST *u;
if ( t == NULL ) return NULL;
u = zzastnew();
*u = *t;
#ifdef zzAST_DOUBLE
u->up = NULL; /* set by calling invocation */
u->left = NULL;
#endif
u->right = zzdup_ast(t->right);
u->down = zzdup_ast(t->down);
#ifdef zzAST_DOUBLE
if ( u->right!=NULL ) u->right->left = u;
if ( u->down!=NULL ) u->down->up = u;
#endif
return u;
}
void
#ifdef __USE_PROTOS
zztfree(AST *t)
#else
zztfree(t)
AST *t;
#endif
{
#ifdef zzd_ast
zzd_ast( t );
#endif
free( t );
}
#ifdef zzAST_DOUBLE
/*
* Set the 'up', and 'left' pointers of all nodes in 't'.
* Initial call is double_link(your_tree, NULL, NULL).
*/
void
#ifdef __USE_PROTOS
zzdouble_link(AST *t, AST *left, AST *up)
#else
zzdouble_link(t, left, up)
AST *t, *left, *up;
#endif
{
if ( t==NULL ) return;
t->left = left;
t->up = up;
zzdouble_link(t->down, NULL, t);
zzdouble_link(t->right, t, up);
}
#endif

View File

@@ -0,0 +1,121 @@
/* Abstract syntax tree
*
* Macros, definitions
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ZZAST_H
#define ZZAST_H
#define zzastOvfChk \
if ( zzast_sp <= 0 ) \
{ \
fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__); \
exit(PCCTS_EXIT_FAILURE); \
}
#ifndef USER_DEFINED_AST
#ifndef AST_FIELDS
#define AST_FIELDS
#endif
typedef struct _ast {
struct _ast *right, *down;
#ifdef zzAST_DOUBLE
struct _ast *left, *up;
#endif
AST_FIELDS
} AST;
#else
#ifdef zzAST_DOUBLE
#define AST_REQUIRED_FIELDS struct _ast *right, *down, *left, *up;
#else
#define AST_REQUIRED_FIELDS struct _ast *right, *down;
#endif
#endif
/* N o d e a c c e s s m a c r o s */
#define zzchild(t) (((t)==NULL)? (AST *) NULL:(t->down)) /* MR19 */
#define zzsibling(t) (((t)==NULL)? (AST *) NULL:(t->right)) /* MR19 */
/* define global variables needed by #i stack */
#define zzASTgvars \
AST *zzastStack[ZZAST_STACKSIZE]; \
int zzast_sp = ZZAST_STACKSIZE;
#define zzASTVars AST *_ast = NULL, *_sibling = NULL, *_tail = NULL
#define zzSTR ( (_tail==NULL)?(&_sibling):(&(_tail->right)) )
#define zzastCur (zzastStack[zzast_sp])
#define zzastArg(i) (zzastStack[zztsp-i])
#define zzastPush(p) zzastOvfChk; zzastStack[--zzast_sp] = p;
#define zzastDPush --zzast_sp
#define zzastMARK zztsp=zzast_sp; /* Save state of stack */
#define zzastREL zzast_sp=zztsp; /* Return state of stack */
#define zzrm_ast {zzfree_ast(*_root); _tail = _sibling = (*_root)=NULL;}
extern int zzast_sp;
extern AST *zzastStack[];
/* MR26 */
#ifdef PCCTS_USE_STDARG
AST *zztmake(AST *, ...);
#else
AST *zztmake();
#endif
#ifdef __USE_PROTOS
void zzlink(AST **, AST **, AST **);
void zzsubchild(AST **, AST **, AST **);
void zzsubroot(AST **, AST **, AST **);
void zzpre_ast(AST *, void (*)(AST *), void (*)(AST *), void (*)(AST *));
void zzfree_ast(AST *);
AST *zzdup_ast(AST *);
void zztfree(AST *);
void zzdouble_link(AST *, AST *, AST *);
AST *zzastnew(void);
#else
void zzlink();
AST *zzastnew();
void zzsubchild();
void zzsubroot();
void zzpre_ast();
void zzfree_ast();
AST *zzdup_ast();
void zztfree();
void zzdouble_link();
#endif
#endif

View File

@@ -0,0 +1,46 @@
/* ANTLR attribute definition -- constant width text
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ZZCHARBUF_H
#define ZZCHARBUF_H
#include "pcctscfg.h"
#include "pccts_string.h"
#ifndef D_TextSize
#define D_TextSize 30
#endif
typedef struct { char text[D_TextSize]; } Attrib;
#define zzcr_attr(a,tok,t) strncpy((a)->text, t, D_TextSize-1); \
(a)->text[D_TextSize-1] = '\0';
#endif

View File

@@ -0,0 +1,58 @@
/*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#include "pcctscfg.h"
#ifdef __STDC__
#include "pccts_stdlib.h"
#else
#include <malloc.h>
#endif
#include "pccts_string.h"
/* 133MR1 include stdio.h for fprintf in charptr.c */
#include "pccts_stdio.h"
/* 133MR1 include charptr.h for Attrib in charptr.c */
#include "charptr.h"
#ifdef __USE_PROTOS
zzcr_attr(Attrib *a,int token,char *text)
#else
zzcr_attr(a,token,text)
Attrib *a;
int token;
char *text;
#endif
{
*a = (char *) malloc(strlen(text)+1); /* MR6 */
if ( *a == NULL ) {fprintf(stderr, "zzcr_attr: out of memory!\n"); exit(-1);}
strcpy(*a, text);
}

View File

@@ -0,0 +1,48 @@
/*
*
* 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.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
/*
* WARNING!!!!: charptr.h does NOT make copies and the
* memory is freed after the attribute scope exits.
*/
#ifndef ZZCHARPTR_H
#define ZZCHARPTR_H
typedef char *Attrib;
#define zzdef0(a) {*(a)=NULL;}
/* MR8 Jens Tingleff (jensting@imaginet.fr) */
/* Set memory pointer to null after free() */
#define zzd_attr(a) {if ( *(a)!=NULL ) {free(*(a)); *(a)=NULL; }; }
#ifdef __STDC__
extern zzcr_attr(Attrib *,int,char *);
#endif
#endif

View File

@@ -0,0 +1 @@
#include "pcctscfg.h"

View File

@@ -0,0 +1,504 @@
/* dlgauto.h automaton
*
* 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.
*
* ANTLR 1.33
* Will Cohen and Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2000
*/
#ifndef ZZDEFAUTO_H
#define ZZDEFAUTO_H
/* 10-Apr-97 133MR1 Uses __USE_PROTOS show should #include pcctscfg.h */
#include "pcctscfg.h"
zzchar_t *zzlextext; /* text of most recently matched token */
zzchar_t *zzbegexpr; /* beginning of last reg expr recogn. */
zzchar_t *zzendexpr; /* beginning of last reg expr recogn. */
int zzbufsize = 0; /* number of characters in zzlextext */ /* MR7 */
int zzbegcol = 0; /* column that first character of token is in*/
int zzendcol = 0; /* column that last character of token is in */
int zzline = 1; /* line current token is on */
int zzreal_line=1; /* line of 1st portion of token that is not skipped */
int zzchar; /* character to determine next state */
int zzbufovf; /* indicates that buffer too small for text */
int zzcharfull = 0;
static zzchar_t *zznextpos;/* points to next available position in zzlextext*/
static int zzclass;
#ifdef __USE_PROTOS
void zzerrstd(const char *);
void (*zzerr)(const char *)=zzerrstd;/* pointer to error reporting function */
extern int zzerr_in(void);
static int (*zzfunc_in)(void) = zzerr_in; /* MR20 */
#else
void zzerrstd();
void (*zzerr)()=zzerrstd; /* pointer to error reporting function */
extern int zzerr_in();
static int (*zzfunc_in)() = zzerr_in; /* MR20 */
#endif
static FILE *zzstream_in=0;
static zzchar_t *zzstr_in=0;
#ifdef USER_ZZMODE_STACK
int zzauto = 0;
#else
static int zzauto = 0;
#endif
static int zzadd_erase;
static char zzebuf[70];
#ifdef ZZCOL
#define ZZINC (++zzendcol)
#else
#define ZZINC
#endif
#define ZZGETC_STREAM {zzchar = getc(zzstream_in); zzclass = ZZSHIFT(zzchar);}
#define ZZGETC_FUNC {zzchar = (*zzfunc_in)(); zzclass = ZZSHIFT(zzchar);}
#define ZZGETC_STR { \
if (*zzstr_in){ \
zzchar = *zzstr_in; \
++zzstr_in; \
}else{ \
zzchar = EOF; \
} \
zzclass = ZZSHIFT(zzchar); \
}
#define ZZNEWSTATE (newstate = dfa[state][zzclass])
#ifndef ZZCOPY
#define ZZCOPY \
/* Truncate matching buffer to size (not an error) */ \
if (zznextpos < lastpos){ \
*(zznextpos++) = zzchar; \
}else{ \
zzbufovf = 1; \
}
#endif
void
#ifdef __USE_PROTOS
zzrdstream( FILE *f )
#else
zzrdstream( f )
FILE *f;
#endif
{
/* make sure that it is really set to something, otherwise just
leave it be.
*/
if (f){
/* make sure that there is always someplace to get input
before closing zzstream_in
*/
#if 0
if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );
#endif
zzline = 1;
zzstream_in = f;
zzfunc_in = NULL;
zzstr_in = 0;
zzcharfull = 0;
}
}
void
#ifdef __USE_PROTOS
zzrdfunc( int (*f)(void) )
#else
zzrdfunc( f )
int (*f)();
#endif
{
/* make sure that it is really set to something, otherwise just
leave it be.
*/
if (f){
/* make sure that there is always someplace to get input
before closing zzstream_in
*/
#if 0
if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );
#endif
zzline = 1;
zzstream_in = NULL;
zzfunc_in = f;
zzstr_in = 0;
zzcharfull = 0;
}
}
void
#ifdef __USE_PROTOS
zzrdstr( zzchar_t *s )
#else
zzrdstr( s )
zzchar_t *s;
#endif
{
/* make sure that it is really set to something, otherwise just
leave it be.
*/
if (s){
/* make sure that there is always someplace to get input
before closing zzstream_in
*/
#if 0
if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );
#endif
zzline = 1;
zzstream_in = NULL;
zzfunc_in = 0;
zzstr_in = s;
zzcharfull = 0;
}
}
#ifdef __USE_PROTOS
void zzclose_stream(void)
#else
void zzclose_stream()
#endif
{
#if 0
fclose( zzstream_in );
zzstream_in = NULL;
zzfunc_in = NULL;
#endif
}
/* saves dlg state, but not what feeds dlg (such as file position) */
void
#ifdef __USE_PROTOS
zzsave_dlg_state(struct zzdlg_state *state)
#else
zzsave_dlg_state(state)
struct zzdlg_state *state;
#endif
{
state->stream = zzstream_in;
state->func_ptr = zzfunc_in;
state->str = zzstr_in;
state->auto_num = zzauto;
state->add_erase = zzadd_erase;
state->lookc = zzchar;
state->char_full = zzcharfull;
state->begcol = zzbegcol;
state->endcol = zzendcol;
state->line = zzline;
state->lextext = zzlextext;
state->begexpr = zzbegexpr;
state->endexpr = zzendexpr;
state->bufsize = zzbufsize;
state->bufovf = zzbufovf;
state->nextpos = zznextpos;
state->class_num = zzclass;
}
void
#ifdef __USE_PROTOS
zzrestore_dlg_state(struct zzdlg_state *state)
#else
zzrestore_dlg_state(state)
struct zzdlg_state *state;
#endif
{
zzstream_in = state->stream;
zzfunc_in = state->func_ptr;
zzstr_in = state->str;
zzauto = state->auto_num;
zzadd_erase = state->add_erase;
zzchar = state->lookc;
zzcharfull = state->char_full;
zzbegcol = state->begcol;
zzendcol = state->endcol;
zzline = state->line;
zzlextext = state->lextext;
zzbegexpr = state->begexpr;
zzendexpr = state->endexpr;
zzbufsize = state->bufsize;
zzbufovf = state->bufovf;
zznextpos = state->nextpos;
zzclass = state->class_num;
}
void
#ifdef __USE_PROTOS
zzmode( int m )
#else
zzmode( m )
int m;
#endif
{
/* points to base of dfa table */
if (m<MAX_MODE){
zzauto = m;
/* have to redo class since using different compression */
zzclass = ZZSHIFT(zzchar);
}else{
sprintf(zzebuf,"Invalid automaton mode = %d ",m);
zzerr(zzebuf);
}
}
/* erase what is currently in the buffer, and get a new reg. expr */
#ifdef __USE_PROTOS
void zzskip(void)
#else
void zzskip()
#endif
{
zzadd_erase = 1;
}
/* don't erase what is in the zzlextext buffer, add on to it */
#ifdef __USE_PROTOS
void zzmore()
#else
void zzmore()
#endif
{
zzadd_erase = 2;
}
/* substitute c for the reg. expr last matched and is in the buffer */
#ifdef __USE_PROTOS
void
zzreplchar(zzchar_t c)
#else
void
zzreplchar(c)
zzchar_t c;
#endif
{
/* can't allow overwriting null at end of string */
if (zzbegexpr < &zzlextext[zzbufsize-1]){
*zzbegexpr = c;
*(zzbegexpr+1) = '\0';
}
zzendexpr = zzbegexpr;
if (c != '\0') {
zznextpos = zzbegexpr + 1;
}
else {
zznextpos = zzbegexpr; /* MR30 Zero terminates string. */
}
}
/* replace the string s for the reg. expr last matched and in the buffer */
void
#ifdef __USE_PROTOS
zzreplstr(register zzchar_t *s)
#else
zzreplstr(s)
register zzchar_t *s;
#endif
{
register zzchar_t *l= &zzlextext[zzbufsize -1];
zznextpos = zzbegexpr;
if (s){
while ((zznextpos <= l) && (*(zznextpos++) = *(s++))!=0){
/* empty */
}
/* correct for NULL at end of string */
zznextpos--;
}
if ((zznextpos <= l) && (*(--s) == 0)){
zzbufovf = 0;
}else{
zzbufovf = 1;
}
*(zznextpos) = '\0';
zzendexpr = zznextpos - 1;
}
#ifdef __USE_PROTOS
void zzgettok(void)
#else
void zzgettok()
#endif
{
register int state, newstate;
/* last space reserved for the null char */
zzchar_t *lastpos; /* MR27 Remove register since address operator used. */
skip:
zzreal_line = zzline;
zzbufovf = 0;
lastpos = &zzlextext[zzbufsize-1];
zznextpos = zzlextext;
zzbegcol = zzendcol+1;
more:
zzbegexpr = zznextpos;
#ifdef ZZINTERACTIVE
/* interactive version of automaton */
/* if there is something in zzchar, process it */
state = newstate = dfa_base[zzauto];
if (zzcharfull){
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
if (zzstr_in)
while (zzalternatives[newstate]){
state = newstate;
ZZGETC_STR;
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
else if (zzstream_in)
while (zzalternatives[newstate]){
state = newstate;
ZZGETC_STREAM;
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
else if (zzfunc_in)
while (zzalternatives[newstate]){
state = newstate;
ZZGETC_FUNC;
ZZINC;
ZZCOPY;
ZZNEWSTATE;
}
/* figure out if last character really part of token */
if ((state != dfa_base[zzauto]) && (newstate == DfaStates)){
zzcharfull = 1;
--zznextpos;
}else{
zzcharfull = 0;
state = newstate;
}
*(zznextpos) = '\0';
/* Able to transition out of start state to some non err state?*/
if ( state == dfa_base[zzauto] ){
/* make sure doesn't get stuck */
zzadvance();
}
#else
/* non-interactive version of automaton */
if (!zzcharfull)
zzadvance();
else
ZZINC;
state = dfa_base[zzauto];
if (zzstr_in)
while (ZZNEWSTATE != DfaStates){
state = newstate;
ZZCOPY;
ZZGETC_STR;
ZZINC;
}
else if (zzstream_in)
while (ZZNEWSTATE != DfaStates){
state = newstate;
ZZCOPY;
ZZGETC_STREAM;
ZZINC;
}
else if (zzfunc_in)
while (ZZNEWSTATE != DfaStates){
state = newstate;
ZZCOPY;
ZZGETC_FUNC;
ZZINC;
}
zzcharfull = 1;
if ( state == dfa_base[zzauto] ){
if (zznextpos < lastpos){
*(zznextpos++) = zzchar;
}else{
zzbufovf = 1;
}
*zznextpos = '\0';
/* make sure doesn't get stuck */
zzadvance();
}else{
*zznextpos = '\0';
}
#endif
#ifdef ZZCOL
zzendcol -= zzcharfull;
#endif
zzendexpr = zznextpos -1;
zzadd_erase = 0;
(*actions[accepts[state]])();
switch (zzadd_erase) {
case 1: goto skip;
case 2: goto more;
}
}
#ifdef __USE_PROTOS
void zzadvance(void)
#else
void zzadvance()
#endif
{
if (zzstream_in) { ZZGETC_STREAM; zzcharfull = 1; ZZINC;}
if (zzfunc_in) { ZZGETC_FUNC; zzcharfull = 1; ZZINC;}
if (zzstr_in) { ZZGETC_STR; zzcharfull = 1; ZZINC;}
if (!(zzstream_in || zzfunc_in || zzstr_in)){
zzerr_in();
}
}
void
#ifdef __USE_PROTOS
zzerrstd(const char *s)
#else
zzerrstd(s)
char *s;
#endif
{
zzLexErrCount++; /* MR11 */
fprintf(stderr,
"%s near line %d (text was '%s')\n",
((s == NULL) ? "Lexical error" : s),
zzline,zzlextext);
}
#ifdef __USE_PROTOS
int zzerr_in(void)
#else
int zzerr_in()
#endif
{
fprintf(stderr,"No input stream, function, or string\n");
/* return eof to get out gracefully */
return EOF;
}
#endif

Some files were not shown because too many files have changed in this diff Show More