cccc-3.1.4/0000755000000000000000000000000010357462460011117 5ustar rootrootcccc-3.1.4/bug_reports/0000755000000000000000000000000010357462263013453 5ustar rootrootcccc-3.1.4/bug_reports/prn10.html0000644000000000000000000006722207401205477015310 0ustar rootroot SourceForge: Modify: 233584 - Dislikes "const static" member declarations
  OSDN: Open Source Development NetworkNewsletters - Jobs  SEARCH:   

Counter

Logged In: tim_littlefair
Logout  
Register New Project  
Account Maintenance  

Change My Theme  
My Personal Page  

Bookmark this page  

Search

Require All Words


Project: C and C++ Code Counter
Project Summary  

Project Admin  

Software
Software Map  
New Releases  
Other Site Mirrors  
Code Snippet Library  

SourceForge.net
Site Docs  
Work for Sourceforge!  
Discussion Forums  
Project Help Wanted  
Top Projects  
Site Status  
Contact Support  

jobs.osdn.com  

Compile Farm  

Contact SourceForge.net  
About SourceForge.net  

SourceForge.net Foundries
About Foundries  

Clustering  
Distributed Computing  
Linux on Large Systems  
Linux Kernel  
Linux Drivers  
3D  
Games  
Java  
Printing  
Storage  

 
Project: C and C++ Code Counter

Trackers


Summary |  Admin |  Home Page |  Forums |  Tracker |  Bugs |  Support |  Lists |  Tasks |  News |  Files | 

Submit New | Browse | Reporting | Admin

[ #233584 ] Dislikes "const static" member declarations

 (?)
Submitted By:
Victor B. Putz (vputz)
Date Submitted:
2001-02-22 12:37
Data Type: (?)
Category: (?)
 (admin)
Group: (?)
 (admin)
Assigned To: (?)
 (admin)
Priority: (?)
Status: (?)
Resolution: (?)
Summary: (?)
C++ parser generates errors when members of a function are declared as "const static". It is, however, okay with "static const". Both declarations are acceptable to gcc.

The following file demonstrates:

test.cpp:

class a
{
const static char member;
};

CCCC produces

Parsing
Processing test.cpp as C/C++ (c++.ansi)
test.cpp(3): syntax error at token const
Parser context:
test.cpp(3): trying to match class_block_item_list at 'const
test.cpp(2): trying to match class_block at '{
test.cpp(2): trying to match class_suffix at '{
test.cpp(1): trying to match class_declaration_or_definition at 'class
test.cpp(1): trying to match definition_or_declaration at 'class
test.cpp(1): trying to match link_item at 'class
test.cpp(1): trying to match start at 'class

Use Canned Response: (?)
 (admin)

OR Attach A Comment: (?)

Followups:

No Followups Have Been Posted

Check to Upload & Attach File: (?)

File Description:

Existing Files:

Delete Name Description Download
No Files Currently Attached

Change Log:

No Changes Have Been Made to This Item

 

 

Show Source

Counter

Logged In: tim_littlefair
Logout  
Register New Project  
Account Maintenance  

Change My Theme  
My Personal Page  

Bookmark this page  

Search

Require All Words


Project: C and C++ Code Counter
Project Summary  

Project Admin  

Software
Software Map  
New Releases  
Other Site Mirrors  
Code Snippet Library  

SourceForge.net
Site Docs  
Work for Sourceforge!  
Discussion Forums  
Project Help Wanted  
Top Projects  
Site Status  
Contact Support  

jobs.osdn.com  

Compile Farm  

Contact SourceForge.net  
About SourceForge.net  

SourceForge.net Foundries
About Foundries  

Clustering  
Distributed Computing  
Linux on Large Systems  
Linux Kernel  
Linux Drivers  
3D  
Games  
Java  
Printing  
Storage  

 
Project: C and C++ Code Counter

Trackers


Summary |  Admin |  Home Page |  Forums |  Tracker |  Bugs |  Support |  Lists |  Tasks |  News |  Files | 

Submit New | Browse | Reporting | Admin

[ #233585 ] Does not handle namespace declarations

 (?)
Submitted By:
Victor B. Putz (vputz)
Date Submitted:
2001-02-22 12:45
Data Type: (?)
Category: (?)
 (admin)
Group: (?)
 (admin)
Assigned To: (?)
 (admin)
Priority: (?)
Status: (?)
Resolution: (?)
Summary: (?)
Current version of cccc does not appear to handle namespace declarations. The following program compiles under gcc 2.96-69 but generates errors when parsed under gcc:

namespace a {
void b( void );
};

void a::b( void )
{
}

CCCC generates the following output:

Parsing
Processing test.cpp as C/C++ (c++.ansi)
test.cpp(2): syntax error at token void
Parser context:
test.cpp(1): trying to match namespace_block at 'namespace
test.cpp(1): trying to match link_item at 'namespace
test.cpp(1): trying to match start at 'namespace

test.cpp(3): syntax error at token }
Parser context:
test.cpp(3): trying to match start at '}
test.cpp(2): trying to match start at 'void
test.cpp(1): trying to match start at 'namespace



Unlike my other reports, I cannot seem to restate the code in a manner acceptable to CCCC.

-->VPutz
Use Canned Response: (?)
 (admin)

OR Attach A Comment: (?)

Followups:

No Followups Have Been Posted

Check to Upload & Attach File: (?)

File Description:

Existing Files:

Delete Name Description Download
No Files Currently Attached

Change Log:

No Changes Have Been Made to This Item

 

 

Show Source

Counter

Logged In: tim_littlefair
Logout  
Register New Project  
Account Maintenance  

Change My Theme  
My Personal Page  

Bookmark this page  

Search

Require All Words


Project: C and C++ Code Counter
Project Summary  

Project Admin  

Software
Software Map  
New Releases  
Other Site Mirrors  
Code Snippet Library  

SourceForge.net
Site Docs  
Work for Sourceforge!  
Discussion Forums  
Project Help Wanted  
Top Projects  
Site Status  
Contact Support  

jobs.osdn.com  

Compile Farm  

Contact SourceForge.net  
About SourceForge.net  

SourceForge.net Foundries
About Foundries  

Clustering  
Distributed Computing  
Linux on Large Systems  
Linux Kernel  
Linux Drivers  
3D  
Games  
Java  
Printing  
Storage  

 
Project: C and C++ Code Counter

Trackers


Summary |  Admin |  Home Page |  Forums |  Tracker |  Bugs |  Support |  Lists |  Tasks |  News |  Files | 

Submit New | Browse | Reporting | Admin

[ #233587 ] Does not handle negative numbers in member initializers

 (?)
Submitted By:
Victor B. Putz (vputz)
Date Submitted:
2001-02-22 13:14
Data Type: (?)
Category: (?)
 (admin)
Group: (?)
 (admin)
Assigned To: (?)
 (admin)
Priority: (?)
Status: (?)
Resolution: (?)
Summary: (?)
C++ code parser does not handle negative numbers in member initialization lists. The following code compiles correctly under gcc but cannot be parsed correctly by cccc:

test.cpp
class c
{
int a;
c( void ) :
e( -1 ) {};
};


cccc generates the following:

Parsing
Processing test.cpp as C/C++ (c++.ansi)
test.cpp(4): syntax error at token c
Parser context:
test.cpp(4): trying to match class_block_item_list at 'c
test.cpp(3): trying to match class_block_item_list at 'int
test.cpp(2): trying to match class_block at '{
test.cpp(2): trying to match class_suffix at '{
test.cpp(1): trying to match class_declaration_or_definition at 'class
test.cpp(1): trying to match definition_or_declaration at 'class
test.cpp(1): trying to match link_item at 'class
test.cpp(1): trying to match start at 'class

test.cpp(6): syntax error at token }
Parser context:
test.cpp(6): trying to match start at '}
test.cpp(1): trying to match start at 'class



Changing the "-1" in the example above to a "1" will not generate an error. Enclosing the "-1" in parentheses will also not generate an error.

-->VPutz
Use Canned Response: (?)
 (admin)

OR Attach A Comment: (?)

Followups:

No Followups Have Been Posted

Check to Upload & Attach File: (?)

File Description:

Existing Files:

Delete Name Description Download
No Files Currently Attached

Change Log:

No Changes Have Been Made to This Item

 

 

Show Source

Counter

Logged In: tim_littlefair
Logout  
Register New Project  
Account Maintenance  

Change My Theme  
My Personal Page  

Bookmark this page  

Search

Require All Words


Project: C and C++ Code Counter
Project Summary  

Project Admin  

Software
Software Map  
New Releases  
Other Site Mirrors  
Code Snippet Library  

SourceForge.net
Site Docs  
Work for Sourceforge!  
Discussion Forums  
Project Help Wanted  
Top Projects  
Site Status  
Contact Support  

jobs.osdn.com  

Compile Farm  

Contact SourceForge.net  
About SourceForge.net  

SourceForge.net Foundries
About Foundries  

Clustering  
Distributed Computing  
Linux on Large Systems  
Linux Kernel  
Linux Drivers  
3D  
Games  
Java  
Printing  
Storage  

 
Project: C and C++ Code Counter

Trackers


Summary |  Admin |  Home Page |  Forums |  Tracker |  Bugs |  Support |  Lists |  Tasks |  News |  Files | 

Submit New | Browse | Reporting | Admin

[ #226676 ] java-parsing: assertion bug w/ switch-statement

 (?)
Submitted By:
Erik Pischel (epischel)
Date Submitted:
2000-12-22 12:51
Data Type: (?)
Category: (?)
 (admin)
Group: (?)
 (admin)
Assigned To: (?)
 (admin)
Priority: (?)
Status: (?)
Resolution: (?)
Summary: (?)
Hi,
while using cccc for a project, the processing of 3 out of 167 java files would be aborted due
to
cccc: java.cpp:1278: void JParser::ctorDefinition(const class string &, enum Visibility): Zusicherung »className==LT(1)->getText()« nicht erfüllt.
Aborted
(Zusicherung ~= assertion, nicht erfüllt ~= not fullfilled)

I reduced much code of one of those files and here it is:
==================BEGIN=================================
public class EwoisErrorHandler
{

public synchronized void handleError(
int fehlertyp
)
{

String lvTyp = "";
switch (fehlertyp) {
case WARNING: lvTyp = "Warnung";
break;
case LOGINFO: lvTyp = "LogInfo"; break;
}
StringBuffer buffer = new StringBuffer(lvTyp);
buffer.append("Zeit: ").append("");

}
int WARNING = 1;
int LOGINFO = 2;
}
====================END==============================
But when deleting ".append("")" (last line in the method), cccc does not abort
(although printing out error messages).

Other switching statements are processed w/o abortion.

bye,
erik
Use Canned Response: (?)
 (admin)

OR Attach A Comment: (?)

Followups:

No Followups Have Been Posted

Check to Upload & Attach File: (?)

File Description:

Existing Files:

Delete Name Description Download
No Files Currently Attached

Change Log:

No Changes Have Been Made to This Item

 

 

Show Source

Counter

Logged In: tim_littlefair
Logout  
Register New Project  
Account Maintenance  

Change My Theme  
My Personal Page  

Bookmark this page  

Search

Require All Words


Project: C and C++ Code Counter
Project Summary  

Project Admin  

Software
Software Map  
New Releases  
Other Site Mirrors  
Code Snippet Library  

SourceForge.net
Site Docs  
Work for Sourceforge!  
Discussion Forums  
Project Help Wanted  
Top Projects  
Site Status  
Contact Support  

jobs.osdn.com  

Compile Farm  

Contact SourceForge.net  
About SourceForge.net  

SourceForge.net Foundries
About Foundries  

Clustering  
Distributed Computing  
Linux on Large Systems  
Linux Kernel  
Linux Drivers  
3D  
Games  
Java  
Printing  
Storage  

 
Project: C and C++ Code Counter

Trackers


Summary |  Admin |  Home Page |  Forums |  Tracker |  Bugs |  Support |  Lists |  Tasks |  News |  Files | 

Submit New | Browse | Reporting | Admin

[ #233548 ] Doesn't accept "public virtual" base classes

 (?)
Submitted By:
Victor B. Putz (vputz)
Date Submitted:
2001-02-22 05:13
Data Type: (?)
Category: (?)
 (admin)
Group: (?)
 (admin)
Assigned To: (?)
 (admin)
Priority: (?)
Status: (?)
Resolution: (?)
Summary: (?)
When specifying virtual base classes, CCCC understands the word order "virtual public", but not the word order "public virtual". GCC happily compiles both versions.

For example:

test.cpp :

class a
{
};

class b : public virtual a
{
};

void main( void )
{
}


When run with the above file (gcc-compatible), CCCC responds with the following:

Processing test.cpp as C/C++ (c++.ansi)
test.cpp(5): syntax error at token virtual
Parser context:
test.cpp(5): trying to match type_name at 'virtual
test.cpp(5): trying to match inheritance_item at 'public
test.cpp(5): trying to match inheritance_item_list at 'public
test.cpp(5): trying to match inheritance_list at ':
test.cpp(5): trying to match class_suffix at ':
test.cpp(5): trying to match class_declaration_or_definition at 'class
test.cpp(5): trying to match definition_or_declaration at 'class
test.cpp(5): trying to match link_item at 'class
test.cpp(5): trying to match start at 'class
test.cpp(1): trying to match start at 'class

test.cpp(5): syntax error at token a
Parser context:
test.cpp(5): trying to match class_block at 'a
test.cpp(5): trying to match class_suffix at ':
test.cpp(5): trying to match class_declaration_or_definition at 'class
test.cpp(5): trying to match definition_or_declaration at 'class
test.cpp(5): trying to match link_item at 'class
test.cpp(5): trying to match start at 'class
test.cpp(1): trying to match start at 'class

test.cpp(6): syntax error at token {
Parser context:
test.cpp(5): trying to match class_suffix_trailer at 'a
test.cpp(5): trying to match class_suffix at ':
test.cpp(5): trying to match class_declaration_or_definition at 'class
test.cpp(5): trying to match definition_or_declaration at 'class
test.cpp(5): trying to match link_item at 'class
test.cpp(5): trying to match start at 'class
test.cpp(1): trying to match start at 'class

test.cpp(7): syntax error at token }
Parser context:
test.cpp(7): trying to match start at '}
test.cpp(5): trying to match start at 'class
test.cpp(1): trying to match start at 'class


Generating reports

Primary HTML output is in .cccc/cccc.html
Detailed reports on modules and source are in .cccc
Database dump is in .cccc/cccc.db






Note that if the words "public" and "virtual" are reversed in the above class definition, CCCC seems to be just fine (ie "virtual public" is acceptable to CCCC, but "public virtual" is not).

Perhaps there's a C++ standard that prohibits "public virtual", but gcc, even with warnings on, accepts it without comment.

-->VPutz
Use Canned Response: (?)
 (admin)

OR Attach A Comment: (?)

Followups:

No Followups Have Been Posted

Check to Upload & Attach File: (?)

File Description:

Existing Files:

Delete Name Description Download
No Files Currently Attached

Change Log:

No Changes Have Been Made to This Item

 

 

Show Source

Introduction

CCCC is a tool for the analysis of source code in various languages (primarily C++), which generates a report in HTML format on various measurements of the code processed. Although the tool was originally implemented to process C++ and ANSI C, the present version is also able to process Java source files, and support has been present in earlier versions for Ada95. The name CCCC stands for 'C and C++ Code Counter'.

Measurements of source code of this kind are generally referred to as 'software metrics', or more precisely 'software product metrics' (as the term 'software metrics` also covers measurements of the software process, which are called 'software process metrics'). There is a reasonable consensus among modern opinion leaders in the software engineering field that measurement of some kind is probably a Good Thing, although there is less consensus on what is worth measuring and what the measurements mean.

CCCC has been developed as freeware, and is released in source code form. Users are encouraged to compile the program themselves, and to modify the source to reflect their preferences and interests.

The simplest way of using CCCC is just to run it with the names of a selection of files on the command line like this:

cccc my_types.h big.h small.h *.cc

Alternatively, the for a complex hierarchy, the user could enter a command like this:

find . | cccc - (on Unix family platforms)

or

dir /b/s | cccc - (on DOS/Windows family platforms)

CCCC will process each of the files specified on the command line (using standard wildcard processing were appropriate), or, if the '-' option is specified in the standard input stream. For each file, named, CCCC will examine the extension of the filename, and if the extension is recognized as indicating a supported language, the appropriate parser will run on the file. As each file is parsed, recognition of certain constructs will cause records to be written into an internal database. When all files have been processed, a report on the contents of the internal database will be generated in HTML format. By default the main summary HTML report is generated to the file cccc.htm in a subdirectory called .cccc of the the current working directory, with detailed reports on each module (i.e. C++ or Java class) identified by the analysis run.

In addition to the summary and detailed HTML reports, the run will cause generation of corresponding summary and detailed reports in XML format, and a further file called cccc.db to be created. cccc.db will contain a dump of the internal database of the program in a format delimited with the character '@' (chosen because it is one of the few characters which cannot legally appear in C/C++ non-comment source code).

The report contains a number of tables identifying the modules in the files submitted and covering:

Some of the data presented in the report may be displayed in an emphasized form (either with a bold or italic font, or with a red or yellow background). These are items which have been identified as lying outside ranges which have been laid down as desirable for the particular items. A bold font or red background indicates a value which exceeds a threshold defined as being dangerous for that measure, while italic fonts and yellow backgrounds indicate values below the danger threshold but still above a second lower threshold which has been laid down to indicate cause for concern. The two thresholds are configurable by the user of the tool: see the section below on configuring metric treatment for more details.

Report Contents

The report generated by CCCC normally consists of six tables plus a table of contents at the beginning and some informational material about CCCC itself at the end.

Tables generated

Table name

Description

Project Summary

This table presents summary values of various measures over the body of source code submitted.

Procedural Summary

This table presents values of procedural measures summed for each module identified in the code submitted.

Procedural Details

This table presents values of the same procedural measures covered in the procedural summary report, but this time broken down within each module into the contributions of each member function of the module.

Structural Summary

This table presents counts of fan-in and fan-out relationships to each module identified, and a derived metric called the Henry/Kafura/Shepperd measure, which is calculated as the square of the product of the fan-in and fan-out counts.

Structural Details

This table presents lists of the modules contributing to the relationship counts reported in the structural summary.

Rejected Extents

This table presents a list of code regions which the analyser was unable to parse.

Metrics displayed

Tag

Metric Name

Description

LOC

Lines of Code

This metric counts the lines of non-blank, non-comment source code in a function (LOCf), module (LOCm), or project (LOCp). LOC was one of the earliest metrics to come into use (principally because it is straightforward to measure).

It has an obvious relation to the size or complexity of a piece of code, and

can be calibrated for use in prediction of maintenance effort, although concern has been expressed that use of this metric as a measure of programmer productivity may tend to encourage verbose programming practises and discourage desirable simplification.

MVG

McCabe's Cyclomatic Complexity

A measure of a body of code based on analysis of the cyclomatic complexity of the directed acyclic graph which represents the flow of control within each function. First proposed as a measure of the minimum number of test cases to ensure all parts of each function are exercised, it is now widely accepted as a measure for the detection of code which is likely to be error-prone and/or difficult to maintain.

COM

Comment Lines

A crude measure comparable to LOC of the extent of commenting within a region of code. Not very meaningful in isolation, but sometimes used in ratio with LOC or MVG to ensure that comments are distributed proportionately to the bulk or complexity of a region of code.

L_C,M_C

LOC/COM, MVG/COM

See above

FO,FOc,FOv
FI,FIc,FIc

Fan-out, Fan-in

For a given module A, the fan-out is the number of other modules which the module A uses, while the fan-in is the number of other modules which use A.
See the section below on counting methods for a discussion of the distinction between the variants on each of these measures. these figures.

HKS, HKSv, HKSc

Henry-Kafura/Shepperd measure

This metric is derived by squaring the product of the fan-in and fan-out of each module. The original Henry-Kafura measure, which has been described as a measure of 'information flow complexity' includes a term for the length of the module under consideration, but CCCC uses the measure as modified by Shepperd, which omits this term on the basis that it debases the measure by combining two attributes which can and should be separately measured.
Corresponding to the variants on the fan-in and fan-out measures described above, similar variants are calculated on this metric.

NOM

Number of modules

Number of modules identified in the project. See discussion below about what constitutes a module.

WMC

Weighted methods per class

This measure, proposed by Chidamber and Kemerer, is a count of the number of functions defined in a module multiplied by a weighting factor. The only weighting algorithm suggested in the original formulation is a uniform weighting of one unit per function.

REJ

Rejected lines

This is a measure of the number of non-blank non-comment lines of code which was not successfully analysed by the parser. This is more of a validity check on the report generated than a metric of the code submitted: if the amount of code rejected was more than a small fraction (say 10%) of the total code processed, the meaningfulness of the numbers generated by the run must be in doubt.

Counting methods

CCCC implements simple algorithms to calculate each of the measures presented. The algorithms are intended to present a useful approximation to the underlying quantities, rather than meticulously exact counting: in general agreement with manual counts based on the same definitions should agree with CCCC to within 2-3%. If larger discrepancies are discovered, or if this level of agreement is not considered adequate, users are welcome to modify the source code to implement closer agreement, or to change the counting behaviour to reflect a desired basis of calculation. The basic definitions of each count are as follows:

Command-line syntax

The command line flags supported by CCCC are defined in the file ccccmain.cc. A brief usage message can be generated on standard output by entering the command 'cccc --help'. The same message will be generated on standard error if an invalid command line is entered. As of version 3.pre57 the text generated by this command is as follows:

Usage: 
cccc [options] file1.c ...  
Process files listed on command line.
If the filenames include '-', read a list of files from standard input.
This program is work in progress and is not well documented.
Please be prepared to refer to the source code for the 
meaning of some options.
Options:
--help                   * generate this help message
--outdir=<dname>         * directory for generated files
                           (default=.cccc)
--html_outfile=<fname>   * name of primary HTML report generated 
                           (default=<outdir>/cccc.html)
--xml_outfile=<fname>    * name of primary XML report generated 
                           (default=<outdir>/cccc.xml)
--db_infile=<fname>      * preload internal database from named file
                           (default=no initial content)
--db_outfile=<fname>     * save internal database to named file
                           (default=<outdir>/cccc.db)
--opt_infile=<fname>     * load options from named file
                           (default=use compiled-in option values, 
                           refer to cccc_opt.cc for option information)
--opt_outfile=<fname>    * save options to named file
                           (default=<outdir>/cccc.opt)
--lang=<string>          * use language specified for files specified 
                           after this option 
                           languages supported are c,c++,ada,java
                           (default=use language/extension mapping 
                           controlled by options)
--report_mask=<hex>      * control report content 
                           (refer to ccccmain.cc for mask values) 
--debug_mask=<hex>       * control debug output content 
                           (refer to ccccmain.cc for mask values)

Configuration

Much of the behaviour of CCCC can be controlled by a stream of configuration data. The file cccc_opt.cc contains the default value for this stream, which can be dumped using the --opt_outfile qualifier. The resulting file can then be edited to customize behaviour and loaded into a later run of cccc using the --opt_infile qualifier. As of version 3.pre57, the contents of the file dumped by the command cccc --opt_outfile=cccc.opt are as follows:

CCCC_FileExt@.ADA@ada.95@
CCCC_FileExt@.ADB@ada.95@
CCCC_FileExt@.ADS@ada.95@
CCCC_FileExt@.C@c++.ansi@
CCCC_FileExt@.CC@c++.ansi@
CCCC_FileExt@.CPP@c++.ansi@
CCCC_FileExt@.CXX@c++.ansi@
CCCC_FileExt@.H@c++.ansi@
CCCC_FileExt@.H++@c++.ansi@
CCCC_FileExt@.HH@c++.ansi@
CCCC_FileExt@.HPP@c++.ansi@
CCCC_FileExt@.HXX@c++.ansi@
CCCC_FileExt@.J@java@
CCCC_FileExt@.JAV@java@
CCCC_FileExt@.JAVA@java@
CCCC_FileExt@.ada@ada.95@
CCCC_FileExt@.adb@ada.95@
CCCC_FileExt@.ads@ada.95@
CCCC_FileExt@.c@c.ansi@
CCCC_FileExt@.c++@c++.ansi@
CCCC_FileExt@.cc@c++.ansi@
CCCC_FileExt@.cpp@c++.ansi@
CCCC_FileExt@.cxx@c++.ansi@
CCCC_FileExt@.h@c++.ansi@
CCCC_FileExt@.h++@c++.ansi@
CCCC_FileExt@.hh@c++.ansi@
CCCC_FileExt@.hpp@c++.ansi@
CCCC_FileExt@.hxx@c++.ansi@
CCCC_FileExt@.j@java@
CCCC_FileExt@.jav@java@
CCCC_FileExt@.java@java@
CCCC_MetTmnt@8.3@999999.000000@999999.000000@0@8@3@General format for fixed precision 3 d.p.@
CCCC_MetTmnt@CBO@12.000000@30.000000@0@6@0@Coupling between objects@
CCCC_MetTmnt@COM@999999.000000@999999.000000@0@6@0@Comment lines@
CCCC_MetTmnt@COMper@999999.000000@999999.000000@0@6@3@Comment lines (averaged)@
CCCC_MetTmnt@DIT@3.000000@6.000000@0@6@0@Depth of Inheritance Tree@
CCCC_MetTmnt@FI@12.000000@20.000000@0@6@0@Fan in (overall)@
CCCC_MetTmnt@FIc@6.000000@12.000000@0@6@0@Fan in (concrete uses only)@
CCCC_MetTmnt@FIv@6.000000@12.000000@0@6@0@Fan in (visible uses only)@
CCCC_MetTmnt@FO@12.000000@20.000000@0@6@0@Fan out (overall)@
CCCC_MetTmnt@FOc@6.000000@12.000000@0@6@0@Fan out (concrete uses only)@
CCCC_MetTmnt@FOv@6.000000@12.000000@0@6@0@Fan out (visible uses only)@
CCCC_MetTmnt@IF4@100.000000@1000.000000@0@6@0@Henry-Kafura/Shepperd measure (overall)@
CCCC_MetTmnt@IF4c@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (concrete)@
CCCC_MetTmnt@IF4v@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (visible)@
CCCC_MetTmnt@LOCf@30.000000@100.000000@0@6@0@Lines of code/function@
CCCC_MetTmnt@LOCm@500.000000@2000.000000@0@6@0@Lines of code/single module@
CCCC_MetTmnt@LOCp@999999.000000@999999.000000@0@6@0@Lines of code/project@
CCCC_MetTmnt@LOCper@500.000000@2000.000000@0@6@3@Lines of code/average module@
CCCC_MetTmnt@L_C@7.000000@30.000000@20@6@3@LOC/COM Lines of code/comment line@
CCCC_MetTmnt@MVGf@10.000000@30.000000@0@6@0@Cyclomatic complexity/function@
CCCC_MetTmnt@MVGm@200.000000@1000.000000@0@6@0@Cyclomatic complexity/single module@
CCCC_MetTmnt@MVGp@999999.000000@999999.000000@0@6@0@Cyclomatic complexity/project@
CCCC_MetTmnt@MVGper@200.000000@1000.000000@0@6@3@Cyclomatic complexity/average module@
CCCC_MetTmnt@M_C@5.000000@10.000000@5@6@3@MVG/COM McCabe/comment line@
CCCC_MetTmnt@NOC@4.000000@15.000000@0@6@0@Number of children@
CCCC_MetTmnt@WMC1@30.000000@100.000000@0@6@0@Weighting function=1 unit per method@
CCCC_MetTmnt@WMCv@10.000000@30.000000@0@6@0@Weighting function=1 unit per visible method@
CCCC_Dialect@c++.mfc@BEGIN_MESSAGE_MAP@start_skipping@
CCCC_Dialect@c++.mfc@END_MESSAGE_MAP@stop_skipping@
CCCC_Dialect@c++.stl@__STL_BEGIN_NAMESPACE@ignore@
CCCC_Dialect@c++.stl@__STL_END_NAMESPACE@ignore@

Configuration of the extension/language mapping

Records in the configuration stream of type CCCC_FileExt control the mapping of file extensions to languages.

Treatment of metric values

Records in the configuration stream of type CCCC_MetTmnt control the treatment of values for each of the metrics defined by CCCC.

Ignoring compiler-specific keywords

Records in the configuration stream of type CCCC_Dialect control the handling of dialect-specific pseudo keywords by the CCCC parsers.

Disclaimers

CCCC was produced as an artifact of an academic research project. The primary motivation was to provide a platform for the exploration of issues related to metrics. The program is not now, and will never become, a commercial standard supported product. While CCCC attempts to recover from parse failures, there are some language constructs which cause crashes, and others which result in code going unanalyzed. If CCCC does not report syntax errors and terminates normally, it is likely that all files have been analyzed, otherwise it is strongly recommended that the user does some kind of independent check on the quantity of code ignored, rather than relying on CCCC's own report on 'Rejected Extents'.

There is one further important disclaimer. As noted above, the primary motivation for the development of CCCC was to aid an academic project to investigate the use of metrics. Over the five years or so the project was running various research activities were conducted, culminating in a practical experiment into the value of metric analysis data in a simulated software engineering task. The aim of this final experiment was to attempt to demonstrate a benefit from the use of such data, its conclusion was that, at best, the presence of a benefit was "not proven". The research project, including the design and outcomes of the final experiment is described at http://www.fchs.ecu.edu.au/~tlittlef, which includes a link to download a PDF of the final PhD thesis arising from the project.

The CCCC project is now dormant. There are no plans for new releases, either to add new features to the program or to fix existing defects. The current version of the program is released under the GNU Public License, giving users the right to work on the source code to address any specific issues they have. The project is hosted on sourceforge.net, the primary developer, Tim Littlefair, can be contacted by email and will be happy to provide advice and encouragement. Contact details appear on the sourceforge website.

Getting CCCC

The best place to look for information about CCCC is the CCCC home page at http://cccc.sourceforge.net.

CCCC downloads are accessible via the standard SourceForge project hierarchy starting at http://sourceforge.net/projects/cccc. SourceForge also hosts mailing lists where new versions are announced and a bug tracker database for the project.

The CCCC distribution includes a version of the Purdue Compiler Construction Toolset (PCCTS) originally created by Terence Parr and coworkers at Purdue University, later maintained by Tom Moog. Many thanks to Terence, his colleagues and Tom for developing this excellent tool, and for releasing it under terms which make it possible for it to be included in the CCCC distribution.

The Win32 installer package for CCCC is created using version 2.0.18 of the "My Inno Setup Extensions" package by Jordan Russell, based on "Inno Setup" by Martjin Laan. This package can be downloaded from http://www.wintax.nl/isx

The program will also require a C++ compiler to build. Past versions have been buildable with various versions of the GNU C++ compiler and/or Microsoft Visual C++, although the code is intended to be portable to a range of modern C++ compilers (with a bit of work in some cases, as the original code base dates back to times before the ANSI standardisation of the C++ language). The reference build tools for the current version are GCC version 3.3 and the freely distributed Microsoft Visual C++ Toolkit 2003. See http://msdn.microsoft.com/visualc/vctoolkit2003/ for details.

cccc-3.1.4/cccc/COPYING0000644000000000000000000004310510357232456013050 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. cccc-3.1.4/cccc/Cccc.dsp0000644000000000000000000001157607272040214013356 0ustar rootroot# Microsoft Developer Studio Project File - Name="cccc" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) External Target" 0x0106 CFG=cccc - Win32 Release !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "Cccc.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "Cccc.mak" CFG="cccc - Win32 Release" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "cccc - Win32 Release" (based on "Win32 (x86) External Target") !MESSAGE "cccc - Win32 Debug" (based on "Win32 (x86) External Target") !MESSAGE # Begin Project # PROP Scc_ProjName "" # PROP Scc_LocalPath "" !IF "$(CFG)" == "cccc - Win32 Release" # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Cmd_Line "NMAKE /f cccc.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "cccc.exe" # PROP BASE Bsc_Name "cccc.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Cmd_Line "nmake -f w32vc.mak DEBUG=false" # PROP Rebuild_Opt "" # PROP Target_File "\ccccprod\bin\cccc.exe" # PROP Bsc_Name "" # PROP Target_Dir "" !ELSEIF "$(CFG)" == "cccc - Win32 Debug" # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Cmd_Line "NMAKE /f cccc.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "cccc.exe" # PROP BASE Bsc_Name "cccc.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Cmd_Line "nmake -f w32vc.mak DEBUG=true" # PROP Rebuild_Opt "clean all" # PROP Target_File "cccc.exe" # PROP Bsc_Name "" # PROP Target_Dir "" !ENDIF # Begin Target # Name "cccc - Win32 Release" # Name "cccc - Win32 Debug" !IF "$(CFG)" == "cccc - Win32 Release" !ELSEIF "$(CFG)" == "cccc - Win32 Debug" !ENDIF # Begin Group "PCCTS grammars" # PROP Default_Filter "g" # Begin Source File SOURCE=.\ada.g # End Source File # Begin Source File SOURCE=.\cccc.g # End Source File # Begin Source File SOURCE=.\java.g # End Source File # End Group # Begin Group "C++ header files" # PROP Default_Filter "" # Begin Source File SOURCE=.\cccc.h # End Source File # Begin Source File SOURCE=.\cccc_db.h # End Source File # Begin Source File SOURCE=.\cccc_ext.h # End Source File # Begin Source File SOURCE=.\cccc_htm.h # End Source File # Begin Source File SOURCE=.\cccc_itm.h # End Source File # Begin Source File SOURCE=.\cccc_mem.h # End Source File # Begin Source File SOURCE=.\cccc_met.h # End Source File # Begin Source File SOURCE=.\cccc_mod.h # End Source File # Begin Source File SOURCE=.\cccc_opt.h # End Source File # Begin Source File SOURCE=.\cccc_prj.h # End Source File # Begin Source File SOURCE=.\cccc_rec.h # End Source File # Begin Source File SOURCE=.\cccc_tbl.h # End Source File # Begin Source File SOURCE=.\cccc_tok.h # End Source File # Begin Source File SOURCE=.\cccc_use.h # End Source File # Begin Source File SOURCE=.\cccc_utl.h # End Source File # End Group # Begin Group "C++ implementation files" # PROP Default_Filter "" # Begin Source File SOURCE=.\cccc_db.cc # End Source File # Begin Source File SOURCE=.\cccc_ext.cc # End Source File # Begin Source File SOURCE=.\cccc_htm.cc # End Source File # Begin Source File SOURCE=.\cccc_itm.cc # End Source File # Begin Source File SOURCE=.\cccc_mem.cc # End Source File # Begin Source File SOURCE=.\cccc_met.cc # End Source File # Begin Source File SOURCE=.\cccc_mod.cc # End Source File # Begin Source File SOURCE=.\cccc_new.cc # End Source File # Begin Source File SOURCE=.\cccc_opt.cc # End Source File # Begin Source File SOURCE=.\cccc_prj.cc # End Source File # Begin Source File SOURCE=.\cccc_rec.cc # End Source File # Begin Source File SOURCE=.\cccc_tbl.cc # End Source File # Begin Source File SOURCE=.\cccc_tok.cc # End Source File # Begin Source File SOURCE=.\cccc_tpl.cc # End Source File # Begin Source File SOURCE=.\cccc_use.cc # End Source File # Begin Source File SOURCE=.\cccc_utl.cc # End Source File # Begin Source File SOURCE=.\ccccmain.cc # End Source File # End Group # Begin Group "makefiles" # PROP Default_Filter "*.mak" # Begin Source File SOURCE=.\posixgcc.mak # End Source File # Begin Source File SOURCE=.\rules.mak # End Source File # Begin Source File SOURCE=.\w32bcb.mak # End Source File # Begin Source File SOURCE=.\w32cygnus.mak # End Source File # Begin Source File SOURCE=.\w32cygnus_gmake.mak # End Source File # Begin Source File SOURCE=.\w32cygnus_nmake.mak # End Source File # Begin Source File SOURCE=.\w32vc.mak # End Source File # End Group # End Target # End Project cccc-3.1.4/cccc/ada.g0000644000000000000000000007517410357241712012720 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // ada95.g // derived from the publicly available files grammar9x.y and lexer9x.l // from Intermetrics, available from: // somewhere on the internet // the Intermetrics notices: /******* A YACC grammar for Ada 9X *********************************/ /* Copyright (C) Intermetrics, Inc. 1994 Cambridge, MA USA */ /* Copying permitted if accompanied by this statement. */ /* Derivative works are permitted if accompanied by this statement.*/ /* This grammar is thought to be correct as of May 1, 1994 */ /* but as usual there is *no warranty* to that effect. */ /*******************************************************************/ /******* A "lex"-style lexer for Ada 9X ****************************/ /* Copyright (C) Intermetrics, Inc. 1994 Cambridge, MA USA */ /* Copying permitted if accompanied by this statement. */ /* Derivative works are permitted if accompanied by this statement.*/ /* This lexer is known to be only approximately correct, but it is */ /* more than adequate for most uses (the lexing of apostrophe is */ /* not as sophisticated as it needs to be to be "perfect"). */ /* As usual there is *no warranty* but we hope it is useful. */ /*******************************************************************/ #header << #include "cccc.h" #include "cccc_ast.h" #include "cccc_utl.h" // the objects which PCCTS creates for ASTs as the #0 variable etc // have type "pointer to ASTBase", which means they need to be cast // to a pointer to my variant of AST if I want to call my AST // methods on them #define MY_AST(X) ( (AST*) X) >> #lexaction << void lex_error(int tok) { cerr << "Accepting lexical error token " << tok << endl; } >> #token Eof "@" <");>> #token ADA_COMMENT "\-\- ~[\n]* \n" << IncrementCount(tcCOMLINES); newline(); skip(); >> #token WHITESPACE "[\ \r\t\f]" << skip(); >> #token NEWLINE "\n" << if(ANTLRToken::bCodeLine!=0) { IncrementCount(tcCODELINES); } newline(); skip(); >> #token LPAREN "\(" <<;>> #token RPAREN "\)" <<;>> #token LBRACK "\[" <<;>> #token RBRACK "\]" <<;>> #token LBRACE "\{" <<;>> #token RBRACE "\}" <<;>> #token PIPE "\|" <<;>> #token PLUS "\+" <<;>> #token MINUS "\-" <<;>> #token TIMES "\*" <<;>> #token DIVIDE "\/" <<;>> // Ada provides support for explicitly requesting short circuit evaluation // on AND THEN and OR ELSE boolean expressions. // We need to count these as increments to the McCabe value, as they introduce // new paths through the code. // To do this we need to trick the lexer into doing lookahead for us #token AND "and" << mode(AND_RECOGNIZED); >> #lexclass AND_RECOGNIZED #token AND_WS "[\ \t\r\f]" << skip(); >> #token AND_NL "\n" << newline(); skip(); >> #token THEN_AFTER_AND "then" << IncrementCount(tcMCCABES_VG); mode(START); >> #token AND_OTHER1 "~[]" << _endexpr-=1; mode(START); skip(); >> #token AND_OTHER2 "t~[]" << _endexpr-=2; mode(START); skip(); >> #token AND_OTHER3 "th~[]" << _endexpr-=3; mode(START); skip(); >> #token AND_OTHER4 "the~[]" << _endexpr-=4; mode(START); skip(); >> #lexclass START #token OR "or" << mode(OR_RECOGNIZED); >> #lexclass OR_RECOGNIZED #token OR_WS "[\ \t\r\f]" << skip(); >> #token OR_NL "\n" << newline(); skip(); >> #token ELSE_AFTER_OR "else" << IncrementCount(tcMCCABES_VG); mode(START); >> #token OR_OTHER1 "~[]" << _endexpr-=1; mode(START); skip(); >> #token OR_OTHER2 "e~[]" << _endexpr-=2; mode(START); skip(); >> #token OR_OTHER3 "el~[]" << _endexpr-=3; mode(START); skip(); >> #token OR_OTHER4 "els~[]" << _endexpr-=4; mode(START); skip(); >> #lexclass START // We want to use nesting levels to control resynchronisation strategies after // unrecognized text. // in C, C++ and Java, the useful nesting relation is simple: // depth=number of "{" seen - number of "}" seen // (this assumes that people do not use the preprocessor to hide or create // more of one kind of brace than the other) // in Ada, the useful nesting is BEGIN ... END, but there are some // complications as END tokens are used to match with tokens other than the // BEGIN, including IS, DO, LOOP, SELECT, RECORD, IF and CASE. // Of these: // IF, SELECT, LOOP and DO stand in positions similar to an opening // BEGIN, before groups of statements, so we treat them as an alternate // forms of nesting depth increase, // IS before a block of statements or declarations matches an END at the // end // RECORD at the start of a group of declarations matches an END RECORD // at the end. // Unfortunately, IS is used quite widely, sometimes in contexts where // it does not need a matching END, sometimes where it does. Detecting this // in the lexer is not trivial #token PERIOD "." <<;>> #token DOT_DOT ".." <<;>> #token LT_LT "\<\<" <<;>> #token BOX "\<\>" <<;>> #token LT_EQ "\<=" <<;>> #token EXPON "\*\*" <<;>> #token NE "\/=" <<;>> #token GT_GT "/>/>" <<;>> #token GE "\>=" <<;>> #token IS_ASSIGNED ":=" <<;>> #token RIGHT_SHAFT "=\>" <<;>> #token ABORT "abort" <<;>> #token ABS "abs" <<;>> #token ABSTRACT "abstract" <<;>> #token ACCEPT "accept" <<;>> #token ACCESS "access" <<;>> #token ALIASED "aliased" <<;>> #token ALL "all" <<;>> #token ARRAY "array" <<;>> #token AT "at" <<;>> #token BEGiN "begin" <<;>> #token BODY "body" <<;>> #token CASE "case" << IncrementCount(tcMCCABES_VG); >> #token CONSTANT "constant" <<;>> #token DECLARE "declare" <<;>> #token DELAY "delay" <<;>> #token DELTA "delta" <<;>> #token DIGITS "digits" <<;>> #token DO "do" <<;>> #token ELSE "else" <<;>> #token ELSIF "elsif" << IncrementCount(tcMCCABES_VG); >> #token END "end" <<;>> #token ENTRY "entry" <<;>> #token EXCEPTION "exception" <<;>> #token EXIT "exit" <<;>> #token FOR "for" << IncrementCount(tcMCCABES_VG); >> #token FUNCTION "function" <<;>> #token GENERIC "generic" <<;>> #token GOTO "goto" <<;>> #token IF "if" << IncrementCount(tcMCCABES_VG); >> #token IN "in" <<;>> #token IS "is" <<;>> #token LIMITED "limited" <<;>> #token LOOP "loop" <<;>> #token MOD "mod" <<;>> #token NEW "new" <<;>> #token NOT "not" <<;>> #token NuLL "null" <<;>> #token OF "of" <<;>> #token OTHERS "others" <<;>> #token OUT "out" <<;>> #token PACKAGE "package" <<;>> #token PRAGMA "pragma" <<;>> #token PRIVATE "private" <<;>> #token PROCEDURE "procedure" <<;>> #token PROTECTED "protected" <<;>> #token RAISE "raise" <<;>> #token RANGE "range" <<;>> #token RECORD "record" <<;>> #token REM "rem" <<;>> #token RENAMES "renames" <<;>> #token REQUEUE "requeue" <<;>> #token RETURN "return" <<;>> #token REVERSE "reverse" <<;>> #token SELECT "select" <<;>> #token SEPARATE "separate" <<;>> #token SUBTYPE "subtype" <<;>> #token TAGGED "tagged" <<;>> #token TASK "task" <<;>> #token TERMINATE "terminate" <<;>> #token THEN "then" <<;>> #token TYPE "type" <<;>> #token UNTIL "until" <<;>> #token USE "use" <<;>> #token WHEN "when" <<;>> #token WHILE "while" << IncrementCount(tcMCCABES_VG); >> #token WITH "with" <<;>> #token XOR "xor" <<;>> #token IDENTIFIER "[a-zA-Z][_a-zA-Z0-9]*" <<;>> #token CHAR_STRING "\"~[\"]*\"" <<;>> // there is a very nasty lexer ambiguity between single quote as the start of // a character literal, and single quote as the modifier for an attribute // to resolve this, we use the lexclass processing below #token TIC "'" << mode(TIC_SEEN); >> #lexclass TIC_SEEN #token TIC_CHAR_TIC "~[]'" << mode(START); >> #token TIC_LPAREN "\(" << mode(START); return LPAREN; >> #token TIC_IDENTIFIER "[a-zA-Z][_a-zA-Z0-9]+" << mode(START); return IDENTIFIER; >> #token TIC_SHORT_ID "[a-zA-Z]" << mode(START); return IDENTIFIER; >> #token TIC_ERROR "~[]" << mode(START); lex_error(TIC_ERROR); >> #lexclass START /* these are the lex patterns which build up into DECIMAL_LITERAL and BASED_LITERAL which are the two forms of numeric literal used in the original lex/yacc grammar I've implemented them as rules, based on component token patterns as below EXTENDED_DIGIT [0-9a-zA-Z] INTEGER ({DIGIT}(_?{DIGIT})*) EXPONENT ([eE](\+?|-){INTEGER}) DECIMAL_LITERAL {INTEGER}(\.?{INTEGER})?{EXPONENT}? BASE {INTEGER} BASED_INTEGER {EXTENDED_DIGIT}(_?{EXTENDED_DIGIT})* BASED_LITERAL {BASE}#{BASED_INTEGER}(\.{BASED_INTEGER})?#{EXPONENT}? */ #token DECIMAL_STRING "[0-9_]+" << ; >> #token DECIMAL_EXPON "[Ee]{[\+\-]}" << ; >> #token BASED_INDIC_BEG "#" << mode(BASED); >> #lexclass BASED #token BASED_STRING "[_0-9A-Za-z]+" << ; >> #token BASED_POINT "." << ; >> #token BASED_INDIC_END "#" << mode(START); >> // we don't expect to see anything except the tokens above while in // this mode, but just in case... #token BASED_ERROR "~[]" << mode(START); lex_error(BASED_ERROR); >> #lexclass START #tokclass RESYNCHRONISATION { ";" } class AdaPrser { << ParseUtility ps; #define TOKEN_INFO "\t" << LT(1)->getText() << " on line " << LT(1)->getLine() void tracein(char *rulename) { ps.tracein(rulename,guessing,LT(1)); } void traceout(char *rulename) { ps.traceout(rulename,guessing,LT(1)); } void syn( _ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k ) { if(DebugMask&PARSER) { ps.syn(tok); } } /* Parser Members */ string parse_language; public: void init(const string& filename, const string& language) { ps.reset(this); ps.set_string(pssFILE, filename); parse_language=language; ANTLRParser::init(); } >> goal_symbol : compilation Eof ; // numeric literal handling numeric_literal : decimal_literal | based_literal ; decimal_literal : DECIMAL_STRING { decimal_fractional_part } { decimal_exponent } | decimal_fractional_part { decimal_exponent } ; decimal_fractional_part : PERIOD DECIMAL_STRING ; decimal_exponent : DECIMAL_EXPON DECIMAL_STRING ; based_literal : DECIMAL_STRING based_number { decimal_exponent } ; based_number : BASED_INDIC_BEG based_float BASED_INDIC_END ; based_float : BASED_STRING { BASED_POINT BASED_STRING } | BASED_POINT BASED_STRING ; error : << (LT(1)->getType() == 9999) >>? "!!!!!!" ";" ; pragma! : PRAGMA simple_name { LPAREN pragma_arg_s RPAREN } ";" ; pragma_arg_s : pragma_arg ( "," pragma_arg )* | /* empty */ ; pragma_arg : (simple_name RIGHT_SHAFT)? simple_name RIGHT_SHAFT expression | expression ; pragma_s : ( pragma )* ; /* recast for LL parsing */ def_id_s : def_id ( "," def_id )* ; def_id : IDENTIFIER ; object_qualifier_opt : ( ALIASED CONSTANT )? | ALIASED | CONSTANT | /* empty */ ; object_subtype_def : subtype_ind | array_type ; init_opt! : IS_ASSIGNED expression | /* empty */ ; object_or_number_decl : def_id_s ":" object_or_number_decl_completion ; object_or_number_decl_completion : CONSTANT IS_ASSIGNED expression ";" | object_qualifier_opt object_subtype_def init_opt ";" ; type_decl : TYPE IDENTIFIER discrim_part_opt type_completion ";" ; discrim_part_opt : discrim_part | LPAREN BOX RPAREN | /* empty */ ; type_completion : IS type_def | /* empty */ ; type_def : (private_type)? | enumeration_type | integer_type | real_type | array_type | record_type | access_type | derived_type ; subtype_decl : SUBTYPE IDENTIFIER IS subtype_ind ";" ; subtype_ind : ( name constraint )? | name ; constraint : range_constraint | decimal_digits_constraint ; decimal_digits_constraint : DIGITS expression range_constr_opt ; derived_type : { ABSTRACT } NEW subtype_ind subtype_opt_with_extension ; subtype_opt_with_extension : WITH PRIVATE | WITH record_def | /* empty */ ; range_constraint : RANGE range ; range : ( name TIC RANGE LPAREN expression RPAREN )? | ( name TIC RANGE )? | simple_expression DOT_DOT simple_expression ; enumeration_type : LPAREN enum_id_s RPAREN ; enum_id_s : enum_id ( "," enum_id )* ; enum_id : IDENTIFIER | char_lit ; char_lit : TIC TIC_CHAR_TIC ; integer_type : range_spec | MOD expression ; range_spec : range_constraint ; range_spec_opt : range_spec | /* empty */ ; real_type : float_type | fixed_type ; float_type : DIGITS expression range_spec_opt ; fixed_type : DELTA expression fixed_type_suffix ; fixed_type_suffix : range_spec | DIGITS expression range_spec_opt ; array_type : ARRAY LPAREN array_index_spec RPAREN OF component_subtype_def ; array_index_spec : ( iter_discrete_range_s )? | index_s ; component_subtype_def : { ALIASED } subtype_ind ; index_s : index ( "," index )* ; index : name RANGE BOX ; iter_index_constraint : LPAREN iter_discrete_range_s RPAREN ; iter_discrete_range_s : discrete_range ( "," discrete_range )* ; discrete_range : | ( name range_suffix )? | ( simple_expression DOT_DOT )? simple_expression DOT_DOT simple_expression | name ; range_constr_opt : | range_constraint ; record_type : tagged_opt limited_opt record_def ; record_def : RECORD pragma_s comp_list END RECORD | NuLL RECORD ; tagged_opt : | TAGGED | ABSTRACT TAGGED ; comp_list : comp_decl_s variant_part_opt | variant_part pragma_s | NuLL ";" pragma_s ; comp_decl_s : comp_decl comp_decl_or_pragma_list ; comp_decl_or_pragma_list : (comp_decl)? comp_decl comp_decl_s | (PRAGMA)? pragma comp_decl_s | empty ; variant_part_opt : pragma_s (variant_part pragma_s)* ; comp_decl : def_id_s ":" component_subtype_def init_opt ";" | error ";" ; discrim_part : LPAREN discrim_spec_s RPAREN ; discrim_spec_s : discrim_spec ( ";" discrim_spec )* ; discrim_spec : def_id_s ":" { ACCESS } mark init_opt | error ; variant_part : CASE simple_name IS pragma_s variant_s END CASE ";" ; variant_s : ( variant )* ; variant : WHEN choice_s RIGHT_SHAFT pragma_s comp_list ; choice_s : choice ( PIPE choice )* ; choice : ( discrete_with_range )? | expression | OTHERS ; discrete_with_range : ( name RANGE)? name range_suffix | ( name TIC RANGE )? name range_suffix | simple_expression DOT_DOT simple_expression ; range_suffix : range_constraint | TIC RANGE { LPAREN expression RPAREN } ; access_type : ACCESS subtype_ind | ACCESS CONSTANT subtype_ind | ACCESS ALL subtype_ind | ACCESS { PROTECTED } proc_func_spec ; proc_func_spec : PROCEDURE formal_part_opt | FUNCTION formal_part_opt RETURN mark ; decl_part : decl_item_or_body_s1 ; decl_item_s : (END|PRIVATE)? empty | decl_item_or_body decl_item_s ; empty : /* nothing */ ; decl_item_or_body_s1 : decl_item_or_body decl_item_s ; decl_item_or_body : << // prepare in case we need to resynchronize ANTLRTokenPtr initial_token=LT(1); string initial_text=ps.lookahead_text(3); >> ( generic_decl )? | ( rename_decl )? | type_decl | prot_decl | subtype_decl | pkg_decl | task_decl_or_body | subprog_decl_or_body | use_clause | rep_spec | pragma | pkg_body | prot_body | (exception_decl)? | object_or_number_decl ; << { ANTLRTokenPtr resync_token; int resync_nesting=mytoken(initial_token)->getNestingLevel(); ps.resynchronize(resync_nesting,RESYNCHRONISATION_set,resync_token); cerr << "Syntax error: parser failed to handle " << initial_text << "..." << resync_token->getText() << " on lines " << initial_token->getLine() << " to " << resync_token->getLine() << endl; // now we build an AST representing the rejected area... initial_token->setText(initial_text.c_str()); AST *rejected_ast=new AST(initial_token); AST *rejected_ast_end=new AST(resync_token); rejected_ast->setRight(rejected_ast_end); ps.record_rejected_extent(rejected_ast); // we only delete the root tree - it deletes the other one delete rejected_ast; } >> name : simple_name name_extension_list | operator_symbol ; name_extension_list : (LPAREN|TIC|PERIOD)? extension_item name_extension_list | /* empty */ ; extension_item : index_extension | selection_extension | attribute_extension ; mark : simple_name ( mark_extension )* ; mark_extension : TIC! attribute_id! | PERIOD simple_name ; simple_name : IDENTIFIER ; compound_name : simple_name ( PERIOD simple_name )* ; compound_member_name : first_name_element extra_name_elements ; first_name_element : nm:IDENTIFIER << ps.set_string(pssMEMBER,$nm->getText()); >> ; extra_name_elements : /* empty */ | PERIOD nm:IDENTIFIER extra_name_elements << ps.set_string(pssMODULE,ps.get_string(pssMEMBER)); ps.set_string(pssMEMBER,$nm->getText()); >> ; c_name_list : compound_name ( "," compound_name )* ; used_char : CHAR_LIT ; operator_symbol : CHAR_STRING ; index_extension : LPAREN value_s RPAREN ; value_s : value ( "," value )* ; value : ( discrete_with_range )? | choice_s opt_assoc | error ; opt_assoc : (RIGHT_SHAFT)? RIGHT_SHAFT expression | /* empty */ ; selection_extension : PERIOD simple_name | PERIOD used_char | PERIOD operator_symbol | PERIOD ALL ; attribute_extension : TIC attribute_id ; attribute_id : IDENTIFIER | DIGITS | DELTA | ACCESS ; literal : numeric_literal | used_char | NuLL ; aggregate : LPAREN aggregate_contents RPAREN ; aggregate_contents : ( value_s_2 )? | (choice_s RIGHT_SHAFT)? comp_assoc | expression WITH aggregate_with_operand | NuLL RECORD ; aggregate_with_operand : value_s | NuLL RECORD ; value_s_2 : value "," value ( "," value )* ; comp_assoc : choice_s RIGHT_SHAFT expression ; expression : relation expression_extension ; expression_extension : (logical)? logical expression | (short_circuit)? short_circuit expression | /* empty */ ; logical : AND | OR | XOR ; short_circuit : AND THEN_AFTER_AND | OR ELSE_AFTER_OR ; relation : simple_expression relation_extension ; relation_extension : ( membership range )? | membership name | ( relational simple_expression )* ; relational : "=" | NE | "<" | LT_EQ | ">" | GE ; membership : IN | NOT IN ; simple_expression : (unary)? unary term | term ( adding term )* ; unary : PLUS | MINUS ; adding : PLUS | MINUS | "&" ; term : factor ( multiplying factor )* ; multiplying : TIMES | DIVIDE | MOD | REM ; factor : NOT primary | ABS primary | primary ( EXPON primary )* ; primary : literal | (qualified)? | name | allocator | parenthesized_primary ; parenthesized_primary : LPAREN paren_primary_contents RPAREN ; // in the original grammar, the options here are value_s_2 (i.e. at least // two patterns matching value, separated by commas) or expression // as expression matches value, this creates an ambiguity, so we relax the // rule a little... paren_primary_contents : value ( "," value )* ; qualified : name TIC parenthesized_primary ; allocator : ( NEW qualified )? | NEW name ; statement_s : (statement)? statement statement_s | /* empty */ ; statement : unlabeled | label statement ; unlabeled : simple_stmt | compound_stmt | pragma ; simple_stmt : null_stmt | (assign_stmt)? | exit_stmt | return_stmt | goto_stmt | (procedure_call)? | delay_stmt | abort_stmt | raise_stmt | code_stmt | requeue_stmt | error ";" ; compound_stmt : if_stmt | case_stmt | ( loop_stmt )? | block | accept_stmt | select_stmt ; label : LT_LT IDENTIFIER GT_GT ; null_stmt : NuLL ";" ; assign_stmt : name IS_ASSIGNED expression ";" ; if_stmt : IF cond_clause_s else_opt END IF ";" ; cond_clause_s : cond_clause ( ELSIF cond_clause )* ; cond_clause : cond_part statement_s ; cond_part : condition THEN ; condition : expression ; else_opt : | ELSE statement_s ; case_stmt : case_hdr pragma_s alternative_s END CASE ";" ; case_hdr : CASE expression IS ; alternative_s : | alternative alternative_s ; alternative : WHEN choice_s RIGHT_SHAFT statement_s ; loop_stmt : label_opt iteration basic_loop id_opt ";" ; label_opt : | IDENTIFIER ":" ; iteration : | WHILE condition | iter_part reverse_opt discrete_range ; iter_part : FOR IDENTIFIER IN ; reverse_opt : | REVERSE ; basic_loop : LOOP statement_s END LOOP ; id_opt : | func_designator ; block : label_opt block_decl block_body END id_opt ";" ; block_decl : | DECLARE decl_part ; block_body : BEGiN handled_stmt_s ; handled_stmt_s : statement_s except_handler_part_opt ; except_handler_part_opt : | except_handler_part ; exit_stmt : EXIT name_opt when_opt ";" ; name_opt : | name ; when_opt : | WHEN condition ; return_stmt : RETURN ";" | RETURN expression ";" ; goto_stmt : GOTO name ";" ; subprog_decl_or_body : << string sp_str; UseType ut; >> subprog_spec subprog_decl_or_body_completion>[ut] << ps.record_function_extent(MY_AST(#0),ut); >> ; subprog_decl_or_body_completion > [UseType _retv] : ( IS SEPARATE ";" | ";" ) << _retv=utDECLARATION; ps.set_string(pssDESCRIPTION,"declaration"); >> | ( IS ABSTRACT ";" | IS decl_part block_body END id_opt ";" | IS generic_inst ) << _retv=utDEFINITION; ps.set_string(pssDESCRIPTION,"definition"); >> ; subprog_spec : PROCEDURE proc_designator formal_part_opt | FUNCTION func_designator formal_part_opt return_part_opt ; proc_designator : << string final_name; >> compound_member_name ; func_designator : << string final_name; >> proc_designator | opname:CHAR_STRING << final_name=$opname->getText(); ps.set_string(pssMEMBER,final_name); >> ; formal_part_opt : | formal_part ; return_part : RETURN n:name << ps.set_string(pssUTYPE,MY_AST(#n)->last_token()->getText()); ps.set_string(pssDESCRIPTION,"returns by value"); ps.record_userel_extent(MY_AST(#n),utPARBYVAL); >> ; return_part_opt : return_part | /* empty */ ; formal_part : LPAREN param_s RPAREN ; param_s : param ( ";" param )* ; param : << UseType ut; >> def_id_s ":" param_mode>[ut] mk:mark init_opt << ps.set_string(pssUTYPE,MY_AST(#mk)->last_token()->getText()); ps.set_string(pssDESCRIPTION,"parameter"); ps.record_userel_extent(MY_AST(#mk),ut); >> ; param_mode >[UseType ut]: << $ut=utPARBYVAL; >> | IN | OUT | IN OUT | ACCESS << $ut=utPARBYREF; >> ; procedure_call : name ";" ; pkg_decl : normal_or_instance_pkg_spec ";" ; pkg_spec : normal_or_instance_pkg_spec ; normal_or_instance_pkg_spec : PACKAGE cn:compound_name << ps.set_string( pssMODULE,MY_AST(#cn)->last_token()->getText()); ps.set_string(pssMODTYPE,"Ada package"); >> normal_or_instance_pkg_spec_completion ; normal_or_instance_pkg_spec_completion : RENAMES name << ps.set_string(pssDESCRIPTION,"renames definition"); ps.record_module_extent(MY_AST(#0), utDEFINITION); >> | IS generic_inst << ps.set_string(pssDESCRIPTION,"instanced declaration"); ps.record_module_extent(MY_AST(#0), utDECLARATION); >> | IS decl_item_s private_part END c_id_opt << ps.set_string(pssDESCRIPTION,"declaration"); ps.record_module_extent(MY_AST(#0), utDECLARATION); >> ; private_part : << LT(1)->getType() == END >>? /* empty */ | << LT(1)->getType() == PRIVATE >>? PRIVATE decl_item_s ; c_id_opt : | compound_name ; pkg_body : PACKAGE BODY cn:compound_name << ps.set_string( pssMODULE,MY_AST(#cn)->last_token()->getText()); ps.set_string(pssMODTYPE,"Ada package"); >> IS pkg_body_or_separate ";" ; pkg_body_or_separate : SEPARATE | decl_part body_opt END c_id_opt ; body_opt : | block_body ; private_type : tagged_opt limited_opt PRIVATE ; limited_opt : | LIMITED ; use_clause : USE name_s ";" | USE TYPE name_s ";" ; name_s : name ( "," name )* ; rename_decl : (rename_unit)? | def_id_s ":" rename_completion ; rename_completion : object_qualifier_opt subtype_ind renames ";" | EXCEPTION renames ";" ; rename_unit : PACKAGE compound_name renames ";" | subprog_spec renames ";" | generic_formal_part generic_renames_completion ; generic_renames_completion : PACKAGE compound_name renames ";" | subprog_spec renames ";" ; renames : RENAMES name ; task_decl_or_body : task_spec ";" ; task_spec : TASK TYPE simple_name discrim_part_opt task_def | TASK BODY simple_name IS body_or_separate | TASK simple_name task_def ; body_or_separate : SEPARATE | decl_part block_body END id_opt ";" ; task_def : | IS entry_decl_s rep_spec_s task_private_opt END id_opt ; task_private_opt : | PRIVATE entry_decl_s rep_spec_s ; prot_decl : prot_spec ";" ; prot_spec : PROTECTED prot_item ; prot_item : IDENTIFIER prot_def | TYPE simple_name discrim_part_opt prot_def ; prot_def : IS prot_op_decl_s prot_private_opt END id_opt ; prot_private_opt : | PRIVATE prot_elem_decl_s ; prot_op_decl_s : | prot_op_decl prot_op_decl_s ; prot_op_decl : entry_decl | subprog_spec ";" | rep_spec | pragma ; prot_elem_decl_s : | prot_elem_decl prot_elem_decl_s ; prot_elem_decl : prot_op_decl | comp_decl ; prot_body : PROTECTED BODY simple_name IS prot_separate_or_body ";" ; prot_separate_or_body : SEPARATE | prot_op_body_s END id_opt ; prot_op_body_s : pragma_s ( prot_op_body pragma_s )* ; prot_op_body : entry_body | subprog_decl_or_body ; entry_decl_s : pragma_s ( entry_decl pragma_s )* ; entry_decl : ENTRY IDENTIFIER entry_decl_completion ; entry_decl_completion : ( paren_discrete_range )? paren_discrete_range formal_part_opt ";" | formal_part_opt ";" ; paren_discrete_range : LPAREN discrete_range RPAREN ; entry_body : ENTRY IDENTIFIER { LPAREN iter_part discrete_range RPAREN } formal_part_opt WHEN condition entry_body_part ; entry_body_part : ";" | IS decl_part block_body END id_opt ";" ; rep_spec_s : ( rep_spec pragma_s )* ; entry_call : procedure_call ; accept_stmt : accept_hdr accept_completion ; accept_completion : ";" | DO handled_stmt_s END id_opt ";" ; accept_hdr : ACCEPT entry_name formal_part_opt ; entry_name : simple_name paren_expression_list ; paren_expression_list : ( LPAREN )? LPAREN expression RPAREN paren_expression_list | /* empty */ ; delay_stmt : DELAY expression ";" | DELAY UNTIL expression ";" ; select_stmt : SELECT select_completion ; select_completion : ( select_wait_completion )? | ( async_select_completion )? | entry_completion ; select_wait_completion : guarded_select_alt or_select else_opt END SELECT ";" ; guarded_select_alt : select_alt | WHEN condition RIGHT_SHAFT select_alt ; or_select : ( OR guarded_select_alt )* ; select_alt : accept_stmt stmts_opt | delay_stmt stmts_opt | TERMINATE ";" ; delay_or_entry_alt : delay_stmt stmts_opt | entry_call stmts_opt ; async_select_completion : delay_or_entry_alt THEN ABORT statement_s END SELECT ";" ; entry_completion : entry_call stmts_opt entry_completion_tail ; entry_completion_tail : OR delay_stmt stmts_opt END SELECT ";" | ELSE statement_s END SELECT ";" ; stmts_opt : statement_s | /* empty */ ; abort_stmt : ABORT name_s ";" ; compilation : | comp_unit compilation ; comp_unit : << ParseUtility saved_ps=ps; >> pragma_s cs:opt_context_spec private_opt unit << { ps.set_flag(vPUBLIC); ps.set_string(pssDESCRIPTION,"with relationship"); while(cs != NULL) { if( (MY_AST(#cs)->token.getType() == IDENTIFIER) && (MY_AST(#cs->right())->token.getType() != PERIOD) ) { ps.set_string(pssUTYPE,MY_AST(#cs)->token.getText()); ps.record_userel_extent(MY_AST(#cs),utWITH); ps.set_flag(vPUBLIC); } else if(MY_AST(#cs)->token.getType() == PRIVATE) { ps.set_flag(vPRIVATE); } #cs=MY_AST(#cs->right()); } ps=saved_ps; } >> ; private_opt : | PRIVATE ; opt_context_spec : { context_spec } ; context_spec : with_clause use_clause_opt pragma_with_list ; pragma_with_list : (pragma_with_item)? pragma_with_item pragma_with_list | /* empty */ ; pragma_with_item : pragma | with_clause use_clause_opt ; with_clause : WITH! c_name_list ";"! ; use_clause_opt! : ( use_clause )? use_clause use_clause_opt | /* empty */ ; unit : pkg_decl | pkg_body | subprog_decl_or_body | subunit | generic_decl // | rename_unit ; subunit : SEPARATE LPAREN compound_name RPAREN subunit_body ; subunit_body : subprog_decl_or_body | pkg_body | task_decl_or_body | prot_body ; exception_decl : def_id_s ":" exception_spec ; exception_spec : EXCEPTION ";" | EXCEPTION RENAMES name ";" ; except_handler_part : EXCEPTION ( exception_handler )* ; exception_handler : WHEN { IDENTIFIER ":" } except_choice_s RIGHT_SHAFT statement_s ; except_choice_s : except_choice more_except_choices ; more_except_choices : (PIPE)? PIPE except_choice_s | /* empty */ ; except_choice : name | OTHERS ; raise_stmt : RAISE name_opt ";" ; requeue_stmt : REQUEUE name { WITH ABORT } ";" ; generic_decl : generic_formal_part generic_decl_completion ; generic_decl_completion : subprog_spec ";" | pkg_spec ";" ; /* recast for LL parsing */ generic_formal_part : GENERIC | generic_formal generic_formal_part ; generic_formal : param ";" | TYPE simple_name generic_discrim_part_opt IS generic_type_def ";" | WITH PROCEDURE simple_name formal_part_opt subp_default ";" | WITH FUNCTION func_designator formal_part_opt return_part subp_default ";" | WITH PACKAGE simple_name IS NEW name { LPAREN BOX RPAREN } ";" | use_clause ; generic_discrim_part_opt : | discrim_part | LPAREN BOX RPAREN ; subp_default : | IS name | IS BOX ; generic_type_def : LPAREN BOX RPAREN | RANGE BOX | MOD BOX | ( DELTA BOX DIGITS BOX )? | DELTA BOX | DIGITS BOX | array_type | access_type | private_type | generic_derived_type ; generic_derived_type : NEW subtype_ind { WITH PRIVATE } | ABSTRACT NEW subtype_ind WITH PRIVATE ; generic_inst : NEW name ; rep_spec : FOR mark USE rep_def ; rep_def : expression ";" | RECORD align_opt comp_loc_s END RECORD ";" | AT expression ";" ; align_opt : | AT MOD expression ";" ; comp_loc_s : | mark AT expression RANGE range ";" comp_loc_s ; code_stmt : qualified ";" ; } cccc-3.1.4/cccc/cccc.g0000644000000000000000000010256610357241712013062 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * * A coarse grammar for C++ * This file is designed to be processed by the PCCTS utilities ANTLR and * DLG to generate a scanner and parser for the cccc metric analyser project * * by Tim Littlefair, 1995-2001 */ #header<< #define zzTRACE_RULES #include "AParser.h" #include "cccc.h" #include "cccc_utl.h" #include "cccc_opt.h" // the objects which PCCTS creates for ASTs as the #0 variable etc // have type "pointer to ASTBase", which means they need to be cast // to a pointer to my variant of AST if I want to call my AST // methods on them #define MY_AST(X) ( (AST*) X) // we have a global variable member for the language of the parse so // that we can supply the names of dialects (ansi_c, ansi_c++, mfc_c++ etc) // for contexts where we wish to apply dialect-specific lexing or parsing // rules extern string parse_language; >> #lexaction << #include // Need to see definition of CLexer class before defining the // next actions. // This will mean this file is included twice in CLexer.cpp. This // should do no harm... #include "CLexer.h" // The lexical analyser passes some information through to // the parse store to be integrated with parse information before // recording in the database. inline void IncrementCount(LexicalCount tc) { assert(ParseStore::currentInstance()!=NULL); ParseStore::currentInstance()->IncrementCount(tc); } inline void endOfLine(CLexer &lexer) { assert(ParseStore::currentInstance()!=NULL); ParseStore::currentInstance()->endOfLine(lexer.line()); lexer.newline(); lexer.skip(); } >> #token Eof "@" << replstr(""); >> #token WHITESPACE "[\ \t\r]+" << skip(); >> // handle newlines #token DOS_NL "\r\n" << endOfLine(*this); >> #token MAC_NL "\r" << endOfLine(*this); >> #token UNIX_NL "\n" << endOfLine(*this); >> /* preprocessor constructs - comments, #defines etc */ #token HASH "#" << mode(PREPROC); more(); >> #lexclass PREPROC #token DOS_P_EOL "\r\n" << mode(START); endOfLine(*this); >> #token MAC_P_EOL "\r" << mode(START); endOfLine(*this); >> #token UNIX_P_EOL "\n" << mode(START); endOfLine(*this); >> #token P_LINECONT "\\\n" << ; skip(); >> #token P_ANYTHING "~[\n]" << ; more(); >> #token P_COMMULTI "/\*" << mode(COMMENT_MULTI); more(); skip(); >> #lexclass START /* ** The object oriented design editor Rational Rose/C++ generates source ** inserting directives into source files disguised as comments so that ** C++ source contributed by Rational Rose, which Rose is at liberty to ** change or overwrite can be distinguished from source code written by ** the programmer, which Rose will do its best to preserve. ** We do not count these as user comments. */ #token RR_DIRECTIVE "//##" << mode(RR); skip(); >> #lexclass RR #token RR_ANYTHING "~[\n]" << skip(); >> #token RR_END "\n" << mode(START); endOfLine(*this); >> #lexclass START /* ** for some reason, the string //#define gives an invalid token error ** with //# quoted as the token name, the 'd' lost in space and 'efine' ** quoted as the next token. For the time being we will just try to trap ** this here (NB we _do_ count this as a user comment) */ #token COMDEF "//#" << mode(COMMENT_LINE); skip(); >> #token COMLINE "//" << mode(COMMENT_LINE); skip(); >> #lexclass COMMENT_LINE #token COMLINE_END "\n" << IncrementCount(tcCOMLINES); endOfLine(*this); mode(START); >> #token COMLINE_ANYTHING "~[\n]" << skip(); >> #lexclass START #token COMMULTI "/\*" << mode(COMMENT_MULTI); skip(); >> #lexclass COMMENT_MULTI #token COMMULTI_END "\*/" << IncrementCount(tcCOMLINES); mode(START); skip(); >> #token COMMULTI_EOL "\n" << IncrementCount(tcCOMLINES); endOfLine(*this); >> #token COMMULTI_ANYTHING "~[\n]" << skip(); >> #lexclass START #token STRINGSTART "\"" << mode(CONST_STRING); skip(); >> #lexclass CONST_STRING #token STRINGCONST "\"" << mode(START); >> // thanks to Lynn Wilson for pointing out the need for a simple fix // to handle escaped newlines within string constants #token LYNNS_FIX "\\\n" << endOfLine(*this); >> #token ESCAPED_DQUOTE "\\\"" << skip(); >> #token ESCAPED_OTHER "\\~[\"]" << skip(); >> #token S_ANYTHING "~[\"]" << skip(); >> #lexclass START #token CHARSTART "\'" << mode(CONST_CHAR); skip(); >> #lexclass CONST_CHAR #token CHARCONST "'" << replstr("'.'"); mode(START); >> #token CH_ANYTHING "~[']" << skip(); >> #lexclass START #token LBRACE "\{" << ANTLRToken::IncrementNesting(); >> #token RBRACE "\}" << ANTLRToken::DecrementNesting(); >> #token LPAREN "\(" << ; >> #token RPAREN "\)" << ; >> #token LBRACK "\[" << ; >> #token RBRACK "\]" << ; >> /* keywords */ // Some of the keywords below have recently acquired the prefix // KW_. This is to avoid clashes between items in the token type // enumeration generated by PCCTS and predefined datatypes in Windows. // (Problem first seen under Borland C++ Builder v3). #token ASM "asm" << ; >> #token AUTO "auto" << ; >> #token BREAK "break" << IncrementCount(tcMCCABES_VG); >> #token CASE "case" << ; >> #token CATCH "catch" << ; >> #token KW_CHAR "char" << ; >> #token CLASS "class" << ; >> #token KW_CONST "const" << ; >> #token CONTINUE "continue" << ; >> #token DEFAULT "default" << ; >> #token DELETE "delete" << ; >> #token DO "do" << ; >> #token KW_DOUBLE "double" << ; >> #token ELSE "else" << ; >> #token ENUM "enum" << ; >> #token EXTERN "extern" << ; >> #token KW_FLOAT "float" << ; >> #token FOR "for" << IncrementCount(tcMCCABES_VG); >> #token FRIEND "friend" << ; >> #token GOTO "goto" << ; >> #token IF "if" << IncrementCount(tcMCCABES_VG); >> #token INLINE "inline" << ; >> #token KW_INT "int" << ; >> #token KW_LONG "long" << ; >> #token NEW "new" << ; >> #token OPERATOR "operator" << ; >> #token PRIVATE "private" << ; >> #token PROTECTED "protected" << ; >> #token PUBLIC "public" << ; >> #token REGISTER "register" << ; >> #token RETURN "return" << IncrementCount(tcMCCABES_VG); >> #token KW_SHORT "short" << ; >> #token SIGNED "signed" << ; >> #token SIZEOF "sizeof" << ; >> #token STATIC "static" << ; >> #token STRUCT "struct" << ; >> #token SWITCH "switch" << IncrementCount(tcMCCABES_VG); >> #token TEMPLATE "template" << ; >> #token KW_THIS "this" << ; >> #token THROW "throw" << ; >> #token TRY "try" << ; >> #token TYPEDEF "typedef" << ; >> #token UNION "union" << ; >> #token UNSIGNED "unsigned" << ; >> #token VIRTUAL "virtual" << ; >> #token KW_VOID "void" << ; >> #token VOLATILE "volatile" << ; >> #token WHILE "while" << IncrementCount(tcMCCABES_VG); >> /* operators */ #token "==" << ; >> #token "!=" << ; >> #tokclass EQUAL_OP { "==" "!=" } #token ASSIGN_OP "=" << ; >> #token "\*=" << ; >> #token "\/=" << ; >> #token "%=" << ; >> #token "\+=" << ; >> #token "\-=" << ; >> #token "\>\>=" << ; >> #token "\<\<=" << ; >> #token "&=" << ; >> #token "\^=" << ; >> #token "\|=" << ; >> #tokclass OP_ASSIGN_OP { "\*=" "\/=" "%=" "\+=" "\-=" "\>\>=" "\<\<=" "&=" "\^=" "\|=" } #token "\>\>" << ; >> #token "\<\<" << ; >> #tokclass SHIFT_OP { "\>\>" "\<\<" } #token GREATERTHAN "\>" << ; >> #token LESSTHAN "\<" << ; >> #token GREATEREQUAL "\>=" << ; >> #token LESSEQUAL "\<=" << ; >> #tokclass REL_OP { "\>" "\<" "\>=" "\<=" } #token ASTERISK "\*" << ; >> #token "\/" << ; >> #token "%" << ; >> #tokclass DIV_OP { "\/" "%" } #token "\.\*" << ; >> #token "\-\>\*" << ; >> #tokclass PM_OP { "\.\*" "\->\*" } #token "\+\+" << ; >> #token "\-\-" << ; >> #tokclass INCR_OP { "\+\+" "\-\-" } #token "\+" << ; >> #token "\-" << ; >> #tokclass ADD_OP { "\+" "\-" } #token LOGICAL_AND_OP "&&" << IncrementCount(tcMCCABES_VG); >> #token LOGICAL_OR_OP "\|\|" << IncrementCount(tcMCCABES_VG); >> #token LOGICAL_NOT_OP "!" << ; >> #token QUERY_OP "?" << IncrementCount(tcMCCABES_VG); >> #token AMPERSAND "&" << ; >> #token PIPE "\|" << ; >> #token TILDA "\~" << ; >> #tokclass BITWISE_OP { "&" "\|" "\~" } #token COLONCOLON "::" << ; >> #token ARROW "\-\>" << ; >> #token COLON ":" << ; >> #token PERIOD "\." << ; >> #token COMMA "," << ; >> #token SEMICOLON ";" << ; >> /* ** draft ANSI C++ keywords ** ** this grammar is intended to look forward to ANSI C++, so we at least ** try to lex up the new keywords (taken from the revised appendix to the ** ARM, which claims to cover decisions up to February 1995) ** ** namespaces will be treated as a kind of module, along with class and struct ** ** most of the other keywords will make little difference except ** that they will not be recognized as identifiers ** in general, anyone who is using these keywords as identifiers today, ** probably shouldn't be ** ** most of the rest of the new keywords occur in contexts where we aren't ** looking too hard (e.g. in procedural code rather than declaration or ** definition signatures) */ #token NAMESPACE "namespace" << ; >> #token USING "using" << ; >> #token AND "and" << ; >> #token AND_EQ "and_eq" << ; >> #token BITAND "bitand" << ; >> #token BITOR "bitor" << ; >> #token COMPL "compl" << ; >> #token NOT "not" << ; >> #token OR "or" << ; >> #token OR_EQ "or_eq" << ; >> #token XOR "xor" << ; >> #token XOR_EQ "xor_eq" << ; >> #token KW_BOOL "bool" << ; >> #token BTRUE "true" << ; >> #token BFALSE "false" << ; >> #token STATIC_CAST "static_cast" << ; >> #token REINTERPRET_CAST "reinterpret_cast" << ; >> #token CONST_CAST "const_cast" << ; >> #token DYNAMIC_CAST "dynamic_cast" << ; >> #token TYPEID "typeid" << ; >> // The next definition reserves a member of the token type enumeration for // later use. We do not expect to match the associated regular expression. #token IMPLEMENTATION_KEYWORD "XXXXXXXXXXXXXXXXXXXXXXXXXX" << ; >> /* identifiers */ #token IDENTIFIER "[A-Za-z_][A-Za-z_0-9]*" << // Check whether there are any dialect-specific rules // about the current token. std::string treatment = CCCC_Options::dialectKeywordPolicy(parse_language,lextext()); std::string toktext=lextext(); if( treatment == "ignore" ) { skip(); } // Ultimately, the next two cases will need to be handled // using a #lexclass or something similar, for the moment // we just try to skip the tokens themselves. else if ( treatment == "start_skipping" ) { skip(); } else if ( treatment == "stop_skipping" ) { skip(); } >> /* Literal elements - integer and float numbers and strings */ #lexclass START #token OCT_NUM "[0][0-7]*" #token L_OCT_NUM "[0][0-7]*[Ll]" #token INT_NUM "[1-9][0-9]*" #token L_INT_NUM "[1-9][0-9]*[Ll]" #token HEX_NUM "[0][Xx][0-9A-Fa-f]+" #token L_HEX_NUM "[0][Xx][0-9A-Fa-f]+[Ll]" //#token FNUM "([1-9][0-9]*{.[0-9]*} | {[0]}.[0-9]+ | 0. ) {[Ee]{[\+\-]}[0-9]+}" #token FNUM "([0-9]+.[0-9]+ | [0-9]+. | .[0-9]+ ) {[Ee]{[\+\-]}[0-9]+}" #token ANYTHING "~[\{\}\[\]\(\)@]" << skip(); >> // it is not obvious from the PCCTS documentation that it a token class // may contain things already declared as tokens, but it does not appear // to cause problems #tokclass RESYNCHRONISATION { "\}" ";" } class CParser { << ParseStore* ps; ParseUtility* pu; void tracein(const char *rulename) { pu->tracein(rulename,guessing,LT(1)); } void traceout(const char *rulename) { pu->traceout(rulename,guessing,LT(1)); } void syn( _ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k) { pu->syn(tok,egroup,eset,etok,k); } string typeCombine(const string& modifiers, const string& name, const string& indir) { string retval; if(modifiers.size()>0) { retval=modifiers+" "+name; } else { retval=name; } if(indir.size()>0) { retval+=" "; retval+=indir; } return retval; } // Many of the rules below accept string parameters to // allow upward passing of attributes. // Where the calling context does not need to receive // the attributes, it can use the dummy values defined // here to save allocating a string locally to satisfy the // parameter list. string d1,d2,d3; public: void init(const string& filename, const string& language) { pu=ParseUtility::currentInstance(); ps=ParseStore::currentInstance(); ANTLRParser::init(); parse_language=language; } >> /* ** the start symbol for the grammar: */ start : << string fileScope; >> end_of_file | link_item[fileScope] start ; link_item[string& scope] : (EXTERN STRINGCONST LBRACE)? extern_linkage_block | namespace_block | using_statement | linkage_qualifiers definition_or_declaration[scope] ; end_of_file : eof:Eof << ps->record_other_extent(1,$eof->getLine(),""); >> ; definition_or_declaration[string& scope] : << // get ready in case we need to resynchronize... ANTLRTokenPtr initial_token=LT(1); int startLine=LT(1)->getLine(); string initial_text=pu->lookahead_text(3); >> typedef_definition | ( explicit_template_instantiation )? | ( scoped_member_name SEMICOLON )? // e.g. 'friend CCCC_Project;' | ( scoped_member_name LPAREN )? method_declaration_or_definition_with_implicit_type[scope] | (type[d1,d2,d3] scoped_member_name LPAREN )? method_declaration_or_definition_with_explicit_type[scope] | (type[d1,d2,d3] scoped_member_name )? instance_declaration[scope] | (type[d1,d2,d3] LPAREN ASTERISK scoped_member_name RPAREN)? instance_declaration[scope] | class_declaration_or_definition[scope] | union_definition | enum_definition // suggested by Kenneth H. Cox to deal with coders who put // a semicolon after the '}' at the end of an inline method // definition | SEMICOLON ; << { ANTLRTokenPtr resync_token; int resync_nesting=mytoken(initial_token)->getNestingLevel(); pu->resynchronize(resync_nesting,RESYNCHRONISATION_set,resync_token); cerr << "Syntax error: parser failed to handle " << initial_text << "..." << resync_token->getText() << " on lines " << initial_token->getLine() << " to " << resync_token->getLine() << endl; // record the rejected extent in the database int endLine=LT(1)->getLine(); ps->record_other_extent(startLine,endLine,initial_text); } >> // the following rule is included to cause generation of a token class // which will be passed to the resynchronise() function // it is not intended to be matched within the grammar resync_tokens : RBRACE | SEMICOLON ; extern_linkage_block : << string dummy; >> EXTERN STRINGCONST LBRACE (link_item[dummy])* RBRACE ; namespace_block : << string dummy; >> NAMESPACE { IDENTIFIER } LBRACE (link_item[dummy])* RBRACE SEMICOLON ; using_statement : USING { NAMESPACE } scoped_member_name SEMICOLON ; explicit_template_instantiation : scoped_member_name angle_block SEMICOLON ; class_declaration_or_definition[string& scope] : << int startLine=LT(1)->getLine(); bool is_definition; string modname,modtype; >> class_prefix[modname,modtype] sfx:class_suffix[is_definition,modname] << int endLine=LT(1)->getLine(); if(is_definition==false) { ps->record_module_extent(startLine,endLine,modname,modtype, "declaration",utDECLARATION); } else { ps->record_module_extent(startLine,endLine,modname,modtype, "definition",utDEFINITION); } >> ; class_suffix[bool& is_definition,string& scope] : SEMICOLON << is_definition=false; >> | { inheritance_list[scope] } class_block[scope] class_suffix_trailer << is_definition=true; >> ; // version 3.pre42 // Attempting to add support for C-style anonymous struct declarations, // where there is no class name between the keyword (usually 'struct') // and the start of the definition block, but there are a list of instances // of the anonymous class declared between the end of the definition block // and the semicolon. class_suffix_trailer : opt_instance_list SEMICOLON ; opt_instance_list : IDENTIFIER ( COMMA IDENTIFIER )* | /* empty */ ; union_definition : (anonymous_union_definition)? | named_union_definition ; anonymous_union_definition : UNION brace_block opt_instance_list SEMICOLON ; named_union_definition : << int startLine=LT(1)->getLine(); >> UNION id:IDENTIFIER brace_block SEMICOLON << ps->record_module_extent(startLine,startLine, $id->getText(),"union", "definition",utDEFINITION); >> ; enum_definition : ( anonymous_enum_definition )? | named_enum_definition ; anonymous_enum_definition : ENUM brace_block opt_instance_list SEMICOLON ; named_enum_definition : <getLine(); >> ENUM id:IDENTIFIER brace_block SEMICOLON << ps->record_module_extent(startLine,startLine, $id->getText(),"enum", "definition",utDEFINITION); >> ; /* ** instance_declaration embraces declarations which initialise the variable ** as the same declaration may initialise some variables but not others, ** so we do not have a separate instance_definition rule */ instance_declaration[string& scopeName] : << int startLine=LT(1)->getLine(); string cvQuals,typeName,varName,indir; >> (cv_qualifier[cvQuals])* { STATIC } type_name[typeName] instance_item[indir,varName] ( COMMA instance_item[d1,d2] )* SEMICOLON << if(indir.size()!=0) { ps->record_userel_extent(startLine,startLine, scopeName,varName,typeName, "has by reference", ps->get_visibility(), utHASBYREF); } else { ps->record_userel_extent(startLine,startLine, scopeName,"",typeName, "has by value", ps->get_visibility(), utHASBYVAL); } >> ; class_block [string& scope]: << int saved_visibility=ps->get_flag(psfVISIBILITY); >> LBRACE class_block_item_list[scope] RBRACE << ps->set_flag(psfVISIBILITY,saved_visibility); >> ; class_block_item_list[string& scope] : (class_block_item[scope])? class_block_item[scope] class_block_item_list[scope] | /* empty */ ; class_block_item[string& scope] : ( access_modifier )? | class_item_qualifier_list definition_or_declaration[scope] ; class_item_qualifier_list! : (class_item_qualifier)? class_item_qualifier class_item_qualifier_list | /* empty */ ; class_item_qualifier : FRIEND | VIRTUAL << ps->set_flag(psfVIRTUAL,abTRUE); >> | STATIC << ps->set_flag(psfSTATIC,abTRUE); >> | INLINE ; access_modifier! : access_key COLON ; method_declaration_or_definition_with_implicit_type[string& implicitScope] : << int startLine=LT(1)->getLine(); bool is_definition; string returnType,scope=implicitScope,methodName, paramList; >> method_signature[scope,methodName,paramList] method_suffix[is_definition] << int endLine=LT(1)->getLine(); if(is_definition==false) { ps->record_function_extent(startLine,endLine, returnType,scope, methodName,paramList, "declaration", ps->get_visibility(), utDECLARATION); } else { ps->record_function_extent(startLine,endLine, returnType,scope, methodName,paramList, "definition", ps->get_visibility(), utDEFINITION); } >> ; method_declaration_or_definition_with_explicit_type[string &scope] : << string cvQualifiers,typeName,indirMods; >> type[cvQualifiers,typeName,indirMods] method_declaration_or_definition_with_implicit_type[scope] ; // It has become increasingly obvious that one of the major // reasons for people in the field to use CCCC is to assess // legacy code, which is often not pure ANSI C. // One common idiom which has been reported is hybrid // Kernighan&Ritche/ANSI C with the preprocessor used // to offer either compiler sight of their appropriate // kind of signature. CCCC runs on code which has not // been preprocessed and ignores the preprocessor // directives, so this idiom looks to it as if the // function has two signatures, one after another, // followed by the function's implementation. // Attempts have been made to support this idiom but // they are disabled at present. // Once we have seen the signature of a function, there are a // number of ways the item can end. method_suffix[bool& is_definition] : // a simple declaration SEMICOLON << is_definition=false; >> // declaration of a pure virtual function // NB the value zero may look like a normal integer, but to the // lexer, it is seen as an octal literal | ASSIGN_OP OCT_NUM SEMICOLON << is_definition=false; >> // definition of a constructor with an initializer list | ctor_init_list brace_block << is_definition=true; >> // definition of any other kind of method | brace_block << is_definition=true; >> ; method_signature[string& scope, string& methodName, string& paramList] : << int startLine=LT(1)->getLine(); >> scoped_identifier[scope,methodName] param_list[scope,paramList] opt_const_modifier << >> ; type[string& cvQualifiers, string& typeName, string& indirMods] : (cv_qualifier[cvQualifiers])* { STATIC } type_name[typeName] indirection_modifiers[indirMods] ; cv_qualifier[string& cvQualifiers] : << string nextTokenText=LT(1)->getText(); >> ( KW_CONST | MUTABLE | VOLATILE | REGISTER ) << cvQualifiers=typeCombine(cvQualifiers,nextTokenText,""); >> ; type_name[string& typeName] : builtin_type[typeName] | user_type[typeName] ; indirection_modifiers[string& indirMods] : (indirection_modifier[indirMods])? indirection_modifier[indirMods] indirection_modifiers[indirMods] | /* empty */ ; indirection_modifier[string& indirMods] : (KW_CONST ASTERISK)? << indirMods+="const*"; >> | ASTERISK << indirMods+="*"; >> | AMPERSAND << indirMods+="&"; >> ; builtin_type[string& typeName] : (type_keyword[typeName])+ ; type_keyword[string& typeName] : << string tokenText=LT(1)->getText(); >> ( KW_VOID | KW_BOOL | KW_CHAR | KW_INT | KW_FLOAT | KW_DOUBLE | KW_SHORT | KW_LONG | UNSIGNED | SIGNED ) << // We only really care about the type name so that we // can count relationships between classes, so what we store // here is a bit arbitrary. We choose to represent the type // of composed builtin types such as 'unsigned char' using // only the last keyword (i.e. 'char' in this case), so that // we don't have to have an enormous supression list of different // variants like 'long long unsigned int'. typeName=tokenText; >> ; user_type[string& typeName] : << string scope,name; >> { class_key[d1] } scoped_identifier[scope,name] << typeName=pu->scopeCombine(scope,name); >> ; scoped_member_name: << string dummy1, dummy2; >> scoped_identifier[dummy1,dummy2] ; scoped_identifier[string& scope, string& name] : ( explicit_scope_spec[scope] )? explicit_scope_spec[scope] scoped_identifier[scope,name] | unscoped_member_name[name] ; explicit_scope_spec[string& scope] : cl:IDENTIFIER {angle_block} COLONCOLON << scope=cl->getText(); ps->set_flag(vDONTKNOW); >> ; unscoped_member_name[string& name] : ( (id1:IDENTIFIER angle_block)? << name=$id1->getText(); >> | id2:IDENTIFIER << name=$id2->getText(); >> | dtor_member_name[name] | operator_member_name[name] ) ; dtor_member_name[string& name] : TILDA id:IDENTIFIER << name="~"; name+=$id->getText(); >> ; operator_member_name[string& name] : << string operatorIdentifier; >> OPERATOR operator_identifier[operatorIdentifier] << name+="operator "; name+=operatorIdentifier; >> ; operator_identifier[string& opname] : << string cv,name,indir; opname=LT(1)->getText(); >> (op)? | (new_or_delete LBRACK RBRACK)? << opname+="[]"; >> | new_or_delete | type[cv,name,indir] << opname=name+indir; >> | LPAREN RPAREN << opname="()"; >> | LBRACK RBRACK << opname="[]"; >> ; new_or_delete : NEW | DELETE ; param_list[string& scope, string& params] : << int startLine=LT(1)->getLine(); string param_items; >> ( LPAREN param_list_items[scope,param_items] RPAREN )? << params="("; params+=param_items; params+=")"; >> | paren_block << params="(...)"; >> ; param_list_items [string& scope, string& items] : /* empty */ | param_item[scope,items] more_param_items[scope,items] ; more_param_items[string& scope, string& items] : << string next_item, further_items; >> /* empty */ | COMMA param_item[scope,next_item] more_param_items[scope,further_items] << items+=","; items+=next_item; items+=further_items; >> ; param_item[string& scope, string& item] : param_type[scope,item] param_spec ; param_type[string& scope, string& typeName] : << string cvmods, name, indir; int startLine=LT(1)->getLine(); >> type[cvmods,name,indir] << // we distinguish between value & reference by // looking at the length of the string of indirection // operator associated with the last recognised type if(indir.size()!=0) { ps->record_userel_extent(startLine,startLine, scope,"",name, "pass by reference", ps->get_visibility(), utPARBYREF); } else { ps->record_userel_extent(startLine,startLine, scope,"",name, "pass by value", ps->get_visibility(), utPARBYVAL); } typeName=typeCombine(cvmods,name,indir); >> ; param_spec : { IDENTIFIER } { "=" literal } ; knr_param_decl_list : /* empty */ | instance_declaration[d1] knr_param_decl_list ; << cerr << "failed knr_param_decl_list for token " << static_cast(LT(1)->getType()) << ' ' << LT(1)->getText() << endl; >> opt_const_modifier : /* empty */ << ps->set_flag(psfCONST,abFALSE); >> | KW_CONST << ps->set_flag(psfCONST,abTRUE); >> ; << // fail action for opt_const_modifier // I can't see how we can fail this, but we seem to manage cerr << "failed opt_const_modifier for token " << static_cast(LT(1)->getType()) << ' ' << LT(1)->getText() << endl; >> typedef_definition : << string dummy; >> ( fptr_typedef_definition )? | ( TYPEDEF class_key[dummy])? struct_typedef_definition | simple_typedef_definition ; fptr_typedef_definition : TYPEDEF type[d1,d2,d3] fptr_type_alias SEMICOLON ; // This rule added in response to a report sent by Tennis Smith of // Cisco. // It supports the old C-style idiom where a struct is defined within // a typedef (either with or without a name). // There's a lot of this code out there... struct_typedef_definition : << string dummy; >> TYPEDEF class_key[dummy] identifier_opt brace_block tag_list_opt SEMICOLON ; simple_typedef_definition : TYPEDEF type[d1,d2,d3] simple_type_alias SEMICOLON ; identifier_opt : IDENTIFIER | /* empty */ ; tag_list_opt : tag ( COMMA tag )* | /* empty */ ; tag : ( ASTERISK )* IDENTIFIER ; simple_type_alias : id:IDENTIFIER ; fptr_type_alias : LPAREN ASTERISK scoped_identifier[d1,d2] RPAREN paren_block ; class_or_method_declaration_or_definition[string& scope] : << string dummy; >> (class_key[dummy])? class_declaration_or_definition[scope] | (scoped_member_name LPAREN)? method_declaration_or_definition_with_implicit_type[scope] | method_declaration_or_definition_with_explicit_type[scope] ; class_prefix[string& modname, string& modtype] : class_key[modtype] scoped_identifier[d1,modname] { angle_block } // or perhaps an anonymous type... | class_key[modtype] ; inheritance_list [string& childName] : << ps->set_flag(vPRIVATE); >> COLON inheritance_item_list[childName] ; inheritance_item_list[string& childName] : inheritance_item[childName] ( COMMA inheritance_item[childName])* ; inheritance_access_key : VIRTUAL { access_key } | access_key { VIRTUAL } | /* empty */ ; inheritance_item[string& childName] : << string parent_scope,parent_name; int startLine=LT(1)->getLine(); >> inheritance_access_key type_name[parent_name] << int endLine=LT(1)->getLine(); ps->record_userel_extent(startLine,endLine, childName,"",parent_name, "inheritance", ps->get_visibility(), utINHERITS); >> ; class_key[string& modtype] : << modtype=LT(1)->getText(); >> CLASS << ps->set_flag(vPRIVATE); >> | STRUCT << ps->set_flag(vPUBLIC); >> ; access_key : PUBLIC! << ps->set_flag(vPUBLIC); >> | PRIVATE! << ps->set_flag(vPRIVATE); >> | PROTECTED! << ps->set_flag(vPROTECTED); >> ; ctor_init_list : COLON ctor_init_item_list ; ctor_init_item_list : ( ctor_init_item COMMA )? ctor_init_item COMMA ctor_init_item_list | ctor_init_item ; ctor_init_item : instance_item[d1,d2] ; linkage_qualifiers: (linkage_qualifier)? linkage_qualifier linkage_qualifiers | /* empty */ ; linkage_qualifier : STATIC << ps->set_flag(psfSTATIC,abTRUE); >> | ( EXTERN STRINGCONST )? | EXTERN | INLINE | TEMPLATE { angle_block } ; identifier_or_brace_block_or_both : IDENTIFIER opt_brace_block ; opt_brace_block : ( brace_block )? | /* empty */ ; instance_item[string& indir,string& name] : item_specifier[indir,name] brack_list opt_initializer ; item_specifier[string& indir,string& name] : LPAREN ASTERISK scoped_member_name RPAREN paren_block | (indirection_modifier[indir])* scoped_identifier[d1,name] ; opt_initializer: << string dummy; >> "=" init_expr | ( LPAREN RPAREN )? | LPAREN init_expr RPAREN | /* empty */ ; init_expr : ( init_expr_item op )? init_expr_item op init_expr | init_expr_item ; init_expr_item : SIZEOF paren_block | paren_block | brace_block | (IDENTIFIER paren_block)? | cast_keyword angle_block paren_block | constant ; cast_keyword : STATIC_CAST | CONST_CAST | REINTERPRET_CAST ; init_value: constant | brace_block | paren_block ; keyword : ASM | AUTO | KW_BOOL | BREAK | CASE | CATCH | KW_CHAR | CLASS | KW_CONST | CONTINUE | DEFAULT | DELETE | KW_DOUBLE | DO | DYNAMIC_CAST | ELSE | ENUM | EXTERN | EXPLICIT | BFALSE | KW_FLOAT | FOR | FRIEND | GOTO | IF | INLINE | KW_INT | KW_LONG | NEW | OPERATOR | PRIVATE | PROTECTED | PUBLIC | REGISTER | REINTERPRET_CAST | RETURN | KW_SHORT | SIGNED | SIZEOF | STATIC | STATIC_CAST | STRUCT | SWITCH | TEMPLATE | KW_THIS | THROW | BTRUE | TRY | TYPEDEF | UNION | UNSIGNED | VIRTUAL | KW_VOID | VOLATILE | WHILE ; op : EQUAL_OP | ASSIGN_OP | OP_ASSIGN_OP | SHIFT_OP | REL_OP | ASTERISK | DIV_OP | PM_OP | INCR_OP | ADD_OP | QUERY_OP | LOGICAL_AND_OP | LOGICAL_OR_OP | LOGICAL_NOT_OP | BITWISE_OP | COLONCOLON | COLON | PERIOD | ARROW | COMMA ; constant : literal | IDENTIFIER ; literal : string_literal | CHARCONST | FNUM | OCT_NUM | L_OCT_NUM | HEX_NUM | L_HEX_NUM | INT_NUM | L_INT_NUM | BTRUE | BFALSE | ADD_OP literal ; string_literal : (STRINGCONST STRINGCONST)? STRINGCONST string_literal | STRINGCONST ; block : brace_block | brack_block | paren_block ; balanced : scoped | block | SEMICOLON ; balanced_list : ( balanced )? balanced balanced_list | /* empty */ ; nested_token_list [ int nl ] : nested_token[nl] nested_token_list[nl] | /* empty */ ; nested_token [ int nl ] : << ANTLRTokenPtr la_ptr=LT(1); >> << (la_ptr!=0) && (mytoken(la_ptr)->getNestingLevel() > nl) >>? tok:. ; scoped : ( keyword )? | (op)? | IDENTIFIER | literal ; brace_block : << int brace_level=MY_TOK(LT(1))->getNestingLevel(); >> LBRACE skip_until_matching_rbrace[brace_level] ; skip_until_matching_rbrace [ int brace_level ] : << // this is an init action, so it should be executed unconditionally // when we try to match this rule while(MY_TOK(LT(1))->getNestingLevel()>=brace_level) { if(LT(1)->getType()==Eof) { // We have reached the end of file with unbalanced {} nesting. // Presumably somebody stuffed up. Maybe a preprocessor problem. // Anyway, get out of this rule. Expect a syntax error RSN. break; } else { consume(); } } >> RBRACE ; paren_block : LPAREN balanced_list! RPAREN ; brack_block : LBRACK balanced_list! RBRACK ; brack_list : ( brack_block )? brack_block brack_list | /* empty */ ; angle_balanced_list : << LT(1)->getType() == LESSTHAN >>? angle_block angle_balanced_list | << LT(1)->getType() == GREATERTHAN >>? /* empty, the token will be matched in parent rule angle_block */ | ~GREATERTHAN angle_balanced_list /* consume one token & recurse */ ; angle_block : LESSTHAN! angle_balanced_list! GREATERTHAN! ; } #token TOKENTYPE_MAX // -*-c++-*- (Emacs mode request) cccc-3.1.4/cccc/cccc.h0000644000000000000000000000443410020121650013037 0ustar rootroot/* * cccc.h * diagnostic and portability facilities for the cccc project */ #ifndef _CCCC_H__ #define _CCCC_H__ #ifdef _WIN32 #pragma warning (disable:4786 4503) #endif // I am trying to standardise on using the ANSI C++ names // for the ANSI C header files, and bringing all of // the includes of these libraries into this file. // I have not yet attempted to purge includes for these // files from the other source files. #include #include #include #include #include #include #include using std::string; #include #include #include using std::ostream; using std::istream; using std::ifstream; using std::ofstream; using std::istringstream; using std::ostringstream; using std::stringstream; using std::endl; using std::cout; using std::cerr; // debugging facilities extern int DebugMask; enum DebugFlags { LEXER=0x01, PARSER=0x02, COUNTER=0x04, MEMORY=0x08, EXTENT=0x10, DATABASE=0x20 }; #define DbgMsg(DF,OS,X) if(DebugMask&DF) { OS << X ; } // the global database to which stuff is added... class CCCC_Project; extern CCCC_Project *prj; // a nasty global array of identifiers we want the lexer to ignore #define SKIP_IDENTIFIERS_ARRAY_SIZE 256 extern char *skip_identifiers[SKIP_IDENTIFIERS_ARRAY_SIZE]; #if 0 #include "DLGLexer.h" #endif // These macros were used to cover differences between the way the // old strstream classes were used in Win32 and GNU builds. // The differences are no longer necessary. #define MAKE_STRSTREAM(X) stringstream X; #define CONVERT_STRSTREAM(X) (X) #define RELEASE_STRSTREAM(X) // The -gd option generates uncompilable code with a missing // variable called zzTracePrevRuleName if the generated // files cccc.cpp, java.cpp, ada.cpp don't include a version // of AParser.h seen with zzTRACE_RULES defined. // I'm not sure how this is supposed to work, but for the moment // I am including it here which should make all three files OK. // Note that this could break again if the header files shift around // and AParser.h gets read before zzTRACE_RULES is defined. // Another option is turning -gd off, but its the way we do the // cccc -dp debug output which is very useful. #include "cccc_tok.h" #define zzTRACE_RULES #include "AParser.h" #endif cccc-3.1.4/cccc/cccc_db.cc0000644000000000000000000000767010357241712013666 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "cccc.h" #include #include "cccc_itm.h" #include "cccc_db.h" CCCC_Project *current_loading_project=NULL; CCCC_Module *current_loading_module=NULL; CCCC_Member *current_loading_extent=NULL; CCCC_UseRelationship *current_loading_userel=NULL; #define LINE_BUFFER_SIZE 1000 int ifstr_line; extern CCCC_Project *prj; // the file scope variable last_supplier is used to supress repeated // output of the supplier name in the use relationship section where // the current record has the same supplier as the previous one // the indentation makes this reasonably clear static string last_supplier=""; // persistence facilities #define SEP '@' // This function provides the ability for the persistence functions // defined below to do a quick peek at the first token on the stream // leaving the get pointer at the start of that token. // This should be static, but on MSVC++ this gives me an unresolved // symbol at link. bool PeekAtNextLinePrefix(ifstream& ifstr, string pfx) { bool retval=false; char prefix_buffer[1024]; size_t initial_stream_pos=ifstr.tellg(); ifstr.getline(prefix_buffer,1023,SEP); if(pfx==prefix_buffer) { retval=true; } ifstr.seekg(initial_stream_pos); return retval; } // this is a sort of abstract junkyard function (cf Abstract Factory) template void DisposeOfImportRecord(T *record_ptr, int fromfile_status) { switch(fromfile_status) { case RECORD_ADDED: // the newly created object has been added to the // database // we must not delete it break; case RECORD_TRANSCRIBED: // the database already had an object for this item // the content of the new object was merged in, but the object // itself is no longer required delete record_ptr; break; default: // something went wrong, so we mention it cerr << "Import error " << fromfile_status << " at line " << ifstr_line << " for " << record_ptr->key() << endl; delete record_ptr; } } // when we add a record to, for example, the extent table for a member of // a module, we need to merge the information in the new extent // with what is already known // there are two kinds of merge: // 1. ordinary fields like module_type should either be consistent or // blank for all extents relating to the same module, so where the old // field is blank, we overwrite with the new field // 2. the flags field in CCCC_Member contains a variety of single character // flags giving the visibility, constness, etc. of the member, with '?' being // used to reflect a state of lack of knowledge: in these cases, any other // value can overwrite '?', all other values do not change. void Resolve_Fields(string& field1, string& field2) { if(field1.size()==0) { field1=field2; } } template void DisposeOfImportRecord(CCCC_Module *record_ptr, int fromfile_status); template void DisposeOfImportRecord(CCCC_Member *record_ptr, int fromfile_status); template void DisposeOfImportRecord(CCCC_UseRelationship *record_ptr, int fromfile_status); template void DisposeOfImportRecord(CCCC_Extent *record_ptr, int fromfile_status); cccc-3.1.4/cccc/cccc_db.h0000644000000000000000000000561310357241712013523 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_db.h */ #ifndef CCCC_DB_H #define CCCC_DB_H #include "cccc.h" #include "cccc_ext.h" #include "cccc_rec.h" #include "cccc_prj.h" #include "cccc_mod.h" #include "cccc_mem.h" #include "cccc_use.h" // The various FromFile functions need to indicate to their // caller their status, particularly because the caller will have // allocated an instance of the incoming class on the heap, and needs // to know whether it has to delete it. There are two 'normal' outcomes // plus a potentially infinite range of possible application error // conditions. The normal conditions are where the new instance is // the first encountered of this module/member/relationship/whatever // and the allocated item has been added to the database and must not // be deleted, and when the new instance is of a previously encountered // entity, and the information from the new record has been transcribed // and merged into the instance in the database, and the locally allocated // instance must be deleted. enum GeneralFromFileStatuses { RECORD_TRANSCRIBED = 0, RECORD_ADDED = 1, RECORD_ERROR = 2 // error conditions may return RECORD_ERROR, or may use a distinctive // value defined as a literal }; // This function provides the ability for the persistence functions // defined below to do a quick peek at the first token on the stream // leaving the get pointer at the start of that token. bool PeekAtNextLinePrefix(ifstream& ifstr, string pfx); // These are global variables because I don't want to have // to pass the project, module, member, relationship down into all of the // FromFile methods. // There is probably a better way for a less lazy programmer than me. extern CCCC_Project *current_loading_project; extern CCCC_Module *current_loading_module; extern CCCC_Member *current_loading_extent; extern CCCC_UseRelationship *current_loading_userel; // this one tracks the line number in the input file extern int ifstr_line; template void DisposeOfImportRecord(T *record_ptr, int fromfile_status); void Resolve_Fields(string& field1, string& field2); #endif // CCCC_DB_H cccc-3.1.4/cccc/cccc_ext.cc0000644000000000000000000000732210357241712014073 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_ext.cc */ #include "cccc_itm.h" #include "cccc_ext.h" #include "cccc_db.h" #include "cccc_utl.h" unsigned int CCCC_Extent::nextkey=0; CCCC_Extent::CCCC_Extent() { v=vINVALID; ut=utINVALID; extkey=++nextkey; } CCCC_Extent::CCCC_Extent(CCCC_Item& is) { char v_as_char='!', ut_as_char='!'; if( is.Extract(filename) && is.Extract(linenumber) && is.Extract(description) && is.Extract(flags) && is.Extract(count_buffer) && is.Extract(v_as_char) && is.Extract(ut_as_char) ) { v=(Visibility) v_as_char; ut=(UseType) ut_as_char; } else { // we can trust the string constructor to give us empty strings, // but we need to initialise these v=vDONTKNOW; ut=utDONTKNOW; } extkey=++nextkey; } int CCCC_Extent::AddToItem(CCCC_Item& item) { int retval=FALSE; if( item.Insert(filename) && item.Insert(linenumber) && item.Insert(description) && item.Insert(flags) && item.Insert(count_buffer) && item.Insert((char) v) && item.Insert((char) ut) ) { retval=TRUE; } return retval; } int CCCC_Extent::GetFromItem(CCCC_Item &item) { int retval=FALSE; char v_as_char, ut_as_char; if( item.Extract(filename) && item.Extract(linenumber) && item.Extract(description) && item.Extract(flags) && item.Extract(count_buffer) && item.Extract(v_as_char) && item.Extract(ut_as_char) ) { v = (Visibility) v_as_char; ut = (UseType) ut_as_char; retval=TRUE; } return retval; } string CCCC_Extent::name(int level) const { string rtnbuf; rtnbuf=""; switch(level) { case nlFILENAME: rtnbuf=filename; break; case nlLINENUMBER: rtnbuf=linenumber; break; case nlDESCRIPTION: rtnbuf=description; break; case nlSEARCH: case nlRANK: // Extents have no meaningful internal primary key. // We never want two extents to have the same // key, so we use the running number extkey // which is initialized in both constructors. // This should cause extents to sort in order of // their creation, which is fine. char buf[16]; sprintf(buf,"%015d",extkey); rtnbuf=buf; break; default: rtnbuf+=filename; rtnbuf+=":"; rtnbuf+=linenumber; } return rtnbuf.c_str(); } string CCCC_Extent::key() const { return name(nlRANK); } int CCCC_Extent::get_count(const char* count_tag) { int retval=0; char local_count_buffer[100], *count_tag_ptr, *count_value_ptr; strcpy(local_count_buffer,count_buffer.c_str()); count_tag_ptr=strtok(local_count_buffer,":"); while(count_tag_ptr!=NULL) { count_value_ptr=strtok(NULL," "); if(strcmp(count_tag_ptr, count_tag) ==0) { retval+=atoi(count_value_ptr); } count_tag_ptr=strtok(NULL,":"); } return retval; } cccc-3.1.4/cccc/cccc_ext.h0000644000000000000000000000330310357241712013730 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_ext.h */ #ifndef CCCC_EXT_H #define CCCC_EXT_H #include using std::string; #include "cccc_utl.h" class CCCC_Item; enum ExtentNameLevel { nlFILENAME=-1, nlLINENUMBER=-2, nlDESCRIPTION=-3}; class CCCC_Extent { friend class CCCC_Record; friend class CCCC_Project; string filename; string linenumber; string description; string flags; string count_buffer; UseType ut; Visibility v; static unsigned int nextkey; unsigned int extkey; public: CCCC_Extent(); CCCC_Extent(CCCC_Item& is); string name( int index ) const; string key() const; int GetFromItem(CCCC_Item& item); int AddToItem(CCCC_Item& item); Visibility get_visibility() const { return v; } int get_count(const char *count_tag); UseType get_usetype() const { return ut; } const char* get_description() const { return description.c_str(); } }; #endif // CCCC_EXT_H cccc-3.1.4/cccc/cccc_htm.cc0000644000000000000000000012676610357241712014101 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_htm.cc // this file defines HTML output facilities for the CCCC project #include "cccc.h" #include "cccc_itm.h" #include "cccc_htm.h" // I would love to use the C++ standard preprocessor // directive #if here, but I have had reports before now // of people who are using compilers which only support // #ifdef. #ifdef CCCC_CONF_W32VC #include #else #ifdef CCCC_CONF_W32BC #include #else #include #endif #endif #include #include #include "cccc_utl.h" typedef std::map source_anchor_map_t; source_anchor_map_t source_anchor_map; // class static data members CCCC_Project* CCCC_Html_Stream::prjptr; string CCCC_Html_Stream::outdir; string CCCC_Html_Stream::libdir; void CCCC_Html_Stream::GenerateReports(CCCC_Project* prj, int report_mask, const string& file, const string& dir) { prjptr=prj; outdir=dir; CCCC_Html_Stream main_html_stream(file.c_str(),"Report on software metrics"); if(report_mask & rtCONTENTS) { // For testing purposes, we want to be able to disable the inclusion // of the current time in the report. This enables us to store a // reference version of the report in RCS and expect the program // to generate an identical one at regression testing time. if(report_mask & rtSHOW_GEN_TIME) { main_html_stream.Table_Of_Contents(report_mask,true); } else { main_html_stream.Table_Of_Contents(report_mask,false); } } if(report_mask & rtSUMMARY) { main_html_stream.Project_Summary(); } if(report_mask & rtPROC1) { main_html_stream.Procedural_Summary(); } if(report_mask & rtPROC2) { main_html_stream.Procedural_Detail(); } if(report_mask & rtOODESIGN) { main_html_stream.OO_Design(); } if(report_mask & rtSTRUCT1) { main_html_stream.Structural_Summary(); } if(report_mask & rtSTRUCT2) { main_html_stream.Structural_Detail(); } if(report_mask & rtSEPARATE_MODULES) { main_html_stream.Separate_Modules(); } if(report_mask & rtOTHER) { main_html_stream.Other_Extents(); } if(report_mask & rtSOURCE) { main_html_stream.Source_Listing(); } if(report_mask & rtCCCC) { main_html_stream.Put_Section_Heading("About CCCC","infocccc",1); main_html_stream.fstr << "

This report was generated by the program CCCC, which is FREELY " << "REDISTRIBUTABLE but carries NO WARRANTY." << endl << "

CCCC was developed by Tim Littlefair. " << endl << "as part of a PhD research project. " << "This project is now completed and descriptions of the " << "findings can be accessed at " << "" << "http://www.chs.ecu.edu.au/~tlittlef. " << "

User support for CCCC can be obtained by " << "" << "mailing the list cccc-users@lists.sourceforge.net." << "

Please also visit the CCCC development website at " << "http://cccc.sourceforge.net." << endl; } } CCCC_Html_Stream::~CCCC_Html_Stream() { fstr << "" << endl; fstr.close(); } void CCCC_Html_Stream::Table_Of_Contents(int report_mask, bool showGenTime) { // record the number of report parts in the table, and the // stream put pointer // if we find that we have only generated a single part, we supress // the TOC by seeking to the saved stream offset int number_of_report_parts=0; int saved_stream_offset=fstr.tellp(); fstr << "" << endl << "" << endl; if(report_mask & rtSUMMARY) { Put_Section_TOC_Entry( "Project Summary","projsum", "Summary table of high level measures summed " "over all files processed in the current run."); number_of_report_parts++; } if(report_mask & rtPROC1) { Put_Section_TOC_Entry( "Procedural Metrics Summary", "procsum", "Table of procedural measures (i.e. lines of " "code, lines of comment, McCabe's cyclomatic " "complexity summed over each module."); number_of_report_parts++; } if(report_mask & rtPROC2) { Put_Section_TOC_Entry( "Procedural Metrics Detail", "procdet", "The same procedural metrics as in the procedural " "metrics summary, reported for individual " "functions, grouped by module."); number_of_report_parts++; } if(report_mask & rtOODESIGN) { Put_Section_TOC_Entry( "Object Oriented Design","oodesign", "Table of four of the 6 metrics proposed by " "Chidamber and Kemerer in their various papers on " "'a metrics suite for object oriented design'."); number_of_report_parts++; } if(report_mask & rtSTRUCT1) { Put_Section_TOC_Entry( "Structural Metrics Summary", "structsum", "Structural metrics based on the relationships of " "each module with others. Includes fan-out (i.e. " "number of other modules the current module " "uses), fan-in (number of other modules which use " "the current module), and the Information Flow " "measure suggested by Henry and Kafura, which " "combines these to give a measure of coupling for " "the module."); number_of_report_parts++; } if(report_mask & rtSTRUCT2) { Put_Section_TOC_Entry( "Structural Metrics Detail", "structdet", "The names of the modules included as clients and " "suppliers in the counts for the Structural " "Metrics Summary."); number_of_report_parts++; } if(report_mask & rtOTHER) { Put_Section_TOC_Entry( "Other Extents", "other", "Lexical counts for parts of submitted source " "files which the analyser was unable to assign to " "a module. Each record in this table relates to " "either a part of the code which triggered a " "parse failure, or to the residual lexical counts " "relating to parts of a file not associated with " "a specific module." ); number_of_report_parts++; } if(report_mask & rtCCCC) { Put_Section_TOC_Entry( "About CCCC", "infocccc", "A description of the CCCC program."); number_of_report_parts++; } fstr << "
" << endl << "CCCC Software Metrics Report"; if( prjptr->name(nlSIMPLE)!="" ) { fstr << " on project " << prjptr->name(nlSIMPLE); } fstr << endl; // we have the option to disable the display of the generation time // so that we can generate identical reports for regression testing if(showGenTime==true) { time_t generationTime=time(NULL); fstr << "
generated " << ctime(&generationTime) << endl; } fstr << "
" << endl; if(number_of_report_parts<2) { fstr.seekp(saved_stream_offset); } } void CCCC_Html_Stream::Put_Section_Heading( string heading_title, string heading_tag, int heading_level) { fstr << "" << "" << heading_title << "" << endl; } void CCCC_Html_Stream::Project_Summary() { Put_Section_Heading("Project Summary","projsum",1); fstr << "This table shows measures over the project as a whole." << endl; fstr << "

    " << endl; Metric_Description("NOM","Number of modules", "Number of non-trivial modules identified by the " "analyser. Non-trivial modules include all classes, " "and any other module for which member functions are " "identified."); Metric_Description("LOC","Lines of Code", "Number of non-blank, non-comment lines of source code " "counted by the analyser."); Metric_Description("COM","Lines of Comments", "Number of lines of comment identified by the analyser"); Metric_Description("MVG","McCabe's Cyclomatic Complexity", "A measure of the decision complexity of the functions " "which make up the program." "The strict definition of this measure is that it is " "the number of linearly independent routes through " "a directed acyclic graph which maps the flow of control " "of a subprogram. The analyser counts this by recording " "the number of distinct decision outcomes contained " "within each function, which yields a good approximation " "to the formally defined version of the measure."); Metric_Description("L_C","Lines of code per line of comment", "Indicates density of comments with respect to textual " "size of program"); Metric_Description("M_C","Cyclomatic Complexity per line of comment", "Indicates density of comments with respect to logical " "complexity of program"); Metric_Description("IF4","Information Flow measure", "Measure of information flow between modules suggested " "by Henry and Kafura. The analyser makes an approximate " "count of this by counting inter-module couplings " "identified in the module interfaces."); fstr << "
" << endl << "Two variants on the information flow measure IF4 are also " << "presented, one (IF4v) calculated using only relationships in the " << "visible part of the module interface, and the other (IF4c) " << "calculated using only those relationships which imply that changes " << "to the client must be recompiled of the supplier's definition " << "changes." << endl << endl; // calculate the counts on which all displayed data will be based int nom=prjptr->get_count("NOM"); // number of modules int loc=prjptr->get_count("LOC"); // lines of code int mvg=prjptr->get_count("MVG"); // McCabes cyclomatic complexity int com=prjptr->get_count("COM"); // lines of comment int if4=prjptr->get_count("IF4"); // intermodule complexity (all couplings) int if4v=prjptr->get_count("IF4v"); // intermodule complexity (visible only) int if4c=prjptr->get_count("IF4c"); // intermodule complexity (concrete only) int rej=prjptr->rejected_extent_table.get_count("LOC"); fstr << "" << endl << "" << endl; Put_Header_Cell("Metric",70); Put_Header_Cell("Tag",10); Put_Header_Cell("Overall",10); Put_Header_Cell("Per Module",10); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Number of modules"); Put_Label_Cell("NOM"); Put_Metric_Cell(nom); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Lines of Code",700); Put_Label_Cell("LOC",120); Put_Metric_Cell(loc,"LOCp"); Put_Metric_Cell(loc,nom,"LOCper"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("McCabe's Cyclomatic Number"); Put_Label_Cell("MVG"); Put_Metric_Cell(mvg,"MVGp"); Put_Metric_Cell(mvg,nom,"MVGper"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Lines of Comment"); Put_Label_Cell("COM"); Put_Metric_Cell(com,"COM"); Put_Metric_Cell(com,nom,"COMper"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("LOC/COM"); Put_Label_Cell("L_C"); Put_Metric_Cell(loc,com,"L_C"); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("MVG/COM"); Put_Label_Cell("M_C"); Put_Metric_Cell(mvg,com,"M_C"); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (inclusive)"); Put_Label_Cell("IF4"); Put_Metric_Cell(if4); Put_Metric_Cell(if4,nom,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (visible)"); Put_Label_Cell("IF4v"); Put_Metric_Cell(if4v); Put_Metric_Cell(if4v,nom,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (concrete)"); Put_Label_Cell("IF4c"); Put_Metric_Cell(if4c); Put_Metric_Cell(if4c,nom,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Lines of Code rejected by parser"); Put_Label_Cell("REJ"); Put_Metric_Cell(rej,"REJ"); Put_Label_Cell(""); fstr << "" << endl; fstr << "
" << endl; } void CCCC_Html_Stream::OO_Design() { Put_Section_Heading("Object Oriented Design","oodesign",1); fstr << "
    " << endl; Metric_Description("WMC","Weighted methods per class", "The sum of a weighting function over the functions of " "the module. Two different weighting functions are " "applied: WMC1 uses the nominal weight of 1 for each " "function, and hence measures the number of functions, " "WMCv uses a weighting function which is 1 for functions " "accessible to other modules, 0 for private functions."); Metric_Description("DIT","Depth of inheritance tree", "The length of the longest path of inheritance ending at " "the current module. The deeper the inheritance tree " "for a module, the harder it may be to predict its " "behaviour. On the other hand, increasing depth gives " "the potential of greater reuse by the current module " "of behaviour defined for ancestor classes."); Metric_Description("NOC","Number of children", "The number of modules which inherit directly from the " "current module. Moderate values of this measure " "indicate scope for reuse, however high values may " "indicate an inappropriate abstraction in the design."); Metric_Description("CBO","Coupling between objects", "The number of other modules which are coupled to the " "current module either as a client or a supplier. " "Excessive coupling indicates weakness of module " "encapsulation and may inhibit reuse."); fstr << "
" << endl << endl; fstr << "The label cell for each row in this table provides a link to " << "the module summary table in the detailed report for the " << "module in question" << endl; fstr << "" << endl << "" << endl; Put_Header_Cell("Module Name",50); Put_Header_Cell("WMC1",10); Put_Header_Cell("WMCv",10); Put_Header_Cell("DIT",10); Put_Header_Cell("NOC",10); Put_Header_Cell("CBO",10); fstr << "" << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); int i=0; while(mod_ptr!=NULL) { i++; if( mod_ptr->is_trivial() == FALSE) { char *metric_tags[5]={"WMC1","WMCv","DIT","NOC","CBO"}; fstr << "" << endl; string href=mod_ptr->key()+".html#summary"; Put_Label_Cell(mod_ptr->name(nlSIMPLE).c_str(),0,"",href.c_str()); int j; for(j=0; j<5; j++) { CCCC_Metric metric_value( mod_ptr->get_count(metric_tags[j]), metric_tags[j] ); Put_Metric_Cell(metric_value); } fstr << "" << endl; } mod_ptr=prjptr->module_table.next_item(); } fstr << "
" << endl; } void CCCC_Html_Stream::Procedural_Summary() { Put_Section_Heading("Procedural Metrics Summary","procsum",1); fstr << "For descriptions of each of these metrics see the information " << "preceding the project summary table." << endl << endl; fstr << "The label cell for each row in this table provides a link to " << "the functions table in the detailed report for the " << "module in question" << endl; fstr << "" << endl << "" << endl; Put_Header_Cell("Module Name"); Put_Header_Cell("LOC",8); Put_Header_Cell("MVG",8); Put_Header_Cell("COM",8); Put_Header_Cell("L_C",8); Put_Header_Cell("M_C",8); fstr << "" << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); int i=0; while(mod_ptr!=NULL) { i++; if( mod_ptr->is_trivial() == FALSE) { fstr << "" << endl; string href=mod_ptr->key()+".html#procdet"; Put_Label_Cell(mod_ptr->name(nlSIMPLE).c_str(),0,"",href.c_str()); int loc=mod_ptr->get_count("LOC"); int mvg=mod_ptr->get_count("MVG"); int com=mod_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCm"); CCCC_Metric mmvg(mvg,"MVGm"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Cell(mloc); Put_Metric_Cell(mmvg); Put_Metric_Cell(com); Put_Metric_Cell(ml_c); Put_Metric_Cell(mm_c); fstr << "" << endl; } mod_ptr=prjptr->module_table.next_item(); } fstr << "
" << endl; } void CCCC_Html_Stream::Structural_Summary() { Put_Section_Heading("Structural Metrics Summary","structsum",1); fstr << "
    " << endl; Metric_Description("FI","Fan-in", "The number of other modules which pass information " "into the current module."); Metric_Description("FO","Fan-out", "The number of other modules into which the current " "module passes information"); Metric_Description("IF4","Information Flow measure", "A composite measure of structural complexity, " "calculated as the square of the product of the fan-in " "and fan-out of a single module. Proposed by Henry and " "Kafura."); fstr << "
" << endl; fstr << "Note that the fan-in and fan-out are calculated by examining the " << "interface of each module. As noted above, three variants of each " << "each of these measures are presented: a count restricted to the " << "part of the interface which is externally visible, a count which " << "only includes relationships which imply the client module needs " << "to be recompiled if the supplier's implementation changes, and an " << "inclusive count" << endl << endl; fstr << "The label cell for each row in this table provides a link to " << "the relationships table in the detailed report for the " << "module in question" << endl << endl; fstr << "" << endl; fstr << "" << endl << "" << endl << "" << endl << "" << endl << "" << endl << "" << endl; Put_Header_Cell("vis",7); Put_Header_Cell("con",7); Put_Header_Cell("inc",7); Put_Header_Cell("vis",7); Put_Header_Cell("con",7); Put_Header_Cell("incl",7); Put_Header_Cell("vis",7); Put_Header_Cell("con",7); Put_Header_Cell("inc",7); fstr << "" << endl; CCCC_Module* module_ptr=prjptr->module_table.first_item(); while(module_ptr!=NULL) { if(module_ptr->is_trivial()==FALSE) { fstr << "" << endl; int fov=module_ptr->get_count("FOv"); int foc=module_ptr->get_count("FOc"); int fo=module_ptr->get_count("FO"); int fiv=module_ptr->get_count("FIv"); int fic=module_ptr->get_count("FIc"); int fi=module_ptr->get_count("FI"); int if4v=module_ptr->get_count("IF4v"); int if4c=module_ptr->get_count("IF4c"); int if4=module_ptr->get_count("IF4"); // the last two arguments here turn on links to enable jumping between // the summary and detail cells for the same module string href=module_ptr->key()+".html#structdet"; Put_Label_Cell(module_ptr->name(nlSIMPLE).c_str(), 0, "",href.c_str()); Put_Metric_Cell(CCCC_Metric(fov,"FOv")); Put_Metric_Cell(CCCC_Metric(foc,"FOc")); Put_Metric_Cell(CCCC_Metric(fo,"FO")); Put_Metric_Cell(CCCC_Metric(fiv,"FIv")); Put_Metric_Cell(CCCC_Metric(fic,"FIc")); Put_Metric_Cell(CCCC_Metric(fi,"FI")); Put_Metric_Cell(CCCC_Metric(if4v,"IF4v")); Put_Metric_Cell(CCCC_Metric(if4c,"IF4c")); Put_Metric_Cell(CCCC_Metric(if4,"IF4")); fstr << "" << endl; } module_ptr=prjptr->module_table.next_item(); } fstr << "
Module NameFan-outFan-inIF4
" << endl; } void CCCC_Html_Stream::Put_Structural_Details_Cell( CCCC_Module *mod, CCCC_Project *prj, int mask, UserelNameLevel nl) { fstr << "" << endl; #if 0 std::cerr << "Relationships for " << mod->name(nlMODULE_NAME) << " (" << mod << ")" << std::endl; #endif CCCC_Module::relationship_map_t::iterator iter; CCCC_Module::relationship_map_t *relationship_map=NULL; if(mask==rmeCLIENT) { relationship_map=&(mod->client_map); } else if(mask==rmeSUPPLIER) { relationship_map=&(mod->supplier_map); } if(relationship_map==NULL) { cerr << "unexpected relationship mask " << mask << endl; } else { for( iter=relationship_map->begin(); iter!=relationship_map->end(); iter++ ) { CCCC_UseRelationship *ur_ptr=(*iter).second; fstr << ur_ptr->name(nl) << " "; AugmentedBool vis=ur_ptr->is_visible(); AugmentedBool con=ur_ptr->is_concrete(); #if 0 std::cerr << ur_ptr->name(nlCLIENT) << " uses " << ur_ptr->name(nlSUPPLIER) << std::endl; #endif if( (vis != abFALSE) && (con != abFALSE) ) { fstr << "[CV] "; } else if(vis != abFALSE) { fstr << "[V] "; } else if(con != abFALSE) { fstr << "[C] "; } fstr << "
" << endl; Put_Extent_List(*ur_ptr,true); fstr << "
" << endl; } } // put a non-breaking space in to avoid the unpleasantness which // goes with completely empty cells fstr << " " << endl; fstr << "" << endl; } void CCCC_Html_Stream::Structural_Detail() { Put_Section_Heading("Structural Metrics Detail","structdet",1); fstr << "" << endl; fstr << "" << endl; Put_Header_Cell("Module Name",20); Put_Header_Cell("Clients",40); Put_Header_Cell("Suppliers",40); fstr << "" << endl; CCCC_Module* module_ptr=prjptr->module_table.first_item(); while(module_ptr!=NULL) { if(module_ptr->is_trivial()==FALSE) { fstr << "" << endl; Put_Label_Cell(module_ptr->name(nlSIMPLE).c_str(), 0, "structdet","structsum"); Structural_Detail(module_ptr); fstr << "" << endl; } module_ptr=prjptr->module_table.next_item(); } fstr << "
" << endl; } void CCCC_Html_Stream::Procedural_Detail() { Put_Section_Heading("Procedural Metrics Detail","procdet",1); fstr << "" << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); while(mod_ptr!=NULL) { if( (mod_ptr->name(nlMODULE_TYPE)!="builtin") && (mod_ptr->name(nlMODULE_TYPE)!="enum") && (mod_ptr->name(nlMODULE_TYPE)!="union") ) { fstr << "" << endl; Put_Label_Cell(mod_ptr->name(nlSIMPLE).c_str(),50, "procdet","procsum",mod_ptr); Put_Header_Cell("LOC",10); Put_Header_Cell("MVG",10); Put_Header_Cell("COM",10); Put_Header_Cell("L_C",10); Put_Header_Cell("M_C",10); fstr << "" << endl; Procedural_Detail(mod_ptr); } mod_ptr=prjptr->module_table.next_item(); } fstr << "
" << endl; } void CCCC_Html_Stream::Other_Extents() { Put_Section_Heading("Other Extents","other",1); fstr << "" << endl; fstr << "" << endl; Put_Header_Cell("Location",25); Put_Header_Cell("Text",45); Put_Header_Cell("LOC",10); Put_Header_Cell("COM",10); Put_Header_Cell("MVG",10); fstr << "" << endl; if(prjptr->rejected_extent_table.records() == 0) { fstr << "" << endl; } else { CCCC_Extent *extent_ptr=prjptr->rejected_extent_table.first_item(); while(extent_ptr!=NULL) { fstr << ""; Put_Extent_Cell(*extent_ptr,0); Put_Label_Cell(extent_ptr->name(nlDESCRIPTION).c_str()); Put_Metric_Cell(extent_ptr->get_count("LOC"),""); Put_Metric_Cell(extent_ptr->get_count("COM"),""); Put_Metric_Cell(extent_ptr->get_count("MVG"),""); fstr << "" << endl; extent_ptr=prjptr->rejected_extent_table.next_item(); } } fstr << "
" << " " << "
" << endl; } void CCCC_Html_Stream::Put_Section_TOC_Entry( string section_name, string section_href, string section_description) { fstr << "" << endl << "

" << section_name << "

" << endl << "" << endl << section_description << endl << "" << endl; } void CCCC_Html_Stream::Put_Header_Cell(string label, int width) { fstr << "0) { fstr << " WIDTH=" << width << "%" ; } fstr << ">" ; if(label.size()>0) { *this << label.c_str(); } else { // put a non-breaking space in to avoid the strange // bevelling associated with empty cells fstr << " "; } fstr << ""; } void CCCC_Html_Stream::Put_Label_Cell( string label, int width, string ref_name, string ref_href, CCCC_Record *rec_ptr) { fstr << "0) { fstr << " WIDTH=" << width <<"%"; } fstr << ">" ; if(ref_name.size() > 0) { // we need to insert an HTML " tag for the current cell // this enables other locations to jump in fstr << "" << endl; } if(ref_href.size() > 0) { // we need to insert an HTML tag for the current cell // this enables this cell to be a link to jump out fstr << "" << endl; // this anchor will need to be closed after the label has been displayed } if(label.size()>0) { *this << label.c_str() ; } else { // put a non-breaking space in to avoid the strange // bevelling associated with empty cells fstr << " "; } if(ref_href.size() > 0) { // closing the anchor we opened above fstr << "" << endl; } if(rec_ptr != 0) { fstr << "
" << endl; Put_Extent_List(*rec_ptr,true); } fstr << ""; } void CCCC_Html_Stream::Put_Metric_Cell( int count, string tag, int width) { CCCC_Metric m(count, tag.c_str()); Put_Metric_Cell(m, width); } void CCCC_Html_Stream::Put_Metric_Cell( int num, int denom, string tag, int width) { CCCC_Metric m(num,denom, tag.c_str()); Put_Metric_Cell(m, width); } void CCCC_Html_Stream::Put_Metric_Cell(const CCCC_Metric& metric, int width) { fstr << "0) { fstr << " WIDTH=" << width << "%" ; } switch(metric.emphasis_level()) { case elMEDIUM: fstr << " BGCOLOR=\"YELLOW\""; break; case elHIGH: fstr << " BGCOLOR=\"RED\""; break; default: // no background colour break; } fstr << ">"; *this << metric; fstr << ""; } void CCCC_Html_Stream::Put_Extent_URL(const CCCC_Extent& extent) { string filename=extent.name(nlFILENAME); int linenumber=atoi(extent.name(nlLINENUMBER).c_str()); Source_Anchor anchor(filename, linenumber); string key=anchor.key(); source_anchor_map_t::value_type anchor_value(key, anchor); source_anchor_map.insert(anchor_value); anchor.Emit_HREF(fstr); fstr // << extent.name(nlDESCRIPTION) << "
" << endl; } void CCCC_Html_Stream::Put_Extent_Cell(const CCCC_Extent& extent, int width, bool withDescription) { fstr << "0) { fstr << " WIDTH=" << width << "%>"; } else { fstr << ">"; } if(withDescription) { fstr << extent.name(nlDESCRIPTION) << "  " << endl; } Put_Extent_URL(extent); fstr << "" << endl; } void CCCC_Html_Stream::Put_Extent_List(CCCC_Record& record, bool withDescription) { CCCC_Extent *ext_ptr=record.extent_table.first_item(); while(ext_ptr!=NULL) { if(withDescription) { fstr << ext_ptr->name(nlDESCRIPTION) << "  " << endl; } Put_Extent_URL(*ext_ptr); ext_ptr=record.extent_table.next_item(); } fstr << "
" << endl; } // the next two methods define the two basic output operations through which // all of the higher level output operations are composed CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const string& stg) { // initialise a character pointer to the start of the string's buffer const char *cptr=stg.c_str(); while(*cptr!='\000') { char c=*cptr; // the purpose of this is to filter out the characters which // must be escaped in HTML switch(c) { case '>': os.fstr << ">" ; break; case '<': os.fstr << "<" ; break; case '&': os.fstr << "&"; break; // commas and parentheses do not need to be escaped, but // we want to allow line breaking just inside // parameter lists and after commas // we insert a non-breaking space to guarantee a small indent // on the new line, and one before the right parenthesis for // symmetry case ',': os.fstr << ",  " ; break; case '(': os.fstr << "(  " ; break; case ')': os.fstr << " )" ; break; default : os.fstr << c; } cptr++; } return os; } CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const CCCC_Metric& mtc) { char *emphasis_prefix[]={"","",""}; char *emphasis_suffix[]={"","",""}; // by writing to the underlying ostream object, we avoid the escape // functionality os.fstr << emphasis_prefix[mtc.emphasis_level()] << mtc.value_string() << emphasis_suffix[mtc.emphasis_level()]; return os; } void CCCC_Html_Stream::Separate_Modules() { // this function generates a separate HTML report for each non-trivial // module in the database CCCC_Module* mod_ptr=prjptr->module_table.first_item(); while(mod_ptr!=NULL) { int trivial_module=mod_ptr->is_trivial(); if(trivial_module==FALSE) { string info="Detailed report on module " + mod_ptr->key(); string filename=outdir; filename+="/"; filename+=mod_ptr->key()+".html"; CCCC_Html_Stream module_html_str(filename,info.c_str()); module_html_str.Put_Section_Heading(info.c_str(),"summary",1); module_html_str.Module_Summary(mod_ptr); module_html_str.Put_Section_Heading("Definitions and Declarations", "modext",2); module_html_str.fstr << "" << endl; module_html_str.Put_Label_Cell("Description",50); module_html_str.Put_Header_Cell("LOC",10); module_html_str.Put_Header_Cell("MVG",10); module_html_str.Put_Header_Cell("COM",10); module_html_str.Put_Header_Cell("L_C",10); module_html_str.Put_Header_Cell("M_C",10); module_html_str.Module_Detail(mod_ptr); module_html_str.fstr << "
" << endl; module_html_str.Put_Section_Heading("Functions","proc",2); module_html_str.fstr << "" << endl; module_html_str.Put_Label_Cell("Function prototype",50); module_html_str.Put_Header_Cell("LOC",10); module_html_str.Put_Header_Cell("MVG",10); module_html_str.Put_Header_Cell("COM",10); module_html_str.Put_Header_Cell("L_C",10); module_html_str.Put_Header_Cell("M_C",10); module_html_str.Procedural_Detail(mod_ptr); module_html_str.fstr << "
" << endl; module_html_str.Put_Section_Heading("Relationships","structdet",2); module_html_str.fstr << "" << endl << "" << endl << "" << endl; module_html_str.Structural_Detail(mod_ptr); module_html_str.fstr << "
ClientsSuppliers
" << endl; } else { #if 0 cerr << mod_ptr->module_type << " " << mod_ptr->key() << " is trivial" << endl; #endif } mod_ptr=prjptr->module_table.next_item(); } } void CCCC_Html_Stream::Module_Detail(CCCC_Module *module_ptr) { // this function generates the contents of the table of definition // and declaration extents for a single module // the output needs to be enveloped in a pair of
tags // these have not been put within the function because it is designed // to be used in two contexts: // 1. within the Separate_Modules function, wrapped directly in the table // tags // 2. within the Module_Detail function, where the table tags are // around the output of many calls to this function (not yet implemented) CCCC_Record::Extent_Table::iterator eIter = module_ptr->extent_table.begin(); if(eIter==module_ptr->extent_table.end()) { fstr << "" << "No module extents have been identified for this module" << "" << endl; } else { while(eIter!=module_ptr->extent_table.end()) { CCCC_Extent *ext_ptr=(*eIter).second; fstr << "" << endl; Put_Extent_Cell(*ext_ptr,0,true); int loc=ext_ptr->get_count("LOC"); int mvg=ext_ptr->get_count("MVG"); int com=ext_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCf"); CCCC_Metric mmvg(mvg,"MVGf"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Cell(mloc); Put_Metric_Cell(mmvg); Put_Metric_Cell(com); Put_Metric_Cell(ml_c); Put_Metric_Cell(mm_c); fstr << "" << endl; eIter++; } } fstr << "" << endl; } void CCCC_Html_Stream::Procedural_Detail(CCCC_Module *module_ptr) { // this function generates the contents of the procedural detail table // relating to a single module // the output needs to be enveloped in a pair of
tags // these have not been put within the function because it is designed // to be used in two contexts: // 1. within the Separate_Modules function, wrapped directly in the table // tags // 2. within the Procedural_Detail function, where the table tags are // around the output of many calls to this function CCCC_Module::member_map_t::iterator iter = module_ptr->member_map.begin(); if(iter==module_ptr->member_map.end()) { fstr << "" << "No member functions have been identified for this module" << "" << endl; } else { while(iter!=module_ptr->member_map.end()) { CCCC_Member *mem_ptr=(*iter).second; fstr << "" << endl; Put_Label_Cell(mem_ptr->name(nlLOCAL).c_str(),0,"","",mem_ptr); int loc=mem_ptr->get_count("LOC"); int mvg=mem_ptr->get_count("MVG"); int com=mem_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCf"); CCCC_Metric mmvg(mvg,"MVGf"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Cell(mloc); Put_Metric_Cell(mmvg); Put_Metric_Cell(com); Put_Metric_Cell(ml_c); Put_Metric_Cell(mm_c); fstr << "" << endl; iter++; } } fstr << "" << endl; } void CCCC_Html_Stream::Metric_Description( string abbreviation, string name, string description) { // this is intended to be called in the context of an unnumbered list fstr << "
  • " << abbreviation << " = " << name << "
    " << endl << description << endl; } void CCCC_Html_Stream::Structural_Detail(CCCC_Module *module_ptr) { Put_Structural_Details_Cell(module_ptr, prjptr, rmeCLIENT, nlCLIENT); Put_Structural_Details_Cell(module_ptr, prjptr, rmeSUPPLIER, nlSUPPLIER); } void CCCC_Html_Stream::Module_Summary(CCCC_Module *module_ptr) { // calculate the counts on which all displayed data will be based // int nof=module_ptr->member_table.records(); // Number of functions int nof=0; int loc=module_ptr->get_count("LOC"); // lines of code int mvg=module_ptr->get_count("MVG"); // McCabes cyclomatic complexity int com=module_ptr->get_count("COM"); // lines of comment // the variants of IF4 measure information flow and couplings int if4=module_ptr->get_count("IF4"); // (all couplings) int if4v=module_ptr->get_count("IF4v"); // (visible only) int if4c=module_ptr->get_count("IF4c"); // (concrete only) int wmc1=module_ptr->get_count("WMC1"); // Weighted methods/class (unity) int wmcv=module_ptr->get_count("WMCv"); // Weighted methods/class (visible) int dit=module_ptr->get_count("DIT"); // depth of inheritance tree int noc=module_ptr->get_count("NOC"); // number of children int cbo=module_ptr->get_count("CBO"); // coupling between objects fstr << "" << endl << "" << endl; Put_Header_Cell("Metric",70); Put_Header_Cell("Tag",10); Put_Header_Cell("Overall",10); Put_Header_Cell("Per Function",10); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Lines of Code"); Put_Label_Cell("LOC"); Put_Metric_Cell(loc,"LOCm"); Put_Metric_Cell(loc,nof,"LOCg"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("McCabe's Cyclomatic Number"); Put_Label_Cell("MVG"); Put_Metric_Cell(mvg,"MVGm"); Put_Metric_Cell(mvg,nof,"MVGf"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Lines of Comment"); Put_Label_Cell("COM"); Put_Metric_Cell(com,"COMm"); Put_Metric_Cell(com,nof,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("LOC/COM"); Put_Label_Cell("L_C"); Put_Metric_Cell(loc,com,"L_C"); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("MVG/COM"); Put_Label_Cell("M_C"); Put_Metric_Cell(mvg,com,"M_C"); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Weighted Methods per Class (weighting = unity)"); Put_Label_Cell("WMC1"); Put_Metric_Cell(wmc1); Put_Label_Cell(""); // wmc1 should be identical to nof fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Weighted Methods per Class (weighting = visible)"); Put_Label_Cell("WMCv"); Put_Metric_Cell(wmcv); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Depth of Inheritance Tree"); Put_Label_Cell("DIT"); Put_Metric_Cell(dit); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Number of Children"); Put_Label_Cell("NOC"); Put_Metric_Cell(noc); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Coupling between objects"); Put_Label_Cell("CBO"); Put_Metric_Cell(cbo); Put_Label_Cell(""); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (inclusive)"); Put_Label_Cell("IF4"); Put_Metric_Cell(if4,1,"IF4"); Put_Metric_Cell(if4,nof,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (visible)"); Put_Label_Cell("IF4v"); Put_Metric_Cell(if4v,1,"IF4v"); Put_Metric_Cell(if4v,nof,"8.3"); fstr << "" << endl; fstr << "" << endl; Put_Label_Cell("Information Flow measure (concrete)"); Put_Label_Cell("IF4c"); Put_Metric_Cell(if4c,1,"IF4c"); Put_Metric_Cell(if4c,nof,"8.3"); fstr << "" << endl; fstr << "
    " << endl; } CCCC_Html_Stream::CCCC_Html_Stream(const string& fname, const string& info) { // cerr << "Attempting to open file in directory " << outdir.c_str() << endl; fstr.open(fname.c_str()); if(fstr.good() != TRUE) { cerr << "failed to open " << fname.c_str() << " for output in directory " << outdir.c_str() << endl; exit(1); } else { // cerr << "File: " << fname << " Info: " << info << endl; } fstr << "" << endl << info << endl << "" << endl << "" << endl << "" << endl; } int setup_anchor_data() { int i=0; Source_Anchor a1("cccc_use.h",12); Source_Anchor a2("cccc_htm.h",15); i++; string key1=a1.key(), key2=a2.key(); i++; source_anchor_map_t::value_type v1(key1,a1); source_anchor_map_t::value_type v2(key2,a2); i++; source_anchor_map.insert(v1); source_anchor_map.insert(v2); return i; } void CCCC_Html_Stream::Source_Listing() { // The variable stream src_str used to be an instance // of fstream which gets reopened many times. // this worked under Linux but broke under Win32, so // this variable is now a pointer which is repeatedly // deleted and new'ed string current_filename; int current_line=0; int next_anchor_required=0; ifstream *src_str=NULL; const char *style_open="", *style_close=""; string filename=outdir; filename+="/cccc_src.html"; CCCC_Html_Stream source_html_str(filename.c_str(),"source file"); source_html_str.fstr << style_open << endl; source_anchor_map_t::iterator iter=source_anchor_map.begin(); while(iter!=source_anchor_map.end()) { char linebuf[1024]; Source_Anchor& nextAnchor=(*iter).second; if(current_filename!=nextAnchor.get_file()) { current_filename=nextAnchor.get_file(); current_line=0; delete src_str; src_str=new ifstream(current_filename.c_str(),std::ios::in); src_str->getline(linebuf,1023); source_html_str.fstr << style_close << endl; source_html_str.Put_Section_Heading(current_filename.c_str(),"",1); source_html_str.fstr << style_open << endl; } while(src_str->good()) { current_line++; if( (iter!=source_anchor_map.end()) && (current_filename==(*iter).second.get_file()) && (current_line==(*iter).second.get_line()) ) { (*iter).second.Emit_NAME(source_html_str.fstr); iter++; } else { (*iter).second.Emit_SPACE(source_html_str.fstr); } source_html_str << linebuf; source_html_str.fstr << "
    " << endl; src_str->getline(linebuf,1023); } // if there are any remaining anchors for this file the sorting // by line number must be wrong // complain and ignore while( (iter!=source_anchor_map.end()) && (current_filename==(*iter).second.get_file()) ) { (*iter).second.Emit_NAME(source_html_str.fstr); iter++; source_html_str.fstr << "
    " << endl; } } // delete the last input stream created delete src_str; source_html_str.fstr << style_close << " " << endl; } static string pad_string(int target_width, string the_string, string padding) { int spaces_required=target_width-the_string.size(); string pad_string; while(spaces_required>0) { pad_string+=padding; spaces_required--; } return pad_string+the_string; } string Source_Anchor::key() const { string retval; char linebuf[16]; sprintf(linebuf,"%d",line_); retval=file_+":"+pad_string(10,linebuf," "); return retval; } void Source_Anchor::Emit_HREF(ofstream& fstr) { string anchor_key=key(); fstr << "" << file_.c_str() << ":" << line_ << ""; } void Source_Anchor::Emit_NAME(ofstream& fstr) { string anchor_key=key(); char ln_buf[32]; sprintf(ln_buf,"%d",line_); string ln_string=pad_string(8,ln_buf," "); string space_string=pad_string(2,""," "); fstr << "" << ln_string.c_str() << space_string.c_str() << ""; } void Source_Anchor::Emit_SPACE(ofstream& fstr) { string space_string=pad_string(10,""," "); fstr << space_string.c_str(); } #ifdef UNIT_TEST int main() { CCCC_Project *prj_ptr=test_project_ptr(); CCCC_Html_Stream os(*prj_ptr,"cccc.htm","."); return 0; } #endif cccc-3.1.4/cccc/cccc_htm.h0000644000000000000000000001077710357241712013735 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __CCCC_HTM_H #define __CCCC_HTM_H #include "cccc.h" #include #include #include "cccc_db.h" #include "cccc_met.h" enum ReportType { rtCONTENTS=0x0001, rtSUMMARY=0x0002, rtOODESIGN=0x0004, rtPROC1=0x0010, rtPROC2=0x0020, rtSTRUCT1=0x0040, rtSTRUCT2=0x0080, rtOTHER=0x0100, rtSEPARATE_MODULES=0x0200, rtSOURCE=0x0400, rtSHOW_GEN_TIME=0x800, rtCCCC=0x8000 }; class CCCC_Html_Stream { friend CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const string& stg); friend CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const CCCC_Metric& mtc); ofstream fstr; static string libdir; static string outdir; static CCCC_Project* prjptr; void Table_Of_Contents(int report_mask, bool showGenTime); void Project_Summary(); void Procedural_Summary(); void Procedural_Detail(); void Structural_Summary(); void Structural_Detail(); void OO_Design(); void Other_Extents(); void Separate_Modules(); void Source_Listing(); void Module_Summary(CCCC_Module *module_ptr); void Module_Detail(CCCC_Module *module_ptr); void Procedural_Detail(CCCC_Module *module_ptr); void Structural_Detail(CCCC_Module *module_ptr); void Separate_Module_Link(CCCC_Module *module_ptr); void Put_Section_Heading(string section_name,string section_tag, int section_level); void Put_Section_TOC_Entry(string section_name, string section_href, string section_description); void Put_Header_Cell(string label, int width=0); void Put_Label_Cell(string label, int width=0, string ref_name="", string ref_href="", CCCC_Record *rec_ptr=0); void Put_Metric_Cell(const CCCC_Metric& metric, int width=0); void Put_Metric_Cell(int count, string tag, int width=0); void Put_Metric_Cell(int num, int denom, string tag, int width=0); void Put_Extent_URL(const CCCC_Extent& extent); void Put_Extent_Cell(const CCCC_Extent& extent, int width=0, bool withDescription=false); void Put_Extent_List(CCCC_Record& record,bool withDescription=false); void Put_Structural_Details_Cell(CCCC_Module *mod, CCCC_Project *prj, int mask, UserelNameLevel nl); void Metric_Description(string abbreviation, string name, string description); public: static void GenerateReports(CCCC_Project* project, int report_mask, const string& outfile, const string& outdir); // general-purpose constructor with standard preamble CCCC_Html_Stream(const string& fname, const string& info); // destructor with standard trailer ~CCCC_Html_Stream(); }; CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const string& stg); CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const CCCC_Metric& mtc); CCCC_Html_Stream& operator <<(CCCC_Html_Stream& os, const CCCC_Extent& ext); // this class is added to support the generation of an HTML file // containing the source analysed by the run, with anchors embedded at // each of the lines referred to in the other parts of the report class Source_Anchor { // if this looks more like a struct to you, it does to me too... // it could be embedded withing CCCC_Html_Stream except that this // might make the default constructor unavailable for the std::map // instantiation string file_; int line_; public: Source_Anchor():line_(0) {} Source_Anchor(string file, int line) : file_(file), line_(line) {} string get_file() const { return file_; } int get_line() const { return line_; } string key() const; void Emit_HREF(ofstream& fstr); void Emit_NAME(ofstream& fstr); void Emit_SPACE(ofstream& fstr); // the default copy constructor, assignment operator and destructor // are OK for this class }; #endif /* __CCCC_HTM_H */ cccc-3.1.4/cccc/cccc_itm.cc0000644000000000000000000000411610357241712014062 0ustar rootroot// cccc_itm.cc #include "cccc.h" #include #include "cccc_itm.h" #include #include CCCC_Item::CCCC_Item(const string& s, char c) { buffer=s; delimiter=c; good=true; } CCCC_Item::CCCC_Item(const string& s) { buffer=s; delimiter='@'; good=true; } CCCC_Item::CCCC_Item() { buffer=""; delimiter='@'; good=true; } bool CCCC_Item::Insert(const string& s) { buffer+=s; buffer+=delimiter; #if 0 cerr << buffer << endl; #endif return good; } bool CCCC_Item::Insert(const char* cptr) { string s(cptr); return Insert(s); } bool CCCC_Item::Extract(string& s) { size_t delimiter_position=buffer.find(delimiter); if(delimiter_position!=string::npos) { good=true; s=buffer.substr(0,delimiter_position); string tempBuffer=buffer.substr(delimiter_position+1); buffer=tempBuffer; } else { good=false; } return good; } bool CCCC_Item::Insert(int n) { char numbuf[64]; sprintf(numbuf,"%d",n); return Insert(numbuf); } bool CCCC_Item::Extract(int& n) { string numstr; bool retval=Extract(numstr); n=atoi(numstr.c_str()); return retval; } bool CCCC_Item::Insert(char c) { char charbuf[2]; sprintf(charbuf,"%c",c); return Insert(charbuf); } bool CCCC_Item::Extract(char& c) { string charstr; bool retval=Extract(charstr); if(charstr.size()==1) { c=charstr[0]; } return retval; } bool CCCC_Item::Insert(float f) { char numbuf[64]; sprintf(numbuf,"%f",f); return Insert(numbuf); } bool CCCC_Item::Extract(float& f) { string numstr; bool retval=Extract(numstr); f=atof(numstr.c_str()); return retval; } bool CCCC_Item::ToFile(ofstream& ofstr) { ofstr << buffer << endl; good=ofstr.good(); return good; } bool CCCC_Item::FromFile(ifstream& ifstr) { good=false; char line_buffer[1024]; ifstr.getline(line_buffer,1023); buffer=line_buffer; if(ifstr.good() && buffer.size()>0 && buffer.size()<1023) { delimiter=buffer[buffer.size()-1]; good=true; #if 0 cerr << "Delimiter is " << delimiter << endl; #endif } return good; } cccc-3.1.4/cccc/cccc_itm.h0000644000000000000000000000177410357241712013733 0ustar rootroot// cccc_itm.h #ifndef __CCCC_ITM_H #define __CCCC_ITM_H #include "cccc.h" // Class CCCC_Item is a wrapper for a C++ standard string which allows // insertion and extraction of fields using a standard delimiter. // It is intended for use in the following contexts: // 1. for transmission of extent information from the parser to the database // 2. for transmission of option information from the main line to the database // 3. for storage from the database to a flat file // 4. for reloading from a flat file to the database. class CCCC_Item { private: char delimiter; string buffer; bool good; public: CCCC_Item(const string& s, char c); CCCC_Item(const string& s); CCCC_Item(); bool Insert(const string& s); bool Insert(const char* cptr); bool Extract(string& s); bool Insert(int n); bool Extract(int& n); bool Insert(char c); bool Extract(char& c); bool Insert(float f); bool Extract(float& f); bool ToFile(ofstream& ofstr); bool FromFile(ifstream& ifstr); }; #endif cccc-3.1.4/cccc/cccc_mem.cc0000644000000000000000000001333710357241712014054 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_mem.cc // implementation file for class CCCC_Member #include "cccc.h" #include "cccc_itm.h" #include "cccc_mem.h" #include "cccc_db.h" CCCC_Member::CCCC_Member() : parent(NULL) { visibility=vDONTKNOW; } int CCCC_Member::get_count(const char* count_tag) { int retval=0; string count_tag_str=count_tag; if(count_tag_str=="WMC1") { retval=1; } else if(count_tag_str=="WMCv") { switch(get_visibility()) { case vPUBLIC: case vPROTECTED: retval=1; break; default: NULL; } } else { retval=extent_table.get_count(count_tag); } return retval; } int CCCC_Member::ToFile(ofstream& ofstr) { int retval=FALSE; CCCC_Item member_line; member_line.Insert(MEMBER_PREFIX); member_line.Insert(parent->key()); member_line.Insert(member_name); member_line.Insert(member_type); member_line.Insert(param_list); member_line.ToFile(ofstr); CCCC_Extent *extent_ptr=extent_table.first_item(); while(extent_ptr!=NULL) { CCCC_Item extent_line; extent_line.Insert(MEMEXT_PREFIX); extent_line.Insert(parent->key()); extent_line.Insert(member_name); extent_line.Insert(member_type); extent_line.Insert(param_list); extent_ptr->AddToItem(extent_line); extent_line.ToFile(ofstr); extent_ptr=extent_table.next_item(); } if(ofstr.good()) { retval=TRUE; } return retval; } string CCCC_Member::name(int name_level) const { string namestr; switch(name_level) { case nlRANK: case nlSEARCH: // there is no scoping for C-style functions ... if(parent==NULL) { namestr.append("::"); } else if( (parent->name(nlMODULE_NAME)!="") && (parent->name(nlMODULE_TYPE)!="file") ) { namestr.append(parent->name(nlMODULE_NAME)); namestr.append("::"); } namestr.append(member_name); namestr.append(param_list); break; case nlMEMBER_NAME: case nlSIMPLE: namestr=member_name; break; case nlMEMBER_TYPE: namestr=member_type; break; case nlMEMBER_PARAMS: namestr=param_list; break; case nlLOCAL: namestr.append(member_name); namestr.append(param_list); break; default: cerr << "unexpected name level" << endl; } return namestr.c_str(); } int CCCC_Member::FromFile(ifstream& ifstr) { int retval=RECORD_ERROR; enum MemberFromFileStatuses { MEMBER_RECORD_NO_PARENT_FOUND=3 }; CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; string line_keyword_dummy; string parent_name; CCCC_Member *found_mptr=NULL; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(parent_name) && next_line.Extract(this->member_name) && next_line.Extract(this->member_type) && next_line.Extract(this->param_list) ) { parent=current_loading_project->module_table.find(parent_name); if(parent!=NULL) { found_mptr= current_loading_project->member_table.find_or_insert(this); if(found_mptr==this) { // the newly created instance of the module is the first // and has taken its place in the database, so we protect // it from deletion retval=RECORD_ADDED; } else { retval=RECORD_TRANSCRIBED; } // process extent records while(PeekAtNextLinePrefix(ifstr,MEMEXT_PREFIX)) { CCCC_Extent *new_extent=new CCCC_Extent; next_line.FromFile(ifstr); ifstr_line++; string parent_key_dummy, member_name_dummy, member_type_dummy, param_list_dummy; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(parent_key_dummy) && next_line.Extract(member_name_dummy) && next_line.Extract(member_type_dummy) && next_line.Extract(param_list_dummy) && new_extent->GetFromItem(next_line) ) { // We don't ever expect to find duplicated extent records // but just in case... CCCC_Extent *found_eptr= found_mptr->extent_table.find_or_insert(new_extent); if(found_eptr!=new_extent) { cerr << "Failed to add extent for member " << found_mptr->key() << " at line " << ifstr_line << endl; delete new_extent; } } } } else // parent record not found { retval=MEMBER_RECORD_NO_PARENT_FOUND; } } else // extraction of module intial line failed { // unexpected problem with the input retval=RECORD_ERROR; } // If the import was successful, we will also have imported all dependent // extent records following the main record. // If not, we must skip them. while(PeekAtNextLinePrefix(ifstr,MEMEXT_PREFIX)) { CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; cerr << "Ignoring member extent on line " << ifstr_line << endl; } return retval; } Visibility CCCC_Member::get_visibility() { return visibility; } cccc-3.1.4/cccc/cccc_mem.h0000644000000000000000000000316210357241712013711 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_mem.h */ #ifndef CCCC_MEM_H #define CCCC_MEM_H #include "cccc_rec.h" static const string MEMBER_PREFIX="CCCC_Member"; static const string MEMEXT_PREFIX="CCCC_MemExt"; enum MemberNameLevel { nlMEMBER_NAME=-1, nlMEMBER_TYPE=-2, nlMEMBER_PARAMS=-3 }; class CCCC_Module; class CCCC_Member : public CCCC_Record { friend class CCCC_Project; friend class CCCC_Module; string member_type, member_name, param_list; Visibility visibility; CCCC_Module *parent; CCCC_Member(); public: string name( int index ) const; CCCC_Member(CCCC_Item& member_data_line, CCCC_Module* parent_ptr=NULL); int FromFile(ifstream& infile); int ToFile(ofstream& outfile); void generate_report(ostream&); int get_count(const char *count_tag); Visibility get_visibility(); }; #endif // CCCC_MEM_H cccc-3.1.4/cccc/cccc_met.cc0000644000000000000000000001362210357241712014060 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_met.cc #include "cccc.h" #include "cccc_itm.h" #include "cccc_met.h" #include using std::ostringstream; #include "cccc_opt.h" Metric_Treatment::Metric_Treatment(CCCC_Item& treatment_line) { lower_threshold=0; upper_threshold=0; numerator_threshold=0; width=0; precision=0; string option_dummy, treatment_dummy, lothresh_str, hithresh_str, numthresh_str, width_str, precision_str; if( // treatment_line.Extract(option_dummy) && // treatment_line.Extract(treatment_dummy) && treatment_line.Extract(code) && treatment_line.Extract(lothresh_str) && treatment_line.Extract(hithresh_str) && treatment_line.Extract(numerator_threshold) && treatment_line.Extract(width) && treatment_line.Extract(precision) && treatment_line.Extract(name) ) { lower_threshold=atof(lothresh_str.c_str()); upper_threshold=atof(hithresh_str.c_str()); } } CCCC_Metric::CCCC_Metric() { set_ratio(0,0); set_treatment(""); } CCCC_Metric::CCCC_Metric(int n, const char* treatment_tag) { set_ratio(n,1); set_treatment(treatment_tag); } CCCC_Metric::CCCC_Metric(int n, int d, const char* treatment_tag) { set_ratio(n,d); set_treatment(treatment_tag); } void CCCC_Metric::set_treatment(const char* code) { treatment=CCCC_Options::getMetricTreatment(code); } void CCCC_Metric::set_ratio(float _num, float _denom) { numerator=_num; denominator=_denom; } EmphasisLevel CCCC_Metric::emphasis_level() const { EmphasisLevel retval=elLOW; if(treatment!=NULL && numerator>treatment->numerator_threshold) { if( numerator > (treatment->upper_threshold*denominator) ) { retval=elHIGH; } else if(numerator> (treatment->lower_threshold*denominator) ) { retval=elMEDIUM; } } return retval; } string CCCC_Metric::code() const { string retval; if(treatment != NULL) { retval=treatment->code; } return retval; } string CCCC_Metric::name() const { string retval; if(treatment != NULL) { retval=treatment->name; } return retval; } string CCCC_Metric::value_string() const { string retval; char numerator_too_low='-'; char infinity='*'; ostringstream valuestr; valuestr.setf(std::ios::fixed); int width=6, precision=0; float n_threshold=0, low_threshold=1e9, high_threshold=1e9; if(treatment!=NULL) { width=treatment->width; precision=treatment->precision; n_threshold=treatment->numerator_threshold; low_threshold=treatment->lower_threshold; high_threshold=treatment->upper_threshold; } valuestr.width(width); valuestr.precision(precision); if(numerator #include "cccc_db.h" #include "cccc_itm.h" enum EmphasisLevel { elLOW=0, elMEDIUM=1, elHIGH=2 }; class CCCC_Html_Stream; class CCCC_Metric; // the single class CCCC_Metric which will be defined later in this file // will be used for all metrics // differences in output formats will be handled by giving each object // of type CCCC_Metric a pointer to a an object of type Metric_Treatment // which will be held in a global array called Metric_Treatment_Table class Metric_Treatment { friend class CCCC_Metric; friend void add_treatment(CCCC_Item&); friend CCCC_Html_Stream& operator <<(CCCC_Html_Stream&,const CCCC_Metric&); // a short code string is used to search for the metric treatment, and // it has a full name string code, name; // lower_threshold and upper_threshold are the levels at which the metric // is interpreted as moving between low, medium and high emphasis levels float lower_threshold, upper_threshold; // for ratio type metrics, we provide the facility for screening out of // items for which the numerator lies below a given value // e.g. we may impose a standard of 1 line of comment per 3 of code, but // say that we do not require this standard to apply to routines shorter // than 5 lines int numerator_threshold; // preferred display width and number of decimal places int width, precision; public: Metric_Treatment(CCCC_Item& treatment_line); friend class CCCC_Options; }; // the main metric class class CCCC_Metric { Metric_Treatment* treatment; float numerator, denominator; friend CCCC_Metric& operator+(const CCCC_Metric&, const CCCC_Metric&); public: CCCC_Metric(); CCCC_Metric(int n, const char* treatment_tag=""); CCCC_Metric(int n, int d, const char* treatment_tag=""); void set_treatment(const char* code); void set_ratio(float _num, float _denom=1.0); EmphasisLevel emphasis_level() const; string code() const; string name() const; string value_string() const; }; #endif /* __CCCC_MET_H */ cccc-3.1.4/cccc/cccc_mod.cc0000644000000000000000000001552210357241712014053 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_mod.cc // implementation file for CCCC_Module class #include "cccc.h" #include "cccc_itm.h" #include "cccc_mod.h" #include "cccc_db.h" CCCC_Module::CCCC_Module() { project=get_active_project(); } string CCCC_Module::name(int name_level) const { string retval; switch(name_level) { case nlMODULE_TYPE: retval=module_type; break; case nlMODULE_NAME: retval=module_name; break; case nlMODULE_TYPE_AND_NAME: retval=module_type; if(retval.size()>0) { retval=retval+" "; } retval=retval+module_name; break; default: retval=module_name; } return retval.c_str(); } int CCCC_Module::get_count(const char* count_tag) { int retval=0; if(strcmp(count_tag,"NOM")==0) { if(is_trivial()==FALSE) { retval=1; } } else if(strcmp(count_tag,"CBO")==0) { retval=client_map.size()+supplier_map.size(); } else if(strcmp(count_tag,"NOC")==0) { retval=0; relationship_map_t::iterator iter; iter=client_map.begin(); while(iter!=client_map.end()) { if((*iter).second->get_usetype()==utINHERITS) { retval++; } iter++; } } else if(strcmp(count_tag,"DIT")==0) { retval=0; // cyclical inheritance relationships in code would // never compile, but this is no excuse for us allowing them // to cause us to overflow the stack static int recursion_depth=0; recursion_depth++; if(recursion_depth>100) { cerr << "Recursion overflow attempting to calculate DIT for " << key() << endl; retval=1000; } else { relationship_map_t::iterator iter; iter=supplier_map.begin(); while(iter!=supplier_map.end()) { if((*iter).second->get_usetype()==utINHERITS) { int parent_depth= (*iter).second->supplier_module_ptr(project)->get_count("DIT"); if(retvalget_count(count_tag); iter++; } } else if(strncmp(count_tag,"FO",2)==0) { relationship_map_t::iterator iter; iter=client_map.begin(); while(iter!=client_map.end()) { retval+=(*iter).second->get_count(count_tag); iter++; } } else if(strncmp(count_tag,"IF4",3)==0) { char if4_suffix=count_tag[3]; string fi_variant="FI", fo_variant="FO"; if(if4_suffix!=0) { fi_variant+=if4_suffix; fo_variant+=if4_suffix; } retval=get_count(fi_variant.c_str())*get_count(fo_variant.c_str()); retval*=retval; } else { CCCC_Extent *extPtr=extent_table.first_item(); while(extPtr!=NULL) { int extent_count=extPtr->get_count(count_tag); retval+=extent_count; extPtr=extent_table.next_item(); } member_map_t::iterator memIter=member_map.begin(); while(memIter!=member_map.end()) { int member_count=(*memIter).second->get_count(count_tag); retval+=member_count; memIter++; } } return retval; } int CCCC_Module::is_trivial() { int retval=FALSE; if( (module_type=="builtin") || (module_type=="enum") || (module_type=="struct") || (module_type=="trivial") ) { retval=TRUE; } return retval; } int CCCC_Module::ToFile(ofstream& ofstr) { int retval=FALSE; CCCC_Item module_line; module_line.Insert(MODULE_PREFIX); module_line.Insert(module_name); module_line.Insert(module_type); module_line.ToFile(ofstr); CCCC_Extent *extent_ptr=extent_table.first_item(); while(extent_ptr!=NULL) { CCCC_Item extent_line; extent_line.Insert(MODEXT_PREFIX); extent_line.Insert(module_name); extent_line.Insert(module_type); extent_ptr->AddToItem(extent_line); extent_line.ToFile(ofstr); extent_ptr=extent_table.next_item(); } if(ofstr.good()) { retval=TRUE; } return retval; } int CCCC_Module::FromFile(ifstream& ifstr) { int retval=RECORD_ERROR; CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; string line_keyword_dummy; CCCC_Module *found_mptr=NULL; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(this->module_name) && next_line.Extract(this->module_type) ) { found_mptr= current_loading_project->module_table.find_or_insert(this); if(found_mptr==this) { // the newly created instance of the module is the first // and has taken its place in the database, so we protect // it from deletion retval=RECORD_ADDED; } else { retval=RECORD_TRANSCRIBED; } // process extent records while(PeekAtNextLinePrefix(ifstr,MODEXT_PREFIX)) { CCCC_Extent *new_extent=new CCCC_Extent; next_line.FromFile(ifstr); ifstr_line++; string module_name_dummy, module_type_dummy; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(module_name_dummy) && next_line.Extract(module_type_dummy) && new_extent->GetFromItem(next_line) ) { // We don't ever expect to find duplicated extent records // but just in case... CCCC_Extent *found_eptr= found_mptr->extent_table.find_or_insert(new_extent); if(found_eptr!=new_extent) { cerr << "Failed to add extent for module " << found_mptr->key() << " at line " << ifstr_line << endl; delete new_extent; } } } } else { // unexpected problem with the input retval=RECORD_ERROR; } // If the import was successful, we will also have imported all dependent // extent records following the main record. // If not, we must skip them. while(PeekAtNextLinePrefix(ifstr,MODEXT_PREFIX)) { CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; cerr << "Ignoring member extent on line " << ifstr_line << endl; } return retval; } cccc-3.1.4/cccc/cccc_mod.h0000644000000000000000000000351510357241712013714 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_mod.h */ #ifndef CCCC_MOD_H #define CCCC_MOD_H #include "cccc.h" #include "cccc_rec.h" class CCCC_Item; class CCCC_Project; class CCCC_UseRelationship; class CCCC_Member; static const string MODULE_PREFIX="CCCC_Module"; static const string MODEXT_PREFIX="CCCC_ModExt"; enum ModuleNameLevel { nlMODULE_TYPE=-1, nlMODULE_NAME=-2, nlMODULE_TYPE_AND_NAME=-3 }; class CCCC_Module : public CCCC_Record { friend class CCCC_Project; friend class CCCC_Html_Stream; friend class CCCC_Xml_Stream; CCCC_Project *project; string module_name, module_type; typedef std::map member_map_t; member_map_t member_map; typedef std::map relationship_map_t; relationship_map_t client_map; relationship_map_t supplier_map; CCCC_Module(); public: string name(int name_level) const; int FromFile(ifstream& infile); int ToFile(ofstream& outfile); virtual int get_count(const char *count_tag); int is_trivial(); }; #endif // CCCC_MOD_H cccc-3.1.4/cccc/cccc_new.cc0000644000000000000000000000372610357241712014070 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_new.cc // we are having some problems with heap corruption, so I am making sure that // all class news and deletes are done by the malloc subsystem, and adding // logging and deletion suppression #include "cccc.h" #include #include #ifdef CCCC_CONF_W32VC #include #else #ifdef CCCC_CONF_W32BC #include #else #include #endif #endif #define USE_SYSTEM_NEW #ifndef USE_SYSTEM_NEW extern int dont_free; ofstream str("cccc_new.log"); void * operator new(size_t n) { void *retval=malloc(n); memset(retval,0xFA,n); str << hex << retval << "@" << time(NULL) << "+" << n << endl; return retval; } void * operator new[](size_t n) { void *retval=malloc(n); memset(retval,0xFB,n); str << hex << retval << "@" << time(NULL) << "*" << n << endl; return retval; } void operator delete(void * cp) { str << hex << cp << "@" << time(NULL) << "-" << endl; memset(cp,0xFC,1); if(dont_free==0) { free(cp); } } void operator delete[](void * cp) { str << hex << cp << "@" << time(NULL) << "/" << endl; memset(cp,0xFD,1); if(dont_free==0) { free(cp); } } #endif cccc-3.1.4/cccc/cccc_opt.cc0000644000000000000000000003027510357241712014100 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_opt.cc #include "cccc.h" #include #include "cccc_opt.h" #include "cccc_utl.h" #include "cccc_met.h" #include typedef std::map file_extension_language_map_t; typedef std::map metric_treatment_map_t; typedef std::pair dialect_keyword_t; typedef std::map dialect_keyword_map_t; static file_extension_language_map_t extension_map; static metric_treatment_map_t treatment_map; static dialect_keyword_map_t dialect_keyword_map; // these are declared extern so that it can be defined later in the file extern char *default_fileext_options[]; extern char *default_treatment_options[]; extern char *default_dialect_options[]; static void add_file_extension(CCCC_Item& fileext_line) { string ext, lang; if( fileext_line.Extract(ext) && fileext_line.Extract(lang) ) { file_extension_language_map_t::value_type extension_pair(ext,lang); extension_map.insert(extension_pair); } } void add_treatment(CCCC_Item& treatment_line) { Metric_Treatment *new_treatment=new Metric_Treatment(treatment_line); metric_treatment_map_t::iterator iter= treatment_map.find(new_treatment->code); if(iter!=treatment_map.end()) { delete (*iter).second; (*iter).second=new_treatment; } else { metric_treatment_map_t::value_type treatment_pair(new_treatment->code,new_treatment); treatment_map.insert(treatment_pair); } } static void add_dialect_keyword(CCCC_Item& dialect_keyword_line) { string dialect, keyword, policy; if( dialect_keyword_line.Extract(dialect) && dialect_keyword_line.Extract(keyword) && dialect_keyword_line.Extract(policy) ) { dialect_keyword_map_t::key_type kt(dialect,keyword); dialect_keyword_map_t::value_type vt(kt,policy); dialect_keyword_map.insert(vt); } } void CCCC_Options::Add_Option(CCCC_Item& option) { string first_token; bool retval=option.Extract(first_token); if(retval==false) { // do nothing } else if(first_token=="CCCC_FileExt") { add_file_extension(option); } else if(first_token=="CCCC_MetTmnt") { add_treatment(option); } else if(first_token=="CCCC_Dialect") { add_dialect_keyword(option); } else { retval=false; } } void CCCC_Options::Save_Options(const string& filename) { ofstream optstr(filename.c_str()); file_extension_language_map_t::iterator felIter; for(felIter=extension_map.begin(); felIter!=extension_map.end(); ++felIter) { CCCC_Item extLine; extLine.Insert("CCCC_FileExt"); extLine.Insert((*felIter).first.c_str()); extLine.Insert((*felIter).second.c_str()); extLine.ToFile(optstr); } metric_treatment_map_t::iterator tIter; for(tIter=treatment_map.begin(); tIter!=treatment_map.end(); ++tIter) { CCCC_Item tmtLine; tmtLine.Insert("CCCC_MetTmnt"); tmtLine.Insert((*tIter).second->code); tmtLine.Insert((*tIter).second->lower_threshold); tmtLine.Insert((*tIter).second->upper_threshold); tmtLine.Insert((*tIter).second->numerator_threshold); tmtLine.Insert((*tIter).second->width); tmtLine.Insert((*tIter).second->precision); tmtLine.Insert((*tIter).second->name); tmtLine.ToFile(optstr); } dialect_keyword_map_t::iterator dkIter; for(dkIter=dialect_keyword_map.begin(); dkIter!=dialect_keyword_map.end(); ++dkIter) { CCCC_Item dkLine; dkLine.Insert("CCCC_Dialect"); dkLine.Insert((*dkIter).first.first); dkLine.Insert((*dkIter).first.second); dkLine.Insert((*dkIter).second); dkLine.ToFile(optstr); } } void CCCC_Options::Load_Options(const string& filename) { ifstream optstr(filename.c_str()); while(optstr.good()) { CCCC_Item option_line; if(optstr.good() && option_line.FromFile(optstr) ) { Add_Option(option_line); } } } // initialise using hard-coded defaults void CCCC_Options::Load_Options() { int i=0; char **option_ptr; option_ptr=default_fileext_options; while( (*option_ptr)!=NULL) { string option_string="CCCC_FileExt@"; option_string+=(*option_ptr); CCCC_Item option_line(option_string); Add_Option(option_line); option_ptr++; } option_ptr=default_treatment_options; while( (*option_ptr)!=NULL) { string option_string="CCCC_MetTmnt@"; option_string+=(*option_ptr); CCCC_Item option_line(option_string); Add_Option(option_line); option_ptr++; } option_ptr=default_dialect_options; while( (*option_ptr)!=NULL) { string option_string="CCCC_Dialect@"; option_string+=(*option_ptr); CCCC_Item option_line(option_string); Add_Option(option_line); option_ptr++; } } // map a filename to a language string CCCC_Options::getFileLanguage(const string& filename) { string retval; string extension; file_extension_language_map_t::iterator iter; unsigned int extpos=filename.rfind("."); if(extpos!=string::npos) { extension=filename.substr(extpos); iter=extension_map.find(extension); if(iter!=extension_map.end()) { retval=(*iter).second; } } if(retval.size()==0) { iter=extension_map.find(""); if(iter!=extension_map.end()) { retval=(*iter).second; } else { // could not find language for extension cerr << "No language found for extension " << extension.c_str() << endl; } } return retval; } // map a metric name to a Metric_Treatment object Metric_Treatment *CCCC_Options::getMetricTreatment(const string& metric_tag) { Metric_Treatment *retval=NULL; metric_treatment_map_t::iterator iter=treatment_map.find(metric_tag); if(iter!=treatment_map.end()) { retval=(*iter).second; } return retval; } string CCCC_Options::dialectKeywordPolicy(const string& lang, const string& kw) { string retval; dialect_keyword_map_t::key_type kt(lang,kw); dialect_keyword_map_t::const_iterator iter=dialect_keyword_map.find(kt); if(iter!=dialect_keyword_map.end()) { retval=(*iter).second; } return retval; } char *default_fileext_options[]= { // file extensions ".c@c.ansi@", ".h@c++.ansi@", ".cc@c++.ansi@", ".cpp@c++.ansi@", ".cxx@c++.ansi@", ".c++@c++.ansi@", ".C@c++.ansi@", ".CC@c++.ansi@", ".CPP@c++.ansi@", ".CXX@c++.ansi@", ".hh@c++.ansi@", ".hpp@c++.ansi@", ".hxx@c++.ansi@", ".h++@c++.ansi@", ".H@c++.ansi@", ".HH@c++.ansi@", ".HPP@c++.ansi@", ".HXX@c++.ansi@", ".H++@c++.ansi@", ".j@java@", ".jav@java@", ".java@java@", ".J@java@", ".JAV@java@", ".JAVA@java@", ".ada@ada.95@", ".ads@ada.95@", ".adb@ada.95@", ".ADA@ada.95@", ".ADS@ada.95@", ".ADB@ada.95@", // The language associated with the empty file extension would be used as a default // if defined. // This is presently disabled so that we don't process files in // MSVC projects like .rc, .odl which are not in C++. // "@c++.ansi@", NULL }; char *default_treatment_options[] = { // metric treatments // all metric values are displayed using the class CCCC_Metric, which may be // viewed as ratio of two integers associated with a character string tag // the denominator of the ratio defaults to 1, allowing simple counts to // be handled by the same code as is used for ratios // // the tag associated with a metric is used as a key to lookup a record // describing a policy for its display (class Metric_Treatment) // // the fields of each treatment record are as follows: // TAG the short string of characters used as the lookup key. // T1, T2 two numeric thresholds which are the lower bounds for the ratio of // the metric's numerator and denominator beyond which the // value is treated as high or extreme by the analyser // these will be displayed in emphasized fonts, and if the browser // supports the BGCOLOR attribute, extreme values will have a red // background, while high values will have a yellow background. // The intent is that high values should be treated as suspicious but // tolerable in moderation, whereas extreme values should almost // always be regarded as defects (not necessarily that you will fix // them). // NT a third threshold which supresses calculation of ratios where // the numerator is lower than NT. // The principal reason for doing this is to prevent ratios like L_C // being shown as *** (infinity) and displayed as extreme when the // denominator is 0, providing the numerator is sufficiently low. // Suitable values are probably similar to those for T1. // W the width of the metric (total number of digits). // P the precision of the metric (digits after the decimal point). // Comment a free form field extending to the end of the line. // TAG T1 T2 NT W P Comment "LOCf@ 30@ 100@ 0@ 6@ 0@Lines of code/function@", "LOCm@ 500@ 2000@ 0@ 6@ 0@Lines of code/single module@", "LOCper@ 500@ 2000@ 0@ 6@ 3@Lines of code/average module@", "LOCp@ 999999@ 999999@ 0@ 6@ 0@Lines of code/project@", "MVGf@ 10@ 30@ 0@ 6@ 0@Cyclomatic complexity/function@", "MVGm@ 200@ 1000@ 0@ 6@ 0@Cyclomatic complexity/single module@", "MVGper@ 200@ 1000@ 0@ 6@ 3@Cyclomatic complexity/average module@", "MVGp@ 999999@ 999999@ 0@ 6@ 0@Cyclomatic complexity/project@", "COM@ 999999@ 999999@ 0@ 6@ 0@Comment lines@", "COMper@999999@ 999999@ 0@ 6@ 3@Comment lines (averaged)@", "M_C@ 5@ 10@ 5@ 6@ 3@MVG/COM McCabe/comment line@", "L_C@ 7@ 30@ 20@ 6@ 3@LOC/COM Lines of code/comment line@", "FI@ 12@ 20@ 0@ 6@ 0@Fan in (overall)@", "FIv@ 6@ 12@ 0@ 6@ 0@Fan in (visible uses only)@", "FIc@ 6@ 12@ 0@ 6@ 0@Fan in (concrete uses only)@", "FO@ 12@ 20@ 0@ 6@ 0@Fan out (overall)@", "FOv@ 6@ 12@ 0@ 6@ 0@Fan out (visible uses only)@", "FOc@ 6@ 12@ 0@ 6@ 0@Fan out (concrete uses only)@", "IF4@ 100@ 1000@ 0@ 6@ 0@Henry-Kafura/Shepperd measure (overall)@", "IF4v@ 30@ 100@ 0@ 6@ 0@Henry-Kafura/Shepperd measure (visible)@", "IF4c@ 30@ 100@ 0@ 6@ 0@Henry-Kafura/Shepperd measure (concrete)@", // WMC stands for weighted methods per class, // the suffix distinguishes the weighting function "WMC1@ 30@ 100@ 0@ 6@ 0@Weighting function=1 unit per method@", "WMCv@ 10@ 30@ 0@ 6@ 0@Weighting function=1 unit per visible method@", "DIT@ 3@ 6@ 0@ 6@ 0@Depth of Inheritance Tree@", "NOC@ 4@ 15@ 0@ 6@ 0@Number of children@", "CBO@ 12@ 30@ 0@ 6@ 0@Coupling between objects@", "8.3@ 999999@ 999999@ 0@ 8@ 3@General format for fixed precision 3 d.p.@", NULL }; char *default_dialect_options[] = { // This configuration item allows the description of // dialects in which C/C++ identifiers get treated // as supplementary keyword. The rules specified // here (or in the runtime option file, if specified) // allow the parser to make the call // CCCC_Options::dialect_keyword_policy(lang,kw) which // returns a string. If nothing is known about the // pair , an empty string is returned. If // an entry is specified here the associated string is // returned, which is called the policy, which the // parser uses to guide its actions. The most common // policy is to ignore, but any string can be // specified, providing the person implementing // the parser can think of an intelligent way to // proceed. "c++.mfc@BEGIN_MESSAGE_MAP@start_skipping@", "c++.mfc@END_MESSAGE_MAP@stop_skipping@", "c++.stl@__STL_BEGIN_NAMESPACE@ignore@", "c++.stl@__STL_END_NAMESPACE@ignore@", NULL }; cccc-3.1.4/cccc/cccc_opt.h0000644000000000000000000000453410357241712013741 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_opt.h #ifndef _CCCC_OPT_H #define _CCCC_OPT_H // This file defines the object which holds the major configuration // options for the CCCC program including: // - the default language associated with each file name extension; // - the treatment of specific values of each metric; and // - the application of dialect specific parsing rule (e.g. rule to // ignore MSVC++-specific pseudo-keywords when parsing the // MS C++ dialect. // This is a natural singleton class, hence all member functions are static // and all data will be declared with static file scope in the implementation // file. #include "cccc.h" #include "cccc_itm.h" class Metric_Treatment; class CCCC_Options { public: // initialise using a file static void Load_Options(const string& filename); // initialise using hard-coded defaults static void Load_Options(); // save the current set of options to a file static void Save_Options(const string& filename); // add a new option into the current option set static void Add_Option(CCCC_Item& option_line); // map a filename to a language static string getFileLanguage(const string& filename); // map a metric name to a Metric_Treatment object static Metric_Treatment *getMetricTreatment(const string& metric_tag); // the following function allows the parser to use special // handling rules for identifiers in particular situations // (especially pseudo-keywords like BEGIN_MESSAGE_MAP) static string dialectKeywordPolicy(const string& lang, const string& kw); }; #endif cccc-3.1.4/cccc/cccc_prj.cc0000644000000000000000000002527110357241712014071 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_prj.cc // We have some debugging messages specifically for looking at how // use relationships are being handled. #define DEBUG_USEREL 0 // implementation file for class CCCC_Project #include "cccc.h" #include "cccc_itm.h" #include "cccc_prj.h" #include "cccc_db.h" CCCC_Project::CCCC_Project(const string& name) { // we prime the database with knowledge of the builtin base types // we also add a record for the anonymous class which we will treat // as the parent of all non-member functions char *builtin_type_info[]= { "void@builtin@@0@builtin definition@d?????@@0@d@", "int@builtin@@0@builtin definition@d?????@@0@d@", "char@builtin@@0@builtin definition@d?????@@0@d@", "long@builtin@@0@builtin definition@d?????@@0@d@", "float@builtin@@0@builtin definition@d?????@@0@d@", "double@builtin@@0@builtin definition@d?????@@0@d@", NULL }; for(char **ptr=builtin_type_info; *ptr!=NULL; ptr++) { CCCC_Item type_info(*ptr); add_module(type_info); } } void CCCC_Project::add_module(CCCC_Item& module_line) { char linebuf[1024]; CCCC_Module *module_ptr=new CCCC_Module; CCCC_Extent *extent_ptr=new CCCC_Extent; if( module_line.Extract(module_ptr->module_name) && module_line.Extract(module_ptr->module_type) && extent_ptr->GetFromItem(module_line) ) { CCCC_Module *lookup_module_ptr=module_table.find_or_insert(module_ptr); if(lookup_module_ptr != NULL) { lookup_module_ptr->extent_table.find_or_insert(extent_ptr); if(lookup_module_ptr!=module_ptr) { // do some work to transfer knowledge from the new module object // then delete it Resolve_Fields(lookup_module_ptr->module_type,module_ptr->module_type); delete module_ptr; } } } else { cerr << "CCCC_Project::add_module_extent: extraction failed" << endl; } } void CCCC_Project::add_member(CCCC_Item& member_data_line) { CCCC_Module *new_module_ptr=new CCCC_Module; CCCC_Member *new_member_ptr=new CCCC_Member; if( member_data_line.Extract(new_module_ptr->module_name) && member_data_line.Extract(new_member_ptr->member_name) && member_data_line.Extract(new_member_ptr->member_type) && member_data_line.Extract(new_member_ptr->param_list) ) { CCCC_Module *found_module_ptr=module_table.find_or_insert(new_module_ptr); if(found_module_ptr==new_module_ptr) { // protect the new module from deletion at the end of this function new_module_ptr=NULL; } new_member_ptr->parent=found_module_ptr; CCCC_Member *found_member_ptr=member_table.find_or_insert(new_member_ptr); if(found_member_ptr==new_member_ptr) { new_member_ptr=NULL; } found_member_ptr->add_extent(member_data_line); } else { cerr << "CCCC_Project::add_module extraction failed" << endl; } // clean up newly allocated records if they have not been accepted // into the database delete new_module_ptr; delete new_member_ptr; } void CCCC_Project::add_userel(CCCC_Item& userel_data_line) { CCCC_UseRelationship *new_userel_ptr = new CCCC_UseRelationship(userel_data_line); CCCC_UseRelationship *lookup_userel_ptr = userel_table.find_or_insert(new_userel_ptr); if(lookup_userel_ptr != NULL) { if(new_userel_ptr != lookup_userel_ptr) { delete new_userel_ptr; } lookup_userel_ptr->add_extent(userel_data_line); } #if DEBUG_USEREL cerr << "Adding " << lookup_userel_ptr->client << " uses " << lookup_userel_ptr->supplier << endl; #endif } void CCCC_Project::add_rejected_extent(CCCC_Item& rejected_data_line) { CCCC_Extent *new_extent=new CCCC_Extent(rejected_data_line); rejected_extent_table.find_or_insert(new_extent); } void CCCC_Project::reindex() { CCCC_Member *member_ptr=member_table.first_item(); while(member_ptr!=NULL) { if(member_ptr->parent!=NULL) { CCCC_Module::member_map_t::value_type new_pair(member_ptr->key(),member_ptr); member_ptr->parent->member_map.insert(new_pair); } else { cerr << "Member " << member_ptr->key() << " has no parent" << endl; } CCCC_Extent *extent_ptr=member_ptr->extent_table.first_item(); while(extent_ptr!=NULL) { Visibility extent_visibility=extent_ptr->get_visibility(); Visibility member_visibility=member_ptr->get_visibility(); if(member_ptr->visibility==vDONTKNOW) { member_ptr->visibility=extent_visibility; } else if( (extent_visibility!=vDONTKNOW) && (member_visibility!=extent_visibility) ) { member_ptr->visibility=vINVALID; } extent_ptr=member_ptr->extent_table.next_item(); } member_ptr=member_table.next_item(); } CCCC_UseRelationship *userel_ptr=userel_table.first_item(); while(userel_ptr!=NULL) { CCCC_Module *supplier_ptr=new CCCC_Module; supplier_ptr->module_name=userel_ptr->supplier; CCCC_Module *found_supplier_ptr= module_table.find_or_insert(supplier_ptr); if(found_supplier_ptr!=supplier_ptr) { delete supplier_ptr; supplier_ptr=found_supplier_ptr; } CCCC_Module *client_ptr=new CCCC_Module; client_ptr->module_name=userel_ptr->client; CCCC_Module *found_client_ptr=module_table.find_or_insert(client_ptr); if(found_client_ptr!=client_ptr) { delete client_ptr; client_ptr=found_client_ptr; } if( (userel_ptr->supplier==userel_ptr->client) || userel_ptr->supplier=="" || userel_ptr->client=="" || supplier_ptr->is_trivial() || client_ptr->is_trivial() ) { #if DEBUG_USEREL cerr << "Removing relationship between " << userel_ptr->supplier.c_str() << " and " << userel_ptr->client.c_str() << endl; #endif userel_table.remove(userel_ptr); delete userel_ptr; } else { // create links from the client and supplier modules to the // relationship object #if DEBUG_USEREL std::cerr << "Creating links for " << client_ptr->key() << " (" << client_ptr << ") uses " << supplier_ptr->key() << " (" << supplier_ptr << ")" << std::endl; #endif CCCC_Module::relationship_map_t::value_type new_supplier_pair(supplier_ptr->key(), userel_ptr), new_client_pair(client_ptr->key(), userel_ptr); client_ptr->supplier_map.insert(new_supplier_pair); supplier_ptr->client_map.insert(new_client_pair); // calculate the visibility and concreteness of the // relationship AugmentedBool visible=abDONTKNOW; AugmentedBool concrete=abDONTKNOW; CCCC_Extent *extent_ptr=userel_ptr->extent_table.first_item(); while(extent_ptr!=NULL) { switch(extent_ptr->get_visibility()) { case vPRIVATE: case vIMPLEMENTATION: if(visible!=abTRUE) { visible=abFALSE; } break; case vPROTECTED: case vPUBLIC: visible=abTRUE; break; default: // nothing to do ; } switch(extent_ptr->get_usetype()) { case utPARBYREF: case utHASBYREF: if(concrete!=abTRUE) { concrete=abFALSE; } break; case utINHERITS: case utPARBYVAL: case utHASBYVAL: concrete=abTRUE; break; default: // nothing to do ; } extent_ptr=userel_ptr->extent_table.next_item(); } userel_ptr->visible=visible; userel_ptr->concrete=concrete; } userel_ptr=userel_table.next_item(); } } int CCCC_Project::get_count(const char* count_tag) { int retval=0; retval+=module_table.get_count(count_tag); retval+=rejected_extent_table.get_count(count_tag); return retval; } int CCCC_Project::ToFile(ofstream& ofstr) { // this function could be rewritten much more elegantly using // STL output iterators, and one day will be ... int retval=FALSE; CCCC_Module *module_ptr=module_table.first_item(); while(module_ptr!=NULL) { module_ptr->ToFile(ofstr); module_ptr=module_table.next_item(); } CCCC_Member *member_ptr=member_table.first_item(); while(member_ptr!=NULL) { member_ptr->ToFile(ofstr); member_ptr=member_table.next_item(); } CCCC_UseRelationship *userel_ptr=userel_table.first_item(); while(userel_ptr!=NULL) { userel_ptr->ToFile(ofstr); userel_ptr=userel_table.next_item(); } CCCC_Extent *rejext_ptr=rejected_extent_table.first_item(); while(rejext_ptr!=NULL) { CCCC_Item extent_line; extent_line.Insert(REJEXT_PREFIX); rejext_ptr->AddToItem(extent_line); extent_line.ToFile(ofstr); rejext_ptr=rejected_extent_table.next_item(); } if(ofstr.good()) { retval=TRUE; } return retval; } int CCCC_Project::FromFile(ifstream& ifstr) { int retval=FALSE; set_active_project(this); while(PeekAtNextLinePrefix(ifstr,MODULE_PREFIX)) { CCCC_Module *new_module=new CCCC_Module; int fromfile_status=new_module->FromFile(ifstr); DisposeOfImportRecord(new_module,fromfile_status); } while(PeekAtNextLinePrefix(ifstr,MEMBER_PREFIX)) { CCCC_Member *new_member=new CCCC_Member; int fromfile_status=new_member->FromFile(ifstr); DisposeOfImportRecord(new_member,fromfile_status); } while(PeekAtNextLinePrefix(ifstr,USEREL_PREFIX)) { CCCC_UseRelationship *new_userel=new CCCC_UseRelationship; int fromfile_status=new_userel->FromFile(ifstr); DisposeOfImportRecord(new_userel,fromfile_status); } while(PeekAtNextLinePrefix(ifstr,REJEXT_PREFIX)) { CCCC_Extent *new_rejext=new CCCC_Extent; CCCC_Item next_line; next_line.FromFile(ifstr); int fromfile_status=RECORD_ERROR; if( new_rejext->GetFromItem(next_line) && new_rejext==rejected_extent_table.find_or_insert(new_rejext) ) { fromfile_status=RECORD_ADDED; } DisposeOfImportRecord(new_rejext,fromfile_status); } set_active_project(NULL); return retval; } string CCCC_Project::name(int level) const { return ""; } cccc-3.1.4/cccc/cccc_prj.h0000644000000000000000000000617110357241712013731 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_prj.h */ #ifndef CCCC_PRJ_H #define CCCC_PRJ_H #include "cccc_rec.h" // forward declarations class CCCC_Item; class CCCC_Record; class CCCC_Project; class CCCC_Module; class CCCC_Member; class CCCC_UseRelationship; class CCCC_Extent; static const string REJEXT_PREFIX="CCCC_RejExt"; enum RelationshipMaskElements { rmeCLIENT=0x01, rmeSUPPLIER=0x02, rmeHIDDEN=0x10, rmeVISIBLE=0x20, rmeHIDDEN_OR_VISIBLE=0x30, rmeABSTRACT=0x40, rmeCONCRETE=0x80, rmeABSTRACT_OR_CONCRETE=0xC0 }; class CCCC_Project : public CCCC_Record { friend class CCCC_Html_Stream; friend class CCCC_Xml_Stream; friend class CCCC_Module; friend class CCCC_Member; friend class CCCC_UseRelationship; friend class CCCC_Extent; CCCC_Table module_table; CCCC_Table member_table; CCCC_Table userel_table; CCCC_Table rejected_extent_table; std::map OptionTable; public: // because MSVC++ version of STL needs it to be... // we need a record of which extents came from which files // so that when we implement persistence, we can purge // extent records from each file as we re-analyze it struct ExtentTableEntry { CCCC_Table *table_ptr; CCCC_Extent *extent_ptr; ExtentTableEntry() : table_ptr(NULL), extent_ptr(NULL) {} }; typedef std::multimap FileExtentTable; FileExtentTable file_extent_table; public: CCCC_Project(const string& name=""); // these functions are used in both the analyzer // and the load side of the persistence code // to add entities to the project void add_module(CCCC_Item& module_data_line); void add_member(CCCC_Item& member_data_line); void add_userel(CCCC_Item& use_data_line); void add_rejected_extent(CCCC_Item& rejected_data_line); // this function is used after loading and/or analysis // has been completed to (re)create the maps owned by // each module of its members and relationships void reindex(); int get_count(const char *count_tag); string name(int level) const; int FromFile(ifstream& infile); int ToFile(ofstream& outfile); void set_option(string key, CCCC_Item& option_data_line); int get_option(string key, CCCC_Item& option_data_line); }; #endif // CCCC_PRJ_H cccc-3.1.4/cccc/cccc_rec.cc0000644000000000000000000000425410357241712014045 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_rec.cc */ #include "cccc_itm.h" #include "cccc_rec.h" #include "cccc_db.h" CCCC_Project* CCCC_Record::active_project=NULL; CCCC_Project* CCCC_Record::get_active_project() { return active_project; } void CCCC_Record::set_active_project(CCCC_Project* prj) { active_project=prj; } void CCCC_Record::merge_flags(string& new_flags) { const char *new_flag_array=new_flags.c_str(); const char *flag_array=flags.c_str(); unsigned int len=strlen(flag_array); if(strlen(new_flag_array)==len) { char buf[100]; unsigned int i; for(i=0; iGetFromItem(is); CCCC_Extent *inserted_extent=extent_table.find_or_insert(new_extent); if(new_extent != inserted_extent) { delete new_extent; } } string CCCC_Record::name(int /* level */) const { return ""; } string CCCC_Record::key() const { return name(nlRANK); } cccc-3.1.4/cccc/cccc_rec.h0000644000000000000000000000426210357241712013706 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_rec.h * * defines the database used by CCCC to generate a report */ #ifndef CCCC_REC_H #define CCCC_REC_H #include "cccc_tbl.h" #include "cccc_ext.h" #include "cccc_utl.h" // The entities held within the database need to be able to return a variety // of kinds of name including a simple name (typically one word), a fully // qualified local name (i.e as used within a class), and a fully // qualified global name. // Subclasses may also have particular other names, which should be defined // using negative indexes. enum NameLevel { nlRANK, nlSEARCH, nlSIMPLE, nlLOCAL, nlGLOBAL }; class CCCC_Record { friend class CCCC_Html_Stream; friend class CCCC_Xml_Stream; static CCCC_Project *active_project; protected: typedef CCCC_Table Extent_Table; Extent_Table extent_table; string flags; virtual void merge_flags(string& new_flags); public: virtual ~CCCC_Record() {} virtual string name(int level) const; virtual string key() const; AugmentedBool get_flag(PSFlag psf) { return (AugmentedBool) flags[psf]; } virtual void add_extent(CCCC_Item&); virtual void sort() { extent_table.sort(); } virtual int get_count(const char *count_tag)=0; friend int rank_by_string(const void *p1, const void *p2); static CCCC_Project* get_active_project(); static void set_active_project(CCCC_Project* prj); }; #endif // CCCC_REC_H cccc-3.1.4/cccc/cccc_tbl.cc0000644000000000000000000000617510357241712014061 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_tbl.cc #ifndef _CCCC_TBL_BODY #define _CCCC_TBL_BODY #include "cccc_itm.h" #include "cccc_tbl.h" #include #define LINE_BUFFER_SIZE 1000 template CCCC_Table::CCCC_Table() : sorted(true) { iter_ = map_t::end(); } template CCCC_Table::~CCCC_Table() { // the container should manage the destruction of its own // nodes correctly, we just need to get rid of the // objects to which we hold pointers. // NB Although CCCC_Table holds pointers, it owns the // objects they point to and is responsible for their disposal. T* itemptr=first_item(); while(itemptr!=NULL) { delete itemptr; itemptr=next_item(); } } template int CCCC_Table::get_count(const char* count_tag) { int retval=0; T* itemptr=first_item(); while(itemptr!=NULL) { retval+=itemptr->get_count(count_tag); itemptr=next_item(); } return retval; } template T* CCCC_Table::find(string name) { T *retval=NULL; typename map_t::iterator value_iterator=map_t::find(name); if(value_iterator!=map_t::end()) { retval=(*value_iterator).second; } return retval; } template T* CCCC_Table::find_or_insert(T* new_item_ptr) { string new_key=new_item_ptr->key(); T *retval=find(new_key); if(retval==NULL) { typename map_t::value_type new_pair(new_key,new_item_ptr); map_t::insert(new_pair); sorted=false; retval=new_item_ptr; } return retval; } template bool CCCC_Table::remove(T* old_item_ptr) { bool retval=false; typename map_t::iterator value_iterator=map_t::find(old_item_ptr->key()); if(value_iterator!=map_t::end()) { erase(value_iterator); retval=true; } return retval; } template void CCCC_Table::sort() { if(sorted==false) { sorted=true; } } template void CCCC_Table::reset_iterator() { iter_=map_t::begin(); } template T* CCCC_Table::first_item() { reset_iterator(); return next_item(); } template T* CCCC_Table::next_item() { T* retval=NULL; if(iter_!=map_t::end()) { retval=(*iter_).second; iter_++; } return retval; } template int CCCC_Table::records() { return map_t::size(); } #endif // _CCCC_TBL_BODY cccc-3.1.4/cccc/cccc_tbl.h0000644000000000000000000000326410357241712013717 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_tbl.h * * defines the database used by CCCC to generate a report */ #ifndef CCCC_TBL_H #define CCCC_TBL_H #include #include #include using std::string; // CCCC_Table started its life as an array of pointers to CCCC_Records. // It will ultimately become identical to a std::map from string to T*. // In the mean time we are supporting a legacy API. template class CCCC_Table : public std::map { typedef std::map map_t; typename map_t::iterator iter_; bool sorted; public: CCCC_Table(); virtual ~CCCC_Table(); int records(); T* find(string name); T* find_or_insert(T* new_item_ptr); bool remove(T* old_item_ptr); void reset_iterator(); T* first_item(); T* next_item(); virtual int get_count(const char *count_tag); void sort(); }; #include "cccc_tbl.cc" #endif // CCCC_DB_H cccc-3.1.4/cccc/cccc_tok.cc0000644000000000000000000001261610357241712014072 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_tok.C * implementation of a token class for the cccc project * */ #include "cccc.h" #include "cccc_tok.h" /* static variables */ int ANTLRToken::RunningNesting=0; int ANTLRToken::bCodeLine=0; int ANTLRToken::numAllocated=0; int toks_alloc1=0, toks_alloc2=0, toks_alloc3=0, toks_freed=0; ANTLRToken currentLexerToken; /* ** Token objects are used to count the occurences of states which ** our analyser is interested in within the text. Any metric which ** can be reduced to lexical counting on the text can be recorded ** this way. ** ** This implementation counts the following features: ** tokens ** comment lines ** lines containing at least one token of code ** ** It also makes a lexical count for the following tokens, each of which ** is expected to increase McCabe's cyclomatic complexity (Vg) for the ** section of code by one unit: ** IF FOR WHILE SWITCH BREAK RETURN ? && || ** ** Note that && and || create additional paths through the code due to C/C++ ** short circuit evaluation of logical expressions. ** ** Also note the way SWITCH constructs are counted: the desired increment ** in Vg is equal to the number of cases provided for, including the ** default case, whether or not an action is defined for it. This is acheived ** by counting the SWITCH at the head of the construct as a surrogate for ** the default case, and counting BREAKs as surrogates for the individual ** cases. This approach yields the correct results provided that the ** coding style in use ensures the use of BREAK after all non-default ** cases, and forbids 'drop through' from one case to another other than ** in the case where two or more values of the switch variable require ** identical actions, and no executable code is defined between the ** case gates (as in the switch statement in ANTLRToken::CountToken() below). */ /* default constructor */ ANTLRToken::ANTLRToken() : ANTLRCommonToken() { toks_alloc1++; CurrentNesting=-99; } /* ** constructor used by makeToken below */ ANTLRToken::ANTLRToken(ANTLRTokenType t, ANTLRChar *s) : ANTLRCommonToken(t,s) { setType(t); setText(s); CountToken(); toks_alloc2++; } /* copy constructor */ ANTLRToken::ANTLRToken(ANTLRToken& copyTok) { setType(copyTok.getType()); setText(copyTok.getText()); setLine(copyTok.getLine()); CurrentNesting=copyTok.CurrentNesting; toks_alloc3++; } /* ** the virtual pseudo-constructor ** This is required because the PCCTS support code does not know the ** exact nature of the token which will be created by the user's code, ** and indeed does not forbid the user creating more than one kind of ** token, so long as ANTLRToken is defined and all token classes are ** subclassed from ANTLRAbstractToken */ ANTLRAbstractToken *ANTLRToken::makeToken( ANTLRTokenType tt, ANTLRChar *txt, int line ) { ANTLRToken *new_t = new ANTLRToken(tt,txt); if(new_t==0) { cerr << "Memory overflow in " "ANTLRToken::makeToken(" << static_cast(tt) << "," << txt << "," << line << ")" << endl; exit(2); } new_t->setLine(line); DbgMsg( LEXER,cerr, "makeToken(tt=>" << static_cast(tt) << ", txt=>" << txt << ",line=>" << line << ")" << endl ); return new_t; } /* the destructor */ ANTLRToken::~ANTLRToken() { toks_freed++; DbgMsg(MEMORY,cerr,"freeing token " << getText() << " on line " << getLine() << " c1:" << toks_alloc1 << " c2:" << toks_alloc2 << " c3:" << toks_alloc3 << " freed:" << toks_freed << endl); } /* the assignment operator */ ANTLRToken& ANTLRToken::operator=(ANTLRToken& copyTok) { setType(copyTok.getType()); setText(copyTok.getText()); setLine(copyTok.getLine()); CurrentNesting=copyTok.CurrentNesting; return *this; } /* ** ANTLRToken::CountToken performs counting of features which are traced ** back to individual tokens created up by the lexer, i.e. the token count ** and McCabes VG. Code lines and comment lines are both identified during ** the processing of text which the lexer will (usually) skip, so the code ** to increment these counts is in the relevant lexer rules in the file ** cccc.g */ void ANTLRToken::CountToken() { // we have seen a non-skippable pattern => this line counts toward LOC bCodeLine=1; CurrentNesting=RunningNesting; DbgMsg(COUNTER,cerr,*this); } char *ANTLRToken::getTokenTypeName() { return ""; } /* ** structured output method for token objects */ ostream& operator << (ostream& out, ANTLRToken& t) { int i; out << "TOK: " << t.getTokenTypeName() << " " << t.getText() << " " << t.getLine() << " " << t.getNestingLevel(); out << endl; return out; } cccc-3.1.4/cccc/cccc_tok.h0000644000000000000000000000550610357241712013734 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_tok.h * definition of the token class interface for the cccc project * */ #ifndef __CCCC_TOK_H #define __CCCC_TOK_H #include "cccc.h" // before we go into the token header file, the compiler must have seen // a definition for enum ANTLRTokenType // there are three conflicting 'real' definitions, one in use by each parser // if we have seen one of these, we do not need to worry, otherwise we // must create a dummy one // the three definitions are in the files Ctokens.h Jtokens.h and Atokens.h #if !defined(Ctokens_h) && !defined(Jtokens_h) && !defined(Atokens_h) enum ANTLRTokenType { DUMMY,DEFINITION }; #endif #include "AToken.h" #include "cccc.h" /* ** the class definition for ANTLRToken ** Note that the name ANTLRToken is required to be either a class or a typedef ** by the PCCTS support code */ class ANTLRToken : public ANTLRCommonToken { // Lexical counting is done by attaching running counts of each of the // interesting features to every token produced by the lexer // the parser calculates the counts for a particular region by taking // taking the differences of the counts for the first and last tokens // in the region's extent. // nesting levels are used to control resynchronisation static int RunningNesting; static int numAllocated; int CurrentNesting; friend ostream& operator << (ostream&,ANTLRToken&); friend class DLGLexer; public: static int bCodeLine; ANTLRToken(ANTLRTokenType t, ANTLRChar *s); ANTLRToken(ANTLRToken& copyTok); ANTLRToken(); ANTLRToken& operator=(ANTLRToken& copyTok); virtual ~ANTLRToken(); virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt, ANTLRChar *txt, int line); static void IncrementNesting() { RunningNesting++; } static void DecrementNesting() { RunningNesting--; } int getNestingLevel() { return CurrentNesting; } void CountToken(); char *getTokenTypeName(); }; #define MY_TOK(t) ((ANTLRToken*)(t)) ostream& operator << (ostream&, ANTLRToken&); extern ANTLRToken currentLexerToken; #endif cccc-3.1.4/cccc/cccc_tpl.cc0000644000000000000000000000256610357241712014077 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_tpl.cc // all explicit template instantiations for the project are collected here // the assumption is that this file will be stable, so the expensive // recompilation of the templates will be infrequent #include "cccc_itm.h" #include "cccc_tbl.h" #include "cccc_db.h" #include "cccc_htm.h" #include "cccc_met.h" #include "cccc_tbl.cc" template class std::map; template class CCCC_Table; template class CCCC_Table; template class CCCC_Table; template class CCCC_Table; cccc-3.1.4/cccc/cccc_use.cc0000644000000000000000000001435510357241712014073 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_use.cc // implementation of CCCC_UseRelationship class #include "cccc.h" #include "cccc_itm.h" #include "cccc_use.h" #include "cccc_db.h" CCCC_UseRelationship::CCCC_UseRelationship(CCCC_Item& is) { is.Extract(client); is.Extract(member); is.Extract(supplier); visible=abDONTKNOW; concrete=abDONTKNOW; ut=utDONTKNOW; } string CCCC_UseRelationship::name(int name_level) const { string namestr; switch(name_level) { case nlRANK: case nlSIMPLE: namestr.append(client); namestr.append(" uses "); namestr.append(supplier); break; case nlSUPPLIER: namestr=supplier; break; case nlCLIENT: namestr=client; break; default: cerr << "unexpected name level" << endl; } return namestr.c_str(); } void CCCC_UseRelationship::add_extent(CCCC_Item& is) { // processing is similar to the CCCC_Record method, except that we update // the visibility and concreteness data members // but do not do merge_flags CCCC_Extent *new_extent=new CCCC_Extent(is); CCCC_Extent *inserted_extent=extent_table.find_or_insert(new_extent); switch(new_extent->get_visibility()) { case vPUBLIC: case vPROTECTED: visible=abTRUE; break; case vPRIVATE: case vIMPLEMENTATION: visible=abFALSE; break; default: // nothing required ;; } // a single relationship record represents all connections between two // modules, hence it may have multiple extents which are of different use // types // the use type attached to the relationship record is used only to identify // inheritance relationships UseType new_ut=new_extent->get_usetype(); if(new_ut==utINHERITS) { ut=utINHERITS; } switch(new_ut) { case utINHERITS: case utHASBYVAL: case utPARBYVAL: case utVARBYVAL: concrete=abTRUE; break; default: // no change required ;; } if(new_extent != inserted_extent) { delete new_extent; } } int CCCC_UseRelationship::get_count(const char* count_tag) { int retval=0; if( (strncmp(count_tag,"FI",2)==0) || (strncmp(count_tag,"FO",2)==0) ) { char suffix=count_tag[2]; switch(suffix) { case 0: retval=1; break; case 'v': if(visible!=abFALSE) { retval=1; } break; case 'c': if(concrete!=abFALSE) { retval=1; } break; default: cerr << "Unexpected count tag suffix" << count_tag << endl; } } else { cerr << "Unexpected count tag " << count_tag << endl; } return retval; } CCCC_Module* CCCC_UseRelationship::supplier_module_ptr(CCCC_Project *prj) { return prj->module_table.find(supplier.c_str()); } CCCC_Module* CCCC_UseRelationship::client_module_ptr(CCCC_Project *prj) { return prj->module_table.find(client.c_str()); } int CCCC_UseRelationship::ToFile(ofstream& ofstr) { int retval=FALSE; CCCC_Item line; line.Insert(USEREL_PREFIX); line.Insert(supplier); line.Insert(client); line.ToFile(ofstr); CCCC_Extent *extent_ptr=extent_table.first_item(); while(extent_ptr!=NULL) { CCCC_Item extent_line; extent_line.Insert(USEEXT_PREFIX); extent_line.Insert(supplier); extent_line.Insert(client); extent_ptr->AddToItem(extent_line); extent_line.ToFile(ofstr); extent_ptr=extent_table.next_item(); } if(ofstr.good()) { retval=TRUE; } return retval; } int CCCC_UseRelationship::FromFile(ifstream& ifstr) { int retval; CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; string line_keyword_dummy; CCCC_UseRelationship *found_uptr=NULL; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(this->supplier) && next_line.Extract(this->client) ) { found_uptr= current_loading_project->userel_table.find_or_insert(this); if(found_uptr==this) { // the newly created instance of the module is the first // and has taken its place in the database, so we protect // it from deletion retval=RECORD_ADDED; } else { retval=RECORD_TRANSCRIBED; } // process extent records while(PeekAtNextLinePrefix(ifstr,USEEXT_PREFIX)) { CCCC_Extent *new_extent=new CCCC_Extent; next_line.FromFile(ifstr); ifstr_line++; string supplier_dummy, client_dummy; if( next_line.Extract(line_keyword_dummy) && next_line.Extract(supplier_dummy) && next_line.Extract(client_dummy) && new_extent->GetFromItem(next_line) ) { // We don't ever expect to find duplicated extent records // but just in case... CCCC_Extent *found_eptr= found_uptr->extent_table.find_or_insert(new_extent); if(found_eptr!=new_extent) { cerr << "Failed to add extent for relationship " << found_uptr->key() << " at line " << ifstr_line << endl; delete new_extent; } } } } else // extraction of module intial line failed { // unexpected problem with the input retval=RECORD_ERROR; } // If the import was successful, we will also have imported all dependent // extent records following the main record. // If not, we must skip them. while(PeekAtNextLinePrefix(ifstr,USEEXT_PREFIX)) { CCCC_Item next_line; next_line.FromFile(ifstr); ifstr_line++; cerr << "Ignoring userel extent on line " << ifstr_line << endl; } return retval; } cccc-3.1.4/cccc/cccc_use.h0000644000000000000000000000351310357241712013727 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * cccc_use.h */ #ifndef CCCC_USE_H #define CCCC_USE_H #include "cccc_rec.h" class CCCC_Module; static const string USEREL_PREFIX="CCCC_UseRel"; static const string USEEXT_PREFIX="CCCC_UseExt"; enum UserelNameLevel { nlSUPPLIER=-1, nlCLIENT=-2, nlMEMBER=-3 }; class CCCC_UseRelationship : public CCCC_Record { friend class CCCC_Project; string supplier, client, member; UseType ut; AugmentedBool visible, concrete; CCCC_UseRelationship() { ut=utDONTKNOW; } public: string name( int index ) const; CCCC_UseRelationship(CCCC_Item& is); int FromFile(ifstream& infile); int ToFile(ofstream& outfile); void add_extent(CCCC_Item&); int get_count(const char *count_tag); UseType get_usetype() const { return ut; } AugmentedBool is_visible () const { return visible; } AugmentedBool is_concrete () const { return concrete; } void generate_report(ostream& os); CCCC_Module* supplier_module_ptr(CCCC_Project *prj); CCCC_Module* client_module_ptr(CCCC_Project *prj); }; #endif // CCCC_USE_H cccc-3.1.4/cccc/cccc_utl.cc0000644000000000000000000004042410357241712014077 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_utl.cc // implementation of enumerations and utility classes for CCCC // includes the Parse_Utility class which is a helper to centralise // error recovery and recording facilities across the three parsers #include "cccc.h" #include "cccc_itm.h" #include "cccc_utl.h" #include "cccc_db.h" #include "cccc_tok.h" #include "AParser.h" #include "ATokPtr.h" #define DEBUG_EXTENT_STREAMS 1 #include #include using std::ios; //using std::trunc; using std::ends; using std::setw; using std::setiosflags; using std::resetiosflags; #define FS "@" #define RS "\n" string ParseUtility::stack_rules[MAX_STACK_DEPTH]; int ParseUtility::stack_tokenline[MAX_STACK_DEPTH]; string ParseUtility::stack_tokentext[MAX_STACK_DEPTH]; int ParseUtility::stack_depth; ParseUtility* ParseUtility::theCurrentInstance=NULL; ParseStore* ParseStore::theCurrentInstance=NULL; // insertion and extraction functions intended to support enumerations void insert_enum(ostream& os, int e) { os << (char) e; } void extract_enum(istream& is, int& e) { e=0; is >> (char&) e; } ostream& operator<<(ostream& os, AugmentedBool ab) { insert_enum(os,ab); return os; } istream& operator>>(istream& is, AugmentedBool& ab) { extract_enum(is,(int&)ab); return is; } ostream& operator<<(ostream& os, Visibility v) { insert_enum(os,v); return os; } istream& operator>>(istream& is, Visibility& v) { extract_enum(is,(int&)v); return is; } ostream& operator<<(ostream& os, UseType ut) { insert_enum(os,ut); return os; } istream& operator>>(istream& is, UseType& ut) { extract_enum(is,(int&)ut); return is; } string ParseUtility::lookahead_text(int n) { static string retval; retval=""; int i; for(i=1; i<=n; i++) { if(parser->LT(i) != NULL) { retval=retval+parser->LT(i)->getText(); retval=retval+" "; } } return retval; } void ParseUtility::resynchronize(int initial_nesting, SetWordType *resync_token_class, ANTLRTokenPtr& resync_token) { // the interface for resynchronisation is as follows: // the caller supplies a nesting level at which the resynchronisation must // occur, and a token class containing all of the tokens which can // be accepted to delimit the resynchronisation // this function will scan until it finds that it is at the correct level and // the next token of lookahead is in the resynchronisation set // it will then accept as many tokens from the resynchronisation set as // are available, consolidating the text of the tokens accepted // as the text associated with the last token string resync_text="..."; string string1=parser->LT(1)->getText(); int line1=parser->LT(1)->getLine(); string string2; int line2=0; int resynchronising=1; while(resynchronising) { parser->consumeUntil(resync_token_class); if( (MY_TOK(parser->LT(1))->getNestingLevel() > initial_nesting) && (parser->LT(2) != NULL) ) { parser->consume(); } else { // we are ready to resynchronise resynchronising=0; string2=parser->LT(1)->getText(); line2=parser->LT(1)->getLine(); } } // we now consume a succession of tokens from the resynchronisation token // class until we come across a token which is not in the set, or the // nesting level changes resync_token=parser->LT(1); while( parser->set_el(parser->LT(1)->getType(),resync_token_class) && ( MY_TOK(parser->LT(1))->getNestingLevel() == initial_nesting) ) { string2=parser->LT(1)->getText(); line2=parser->LT(1)->getLine(); resync_text+=parser->LT(1)->getText(); resync_text+=" "; resync_token=parser->LT(1); resync_token->setText(resync_text.c_str()); parser->consume(); } cerr << "Unrecognized section from " << string1.c_str() << " on line " << line1 << " to " << string2.c_str() << " on line " << line2 << endl << "=====ignored section begins=====" << endl << resync_text.c_str() << endl << "===== ignored section ends =====" << endl; } ParseUtility::ParseUtility(ANTLRParser *parser) { // This is designed as a serial-singleton class (e.g. many // instances may exist over time but no more than one at a // time). // For the lifetime of an instance, the static member theCurrentInstance // points to it. When no instance exists, this pointer is null. assert(theCurrentInstance==NULL); theCurrentInstance=this; trace_depth=0; stack_depth=0; this->parser=(ANTLR_Assisted_Parser*)parser; } ParseUtility::~ParseUtility() { theCurrentInstance=NULL; } // This utility function is used to create // a composite scope name from a qualifier scope // and a relative name. string ParseUtility::scopeCombine(const string& baseScope, const string& name) { // I am presently (as at 3.pre44) experimenting with // how I handle scopes. The present code has a policy // of discarding scope information altogether and defining // modules based solely on the final component of the // fully qualified name. // This variable may become a parameter to control policy in this // area. bool bIgnoreScope=true; string retval; if(bIgnoreScope) { retval=name; } else if(baseScope.size()>0 && name.size()>0) { retval=baseScope+"::"+name; } else { retval=baseScope+name; } return retval; } ParseStore::ParseStore(const string& filename) : theFilename(filename) , pendingLexicalCounts(static_cast(tcLAST),0) , flag(static_cast(psfLAST)+1,'?') { // This is designed as a serial-singleton class (e.g. many // instances may exist over time but no more than one at a // time). // For the lifetime of an instance, the static member theCurrentInstance // points to it. When no instance exists, this pointer is null. assert(theCurrentInstance==NULL); theCurrentInstance=this; flag[psfLAST]='\0'; } ParseStore::~ParseStore() { // If the current object came from the default constructor // it is the primary singleton instance and we wish to // set the static pointer to itself back to null. Otherwise, // it was a cached copy, and we don't really care. if(theCurrentInstance==this) { theCurrentInstance=NULL; } } int ParseStore::get_flag(PSFlag psf) const { return int(flag[psf]); } void ParseStore::set_flag(PSFlag psf, int value) { flag[psf]=value; } void ParseStore::set_flag(Visibility value) { MAKE_STRSTREAM(ofstr); ofstr << value; flag[psfVISIBILITY]=(ofstr.str())[0]; RELEASE_STRSTREAM(ofstr); } Visibility ParseStore::get_visibility() { return static_cast(flag[psfVISIBILITY]); } string ParseStore::filename() { return theFilename; } void ParseStore:: insert_extent(CCCC_Item& os, int startLine, int endLine, const string& description, const string& flags, UseType ut, bool allocate_lexcounts) { os.Insert(theFilename); os.Insert(startLine); os.Insert(description); os.Insert(flags); int i; int lexical_counts_for_this_extent[tcLAST]; for(i=0; i0) { CCCC_Item module_line; module_line.Insert(moduleName); module_line.Insert(moduleType); insert_extent(module_line,startLine,endLine, description,flags(),ut,true); prj->add_module(module_line); } } void ParseStore::record_function_extent(int startLine, int endLine, const string& returnType, const string& moduleName, const string& memberName, const string& paramList, const string& description, Visibility visibility, UseType ut) { // We require every call to this function to specify a member // function name and a parameter list. if(memberName.size()>0) { // If the moduleName is an empty string, we remap this to the // string "anonymous". This implies that we treat all // C-style functions as belonging to a single module. string mappedModuleName = moduleName; if(mappedModuleName.size()==0) { mappedModuleName = "anonymous"; } CCCC_Item function_line; function_line.Insert(mappedModuleName); function_line.Insert(memberName); function_line.Insert(returnType); function_line.Insert(paramList); string baseFlags=flags(); baseFlags[psfVISIBILITY]=visibility; insert_extent(function_line,startLine,endLine, description,baseFlags,ut,true); prj->add_member(function_line); } } void ParseStore::record_userel_extent(int startLine, int endLine, const string& clientName, const string& memberName, const string& serverName, const string& description, Visibility visibility, UseType ut) { CCCC_Item userel_line; // This function should not be invoked unless the clientName // and serverName are non-empty strings, however it appears // that in test case prn16.java the parser does execute the // actions of the 'implementsClause' rule, even though there // is no 'implements' keyword outside comments in the program // text. // I don't understand this, but as a workaround, I filter at // this point and ensure that if either clientName or serverName // is empty, no action is taken. if(clientName.size()>0 && serverName.size()>0) { userel_line.Insert(clientName); userel_line.Insert(memberName); userel_line.Insert(serverName); // for data member definitions, we record lexical data for the // extent, // for inheritance and parameter relationships we do not bool record_lexcounts=false; switch(ut) { case utHASBYVAL: case utHASBYREF: record_lexcounts=true; break; default: record_lexcounts=false; } string baseFlags=flags(); baseFlags[psfVISIBILITY]=visibility; insert_extent(userel_line,startLine,endLine, description,baseFlags,ut,record_lexcounts); prj->add_userel(userel_line); } } void ParseStore::record_other_extent(int startLine, int endLine, const string& description) { CCCC_Item rejext_line; insert_extent(rejext_line,startLine,endLine,description,flags(),utREJECTED,true); prj->add_rejected_extent(rejext_line); } static void toktrace(ANTLRAbstractToken *tok) { // at the LHS we put out information about the current token if(tok != NULL) { DbgMsg(PARSER,cerr, std::setw(6) << tok->getLine() << std::setw(4) << (int)tok->getType() << std::setiosflags(ios::left) << std::resetiosflags(ios::right) << std::setw(20) << tok->getText() ); } else { DbgMsg(PARSER,cerr,std::setw(30)<<""); } } enum InOrOut { IO_IN, IO_OUT }; static void rectrace(const char *rulename, const char *dir_indic, int guessing, ANTLRAbstractToken *tok) { static int trace_depth=0; if(guessing) { DbgMsg(PARSER,cerr, setw(trace_depth*4+1) << "" << dir_indic << "?" << rulename << endl); } else { trace_depth=((ANTLRToken*) tok)->getNestingLevel(); DbgMsg(PARSER,cerr, setw(trace_depth*4)<< "" << dir_indic << rulename << endl); } } void ParseUtility::tracein( const char *rulename, int guessing, ANTLRAbstractToken *tok) { if(guessing == 0) { stack_tokentext[stack_depth]=tok->getText(); stack_tokenline[stack_depth]=tok->getLine(); stack_rules[stack_depth]=rulename; stack_depth++; } // first put out the token details toktrace(tok); // then the indented recognition trace rectrace(rulename,"-> ",guessing,tok); } void ParseUtility::traceout(const char *rulename, int guessing, ANTLRAbstractToken *tok) { if(guessing == 0) { stack_depth--; // some error checking... if(stack_depth<0) { cerr << "ParseUtility::traceout negative stack depth - " << "exiting from rule " << rulename << " at " << tok->getText() << " on line " << tok->getLine() << endl; } else if(rulename!=stack_rules[stack_depth]) { cerr << "ParseStore::traceout rule name mismatch - " << rulename << "!=" << stack_rules[stack_depth] << endl; } stack_tokentext[stack_depth]=""; stack_tokenline[stack_depth]=0; stack_rules[stack_depth]=""; } // first put out the token details toktrace(tok); rectrace(rulename,"<- ",guessing,tok); } void ParseUtility::syn( _ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k) { string filename=ParseStore::currentInstance()->filename(); if(tok != NULL) { cerr << filename << '(' << tok->getLine() << "):" << " syntax error at token " << tok->getText() << endl; } else { cerr << filename << "(0): syntax error at null token" << endl; } #if 1 // The logic in the other half of this #if section // generated too much noise for some people's taste. // It's only really useful to myself (TJL) or anyone // else with a taste for debugging cccc.g/java.g etc. int i=stack_depth-1; cerr << filename << '(' << stack_tokenline[i] << "): trying to match " << stack_rules[i] << " at '" << stack_tokentext[i] << "'" << endl; #else cerr << "Parser context:" << endl; for(int i=stack_depth-1; i>=0; i--) { cerr << filename << '(' << stack_tokenline[i] << "): trying to match " << stack_rules[i] << " at '" << stack_tokentext[i] << "'" << endl; } cerr << endl; #endif } void ParseStore::endOfLine(int line) { // We only do the processing below if the line which has just // ended contained at least one non-skippable token // The flag which tells us whether this is true is set in the // token constructor if(ANTLRToken::bCodeLine) { pendingLexicalCounts[tcCODELINES]++; LineLexicalCountMatrix::value_type vt(line,LexicalCountArray(static_cast(tcLAST),0)); for(int i=0; i #include #include "cccc_tok.h" #include "AParser.h" class ANTLRAbstractToken; class ANTLRTokenPtr; class CCCC_Item; // this file declares all enumeration datatypes used in the project, and // also the parse state class, which is used to capture information in the // parse and transfer it to the code database for later report generation // for each enumeration, a single character code is defined for each member // these codes are shown in the inline comments // the enumerations are designed to support resolution of incomplete // knowledge about several sections of code which relate to the same // object to give the most complete picture available class AST; // the languages which can be parsed // only C and C++ are implemented as yet enum Language { lAUTO, lCPLUSPLUS, lANSIC, lJAVA, lADA }; extern Language global_language, file_language; enum Visibility { vPUBLIC='0',vPROTECTED='1',vPRIVATE='2',vIMPLEMENTATION='3', vDONTKNOW='?',vDONTCARE='X',vINVALID='*' }; ostream& operator << (ostream&, Visibility); istream& operator >> (istream&, Visibility&); enum AugmentedBool { abFALSE='F', abTRUE='T', abDONTKNOW='?', abDONTCARE='X', abINVALID='*' }; ostream& operator << (ostream& os, AugmentedBool ab); istream& operator >> (istream& is, AugmentedBool& ab); enum UseType { utDECLARATION='D', utDEFINITION='d', // of methods and classes utINHERITS='I', // inheritance, including Java // extends and implements relations utHASBYVAL='H', utHASBYREF='h', // class data member utPARBYVAL='P', utPARBYREF='p', // method parameter or return value utVARBYVAL='V', utVARBYREF='v', // local variable within a method utTEMPLATE_NAME='T', // typedef alias for a template utTEMPLATE_TYPE='t', // type over which a template is // instantiated utINVOKES='i', // C function invocation utREJECTED='r', // for extents rejected by the parser utWITH='w', // Ada 'with' keyword context utDONTKNOW='?', utDONTCARE='X', utINVALID='*' }; // the parse state object consists of a number of strings representing // knowledge about the identification of the source code object currently // being processed, a number of flags of type AugmentedBool, and // items representing knowledge about the // concerning the object's nature, and also its visibility enum PSString { pssFILE, pssRULE, pssFLAGS, // the context of the parse pssMODTYPE, pssMODULE, // the syntactic class and name of the module pssUTYPE, // unqualified type of the current member pssINDIR, // indirection associated with the type above pssITYPE, // type qualified with indirection pssMEMBER, pssPARAMS, // name, parameter list of a member pssDESCRIPTION, // textual description of the relationship type pssLAST // used to dimension the array }; enum PSFlag { psfCONST, psfSTATIC, psfEXTERN, psfVIRTUAL, // AugmentedBool psfVISIBILITY, // Visibility psfLAST // used to dimension the array }; enum PSVerbosity { psvSILENT, psvQUIET, psvLOUD }; #define MAX_STACK_DEPTH 1000 // I have moved some actions originally embedded within the C++ grammar // out of the grammar into the class ParseUtility defined below, so that // other grammars can use them as well for consistency and efficiency. // The ParseUtility::resynchronize() method provides a standardised way // of 1) resynchronising the parser, and 2) reporting the parse error // which caused the problem. Unfortunately, to do the resynchronisation // it requires access to protected functions of ANTLRParser. // The class ANTLR_Assisted_Parser below is a hack to enable ParseUtility // to violate the protection of the functions required: ParseUtility is // passed a pointer to a real parser which is of a subclass of ANTLRParser, // and casts it to this artificial subclass, so as to give ParseUtility // friend rights and to access the protected functions. // This hack is necessary because the class definition we need to affect // is generated by PCCTS: I am not proud of it and if anyone can suggest // a way of doing without modifying PCCTS or its support code, I will be // very happy to hear about it. class ANTLR_Assisted_Parser : public ANTLRParser { ANTLR_Assisted_Parser(ANTLRParser& parser) : ANTLRParser(parser) {} friend class ParseUtility; }; // The parse utility class is intended to assist the parser in a number // of ways. In earlier versions, this class had at least two distinct // roles: // 1) as a place for common functions which each parser might call // for diagnostics, resynchronisation etc; and // 2) as a general storage area for state which needs to be remembered // for any length of time during the parsing process. // The class ParseStore has been added to support the second role, // and it is hoped that the amount of stored state can be reduced // in the near future. class ParseUtility { public: ParseUtility(ANTLRParser *parser); ~ParseUtility(); // the following methods are used to service the standard tracein/traceout // and syntax error reporting calls generated by PCCTS void tracein(const char *rulename, int guessing, ANTLRAbstractToken *tok); void traceout(const char *rulename, int guessing, ANTLRAbstractToken *tok); void syn(_ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k); // this method consolidates the text of the next n tokens of lookahead string lookahead_text(int n); // this method searches for a string of tokens at the specified nesting // depth from the specified token class, and uses them as a marker to // resynchronise the parser void resynchronize( int initial_nesting, SetWordType *resync_token_class, ANTLRTokenPtr& resync_token); // This utility function is used to create // a composite scope name from a qualifier scope // and a relative name. string scopeCombine(const string& baseScope, const string& name); // Only one instance of this class should exist at any time. // This method allows the parsers and lexers to access the instance. static ParseUtility *currentInstance() { return theCurrentInstance; } private: static ParseUtility *theCurrentInstance; ANTLR_Assisted_Parser *parser; int trace_depth; static int stack_depth; static string stack_tokentext[MAX_STACK_DEPTH]; static int stack_tokenline[MAX_STACK_DEPTH]; static string stack_rules[MAX_STACK_DEPTH]; // copy constructor and assignment operator are private to // prevent unexpected copying ParseUtility(const ParseUtility&); const ParseUtility& operator=(const ParseUtility&); }; // LOC, COM and MVG are all counted by the lexical analyzer, // but the counts must be apportioned after the parser has // identified the extents of the various declarations and definitions // they belong to. // This is achieved by the lexer maintaining counts of each // which are reported to the ParseUtility class on a line by line // basis. ParseUtility uses this data to create a store which is // used to apportion counts as the parser reports extents. enum LexicalCount { tcCOMLINES, tcCODELINES, tcMCCABES_VG, tcLAST }; // The ParseStore class encapsulates all information storage // requirements related to the parser, and also manages // the process of feeding that information to the database // when it is complete. // In particular, the class is responsible for receiving and // retaining counts of the lexical metrics (LOC, COM, // MVG) on a line-by-line basis. These are counted in the // lexical analyzer, and the line-by-line counts must be // integrated to allocate the counts to the extents identified // by the parser as belonging to significant declarations and // definitions. class ParseStore { public: ParseStore(const string& filename); ~ParseStore(); void IncrementCount(LexicalCount lc) { pendingLexicalCounts[lc]++; } void endOfLine(int line); // each of the functions below writes one or more records into // the database of code void record_module_extent(int startLine, int endLine, const string& moduleName, const string& moduleType, const string& description, UseType ut); void record_function_extent(int startLine, int endLine, const string& returnType, const string& moduleName, const string& memberName, const string& paramList, const string& description, Visibility visibility, UseType ut); void record_userel_extent(int startLine, int endLine, const string& clientName, const string& memberName, const string& serverName, const string& description, Visibility visibility, UseType ut); void record_other_extent(int startLine, int endLine, const string& description); void record_file_balance_extent(string); // Each of the record_XXX methods above uses this function to // add an extent record. void insert_extent(CCCC_Item&, int, int, const string&, const string&, UseType, bool allocate_lexcounts); // the class maintains a number of strings and flags which reflect // the most recently recognized module, member, type (with and without // indirection) etc, and the visibility of items occuring at the current // context int get_flag(PSFlag) const; void set_flag(PSFlag,int); void set_flag(Visibility); Visibility get_visibility(); string filename(); char *flags() { return &(*flag.begin()); } // We also need the automatically generated copy constructor // and assignment operator to allow us to save state in the // parser. // Only one instance of this class should exist at any time. // This method allows the parsers and lexers to access the instance. static ParseStore *currentInstance() { return theCurrentInstance; } private: static ParseStore *theCurrentInstance; string theFilename; typedef std::vector LexicalCountArray; LexicalCountArray pendingLexicalCounts; typedef std::map LineLexicalCountMatrix; LineLexicalCountMatrix lineLexicalCounts; typedef std::vector CharArray; CharArray flag; // copy constructor and assignment operator are private to // prevent unexpected copying ParseStore(const ParseStore&); const ParseStore& operator=(const ParseStore&); }; #endif cccc-3.1.4/cccc/cccc_ver.h0000644000000000000000000000004410357462461013731 0ustar rootroot#define CCCC_VERSION_STRING "3.1.4" cccc-3.1.4/cccc/cccc_xml.cc0000644000000000000000000007114710357241712014101 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // cccc_xml.cc // this file defines XML output facilities for the CCCC project #include "cccc.h" #include "cccc_itm.h" #include "cccc_xml.h" // I would love to use the C++ standard preprocessor // directive #if here, but I have had reports before now // of people who are using compilers which only support // #ifdef. #ifdef CCCC_CONF_W32VC #include #else #ifdef CCCC_CONF_W32BC #include #else #include #endif #endif #include #include #include #include "cccc_utl.h" // class static data members CCCC_Project* CCCC_Xml_Stream::prjptr; string CCCC_Xml_Stream::outdir; string CCCC_Xml_Stream::libdir; static const string XML_PREAMBLE = ""; static const string XML_COMMENT_BEGIN = ""; static const string XML_TAG_OPEN_BEGIN = "<"; static const string XML_TAG_OPEN_END = ">"; static const string XML_TAG_CLOSE_BEGIN = ""; static const string XML_TAG_INLINE_BEGIN = "<"; static const string XML_TAG_INLINE_END = "/>"; static const string XML_SPACE = " "; static const string XML_NEWLINE = "\n"; static const string XML_DQUOTE = "\""; static const string XML_EQUALS = "="; static const string PROJECT_NODE_NAME = "CCCC_Project"; static const string TIMESTAMP_NODE_NAME = "timestamp"; static const string SUMMARY_NODE_NAME = "project_summary"; static const string MODSUM_NODE_NAME = "module_summary"; static const string MODDET_NODE_NAME = "module_detail"; static const string PROCSUM_NODE_NAME = "procedural_summary"; static const string PROCDET_NODE_NAME = "procedural_detail"; static const string STRUCTSUM_NODE_NAME = "structural_summary"; static const string STRUCTDET_NODE_NAME = "structural_detail"; static const string OODESIGN_NODE_NAME = "oo_design"; static const string OTHER_NODE_NAME = "other_extents"; static const string REJECTED_NODE_NAME = "rejected_extent"; static const string NAME_NODE_NAME = "name"; static const string MODULE_NODE_NAME = "module"; static const string MEMBER_NODE_NAME = "member_function"; static const string EXTENT_NODE_NAME = "extent"; static const string SUPPLIERS_NODE_NAME = "suppliers"; static const string SUPMOD_NODE_NAME = "supplier_module"; static const string CLIENTS_NODE_NAME = "clients"; static const string CLIMOD_NODE_NAME = "client_module"; static const string DESC_NODE_NAME = "description"; static const string SRCREF_NODE_NAME = "source_reference"; static const string NOM_NODE_NAME = "number_of_modules"; static const string LOC_NODE_NAME = "lines_of_code"; static const string LOCPERMOD_NODE_NAME = "lines_of_code_per_module"; static const string LOCPERCOM_NODE_NAME = "lines_of_code_per_line_of_comment"; static const string LOCPERMEM_NODE_NAME = "lines_of_code_per_member_function"; static const string MVG_NODE_NAME = "McCabes_cyclomatic_complexity"; static const string MVGPERMOD_NODE_NAME = "McCabes_cyclomatic_complexity_per_module"; static const string MVGPERCOM_NODE_NAME = "McCabes_cyclomatic_complexity_per_line_of_comment"; static const string MVGPERMEM_NODE_NAME = "McCabes_cyclomatic_complexity_per_member_function"; static const string COM_NODE_NAME = "lines_of_comment"; static const string COMPERMOD_NODE_NAME = "lines_of_comment_per_module"; static const string COMPERMEM_NODE_NAME = "lines_of_comment_per_member_function"; static const string WMC1_NODE_NAME = "weighted_methods_per_class_unity"; static const string WMCV_NODE_NAME = "weighted_methods_per_class_visibility"; static const string DIT_NODE_NAME = "depth_of_inheritance_tree"; static const string NOC_NODE_NAME = "number_of_children"; static const string CBO_NODE_NAME = "coupling_between_objects"; static const string IF4_NODE_NAME = "IF4"; static const string IF4PERMOD_NODE_NAME = "IF4_per_module"; static const string IF4PERMEM_NODE_NAME = "IF4_per_member_function"; static const string IF4VIS_NODE_NAME = "IF4_visible"; static const string IF4VISPERMOD_NODE_NAME = "IF4_visible_per_module"; static const string IF4VISPERMEM_NODE_NAME = "IF4_visible_per_member_function"; static const string IF4CON_NODE_NAME = "IF4_concrete"; static const string IF4CONPERMOD_NODE_NAME = "IF4_concrete"; static const string IF4CONPERMEM_NODE_NAME = "IF4_concrete_per_member_function"; static const string FO_NODE_NAME = "fan_out"; static const string FOV_NODE_NAME = "fan_out_visible"; static const string FOC_NODE_NAME = "fan_out_concrete"; static const string FI_NODE_NAME = "fan_in"; static const string FIV_NODE_NAME = "fan_in_visible"; static const string FIC_NODE_NAME = "fan_in_concrete"; static const string REJ_LOC_NODE_NAME = "rejected_lines_of_code"; static const string VALUE_ATTR = "value"; static const string LEVEL_ATTR = "level"; static const string FILE_ATTR = "file"; static const string LINE_ATTR = "line"; static const string VISIBLE_ATTR = "visible"; static const string CONCRETE_ATTR = "concrete"; static const string LEVEL_NORMAL = "0"; static const string LEVEL_MEDIUM = "1"; static const string LEVEL_HIGH = "2"; static const string BOOL_FALSE = "false"; static const string BOOL_TRUE = "true"; static string ltrim(string value) { const int MAX_LENGTH = 1000; int i = 0; while(iget_count("NOM"); // number of modules int loc=prjptr->get_count("LOC"); // lines of code int mvg=prjptr->get_count("MVG"); // McCabes cyclomatic complexity int com=prjptr->get_count("COM"); // lines of comment int if4=prjptr->get_count("IF4"); // intermodule complexity (all couplings) int if4v=prjptr->get_count("IF4v"); // intermodule complexity (visible only) int if4c=prjptr->get_count("IF4c"); // intermodule complexity (concrete only) int rej=prjptr->rejected_extent_table.get_count("LOC"); fstr << XML_TAG_OPEN_BEGIN << SUMMARY_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Metric_Node(NOM_NODE_NAME,nom); Put_Metric_Node(LOC_NODE_NAME,loc,"LOCp"); Put_Metric_Node(LOCPERMOD_NODE_NAME,loc,nom,"LOCper"); Put_Metric_Node(MVG_NODE_NAME,mvg,"MVGp"); Put_Metric_Node(MVGPERMOD_NODE_NAME,mvg,nom,"MVGper"); Put_Metric_Node(COM_NODE_NAME,com,"COM"); Put_Metric_Node(COMPERMOD_NODE_NAME,com,nom,"COMper"); Put_Metric_Node(LOCPERCOM_NODE_NAME,loc,com,"L_C"); Put_Metric_Node(MVGPERCOM_NODE_NAME,mvg,com,"M_C"); Put_Metric_Node(IF4_NODE_NAME,if4); Put_Metric_Node(IF4PERMOD_NODE_NAME,if4,nom,"8.3"); Put_Metric_Node(IF4VIS_NODE_NAME,if4v); Put_Metric_Node(IF4VISPERMOD_NODE_NAME,if4v,nom,"8.3"); Put_Metric_Node(IF4CON_NODE_NAME,if4c); Put_Metric_Node(IF4CONPERMOD_NODE_NAME,if4c,nom,"8.3"); Put_Metric_Node(REJ_LOC_NODE_NAME,rej,"REJ"); fstr << XML_TAG_CLOSE_BEGIN << SUMMARY_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::OO_Design() { fstr << XML_TAG_OPEN_BEGIN << OODESIGN_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); int i=0; while(mod_ptr!=NULL) { i++; if( mod_ptr->is_trivial() == FALSE) { fstr << XML_TAG_OPEN_BEGIN << MODULE_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,mod_ptr->name(nlSIMPLE).c_str(),0,"",""); CCCC_Metric wmc1(mod_ptr->get_count("WMC1"),"WMC1"); CCCC_Metric wmcv(mod_ptr->get_count("WMCv"),"WMCv"); CCCC_Metric dit(mod_ptr->get_count("DIT"),"DIT"); CCCC_Metric noc(mod_ptr->get_count("NOC"),"NOC"); CCCC_Metric cbo(mod_ptr->get_count("CBO"),"CBO"); Put_Metric_Node(WMC1_NODE_NAME,wmc1); Put_Metric_Node(WMCV_NODE_NAME,wmcv); Put_Metric_Node(DIT_NODE_NAME,dit); Put_Metric_Node(NOC_NODE_NAME,noc); Put_Metric_Node(CBO_NODE_NAME,cbo); fstr << XML_TAG_CLOSE_BEGIN << MODULE_NODE_NAME << XML_TAG_CLOSE_END << endl; } mod_ptr=prjptr->module_table.next_item(); } fstr << XML_TAG_CLOSE_BEGIN << OODESIGN_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Procedural_Summary() { fstr << XML_TAG_OPEN_BEGIN << PROCSUM_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); int i=0; while(mod_ptr!=NULL) { i++; if( mod_ptr->is_trivial() == FALSE) { fstr << XML_TAG_OPEN_BEGIN << MODULE_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,mod_ptr->name(nlSIMPLE).c_str(),0,"",""); int loc=mod_ptr->get_count("LOC"); int mvg=mod_ptr->get_count("MVG"); int com=mod_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCm"); CCCC_Metric mmvg(mvg,"MVGm"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Node(LOC_NODE_NAME,mloc); Put_Metric_Node(MVG_NODE_NAME,mmvg); Put_Metric_Node(COM_NODE_NAME,com); Put_Metric_Node(LOCPERCOM_NODE_NAME,ml_c); Put_Metric_Node(MVGPERCOM_NODE_NAME,mm_c); fstr << XML_TAG_CLOSE_BEGIN << MODULE_NODE_NAME << XML_TAG_CLOSE_END << endl; } mod_ptr=prjptr->module_table.next_item(); } fstr << XML_TAG_CLOSE_BEGIN << PROCSUM_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Structural_Summary() { fstr << XML_TAG_OPEN_BEGIN << STRUCTSUM_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Module* module_ptr=prjptr->module_table.first_item(); while(module_ptr!=NULL) { if(module_ptr->is_trivial()==FALSE) { fstr << XML_TAG_OPEN_BEGIN << MODULE_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,module_ptr->name(nlSIMPLE).c_str(),0,"",""); int fov=module_ptr->get_count("FOv"); int foc=module_ptr->get_count("FOc"); int fo=module_ptr->get_count("FO"); int fiv=module_ptr->get_count("FIv"); int fic=module_ptr->get_count("FIc"); int fi=module_ptr->get_count("FI"); int if4v=module_ptr->get_count("IF4v"); int if4c=module_ptr->get_count("IF4c"); int if4=module_ptr->get_count("IF4"); // the last two arguments here turn on links to enable jumping between // the summary and detail cells for the same module Put_Metric_Node(FOV_NODE_NAME,CCCC_Metric(fov,"FOv")); Put_Metric_Node(FOC_NODE_NAME,CCCC_Metric(foc,"FOc")); Put_Metric_Node(FO_NODE_NAME,CCCC_Metric(fo,"FO")); Put_Metric_Node(FIV_NODE_NAME,CCCC_Metric(fiv,"FIv")); Put_Metric_Node(FIC_NODE_NAME,CCCC_Metric(fic,"FIc")); Put_Metric_Node(FI_NODE_NAME,CCCC_Metric(fi,"FI")); Put_Metric_Node(IF4VIS_NODE_NAME,CCCC_Metric(if4v,"IF4v")); Put_Metric_Node(IF4CON_NODE_NAME,CCCC_Metric(if4c,"IF4c")); Put_Metric_Node(IF4_NODE_NAME,CCCC_Metric(if4,"IF4")); fstr << XML_TAG_CLOSE_BEGIN << MODULE_NODE_NAME << XML_TAG_CLOSE_END << endl; } module_ptr=prjptr->module_table.next_item(); } fstr << XML_TAG_CLOSE_BEGIN << STRUCTSUM_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Put_Structural_Details_Node( CCCC_Module *mod, CCCC_Project *prj, int mask, UserelNameLevel nl) { #if 0 std::cerr << "Relationships for " << mod->name(nlMODULE_NAME) << " (" << mod << ")" << std::endl; #endif CCCC_Module::relationship_map_t::iterator iter; CCCC_Module::relationship_map_t *relationship_map=NULL; string nodeTag; if(mask==rmeCLIENT) { nodeTag = CLIMOD_NODE_NAME; relationship_map=&(mod->client_map); } else if(mask==rmeSUPPLIER) { nodeTag = SUPMOD_NODE_NAME; relationship_map=&(mod->supplier_map); } if(relationship_map==NULL) { cerr << "unexpected relationship mask " << mask << endl; } else { fstr << XML_TAG_OPEN_BEGIN << nodeTag << XML_TAG_OPEN_END << endl; for( iter=relationship_map->begin(); iter!=relationship_map->end(); iter++ ) { CCCC_UseRelationship *ur_ptr=(*iter).second; Put_Label_Node(NAME_NODE_NAME, ur_ptr->name(nl).c_str(),0,"",""); AugmentedBool vis=ur_ptr->is_visible(); AugmentedBool con=ur_ptr->is_concrete(); string visvalue = BOOL_FALSE; string convalue = BOOL_FALSE; if(vis!=abFALSE) { visvalue = BOOL_TRUE; } if(con!=abFALSE) { convalue = BOOL_TRUE; } Put_Label_Node(VISIBLE_ATTR,visvalue,0,"",""); Put_Label_Node(CONCRETE_ATTR,convalue,0,"",""); Put_Extent_List(*ur_ptr,true); } fstr << XML_TAG_CLOSE_BEGIN << nodeTag << XML_TAG_CLOSE_END << endl; } } void CCCC_Xml_Stream::Structural_Detail() { fstr << XML_TAG_OPEN_BEGIN << STRUCTDET_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Module* module_ptr=prjptr->module_table.first_item(); while(module_ptr!=NULL) { if(module_ptr->is_trivial()==FALSE) { Structural_Detail(module_ptr); } module_ptr=prjptr->module_table.next_item(); } fstr << XML_TAG_CLOSE_BEGIN << STRUCTDET_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Procedural_Detail() { fstr << XML_TAG_OPEN_BEGIN << PROCDET_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Module* mod_ptr=prjptr->module_table.first_item(); while(mod_ptr!=NULL) { if( (mod_ptr->name(nlMODULE_TYPE)!="builtin") && (mod_ptr->name(nlMODULE_TYPE)!="enum") && (mod_ptr->name(nlMODULE_TYPE)!="union") ) { fstr << XML_TAG_OPEN_BEGIN << MODULE_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,mod_ptr->name(nlSIMPLE).c_str(),50, "procdet","procsum",mod_ptr); Procedural_Detail(mod_ptr); fstr << XML_TAG_CLOSE_BEGIN << MODULE_NODE_NAME << XML_TAG_CLOSE_END << endl; } mod_ptr=prjptr->module_table.next_item(); } fstr << XML_TAG_CLOSE_BEGIN << PROCDET_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Other_Extents() { fstr << XML_TAG_OPEN_BEGIN << OTHER_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Extent *extent_ptr=prjptr->rejected_extent_table.first_item(); while(extent_ptr!=NULL) { fstr << XML_TAG_OPEN_BEGIN << REJECTED_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,extent_ptr->name(nlDESCRIPTION).c_str()); Put_Extent_Node(*extent_ptr,0); Put_Metric_Node(LOC_NODE_NAME,extent_ptr->get_count("LOC"),""); Put_Metric_Node(COM_NODE_NAME,extent_ptr->get_count("COM"),""); Put_Metric_Node(MVG_NODE_NAME,extent_ptr->get_count("MVG"),""); extent_ptr=prjptr->rejected_extent_table.next_item(); fstr << XML_TAG_CLOSE_BEGIN << REJECTED_NODE_NAME << XML_TAG_CLOSE_END << endl; } fstr << XML_TAG_CLOSE_BEGIN << OTHER_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Put_Label_Node(string nodeTag, string label, int width, string ref_name, string ref_href, CCCC_Record *rec_ptr) { if(label.size()>0) { fstr << XML_TAG_OPEN_BEGIN << nodeTag << XML_TAG_OPEN_END; *this << label; fstr << XML_TAG_CLOSE_BEGIN << nodeTag << XML_TAG_CLOSE_END << endl; } else { // Do nothing } if(rec_ptr != 0) { Put_Extent_List(*rec_ptr,true); } } void CCCC_Xml_Stream::Put_Metric_Node(string nodeTag, int count, string tag) { CCCC_Metric m(count, tag.c_str()); Put_Metric_Node(nodeTag,m); } void CCCC_Xml_Stream::Put_Metric_Node(string nodeTag, int num, int denom, string tag) { CCCC_Metric m(num,denom, tag.c_str()); Put_Metric_Node(nodeTag,m); } void CCCC_Xml_Stream::Put_Metric_Node(string nodeTag,const CCCC_Metric& metric) { fstr << XML_TAG_INLINE_BEGIN << nodeTag << XML_SPACE << VALUE_ATTR << XML_EQUALS << XML_DQUOTE; *this << metric; fstr << XML_DQUOTE << XML_SPACE << LEVEL_ATTR << XML_EQUALS << XML_DQUOTE; switch(metric.emphasis_level()) { case elMEDIUM: fstr << LEVEL_MEDIUM; break; case elHIGH: fstr << LEVEL_HIGH; break; default: fstr << LEVEL_NORMAL; break; } fstr << XML_DQUOTE << XML_SPACE << XML_TAG_INLINE_END << endl; } void CCCC_Xml_Stream::Put_Extent_URL(const CCCC_Extent& extent) { string filename=extent.name(nlFILENAME); int linenumber=atoi(extent.name(nlLINENUMBER).c_str()); fstr << XML_TAG_INLINE_BEGIN << SRCREF_NODE_NAME << XML_SPACE << FILE_ATTR << XML_EQUALS << XML_DQUOTE; *this << filename; fstr << XML_DQUOTE << XML_SPACE << LINE_ATTR << XML_EQUALS << XML_DQUOTE; *this << linenumber; fstr << XML_DQUOTE << XML_SPACE << XML_TAG_INLINE_END << endl; } void CCCC_Xml_Stream::Put_Extent_Node(const CCCC_Extent& extent, int width, bool withDescription) { if(withDescription) { fstr << XML_TAG_OPEN_BEGIN << DESC_NODE_NAME << XML_TAG_OPEN_END << extent.name(nlDESCRIPTION) << XML_TAG_CLOSE_BEGIN << DESC_NODE_NAME << XML_TAG_CLOSE_END << endl; } Put_Extent_URL(extent); } void CCCC_Xml_Stream::Put_Extent_List(CCCC_Record& record, bool withDescription) { CCCC_Extent *ext_ptr=record.extent_table.first_item(); while(ext_ptr!=NULL) { fstr << XML_TAG_OPEN_BEGIN << EXTENT_NODE_NAME << XML_TAG_OPEN_END << endl; if(withDescription) { fstr << XML_TAG_OPEN_BEGIN << DESC_NODE_NAME << XML_TAG_OPEN_END << ext_ptr->name(nlDESCRIPTION) << XML_TAG_CLOSE_BEGIN << DESC_NODE_NAME << XML_TAG_CLOSE_END << endl; } Put_Extent_URL(*ext_ptr); fstr << XML_TAG_CLOSE_BEGIN << EXTENT_NODE_NAME << XML_TAG_CLOSE_END << endl; ext_ptr=record.extent_table.next_item(); } } // the next two methods define the two basic output operations through which // all of the higher level output operations are composed CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const string& stg) { // initialise a character pointer to the start of the string's buffer const char *cptr=stg.c_str(); while(*cptr!='\000') { char c=*cptr; // the purpose of this is to filter out the characters which // must be escaped in HTML switch(c) { case '>': os.fstr << ">" ; break; case '<': os.fstr << "<" ; break; case '&': os.fstr << "&"; break; default : os.fstr << c; } cptr++; } return os; } CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const CCCC_Metric& mtc) { // by writing to the underlying ostream object, we avoid the escape // functionality os.fstr << ltrim(mtc.value_string()) ; return os; } void CCCC_Xml_Stream::Separate_Modules() { // this function generates a separate HTML report for each non-trivial // module in the database CCCC_Module* mod_ptr=prjptr->module_table.first_item(); while(mod_ptr!=NULL) { int trivial_module=mod_ptr->is_trivial(); if(trivial_module==FALSE) { string info="Detailed report on module " + mod_ptr->key(); string filename=outdir; filename+="/"; filename+=mod_ptr->key()+".xml"; CCCC_Xml_Stream module_xml_str(filename,info.c_str()); module_xml_str.Module_Summary(mod_ptr); module_xml_str.fstr << XML_TAG_OPEN_BEGIN << MODDET_NODE_NAME << XML_TAG_OPEN_END << endl; module_xml_str.Module_Detail(mod_ptr); module_xml_str.fstr << XML_TAG_CLOSE_BEGIN << MODDET_NODE_NAME << XML_TAG_CLOSE_END << endl; module_xml_str.fstr << XML_TAG_OPEN_BEGIN << PROCDET_NODE_NAME << XML_TAG_OPEN_END << endl; module_xml_str.Procedural_Detail(mod_ptr); module_xml_str.fstr << XML_TAG_CLOSE_BEGIN << PROCDET_NODE_NAME << XML_TAG_CLOSE_END << endl; module_xml_str.fstr << XML_TAG_OPEN_BEGIN << STRUCTDET_NODE_NAME << XML_TAG_OPEN_END << endl; module_xml_str.Structural_Detail(mod_ptr); module_xml_str.fstr << XML_TAG_CLOSE_BEGIN << STRUCTDET_NODE_NAME << XML_TAG_CLOSE_END << endl; } else { #if 0 cerr << mod_ptr->module_type << " " << mod_ptr->key() << " is trivial" << endl; #endif } mod_ptr=prjptr->module_table.next_item(); } } void CCCC_Xml_Stream::Module_Detail(CCCC_Module *module_ptr) { // this function generates the contents of the table of definition // and declaration extents for a single module // the output needs to be enveloped in a pair of
    tags // these have not been put within the function because it is designed // to be used in two contexts: // 1. within the Separate_Modules function, wrapped directly in the table // tags // 2. within the Module_Detail function, where the table tags are // around the output of many calls to this function (not yet implemented) CCCC_Record::Extent_Table::iterator eIter = module_ptr->extent_table.begin(); while(eIter!=module_ptr->extent_table.end()) { CCCC_Extent *ext_ptr=(*eIter).second; Put_Extent_Node(*ext_ptr,0,true); int loc=ext_ptr->get_count("LOC"); int mvg=ext_ptr->get_count("MVG"); int com=ext_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCf"); CCCC_Metric mmvg(mvg,"MVGf"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Node(LOC_NODE_NAME,mloc); Put_Metric_Node(MVG_NODE_NAME,mmvg); Put_Metric_Node(COM_NODE_NAME,com); Put_Metric_Node(LOCPERCOM_NODE_NAME,ml_c); Put_Metric_Node(MVGPERCOM_NODE_NAME,mm_c); eIter++; } } void CCCC_Xml_Stream::Procedural_Detail(CCCC_Module *module_ptr) { // this function generates the contents of the procedural detail table // relating to a single module // the output needs to be enveloped in a pair of
    tags // these have not been put within the function because it is designed // to be used in two contexts: // 1. within the Separate_Modules function, wrapped directly in the table // tags // 2. within the Procedural_Detail function, where the table tags are // around the output of many calls to this function CCCC_Module::member_map_t::iterator iter = module_ptr->member_map.begin(); while(iter!=module_ptr->member_map.end()) { fstr << XML_TAG_OPEN_BEGIN << MEMBER_NODE_NAME << XML_TAG_OPEN_END << endl; CCCC_Member *mem_ptr=(*iter).second; Put_Label_Node(NAME_NODE_NAME,mem_ptr->name(nlLOCAL).c_str(),0,"","",mem_ptr); int loc=mem_ptr->get_count("LOC"); int mvg=mem_ptr->get_count("MVG"); int com=mem_ptr->get_count("COM"); CCCC_Metric mloc(loc,"LOCf"); CCCC_Metric mmvg(mvg,"MVGf"); CCCC_Metric ml_c(loc,com,"L_C"); CCCC_Metric mm_c(mvg,com,"M_C"); Put_Metric_Node(LOC_NODE_NAME,mloc); Put_Metric_Node(MVG_NODE_NAME,mmvg); Put_Metric_Node(COM_NODE_NAME,com); Put_Metric_Node(LOCPERCOM_NODE_NAME,ml_c); Put_Metric_Node(MVGPERCOM_NODE_NAME,mm_c); iter++; fstr << XML_TAG_CLOSE_BEGIN << MEMBER_NODE_NAME << XML_TAG_CLOSE_END << endl; } } void CCCC_Xml_Stream::Structural_Detail(CCCC_Module *module_ptr) { fstr << XML_TAG_OPEN_BEGIN << MODULE_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Label_Node(NAME_NODE_NAME,module_ptr->name(nlSIMPLE).c_str(), 0, "",""); Put_Structural_Details_Node(module_ptr, prjptr, rmeCLIENT, nlCLIENT); Put_Structural_Details_Node(module_ptr, prjptr, rmeSUPPLIER, nlSUPPLIER); fstr << XML_TAG_CLOSE_BEGIN << MODULE_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Module_Summary(CCCC_Module *module_ptr) { // calculate the counts on which all displayed data will be based // int nof=module_ptr->member_table.records(); // Number of functions int nof=0; int loc=module_ptr->get_count("LOC"); // lines of code int mvg=module_ptr->get_count("MVG"); // McCabes cyclomatic complexity int com=module_ptr->get_count("COM"); // lines of comment // the variants of IF4 measure information flow and couplings int if4=module_ptr->get_count("IF4"); // (all couplings) int if4v=module_ptr->get_count("IF4v"); // (visible only) int if4c=module_ptr->get_count("IF4c"); // (concrete only) int wmc1=module_ptr->get_count("WMC1"); // Weighted methods/class (unity) int wmcv=module_ptr->get_count("WMCv"); // Weighted methods/class (visible) int dit=module_ptr->get_count("DIT"); // depth of inheritance tree int noc=module_ptr->get_count("NOC"); // number of children int cbo=module_ptr->get_count("CBO"); // coupling between objects fstr << XML_TAG_OPEN_BEGIN << MODSUM_NODE_NAME << XML_TAG_OPEN_END << endl; Put_Metric_Node(LOC_NODE_NAME,loc,"LOCm"); Put_Metric_Node(LOCPERMEM_NODE_NAME,loc,nof,"LOCg"); Put_Metric_Node(MVG_NODE_NAME,mvg,"MVGm"); Put_Metric_Node(MVGPERMEM_NODE_NAME,mvg,nof,"MVGf"); Put_Metric_Node(LOC_NODE_NAME,com,"COMm"); Put_Metric_Node(LOCPERMEM_NODE_NAME,com,nof,"8.3"); Put_Metric_Node(LOCPERCOM_NODE_NAME,loc,com,"L_C"); Put_Metric_Node(MVGPERCOM_NODE_NAME,mvg,com,"M_C"); Put_Metric_Node(WMC1_NODE_NAME,wmc1); Put_Metric_Node(WMCV_NODE_NAME,wmcv); Put_Metric_Node(DIT_NODE_NAME,dit); Put_Metric_Node(NOC_NODE_NAME,noc); Put_Metric_Node(CBO_NODE_NAME,cbo); Put_Metric_Node(IF4_NODE_NAME,if4,1,"IF4"); Put_Metric_Node(IF4PERMEM_NODE_NAME,if4,nof,"8.3"); Put_Metric_Node(IF4VIS_NODE_NAME,if4v,1,"IF4v"); Put_Metric_Node(IF4VISPERMEM_NODE_NAME,if4v,nof,"8.3"); Put_Metric_Node(IF4CON_NODE_NAME,if4c,1,"IF4c"); Put_Metric_Node(IF4CONPERMEM_NODE_NAME,if4c,nof,"8.3"); fstr << XML_TAG_CLOSE_BEGIN << MODSUM_NODE_NAME << XML_TAG_CLOSE_END << endl; } void CCCC_Xml_Stream::Source_Listing() { } #if 0 static string pad_string(int target_width, string the_string, string padding) { int spaces_required=target_width-the_string.size(); string pad_string; while(spaces_required>0) { pad_string+=padding; spaces_required--; } return pad_string+the_string; } #endif #ifdef UNIT_TEST int main() { CCCC_Project *prj_ptr=test_project_ptr(); CCCC_Xml_Stream os(*prj_ptr,"cccc.htm","."); return 0; } #endif cccc-3.1.4/cccc/cccc_xml.h0000644000000000000000000001031210357241712013726 0ustar rootroot/* CCCC - C and C++ Code Counter Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __CCCC_XML_H #define __CCCC_XML_H #include "cccc.h" #include #include #include "cccc_db.h" #include "cccc_met.h" // Ideally, this class would be defined to reuse common // facilities abstracted from CCCC_Html_Stream. // This may happen in the future, for the moment, the implementation // has been created by cut and paste. // We need to include cccc_htm.h because it defines the enumeration // ReportType. #include "cccc_htm.h" class CCCC_Xml_Stream { friend CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const string& stg); friend CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const CCCC_Metric& mtc); ofstream fstr; static string libdir; static string outdir; static CCCC_Project* prjptr; void Timestamp(); void Project_Summary(); void Procedural_Summary(); void Procedural_Detail(); void Structural_Summary(); void Structural_Detail(); void OO_Design(); void Other_Extents(); void Separate_Modules(); void Source_Listing(); void Module_Summary(CCCC_Module *module_ptr); void Module_Detail(CCCC_Module *module_ptr); void Procedural_Detail(CCCC_Module *module_ptr); void Structural_Detail(CCCC_Module *module_ptr); void Separate_Module_Link(CCCC_Module *module_ptr); void Put_Label_Node(string nodeTag, string label, int width=0, string ref_name="", string ref_href="", CCCC_Record *rec_ptr=0); void Put_Metric_Node(string nodeTag, const CCCC_Metric& metric); void Put_Metric_Node(string nodeTag, int count, string tag); void Put_Metric_Node(string nodeTag, int num, int denom, string tag); void Put_Extent_URL(const CCCC_Extent& extent); void Put_Extent_Node(const CCCC_Extent& extent, int width=0, bool withDescription=false); void Put_Extent_List(CCCC_Record& record,bool withDescription=false); void Put_Structural_Details_Node(CCCC_Module *mod, CCCC_Project *prj, int mask, UserelNameLevel nl); public: static void GenerateReports(CCCC_Project* project, int report_mask, const string& outfile, const string& outdir); // general-purpose constructor with standard preamble CCCC_Xml_Stream(const string& fname, const string& info); // destructor with standard trailer ~CCCC_Xml_Stream(); }; CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const string& stg); CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const CCCC_Metric& mtc); CCCC_Xml_Stream& operator <<(CCCC_Xml_Stream& os, const CCCC_Extent& ext); #if 0 // this class is added to support the generation of an HTML file // containing the source analysed by the run, with anchors embedded at // each of the lines referred to in the other parts of the report class Source_Anchor { // if this looks more like a struct to you, it does to me too... // it could be embedded withing CCCC_Xml_Stream except that this // might make the default constructor unavailable for the std::map // instantiation string file_; int line_; public: Source_Anchor():line_(0) {} Source_Anchor(string file, int line) : file_(file), line_(line) {} string get_file() const { return file_; } int get_line() const { return line_; } string key() const; void Emit_HREF(ofstream& fstr); void Emit_NAME(ofstream& fstr); void Emit_SPACE(ofstream& fstr); // the default copy constructor, assignment operator and destructor // are OK for this class }; #endif #endif /* __CCCC_XML_H */ cccc-3.1.4/cccc/ccccmain.cc0000644000000000000000000004441710357334136014071 0ustar rootroot// ccccmain.cc // command line interface implementation for the cccc project #include "cccc.h" #include "cccc_ver.h" #include #include #include #ifdef _WIN32 #include #include #define HANDLE intptr_t #define INVALID_HANDLE_VALUE -1 #else #include #endif #include "cccc_itm.h" #include "cccc_opt.h" #include "cccc_met.h" #include "cccc_db.h" #include "cccc_utl.h" #include "cccc_htm.h" #include "cccc_xml.h" // support for languages is now a compile-time option #ifdef CC_INCLUDED #include "CParser.h" #include "CLexer.h" #endif #ifdef JAVA_INCLUDED #include "JParser.h" #include "JLexer.h" #endif #ifdef ADA_INCLUDED #include "AdaPrser.h" #include "ALexer.h" #endif #define NEW_PAGE "\f\n" CCCC_Project *prj=NULL; int DebugMask=0; int dont_free=0; char *skip_identifiers[SKIP_IDENTIFIERS_ARRAY_SIZE]; #if defined(_WIN32) && defined(__GNUG__) // Cygnus gcc for Win32 B19 will try to expand wildcards that are given at // the commandline. Sadly this "globbing" will not work the way it is // supposed in Win32, but luckily the whole globbing can be disabled by // defining the following variable: int _CRT_glob = 0; #endif /* ** global variables to hold default values for various things */ string current_filename, current_rule, parse_language; // class Main encapsulates the top level of control for the program // including command line handling class Main { // most of the data members of this class are either set // by default or gleaned from the command line // each of the data members of type string or int can be // set by a command line flag of the type --= string outdir; string db_infile; string db_outfile; string opt_infile; string opt_outfile; string html_outfile; string xml_outfile; string lang; int report_mask; int debug_mask; int files_parsed; // As we gather up the list of files to be processed // we work out and record the appropriate language to // use for each. typedef std::pair file_entry; std::list file_list; // this function encapsulates adding an argument to the file_list // for the time being, on Win32 only, it also performs filename globbing void AddFileArgument(const string&); public: Main(); void HandleArgs(int argc, char**argv); void HandleDebugOption(const string&); void HandleReportOption(const string&); void PrintCredits(ostream& os); void PrintUsage(ostream& os); int ParseFiles(); int DumpDatabase(); int LoadDatabase(); void GenerateHtml(); void GenerateXml(); void DescribeOutput(); int filesParsed(); friend int main(int argc, char** argv); }; Main *app=NULL; Main::Main() { report_mask=0xFFFF&(~(rtPROC2|rtSTRUCT2)) ; debug_mask=0; files_parsed=0; } void Main::HandleArgs(int argc, char **argv) { bool accepting_options=true; for(int i=1; i> filename; file_entry file_entry(filename,lang); file_list.push_back(file_entry); } } else { #ifdef _WIN32 /* ** In Win32 we will have to expand all wildcards ourself, because the ** shell won't do this for us. ** This code reworked for 3.1.1 because we are now using the Visual C++ 2003 ** Toolkit, which does not provide the same APIs as Visual Studio 5/6. */ _finddata_t fd; HANDLE sh = _findfirst(file_arg.c_str(), &fd); // 3.pre40 // I discovered (by behaviour, not documentation) that // the structure returned by FindFirstFile etc. only includes // the final filename component, even if the search pattern // included a directory. // This is going to be a bugger to fix... string directoryPrefix; size_t directoryPrefixLength = file_arg.find_last_of("/\\"); if(directoryPrefixLength!=string::npos) { directoryPrefix = string(file_arg,0,directoryPrefixLength+1); } // Was it as easy as that?... int findnextReturnValue = 0; while (findnextReturnValue==0) { string sFileName=directoryPrefix; sFileName.append(fd.name); file_entry file_entry(sFileName,lang); file_list.push_back(file_entry); findnextReturnValue = _findnext(sh, &fd); } _findclose(sh); #else file_entry file_entry(file_arg,lang); file_list.push_back(file_entry); cout << file_arg << endl; #endif } } /* ** method to parse all of the supplied list of files */ int Main::ParseFiles() { FILE *f; std::list::iterator file_iterator=file_list.begin(); while(file_iterator!=file_list.end()) { const file_entry &entry=*file_iterator; string filename=entry.first; string file_language=entry.second; ParseStore ps(filename); // The following objects are used to assist in the parsing // process. if(file_language.size()==0) { file_language=CCCC_Options::getFileLanguage(filename); } // CCCC supports a convention that the language may include an // embedded '.', in which case the part before the . controls // which parser runs, while the whole can be examined inside // the parser to check for special dialect handling. unsigned int period_pos=file_language.find("."); string base_language=file_language.substr(0,period_pos); f=fopen(filename.c_str(),"r"); if( f == NULL ) { cerr << "Couldn't open " << filename << endl; } else { DLGFileInput in(f); // show progress cerr << "Processing " << filename; // The first case is just to allow symetric handling // of the optional inclusion of support for each language if(0) { } #ifdef CC_INCLUDED else if( (base_language=="c++") || (base_language=="c") ) { cerr << " as C/C++ (" << file_language << ")" << endl; CLexer theLexer(&in); ANTLRTokenBuffer thePipe(&theLexer); theLexer.setToken(¤tLexerToken); CParser theParser(&thePipe); ParseUtility pu(&theParser); theParser.init(filename,file_language); // This function turns of the annoying "guess failed" messages // every time a syntactic predicate fails. // This message is enabled by default when PCCTS is run with // tracing turned on (as it is by default in this application). // In the current case this is inappropriate as the C++ parser // uses guessing heavily to break ambiguities, and we expect // large numbers of guesses to be tested and to fail. // This message and the flag which gates it were added around // PCCTS 1.33 MR10. // If you are building with an earlier version, this line should // cause an error and can safely be commented out. theParser.traceGuessOption(-1); theParser.start(); files_parsed++; } #endif // CC_INCLUDED #ifdef JAVA_INCLUDED else if(base_language=="java") { cerr << " as Java" << endl; JLexer theLexer(&in); ANTLRTokenBuffer thePipe(&theLexer); theLexer.setToken(¤tLexerToken); JParser theParser(&thePipe); theParser.init(filename,file_language); theParser.traceGuessOption(-1); theParser.compilationUnit(); files_parsed++; } #endif // JAVA_INCLUDED #ifdef ADA_INCLUDED else if(base_language=="ada") { cerr << " as Ada" << endl; ALexer theLexer(&in); ANTLRTokenBuffer thePipe(&theLexer); theLexer.setToken(¤tLexerToken); AdaPrser theParser(&thePipe); theParser.init(filename,file_language); theParser.traceGuessOption(-1); theParser.goal_symbol(); files_parsed++; } #endif // ADA_INCLUDED else if(base_language=="") { cerr << " - no parseable language identified"; } else { cerr << "Unexpected language " << base_language.c_str() << " (" << file_language.c_str() << ") for file " << filename.c_str() << endl; } // close the file fclose(f); } file_iterator++; } return 0; } int Main::DumpDatabase() { ofstream outfile(db_outfile.c_str()); return prj->ToFile(outfile); } int Main::LoadDatabase() { int retval=0; if(db_infile!="") { ifstream infile(db_infile.c_str()); retval=prj->FromFile(infile); } return retval; } void Main::GenerateHtml() { cerr << endl << "Generating HTML reports" << endl; CCCC_Html_Stream::GenerateReports(prj,report_mask,html_outfile,outdir); } void Main::GenerateXml() { cerr << endl << "Generating XML reports" << endl; CCCC_Xml_Stream::GenerateReports(prj,report_mask,xml_outfile,outdir); } void Main::HandleDebugOption(const string& arg) { /* ** arg may either be a number, or a string of letters denoting ** facilities to be debugged. ** the string of letters is the public way - allowing input of a ** number is just there to support quickly adding a category of ** debug messages without having to change this file immediately */ DebugMask=atoi(arg.c_str()); for (int i=0; arg[i]!='\0'; i++) { switch (arg[i]) { case 'p' : DebugMask |= PARSER; break; case 'l' : DebugMask |= LEXER; break; case 'c' : DebugMask |= COUNTER; break; case 'm' : DebugMask |= MEMORY; break; case 'x' : case 'X' : DebugMask = 0xFF; break; } } } void Main::HandleReportOption(const string& arg) { /* ** arg may either be a number, or a string of letters denoting ** reports to be generated */ report_mask=atoi(arg.c_str()); for (int i=0; arg[i]!='\0'; i++) { switch (arg[i]) { case 'c': report_mask |= rtCONTENTS; break; case 's' : report_mask |= rtSUMMARY; break; case 'p' : report_mask |= rtPROC1; break; case 'P': report_mask |= rtPROC2; break; case 'r' : report_mask |= rtSTRUCT1; break; case 'R' : report_mask |= rtSTRUCT2; break; case 'S' : report_mask |= rtSEPARATE_MODULES; break; case 'o' : report_mask |= rtOODESIGN; break; case 'L' : // for 'listing' as s and S for 'source' are already used report_mask |= rtSOURCE; break; case 'j' : report_mask |= rtOTHER; break; case 'h' : report_mask |= rtCCCC; break; case 't' : report_mask |= rtSHOW_GEN_TIME; break; default: cerr << "Unexpected report requested:" << arg[i] << endl; PrintUsage(cerr); exit(-1); } } } /* ** giving credit where it is due */ void Main::PrintCredits(ostream& os) { // the principal purpose of the constructor is to set up the // two lots of boilerplate text that this class requires string version_string="Version "; version_string.append(CCCC_VERSION_STRING); const char *credit_strings[] = { "CCCC - a code counter for C and C++", "===================================", "", "A program to analyse C and C++ source code and report on", "some simple software metrics", version_string.c_str(), "Copyright Tim Littlefair, 1995, 1996, 1997, 1998, 1999, 2000", "with contributions from Bill McLean, Herman Hueni, Lynn Wilson ", "Peter Bell, Thomas Hieber and Kenneth H. Cox.", "", "The development of this program was heavily dependent on", "the Purdue Compiler Construction Tool Set (PCCTS) ", "by Terence Parr, Will Cohen, Hank Dietz, Russel Quoung,", "Tom Moog and others.", "", "CCCC comes with ABSOLUTELY NO WARRANTY.", "This is free software, and you are welcome to redistribute it", "under certain conditions. See the file COPYING in the source", "code distribution for details.", NULL }; const char **string_ptr=credit_strings; while(*string_ptr!=NULL) { os << *string_ptr << endl; string_ptr++; } } void Main::DescribeOutput() { if(files_parsed>0) { // make sure the user knows where the real output went // make sure the user knows where the real output went cerr << endl << "Primary HTML output is in " << html_outfile << endl; if(report_mask & rtSEPARATE_MODULES) { cerr << "Detailed HTML reports on modules and source are in " << outdir << endl; } cerr << "Primary XML output is in " << xml_outfile << endl ; if(report_mask & rtSEPARATE_MODULES) { cerr << "Detailed XML reports on modules are in " << outdir << endl; } cerr << "Database dump is in " << db_outfile << endl << endl; } else { cerr << endl << "No files parsed on this run" << endl << endl; } } /* ** the usage message is printed on cerr if unexpected options are found, ** and on cout if option --help is found. */ void Main::PrintUsage(ostream& os) { const char *usage_strings[] = { "Usage: ", "cccc [options] file1.c ... ", "Process files listed on command line.", "If the filenames include '-', read a list of files from standard input.", "Command Line Options: (default arguments/behaviour specified in braces)", "--help * generate this help message", "--outdir= * directory for generated files {.cccc}", "--html_outfile= * name of main HTML report {/cccc.html}", "--xml_outfile= * name of main XML report {/cccc.xml}", "--db_infile= * preload internal database from named file", " {empty file}", "--db_outfile= * save internal database to file {/cccc.db}", "--opt_infile= * load options from named file {hard coded, see below}", "--opt_outfile= * save options to named file {/cccc.opt}", "--lang= * use language specified for files specified ", " after this option (c,c++,ada,java, no default)", "--report_mask= * control report content ", "--debug_mask= * control debug output content ", " (refer to ccccmain.cc for mask values)", "Refer to ccccmain.cc for usage of --report_mask and --debug_mask.", "Refer to cccc_opt.cc for hard coded default option values, including default ", "extension/language mapping and metric treatment thresholds.", NULL }; const char **string_ptr=usage_strings; while(*string_ptr!=NULL) { os << *string_ptr << endl; string_ptr++; } } int Main::filesParsed() { return files_parsed; } int main(int argc, char **argv) { app=new Main; prj=new CCCC_Project; // process command line app->HandleArgs(argc, argv); // If we are still running, acknowledge those who helped app->PrintCredits(cerr); cerr << "Parsing" << endl; CCCC_Record::set_active_project(prj); app->ParseFiles(); CCCC_Record::set_active_project(NULL); if(app->filesParsed()>0) { prj->reindex(); #ifdef _WIN32 _mkdir(app->outdir.c_str()); #else mkdir(app->outdir.c_str(),0777); #endif app->DumpDatabase(); // generate html output app->GenerateHtml(); app->GenerateXml(); } app->DescribeOutput(); delete app; delete prj; return 0; } cccc-3.1.4/cccc/java.g0000644000000000000000000010607110171515300013072 0ustar rootroot// java.g for CCCC v 3.X // by Tim Littlefair, November 1999 // based on the java.g for ANTLR2 from www.antlr.org // credits from that version follow: /** Java 1.1 Recognizer Grammar * * Contributing authors: * John Mitchell johnm@non.net * Terence Parr parrt@magelang.com * John Lilley jlilley@empathy.com * Scott Stanchfield thetick@magelang.com * Markus Mohnen mohnen@informatik.rwth-aachen.de * Peter Williams pwilliams@netdynamics.com * * Version 1.00 December 9, 1997 -- initial release * Version 1.01 December 10, 1997 * fixed bug in octal def (0..7 not 0..8) * Version 1.10 August 1998 (parrt) * added tree construction * fixed definition of WS,comments for mac,pc,unix newlines * added unary plus * Version 1.11 (Nov 20, 1998) * Added "shutup" option to turn off last ambig warning. * Fixed inner class def to allow named class defs as statements * synchronized requires compound not simple statement * add [] after builtInType DOT class in primaryExpression * "const" is reserved but not valid..removed from modifiers * * Version 1.12 (Feb 2, 1999) * Changed LITERAL_xxx to xxx in tree grammar. * Updated java.g to use tokens {...} now for 2.6.0 (new feature). * * Version 1.13 (Apr 23, 1999) * Didn't have (stat)? for else clause in tree parser. * Didn't gen ASTs for interface extends. Updated tree parser too. * Updated to 2.6.0. * Version 1.14 (Jun 20, 1999) * Allowed final/abstract on local classes. * Removed local interfaces from methods * Put instanceof precedence where it belongs...in relationalExpr * It also had expr not type as arg; fixed it. * Missing ! on SEMI in classBlock * fixed: (expr) + "string" was parsed incorrectly (+ as unary plus). * fixed: didn't like Object[].class in parser or tree parser * * This grammar is in the PUBLIC DOMAIN * * BUGS * */ #header<< #define zzTRACE_RULES #include "AParser.h" #include "cccc.h" #include "cccc_utl.h" #include "cccc_opt.h" // the objects which PCCTS creates for ASTs as the #0 variable etc // have type "pointer to ASTBase", which means they need to be cast // to a pointer to my variant of AST if I want to call my AST // methods on them #define MY_AST(X) ( (AST*) X) >> #lexaction << #include // Need to see definition of JLexer class before defining the // next actions. // This will mean this file is included twice in JLexer.cpp. This // should do no harm... #include "JLexer.h" // The lexical analyser passes some information through to // the parse store to be integrated with parse information before inline void IncrementCount(LexicalCount tc) { assert(ParseStore::currentInstance()!=NULL); ParseStore::currentInstance()->IncrementCount(tc); } inline void endOfLine(JLexer &lexer) { assert(ParseStore::currentInstance()!=NULL); ParseStore::currentInstance()->endOfLine(lexer.line()); lexer.newline(); lexer.skip(); } inline void endOfCommentLine(JLexer &lexer) { IncrementCount(tcCOMLINES); endOfLine(lexer); } >> #token Eof "@" << replstr(""); >> // OPERATORS #token QUESTION "?" << IncrementCount(tcMCCABES_VG);>> #token LPAREN "\(" <<;>> #token RPAREN "\)" <<;>> #token LBRACK "\[" <<;>> #token RBRACK "\]" <<;>> #token LCURLY "\{" <<;>> #token RCURLY "\}" <<;>> #token COLON ":" <<;>> #token COMMA "," <<;>> #token DOT "\." <<;>> #token ASSIGN "=" <<;>> #token EQUAL "==" <<;>> #token LNOT "!" <<;>> #token BNOT "\~" <<;>> #token NOT_EQUAL "!=" <<;>> #token DIV "/" <<;>> #token DIV_ASSIGN "/=" <<;>> #token PLUS "\+" <<;>> #token PLUS_ASSIGN "\+=" <<;>> #token INC "\+\+" <<;>> #token MINUS "\-" <<;>> #token MINUS_ASSIGN "\-=" <<;>> #token DEC "\-\-" <<;>> #token STAR "\*" <<;>> #token STAR_ASSIGN "\*=" <<;>> #token MOD "%" <<;>> #token MOD_ASSIGN "%=" <<;>> #token SR "\>\>" <<;>> #token SR_ASSIGN "\>\>=" <<;>> #token BSR "\>\>\>" <<;>> #token BSR_ASSIGN "\>\>\>=" <<;>> #token GE "\>=" <<;>> #token GT "\>" <<;>> #token SL "\<\<" <<;>> #token SL_ASSIGN "\<\<=" <<;>> #token LE "\<=" <<;>> #token LESSTHAN "\<" <<;>> // LT is reserved for PCCTS support code use // Boolean operators // I'm not sure whether the Java VM definition // mandates short circuit evaluation or not. I assume // it does for logical or and logical and, which means // that expressions involving these operators are choice points // in terms of what code gets executed, hence MVG increases. // In theory, bitwise operators could be shortcircuited if // and only if the first operand examined forces the result // (i.e. 1 | expression or 0 & expression). Again, I'm // not sure what the JVM definition says, but I am assuming // that this does not represent a switch of flow of control, // hence no increment for MVG. // Bitwise exclusive or always requires both operands to be // evaluated, hence it does not increment MVG. // Could someone please email me with chapter and verse if // I am wrong in my assumptions here. // tim_littlefair@hotmail.com #token BXOR "\^" <<;>> #token BXOR_ASSIGN "\^=" <<;>> #token BOR "\|" << ; >> #token BOR_ASSIGN "\|=" << ; >> #token LOR "\|\|" << IncrementCount(tcMCCABES_VG); >> #token BAND "&" << ; >> #token BAND_ASSIGN "&=" <<;>> #token LAND "&&" << IncrementCount(tcMCCABES_VG);>> #token SEMI ";" <<;>> // Whitespace -- ignored #token WS "[\ \t]" << skip(); >> // handle newlines #token DOS_NL "\r\n" << endOfLine(*this); >> #token MAC_NL "\r" << endOfLine(*this); >> #token UNIX_NL "\n" << endOfLine(*this); >> // The handling of single and multiline comments and string // and character literals below is copied from my C++ grammar // and may well be less accurate than the treatment in // TJP's base Java grammar. #token COMLINE "//" << mode(COMMENT_LINE); skip(); >> #lexclass COMMENT_LINE #token DOS_COMLINE_END "\r\n" << endOfCommentLine(*this); mode(START); >> #token MAC_COMLINE_END "\r" << endOfCommentLine(*this); mode(START); >> #token UNIX_COMLINE_END "\n" << endOfCommentLine(*this); mode(START); >> #token COMLINE_ANYTHING "~[\n]" << skip(); >> #lexclass START #token COMMULTI "/\*" << mode(COMMENT_MULTI); skip(); >> #lexclass COMMENT_MULTI #token COMMULTI_END "\*/" << IncrementCount(tcCOMLINES); mode(START); skip(); >> #token DOS_COMMULTI_EOL "\r\n" << endOfCommentLine(*this); >> #token MAC_COMMULTI_EOL "\r" << endOfCommentLine(*this); >> #token UNIX_COMMULTI_EOL "\n" << endOfCommentLine(*this); >> #token COMMULTI_ANYTHING "~[\n]" << skip(); >> #lexclass START #token STRINGSTART "\"" << mode(CONST_STRING); skip(); >> #lexclass CONST_STRING #token STRINGCONST "\"" << mode(START); >> // thanks to Lynn Wilson for pointing out the need for a simple fix // to handle escaped newlines within string constants #token LYNNS_FIX "\\\n" << endOfLine(*this); >> // We also need to handle escaped double quotes #token ESCAPED_DQUOTE "\\\"" << skip(); >> #token ESCAPED_OTHER "\\~[\"]" << skip(); >> #token S_ANYTHING "~[\"]" << skip(); >> #lexclass START #token CHARSTART "\'" << mode(CONST_CHAR); skip(); >> #lexclass CONST_CHAR #token CHARCONST "'" << replstr("'.'"); mode(START); >> #token CH_ANYTHING "~[']" << skip(); >> #lexclass START // keywords #token ABSTRACT "abstract" <<;>> #token KW_BOOLEAN "boolean" <<;>> #token BREAK "break" << IncrementCount(tcMCCABES_VG);>> #token KW_BYTE "byte" <<;>> #token CATCH "catch" << /* IncrementCount(tcMCCABES_VG) ? */ ;>> #token DEFAULT "default" <<;>> #token KW_CHAR "char" <<;>> #token CLASS "class" <<;>> #token KW_CONST "const" <<;>> #token CONTINUE "continue" << IncrementCount(tcMCCABES_VG); >> #token DO "do" <<;>> #token KW_DOUBLE "double" <<;>> #token ELSE "else" <<;>> #token EXTENDS "extends" <<;>> #token BFALSE "false" <<;>> #token FINAL "final" <<;>> #token FINALLY "finally" <<;>> #token KW_FLOAT "float" <<;>> #token FOR "for" << IncrementCount(tcMCCABES_VG); >> #token IF "if" << IncrementCount(tcMCCABES_VG); >> #token IMPLEMENTS "implements" <<;>> #token IMPORT "import" <<;>> #token INSTANCEOF "instanceof" <<;>> #token KW_INT "int" <<;>> #token INTERFACE "interface" <<;>> #token KW_LONG "long" <<;>> #token NATIVE "native" <<;>> #token NEW "new" <<;>> #token PNULL "null" <<;>> #token PACKAGE "package" <<;>> #token PRIVATE "private" <<;>> #token PROTECTED "protected" <<;>> #token PUBLIC "public" <<;>> #token RETURN "return" <<;>> #token KW_SHORT "short" <<;>> #token SHUTUP "shutup" <<;>> #token STATIC "static" <<;>> #token SUPER "super" <<;>> #token SWITCH "switch" << IncrementCount(tcMCCABES_VG); >> #token SYNCHRONIZED "synchronized" <<;>> #token THINGS "things" <<;>> #token KW_THIS "this" <<;>> #token THREADSAFE "threadsafe" <<;>> #token THROW "throw" <<;>> #token THROWS "throws" <<;>> #token TRANSIENT "transient" <<;>> #token BTRUE "true" <<;>> #token TRY "try" <<;>> #token KW_VOID "void" <<;>> #token VOLATILE "volatile" <<;>> #token WHILE "while" << IncrementCount(tcMCCABES_VG); >> #token CASE "case" << IncrementCount(tcMCCABES_VG); >> // an identifier. // TJP & co's original grammar for ANTLR 2.0 sets a state in the // lexer to test for keyword literals defined in grammar rules before // matching regular expressions defined as named tokens. // Under PCCTS 1.33MRxx this won't work, we have to move all of the // literals before the IDENT rule and give them names. // Personally, I don't mind this. #token IDENT "[a-zA-Z_$]([a-zA-Z_$0-9])*" <<;>> // a numeric literal #token NUM_INT1 "([0-9])*\.([0-9])+{[eE]{[\+\-]}([0-9])+}{[fFdD]}" <<;>> #token NUM_INT2 "0([0-7])*{[lL]}" <<;>> #token NUM_INT3 "0[xX]([0-9a-fA-F])*{[lL]}" <<;>> #token NUM_INT4 "[1-9]([0-9])*{[lL]}" <<;>> // Option 1 above does not cover a floating point value with an f at // the end but no decimal point #token NUM_INT1A "([0-9])+{[eE]{[\+\-]}([0-9])+}{[fFdD]}" <<;>> // Nor does it cover a floating point value with a decimal point but // no following mantissa. #token NUM_INT1B "([0-9])+\.{[eE]{[\+\-]}([0-9])+}{[fFdD]}" <<;>> class JParser { << ParseStore* ps; ParseUtility* pu; void tracein(const char *rulename) { pu->tracein(rulename,guessing,LT(1)); } void traceout(const char *rulename) { pu->traceout(rulename,guessing,LT(1)); } void syn( _ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k) { pu->syn(tok,egroup,eset,etok,k); } string typeCombine(const string& modifiers, const string& name, const string& indir) { string retval; if(modifiers.size()>0) { retval=modifiers+" "+name; } else { retval=name; } if(indir.size()>0) { retval+=" "; retval+=indir; } return retval; } // we have a data member for the language of the parse so // that we can supply the names of dialects (ansi_c, ansi_c++, mfc_c++ etc) // for contexts where we wish to apply dialect-specific parsing // rules string parse_language; // Many of the rules below accept string parameters to // allow upward passing of attributes. // Where the calling context does not need to receive // the attributes, it can use the dummy values defined // here to save allocating a string locally to satisfy the // parameter list. string d1,d2,d3; bool db; public: void init(const string& filename, const string& language) { pu=ParseUtility::currentInstance(); ps=ParseStore::currentInstance(); ANTLRParser::init(); parse_language=language; } >> // Compilation Unit: In Java, this is a single file. This is the start // rule for this parser compilationUnit : << // We want to keep track of the scope we are operating in string scope; >> // A compilation unit starts with an optional package definition ( packageDefinition[scope] | /* nothing */ ) // Next we have a series of zero or more import statements ( importDefinition )* // Wrapping things up with any number of class or interface // definitions ( typeDefinition[scope] )* eof:Eof << ps->record_other_extent(1,$eof->getLine(),""); >> ; // Package statement: "package" followed by an identifier. packageDefinition[string& scope] : PACKAGE identifier2[scope] SEMI ; // Import statement: import followed by a package or class name importDefinition : IMPORT identifierStar SEMI ; // A type definition in a file is either a class or interface definition. typeDefinition[string& parentScope] : << Visibility v; >> m:modifiers[v] ( classDefinition[parentScope] | interfaceDefinition[parentScope] ) | SEMI ; /** A declaration is the creation of a reference or primitive-type variable * Create a separate Type/Var tree for each var in the var list. */ declaration : << Visibility v=vDONTKNOW; int startLine=LT(1)->getLine(); >> modifiers[v] typeSpec variableDefinitions[d1,d2,db,v,startLine] ; // A list of zero or more modifiers. We could have used (modifier)* in // place of a call to modifiers, but I thought it was a good idea to keep // this rule separate so they can easily be collected in a Vector if // someone so desires modifiers[Visibility& v] : ( modifier[v] )* ; // A type specification is a type name with possible brackets afterwards // (which would make it an array type). typeSpec : classTypeSpec | builtInTypeSpec ; // A class type specification is a class type with possible brackets afterwards // (which would make it an array type). classTypeSpec : identifier (lb:LBRACK RBRACK)* ; // A builtin type specification is a builtin type with possible brackets // afterwards (which would make it an array type). builtInTypeSpec : builtInType (lb:LBRACK RBRACK)* ; // A type name. which is either a (possibly qualified) class name or // a primitive (builtin) type type : identifier | builtInType ; // The primitive types. builtInType : KW_VOID | KW_BOOLEAN | KW_BYTE | KW_CHAR | KW_SHORT | KW_INT | KW_FLOAT | KW_LONG | KW_DOUBLE ; // A (possibly-qualified) java identifier. We start with the first IDENT // and expand its name by adding dots and following IDENTS identifier : IDENT ( DOT IDENT )* ; // We replicate typeSpec, classTypeSpec, builtIntTypeSpec and identifier // with variants which receive and set a reference to a string // describing the builtin type. typeSpec also has a boolean indicating // whether the described type is built in or not. typeSpec2[string& typeString, bool& isBuiltIn] : classTypeSpec2[typeString] << isBuiltIn=false; >> | builtInTypeSpec2[typeString] << isBuiltIn=true; >> ; classTypeSpec2[string& typeString] : identifier2[typeString] (lb:LBRACK RBRACK << typeString.append("[]"); >> )* ; builtInTypeSpec2[string& typeString] : << ANTLRTokenPtr typeToken=LT(1); >> builtInType << typeString=typeToken->getText(); >> (LBRACK RBRACK << typeString.append("[]"); >> )* ; identifier2[string& scope] : id1:IDENT << scope=pu->scopeCombine(scope,$id1->getText()); >> ( DOT id2:IDENT << scope=pu->scopeCombine(scope,$id2->getText()); >> )* ; identifierStar : (IDENT (DOT IDENT)* DOT STAR)? | IDENT (DOT IDENT)* ; // modifiers for Java classes, interfaces, class/instance vars and methods modifier[Visibility& v] : PRIVATE << v=vPRIVATE; >> | PUBLIC << v=vPUBLIC; >> | PROTECTED << v=vPROTECTED; >> | STATIC | TRANSIENT | FINAL | ABSTRACT | NATIVE | THREADSAFE | SYNCHRONIZED // | KW_CONST // reserved word; leave out | VOLATILE ; // Definition of a Java class classDefinition[string& parentScope] : << int startLine=LT(1)->getLine(); string className; >> // the name of the class "class" id:IDENT << className=$id->getText(); >> // it _might_ have a superclass... sc:superClassClause[className] // it might implement some interfaces... ic:implementsClause[className] // now parse the body of the class cb:classBlock[className] << int endLine=LT(1)->getLine(); ps->record_module_extent(startLine,endLine,className,"class", "definition",utDEFINITION); >> ; superClassClause[const string& className] : << int startLine=LT(1)->getLine(); string parentName; >> { EXTENDS identifier2[parentName] << ps->record_userel_extent( startLine,startLine, className,"",parentName,"extends", // no private inheritance in Java vPUBLIC, utINHERITS); >> } ; // Definition of a Java Interface interfaceDefinition[const string& parentScope] : << string interfaceName; >> INTERFACE id:IDENT << interfaceName=$id->getText(); >> // it might extend some other interfaces ie:interfaceExtends[interfaceName] // now parse the body of the interface (looks like a class...) cb:classBlock[interfaceName] ; // This is the body of a class. You can have fields and extra semicolons, // That's about it (until you see what a field is...) classBlock[const string& className] : LCURLY ( field[className] | SEMI )* RCURLY ; // An interface can extend several other interfaces... interfaceExtends[const string& className] : << int startLine=LT(1)->getLine(); string parentName; >> { EXTENDS identifier2[parentName] moreSuperclassNames[className,"extends"] << ps->record_userel_extent( startLine,startLine, className,"",parentName,"extends", // no private inheritance in Java vPUBLIC, utINHERITS); >> } ; // A class can implement several interfaces... implementsClause[const std::string& className] : << int startLine=LT(1)->getLine(); string parentName; >> { IMPLEMENTS identifier2[parentName] moreSuperclassNames[className,"implements"] } << ps->record_userel_extent( startLine,startLine, className,"",parentName,"implements", // no private inheritance in Java vPUBLIC, utINHERITS); >> ; moreSuperclassNames[const string& className, const string& inheritType] : << int startLine=LT(1)->getLine(); string parentName; >> ( COMMA identifier2[parentName] << ps->record_userel_extent( startLine,startLine, className,"",parentName,inheritType, // no private inheritance in Java vPUBLIC, utINHERITS); >> )* ; // Now the various things that can be defined inside a class or interface... // Note that not all of these are really valid in an interface (constructors, // for example), and if this grammar were used for a compiler there would // need to be some semantic checks to make sure we're doing the right thing... field[const string& className] : << string scope=className, typeName; bool isBuiltIn; Visibility v=vDONTKNOW; int startLine=LT(1)->getLine(); >> // method, constructor, or variable declaration mods:modifiers[v] ( // constructor ctorDefinition[className,v] | cd:classDefinition[scope] // inner class | id:interfaceDefinition[scope] // inner interface // method or variable declaration(s) | t:typeSpec2[typeName,isBuiltIn] typedDeclaration[className,typeName,isBuiltIn,v,startLine] ) // "static { ... }" class initializer | STATIC s3:compoundStatement // "{ ... }" instance initializer | compoundStatement ; typedDeclaration [const string& className,const string& typeName, bool isBuiltIn, Visibility v, int startLine] : methodDefinition[className,typeName,isBuiltIn,v,startLine] | variableDefinitions[className,typeName,isBuiltIn,v,startLine] SEMI ; // The next rule covers that part of a method definition which // occurs after the return type is recognized. // The return type is recognized separately as a left-factoring // because it can equally well be the type of a variable definition. methodDefinition [const string& className, const string& returnType, bool rtIsBuiltIn, Visibility v, int startLine] : << string paramList; bool isDefinition=false; >> // the name of the method id:IDENT // parse the formal parameter declarations. LPAREN param:parameterDeclarationList[paramList,className,v] RPAREN rt:returnTypeBrackersOnEndOfMethodHead // get the list of exceptions that this method is declared to throw { tc:throwsClause } ( s2:compoundStatement << isDefinition=true; >> | SEMI ) << int endLine=LT(1)->getLine(); string methodName=$id->getText(); if(isDefinition==false) { ps->record_function_extent(startLine,endLine, returnType,className, methodName,paramList, "declaration",v, utDECLARATION); } else { ps->record_function_extent(startLine,endLine, returnType,className, methodName,paramList, "definition",v, utDEFINITION); } // the return value is effectively an anonymous // parameter... if(rtIsBuiltIn==false) { // In Java, all parameter passing are effectively by // reference (I think). ps->record_userel_extent(startLine,startLine, className,"",returnType, "return type",v,utPARBYREF); } >> ; variableDefinitions [const string& className, const string& returnType, bool rtIsBuiltIn, Visibility v, int startLine] : variableDeclarator ( COMMA variableDeclarator )* << if(rtIsBuiltIn==false) { // In Java, all containment relationships are effectively by // reference (I think). ps->record_userel_extent(startLine,startLine, className,"",returnType, "member variable",v,utHASBYREF); } >> ; /** Declaration of a variable. This can be a class/instance variable, * or a local variable in a method * It can also include possible initialization. */ variableDeclarator : id:IDENT d:declaratorBrackets v:varInitializer ; declaratorBrackets : (lb:LBRACK RBRACK)* ; varInitializer : { ASSIGN initializer } ; // This is an initializer used to set up an array. arrayInitializer : lc:LCURLY { initializer ( // CONFLICT: does a COMMA after an initializer start a new // initializer or start the option ',' at end? // ANTLR generates proper code by matching // the comma as soon as possible. COMMA initializer )* {COMMA} } RCURLY ; // The two "things" that can initialize an array element are an expression // and another (nested) array initializer. initializer : expression | arrayInitializer ; // This is the header of a method. It includes the name and parameters // for the method. // This also watches for a list of exception classes in a "throws" clause. ctorDefinition[const string& className, Visibility v] : << // The following assertion seemed like a good idea // at the time, but it fails for nested classes. // assert(className==LT(1)->getText()); int startLine=LT(1)->getLine(); string paramList; >> // constructors are the only methods allowed to occur without // return types, and they must have definitions. This makes // life fairly easy ctorHead[paramList,className,v] compoundStatement << int endLine=LT(1)->getLine(); ps->record_function_extent(startLine,endLine, "",className,className,paramList, "definition",v,utDEFINITION); >> ; ctorHead[string& paramList,const string& className, Visibility v] : IDENT // the name of the method // parse the formal parameter declarations. LPAREN parameterDeclarationList[paramList,className,v] RPAREN // get the list of exceptions that this method is declared to throw { throwsClause } ; // This is a list of exception classes that the method is declared to throw throwsClause : THROWS identifier ( COMMA identifier )* ; returnTypeBrackersOnEndOfMethodHead : (LBRACK RBRACK)* ; // A list of formal parameters parameterDeclarationList [ // a string in which we accumulate a string of all parameters string& paramList, // the name of the owner class for the method const string& clientName, // visibility of the method const Visibility& v ] : << string paramItem; >> << paramList+="("; >> { parameterDeclaration[paramList,clientName,v,true] ( COMMA << paramList+=","; >> parameterDeclaration[paramList,clientName,v,true] )* } << paramList+=")"; >> ; // A formal parameter. parameterDeclaration [ // a string in which we accumulate a string of all parameters string& paramList, // the name of the owner class for the method const string& clientName, // visibility of the method const Visibility& v, // is this rule being used from a parameter list (in which case // we want to do record_userel_extent) or from a syntacticly similar // catch statement, which is buried in the implementation of a method // and does not interest us bool inParameterList ] : << string mod, typeName, bracks; bool isBuiltIn; int startLine=LT(1)->getLine(); >> pm:parameterModifier[mod] t:typeSpec2[typeName,isBuiltIn] id:IDENT pd:parameterDeclaratorBrackets[bracks] << if(inParameterList) { paramList+=(mod+typeName+bracks); if(isBuiltIn==false) { // In Java, all parameter passing is effectively by // reference (I think). ps->record_userel_extent(startLine,startLine, clientName,"",typeName, "normal parameter",v,utPARBYREF); } } >> ; parameterDeclaratorBrackets[string& bracks] : (LBRACK RBRACK << bracks+="[]"; >> )* ; parameterModifier[string& paramList] : { f:FINAL << paramList+=$f->getText(); >> } ; // Compound statement. This is used in many contexts: // Inside a class definition prefixed with "static": // it is a class initializer // Inside a class definition without "static": // it is an instance initializer // As the body of a method // As a completely indepdent braced block of code inside a method // it starts a new scope for variable definitions compoundStatement : LCURLY // include the (possibly-empty) list of statements (statement)* RCURLY ; statement // A list of statements in curly braces -- start a new scope! : << string scope; >> ifStatement | forStatement | whileStatement | doWhileStatement | breakStatement | continueStatement | returnStatement | switchStatement | throwStatement | tryBlock | syncStatement | emptyStatement | compoundStatement // class definition | classDefinition[scope] // final class definition | FINAL classDefinition[scope] // abstract class definition | ABSTRACT classDefinition[scope] // declarations are ambiguous with "ID DOT" relative to expression // statements. Must backtrack to be sure. Could use a semantic // predicate to test symbol table to see what the type was coming // up, but that's pretty hard without a symbol table ;) | (declaration)? declaration SEMI // An expression statement. This could be a method call, // assignment statement, or any other expression evaluated for // side-effects. | expression SEMI // Attach a label to the front of a statement | IDENT c:COLON statement ; // If-else statement ifStatement : IF LPAREN expression RPAREN statement optElseClause ; // For statement forStatement : FOR LPAREN forInit SEMI // initializer forCond SEMI // condition test forIter // updater RPAREN statement // statement to loop over ; // While statement whileStatement : WHILE LPAREN expression RPAREN statement ; // do-while statement doWhileStatement : DO statement "while" LPAREN expression RPAREN SEMI ; // get out of a loop (or switch) breakStatement : BREAK { IDENT } SEMI ; // do next iteration of a loop continueStatement : CONTINUE { IDENT } SEMI ; // Return an expression returnStatement : RETURN { expression } SEMI ; // switch/case statement switchStatement : SWITCH LPAREN expression RPAREN LCURLY ( casesGroup )* RCURLY ; // throw an exception throwStatement : THROW expression SEMI ; // synchronize a statement syncStatement : SYNCHRONIZED LPAREN expression RPAREN compoundStatement ; // empty statement emptyStatement : SEMI ; optElseClause : (ELSE)? ELSE statement | /* empty */ ; casesGroup : cases caseSList ; cases : aCase optMoreCases ; optMoreCases : (CASE | DEFAULT)? aCase optMoreCases | /* empty */ ; aCase : DEFAULT COLON | CASE expression COLON ; caseSList : (statement)* ; // The initializer for a for loop forInit // if it looks like a declaration, it is : (declaration)? // otherwise it could be an expression list... | expressionList | // or it could be empty ; forCond : { expression } ; forIter : { expressionList } ; // an exception handler try/catch block tryBlock : TRY compoundStatement (handler)* { FINALLY compoundStatement } ; // an exception handler handler : << Visibility dv; >> CATCH LPAREN parameterDeclaration[d1,d2,dv,false] RPAREN compoundStatement ; // expressions // Note that most of these expressions follow the pattern // thisLevelExpression : // nextHigherPrecedenceExpression // (OPERATOR nextHigherPrecedenceExpression)* // which is a standard recursive definition for a parsing an expression. // The operators in java have the following precedences: // lowest (13) = *= /= %= += -= <<= >>= >>>= &= ^= |= // (12) ?: // (11) || // (10) && // ( 9) | // ( 8) ^ // ( 7) & // ( 6) == != // ( 5) < <= > >= // ( 4) << >> // ( 3) +(binary) -(binary) // ( 2) * / % // ( 1) ++ -- +(unary) -(unary) ~ ! (type) // [] () (method call) . (dot -- identifier qualification) // new () (explicit parenthesis) // // the last two are not usually on a precedence chart; I put them in // to point out that new has a higher precedence than '.', so you // can validy use // new Frame().show() // // Note that the above precedence levels map to the rules below... // Once you have a precedence chart, writing the appropriate rules as below // is usually very straightfoward // the mother of all expressions expression : assignmentExpression ; // This is a list of expressions. expressionList : expression (COMMA expression)* ; // assignment expression (level 13) assignmentExpression : conditionalExpression { ( ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | SR_ASSIGN | BSR_ASSIGN | SL_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN ) assignmentExpression } ; // conditional test (level 12) conditionalExpression : logicalOrExpression { QUESTION conditionalExpression COLON conditionalExpression } ; // logical or (||) (level 11) logicalOrExpression : logicalAndExpression (LOR logicalAndExpression)* ; // logical and (&&) (level 10) logicalAndExpression : inclusiveOrExpression (LAND inclusiveOrExpression)* ; // bitwise or non-short-circuiting or (|) (level 9) inclusiveOrExpression : exclusiveOrExpression (BOR exclusiveOrExpression)* ; // exclusive or (^) (level 8) exclusiveOrExpression : andExpression (BXOR andExpression)* ; // bitwise or non-short-circuiting and (&) (level 7) andExpression : equalityExpression (BAND equalityExpression)* ; // equality/inequality (==/!=) (level 6) equalityExpression : relationalExpression relationalPredicate ; relationalPredicate : INSTANCEOF typeSpec | ((NOT_EQUAL | EQUAL) relationalExpression)* ; // boolean relational expressions (level 5) relationalExpression : shiftExpression ( ( LESSTHAN | GT | LE | GE ) shiftExpression )* ; // bit shift expressions (level 4) shiftExpression : additiveExpression ((SL | SR | BSR) additiveExpression)* ; // binary addition/subtraction (level 3) additiveExpression : multiplicativeExpression ((PLUS | MINUS) multiplicativeExpression)* ; // multiplication/division/modulo (level 2) multiplicativeExpression : unaryExpression ((STAR | DIV | MOD ) unaryExpression)* ; unaryExpression : INC unaryExpression | DEC unaryExpression | MINUS unaryExpression | PLUS unaryExpression | unaryExpressionNotPlusMinus ; unaryExpressionNotPlusMinus : BNOT unaryExpression | LNOT unaryExpression // If typecast is built in type, must be numeric operand // Also, no reason to backtrack if type keyword like int, float... | (LPAREN builtInTypeSpec RPAREN unaryExpression)? // Have to backtrack to see if operator follows. If no operator // follows, it's a typecast. No semantic checking needed to parse. // if it _looks_ like a cast, it _is_ a cast; else it's a "(expr)" | (LPAREN classTypeSpec RPAREN unaryExpressionNotPlusMinus)? | postfixExpression ; // qualified names, array expressions, method invocation, post inc/dec postfixExpression : primaryExpression // start with a primary ( // qualified id (id.id.id.id...) -- build the name DOT ( IDENT | KW_THIS | CLASS | newExpression | SUPER LPAREN { expressionList } RPAREN ) // the above line needs a semantic check to make sure "class" // is the _last_ qualifier. // allow ClassName[].class | ( LBRACK RBRACK )+ DOT CLASS // an array indexing operation | LBRACK expression RBRACK // method invocation // The next line is not strictly proper; it allows x(3)(4) or // x[2](4) which are not valid in Java. If this grammar were used // to validate a Java program a semantic check would be needed, or // this rule would get really ugly... | LPAREN argList RPAREN )* // possibly add on a post-increment or post-decrement. // allows INC/DEC on too much, but semantics can check ( INC | DEC | // nothing ) // look for int.class and int[].class | builtInType ( LBRACK RBRACK )* DOT CLASS ; // the basic element of an expression primaryExpression : IDENT | newExpression | constant | SUPER | BTRUE | BFALSE | KW_THIS | PNULL | LPAREN assignmentExpression RPAREN ; /** object instantiation. * Trees are built as illustrated by the following input/tree pairs: * * new T() * * new * | * T -- ELIST * | * arg1 -- arg2 -- .. -- argn * * new int[] * * new * | * int -- ARRAY_DECLARATOR * * new int[] {1,2} * * new * | * int -- ARRAY_DECLARATOR -- ARRAY_INIT * | * EXPR -- EXPR * | | * 1 2 * * new int[3] * new * | * int -- ARRAY_DECLARATOR * | * EXPR * | * 3 * * new int[1][2] * * new * | * int -- ARRAY_DECLARATOR * | * ARRAY_DECLARATOR -- EXPR * | | * EXPR 1 * | * 2 * */ newExpression : "new" type ( LPAREN argList RPAREN {classBlock[d1]} //java 1.1 // Note: This will allow bad constructs like // new int[4][][3] {exp,exp}. // There needs to be a semantic check here... // to make sure: // a) [ expr ] and [ ] are not mixed // b) [ expr ] and an init are not used together | newArrayDeclarator {arrayInitializer} ) ; argList : ( expressionList | /*nothing*/ ) ; newArrayDeclarator // CONFLICT: // newExpression is a primaryExpression which can be // followed by an array index reference. This is ok, // as the generated code will stay in this loop as // long as it sees an LBRACK (proper behavior) : (LBRACK { expression } RBRACK LBRACK)? LBRACK { expression } RBRACK newArrayDeclarator | LBRACK { expression } RBRACK ; constant : NUM_INT1 | NUM_INT1A | NUM_INT1B | NUM_INT2 | NUM_INT3 | NUM_INT4 | CHARCONST | STRINGCONST | NUM_FLOAT ; } cccc-3.1.4/cccc/posixgcc.mak0000644000000000000000000000173407716074420014330 0ustar rootroot# posixgcc.mak ## GNUMakefile to build the CCCC project on the POSIX compliant ## platforms using the GNU C Compiler. ## Tested with: ## GCC 2.95.3 on Mandrake Linux v7.2 (reported by Tim Littlefair) ## EGCS 2.91.66 (aka kgcc) on Mandrake Linux v7.2 (reported by Tim Littlefair) ## GCC 2.96 on Red Hat 7.2 (reported by Tim Littlefair) ## GCC 3.2 on Mandrake Linux 9.0 (reported by Tim Littlefair) ## The '-static' link argument was removed as a result of problems ## encountered on GCC 3.2 - as we don't prebuild binaries at present ## dynamic linking shouldn't be a killer problem. ## (More reports welcome) ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging ifeq "$(DEBUG)" "true" CFLAGS_DEBUG=-g LDFLAGS_DEBUG=-g endif PATHSEP=/ CCC=g++ LD=g++ CFLAGS=-c -I../pccts/h $(CFLAGS_DEBUG) -x c++ C_OFLAG=-o LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-o OBJEXT=o CCCC_EXE=cccc COPY=cp RM=rm include rules.mak cccc-3.1.4/cccc/rules.mak0000644000000000000000000001662407715607253013654 0ustar rootroot## rules.mak ## ## This file defines a set of rules for building CCCC from source ## on any platform, given a set of predefined make variables ## which configure the compilation commands, flags etc on a given ## platform. ## ## I have attempted to put all the elements of the build which can ## be made consistent across platforms into this script, with ## separate prefixes for each platform to contain the points ## of difference. ## ## One of the points of difference supported is the difference ## in preprocessor syntax between Microsoft NMAKE.EXE and other ## makes including GNU Make. The way I have dealt with this ## is to exclude use of preprocessor features from this file ## while using them freely in the platform-specific files. ## ## The following make variables must be defined before entering this ## file: ## ## PATHSEP= ## CCC= ## CFLAGS= ## C_OFLAG= ## LD= ## LDFLAGS= ## LD_OFLAG= ## OBJEXT= ## CCCC_EXE= # PCCTS is now packaged as part of the CCCC distribution. PCCTS=..$(PATHSEP)pccts PCCTS_H=$(PCCTS)$(PATHSEP)h PCCTS_BIN=$(PCCTS)$(PATHSEP)bin # PCCTS_OBJDIR needs to be defined in the platform-specific makefile # as some compilers put the obj file in $(PCCTS_H), others put it # in the current directory. # locations and flags for antlr and dlg (don't change the flags unless you # understand PCCTS) ANTLR = $(PCCTS_BIN)$(PATHSEP)antlr DLG = $(PCCTS_BIN)$(PATHSEP)dlg # Flags for ANTLR: # -CC = generate C++ output # -k 2 = use at least 2 tokens of lookahead # -gd = generate rule tracing code (calls to tracein() and traceout()) # -ge = generate token classes to represent the initial set for # each rule (called error sets, because their main use is # in simplifying error reporting when a rule fails). # -rl 5000 = a limit on the size of the internal analysis network # used by the parser generator # -w1 = basic error reporting # The -gl flag is an option. This causes ANTLR to emit #line directives # which allow the compiler to generate line numbers relating to # positions in the .g file instead of the generated cpp files. # These can be useful to an IDE (jumping to error lines, e.g. in # emacs), or in the debugger. # At one time this option was broken to the extent that the code emitted # was actually illegal under some circumstances, but it is better now. # The problem is that there are still a lot of lines in the generated # source which do not correspond with lines in the .g file. On balance, # if I am debugging it is better to leave -gl off, while for onward # development it is better to turn it on and enable the IDE features. AFLAGS = -CC -k 2 -gd -ge -rl 5000 -w1 -e3 #AFLAGS = -CC -k 2 -gd -ge -rl 5000 -w1 -e3 # Flags for DLG DFLAGS = -C2 -CC ## list of files generated by the PCCTS utilities CCCC_SPAWN = cccc.cpp CParser.cpp CParser.h \ Ctokens.h CLexer.cpp CLexer.h JAVA_SPAWN = java.cpp JParser.cpp JParser.h \ Jtokens.h JLexer.cpp JLexer.h ADA_SPAWN = ada.cpp AdaPrser.cpp AdaPrser.h \ Atokens.h ALexer.cpp ALexer.h ## the source files of the project itself USR_G = cccc.g java.g ada.g USR_C = ccccmain.cc cccc_tok.cc cccc_met.cc cccc_utl.cc \ cccc_db.cc cccc_rec.cc cccc_ext.cc cccc_prj.cc cccc_mod.cc \ cccc_mem.cc cccc_use.cc cccc_htm.cc cccc_xml.cc cccc_tbl.cc \ cccc_tpl.cc cccc_new.cc cccc_itm.cc cccc_opt.cc USR_H = cccc.h cccc_tok.h cccc_met.h cccc_utl.h \ cccc_db.h cccc_htm.h cccc_tbl.h cccc_itm.h \ cccc_opt.h ## documentation USR_DOC = readme.txt cccc_ug.htm ## all source files USR_SOURCE = makefile cccc.mak cccc.dsw \ $(USR_G) $(USR_H) $(USR_C) $(USR_DAT) $(USR_DOC) ## the final executable is linked from 3 groups of object files: # object files compiled from PCCTS support code which does not change PCCTS_OBJ = \ AParser.$(OBJEXT) \ DLexerBase.$(OBJEXT) \ ATokenBuffer.$(OBJEXT) # object files compiled from C++ files generated by anltr and dlg # They are now separated so that each language can be included or # excluded by using make variables defined above. CCCC_SPAWN_OBJ=cccc.$(OBJEXT) CLexer.$(OBJEXT) CParser.$(OBJEXT) CC_LANG_DEFINE=-DCC_INCLUDED JAVA_SPAWN_OBJ=java.$(OBJEXT) JLexer.$(OBJEXT) JParser.$(OBJEXT) JAVA_LANG_DEFINE=-DJAVA_INCLUDED SPAWN_OBJ = $(CCCC_SPAWN_OBJ) $(JAVA_SPAWN_OBJ) $(ADA_SPAWN_OBJ) LANG_DEFINES = $(CC_LANG_DEFINE) $(JAVA_LANG_DEFINE) $(ADA_LANG_DEFINE) # object files compiled from .cc files which are part of the cccc source USR_OBJ = \ ccccmain.$(OBJEXT) cccc_utl.$(OBJEXT) cccc_opt.$(OBJEXT) \ cccc_db.$(OBJEXT) cccc_rec.$(OBJEXT) cccc_ext.$(OBJEXT) \ cccc_prj.$(OBJEXT) cccc_mod.$(OBJEXT) cccc_mem.$(OBJEXT) \ cccc_use.$(OBJEXT) cccc_met.$(OBJEXT) cccc_htm.$(OBJEXT) cccc_xml.$(OBJEXT) \ cccc_tok.$(OBJEXT) cccc_tbl.$(OBJEXT) \ cccc_tpl.$(OBJEXT) cccc_new.$(OBJEXT) cccc_itm.$(OBJEXT) \ ALL_OBJ = $(SPAWN_OBJ) $(USR_OBJ) $(PCCTS_OBJ) all: $(CCCC_EXE) $(CCCC_EXE): $(USR_G) $(ANLTR_SPAWN) $(DLG_SPAWN) $(USR_H) $(USR_C) $(ALL_OBJ) $(LD) $(ALL_OBJ) $(LD_EXTRA_LIBS) $(LDFLAGS) $(LD_OFLAG)$(CCCC_EXE) .SUFFIXES: .cc .$(OBJEXT) .cpp .cxx .g .g_info ## ANTLR can give us some very useful documentation including a ## cross reference of the rules and a list of first token sets ## for each rule .g.g_info: $(ANTLR) $(AFLAGS) -gc -gx -pa $< > $*.1st $(ANTLR) $(AFLAGS) -gc -gx -cr $< > $*.xrf ccccmain.$(OBJEXT) : ccccmain.cc $(CCC) $(CFLAGS) $(LANG_DEFINES) ccccmain.cc .cc.$(OBJEXT): $(CCC) $(CFLAGS) $< $(C_OFLAG)$*.$(OBJEXT) .cpp.$(OBJEXT): $(CCC) $(CFLAGS) $< $(C_OFLAG)$*.$(OBJEXT) .cxx.$(OBJEXT): $(CCC) -c $(CFLAGS) $< $(C_OFLAG)$*.$(OBJEXT) # Different compilers handle the source file being in a # different directory in different ways. The easiest way # to cover this is to add explicit rules for the three # PCCTS support files which give rise to linkable object # files. AParser.$(OBJEXT): $(PCCTS_H)$(PATHSEP)AParser.cpp $(CCC) $(CFLAGS) $(PCCTS_H)$(PATHSEP)AParser.cpp $(C_OFLAG)$*.$(OBJEXT) DLexerBase.$(OBJEXT): $(PCCTS_H)$(PATHSEP)DLexerBase.cpp $(CCC) $(CFLAGS) $(PCCTS_H)$(PATHSEP)DLexerBase.cpp $(C_OFLAG)$*.$(OBJEXT) ATokenBuffer.$(OBJEXT): $(PCCTS_H)$(PATHSEP)ATokenBuffer.cpp $(CCC) $(CFLAGS) $(PCCTS_H)$(PATHSEP)ATokenBuffer.cpp $(C_OFLAG)$*.$(OBJEXT) $(CCCC_SPAWN) : cccc.g $(ANTLR) $(AFLAGS) -ft Ctokens.h cccc.g $(DLG) $(DFLAGS) -cl CLexer parser.dlg $(JAVA_SPAWN) : java.g $(ANTLR) $(AFLAGS) -ft Jtokens.h java.g $(DLG) $(DFLAGS) -cl JLexer parser.dlg ## -ci argument to DLG is because unlike C\C++\Java, Ada is defined as being ## case insensitive ## NB CCCC does not map case: if the code processed is not consistent in ## capitalisation of the name of a package, the reports will treat it as ## two different packages $(ADA_SPAWN) : ada.g $(ANTLR) $(AFLAGS) -ft Atokens.h ada.g $(DLG) $(DFLAGS) -ci -cl ALexer parser.dlg # touch enables us to mark everything up to date to avoid enormous # recompilations (particularly after checking everything in and out of RCS) touch: touch cccc.g touch *.cpp touch *.cxx touch *.cc touch *.h touch *.$(OBJEXT) touch cccc clean: -$(RM) *.cpp -$(RM) *.$(OBJEXT) -$(RM) $(CCCC_EXE) cccc-3.1.4/cccc/w32bcb.mak0000644000000000000000000000132607343212235013562 0ustar rootroot# w32bcc55.mak ## Makefile to build the CCCC project on the Borland C++ Command Line ## Compiler. ## (tested with a free copy which was shipped on a magazine CD, May 2001) ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" CFLAGS_DEBUG=-v LDFLAGS_DEBUG=-v !ENDIF PATHSEP=\\ CCC=bcc32.exe LD=bcc32.exe -L"$(BCDIR)\lib" CFLAGS= -c -P -D_NO_VCL -DCCCC_CONF_W32BC-I$(PCCTS_H) CFLAGS+= -w-aus -w-par -w-hid -w-inl CFLAGS+= -I"$(BCDIR)\include" -tWC $(CFLAGS_DEBUG) C_OFLAG=-o LDFLAGS=$(LDFLAGS_DEBUG) -ap -v LD_OFLAG=-o OBJEXT=obj CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/cccc/w32bcc.mak0000644000000000000000000000170407345451256013575 0ustar rootroot# w32bcc55.mak ## Makefile to build the CCCC project on the Borland C++ Command Line ## Compiler. ## (tested with a free copy which was shipped on a magazine CD, May 2001) ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" # It would be nice to turn the CodeGuard feature on but this # appears to depend on a library called CG32.lib which doesn't # appear to be present in my free command line version. CFLAGS_DEBUG=-v LDFLAGS_DEBUG=-v !ENDIF PATHSEP=\\ CCC=bcc32.exe #LD=ilink32.exe -L"$(BCDIR)\lib" C0D32.OBJ CW32.LIB IMPORT32.LIB LD=bcc32.exe -v -L"$(BCDIR)\lib" CFLAGS= \ $(CFLAGS_DEBUG) -c -P -D_NO_VCL -DCCCC_CONF_W32BC -I$(PCCTS_H) \ -w-aus -w-par -w-hid -w-inl \ -I"$(BCDIR)\include" -tWC C_OFLAG=-o LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-o OBJEXT=obj CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/cccc/w32bcc55.mak0000644000000000000000000000142107345451256013743 0ustar rootroot# w32bcc55.mak ## Makefile to build the CCCC project on the Borland C++ Command Line ## Compiler. ## (tested with a free copy which was shipped on a magazine CD, May 2001) ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" CFLAGS_DEBUG=-v -y LDFLAGS_DEBUG=-v !ENDIF PATHSEP=\\ CCC=bcc32.exe -v #LD=ilink32.exe -L"$(BCDIR)\lib" C0D32.OBJ CW32.LIB IMPORT32.LIB LD=bcc32.exe -v -L"$(BCDIR)\lib" CFLAGS= \ -c -P -D_NO_VCL -DCCCC_CONF_W32BC -I$(PCCTS_H) \ -w-aus -w-par -w-hid -w-inl \ -I"$(BCDIR)\include" -tWC $(CFLAGS_DEBUG) C_OFLAG=-o LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-o OBJEXT=obj CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/cccc/w32cygnus.mak0000644000000000000000000000105507267050221014343 0ustar rootroot# w32cygnus_nmake.mak ## NMakefile to build the CCCC project on the Win32/CygWinB20 platform. ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" CFLAGS_DEBUG=-g LDFLAGS_DEBUG=-g !ENDIF PATHSEP=\\ CCC=cl.exe -nologo LD=cl.exe -nologo CFLAGS=-c -I$(PCCTS_H) $(CFLAGS_DEBUG) -GX -TP -DCCCC_CONF_W32VC C_OFLAG=-Fo LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-Fe OBJEXT=obj CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/cccc/w32cygnus_gmake.mak0000644000000000000000000000134307343212235015507 0ustar rootroot# w32cygnus_gmake.mak ## GNUMakefile to build the CCCC project on the Win32/CygWinB20 platform. ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging #if "$(DEBUG)"=="true" #CFLAGS_DEBUG=-g #LDFLAGS_DEBUG=-g #endif PATHSEP=/ CYGWIN=/cygnus/cygwin-b20/H-i586-cygwin32 EGCS=$(CYGWIN)/lib/gcc-lib/i586-cygwin32/egcs-2.91.57 PATH=$(CYGWIN)/bin;$(EGCS) export PATH CCC=/usr/bin/g++ LD=/usr/bin/g++ CFLAGS=-c -I../pccts/h -I$(CYGWIN)/../include/g++ -I$(CYGWIN)/i586-cygwin32/include -I$(EGCS)/include $(CFLAGS_DEBUG) -x c++ -DCCCC_CONF_W32VC C_OFLAG=-o LDFLAGS=-L$(EGCS)/../lib $(LDFLAGS_DEBUG) LD_OFLAG=-o OBJEXT=o CCCC_EXE=cccc.exe COPY=copy RM=del include rules.mak cccc-3.1.4/cccc/w32cygnus_nmake.mak0000644000000000000000000000107307343212235015516 0ustar rootroot# w32cygnus_nmake.mak ## NMakefile to build the CCCC project on the Win32/CygWinB20 platform. ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" CFLAGS_DEBUG=-g LDFLAGS_DEBUG=-g !ENDIF PATHSEP=\\ PATH=\cygwin\bin CCC=$(PATH)\gcc.exe LD=$(PATH)\gcc.exe CFLAGS=-c -I$(PCCTS_H) $(CFLAGS_DEBUG) -x c++ -DCCCC_CONF_W32VC C_OFLAG=-o LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-o OBJEXT=o CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/cccc/w32vc.mak0000644000000000000000000000105007272040214013433 0ustar rootroot# w32vc.mak ## Makefile to build the CCCC project on the Win32/Visual Studio platform. ## See rules.mak for discussion of the meaning of the make variables ## which this file defines # support for debugging (note that debug building is on by default) !IF "$(DEBUG)"=="true" CFLAGS_DEBUG=-Zi LDFLAGS_DEBUG=-Zi !ENDIF PATHSEP=\\ CCC=cl.exe -nologo LD=cl.exe -nologo CFLAGS=-c -I$(PCCTS_H) $(CFLAGS_DEBUG) -GX -TP -DCCCC_CONF_W32VC C_OFLAG=-Fo LDFLAGS=$(LDFLAGS_DEBUG) LD_OFLAG=-Fe OBJEXT=obj CCCC_EXE=cccc.exe COPY=copy RM=del !INCLUDE rules.mak cccc-3.1.4/install/0000755000000000000000000000000010357462302012560 5ustar rootrootcccc-3.1.4/install/install.dsp0000644000000000000000000000452507267567717014772 0ustar rootroot# Microsoft Developer Studio Project File - Name="install" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) External Target" 0x0106 CFG=install - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "install.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "install.mak" CFG="install - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "install - Win32 Release" (based on "Win32 (x86) External Target") !MESSAGE "install - Win32 Debug" (based on "Win32 (x86) External Target") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" !IF "$(CFG)" == "install - Win32 Release" # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Cmd_Line "NMAKE /f install.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "install.exe" # PROP BASE Bsc_Name "install.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Cmd_Line "..\w32bin\gmake -f install.mak CONF=w32vc VARIANT=release" # PROP Rebuild_Opt "" # PROP Target_File "install.exe" # PROP Bsc_Name "" # PROP Target_Dir "" !ELSEIF "$(CFG)" == "install - Win32 Debug" # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Cmd_Line "NMAKE /f install.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "install.exe" # PROP BASE Bsc_Name "install.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Cmd_Line "..\w32bin\gmake -f install.mak CONF=w32vc VARIANT=debug" # PROP Rebuild_Opt "" # PROP Target_File "install.exe" # PROP Bsc_Name "" # PROP Target_Dir "" !ENDIF # Begin Target # Name "install - Win32 Release" # Name "install - Win32 Debug" !IF "$(CFG)" == "install - Win32 Release" !ELSEIF "$(CFG)" == "install - Win32 Debug" !ENDIF # Begin Source File SOURCE=.\install.mak # End Source File # End Target # End Project cccc-3.1.4/install/install.mak0000644000000000000000000000270707265351341014732 0ustar rootroot# makefile to control installation of CCCC ifeq "$(CONF)" "w32vc" CD=cd CP=../w32bin/cp RM=../w32bin/rm -f RMDIR=../w32bin/rm -rf MV=../w32bin/mv ECHO=../w32bin/echo DIFF=../w32bin/diff MKDIR=../w32bin/mkdir INSTBIN1=cccc.exe INSTBIN2=CcccDevStudioAddIn.dll INSTDIR=C:/Program\ Files/CCCC else CD=cd CP=cp RM=rm -f RMDIR=rm -rf MV=mv ECHO=echo DIFF=diff MKDIR=mkdir INSTBIN1=cccc INSTBIN2= INSTDIR=/usr/local/bin endif # The installation is pretty crude # we just go to the target directory for the machine # we are on, delete old versions, copy new versions in # There are lots of nicer things we could do on either # platform, but this is the lowest common denominator which # works consistently on both. ifeq "$(CONF)" "w32vc" all : install_cccc install_addin report_success else all : install_cccc report_success endif install_cccc : -$(MKDIR) $(INSTDIR) -$(RM) $(INSTDIR)/$(INSTBIN1) $(CP) ../cccc/$(INSTBIN1) $(INSTDIR) install_addin : -$(RM) $(INSTDIR)/$(INSTBIN2) $(CP) ../vcaddin/$(VARIANT)/$(INSTBIN2) $(INSTDIR) # There are potential error messages relating to directories which # already existed, which will be ignored, because we are being conservative # and attempting creation unconditionally (so we don't have to ship Win32 # bash and test). # So we finish the process with a message reassuring the user that all went well report_success : @$(ECHO) =========================== @$(ECHO) Installation succeeded! @$(ECHO) =========================== cccc-3.1.4/pccts/0000755000000000000000000000000010357462410012226 5ustar rootrootcccc-3.1.4/pccts/antlr/0000755000000000000000000000000010357462364013356 5ustar rootrootcccc-3.1.4/pccts/antlr/Antlr.SUP0000644000000000000000000000051407265347467015041 0ustar rootroot//SUPPRESSIONPROJ:Antlr //VERSION:5.00 //ENABLE:Yes !include Rtl.sup ignore bad_address(20,23) in file EXE:"..\h\dlgauto.h" ignore bad_address(20,20) in file EXE:"..\h\dlgauto.h" ignore resource_leak(16,0) calloc in file EXE:"D:\pccts_now\pccts\support\set\set.c" ignore resource_leak(16,0) calloc in function EXE:"DefErrSetForC1" cccc-3.1.4/pccts/antlr/AntlrMS.mak0000644000000000000000000001231007345450741015364 0ustar rootroot# PCCTS directory PCCTS_HOME=.. ANTLR_SRC=$(PCCTS_HOME)\antlr PCCTS_H=$(PCCTS_HOME)\h # Support directories SET=$(PCCTS_HOME)\support\set # Compiler stuff CC = cl CFLAGS = -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \ -D "ZZLEXBUFSIZE=65536" /D "LONGFILENAMES" /W3 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 antlr.exe: $(ANTLR_OBJS) $(SUPPORT_OBJS) $(CC) $(CFLAGS) -o antlr.exe $(ANTLR_OBJS) $(SUPPORT_OBJS) del *.obj 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 cccc-3.1.4/pccts/antlr/AntlrMSVC50.dsp0000644000000000000000000001200007267567717016013 0ustar rootroot# Microsoft Developer Studio Project File - Name="ANTLR" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=ANTLR - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "AntlrMSVC50.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "AntlrMSVC50.mak" CFG="ANTLR - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "ANTLR - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "ANTLR - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "ANTLR - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /O2 /I "." /I "..\h" /I "..\support\set" /D "__STDC__" /D "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"./Antlr.exe" # Begin Special Build Tool TargetPath=.\Antlr.exe SOURCE="$(InputPath)" PostBuild_Desc=Copying to ../bin PostBuild_Cmds=mkdir ..\bin copy $(TargetPath) ..\bin # End Special Build Tool !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /Gm /ZI /Od /I "." /I "..\h" /I "..\support\set" /D "__STDC__" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -DUSER_ZZSYN -D__STDC__ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"./Antlr.exe" /pdbtype:sept # Begin Special Build Tool TargetPath=.\Antlr.exe SOURCE="$(InputPath)" PostBuild_Desc=Copying to ../bin PostBuild_Cmds=mkdir ..\bin copy $(TargetPath) ..\bin # End Special Build Tool !ENDIF # Begin Target # Name "ANTLR - Win32 Release" # Name "ANTLR - Win32 Debug" # Begin Source File SOURCE=.\antlr.c # End Source File # Begin Source File SOURCE=.\bits.c # End Source File # Begin Source File SOURCE=.\build.c # End Source File # Begin Source File SOURCE=.\egman.c # End Source File # Begin Source File SOURCE=.\err.c !IF "$(CFG)" == "ANTLR - Win32 Release" !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" # SUBTRACT CPP /YX /Yc /Yu !ENDIF # End Source File # Begin Source File SOURCE=.\fcache.c # End Source File # Begin Source File SOURCE=.\fset.c # End Source File # Begin Source File SOURCE=.\fset2.c # End Source File # Begin Source File SOURCE=.\gen.c # End Source File # Begin Source File SOURCE=.\globals.c # End Source File # Begin Source File SOURCE=.\hash.c # End Source File # Begin Source File SOURCE=.\lex.c # End Source File # Begin Source File SOURCE=.\main.c # End Source File # Begin Source File SOURCE=.\misc.c # End Source File # Begin Source File SOURCE=.\mrhoist.c # End Source File # Begin Source File SOURCE=.\pred.c # End Source File # Begin Source File SOURCE=.\scan.c # End Source File # Begin Source File SOURCE=..\support\set\set.c # End Source File # End Target # End Project cccc-3.1.4/pccts/antlr/AntlrMSVC50.dsw0000644000000000000000000000077607265347500016023 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 5.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "ANTLR"=.\AntlrMSVC50.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/antlr/AntlrMSVC50.mak0000644000000000000000000004125707265347506016003 0ustar rootroot# Microsoft Developer Studio Generated NMAKE File, Based on AntlrMSVC50.dsp !IF "$(CFG)" == "" CFG=ANTLR - Win32 Debug !MESSAGE No configuration specified. Defaulting to ANTLR - Win32 Debug. !ENDIF !IF "$(CFG)" != "ANTLR - Win32 Release" && "$(CFG)" != "ANTLR - Win32 Debug" !MESSAGE Invalid configuration "$(CFG)" specified. !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "AntlrMSVC50.mak" CFG="ANTLR - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "ANTLR - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "ANTLR - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE !ERROR An invalid configuration is specified. !ENDIF !IF "$(OS)" == "Windows_NT" NULL= !ELSE NULL=nul !ENDIF !IF "$(CFG)" == "ANTLR - Win32 Release" OUTDIR=.\. INTDIR=.\. # Begin Custom Macros OutDir=.\. # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c" "antlr.c"\ "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" !ELSE ALL : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c" "antlr.c"\ "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" !ENDIF CLEAN : -@erase "$(INTDIR)\antlr.obj" -@erase "$(INTDIR)\antlr.sbr" -@erase "$(INTDIR)\bits.obj" -@erase "$(INTDIR)\bits.sbr" -@erase "$(INTDIR)\build.obj" -@erase "$(INTDIR)\build.sbr" -@erase "$(INTDIR)\egman.obj" -@erase "$(INTDIR)\egman.sbr" -@erase "$(INTDIR)\err.obj" -@erase "$(INTDIR)\err.sbr" -@erase "$(INTDIR)\fcache.obj" -@erase "$(INTDIR)\fcache.sbr" -@erase "$(INTDIR)\fset.obj" -@erase "$(INTDIR)\fset.sbr" -@erase "$(INTDIR)\fset2.obj" -@erase "$(INTDIR)\fset2.sbr" -@erase "$(INTDIR)\gen.obj" -@erase "$(INTDIR)\gen.sbr" -@erase "$(INTDIR)\globals.obj" -@erase "$(INTDIR)\globals.sbr" -@erase "$(INTDIR)\hash.obj" -@erase "$(INTDIR)\hash.sbr" -@erase "$(INTDIR)\lex.obj" -@erase "$(INTDIR)\lex.sbr" -@erase "$(INTDIR)\main.obj" -@erase "$(INTDIR)\main.sbr" -@erase "$(INTDIR)\misc.obj" -@erase "$(INTDIR)\misc.sbr" -@erase "$(INTDIR)\mrhoist.obj" -@erase "$(INTDIR)\mrhoist.sbr" -@erase "$(INTDIR)\pred.obj" -@erase "$(INTDIR)\pred.sbr" -@erase "$(INTDIR)\scan.obj" -@erase "$(INTDIR)\scan.sbr" -@erase "$(INTDIR)\set.obj" -@erase "$(INTDIR)\set.sbr" -@erase "$(INTDIR)\vc50.idb" -@erase "$(OUTDIR)\Antlr.exe" -@erase "$(OUTDIR)\AntlrMSVC50.bsc" -@erase "antlr.c" -@erase "err.c" -@erase "mode.h" -@erase "parser.dlg" -@erase "scan.c" -@erase "tokens.h" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP=cl.exe CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "." /I "..\h" /I "..\support\set" /D\ "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D\ "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\"\ /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=./ CPP_SBRS=./ .c{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .c{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << RSC=rc.exe BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\AntlrMSVC50.bsc" BSC32_SBRS= \ "$(INTDIR)\antlr.sbr" \ "$(INTDIR)\bits.sbr" \ "$(INTDIR)\build.sbr" \ "$(INTDIR)\egman.sbr" \ "$(INTDIR)\err.sbr" \ "$(INTDIR)\fcache.sbr" \ "$(INTDIR)\fset.sbr" \ "$(INTDIR)\fset2.sbr" \ "$(INTDIR)\gen.sbr" \ "$(INTDIR)\globals.sbr" \ "$(INTDIR)\hash.sbr" \ "$(INTDIR)\lex.sbr" \ "$(INTDIR)\main.sbr" \ "$(INTDIR)\misc.sbr" \ "$(INTDIR)\mrhoist.sbr" \ "$(INTDIR)\pred.sbr" \ "$(INTDIR)\scan.sbr" \ "$(INTDIR)\set.sbr" "$(OUTDIR)\AntlrMSVC50.bsc" : "$(OUTDIR)" $(BSC32_SBRS) $(BSC32) @<< $(BSC32_FLAGS) $(BSC32_SBRS) << LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\ advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\ odbccp32.lib /nologo /subsystem:console /incremental:no\ /pdb:"$(OUTDIR)\Antlr.pdb" /machine:I386 /out:"$(OUTDIR)\Antlr.exe" LINK32_OBJS= \ "$(INTDIR)\antlr.obj" \ "$(INTDIR)\bits.obj" \ "$(INTDIR)\build.obj" \ "$(INTDIR)\egman.obj" \ "$(INTDIR)\err.obj" \ "$(INTDIR)\fcache.obj" \ "$(INTDIR)\fset.obj" \ "$(INTDIR)\fset2.obj" \ "$(INTDIR)\gen.obj" \ "$(INTDIR)\globals.obj" \ "$(INTDIR)\hash.obj" \ "$(INTDIR)\lex.obj" \ "$(INTDIR)\main.obj" \ "$(INTDIR)\misc.obj" \ "$(INTDIR)\mrhoist.obj" \ "$(INTDIR)\pred.obj" \ "$(INTDIR)\scan.obj" \ "$(INTDIR)\set.obj" "$(OUTDIR)\Antlr.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) $(LINK32) @<< $(LINK32_FLAGS) $(LINK32_OBJS) << SOURCE=$(InputPath) PostBuild_Desc=Copy antlr to ..\bin directory DS_POSTBUILD_DEP=$(INTDIR)\postbld.dep ALL : $(DS_POSTBUILD_DEP) # Begin Custom Macros OutDir=.\. # End Custom Macros $(DS_POSTBUILD_DEP) : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c"\ "antlr.c" "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" mkdir ..\bin copy ..\bin\antlr.exe antlr_old.exe copy antlr.exe ..\bin\. echo Helper for Post-build step > "$(DS_POSTBUILD_DEP)" !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" OUTDIR=.\. INTDIR=.\. # Begin Custom Macros OutDir=.\. # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c" "antlr.c"\ "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" !ELSE ALL : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c" "antlr.c"\ "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" !ENDIF CLEAN : -@erase "$(INTDIR)\antlr.obj" -@erase "$(INTDIR)\antlr.sbr" -@erase "$(INTDIR)\bits.obj" -@erase "$(INTDIR)\bits.sbr" -@erase "$(INTDIR)\build.obj" -@erase "$(INTDIR)\build.sbr" -@erase "$(INTDIR)\egman.obj" -@erase "$(INTDIR)\egman.sbr" -@erase "$(INTDIR)\err.obj" -@erase "$(INTDIR)\err.sbr" -@erase "$(INTDIR)\fcache.obj" -@erase "$(INTDIR)\fcache.sbr" -@erase "$(INTDIR)\fset.obj" -@erase "$(INTDIR)\fset.sbr" -@erase "$(INTDIR)\fset2.obj" -@erase "$(INTDIR)\fset2.sbr" -@erase "$(INTDIR)\gen.obj" -@erase "$(INTDIR)\gen.sbr" -@erase "$(INTDIR)\globals.obj" -@erase "$(INTDIR)\globals.sbr" -@erase "$(INTDIR)\hash.obj" -@erase "$(INTDIR)\hash.sbr" -@erase "$(INTDIR)\lex.obj" -@erase "$(INTDIR)\lex.sbr" -@erase "$(INTDIR)\main.obj" -@erase "$(INTDIR)\main.sbr" -@erase "$(INTDIR)\misc.obj" -@erase "$(INTDIR)\misc.sbr" -@erase "$(INTDIR)\mrhoist.obj" -@erase "$(INTDIR)\mrhoist.sbr" -@erase "$(INTDIR)\pred.obj" -@erase "$(INTDIR)\pred.sbr" -@erase "$(INTDIR)\scan.obj" -@erase "$(INTDIR)\scan.sbr" -@erase "$(INTDIR)\set.obj" -@erase "$(INTDIR)\set.sbr" -@erase "$(INTDIR)\vc50.idb" -@erase "$(INTDIR)\vc50.pdb" -@erase "$(OUTDIR)\Antlr.exe" -@erase "$(OUTDIR)\Antlr.ilk" -@erase "$(OUTDIR)\Antlr.pdb" -@erase "$(OUTDIR)\AntlrMSVC50.bsc" -@erase "antlr.c" -@erase "err.c" -@erase "mode.h" -@erase "parser.dlg" -@erase "scan.c" -@erase "tokens.h" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP=cl.exe CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "." /I "..\h" /I "..\support\set"\ /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D\ "WIN32" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\"\ /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=./ CPP_SBRS=./ .c{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .c{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << RSC=rc.exe BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\AntlrMSVC50.bsc" -DUSER_ZZSYN -D__STDC__ BSC32_SBRS= \ "$(INTDIR)\antlr.sbr" \ "$(INTDIR)\bits.sbr" \ "$(INTDIR)\build.sbr" \ "$(INTDIR)\egman.sbr" \ "$(INTDIR)\err.sbr" \ "$(INTDIR)\fcache.sbr" \ "$(INTDIR)\fset.sbr" \ "$(INTDIR)\fset2.sbr" \ "$(INTDIR)\gen.sbr" \ "$(INTDIR)\globals.sbr" \ "$(INTDIR)\hash.sbr" \ "$(INTDIR)\lex.sbr" \ "$(INTDIR)\main.sbr" \ "$(INTDIR)\misc.sbr" \ "$(INTDIR)\mrhoist.sbr" \ "$(INTDIR)\pred.sbr" \ "$(INTDIR)\scan.sbr" \ "$(INTDIR)\set.sbr" "$(OUTDIR)\AntlrMSVC50.bsc" : "$(OUTDIR)" $(BSC32_SBRS) $(BSC32) @<< $(BSC32_FLAGS) $(BSC32_SBRS) << LINK32=link.exe LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\ advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\ odbccp32.lib /nologo /subsystem:console /incremental:yes\ /pdb:"$(OUTDIR)\Antlr.pdb" /debug /machine:I386 /out:"$(OUTDIR)\Antlr.exe"\ /pdbtype:sept LINK32_OBJS= \ "$(INTDIR)\antlr.obj" \ "$(INTDIR)\bits.obj" \ "$(INTDIR)\build.obj" \ "$(INTDIR)\egman.obj" \ "$(INTDIR)\err.obj" \ "$(INTDIR)\fcache.obj" \ "$(INTDIR)\fset.obj" \ "$(INTDIR)\fset2.obj" \ "$(INTDIR)\gen.obj" \ "$(INTDIR)\globals.obj" \ "$(INTDIR)\hash.obj" \ "$(INTDIR)\lex.obj" \ "$(INTDIR)\main.obj" \ "$(INTDIR)\misc.obj" \ "$(INTDIR)\mrhoist.obj" \ "$(INTDIR)\pred.obj" \ "$(INTDIR)\scan.obj" \ "$(INTDIR)\set.obj" "$(OUTDIR)\Antlr.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) $(LINK32) @<< $(LINK32_FLAGS) $(LINK32_OBJS) << SOURCE=$(InputPath) PostBuild_Desc=Copy antlr to ..\bin DS_POSTBUILD_DEP=$(INTDIR)\postbld.dep ALL : $(DS_POSTBUILD_DEP) # Begin Custom Macros OutDir=.\. # End Custom Macros $(DS_POSTBUILD_DEP) : "tokens.h" "scan.c" "parser.dlg" "mode.h" "err.c"\ "antlr.c" "$(OUTDIR)\Antlr.exe" "$(OUTDIR)\AntlrMSVC50.bsc" mkdir ..\bin copy ..\bin\antlr.exe antlr_old.exe copy antlr.exe ..\bin\. echo Helper for Post-build step > "$(DS_POSTBUILD_DEP)" !ENDIF !IF "$(CFG)" == "ANTLR - Win32 Release" || "$(CFG)" == "ANTLR - Win32 Debug" SOURCE=.\antlr.c DEP_CPP_ANTLR=\ "..\h\antlr.h"\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\mode.h"\ ".\proto.h"\ ".\syn.h"\ ".\tokens.h"\ "$(INTDIR)\antlr.obj" "$(INTDIR)\antlr.sbr" : $(SOURCE) $(DEP_CPP_ANTLR)\ "$(INTDIR)" "$(INTDIR)\tokens.h" "$(INTDIR)\mode.h" SOURCE=.\antlr.g !IF "$(CFG)" == "ANTLR - Win32 Release" InputPath=.\antlr.g InputName=antlr "antlr.c" "err.c" "mode.h" "scan.c" "tokens.h" "parser.dlg" : $(SOURCE)\ "$(INTDIR)" "$(OUTDIR)" ../bin/antlr -gh $(InputName).g ../bin/dlg -C2 parser.dlg scan.c !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" InputPath=.\antlr.g InputName=antlr "antlr.c" "err.c" "mode.h" "scan.c" "tokens.h" "parser.dlg" : $(SOURCE)\ "$(INTDIR)" "$(OUTDIR)" ..\bin\antlr -gh $(InputName).g ..\bin\dlg -C2 parser.dlg scan.c !ENDIF SOURCE=.\bits.c DEP_CPP_BITS_=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\bits.obj" "$(INTDIR)\bits.sbr" : $(SOURCE) $(DEP_CPP_BITS_)\ "$(INTDIR)" SOURCE=.\build.c DEP_CPP_BUILD=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\build.obj" "$(INTDIR)\build.sbr" : $(SOURCE) $(DEP_CPP_BUILD)\ "$(INTDIR)" SOURCE=.\egman.c DEP_CPP_EGMAN=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\egman.obj" "$(INTDIR)\egman.sbr" : $(SOURCE) $(DEP_CPP_EGMAN)\ "$(INTDIR)" SOURCE=.\err.c DEP_CPP_ERR_C=\ "..\h\antlr.h"\ "..\h\dlgdef.h"\ "..\h\err.h"\ "..\h\pccts_stdarg.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ ".\tokens.h"\ !IF "$(CFG)" == "ANTLR - Win32 Release" CPP_SWITCHES=/nologo /ML /W3 /GX /O2 /I "." /I "..\h" /I "..\support\set" /D\ "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D\ "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\"\ /Fd"$(INTDIR)\\" /FD /c "$(INTDIR)\err.obj" "$(INTDIR)\err.sbr" : $(SOURCE) $(DEP_CPP_ERR_C)\ "$(INTDIR)" "$(INTDIR)\tokens.h" $(CPP) @<< $(CPP_SWITCHES) $(SOURCE) << !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" CPP_SWITCHES=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "." /I "..\h" /I\ "..\support\set" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D\ ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS"\ /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c "$(INTDIR)\err.obj" "$(INTDIR)\err.sbr" : $(SOURCE) $(DEP_CPP_ERR_C)\ "$(INTDIR)" "$(INTDIR)\tokens.h" $(CPP) @<< $(CPP_SWITCHES) $(SOURCE) << !ENDIF SOURCE=.\fcache.c DEP_CPP_FCACH=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\fcache.obj" "$(INTDIR)\fcache.sbr" : $(SOURCE) $(DEP_CPP_FCACH)\ "$(INTDIR)" SOURCE=.\fset.c DEP_CPP_FSET_=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\fset.obj" "$(INTDIR)\fset.sbr" : $(SOURCE) $(DEP_CPP_FSET_)\ "$(INTDIR)" SOURCE=.\fset2.c DEP_CPP_FSET2=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\fset2.obj" "$(INTDIR)\fset2.sbr" : $(SOURCE) $(DEP_CPP_FSET2)\ "$(INTDIR)" SOURCE=.\gen.c DEP_CPP_GEN_C=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\gen.obj" "$(INTDIR)\gen.sbr" : $(SOURCE) $(DEP_CPP_GEN_C)\ "$(INTDIR)" SOURCE=.\globals.c DEP_CPP_GLOBA=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\globals.obj" "$(INTDIR)\globals.sbr" : $(SOURCE) $(DEP_CPP_GLOBA)\ "$(INTDIR)" SOURCE=.\hash.c DEP_CPP_HASH_=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ ".\hash.h"\ "$(INTDIR)\hash.obj" "$(INTDIR)\hash.sbr" : $(SOURCE) $(DEP_CPP_HASH_)\ "$(INTDIR)" SOURCE=.\lex.c DEP_CPP_LEX_C=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\lex.obj" "$(INTDIR)\lex.sbr" : $(SOURCE) $(DEP_CPP_LEX_C)\ "$(INTDIR)" SOURCE=.\main.c DEP_CPP_MAIN_=\ "..\h\antlr.h"\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\mode.h"\ ".\proto.h"\ ".\stdpccts.h"\ ".\syn.h"\ ".\tokens.h"\ "$(INTDIR)\main.obj" "$(INTDIR)\main.sbr" : $(SOURCE) $(DEP_CPP_MAIN_)\ "$(INTDIR)" "$(INTDIR)\tokens.h" "$(INTDIR)\mode.h" SOURCE=.\misc.c DEP_CPP_MISC_=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\misc.obj" "$(INTDIR)\misc.sbr" : $(SOURCE) $(DEP_CPP_MISC_)\ "$(INTDIR)" SOURCE=.\mrhoist.c DEP_CPP_MRHOI=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\mrhoist.obj" "$(INTDIR)\mrhoist.sbr" : $(SOURCE) $(DEP_CPP_MRHOI)\ "$(INTDIR)" SOURCE=.\pred.c DEP_CPP_PRED_=\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\proto.h"\ ".\syn.h"\ "$(INTDIR)\pred.obj" "$(INTDIR)\pred.sbr" : $(SOURCE) $(DEP_CPP_PRED_)\ "$(INTDIR)" SOURCE=.\scan.c DEP_CPP_SCAN_=\ "..\h\antlr.h"\ "..\h\dlgauto.h"\ "..\h\dlgdef.h"\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ ".\generic.h"\ ".\hash.h"\ ".\mode.h"\ ".\proto.h"\ ".\syn.h"\ ".\tokens.h"\ "$(INTDIR)\scan.obj" "$(INTDIR)\scan.sbr" : $(SOURCE) $(DEP_CPP_SCAN_)\ "$(INTDIR)" "$(INTDIR)\tokens.h" "$(INTDIR)\mode.h" SOURCE=..\support\set\set.c DEP_CPP_SET_C=\ "..\h\pccts_stdio.h"\ "..\h\pccts_stdlib.h"\ "..\h\pccts_string.h"\ "..\h\pcctscfg.h"\ "..\support\set\set.h"\ "$(INTDIR)\set.obj" "$(INTDIR)\set.sbr" : $(SOURCE) $(DEP_CPP_SET_C)\ "$(INTDIR)" $(CPP) $(CPP_PROJ) $(SOURCE) !ENDIF cccc-3.1.4/pccts/antlr/AntlrMSVC60.dsp0000644000000000000000000001453607265347511016016 0ustar rootroot# Microsoft Developer Studio Project File - Name="ANTLR" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=ANTLR - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "AntlrMSVC60.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "AntlrMSVC60.mak" CFG="ANTLR - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "ANTLR - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "ANTLR - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "ANTLR - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /O2 /I "." /I "..\h" /I "..\support\set" /D "__STDC__" /D "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"./Antlr.exe" # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy antlr to ..\bin directory PostBuild_Cmds=mkdir ..\bin copy ..\bin\antlr.exe antlr_old.exe copy antlr.exe ..\bin\. # End Special Build Tool !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /Gm /ZI /Od /I "." /I "..\h" /I "..\support\set" /D "__STDC__" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -DUSER_ZZSYN -D__STDC__ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"./Antlr.exe" /pdbtype:sept # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy antlr to ..\bin PostBuild_Cmds=mkdir ..\bin copy ..\bin\antlr.exe antlr_old.exe copy antlr.exe ..\bin\. # End Special Build Tool !ENDIF # Begin Target # Name "ANTLR - Win32 Release" # Name "ANTLR - Win32 Debug" # Begin Source File SOURCE=.\antlr.c # End Source File # Begin Source File SOURCE=.\antlr.g !IF "$(CFG)" == "ANTLR - Win32 Release" # Begin Custom Build - Building ANTLR Parser from ANTLR Grammar InputPath=.\antlr.g InputName=antlr BuildCmds= \ ../bin/antlr -gh $(InputName).g \ ../bin/dlg -C2 parser.dlg scan.c \ "antlr.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "err.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "mode.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "scan.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "tokens.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "parser.dlg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) # End Custom Build !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" # Begin Custom Build - Building ANTLR Parser from ANTLR Grammar InputPath=.\antlr.g InputName=antlr BuildCmds= \ ..\bin\antlr -gh $(InputName).g \ ..\bin\dlg -C2 parser.dlg scan.c \ "antlr.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "err.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "mode.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "scan.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "tokens.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "parser.dlg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) # End Custom Build !ENDIF # End Source File # Begin Source File SOURCE=.\bits.c # End Source File # Begin Source File SOURCE=.\build.c # End Source File # Begin Source File SOURCE=.\egman.c # End Source File # Begin Source File SOURCE=.\err.c !IF "$(CFG)" == "ANTLR - Win32 Release" !ELSEIF "$(CFG)" == "ANTLR - Win32 Debug" # SUBTRACT CPP /YX /Yc /Yu !ENDIF # End Source File # Begin Source File SOURCE=.\fcache.c # End Source File # Begin Source File SOURCE=.\fset.c # End Source File # Begin Source File SOURCE=.\fset2.c # End Source File # Begin Source File SOURCE=.\gen.c # End Source File # Begin Source File SOURCE=.\globals.c # End Source File # Begin Source File SOURCE=.\hash.c # End Source File # Begin Source File SOURCE=.\lex.c # End Source File # Begin Source File SOURCE=.\main.c # End Source File # Begin Source File SOURCE=.\misc.c # End Source File # Begin Source File SOURCE=.\mrhoist.c # End Source File # Begin Source File SOURCE=.\pred.c # End Source File # Begin Source File SOURCE=.\scan.c # End Source File # Begin Source File SOURCE=..\support\set\set.c # End Source File # End Target # End Project cccc-3.1.4/pccts/antlr/AntlrMSVC60.dsw0000644000000000000000000000077607265347511016026 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "ANTLR"=.\AntlrMSVC60.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/antlr/README0000644000000000000000000000133007265350121014222 0ustar rootroot 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. cccc-3.1.4/pccts/antlr/antlr.10000644000000000000000000002362207265347371014571 0ustar rootroot.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) cccc-3.1.4/pccts/antlr/antlr.c0000644000000000000000000021505707265347425014660 0ustar rootroot/* * 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-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 * * ../bin/antlr -gh antlr.g * */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include "pcctscfg.h" #include "set.h" #include #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" #ifndef PURIFY #define PURIFY(r,s) memset((char *) &(r),'\0',(s)); #endif ANTLR_INFO /* MR20 G. Hobbelt For Borland C++ 4.x & 5.x compiling with ALL warnings enabled */ #if defined(__TURBOC__) #pragma warn -aus /* unused assignment of 'xxx' */ #endif #ifdef __USE_PROTOS static void chkToken(char *, char *, char *, int); #else static void chkToken(); #endif #ifdef __USE_PROTOS static int isDLGmaxToken(char *Token); /* MR3 */ #else static int isDLGmaxToken(); /* MR3 */ #endif static int class_nest_level = 0; /* MR20 G. Hobbelt extern definitions moved to antlr.h */ void #ifdef __USE_PROTOS grammar(void) #else grammar() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { Graph g; { zzBLOCK(zztasp2); zzMake0; { for (;;) { if ( !((setwd1[LA(1)]&0x1))) break; if ( (LA(1)==92) ) { zzmatch(92); zzCONSUME; zzmatch(Action); if ( HdrAction==NULL ) { HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(HdrAction!=NULL, "rule grammar: cannot allocate header action"); strcpy(HdrAction, LATEXT(1)); } else warn("additional #header statement ignored"); zzCONSUME; } else { if ( (LA(1)==93) ) { zzmatch(93); zzCONSUME; zzmatch(Action); if ( FirstAction==NULL ) { FirstAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(FirstAction!=NULL, "rule grammar: cannot allocate #first action"); strcpy(FirstAction, LATEXT(1)); } else { warn("additional #first statement ignored"); }; zzCONSUME; } else { if ( (LA(1)==94) ) { zzmatch(94); zzCONSUME; zzmatch(QuotedTerm); if ( GenCC ) { warn("#parser meta-op incompatible with -CC; ignored"); } else { if ( strcmp(ParserName,"zzparser")==0 ) { ParserName=StripQuotes(mystrdup(LATEXT(1))); if ( RulePrefix[0]!='\0' ) { warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored"); RulePrefix[0]='\0'; } } else warn("additional #parser statement ignored"); } zzCONSUME; } else { if ( (LA(1)==95) ) { zzmatch(95); zzCONSUME; zzmatch(QuotedTerm); { char *fname; zzantlr_state st; FILE *f; struct zzdlg_state dst; UserTokenDefsFile = mystrdup(LATEXT(1)); zzsave_antlr_state(&st); zzsave_dlg_state(&dst); fname = mystrdup(LATEXT(1)); f = fopen(StripQuotes(fname), "r"); if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));} else { ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE); UserDefdTokens = 1; } zzrestore_antlr_state(&st); zzrestore_dlg_state(&dst); } zzCONSUME; } else break; /* MR6 code for exiting loop "for sure" */ } } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { for (;;) { if ( !((setwd1[LA(1)]&0x2))) break; if ( (LA(1)==Action) ) { zzmatch(Action); { UserAction *ua = newUserAction(LATEXT(1)); ua->file = action_file; ua->line = action_line; if ( class_nest_level>0 ) list_add(&class_before_actions, ua); else list_add(&BeforeActions, ua); } zzCONSUME; } else { if ( (LA(1)==106) ) { laction(); } else { if ( (LA(1)==107) ) { lmember(); } else { if ( (LA(1)==108) ) { lprefix(); } else { if ( (LA(1)==114) ) { aLexclass(); } else { if ( (LA(1)==118) ) { token(); } else { if ( (LA(1)==115) ) { error(); } else { if ( (LA(1)==116) ) { tclass(); } else { if ( (LA(1)==109) ) { aPred(); } else { if ( (LA(1)==132) ) { default_exception_handler(); } else { if ( (LA(1)==97) ) { class_def(); } else { if ( (LA(1)==96) ) { zzmatch(96); if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; zzCONSUME; } else break; /* MR6 code for exiting loop "for sure" */ } } } } } } } } } } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } rule(); g=zzaArg(zztasp1,3); SynDiag = (Junction *) zzaArg(zztasp1,3 ).left; { zzBLOCK(zztasp2); zzMake0; { for (;;) { if ( !((setwd1[LA(1)]&0x4))) break; if ( (LA(1)==NonTerminal) ) { rule(); if ( zzaArg(zztasp2,1 ).left!=NULL ) {g.right = NULL; g = Or(g, zzaArg(zztasp2,1));} } else { if ( (LA(1)==114) ) { aLexclass(); } else { if ( (LA(1)==118) ) { token(); } else { if ( (LA(1)==115) ) { error(); } else { if ( (LA(1)==116) ) { tclass(); } else { if ( (LA(1)==109) ) { aPred(); } else { if ( (LA(1)==97) ) { class_def(); } else { if ( (LA(1)==96) ) { zzmatch(96); if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; zzCONSUME; } else break; /* MR6 code for exiting loop "for sure" */ } } } } } } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { for (;;) { if ( !((setwd1[LA(1)]&0x8))) break; if ( (LA(1)==Action) ) { zzmatch(Action); { UserAction *ua = newUserAction(LATEXT(1)); ua->file = action_file; ua->line = action_line; if ( class_nest_level>0 ) list_add(&class_after_actions, ua); else list_add(&AfterActions, ua); } zzCONSUME; } else { if ( (LA(1)==106) ) { laction(); } else { if ( (LA(1)==107) ) { lmember(); } else { if ( (LA(1)==108) ) { lprefix(); } else { if ( (LA(1)==115) ) { error(); } else { if ( (LA(1)==116) ) { tclass(); } else { if ( (LA(1)==97) ) { class_def(); } else { if ( (LA(1)==109) ) { aPred(); } else { if ( (LA(1)==96) ) { zzmatch(96); if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; zzCONSUME; } else break; /* MR6 code for exiting loop "for sure" */ } } } } } } } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } zzmatch(Eof); zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd1, 0x10); } } void #ifdef __USE_PROTOS class_def(void) #else class_def() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { int go=1; char name[MaxRuleName+1]; zzmatch(97); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==NonTerminal) ) { zzmatch(NonTerminal); if(go) strncpy(name,LATEXT(1),MaxRuleName); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if(go) strncpy(name,LATEXT(1),MaxRuleName); zzCONSUME; } else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0 && GenCC ) { err("only one grammar class allowed in this release"); go = 0; } else strcpy(CurrentClassName, name); if ( !GenCC ) { err("class meta-op used without C++ option"); } { zzBLOCK(zztasp2); zzMake0; { while ( (setwd1[LA(1)]&0x20) ) { zzsetmatch(zzerr2); if (ClassDeclStuff == NULL) { /* MR10 */ ClassDeclStuff=(char *)calloc(MaxClassDeclStuff+1,sizeof(char)); /* MR10 */ }; /* MR10 */ strncat(ClassDeclStuff," ",MaxClassDeclStuff); /* MR10 */ strncat(ClassDeclStuff,LATEXT(1),MaxClassDeclStuff); /* MR10 */ zzCONSUME; zzLOOP(zztasp2); } zzEXIT(zztasp2); } } zzmatch(100); no_classes_found = 0; if ( class_nest_level>=1 ) {warn("cannot have nested classes");} else class_nest_level++; zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd1, 0x40); } } void #ifdef __USE_PROTOS rule(void) #else rule() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { /*** ListNode *ex_groups = NULL; MR20 G. Hobbelt Uunused variable ***/ ExceptionGroup *eg; RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e; set toksrefd, rulesrefd; char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL; CurExGroups = NULL; CurElementLabels = NULL; /* We want a new element label hash table for each rule */ if ( Elabel!=NULL ) killHashTable(Elabel); Elabel = newHashTable(); attribsRefdFromAction = empty; zzmatch(NonTerminal); q=NULL; if ( hash_get(Rname, LATEXT(1))!=NULL ) { err(eMsg1("duplicate rule definition: '%s'",LATEXT(1))); CannotContinue=TRUE; } else { q = (RuleEntry *)hash_add(Rname, LATEXT(1), (Entry *)newRuleEntry(LATEXT(1))); CurRule = q->str; } CurRuleNode = q; f = CurFile; l = zzline; NumRules++; zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==101) ) { zzmatch(101); if ( q!=NULL ) q->noAST = TRUE; zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { ; if ( (setwd1[LA(1)]&0x80) ) { { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==102) ) { zzmatch(102); zzCONSUME; } zzEXIT(zztasp3); } } zzmatch(PassAction); pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(pdecl!=NULL, "rule rule: cannot allocate param decl"); strcpy(pdecl, LATEXT(1)); CurParmDef = pdecl; zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==103) ) { zzmatch(103); zzCONSUME; zzmatch(PassAction); ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(ret!=NULL, "rule rule: cannot allocate ret type"); strcpy(ret, LATEXT(1)); CurRetDef = ret; zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1)); zzCONSUME; } zzEXIT(zztasp2); } } if ( GenEClasseForRules && q!=NULL ) { e = newECnode; require(e!=NULL, "cannot allocate error class node"); if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);} else a = q->egroup; if ( Tnum( a ) == 0 ) { e->tok = addTname( a ); list_add(&eclasses, (char *)e); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); /* refers to itself */ list_add(&(e->elist), mystrdup(q->str)); } else { warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a)); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); free((char *)e); } } BlkLevel++; zzmatch(104); inAlt=1; zzCONSUME; block( &toksrefd, &rulesrefd ); r = makeBlk(zzaArg(zztasp1,7),0); CurRuleBlk = (Junction *)r.left; CurRuleBlk->blockid = CurBlockID; CurRuleBlk->jtype = RuleBlk; if ( q!=NULL ) CurRuleBlk->rname = q->str; CurRuleBlk->file = f; CurRuleBlk->line = l; CurRuleBlk->pdecl = pdecl; CurRuleBlk->ret = ret; CurRuleBlk->lock = makelocks(); CurRuleBlk->pred_lock = makelocks(); CurRuleBlk->tokrefs = toksrefd; CurRuleBlk->rulerefs = rulesrefd; p = newJunction(); /* add EndRule Node */ ((Junction *)r.right)->p1 = (Node *)p; r.right = (Node *) p; p->jtype = EndRule; p->lock = makelocks(); p->pred_lock = makelocks(); CurRuleBlk->end = p; if ( q!=NULL ) q->rulenum = NumRules; zzaArg(zztasp1,7) = r; --BlkLevel; altFixup();leFixup();egFixup(); zzmatch(105); inAlt=0; zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==Action) ) { zzmatch(Action); a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule rule: cannot allocate error action"); strcpy(a, LATEXT(1)); CurRuleBlk->erraction = a; zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==132) ) { eg = exception_group(); if ( eg!=NULL ) { list_add(&CurExGroups, (void *)eg); if (eg->label == NULL || *eg->label=='\0' ) q->has_rule_exception = 1; } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } if ( q==NULL ) zzaArg(zztasp1,0 ).left = NULL; else zzaArg(zztasp1,0) = zzaArg(zztasp1,7); CurRuleNode = NULL; CurRuleBlk->exceptions = CurExGroups; CurRuleBlk->el_labels = CurElementLabels; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x1); } } void #ifdef __USE_PROTOS laction(void) #else laction() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *a; zzmatch(106); zzCONSUME; zzmatch(Action); a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule laction: cannot allocate action"); strcpy(a, LATEXT(1)); list_add(&LexActions, a); zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x2); } } void #ifdef __USE_PROTOS lmember(void) #else lmember() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *a; zzmatch(107); zzCONSUME; zzmatch(Action); /* MR1 */ if (! GenCC) { /* MR1 */ err("Use #lexmember only in C++ mode (to insert code in DLG class header"); /* MR1 */ } else { /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); /* MR1 */ require(a!=NULL, "rule lmember: cannot allocate action"); /* MR1 */ strcpy(a, LATEXT(1)); /* MR1 */ list_add(&LexMemberActions, a); /* MR1 */ }; /* MR1 */ zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x4); } } void #ifdef __USE_PROTOS lprefix(void) #else lprefix() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *a; zzmatch(108); zzCONSUME; zzmatch(Action); /* MR1 */ if (! GenCC) { /* MR1 */ err("Use #lexprefixr only in C++ mode (to insert code in DLG class header"); /* MR1 */ } else { /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); /* MR1 */ require(a!=NULL, "rule lprefix: cannot allocate action"); /* MR1 */ strcpy(a, LATEXT(1)); /* MR1 */ list_add(&LexPrefixActions, a); /* MR1 */ }; /* MR1 */ zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x8); } } void #ifdef __USE_PROTOS aPred(void) #else aPred() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { PredEntry *predEntry=NULL; char *name=NULL; Predicate *predExpr=NULL; char *predLiteral=NULL; int save_file; int save_line; int predExprPresent=0; zzmatch(109); MR_usingPredNames=1; /* will need to use -mrhoist version of genPredTree */ zzCONSUME; zzmatch(TokenTerm); name=mystrdup(LATEXT(1)); zzCONSUME; /* don't free - referenced in predicates */ CurPredName=(char *)calloc(1,strlen(name) + 10); strcat(CurPredName,"#pred "); strcat(CurPredName,name); predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry != NULL) { warnFL(eMsg1("#pred %s previously defined - ignored",name), FileStr[action_file],action_line); name=NULL; }; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==Pred) ) { zzmatch(Pred); predLiteral=mystrdup(LATEXT(1)); save_line=action_line; save_file=action_file; zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (setwd2[LA(1)]&0x10) ) { predExpr = predOrExpr(); predExprPresent=1; } zzEXIT(zztasp3); } } if (predLiteral != NULL && name != NULL) { /* * predExpr may be NULL due to syntax errors * or simply omitted by the user */ predEntry=newPredEntry(name); predEntry->file=save_file; predEntry->line=save_line; predExpr=MR_predFlatten(predExpr); predEntry->predLiteral=predLiteral; if (! predExprPresent || predExpr == NULL) { predExpr=new_pred(); predExpr->expr=predLiteral; predExpr->source=newActionNode(); predExpr->source->action=predExpr->expr; predExpr->source->rname=CurPredName; predExpr->source->line=action_line; predExpr->source->file=action_file; predExpr->source->is_predicate=1; predExpr->k=predicateLookaheadDepth(predExpr->source); }; predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); } else { if ( (setwd2[LA(1)]&0x20) ) { save_line=zzline; save_file=CurFile; predExpr = predOrExpr(); if (predExpr != NULL && name != NULL) { predEntry=newPredEntry(name); predEntry->file=CurFile; predEntry->line=zzline; predExpr=MR_predFlatten(predExpr); predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); } else {zzFAIL(1,zzerr3,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==105) ) { zzmatch(105); zzCONSUME; } zzEXIT(zztasp2); } } zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); predicate_free(predExpr); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x40); } } Predicate * #ifdef __USE_PROTOS predOrExpr(void) #else predOrExpr() #endif { Predicate * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( Predicate * )) zzMake0; { Predicate *ORnode; Predicate *predExpr; Predicate **tail=NULL; predExpr = predAndExpr(); ORnode=new_pred(); ORnode->expr=PRED_OR_LIST; if (predExpr != NULL) { ORnode->down=predExpr; tail=&predExpr->right; }; { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==110) ) { zzmatch(110); zzCONSUME; predExpr = predAndExpr(); if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; zzLOOP(zztasp2); } zzEXIT(zztasp2); } } _retv=ORnode; ORnode=NULL; zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); predicate_free(ORnode); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x80); return _retv; } } Predicate * #ifdef __USE_PROTOS predAndExpr(void) #else predAndExpr() #endif { Predicate * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( Predicate * )) zzMake0; { Predicate *ANDnode; Predicate *predExpr; Predicate **tail=NULL; predExpr = predPrimary(); ANDnode=new_pred(); ANDnode->expr=PRED_AND_LIST; if (predExpr != NULL) { ANDnode->down=predExpr; tail=&predExpr->right; }; { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==111) ) { zzmatch(111); zzCONSUME; predExpr = predPrimary(); if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; zzLOOP(zztasp2); } zzEXIT(zztasp2); } } _retv=ANDnode; ANDnode=NULL; zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); predicate_free(ANDnode); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x1); return _retv; } } Predicate * #ifdef __USE_PROTOS predPrimary(void) #else predPrimary() #endif { Predicate * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( Predicate * )) zzMake0; { char *name=NULL; PredEntry *predEntry=NULL; Predicate *predExpr=NULL; if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); name=mystrdup(LATEXT(1)); zzCONSUME; predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry == NULL) { warnFL(eMsg1("no previously defined #pred with name \"%s\"",name), FileStr[CurFile],zzline); name=NULL; _retv=NULL; } else { predExpr=predicate_dup(predEntry->pred); predExpr->predEntry=predEntry; _retv=predExpr; }; } else { if ( (LA(1)==112) ) { zzmatch(112); zzCONSUME; predExpr = predOrExpr(); zzmatch(113); _retv=predExpr; zzCONSUME; } else { if ( (LA(1)==101) ) { zzmatch(101); zzCONSUME; predExpr = predPrimary(); predExpr->inverted=!predExpr->inverted; _retv=predExpr; } else {zzFAIL(1,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); predicate_free(predExpr); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x2); return _retv; } } void #ifdef __USE_PROTOS aLexclass(void) #else aLexclass() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { zzmatch(114); zzCONSUME; zzmatch(TokenTerm); lexclass(mystrdup(LATEXT(1))); zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x4); } } void #ifdef __USE_PROTOS error(void) #else error() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *t=NULL; ECnode *e; int go=1; TermEntry *p; zzmatch(115); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { ; if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); t=mystrdup(LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); t=mystrdup(LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } e = newECnode; require(e!=NULL, "cannot allocate error class node"); e->lexclass = CurrentLexClass; if ( Tnum( (t=StripQuotes(t)) ) == 0 ) { if ( hash_get(Texpr, t) != NULL ) warn(eMsg1("errclass name conflicts with regular expression '%s'",t)); e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is errclass name, not token */ list_add(&eclasses, (char *)e); } else { warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t)); free( (char *)e ); go=0; } zzmatch(100); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==NonTerminal) ) { zzmatch(NonTerminal); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr6,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp2); } } if ( go ) list_add(&(e->elist), t); { zzBLOCK(zztasp2); zzMake0; { while ( (setwd3[LA(1)]&0x8) ) { { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==NonTerminal) ) { zzmatch(NonTerminal); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( go ) t=mystrdup(LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr7,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp3); } } if ( go ) list_add(&(e->elist), t); zzLOOP(zztasp2); } zzEXIT(zztasp2); } } zzmatch(96); zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x10); } } void #ifdef __USE_PROTOS tclass(void) #else tclass() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *t=NULL; TCnode *e; int go=1,tok,totok; TermEntry *p, *term, *toterm; char *totext=NULL; zzmatch(116); zzCONSUME; zzmatch(TokenTerm); t=mystrdup(LATEXT(1)); zzCONSUME; e = newTCnode; require(e!=NULL, "cannot allocate token class node"); e->lexclass = CurrentLexClass; if ( Tnum( t ) == 0 ) { e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); set_orel(e->tok, &tokclasses); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is class name, not token */ p->tclass = e; /* save ptr to this tclass def */ list_add(&tclasses, (char *)e); } else { warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t)); free( (char *)e ); go=0; } zzmatch(100); zzCONSUME; { zzBLOCK(zztasp2); int zzcnt=1; zzMake0; { do { { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if ( go ) { term = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));} } zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==117) ) { zzmatch(117); zzCONSUME; zzmatch(TokenTerm); if ( go ) { toterm = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( toterm==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else { totext=mystrdup(LATEXT(1)); totok=addTname(LATEXT(1)); } } zzCONSUME; } zzEXIT(zztasp4); } } } else { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( go ) { term = (TermEntry *) hash_get(Texpr, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); go = 0; } else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));} } zzCONSUME; } else {zzFAIL(1,zzerr8,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp3); } } if ( go ) { if (totext == NULL) { list_add(&(e->tlist), t); } else { list_add(&(e->tlist),".."); list_add(&(e->tlist),t); list_add(&(e->tlist),totext); } totext=NULL; } zzLOOP(zztasp2); } while ( (setwd3[LA(1)]&0x20) ); zzEXIT(zztasp2); } } zzmatch(96); zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x40); } } void #ifdef __USE_PROTOS token(void) #else token() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { char *t=NULL, *e=NULL, *a=NULL; int tnum=0; char *akaString=NULL; TermEntry *te;int save_file=0,save_line=0; zzmatch(118); tokenActionActive=1; zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); t=mystrdup(LATEXT(1)); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==112) ) { zzmatch(112); zzCONSUME; zzmatch(QuotedTerm); akaString=mystrdup(StripQuotes(LATEXT(1))); /* MR11 */ save_file=CurFile;save_line=zzline; /* MR11 */ zzCONSUME; zzmatch(113); zzCONSUME; } zzEXIT(zztasp3); } } { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==119) ) { zzmatch(119); zzCONSUME; zzmatch(120); tnum = atoi(LATEXT(1)); zzCONSUME; } zzEXIT(zztasp3); } } } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); e=mystrdup(LATEXT(1)); zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==Action) ) { zzmatch(Action); a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule token: cannot allocate action"); strcpy(a, LATEXT(1)); zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==105) ) { zzmatch(105); zzCONSUME; } zzEXIT(zztasp2); } } chkToken(t, e, a, tnum); if (t != NULL) { te=(TermEntry *)hash_get(Tname,t); if (te != NULL && akaString != NULL) { if (te->akaString != NULL) { if (strcmp(te->akaString,akaString) != 0) { warnFL(eMsg2("this #token statment conflicts with a previous #token %s(\"%s\") statement", t,te->akaString), FileStr[save_file],save_line); }; } else { te->akaString=akaString; }; }; }; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x80); } } void #ifdef __USE_PROTOS block( set *toksrefd, set *rulesrefd ) #else block(toksrefd,rulesrefd) set *toksrefd; set *rulesrefd ; #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { Graph g, b; set saveblah; int saveinalt = inAlt; ExceptionGroup *eg; * toksrefd = empty; * rulesrefd = empty; set_clr(AST_nodes_refd_in_actions); CurBlockID++; CurAltNum = 1; saveblah = attribsRefdFromAction; attribsRefdFromAction = empty; alt( toksrefd,rulesrefd ); b = g = zzaArg(zztasp1,1); if ( ((Junction *)g.left)->p1->ntype == nAction ) { ActionNode *actionNode=(ActionNode *) ( ( (Junction *)g.left) ->p1); if (!actionNode->is_predicate ) { actionNode->init_action = TRUE; /* MR12c */ if (actionNode->noHoist) { /* MR12c */ errFL("<> appears as init-action - use <<>> <>", /* MR12c */ FileStr[actionNode->file],actionNode->line); /* MR12c */ }; } } ((Junction *)g.left)->blockid = CurBlockID; { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==132) ) { eg = exception_group(); if ( eg!=NULL ) { /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/ /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } CurAltNum++; { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==121) ) { zzmatch(121); inAlt=1; zzCONSUME; alt( toksrefd,rulesrefd ); g = Or(g, zzaArg(zztasp2,2)); ((Junction *)g.left)->blockid = CurBlockID; { zzBLOCK(zztasp3); zzMake0; { while ( (LA(1)==132) ) { eg = exception_group(); if ( eg!=NULL ) { /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/ /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } zzLOOP(zztasp3); } zzEXIT(zztasp3); } } CurAltNum++; zzLOOP(zztasp2); } zzEXIT(zztasp2); } } zzaArg(zztasp1,0) = b; attribsRefdFromAction = saveblah; inAlt = saveinalt; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd4, 0x1); } } void #ifdef __USE_PROTOS alt( set *toksrefd, set *rulesrefd ) #else alt(toksrefd,rulesrefd) set *toksrefd; set *rulesrefd ; #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { int n=0; Graph g; int e_num=0, not=0; Node *node; set elems, dif; int first_on_line = 1, use_def_MT_handler = 0; g.left=NULL; g.right=NULL; CurAltStart = NULL; elems = empty; inAlt = 1; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==88) ) { zzmatch(88); use_def_MT_handler = 1; zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { ; while ( (setwd4[LA(1)]&0x2) ) { { zzBLOCK(zztasp3); zzMake0; { not=0; if ( (LA(1)==122) ) { zzmatch(122); not=1; zzCONSUME; } zzEXIT(zztasp3); } } node = element( not, first_on_line, use_def_MT_handler ); if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0; if ( zzaArg(zztasp2,2 ).left!=NULL ) { g = Cat(g, zzaArg(zztasp2,2)); n++; if ( node!=NULL ) { if ( node->ntype!=nAction ) e_num++; /* record record number of all rule and token refs */ if ( node->ntype==nToken ) { TokNode *tk = (TokNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1; tk->elnum = e_num; set_orel(e_num, &elems); } else if ( node->ntype==nRuleRef ) { RuleRefNode *rn = (RuleRefNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1; rn->elnum = e_num; set_orel(e_num, rulesrefd); } } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } if ( n == 0 ) g = emptyAlt(); zzaArg(zztasp1,0) = g; /* We want to reduce number of LT(i) calls and the number of * local attribute variables in C++ mode (for moment, later we'll * do for C also). However, if trees are being built, they * require most of the attrib variables to create the tree nodes * with; therefore, we gen a token ptr for each token ref in C++ */ if ( GenCC && !GenAST ) { /* This now free's the temp set -ATG 5/6/95 */ set temp; temp = set_and(elems, attribsRefdFromAction); set_orin( toksrefd, temp); set_free(temp); } else set_orin( toksrefd, elems); if ( GenCC ) { dif = set_dif(attribsRefdFromAction, elems); if ( set_deg(dif)>0 ) err("one or more $i in action(s) refer to non-token elements"); set_free(dif); } set_free(elems); set_free(attribsRefdFromAction); inAlt = 0; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd4, 0x4); } } LabelEntry * #ifdef __USE_PROTOS element_label(void) #else element_label() #endif { LabelEntry * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( LabelEntry * )) zzMake0; { TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab; zzmatch(LABEL); lab = mystrdup(LATEXT(1)); zzCONSUME; UsedNewStyleLabel = 1; if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i"); t = (TermEntry *) hash_get(Tname, lab); if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab); if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab); if ( t!=NULL ) { err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab)); _retv = NULL; } else if ( r!=NULL ) { err(eMsg1("label definition clashes with rule definition: '%s'", lab)); _retv = NULL; } else { /* we don't clash with anybody else */ l = (LabelEntry *) hash_get(Elabel, lab); if ( l==NULL ) { /* ok to add new element label */ l = (LabelEntry *)hash_add(Elabel, lab, (Entry *)newLabelEntry(lab)); /* add to list of element labels for this rule */ list_add(&CurElementLabels, (void *)lab); /* MR7 */ leAdd(l); /* list of labels waiting for exception group definitions */ _retv = l; } else { err(eMsg1("label definitions must be unique per rule: '%s'", lab)); _retv = NULL; } } zzmatch(104); zzCONSUME; zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd4, 0x8); return _retv; } } Node * #ifdef __USE_PROTOS element( int not, int first_on_line, int use_def_MT_handler ) #else element(not,first_on_line,use_def_MT_handler) int not; int first_on_line; int use_def_MT_handler ; #endif { Node * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( Node * )) zzMake0; { Attrib blk; Predicate *pred = NULL; int local_use_def_MT_handler=0; ActionNode *act; RuleRefNode *rr; set toksrefd, rulesrefd; TermEntry *term; TokNode *p=NULL; RuleRefNode *q; int approx=0; LabelEntry *label=NULL; int predMsgDone=0; int semDepth=0; int ampersandStyle; int height; /* MR11 */ int equal_height; /* MR11 */ _retv = NULL; if ( (setwd4[LA(1)]&0x10) ) { { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==LABEL) ) { label = element_label(); } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); term = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); zzaRet.left = zzaRet.right = NULL; } else { zzaRet = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1); term = (TermEntry *) hash_get(Tname, LATEXT(1)); require( term!= NULL, "hash table mechanism is broken"); p->tclass = term->tclass; p->complement = not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==117) ) { zzmatch(117); zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( p!=NULL ) setUpperRange(p, LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if ( p!=NULL ) setUpperRange(p, LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr9,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp4); } } } zzEXIT(zztasp3); } } if ( p!=NULL && (p->upper_range!=0 || p->tclass || not) ) list_add(&MetaTokenNodes, (void *)p); { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==123) ) { zzmatch(123); if ( p!=NULL ) p->astnode=ASTroot; zzCONSUME; } else { if ( (setwd4[LA(1)]&0x20) ) { if ( p!=NULL ) p->astnode=ASTchild; } else { if ( (LA(1)==101) ) { zzmatch(101); if ( p!=NULL ) p->astnode=ASTexclude; zzCONSUME; } else {zzFAIL(1,zzerr10,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp3); } } { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==88) ) { zzmatch(88); local_use_def_MT_handler = 1; zzCONSUME; } zzEXIT(zztasp3); } } if ( p!=NULL && first_on_line ) { CurAltStart = (Junction *)zzaRet.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; } if ( p!=NULL ) p->use_def_MT_handler = use_def_MT_handler || local_use_def_MT_handler; _retv = (Node *)p; } else { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); term = (TermEntry *) hash_get(Texpr, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); zzaRet.left = zzaRet.right = NULL; } else { zzaRet = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1); p->complement = not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==117) ) { zzmatch(117); zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==QuotedTerm) ) { zzmatch(QuotedTerm); if ( p!=NULL ) setUpperRange(p, LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); if ( p!=NULL ) setUpperRange(p, LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr11,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp4); } } } zzEXIT(zztasp3); } } { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==123) ) { zzmatch(123); if ( p!=NULL ) p->astnode=ASTroot; zzCONSUME; } else { if ( (setwd4[LA(1)]&0x40) ) { if ( p!=NULL ) p->astnode=ASTchild; } else { if ( (LA(1)==101) ) { zzmatch(101); if ( p!=NULL ) p->astnode=ASTexclude; zzCONSUME; } else {zzFAIL(1,zzerr12,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp3); } } { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==88) ) { zzmatch(88); local_use_def_MT_handler = 1; zzCONSUME; } zzEXIT(zztasp3); } } if ( p!=NULL && (p->upper_range!=0 || p->tclass || not) ) list_add(&MetaTokenNodes, (void *)p); if ( first_on_line ) { CurAltStart = (Junction *)zzaRet.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; } if ( p!=NULL ) p->use_def_MT_handler = use_def_MT_handler || local_use_def_MT_handler; _retv = (Node *)p; } else { if ( (LA(1)==WildCard) ) { if ( not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')"); zzmatch(WildCard); zzaRet = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==123) ) { zzmatch(123); p->astnode=ASTroot; zzCONSUME; } else { if ( (setwd4[LA(1)]&0x80) ) { p->astnode=ASTchild; } else { if ( (LA(1)==101) ) { zzmatch(101); p->astnode=ASTexclude; zzCONSUME; } else {zzFAIL(1,zzerr13,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp3); } } list_add(&MetaTokenNodes, (void *)p); if ( first_on_line ) { CurAltStart = (Junction *)zzaRet.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } _retv = (Node *)p; } else { if ( (LA(1)==NonTerminal) ) { if ( not ) warn("~ NONTERMINAL is an undefined operation"); zzmatch(NonTerminal); zzaRet = buildRuleRef(LATEXT(1)); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==101) ) { zzmatch(101); q = (RuleRefNode *) ((Junction *)zzaRet.left)->p1; q->astnode=ASTexclude; zzCONSUME; } zzEXIT(zztasp3); } } { zzBLOCK(zztasp3); zzMake0; { if ( (setwd5[LA(1)]&0x1) ) { { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==102) ) { zzmatch(102); zzCONSUME; } zzEXIT(zztasp4); } } zzmatch(PassAction); addParm(((Junction *)zzaRet.left)->p1, LATEXT(1)); zzCONSUME; } zzEXIT(zztasp3); } } rr=(RuleRefNode *) ((Junction *)zzaRet.left)->p1; { zzBLOCK(zztasp3); zzMake0; { char *a; if ( (LA(1)==103) ) { zzmatch(103); zzCONSUME; zzmatch(PassAction); a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate assignment"); strcpy(a, LATEXT(1)); rr->assign = a; zzCONSUME; } zzEXIT(zztasp3); } } if ( label!=NULL ) { rr->el_label = label->str; label->elem = (Node *)rr; } if ( first_on_line ) { CurAltStart = (Junction *)zzaRet.left; altAdd(CurAltStart); /* MR7 */ ((RuleRefNode *)((Junction *)zzaRet.left)->p1)->altstart = CurAltStart; } _retv = (Node *)rr; } else {zzFAIL(1,zzerr14,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } } zzEXIT(zztasp2); } } } else { if ( (LA(1)==Action) ) { if ( not ) warn("~ ACTION is an undefined operation"); zzmatch(Action); zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 0); zzCONSUME; if ( first_on_line ) { /* MR7 */ CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; _retv = (Node *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1; } else { if ( (LA(1)==Pred) ) { if ( not ) warn("~ SEMANTIC-PREDICATE is an undefined operation"); zzmatch(Pred); zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 1); zzCONSUME; act = (ActionNode *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1; if (numericActionLabel) { /* MR10 */ list_add(&NumericPredLabels,act); /* MR10 */ numericActionLabel=0; /* MR10 */ }; /* MR10 */ { zzBLOCK(zztasp2); zzMake0; { char *a; if ( (LA(1)==PassAction) ) { zzmatch(PassAction); a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; zzCONSUME; } zzEXIT(zztasp2); } } if ( first_on_line ) { /* MR7 */ CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; _retv = (Node *)act; } else { if ( (setwd5[LA(1)]&0x2) ) { if ( not ) warn("~ BLOCK is an undefined operation"); BlkLevel++; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==124) ) { zzmatch(124); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==125) ) { zzmatch(125); approx=LL_k; zzCONSUME; } else { if ( (LA(1)==126) ) { zzmatch(126); approx = 1; zzCONSUME; } else { if ( (LA(1)==127) ) { zzmatch(127); approx = 2; zzCONSUME; } else {zzFAIL(1,zzerr15,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp3); } } } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==112) ) { zzmatch(112); zzCONSUME; block( &toksrefd,&rulesrefd ); zzmatch(113); blk = zzaRet = zzaArg(zztasp2,2); --BlkLevel; zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==128) ) { zzmatch(128); zzaRet = makeLoop(zzaRet,approx); zzCONSUME; } else { if ( (LA(1)==129) ) { zzmatch(129); zzaRet = makePlus(zzaRet,approx); zzCONSUME; } else { if ( (LA(1)==130) ) { zzmatch(130); zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (setwd5[LA(1)]&0x4) ) { { zzBLOCK(zztasp5); zzMake0; { if ( (LA(1)==131) ) { zzmatch(131); ampersandStyle=0; zzCONSUME; } else { if ( (LA(1)==111) ) { zzmatch(111); ampersandStyle=1; zzCONSUME; } else {zzFAIL(1,zzerr16,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp5); } } zzmatch(Pred); zzaRet = buildAction(LATEXT(1),action_file,action_line,1); zzCONSUME; act = (ActionNode *) ((Junction *)zzaRet.left)->p1; semDepth=predicateLookaheadDepth(act); if (numericActionLabel) { /* MR10 */ list_add(&NumericPredLabels,act); /* MR10 */ numericActionLabel=0; /* MR10 */ }; /* MR10 */ { zzBLOCK(zztasp5); zzMake0; { char *a; if ( (LA(1)==PassAction) ) { zzmatch(PassAction); a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; zzCONSUME; } zzEXIT(zztasp5); } } if ( first_on_line) { /* MR7 */ CurAltStart=(Junction *)zzaRet.left; /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; _retv = (Node *)act; pred = computePredicateFromContextGuard(blk,&predMsgDone); /* MR10 */ if ( pred==NULL) { /* MR10 */ if ( !predMsgDone) err("invalid or missing context guard"); /* MR10 */ predMsgDone=1; /* MR10 */ } else { /* MR10 */ act->guardNodes=(Junction *)blk.left; /* MR11 */ pred->expr = act->action; pred->source = act; /* MR10 */ pred->ampersandStyle = ampersandStyle; /* 0 means (g)? => ... 1 means (g)? && ... */ /* MR13 */ if (pred->tcontext != NULL) { /* MR13 */ height=MR_max_height_of_tree(pred->tcontext); /* MR13 */ equal_height=MR_all_leaves_same_height(pred->tcontext,height); /* MR13 */ if (! equal_height) { /* MR13 */ errFL("in guarded predicates all tokens in the guard must be at the same height", /* MR13 */ FileStr[act->file],act->line); /* MR13 */ }; /* MR13 */ } /* MR10 */ if (ampersandStyle) { /* MR10 */ act->ampersandPred = pred; /* MR11 */ if (! HoistPredicateContext) { /* MR11 */ errFL("without \"-prc on\" (guard)? && <>? ... doesn't make sense", /* MR11 */ FileStr[act->file],act->line); /* MR11 */ }; /* MR10 */ } else { /* MR10 */ act->guardpred = pred; /* MR10 */ }; /* MR10 */ if (pred->k != semDepth) { /* MR10 */ warn(eMsgd2("length of guard (%d) does not match the length of semantic predicate (%d)", /* MR10 */ pred->k,semDepth)); /* MR10 */ }; } } else { if ( (setwd5[LA(1)]&0x8) ) { zzaRet = makeBlk(zzaRet,approx); FoundGuessBlk = 1; ((Junction *) ((Junction *)zzaRet.left)->p1)->guess=1; if ( ! first_on_line ) { err("(...)? predicate must be first element of production"); } } else {zzFAIL(1,zzerr17,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp4); } } } else { if ( (setwd5[LA(1)]&0x10) ) { zzaRet = makeBlk(zzaRet,approx); } else {zzFAIL(1,zzerr18,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } } zzEXIT(zztasp3); } } if ( pred==NULL && !predMsgDone) { /* MR10 */ ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd; if ( first_on_line ) { /* MR7 */ CurAltStart = (Junction *)((Junction *)((Junction *)zzaRet.left)->p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; /* MR7 */ _retv = (Node *) ((Junction *)zzaRet.left)->p1; } } else { if ( (LA(1)==100) ) { zzmatch(100); zzCONSUME; block( &toksrefd,&rulesrefd ); zzaRet = makeOpt(zzaArg(zztasp2,2),approx); --BlkLevel; zzmatch(96); ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd; zzCONSUME; if ( first_on_line ) { /* MR7 */ CurAltStart = (Junction *) ((Junction *)((Junction *)zzaRet.left)->p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; _retv = (Node *) ((Junction *)zzaRet.left)->p1; } else {zzFAIL(1,zzerr19,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } } else { if ( (LA(1)==128) ) { zzmatch(128); warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE; zzCONSUME; } else { if ( (LA(1)==129) ) { zzmatch(129); warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE; zzCONSUME; } else { if ( (LA(1)==103) ) { zzmatch(103); warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE; zzCONSUME; } else { if ( (LA(1)==PassAction) ) { zzmatch(PassAction); warn("[...] out of context 'rule > [...]'"); CannotContinue=TRUE; zzCONSUME; } else {zzFAIL(1,zzerr20,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } } } } } } zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd5, 0x20); return _retv; } } void #ifdef __USE_PROTOS default_exception_handler(void) #else default_exception_handler() #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { DefaultExGroup = exception_group(); zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd5, 0x40); } } ExceptionGroup * #ifdef __USE_PROTOS exception_group(void) #else exception_group() #endif { ExceptionGroup * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( ExceptionGroup * )) zzMake0; { ExceptionHandler *h; LabelEntry *label=NULL; /* MR6 */ FoundException = 1; FoundExceptionGroup = 1; zzmatch(132); _retv = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup)); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { char *p; if ( (LA(1)==PassAction) ) { zzmatch(PassAction); p = LATEXT(1)+1; p[strlen(p)-1] = '\0'; /* kill trailing space */ label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1); if ( label==NULL ) { err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1)); } zzCONSUME; } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==134) ) { h = exception_handler(); list_add(&(_retv->handlers), (void *)h); zzLOOP(zztasp2); } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==133) ) { zzmatch(133); zzCONSUME; zzmatch(104); zzCONSUME; zzmatch(Action); { ExceptionHandler *eh = (ExceptionHandler *) calloc(1, sizeof(ExceptionHandler)); char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(eh!=NULL, "exception: cannot allocate handler"); require(a!=NULL, "exception: cannot allocate action"); strcpy(a, LATEXT(1)); eh->action = a; eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char)); require(eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy(eh->signalname, "default"); list_add(&(_retv->handlers), (void *)eh); } zzCONSUME; } zzEXIT(zztasp2); } } if ( label!=NULL ) { /* Record ex group in sym tab for this label */ if ( label->ex_group!=NULL ) { err(eMsg1("duplicate exception handler for label '%s'",label->str)); } else { label->ex_group = _retv; /* Label the exception group itself */ _retv->label = label->str; /* Make the labelled element pt to the exception also */ /* MR6 */ if (label->elem == NULL) { /* MR6 */ err(eMsg1("reference in exception handler to undefined label '%s'",label->str)); /* MR6 */ } else { switch ( label->elem->ntype ) { case nRuleRef : { RuleRefNode *r = (RuleRefNode *)label->elem; r->ex_group = _retv; break; } case nToken : { TokNode *t = (TokNode *)label->elem; t->ex_group = _retv; break; } } /* end switch */ /* MR6 */ }; /* end test on label->elem */ } /* end test on label->ex_group */ } /* end test on exception label */ /* MR7 */ /* MR7 */ if (BlkLevel == 1 && label == NULL) { /* MR7 */ _retv->forRule=1; /* MR7 */ } else if (label == NULL) { /* MR7 */ _retv->altID = makeAltID(CurBlockID,CurAltNum); /* MR7 */ egAdd(_retv); /* MR7 */ } else { /* MR7 */ _retv->labelEntry=label; /* MR7 */ }; /* MR7 */ /* MR7 */ /* You may want to remove this exc from the rule list */ /* MR7 */ /* and handle at the labeled element site. */ /* MR7 */ /* MR7 */ if (label != NULL) { /* MR7 */ _retv = NULL; /* MR7 */ }; zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd5, 0x80); return _retv; } } ExceptionHandler * #ifdef __USE_PROTOS exception_handler(void) #else exception_handler() #endif { ExceptionHandler * _retv; zzRULE; zzBLOCK(zztasp1); PURIFY(_retv,sizeof( ExceptionHandler * )) zzMake0; { ; zzmatch(134); _retv = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler)); require(_retv!=NULL, "exception: cannot allocate handler"); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==NonTerminal) ) { zzmatch(NonTerminal); _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(_retv->signalname!=NULL, "exception: cannot allocate sig name"); strcpy(_retv->signalname, LATEXT(1)); zzCONSUME; } else { if ( (LA(1)==TokenTerm) ) { zzmatch(TokenTerm); _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(_retv->signalname!=NULL, "exception: cannot allocate sig name"); strcpy(_retv->signalname, LATEXT(1)); zzCONSUME; } else {zzFAIL(1,zzerr21,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } zzmatch(104); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { _retv->action = NULL; if ( (LA(1)==Action) ) { zzmatch(Action); _retv->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(_retv->action!=NULL, "exception: cannot allocate action"); strcpy(_retv->action, LATEXT(1)); zzCONSUME; } zzEXIT(zztasp2); } } zzEXIT(zztasp1); return _retv; fail: zzEXIT(zztasp1); CannotContinue=TRUE; zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd6, 0x1); return _retv; } } void #ifdef __USE_PROTOS enum_file( char *fname ) #else enum_file(fname) char *fname ; #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { if ( (setwd6[LA(1)]&0x2) ) { { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==142) ) { zzmatch(142); zzCONSUME; zzmatch(ID); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==148) ) { zzmatch(148); zzCONSUME; zzmatch(ID); zzCONSUME; } zzEXIT(zztasp3); } } } zzEXIT(zztasp2); } } { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==150) ) { { zzBLOCK(zztasp3); int zzcnt=1; zzMake0; { do { enum_def( fname ); zzLOOP(zztasp3); } while ( (LA(1)==150) ); zzEXIT(zztasp3); } } } else { if ( (LA(1)==148) ) { defines( fname ); } else {zzFAIL(1,zzerr22,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } } else { if ( (LA(1)==Eof) ) { } else {zzFAIL(1,zzerr23,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd6, 0x4); } } void #ifdef __USE_PROTOS defines( char *fname ) #else defines(fname) char *fname ; #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { int v; int maxt=(-1); char *t; { zzBLOCK(zztasp2); int zzcnt=1; zzMake0; { do { zzmatch(148); zzCONSUME; zzmatch(ID); t = mystrdup(LATEXT(1)); zzCONSUME; zzmatch(INT); v = atoi(LATEXT(1)); /* fprintf(stderr, "#token %s=%d\n", t, v);*/ /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ if ( ! isDLGmaxToken(t)) { /* MR2 */ TokenNum = v; if ( v>maxt ) maxt=v; if ( Tnum( t ) == 0 ) { addForcedTname( t, v ); } else { warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline); }; }; zzCONSUME; zzLOOP(zztasp2); } while ( (LA(1)==148) ); zzEXIT(zztasp2); } } TokenNum = maxt + 1; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd6, 0x8); } } void #ifdef __USE_PROTOS enum_def( char *fname ) #else enum_def(fname) char *fname ; #endif { zzRULE; zzBLOCK(zztasp1); zzMake0; { int v= 0; int maxt=(-1); char *t; zzmatch(150); zzCONSUME; zzmatch(ID); zzCONSUME; zzmatch(151); zzCONSUME; zzmatch(ID); t = mystrdup(LATEXT(1)); zzCONSUME; { zzBLOCK(zztasp2); zzMake0; { if ( (LA(1)==152) ) { zzmatch(152); zzCONSUME; zzmatch(INT); v=atoi(LATEXT(1)); zzCONSUME; } else { if ( (setwd6[LA(1)]&0x10) ) { v++; } else {zzFAIL(1,zzerr24,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp2); } } /* fprintf(stderr, "#token %s=%d\n", t, v);*/ TokenNum = v; if ( v>maxt ) maxt=v; /* MR3 */ if ( Tnum( t ) == 0 ) addForcedTname( t, v ); else { warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline); } { zzBLOCK(zztasp2); zzMake0; { while ( (LA(1)==153) ) { zzmatch(153); zzCONSUME; { zzBLOCK(zztasp3); zzMake0; { if ( (LA(1)==ID)&&(isDLGmaxToken(LATEXT(1))) ) { if (!(isDLGmaxToken(LATEXT(1)))) {zzfailed_pred(" isDLGmaxToken(LATEXT(1))");} zzmatch(ID); zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==152) ) { zzmatch(152); zzCONSUME; zzmatch(INT); zzCONSUME; } zzEXIT(zztasp4); } } } else { if ( (LA(1)==ID) ) { zzmatch(ID); t = mystrdup(LATEXT(1)); zzCONSUME; { zzBLOCK(zztasp4); zzMake0; { if ( (LA(1)==152) ) { zzmatch(152); zzCONSUME; zzmatch(INT); v=atoi(LATEXT(1)); zzCONSUME; } else { if ( (setwd6[LA(1)]&0x20) ) { v++; } else {zzFAIL(1,zzerr25,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } zzEXIT(zztasp4); } } /* fprintf(stderr, "#token %s=%d\n", t, v);*/ TokenNum = v; if ( v>maxt ) maxt=v; /* MR3 */ if ( Tnum( t ) == 0 ) addForcedTname( t, v ); else { warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline); } } } zzEXIT(zztasp3); } } zzLOOP(zztasp2); } zzEXIT(zztasp2); } } zzmatch(154); zzCONSUME; zzmatch(155); TokenNum = maxt + 1; zzCONSUME; zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd6, 0x40); } } /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ /* semantic check on DLGminToken and DLGmaxmaxToken in #tokdefs */ #ifdef __USE_PROTOS static int isDLGmaxToken(char *Token) #else static int isDLGmaxToken(Token) char * Token; #endif { static char checkStr1[] = "DLGmaxToken"; static char checkStr2[] = "DLGminToken"; if (strcmp(Token, checkStr1) == 0) return 1; else if (strcmp(Token, checkStr2) == 0) return 1; else return 0; } /* semantics of #token */ static void #ifdef __USE_PROTOS chkToken(char *t, char *e, char *a, int tnum) #else chkToken(t,e,a,tnum) char *t, *e, *a; int tnum; #endif { TermEntry *p; /* check to see that they don't try to redefine a token as a token class */ if ( t!=NULL ) { p = (TermEntry *) hash_get(Tname, t); if ( p!=NULL && p->classname ) { err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t)); if ( a!=NULL ) free((char *)a); return; } } if ( t==NULL && e==NULL ) { /* none found */ err("#token requires at least token name or rexpr"); } else if ( t!=NULL && e!=NULL ) { /* both found */ if ( UserDefdTokens ) { /* if #tokdefs, must not define new */ p = (TermEntry *) hash_get(Tname, t); if ( p == NULL) { err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t)); return; }; } Tklink(t, e); if ( a!=NULL ) { if ( hasAction(e) ) { err(eMsg1("redefinition of action for %s; ignored",e)); } else setHasAction(e, a); } } else if ( t!=NULL ) { /* only one found */ if ( UserDefdTokens ) { p = (TermEntry *) hash_get(Tname, t); if (p == NULL) { err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t)); }; return; } if ( Tnum( t ) == 0 ) addTname( t ); else { err(eMsg1("redefinition of token %s; ignored",t)); } if ( a!=NULL ) { err(eMsg1("action cannot be attached to a token name (%s); ignored",t)); free((char *)a); } } else if ( e!=NULL ) { if ( Tnum( e ) == 0 ) addTexpr( e ); else { if ( hasAction(e) ) { err(eMsg1("redefinition of action for expr %s; ignored",e)); } else if ( a==NULL ) { err(eMsg1("redefinition of expr %s; ignored",e)); } } if ( a!=NULL ) setHasAction(e, a); } /* if a token type number was specified, then add the token ID and 'tnum' * pair to the ForcedTokens list. (only applies if an id was given) */ if ( t!=NULL && tnum>0 ) { if ( set_el(tnum, reserved_positions) ) { err(eMsgd("a token has already been forced to token number %d; ignored", tnum)); } else { list_add(&ForcedTokens, newForcedToken(t,tnum)); set_orel(tnum, &reserved_positions); } } } static int #ifdef __USE_PROTOS match_token(char *s, char **nxt) #else match_token(s,nxt) char *s; char **nxt; #endif { if ( !(*s>='A' && *s<='Z') ) return 0; s++; while ( (*s>='a' && *s<='z') || (*s>='A' && *s<='Z') || (*s>='0' && *s<='9') || *s=='_' ) { s++; } if ( *s!=' ' && *s!='}' ) return 0; *nxt = s; return 1; } static int #ifdef __USE_PROTOS match_rexpr(char *s, char **nxt) #else match_rexpr(s,nxt) char *s; char **nxt; #endif { if ( *s!='"' ) return 0; s++; while ( *s!='"' ) { if ( *s=='\n' || *s=='\r' ) /* MR13 */ warn("eoln found in regular expression"); if ( *s=='\\' ) s++; s++; } *nxt = s+1; return 1; } /* * Walk a string "{ A .. Z }" where A..Z is a space separated list * of token references (either labels or reg exprs). Return a * string "inlineX_set" for some unique integer X. Basically, * we pretend as if we had seen "#tokclass inlineX { A .. Z }" * on the input stream outside of an action. */ char * #ifdef __USE_PROTOS inline_set(char *s) #else inline_set(s) char *s; #endif { char *nxt; fprintf(stderr, "found consumeUntil( {...} )\n"); while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} if ( *s!='{' ) { err("malformed consumeUntil( {...} ); missing '{'"); return "bad_set"; } s++; while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} while ( *s!='}' ) { if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s); else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s); else { err("invalid element in consumeUntil( {...} )"); return "bad_set"; } s = nxt; while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} } return "inlineX_set"; } /* ANTLR-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, FileStr[CurFile]!=NULL?FileStr[CurFile]:"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"); } cccc-3.1.4/pccts/antlr/antlr.g0000644000000000000000000022237107265347461014661 0ustar rootroot/* * antlr.g -- PCCTS Version 1.xx ANTLR * * Parse an antlr input grammar and build a syntax-diagram. * * Written in itself (needs at least 1.06 to work) * * 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 */ /* MR1 */ /* MR1 10-Apr-97 MR1 Replace #if logic with #include "pcctscfg.h" */ /* MR1 */ #header << #include "pcctscfg.h" #include "set.h" #include #include "syn.h" #include "hash.h" #include "generic.h" #define zzcr_attr(attr,tok,t) >> << /* MR20 G. Hobbelt For Borland C++ 4.x & 5.x compiling with ALL warnings enabled */ #if defined(__TURBOC__) #pragma warn -aus /* unused assignment of 'xxx' */ #endif #ifdef __USE_PROTOS static void chkToken(char *, char *, char *, int); #else static void chkToken(); #endif #ifdef __USE_PROTOS static int isDLGmaxToken(char *Token); /* MR3 */ #else static int isDLGmaxToken(); /* MR3 */ #endif static int class_nest_level = 0; /* MR20 G. Hobbelt extern definitions moved to antlr.h */ >> #lexaction << /* maintained, but not used for now */ set AST_nodes_refd_in_actions = set_init; int inAlt = 0; set attribsRefdFromAction = set_init; /* MR20 */ int UsedOldStyleAttrib = 0; int UsedNewStyleLabel = 0; #ifdef __USE_PROTOS char *inline_set(char *); #else char *inline_set(); #endif /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ int tokenActionActive=0; /* MR1 */ >> #lexclass STRINGS #token QuotedTerm "\"" << zzmode(START); >> #token "\n|\r|\r\n" << zzline++; warn("eoln found in string"); zzskip(); >> #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >> #token "\\~[]" << zzmore(); >> #token "~[\n\r\"\\]+" << zzmore(); >> #lexclass ACTION_STRINGS #token "\"" << zzmode(ACTIONS); zzmore(); >> #token "\n|\r|\r\n" << zzline++; warn("eoln found in string (in user action)"); zzskip(); >> #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >> #token "\\~[]" << zzmore(); >> #token "~[\n\r\"\\]+" << zzmore(); >> #lexclass ACTION_CHARS #token "'" << zzmode(ACTIONS); zzmore(); >> #token "\n|\r|\r\n" << zzline++; warn("eoln found in char literal (in user action)"); zzskip(); >> #token "\\~[]" << zzmore(); >> #token "~[\n\r'\\]+" << zzmore(); >> #lexclass ACTION_COMMENTS #token "\*/" << zzmode(ACTIONS); zzmore(); >> #token "\*" << zzmore(); >> #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >> #token "~[\n\r\*]+" << zzmore(); >> #lexclass TOK_DEF_COMMENTS #token "\*/" << zzmode(PARSE_ENUM_FILE); zzmore(); >> #token "\*" << zzmore(); >> #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >> #token "~[\n\r\*]+" << zzmore(); >> #lexclass TOK_DEF_CPP_COMMENTS #token "\n|\r|\r\n" << zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; >> #token "~[\n\r]+" << zzskip(); >> #lexclass ACTION_CPP_COMMENTS #token "\n|\r|\r\n" << zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; >> #token "~[\n\r]+" << zzmore(); >> #lexclass CPP_COMMENTS #token "\n|\r|\r\n" << zzline++; zzmode(START); zzskip(); DAWDLE; >> #token "~[\n\r]+" << zzskip(); >> #lexclass COMMENTS #token "\*/" << zzmode(START); zzskip(); >> #token "\*" << zzskip(); >> #token "\n|\r|\r\n" << zzline++; zzskip(); DAWDLE; >> #token "~[\n\r\*]+" << zzskip(); >> /* * This lexical class accepts actions of type [..] and <<..>> * * It translates the following special items for C: * * $j --> "zzaArg(current zztasp, j)" * $i.j --> "zzaArg(zztaspi, j)" * $i.nondigit> "zzaArg(current zztasp, i).nondigit" * $$ --> "zzaRet" * $alnum --> "alnum" (used to ref parameters) * $rule --> "zzaRet" * $retval --> "_retv.retval" if > 1 return values else "_retv" * $[token, text] --> "zzconstr_attr(token, text)" * $[] --> "zzempty_attr()" * * It translates the following special items for C++: * (attributes are now stored with 'Token' and $i's are only * pointers to the Tokens. Rules don't have attributes now.) * * $j --> "_tbj" where b is the block level * $i.j --> "_tij" * $j->nondigit> "_tbj->nondigit" * $$ --> "$$" * $alnum --> "alnum" (used to ref parameters) * $rule --> "$rule" * $retval --> "_retv.retval" if > 1 return values else "_retv" * $[token, text] --> invalid * $[] --> invalid * * And, for trees: * * #0 --> "(*_root)" * #i --> "zzastArg(i)" * #[args] --> "zzmk_ast(zzastnew(), args)" * #[] --> "zzastnew()" * #( root, child1, ..., childn ) * --> "zztmake(root, child1, ...., childn, NULL)" * #() --> "NULL" * * For C++, ... * * #0 --> "(*_root)" * #i --> "_astbi" where b is the block level * #alnum --> "alnum_ast" (used to ref #label) * #[args] --> "new AST(args)" * #[] --> "new AST" * #( root, child1, ..., childn ) * --> "AST::tmake(root, child1, ...., childn, NULL)" * #() --> "NULL" * * To escape, * * \] --> ] * \) --> ) * \$ --> $ * \# --> # * * A stack is used to nest action terminators because they can be nested * like crazy: << #[$[..],..] >> */ #lexclass ACTIONS #token Action "\>\>" << /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = ' '; zzbegexpr[1] = ' '; if ( zzbufovf ) { err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE)); } /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ /* MR1 Doesn't matter what kind of action it is - reset*/ tokenActionActive=0; /* MR1 */ >> #token Pred "\>\>?" << /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = '\0'; if ( zzbufovf ) { err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE)); }; #ifdef __cplusplus__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __STDC__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __USE_PROTOS /* MRxx */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else /* MR10 */ list_apply(CurActionLabels,mark_label_used_in_sem_pred); #endif #endif #endif >> #token PassAction "\]" << if ( topint() == ']' ) { popint(); if ( istackempty() ) /* terminate action */ { zzmode(START); NLATEXT[0] = ' '; zzbegexpr[0] = ' '; if ( zzbufovf ) { err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE)); } } else { /* terminate $[..] and #[..] */ if ( GenCC ) zzreplstr("))"); else zzreplstr(")"); zzmore(); } } else if ( topint() == '|' ) { /* end of simple [...] */ popint(); zzmore(); } else zzmore(); >> #token "consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \)" << zzmore(); zzreplstr(inline_set(zzbegexpr+ strlen("consumeUntil("))); >> #token "consumeUntil\( ~[\)]+ \)" << zzmore(); >> #token "\n|\r|\r\n" << zzline++; zzmore(); DAWDLE; >> #token "\>" << zzmore(); >> #token "$" << zzmore(); >> #token "$$" << if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();} else err("$$ use invalid in C++ mode"); >> #token "$\[\]" << if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();} else err("$[] use invalid in C++ mode"); >> #token "$\[" << pushint(']'); if ( !GenCC ) zzreplstr("zzconstr_attr("); else err("$[..] use invalid in C++ mode"); zzmore(); >> #token "$[0-9]+" <<{ static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i attrib ref too big"); set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> #token "$[0-9]+." <<{ static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i.field attrib ref too big"); zzbegexpr[strlen(zzbegexpr)-1] = ' '; set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s.", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> #token "$[0-9]+.[0-9]+" <<{ static char buf[100]; static char i[20], j[20]; char *p,*q; numericActionLabel=1; /* MR10 */ if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big"); for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) { if ( q == &i[20] ) fatalFL("i of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; for (p++, q= &j[0]; *p!='\0'; p++) { if ( q == &j[20] ) fatalFL("j of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j); else sprintf(buf,"_t%s%s",i,j); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> #token "$[_a-zA-Z][_a-zA-Z0-9]*" <<{ static char buf[300]; LabelEntry *el; zzbegexpr[0] = ' '; if ( CurRule != NULL && strcmp(CurRule, &zzbegexpr[1])==0 ) { if ( !GenCC ) zzreplstr("zzaRet"); } else if ( CurRetDef != NULL && strmember(CurRetDef, &zzbegexpr[1])) { if ( HasComma( CurRetDef ) ) { require (strlen(zzbegexpr)<=(size_t)285, "$retval attrib ref too big"); sprintf(buf,"_retv.%s",&zzbegexpr[1]); zzreplstr(buf); } else zzreplstr("_retv"); } else if ( CurParmDef != NULL && strmember(CurParmDef, &zzbegexpr[1])) { ; } else if ( Elabel==NULL ) { { err("$-variables in actions outside of rules are not allowed"); } } else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) { /* MR10 */ /* MR10 */ /* element labels might exist without an elem when */ /* MR10 */ /* it is a forward reference (to a rule) */ /* MR10 */ /* MR10 */ if ( GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) ) /* MR10 */ { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); } /* MR10 */ /* MR10 */ if ( !GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) && GenAST) { /* MR10 */ err("You can no longer use attributes returned by rules when also using ASTs"); /* MR10 */ err(" Use upward inheritance (\"rule >[Attrib a] : ... <<$a=...\>\>\")"); /* MR10 */ }; /* MR10 */ /* MR10 */ /* keep track of <<... $label ...>> for semantic predicates in guess mode */ /* MR10 */ /* element labels contain pointer to the owners node */ /* MR10 */ /* MR10 */ if (el->elem != NULL && el->elem->ntype == nToken) { /* MR10 */ list_add(&CurActionLabels,el); /* MR10 */ }; } else warn(eMsg1("$%s not parameter, return value, (defined) element label",&zzbegexpr[1])); } zzmore(); >> #token "#0" << zzreplstr("(*_root)"); zzmore(); chkGTFlag(); >> #token "#\[\]" << if ( GenCC ) { if (NewAST) zzreplstr("(newAST)"); else zzreplstr("(new AST)");} else {zzreplstr("zzastnew()");} zzmore(); chkGTFlag(); >> #token "#\(\)" << zzreplstr("NULL"); zzmore(); chkGTFlag(); >> #token "#[0-9]+" <<{ static char buf[100]; if ( strlen(zzbegexpr)>(size_t)85 ) fatal("#i AST ref too big"); if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1); else sprintf(buf,"zzastArg(%s)",zzbegexpr+1); zzreplstr(buf); zzmore(); set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions); chkGTFlag(); } >> /* MR14 Arpad Beszedes 26-May-98 Add support for #line directives when antlr source is pre-processed #lexclass ACTIONS */ #token "#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)" << zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); >> #token "#line ~[\n\r]* (\n|\r|\r\n)" << zzline++; zzmore(); >> /* MR14 end of a block to support #line in antlr source code */ #token "#[_a-zA-Z][_a-zA-Z0-9]*" << if ( !(strcmp(zzbegexpr, "#ifdef")==0 || strcmp(zzbegexpr, "#if")==0 || strcmp(zzbegexpr, "#else")==0 || strcmp(zzbegexpr, "#endif")==0 || strcmp(zzbegexpr, "#ifndef")==0 || strcmp(zzbegexpr, "#define")==0 || strcmp(zzbegexpr, "#pragma")==0 || strcmp(zzbegexpr, "#undef")==0 || strcmp(zzbegexpr, "#import")==0 || strcmp(zzbegexpr, "#line")==0 || strcmp(zzbegexpr, "#include")==0 || strcmp(zzbegexpr, "#error")==0) ) { static char buf[100]; sprintf(buf, "%s_ast", zzbegexpr+1); zzreplstr(buf); chkGTFlag(); } zzmore(); >> #token "#\[" << pushint(']'); if ( GenCC ) { if (NewAST) zzreplstr("(newAST("); else zzreplstr("(new AST("); } else zzreplstr("zzmk_ast(zzastnew(),"); zzmore(); chkGTFlag(); >> #token "#\(" << pushint('}'); if ( GenCC ) zzreplstr("ASTBase::tmake("); else zzreplstr("zztmake("); zzmore(); chkGTFlag(); >> #token "#" << zzmore(); >> #token "\)" << if ( istackempty() ) zzmore(); else if ( topint()==')' ) { popint(); } else if ( topint()=='}' ) { popint(); /* terminate #(..) */ zzreplstr(", NULL)"); } zzmore(); >> #token "\[" << pushint('|'); /* look for '|' to terminate simple [...] */ zzmore(); >> #token "\(" << pushint(')'); zzmore(); >> #token "\\\]" << zzreplstr("]"); zzmore(); >> #token "\\\)" << zzreplstr(")"); zzmore(); >> /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ #token "\\>" << if (! tokenActionActive) zzreplstr(">"); /* MR1 */ zzmore(); /* MR1 */ >> /* MR1 */ #token "'" << zzmode(ACTION_CHARS); zzmore();>> #token "\"" << zzmode(ACTION_STRINGS); zzmore();>> #token "\\$" << zzreplstr("$"); zzmore(); >> #token "\\#" << zzreplstr("#"); zzmore(); >> #token "\\(\n|\r|\r\n)" << zzline++; zzmore(); >> #token "\\~[\]\)>$#]" << zzmore(); >> /* escaped char, always ignore */ #token "/" << zzmore(); >> #token "/\*" << zzmode(ACTION_COMMENTS); zzmore(); >> #token "\*/" << warn("Missing /*; found dangling */ in action"); zzmore(); >> #token "//" << zzmode(ACTION_CPP_COMMENTS); zzmore(); >> #token "~[\n\r\)\(\\$#\>\]\[\"'/]+" << zzmore(); >> #lexclass START #token "[\t\ ]+" << zzskip(); >> /* Ignore White */ #token "\n|\r|\r\n" << zzline++; zzskip(); >> /* Track Line # */ #token "\[" << zzmode(ACTIONS); zzmore(); istackreset(); pushint(']'); >> #token "\<\<" << action_file=CurFile; action_line=zzline; zzmode(ACTIONS); zzmore(); list_free(&CurActionLabels,0); /* MR10 */ numericActionLabel=0; /* MR10 */ istackreset(); pushint('>'); >> #token "\"" << zzmode(STRINGS); zzmore(); >> #token "/\*" << zzmode(COMMENTS); zzskip(); >> #token "\*/" << warn("Missing /*; found dangling */"); zzskip(); >> #token "//" << zzmode(CPP_COMMENTS); zzskip(); >> /* MR14 Arpad Beszedes 26-May-98 Add support for #line directives when antlr source is pre-processed #lexclass START */ #token "#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)" << zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); >> #token "#line ~[\n\r]* (\n|\r|\r\n)" << zzline++; zzmore(); >> /* MR14 end of a block to support #line in antlr source code */ /* */ /* 8-Apr-97 Regularize escape sequence for ">>" */ /* appearing in string literals */ /* */ #token "\>\>" << warn("Missing <<; found dangling \>\>"); zzskip(); >> /* MR1 */ #token WildCard "." #token "\@" <> /* MR6 */ #token Eof "@" << /* L o o k F o r A n o t h e r F i l e */ { FILE *new_input; new_input = NextFile(); if ( new_input == NULL ) { NLA=Eof; return; } fclose( input ); input = new_input; zzrdstream( input ); zzskip(); /* Skip the Eof (@) char i.e continue */ } >> #token LABEL #errclass "grammar-element" { element } #errclass "meta-symbol" { "\}" "!" ";" "\|" "\~" "^" "\)" } /* * Get a grammar -- Build a list of rules like: * * o-->Rule1--o * | * o-->Rule2--o * | * ... * | * o-->RuleN--o */ grammar : <> ( "{\\}#header" Action /* MR13 */ << if ( HdrAction==NULL ) { HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(HdrAction!=NULL, "rule grammar: cannot allocate header action"); strcpy(HdrAction, LATEXT(1)); } else warn("additional #header statement ignored"); >> | "{\\}#first" Action << if ( FirstAction==NULL ) { FirstAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(FirstAction!=NULL, "rule grammar: cannot allocate #first action"); strcpy(FirstAction, LATEXT(1)); } else { warn("additional #first statement ignored"); }; >> | "{\\}#parser" QuotedTerm << if ( GenCC ) { warn("#parser meta-op incompatible with -CC; ignored"); } else { if ( strcmp(ParserName,"zzparser")==0 ) { ParserName=StripQuotes(mystrdup(LATEXT(1))); if ( RulePrefix[0]!='\0' ) { warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored"); RulePrefix[0]='\0'; } } else warn("additional #parser statement ignored"); } >> | "{\\}#tokdefs" QuotedTerm <<{ char *fname; zzantlr_state st; FILE *f; struct zzdlg_state dst; UserTokenDefsFile = mystrdup(LATEXT(1)); zzsave_antlr_state(&st); zzsave_dlg_state(&dst); fname = mystrdup(LATEXT(1)); f = fopen(StripQuotes(fname), "r"); if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));} else { ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE); UserDefdTokens = 1; } zzrestore_antlr_state(&st); zzrestore_dlg_state(&dst); }>> )* ( Action <<{ UserAction *ua = newUserAction(LATEXT(1)); ua->file = action_file; ua->line = action_line; if ( class_nest_level>0 ) list_add(&class_before_actions, ua); else list_add(&BeforeActions, ua); }>> | laction | lmember /* MR1 */ | lprefix /* MR1 */ | aLexclass | token | error | tclass | aPred /* MR11 */ | default_exception_handler | class_def | "\}" << if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; >> )* rule <> ( rule <> | aLexclass | token | error | tclass | aPred /* MR11 */ | class_def | "\}" << if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; >> )* ( Action <<{ UserAction *ua = newUserAction(LATEXT(1)); ua->file = action_file; ua->line = action_line; if ( class_nest_level>0 ) list_add(&class_after_actions, ua); else list_add(&AfterActions, ua); }>> | laction | lmember /* MR1 */ | lprefix /* MR1 */ | error | tclass | class_def | aPred /* MR11 */ | "\}" << if ( class_nest_level==0 ) warn("missing class definition for trailing '}'"); class_nest_level--; >> )* Eof ; <> class_def : <> "class" ( NonTerminal <> | TokenTerm <> ) << if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0 && GenCC ) { err("only one grammar class allowed in this release"); go = 0; } else strcpy(CurrentClassName, name); >> <> /* MR10 */ (~ "\{" /* MR10 */ <> /* MR10 */ )* "\{" << no_classes_found = 0; if ( class_nest_level>=1 ) {warn("cannot have nested classes");} else class_nest_level++; >> ; <> /* * Build -o-->o-R-o-->o- where -o-R-o- is the block from rule 'block'. * Construct the RuleBlk front and EndRule node on the end of the * block. This is used to add FOLLOW pointers to the rule end. Add the * new rule name to the Rname hash table and sets its rulenum. * Store the parameter definitions if any are found. * * Note that locks are required on the RuleBlk and EndRule nodes to thwart * infinite recursion. * * Return the left graph pointer == NULL to indicate error/dupl rule def. */ rule : << /*** ListNode *ex_groups = NULL; MR20 G. Hobbelt Uunused variable ***/ ExceptionGroup *eg; RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e; set toksrefd, rulesrefd; char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL; CurExGroups = NULL; CurElementLabels = NULL; /* We want a new element label hash table for each rule */ if ( Elabel!=NULL ) killHashTable(Elabel); Elabel = newHashTable(); attribsRefdFromAction = empty; >> NonTerminal <str; } CurRuleNode = q; f = CurFile; l = zzline; NumRules++; >> { "!" <noAST = TRUE;>> } { <<;>> {"\<"} PassAction << pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(pdecl!=NULL, "rule rule: cannot allocate param decl"); strcpy(pdecl, LATEXT(1)); CurParmDef = pdecl; >> } { "\>" PassAction << ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(ret!=NULL, "rule rule: cannot allocate ret type"); strcpy(ret, LATEXT(1)); CurRetDef = ret; >> } { QuotedTerm <egroup=mystrdup(LATEXT(1));>> } << if ( GenEClasseForRules && q!=NULL ) { e = newECnode; require(e!=NULL, "cannot allocate error class node"); if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);} else a = q->egroup; if ( Tnum( a ) == 0 ) { e->tok = addTname( a ); list_add(&eclasses, (char *)e); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); /* refers to itself */ list_add(&(e->elist), mystrdup(q->str)); } else { warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a)); if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]); free((char *)e); } } >> <> ":" <> block[&toksrefd, &rulesrefd] <blockid = CurBlockID; CurRuleBlk->jtype = RuleBlk; if ( q!=NULL ) CurRuleBlk->rname = q->str; CurRuleBlk->file = f; CurRuleBlk->line = l; CurRuleBlk->pdecl = pdecl; CurRuleBlk->ret = ret; CurRuleBlk->lock = makelocks(); CurRuleBlk->pred_lock = makelocks(); CurRuleBlk->tokrefs = toksrefd; CurRuleBlk->rulerefs = rulesrefd; p = newJunction(); /* add EndRule Node */ ((Junction *)r.right)->p1 = (Node *)p; r.right = (Node *) p; p->jtype = EndRule; p->lock = makelocks(); p->pred_lock = makelocks(); CurRuleBlk->end = p; if ( q!=NULL ) q->rulenum = NumRules; $7 = r; >> <<--BlkLevel;>> <> /* MR7 */ ";" <> { Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule rule: cannot allocate error action"); strcpy(a, LATEXT(1)); CurRuleBlk->erraction = a; >> } ( exception_group > [eg] <label == NULL || *eg->label=='\0' ) q->has_rule_exception = 1; } >> )* <> <> <exceptions = CurExGroups;>> <el_labels = CurElementLabels;>> ; <> /* pragma : "{\\}#pragma" "dup\-labeled\-tokens" <> ; */ laction : <> "{\\}#lexaction" Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule laction: cannot allocate action"); strcpy(a, LATEXT(1)); list_add(&LexActions, a); >> ; <> /* MR1 */ /* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */ /* MR1 via #lexmember <<....>> & #lexprefix <<...>> */ /* MR1 */ lmember: <> /* MR1 */ /* MR1 */ "{\\}#lexmember" /* MR1 */ Action /* MR1 */ << /* MR1 */ if (! GenCC) { /* MR1 */ err("Use #lexmember only in C++ mode (to insert code in DLG class header"); /* MR1 */ } else { /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); /* MR1 */ require(a!=NULL, "rule lmember: cannot allocate action"); /* MR1 */ strcpy(a, LATEXT(1)); /* MR1 */ list_add(&LexMemberActions, a); /* MR1 */ }; /* MR1 */ >> /* MR1 */ ; /* MR1 */ <> lprefix: <> /* MR1 */ /* MR1 */ "{\\}#lexprefix" /* MR1 */ Action /* MR1 */ << /* MR1 */ if (! GenCC) { /* MR1 */ err("Use #lexprefixr only in C++ mode (to insert code in DLG class header"); /* MR1 */ } else { /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); /* MR1 */ require(a!=NULL, "rule lprefix: cannot allocate action"); /* MR1 */ strcpy(a, LATEXT(1)); /* MR1 */ list_add(&LexPrefixActions, a); /* MR1 */ }; /* MR1 */ >> /* MR1 */ ; /* MR1 */ <> /* #pred upper <>? predicate literal #pred lower <>? predicate literal #pred up_or_low upper || lower predicate expression concealed interdependence #pred up_or_low_2 <>? A || B predicate literal equals predicate expr analyze using lower||upper generate using isLetter() */ aPred: <> "{\\}#pred" << MR_usingPredNames=1; /* will need to use -mrhoist version of genPredTree */ >> /* used to allow NonTerminal but it caused problems when a rule name immediately followed a #pred statement */ TokenTerm <> << /* don't free - referenced in predicates */ CurPredName=(char *)calloc(1,strlen(name) + 10); strcat(CurPredName,"#pred "); strcat(CurPredName,name); predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry != NULL) { warnFL(eMsg1("#pred %s previously defined - ignored",name), FileStr[action_file],action_line); name=NULL; }; >> ( Pred <> { predOrExpr>[predExpr] <> } <file=save_file; predEntry->line=save_line; predExpr=MR_predFlatten(predExpr); predEntry->predLiteral=predLiteral; if (! predExprPresent || predExpr == NULL) { predExpr=new_pred(); predExpr->expr=predLiteral; predExpr->source=newActionNode(); predExpr->source->action=predExpr->expr; predExpr->source->rname=CurPredName; predExpr->source->line=action_line; predExpr->source->file=action_file; predExpr->source->is_predicate=1; predExpr->k=predicateLookaheadDepth(predExpr->source); }; predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); >> | <> predOrExpr>[predExpr] <file=CurFile; predEntry->line=zzline; predExpr=MR_predFlatten(predExpr); predEntry->pred=predExpr; hash_add(Pname,name,(Entry *)predEntry); predExpr=NULL; }; predicate_free(predExpr); >> ) {";"} ; /* fail */ <> predOrExpr>[Predicate *result] : <> predAndExpr>[predExpr] << ORnode=new_pred(); ORnode->expr=PRED_OR_LIST; if (predExpr != NULL) { ORnode->down=predExpr; tail=&predExpr->right; }; >> ( "\|\|" predAndExpr>[predExpr] << if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; >> )* << $result=ORnode; ORnode=NULL; >> ; /* fail */ <> predAndExpr>[Predicate *result] : <> predPrimary>[predExpr] << ANDnode=new_pred(); ANDnode->expr=PRED_AND_LIST; if (predExpr != NULL) { ANDnode->down=predExpr; tail=&predExpr->right; }; >> ( "&&" predPrimary>[predExpr] << if (predExpr != NULL) { *tail=predExpr; tail=&predExpr->right; }; >> )* << $result=ANDnode; ANDnode=NULL; >> ; /* fail */ <> predPrimary>[Predicate *result] : << char *name=NULL; PredEntry *predEntry=NULL; Predicate *predExpr=NULL; >> TokenTerm <> << predEntry=(PredEntry *) hash_get(Pname,name); if (predEntry == NULL) { warnFL(eMsg1("no previously defined #pred with name \"%s\"",name), FileStr[CurFile],zzline); name=NULL; $result=NULL; } else { predExpr=predicate_dup(predEntry->pred); predExpr->predEntry=predEntry; $result=predExpr; }; >> | "\(" predOrExpr>[predExpr] "\)" << $result=predExpr; >> | "!" predPrimary>[predExpr] << predExpr->inverted=!predExpr->inverted; $result=predExpr; >> ; /* fail */ << predicate_free(predExpr); >> aLexclass: "{\\}#lexclass" TokenTerm <> ; <> error : <> "{\\}#errclass" (<<;>> TokenTerm <> | QuotedTerm <> ) <lexclass = CurrentLexClass; if ( Tnum( (t=StripQuotes(t)) ) == 0 ) { if ( hash_get(Texpr, t) != NULL ) warn(eMsg1("errclass name conflicts with regular expression '%s'",t)); e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is errclass name, not token */ list_add(&eclasses, (char *)e); } else { warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t)); free( (char *)e ); go=0; } >> "\{" ( NonTerminal <> | TokenTerm <> | QuotedTerm <> ) <elist), t);>> ( ( NonTerminal <> | TokenTerm <> | QuotedTerm <> ) <elist), t);>> )* "\}" ; <> tclass : <> <> "{\\}#tokclass" TokenTerm <> <lexclass = CurrentLexClass; if ( Tnum( t ) == 0 ) { e->tok = addTname( t ); set_orel(e->tok, &imag_tokens); set_orel(e->tok, &tokclasses); require((p=(TermEntry *)hash_get(Tname, t)) != NULL, "hash table mechanism is broken"); p->classname = 1; /* entry is class name, not token */ p->tclass = e; /* save ptr to this tclass def */ list_add(&tclasses, (char *)e); } else { warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t)); free( (char *)e ); go=0; } >> "\{" ( ( TokenTerm <> { ".." TokenTerm <> } | QuotedTerm <> ) <tlist), t); } else { list_add(&(e->tlist),".."); list_add(&(e->tlist),t); list_add(&(e->tlist),totext); } totext=NULL; } >> )+ // MR15 Manfred Kogler - forbid empty #tokclass sets (was "+") "\}" ; <> token : <> <> /* MR11 */ "{\\}#token" /* MR1 10-Apr-97 MR1 Allow shift right operator in DLG actions */ /* MR1 Danger when parser feedback to lexer */ /* MR1 */ <> /* MR1 */ { TokenTerm <> /* MR11 */ { /* MR11 */ "\(" /* MR11 */ QuotedTerm /* MR11 */ <> /* MR11 */ "\)" /* MR11 */ } { "=" "[0-9]+" /* define the token type number */ <> } } { QuotedTerm <> } { Action << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule token: cannot allocate action"); strcpy(a, LATEXT(1)); >> } { ";" } /* MR11 */ <> <akaString != NULL) { if (strcmp(te->akaString,akaString) != 0) { warnFL(eMsg2("this #token statment conflicts with a previous #token %s(\"%s\") statement", t,te->akaString), FileStr[save_file],save_line); }; } else { te->akaString=akaString; }; }; }; >> ; <> block[set *toksrefd, set *rulesrefd] : << Graph g, b; set saveblah; int saveinalt = inAlt; ExceptionGroup *eg; *$toksrefd = empty; *$rulesrefd = empty; set_clr(AST_nodes_refd_in_actions); CurBlockID++; CurAltNum = 1; saveblah = attribsRefdFromAction; attribsRefdFromAction = empty; >> alt[toksrefd,rulesrefd] <> << if ( ((Junction *)g.left)->p1->ntype == nAction ) { ActionNode *actionNode=(ActionNode *) ( ( (Junction *)g.left) ->p1); if (!actionNode->is_predicate ) { actionNode->init_action = TRUE; /* MR12c */ if (actionNode->noHoist) { /* MR12c */ errFL("<> appears as init-action - use <<>> <>", /* MR12c */ FileStr[actionNode->file],actionNode->line); /* MR12c */ }; } } ((Junction *)g.left)->blockid = CurBlockID; >> ( exception_group > [eg] << if ( eg!=NULL ) { /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/ /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } >> )* <> ( "\|" <> alt[toksrefd,rulesrefd] <> << ((Junction *)g.left)->blockid = CurBlockID; >> ( exception_group > [eg] << if ( eg!=NULL ) { /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/ /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/ list_add(&CurExGroups, (void *)eg); } >> )* <> )* <<$0 = b;>> <> ; <> alt[set *toksrefd, set *rulesrefd] : <> { "\@" /* handle MismatchedToken signals with default handler */ <> } ( <<;>> /* MR9 Removed unreferenced variable "tok" */ { <> "\~" <> } element[not, first_on_line, use_def_MT_handler] > [node] <ntype!=nAction ) first_on_line = 0;>> << if ( $2.left!=NULL ) { g = Cat(g, $2); n++; if ( node!=NULL ) { if ( node->ntype!=nAction ) e_num++; /* record record number of all rule and token refs */ if ( node->ntype==nToken ) { TokNode *tk = (TokNode *)((Junction *)$2.left)->p1; tk->elnum = e_num; set_orel(e_num, &elems); } else if ( node->ntype==nRuleRef ) { RuleRefNode *rn = (RuleRefNode *)((Junction *)$2.left)->p1; rn->elnum = e_num; set_orel(e_num, $rulesrefd); } } } >> )* <0 ) err("one or more $i in action(s) refer to non-token elements"); set_free(dif); } set_free(elems); set_free(attribsRefdFromAction); inAlt = 0; >> ; <> element_label > [LabelEntry *label] : <> LABEL <> << UsedNewStyleLabel = 1; if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i"); t = (TermEntry *) hash_get(Tname, lab); if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab); if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab); if ( t!=NULL ) { err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab)); $label = NULL; } else if ( r!=NULL ) { err(eMsg1("label definition clashes with rule definition: '%s'", lab)); $label = NULL; } else { /* we don't clash with anybody else */ l = (LabelEntry *) hash_get(Elabel, lab); if ( l==NULL ) { /* ok to add new element label */ l = (LabelEntry *)hash_add(Elabel, lab, (Entry *)newLabelEntry(lab)); /* add to list of element labels for this rule */ list_add(&CurElementLabels, (void *)lab); /* MR7 */ leAdd(l); /* list of labels waiting for exception group definitions */ $label = l; } else { err(eMsg1("label definitions must be unique per rule: '%s'", lab)); $label = NULL; } } >> ":" ; element[int not, int first_on_line, int use_def_MT_handler] > [Node *node] : << Attrib blk; Predicate *pred = NULL; int local_use_def_MT_handler=0; ActionNode *act; RuleRefNode *rr; set toksrefd, rulesrefd; TermEntry *term; TokNode *p=NULL; RuleRefNode *q; int approx=0; LabelEntry *label=NULL; int predMsgDone=0; int semDepth=0; int ampersandStyle; int height; /* MR11 */ int equal_height; /* MR11 */ $node = NULL; >> {element_label>[label]} ( TokenTerm << term = (TermEntry *) hash_get(Tname, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); $$.left = $$.right = NULL; } else { $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1); term = (TermEntry *) hash_get(Tname, LATEXT(1)); require( term!= NULL, "hash table mechanism is broken"); p->tclass = term->tclass; p->complement = $not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } >> { ".." ( QuotedTerm <> | TokenTerm <> ) } << if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) ) list_add(&MetaTokenNodes, (void *)p); >> ( "^" <astnode=ASTroot;>> | <astnode=ASTchild;>> | "!" <astnode=ASTexclude;>> ) { "\@" <> } << if ( p!=NULL && $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; } if ( p!=NULL ) p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler; $node = (Node *)p; >> | QuotedTerm << term = (TermEntry *) hash_get(Texpr, LATEXT(1)); if ( term==NULL && UserDefdTokens ) { err("implicit token definition not allowed with #tokdefs"); $$.left = $$.right = NULL; } else { $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1); p->complement = $not; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } >> { ".." ( QuotedTerm <> | TokenTerm <> ) } ( "^" <astnode=ASTroot;>> | <astnode=ASTchild;>> | "!" <astnode=ASTexclude;>> ) { "\@" <> } << if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) ) list_add(&MetaTokenNodes, (void *)p); >> << if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; } if ( p!=NULL ) p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler; $node = (Node *)p; >> | <> "." <<$$ = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);>> ( "^" <astnode=ASTroot;>> | <astnode=ASTchild;>> | "!" <astnode=ASTexclude;>> ) <> << if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ p->altstart = CurAltStart; if ( label!=NULL ) { p->el_label = label->str; label->elem = (Node *)p; } } $node = (Node *)p; >> | <> NonTerminal <<$$ = buildRuleRef(LATEXT(1));>> { "!" <p1; q->astnode=ASTexclude;>> } { {"\<"} PassAction <p1, LATEXT(1));>> } <p1;>> { <> "\>" PassAction << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate assignment"); strcpy(a, LATEXT(1)); rr->assign = a; >> } << if ( label!=NULL ) { rr->el_label = label->str; label->elem = (Node *)rr; } if ( $first_on_line ) { CurAltStart = (Junction *)$$.left; altAdd(CurAltStart); /* MR7 */ ((RuleRefNode *)((Junction *)$$.left)->p1)->altstart = CurAltStart; } $node = (Node *)rr; >> ) | <> Action <<$0 = buildAction(LATEXT(1),action_file,action_line, 0);>> <> /* MR7 */ <<$node = (Node *) ((Junction *)$0.left)->p1;>> | <> Pred <<$0 = buildAction(LATEXT(1),action_file,action_line, 1);>> <p1;>> <> { <> PassAction << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; >> } <> /* MR7 */ <<$node = (Node *)act;>> | <> <> { "{\\}#pragma" ( "approx" <> | "LL\(1\)" <> /* MR20 */ | "LL\(2\)" <> /* MR20 */ ) } ( "\(" block[&toksrefd,&rulesrefd] "\)" <> ( "\*" <<$$ = makeLoop($$,approx);>> | "\+" <<$$ = makePlus($$,approx);>> | "?" ( ( "=>" <> | "&&" <> /* MR10 (g)? && <

    >? */ ) Pred /* generalized predicate */ /* first make into a predicate */ <<$$ = buildAction(LATEXT(1),action_file,action_line,1);>> <p1;>> <> /* MR10 */ <> { <> PassAction << a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char)); require(a!=NULL, "rule element: cannot allocate predicate fail action"); strcpy(a, LATEXT(1)); act->pred_fail = a; >> } <> <<$node = (Node *)act;>> /* for now, just snag context */ << pred = computePredicateFromContextGuard(blk,&predMsgDone); /* MR10 */ if ( pred==NULL) { /* MR10 */ if ( !predMsgDone) err("invalid or missing context guard"); /* MR10 */ predMsgDone=1; /* MR10 */ } else { /* MR10 */ act->guardNodes=(Junction *)blk.left; /* MR11 */ pred->expr = act->action; pred->source = act; /* MR10 */ pred->ampersandStyle = ampersandStyle; /* 0 means (g)? => ... 1 means (g)? && ... */ /* MR13 */ if (pred->tcontext != NULL) { /* MR13 */ height=MR_max_height_of_tree(pred->tcontext); /* MR13 */ equal_height=MR_all_leaves_same_height(pred->tcontext,height); /* MR13 */ if (! equal_height) { /* MR13 */ errFL("in guarded predicates all tokens in the guard must be at the same height", /* MR13 */ FileStr[act->file],act->line); /* MR13 */ }; /* MR13 */ } /* MR10 */ if (ampersandStyle) { /* MR10 */ act->ampersandPred = pred; /* MR11 */ if (! HoistPredicateContext) { /* MR11 */ errFL("without \"-prc on\" (guard)? && <>? ... doesn't make sense", /* MR11 */ FileStr[act->file],act->line); /* MR11 */ }; /* MR10 */ } else { /* MR10 */ act->guardpred = pred; /* MR10 */ }; /* MR10 */ if (pred->k != semDepth) { /* MR10 */ warn(eMsgd2("length of guard (%d) does not match the length of semantic predicate (%d)", /* MR10 */ pred->k,semDepth)); /* MR10 */ }; } >> | <<$$ = makeBlk($$,approx); FoundGuessBlk = 1; ((Junction *) ((Junction *)$$.left)->p1)->guess=1; if ( !$first_on_line ) { err("(...)? predicate must be first element of production"); } >> ) | <<$$ = makeBlk($$,approx);>> ) << if ( pred==NULL && !predMsgDone) { /* MR10 */ ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd; if ( $first_on_line ) { /* MR7 */ CurAltStart = (Junction *)((Junction *)((Junction *)$$.left)->p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; /* MR7 */ $node = (Node *) ((Junction *)$$.left)->p1; } >> | "\{" block[&toksrefd,&rulesrefd] <<$$ = makeOpt($2,approx); --BlkLevel;>> "\}" << ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID; ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd; ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd; >> <p1); /* MR7 */ altAdd(CurAltStart); /* MR7 */ }; >> <<$node = (Node *) ((Junction *)$$.left)->p1;>> ) /* Error catching alternatives */ | "\*" <> | "\+" <> | "\>" <' can only appear after a nonterminal"); CannotContinue=TRUE;>> | PassAction < [...]'"); CannotContinue=TRUE;>> ; <> default_exception_handler : exception_group > [DefaultExGroup] ; exception_group > [ExceptionGroup *eg] : <> /* MR6 */ "exception" <<$eg = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));>> { <> PassAction /* did they attach a label? */ << p = LATEXT(1)+1; p[strlen(p)-1] = '\0'; /* kill trailing space */ label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1); if ( label==NULL ) { err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1)); } >> } ( exception_handler > [h] <handlers), (void *)h);>> )* { "default" ":" Action <<{ ExceptionHandler *eh = (ExceptionHandler *) calloc(1, sizeof(ExceptionHandler)); char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require(eh!=NULL, "exception: cannot allocate handler"); require(a!=NULL, "exception: cannot allocate action"); strcpy(a, LATEXT(1)); eh->action = a; eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char)); require(eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy(eh->signalname, "default"); list_add(&($eg->handlers), (void *)eh); }>> } << if ( label!=NULL ) { /* Record ex group in sym tab for this label */ if ( label->ex_group!=NULL ) { err(eMsg1("duplicate exception handler for label '%s'",label->str)); } else { label->ex_group = $eg; /* Label the exception group itself */ $eg->label = label->str; /* Make the labelled element pt to the exception also */ /* MR6 */ if (label->elem == NULL) { /* MR6 */ err(eMsg1("reference in exception handler to undefined label '%s'",label->str)); /* MR6 */ } else { switch ( label->elem->ntype ) { case nRuleRef : { RuleRefNode *r = (RuleRefNode *)label->elem; r->ex_group = $eg; break; } case nToken : { TokNode *t = (TokNode *)label->elem; t->ex_group = $eg; break; } } /* end switch */ /* MR6 */ }; /* end test on label->elem */ } /* end test on label->ex_group */ } /* end test on exception label */ /* MR7 */ /* MR7 */ if (BlkLevel == 1 && label == NULL) { /* MR7 */ $eg->forRule=1; /* MR7 */ } else if (label == NULL) { /* MR7 */ $eg->altID = makeAltID(CurBlockID,CurAltNum); /* MR7 */ egAdd($eg); /* MR7 */ } else { /* MR7 */ $eg->labelEntry=label; /* MR7 */ }; /* MR7 */ /* MR7 */ /* You may want to remove this exc from the rule list */ /* MR7 */ /* and handle at the labeled element site. */ /* MR7 */ /* MR7 */ if (label != NULL) { /* MR7 */ $eg = NULL; /* MR7 */ }; >> ; <> exception_handler > [ExceptionHandler *eh] : <<;>> /* MR9 Removed unreferenced variable "a" */ "catch" << $eh = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler)); require($eh!=NULL, "exception: cannot allocate handler"); >> ( NonTerminal << $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy($eh->signalname, LATEXT(1)); >> | TokenTerm << $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->signalname!=NULL, "exception: cannot allocate sig name"); strcpy($eh->signalname, LATEXT(1)); >> ) ":" { <<$eh->action = NULL;>> Action << $eh->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); require($eh->action!=NULL, "exception: cannot allocate action"); strcpy($eh->action, LATEXT(1)); >> } ; <> #token NonTerminal "[a-z] [A-Za-z0-9_]*" << while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >> #token TokenTerm "[A-Z] [A-Za-z0-9_]*" << while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >> #token "{\\}#[A-Za-z0-9_]*" <> #lexclass PARSE_ENUM_FILE #token "[\t\ ]+" << zzskip(); >> /* Ignore White */ #token "\n|\r|\r\n" << zzline++; zzskip(); >> /* Track Line # */ #token "//" << zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); >> #token "/\*" << zzmode(TOK_DEF_COMMENTS); zzskip(); >> #token "#ifdef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "#if" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "#ifndef" << ; >> #token "#else" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "#endif" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "#undef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "#import" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #token "@" << ; >> enum_file[char *fname] : { "#ifndef" ID { "#define" ID /* ignore if it smells like a gate */ /* First #define after the first #ifndef (if any) is ignored */ } } ( ( enum_def[$fname] )+ | defines[$fname] ) | ; defines[char *fname] : <> /* MR3 */ ( "#define" ID <> INT << v = atoi(LATEXT(1)); /* fprintf(stderr, "#token %s=%d\n", t, v);*/ /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ if ( ! isDLGmaxToken(t)) { /* MR2 */ TokenNum = v; if ( v>maxt ) maxt=v; if ( Tnum( t ) == 0 ) { addForcedTname( t, v ); } else { warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline); }; }; >> )+ <> ; enum_def[char *fname] : <> /* MR3 */ "enum" ID "\{" ID <> ( "=" INT <> | <> ) << /* fprintf(stderr, "#token %s=%d\n", t, v);*/ TokenNum = v; if ( v>maxt ) maxt=v; /* MR3 */ if ( Tnum( t ) == 0 ) addForcedTname( t, v ); else { warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline); } >> ( "," /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ { <>? ID { "=" INT } /* MR2 */ | ID /* MR2 */ <> ( "=" INT <> | <> ) << /* fprintf(stderr, "#token %s=%d\n", t, v);*/ TokenNum = v; if ( v>maxt ) maxt=v; /* MR3 */ if ( Tnum( t ) == 0 ) addForcedTname( t, v ); else { warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline); } >> } )* "\}" ";" <> /* MR3 */ ; #token INT "[0-9]+" #token ID "[a-zA-Z_][_a-zA-Z0-9]*" #lexclass START /* MR14 Arpad Beszedes 26-May-98 Add support for #line directives when antlr source is pre-processed */ #lexaction << static char * #ifdef __USE_PROTOS getFileNameFromTheLineInfo(char *toStr, char *fromStr) #else getFileNameFromTheLineInfo(toStr, fromStr) char *toStr, *fromStr; #endif { int i, j, k; if (!fromStr || !toStr) return toStr; /* find the first " */ for (i=0; (i> << /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */ /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */ /* MR2 Don't let #tokdefs be confused by */ /* MR2 DLGminToken and DLGmaxToken */ /* semantic check on DLGminToken and DLGmaxmaxToken in #tokdefs */ #ifdef __USE_PROTOS static int isDLGmaxToken(char *Token) #else static int isDLGmaxToken(Token) char * Token; #endif { static char checkStr1[] = "DLGmaxToken"; static char checkStr2[] = "DLGminToken"; if (strcmp(Token, checkStr1) == 0) return 1; else if (strcmp(Token, checkStr2) == 0) return 1; else return 0; } /* semantics of #token */ static void #ifdef __USE_PROTOS chkToken(char *t, char *e, char *a, int tnum) #else chkToken(t,e,a,tnum) char *t, *e, *a; int tnum; #endif { TermEntry *p; /* check to see that they don't try to redefine a token as a token class */ if ( t!=NULL ) { p = (TermEntry *) hash_get(Tname, t); if ( p!=NULL && p->classname ) { err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t)); if ( a!=NULL ) free((char *)a); return; } } if ( t==NULL && e==NULL ) { /* none found */ err("#token requires at least token name or rexpr"); } else if ( t!=NULL && e!=NULL ) { /* both found */ if ( UserDefdTokens ) { /* if #tokdefs, must not define new */ p = (TermEntry *) hash_get(Tname, t); if ( p == NULL) { err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t)); return; }; } Tklink(t, e); if ( a!=NULL ) { if ( hasAction(e) ) { err(eMsg1("redefinition of action for %s; ignored",e)); } else setHasAction(e, a); } } else if ( t!=NULL ) { /* only one found */ if ( UserDefdTokens ) { p = (TermEntry *) hash_get(Tname, t); if (p == NULL) { err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t)); }; return; } if ( Tnum( t ) == 0 ) addTname( t ); else { err(eMsg1("redefinition of token %s; ignored",t)); } if ( a!=NULL ) { err(eMsg1("action cannot be attached to a token name (%s); ignored",t)); free((char *)a); } } else if ( e!=NULL ) { if ( Tnum( e ) == 0 ) addTexpr( e ); else { if ( hasAction(e) ) { err(eMsg1("redefinition of action for expr %s; ignored",e)); } else if ( a==NULL ) { err(eMsg1("redefinition of expr %s; ignored",e)); } } if ( a!=NULL ) setHasAction(e, a); } /* if a token type number was specified, then add the token ID and 'tnum' * pair to the ForcedTokens list. (only applies if an id was given) */ if ( t!=NULL && tnum>0 ) { if ( set_el(tnum, reserved_positions) ) { err(eMsgd("a token has already been forced to token number %d; ignored", tnum)); } else { list_add(&ForcedTokens, newForcedToken(t,tnum)); set_orel(tnum, &reserved_positions); } } } >> << static int #ifdef __USE_PROTOS match_token(char *s, char **nxt) #else match_token(s,nxt) char *s; char **nxt; #endif { if ( !(*s>='A' && *s<='Z') ) return 0; s++; while ( (*s>='a' && *s<='z') || (*s>='A' && *s<='Z') || (*s>='0' && *s<='9') || *s=='_' ) { s++; } if ( *s!=' ' && *s!='}' ) return 0; *nxt = s; return 1; } static int #ifdef __USE_PROTOS match_rexpr(char *s, char **nxt) #else match_rexpr(s,nxt) char *s; char **nxt; #endif { if ( *s!='"' ) return 0; s++; while ( *s!='"' ) { if ( *s=='\n' || *s=='\r' ) /* MR13 */ warn("eoln found in regular expression"); if ( *s=='\\' ) s++; s++; } *nxt = s+1; return 1; } /* * Walk a string "{ A .. Z }" where A..Z is a space separated list * of token references (either labels or reg exprs). Return a * string "inlineX_set" for some unique integer X. Basically, * we pretend as if we had seen "#tokclass inlineX { A .. Z }" * on the input stream outside of an action. */ char * #ifdef __USE_PROTOS inline_set(char *s) #else inline_set(s) char *s; #endif { char *nxt; fprintf(stderr, "found consumeUntil( {...} )\n"); while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} if ( *s!='{' ) { err("malformed consumeUntil( {...} ); missing '{'"); return "bad_set"; } s++; while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} while ( *s!='}' ) { if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s); else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s); else { err("invalid element in consumeUntil( {...} )"); return "bad_set"; } s = nxt; while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;} } return "inlineX_set"; } >> << /* ANTLR-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, FileStr[CurFile]!=NULL?FileStr[CurFile]:"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"); } >> #lexaction << #ifdef __USE_PROTOS void mark_label_used_in_sem_pred(LabelEntry *le) /* MR10 */ #else void mark_label_used_in_sem_pred(le) /* MR10 */ LabelEntry *le; #endif { TokNode *tn; require (le->elem->ntype == nToken,"mark_label_used... ntype != nToken"); tn=(TokNode *)le->elem; require (tn->label != 0,"mark_label_used... TokNode has no label"); tn->label_used_in_semantic_pred=1; } >> cccc-3.1.4/pccts/antlr/antlr.r0000644000000000000000000003557207265347467014707 0ustar rootroot/* 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)É", "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É", "", "" }, 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É", "Parse control options may be set with th" "is button." }, /* [9] */ NotDependent { }, NestedDialog { 2, {50, 324, 70, 460}, "Generate OptionsÉ", "Various command line options may be set " "with this button." }, /* [10] */ NotDependent { }, NestedDialog { 3, {78, 324, 98, 460}, "More OptionsÉ", "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É", "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 (É)? 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." } } } }; cccc-3.1.4/pccts/antlr/antlr1.txt0000644000000000000000000002624307265347475015340 0ustar rootroot 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) cccc-3.1.4/pccts/antlr/antlr68K.make0000644000000000000000000000650007265347475015640 0ustar rootroot# File: antlr68K.make # Target: antlr68K # 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:12:02 PM # Author: Kenji Tanaka MAKEFILE = antlr68K.make ¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified Includes = ¶ -i "::h:" ¶ -i "::support:set:" Sym¥68K = ObjDir¥68K = :Obj: COptions = {Includes} {Sym¥68K} -model far -w off -d MPW -d __STDC__=1 -d USER_ZZSYN Objects¥68K = ¶ "{ObjDir¥68K}set.c.o" ¶ "{ObjDir¥68K}antlr.c.o" ¶ "{ObjDir¥68K}bits.c.o" ¶ "{ObjDir¥68K}build.c.o" ¶ "{ObjDir¥68K}egman.c.o" ¶ "{ObjDir¥68K}err.c.o" ¶ "{ObjDir¥68K}fcache.c.o" ¶ "{ObjDir¥68K}fset2.c.o" ¶ "{ObjDir¥68K}fset.c.o" ¶ "{ObjDir¥68K}gen.c.o" ¶ "{ObjDir¥68K}globals.c.o" ¶ "{ObjDir¥68K}hash.c.o" ¶ "{ObjDir¥68K}lex.c.o" ¶ "{ObjDir¥68K}main.c.o" ¶ "{ObjDir¥68K}misc.c.o" ¶ "{ObjDir¥68K}mrhoist.c.o" ¶ "{ObjDir¥68K}pred.c.o" ¶ "{ObjDir¥68K}scan.c.o" antlr68K ÄÄ {¥MondoBuild¥} {Objects¥68K} Link ¶ -o {Targ} -d {Sym¥68K} ¶ {Objects¥68K} ¶ -t 'MPST' ¶ -c 'MPS ' ¶ -mf ¶ -model far ¶ -br ON ¶ -srtsg ALL ¶ "{Libraries}Stubs.o" ¶ #"{Libraries}MathLib.o" ¶ #"{CLibraries}Complex.o" ¶ "{CLibraries}StdCLib.o" ¶ "{Libraries}MacRuntime.o" ¶ "{Libraries}IntEnv.o" ¶ "{Libraries}ToolLibs.o" ¶ "{Libraries}Interface.o" "{ObjDir¥68K}set.c.o" Ä {¥MondoBuild¥} "::support:set:set.c" {C} "::support:set:set.c" -o {Targ} {COptions} "{ObjDir¥68K}antlr.c.o" Ä {¥MondoBuild¥} antlr.c {C} antlr.c -o {Targ} {COptions} "{ObjDir¥68K}bits.c.o" Ä {¥MondoBuild¥} bits.c {C} bits.c -o {Targ} {COptions} "{ObjDir¥68K}build.c.o" Ä {¥MondoBuild¥} build.c {C} build.c -o {Targ} {COptions} "{ObjDir¥68K}egman.c.o" Ä {¥MondoBuild¥} egman.c {C} egman.c -o {Targ} {COptions} "{ObjDir¥68K}err.c.o" Ä {¥MondoBuild¥} err.c {C} err.c -o {Targ} {COptions} "{ObjDir¥68K}fcache.c.o" Ä {¥MondoBuild¥} fcache.c {C} fcache.c -o {Targ} {COptions} "{ObjDir¥68K}fset2.c.o" Ä {¥MondoBuild¥} fset2.c {C} fset2.c -o {Targ} {COptions} "{ObjDir¥68K}fset.c.o" Ä {¥MondoBuild¥} fset.c {C} fset.c -o {Targ} {COptions} "{ObjDir¥68K}gen.c.o" Ä {¥MondoBuild¥} gen.c {C} gen.c -o {Targ} {COptions} "{ObjDir¥68K}globals.c.o" Ä {¥MondoBuild¥} globals.c {C} globals.c -o {Targ} {COptions} "{ObjDir¥68K}hash.c.o" Ä {¥MondoBuild¥} hash.c {C} hash.c -o {Targ} {COptions} "{ObjDir¥68K}lex.c.o" Ä {¥MondoBuild¥} lex.c {C} lex.c -o {Targ} {COptions} "{ObjDir¥68K}main.c.o" Ä {¥MondoBuild¥} main.c {C} main.c -o {Targ} {COptions} "{ObjDir¥68K}misc.c.o" Ä {¥MondoBuild¥} misc.c {C} misc.c -o {Targ} {COptions} "{ObjDir¥68K}mrhoist.c.o" Ä {¥MondoBuild¥} mrhoist.c {C} mrhoist.c -o {Targ} {COptions} "{ObjDir¥68K}pred.c.o" Ä {¥MondoBuild¥} pred.c {C} pred.c -o {Targ} {COptions} "{ObjDir¥68K}scan.c.o" Ä {¥MondoBuild¥} scan.c {C} scan.c -o {Targ} {COptions} antlr68K ÄÄ antlr.r Rez antlr.r -o antlr68K -a Install Ä antlr68K Duplicate -y antlr68K "{MPW}"Tools:antlr cccc-3.1.4/pccts/antlr/antlrPPC.make0000644000000000000000000000644007265347514015707 0ustar rootroot# 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 ¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified Includes = ¶ -i "::h:" ¶ -i "::support:set:" Sym¥PPC = ObjDir¥PPC = :Obj: PPCCOptions = {Includes} {Sym¥PPC} -w off -d MPW -d __STDC__=1 -d USER_ZZSYN Objects¥PPC = ¶ "{ObjDir¥PPC}set.c.x" ¶ "{ObjDir¥PPC}antlr.c.x" ¶ "{ObjDir¥PPC}bits.c.x" ¶ "{ObjDir¥PPC}build.c.x" ¶ "{ObjDir¥PPC}egman.c.x" ¶ "{ObjDir¥PPC}err.c.x" ¶ "{ObjDir¥PPC}fcache.c.x" ¶ "{ObjDir¥PPC}fset2.c.x" ¶ "{ObjDir¥PPC}fset.c.x" ¶ "{ObjDir¥PPC}gen.c.x" ¶ "{ObjDir¥PPC}globals.c.x" ¶ "{ObjDir¥PPC}hash.c.x" ¶ "{ObjDir¥PPC}lex.c.x" ¶ "{ObjDir¥PPC}main.c.x" ¶ "{ObjDir¥PPC}misc.c.x" ¶ "{ObjDir¥PPC}mrhoist.c.x" ¶ "{ObjDir¥PPC}pred.c.x" ¶ "{ObjDir¥PPC}scan.c.x" antlrPPC ÄÄ {¥MondoBuild¥} {Objects¥PPC} PPCLink ¶ -o {Targ} {Sym¥PPC} ¶ {Objects¥PPC} ¶ -t 'MPST' ¶ -c 'MPS ' ¶ "{SharedLibraries}InterfaceLib" ¶ "{SharedLibraries}StdCLib" ¶ #"{SharedLibraries}MathLib" ¶ "{PPCLibraries}StdCRuntime.o" ¶ "{PPCLibraries}PPCCRuntime.o" ¶ "{PPCLibraries}PPCToolLibs.o" "{ObjDir¥PPC}set.c.x" Ä {¥MondoBuild¥} "::support:set:set.c" {PPCC} "::support:set:set.c" -o {Targ} {PPCCOptions} "{ObjDir¥PPC}antlr.c.x" Ä {¥MondoBuild¥} antlr.c {PPCC} antlr.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}bits.c.x" Ä {¥MondoBuild¥} bits.c {PPCC} bits.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}build.c.x" Ä {¥MondoBuild¥} build.c {PPCC} build.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}egman.c.x" Ä {¥MondoBuild¥} egman.c {PPCC} egman.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}err.c.x" Ä {¥MondoBuild¥} err.c {PPCC} err.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}fcache.c.x" Ä {¥MondoBuild¥} fcache.c {PPCC} fcache.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}fset2.c.x" Ä {¥MondoBuild¥} fset2.c {PPCC} fset2.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}fset.c.x" Ä {¥MondoBuild¥} fset.c {PPCC} fset.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}gen.c.x" Ä {¥MondoBuild¥} gen.c {PPCC} gen.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}globals.c.x" Ä {¥MondoBuild¥} globals.c {PPCC} globals.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}hash.c.x" Ä {¥MondoBuild¥} hash.c {PPCC} hash.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}lex.c.x" Ä {¥MondoBuild¥} lex.c {PPCC} lex.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}main.c.x" Ä {¥MondoBuild¥} main.c {PPCC} main.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}misc.c.x" Ä {¥MondoBuild¥} misc.c {PPCC} misc.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}mrhoist.c.x" Ä {¥MondoBuild¥} mrhoist.c {PPCC} mrhoist.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}pred.c.x" Ä {¥MondoBuild¥} pred.c {PPCC} pred.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}scan.c.x" Ä {¥MondoBuild¥} scan.c {PPCC} scan.c -o {Targ} {PPCCOptions} antlrPPC ÄÄ antlr.r Rez antlr.r -o antlrPPC -a Install Ä antlrPPC Duplicate -y antlrPPC "{MPW}"Tools:antlr cccc-3.1.4/pccts/antlr/bits.c0000644000000000000000000006310607373512202014460 0ustar rootroot/* bits.c -- manage creation and output of bit sets used by the parser. * * 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-1998 */ #include #include #include #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" /* char is only thing that is pretty much always known == 8 bits * This allows output of antlr (set stuff, anyway) to be androgynous (portable) */ typedef unsigned char SetWordType; #define BitsPerByte 8 #define BitsPerWord BitsPerByte*sizeof(SetWordType) static SetWordType *setwd = NULL; int setnum = -1; int wordnum = 0; int esetnum = 0; /* Used to convert native wordsize, which ANTLR uses (via set.c) to manipulate sets, to bytes that are most portable size-wise. */ void #ifdef __USE_PROTOS DumpIntAsChars( FILE *f, char *format, unsigned wd ) #else DumpIntAsChars( f, format, wd ) FILE *f; char *format; unsigned wd; #endif { int i; /* uses max of 32 bit unsigned integer for the moment */ static unsigned long byte_mask[sizeof(unsigned long)] = { 0xFF, 0xFF00UL, 0xFF0000UL, 0xFF000000UL }; /* MR20 G. Hobbelt */ /* 0xFF00000000, 0xFF0000000000, 0xFF000000000000, 0xFF00000000000000 };*/ /* for each byte in the word */ assert(sizeof(unsigned) <= 4); /* M20 G. Hobbelt Sanity check */ for (i=0; i>(i*BitsPerByte)); if ( itok))); return empty; } r = RulePtr[q->rulenum]; r->end->halt = TRUE; /* don't let reach fall off end of rule here */ rk = empty; REACH(r, 1, &rk, a); r->end->halt = FALSE; return a; } /* * scan the list of tokens/eclasses/nonterminals filling the new eclass * with the set described by the list. Note that an eclass can be * quoted to allow spaces etc... However, an eclass must not conflict * with a reg expr found elsewhere. The reg expr will be taken over * the eclass name. */ static void #ifdef __USE_PROTOS doEclass( char *eclass ) #else doEclass( eclass ) char *eclass; #endif { TermEntry *q; ECnode *p; ListNode *e; unsigned int t; unsigned deg=0; set a; require(eclass!=NULL, "doEclass: NULL eset"); p = (ECnode *) eclass; lexmode(p->lexclass); /* switch to lexclass where errclass is defined */ p->eset = empty; for (e = (p->elist)->next; e!=NULL; e=e->next) { if ( islower( *((char *)e->elem) ) ) /* is it a rule ref? (alias FIRST request) */ { a = Efirst((char *)e->elem, p); set_orin(&p->eset, a); deg += set_deg(a); set_free( a ); continue; } else if ( *((char *)e->elem)=='"' ) { t = 0; q = (TermEntry *) hash_get(Texpr, (char *) e->elem); if ( q == NULL ) { /* if quoted and not an expr look for eclass name */ q = (TermEntry *) hash_get(Tname, *((char **)&(e->elem))=StripQuotes((char *)e->elem)); if ( q != NULL ) t = q->token; } else t = q->token; } else /* labelled token/eclass/tokclass */ { q = (TermEntry *) hash_get(Tname, (char *)e->elem); if ( q != NULL ) { if ( strcmp((char *)e->elem, TokenString(p->tok))==0 ) { warnNoFL(eMsg1("self-referential error class '%s'; ignored", (char *)e->elem)); continue; } else t = q->token; } else t=0; } if ( t!=0 ) { set_orel(t, &p->eset); deg++; } else warnNoFL(eMsg2("undefined token '%s' referenced in errclass '%s'; ignored", (char *)e->elem, TokenString(p->tok))); } p->setdeg = deg; } void #ifdef __USE_PROTOS ComputeErrorSets( void ) #else ComputeErrorSets( ) #endif { #ifdef __cplusplus list_apply(eclasses, (void (*)(void *)) doEclass); #else #ifdef __USE_PROTOS list_apply(eclasses, (void (*)(void *)) doEclass); #else list_apply(eclasses, doEclass); #endif #endif } void #ifdef __USE_PROTOS ComputeTokSets( void ) #else ComputeTokSets( ) #endif { ListNode *t, *e = NULL, *e1, *e2; int something_changed; int i; TCnode *p; TermEntry *q, *q1, *q2; if ( tclasses == NULL ) return; /* turn lists of token/tokclass references into sets */ for (t = tclasses->next; t!=NULL; t=t->next) { p = (TCnode *) t->elem; /* if wild card, then won't have entries in tclass, assume all_tokens */ if ( p->tok == WildCardToken ) { p->tset = set_dup(all_tokens); continue; } lexmode(p->lexclass); /* switch to lexclass where tokclass is defined */ p->tset = empty; /* instantiate all tokens/token_classes into the tset */ for (e = (p->tlist)->next; e!=NULL; e=e->next) { char *tokstr; tokstr = (char *)e->elem; if ( *tokstr == '"' ) { q = (TermEntry *) hash_get(Texpr, tokstr); require(q!=NULL, "ComputeTokSets: no token def"); set_orel(q->token, &p->tset); } else if (tokstr[0] == '.') { e1=e->next; e2=e1->next; e=e2; q1= (TermEntry *) hash_get(Tname, (char *)e1->elem); require(q1!=NULL, "ComputeTokSets: no token def"); q2= (TermEntry *) hash_get(Tname, (char *)e2->elem); require(q2!=NULL, "ComputeTokSets: no token def"); if (set_el(q1->token,imag_tokens)) { errNoFL(eMsg2("can't define #tokclass %s using #tokclass or #errclass %s", TokenString(p->tok),(char *)e1->elem) ); } if (set_el(q2->token,imag_tokens)) { errNoFL(eMsg2("can't define #tokclass %s using #tokclass or #errclass %s", TokenString(p->tok),(char *)e2->elem) ); } if (q1->token > q2->token) { errNoFL(eMsg3("for #tokclass %s %s..%s - first token number > second token number", TokenString(p->tok),(char *)e1->elem,(char *)e2->elem) ); for (i=q2->token; i<=q1->token; i++) { set_orel(i, &p->tset); } } else { for (i=q1->token; i<=q2->token; i++) { set_orel(i, &p->tset); } } } else { q = (TermEntry *) hash_get(Tname, tokstr); require(q!=NULL, "ComputeTokSets: no token def"); set_orel(q->token, &p->tset); } } } /* Go thru list of tokclasses again looking for tokclasses in sets */ again: something_changed = 0; for (t = tclasses->next; t!=NULL; t=t->next) { set tcl; p = (TCnode *) t->elem; tcl = set_and(p->tset, tokclasses); if ( !set_nil(tcl) ) { int tk; /* replace refs to tokclasses with the associated set of tokens */ something_changed = 1; while ( !set_nil(tcl) ) { tk = set_int(tcl); /* grab one of the tok class refs */ set_rm(tk, tcl); if ( p->tok != tk ) /* tokclass ref to yourself? */ { q = (TermEntry *) hash_get(Tname, TokenString(tk)); require(q!=NULL, "#tokclass not in hash table"); set_orin(&p->tset, q->tclass->tset); } set_rm(tk, p->tset); /* remove ref that we replaced */ } } set_free(tcl); } if ( something_changed ) goto again; } void #ifdef __USE_PROTOS DumpRemainingTokSets(void) #else DumpRemainingTokSets() #endif { TCnode *p; ListNode *t; /* Go thru tclasses (for the last time) and dump the sets not dumped * during code gen; yes, this is a bogus way to do this, but ComputeTokSets() * can't dump the defs as the error file and tok file has not been created * yet etc... */ if ( tclasses==NULL ) return; for (t = tclasses->next; t!=NULL; t=t->next) { unsigned e; p = (TCnode *) t->elem; if ( p->dumped ) continue; e = DefErrSet(&(p->tset), 0, TokenString(p->tok)); p->dumped = 1; p->setnum = e; } } /* replace a subset of an error set with an error class name if a subset is found * repeat process until no replacements made */ void #ifdef __USE_PROTOS SubstErrorClass( set *f ) #else SubstErrorClass( f ) set *f; #endif { int max, done = 0; ListNode *p; ECnode *ec, *maxclass = NULL; set a; require(f!=NULL, "SubstErrorClass: NULL eset"); if ( eclasses == NULL ) return; while ( !done ) { max = 0; maxclass = NULL; for (p=eclasses->next; p!=NULL; p=p->next) /* chk all error classes */ { ec = (ECnode *) p->elem; if ( ec->setdeg > max ) { if ( set_sub(ec->eset, *f) || set_equ(ec->eset, *f) ) {maxclass = ec; max=ec->setdeg;} } } if ( maxclass != NULL ) /* if subset found, replace with token */ { a = set_dif(*f, maxclass->eset); set_orel((unsigned)maxclass->tok, &a); set_free(*f); *f = a; } else done = 1; } } int #ifdef __USE_PROTOS DefErrSet1(int nilOK, set *f, int subst, char *name ) #else DefErrSet1(nilOK, f, subst, name ) int nilOK; set *f; int subst; /* should be substitute error classes? */ char *name; #endif { if ( GenCC ) return DefErrSetForCC1(nilOK, f, subst, name ); else return DefErrSetForC1(nilOK, f, subst, name ); } int #ifdef __USE_PROTOS DefErrSet( set *f, int subst, char *name ) #else DefErrSet( f, subst, name ) set *f; int subst; /* should be substitute error classes? */ char *name; #endif { return DefErrSet1(0,f,subst,name); } /* Define a new error set. WARNING...set-implementation dependent. */ int #ifdef __USE_PROTOS DefErrSetForC1(int nilOK, set *f, int subst, char *name ) #else DefErrSetForC1(nilOK, f, subst, name ) int nilOK; /* MR13 */ set *f; int subst; /* should be substitute error classes? */ char *name; #endif { unsigned *p, *endp; int e=1; if (!nilOK) require(!set_nil(*f), "DefErrSet: nil set to dump?"); if ( subst ) SubstErrorClass(f); p = f->setword; endp = &(f->setword[f->n]); esetnum++; if ( name!=NULL ) fprintf(DefFile, "extern SetWordType %s_set[];\n", name); else fprintf(DefFile, "extern SetWordType zzerr%d[];\n", esetnum); if ( name!=NULL ) { fprintf(ErrFile, "SetWordType %s_set[%d] = {", name, NumWords(TokenNum-1)*sizeof(unsigned)); } else { fprintf(ErrFile, "SetWordType zzerr%d[%d] = {", esetnum, NumWords(TokenNum-1)*sizeof(unsigned)); } while ( p < endp ) { if ( e > 1 ) fprintf(ErrFile, ", "); DumpIntAsChars(ErrFile, "0x%x", *p++); if ( e == 3 ) { DAWDLE; if ( p < endp ) fprintf(ErrFile, ","); fprintf(ErrFile, "\n\t"); e=1; } else e++; } fprintf(ErrFile, "};\n"); return esetnum; } int #ifdef __USE_PROTOS DefErrSetForC( set *f, int subst, char *name ) #else DefErrSetForC( f, subst, name ) set *f; int subst; /* should be substitute error classes? */ char *name; #endif { return DefErrSetForC1(0,f,subst,name); } /* Define a new error set. WARNING...set-implementation dependent; * Only used when -CC on. */ int #ifdef __USE_PROTOS DefErrSetForCC1(int nilOK, set *f, int subst, char *name ) #else DefErrSetForCC1(nilOK, f, subst, name ) int nilOK; /* MR13 */ set *f; int subst; /* should be substitute error classes? */ char *name; #endif { unsigned *p, *endp; int e=1; if (!nilOK) require(!set_nil(*f), "DefErrSet: nil set to dump?"); if ( subst ) SubstErrorClass(f); p = f->setword; endp = &(f->setword[f->n]); esetnum++; if ( name!=NULL ) { fprintf(Parser_h, "\tstatic SetWordType %s_set[%d];\n", name, NumWords(TokenNum-1)*sizeof(unsigned)); fprintf(Parser_c, "SetWordType %s::%s_set[%d] = {", CurrentClassName, name, NumWords(TokenNum-1)*sizeof(unsigned)); } else { fprintf(Parser_c, "SetWordType %s::err%d[%d] = {", CurrentClassName, esetnum, NumWords(TokenNum-1)*sizeof(unsigned)); fprintf(Parser_h, "\tstatic SetWordType err%d[%d];\n", esetnum, NumWords(TokenNum-1)*sizeof(unsigned)); } while ( p < endp ) { if ( e > 1 ) fprintf(Parser_c, ", "); DumpIntAsChars(Parser_c, "0x%x", *p++); if ( e == 3 ) { if ( p < endp ) fprintf(Parser_c, ","); fprintf(Parser_c, "\n\t"); e=1; } else e++; } fprintf(Parser_c, "};\n"); return esetnum; } int #ifdef __USE_PROTOS DefErrSetForCC( set *f, int subst, char *name ) #else DefErrSetForCC( f, subst, name ) set *f; int subst; /* should be substitute error classes? */ char *name; #endif { return DefErrSetForCC1(0,f,subst,name); } void #ifdef __USE_PROTOS GenParser_c_Hdr(void) #else GenParser_c_Hdr() #endif { int i,j; TermEntry *te; fprintf(Parser_c, "/*\n"); fprintf(Parser_c, " * %s: P a r s e r S u p p o r t\n", CurrentClassName); fprintf(Parser_c, " *\n"); fprintf(Parser_c, " * Generated from:"); for (i=0; i=LastTokenCounted ) { fprintf(Parser_c, ",\n\t/* %02d */\t\"invalid\"", i); continue; } if ( TokenString(i) != NULL ) { te=(TermEntry *) hash_get(Tname,TokenString(i)); /* MR11 */ if (te == NULL || te->akaString == NULL) { /* MR11 */ fprintf(Parser_c, ",\n\t/* %02d */\t\"%s\"", i, TokenString(i)); } else { fprintf(Parser_c, ",\n\t/* %02d */\t\"%s\"", i, te->akaString); /* MR11 */ } } else { /* look in all lexclasses for the reg expr */ for (j=0; j=NumLexClasses ) { if ( UserDefdTokens ) { fprintf(Parser_c, ",\n\t/* %02d */\t\"\"", i); } else fatal_internal(eMsgd("No label or expr for token %d",i)); } } } fprintf(Parser_c, "\n};\n"); /* Build constructors */ fprintf(Parser_c, "\n%s::", CurrentClassName); fprintf(Parser_c, "%s(ANTLRTokenBuffer *input) : ANTLRParser(input,%d,%d,%d,%d)\n", CurrentClassName, OutputLL_k, FoundGuessBlk, DemandLookahead, NumWords(TokenNum-1)*sizeof(unsigned)); fprintf(Parser_c, "{\n"); fprintf(Parser_c, "\ttoken_tbl = _token_tbl;\n"); if (TraceGen) { fprintf(Parser_c, "\ttraceOptionValueDefault=1;\t\t// MR10 turn trace ON\n"); } else { fprintf(Parser_c, "\ttraceOptionValueDefault=0;\t\t// MR10 turn trace OFF\n"); }; fprintf(Parser_c, "}\n\n"); } void #ifdef __USE_PROTOS GenParser_h_Hdr(void) #else GenParser_h_Hdr() #endif { int i; fprintf(Parser_h, "/*\n"); fprintf(Parser_h, " * %s: P a r s e r H e a d e r \n", CurrentClassName); fprintf(Parser_h, " *\n"); fprintf(Parser_h, " * Generated from:"); for (i=0; i 1 ) fprintf(ErrFile, "#define LL_K %d\n", OutputLL_k); #ifdef DUM if ( LexGen ) fprintf(ErrFile, "#define zzEOF_TOKEN %d\n", (TokenInd!=NULL?TokenInd[EofToken]:EofToken)); #endif fprintf(ErrFile, "#define zzSET_SIZE %d\n", NumWords(TokenNum-1)*sizeof(unsigned)); if ( DemandLookahead ) fprintf(ErrFile, "#define DEMAND_LOOK\n"); fprintf(ErrFile, "#include \"antlr.h\"\n"); if ( GenAST ) fprintf(ErrFile, "#include \"ast.h\"\n"); if ( UserDefdTokens ) fprintf(ErrFile, "#include %s\n", UserTokenDefsFile); /* still need this one as it has the func prototypes */ fprintf(ErrFile, "#include \"%s\"\n", DefFileName); fprintf(ErrFile, "#include \"dlgdef.h\"\n"); fprintf(ErrFile, "#include \"err.h\"\n\n"); /* Dump a zztokens for each automaton */ if ( strcmp(ParserName, DefaultParserName)!=0 ) { fprintf(ErrFile, "ANTLRChar *%s_zztokens[%d]={\n", ParserName, TokenNum-1); } else { fprintf(ErrFile, "ANTLRChar *zztokens[%d]={\n", TokenNum-1); } fprintf(ErrFile, "\t/* 00 */\t\"Invalid\""); for (i=1; i=LastTokenCounted ) { fprintf(ErrFile, ",\n\t/* %02d */\t\"invalid\"", i); continue; } if ( TokenString(i) != NULL ) { te=(TermEntry *) hash_get(Tname,TokenString(i)); /* MR11 */ if (te == NULL || te->akaString == NULL) { /* MR11 */ fprintf(ErrFile, ",\n\t/* %02d */\t\"%s\"", i, TokenString(i)); } else { fprintf(ErrFile, ",\n\t/* %02d */\t\"%s\"", i, te->akaString); /* MR11 */ } } else { /* look in all lexclasses for the reg expr */ for (j=0; j=NumLexClasses ) { if ( UserDefdTokens ) { fprintf(ErrFile, ",\n\t/* %02d */\t\"\"", i); } else fatal_internal(eMsgd("No label or expr for token %d",i)); } } } fprintf(ErrFile, "\n};\n"); } void #ifdef __USE_PROTOS dumpExpr( FILE *f, char *e ) #else dumpExpr( f, e ) FILE *f; char *e; #endif { while ( *e!='\0' ) { if ( *e=='\\' && *(e+1)=='\\' ) {putc('\\', f); putc('\\', f); e+=2;} else if ( *e=='\\' && *(e+1)=='"' ) {putc('\\', f); putc('"', f); e+=2;} else if ( *e=='\\' ) {putc('\\', f); putc('\\', f); e++;} else {putc(*e, f); e++;} } } cccc-3.1.4/pccts/antlr/build.c0000644000000000000000000004552707265347534014643 0ustar rootroot/* * 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-1998 */ #include #include #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" #define SetBlk(g, t, approx) { \ ((Junction *)g.left)->jtype = t; \ ((Junction *)g.left)->approx = approx; \ ((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 ) #else makeOpt( g1, approx ) Graph g1; int approx; #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 */ g = emptyAlt(); 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); 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 ) #else makeBlk( g1, approx ) Graph g1; int approx; #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); 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 ) #else makeLoop( g1, approx ) Graph g1; int approx; #endif { Junction *back, *front, *begin; Graph g; require(g1.left != NULL && g1.right != NULL, "makeLoop: invalid graph"); back = newJunction(); front = newJunction(); begin = newJunction(); g = emptyAlt(); ((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); 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 ) #else makePlus( g1, approx ) Graph g1; int approx; #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); ((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; } /* 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 #include #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); } } } cccc-3.1.4/pccts/antlr/dumpnode.c0000644000000000000000000002131707265347537015351 0ustar rootroot#include #include #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; iexpr == 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; iscontext[1]); for (i=0; itcontext); 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->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,"#%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; } cccc-3.1.4/pccts/antlr/egman.c0000644000000000000000000002167607265347545014634 0ustar rootroot/* * 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 * 1998 * */ #include #include #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 atlID 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) { 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,eg->altID); #endif if (BlkLevel != i || innerAlt->curAltNum == CurAltNum) { 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; 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); #endif alt->curAltNum=CurAltNum; 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; ipendingLink; 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; }; } cccc-3.1.4/pccts/antlr/err.c0000644000000000000000000002643707265347550014331 0ustar rootroot/* * 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-1999 * Parr Research Corporation * with Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include "pcctscfg.h" #include "set.h" #include #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[156]={ /* 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 */ "{\\}#header", /* 93 */ "{\\}#first", /* 94 */ "{\\}#parser", /* 95 */ "{\\}#tokdefs", /* 96 */ "\\}", /* 97 */ "class", /* 98 */ "NonTerminal", /* 99 */ "TokenTerm", /* 100 */ "\\{", /* 101 */ "!", /* 102 */ "\\<", /* 103 */ "\\>", /* 104 */ ":", /* 105 */ ";", /* 106 */ "{\\}#lexaction", /* 107 */ "{\\}#lexmember", /* 108 */ "{\\}#lexprefix", /* 109 */ "{\\}#pred", /* 110 */ "\\|\\|", /* 111 */ "&&", /* 112 */ "\\(", /* 113 */ "\\)", /* 114 */ "{\\}#lexclass", /* 115 */ "{\\}#errclass", /* 116 */ "{\\}#tokclass", /* 117 */ "..", /* 118 */ "{\\}#token", /* 119 */ "=", /* 120 */ "[0-9]+", /* 121 */ "\\|", /* 122 */ "\\~", /* 123 */ "^", /* 124 */ "{\\}#pragma", /* 125 */ "approx", /* 126 */ "LL\\(1\\)", /* 127 */ "LL\\(2\\)", /* 128 */ "\\*", /* 129 */ "\\+", /* 130 */ "?", /* 131 */ "=>", /* 132 */ "exception", /* 133 */ "default", /* 134 */ "catch", /* 135 */ "{\\}#[A-Za-z0-9_]*", /* 136 */ "[\\t\\ ]+", /* 137 */ "\\n|\\r|\\r\\n", /* 138 */ "//", /* 139 */ "/\\*", /* 140 */ "#ifdef", /* 141 */ "#if", /* 142 */ "#ifndef", /* 143 */ "#else", /* 144 */ "#endif", /* 145 */ "#undef", /* 146 */ "#import", /* 147 */ "ID", /* 148 */ "#define", /* 149 */ "INT", /* 150 */ "enum", /* 151 */ "\\{", /* 152 */ "=", /* 153 */ ",", /* 154 */ "\\}", /* 155 */ ";" }; SetWordType zzerr1[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0xc,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr2[20] = {0xfc,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xf3, 0xef,0xff,0xff,0xff, 0xff,0xff,0xff,0xf}; SetWordType setwd1[156] = {0x0,0x50,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,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,0x21,0x21,0x21, 0x21,0x6e,0x6e,0x64,0x20,0x0,0x20,0xa0, 0x20,0x20,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,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 zzerr3[20] = {0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x28,0x0,0x1,0x0, 0x0,0x0,0x0,0x0}; SetWordType setwd2[156] = {0x0,0xcf,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xcf,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0xcf,0xcf,0xcf,0x30,0x0,0x30,0x0, 0x0,0x0,0x80,0xcf,0xcf,0xcf,0xcf,0x0, 0x0,0x30,0x80,0xcf,0xcf,0xcf,0x0,0xcf, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0xce,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0}; SetWordType zzerr4[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x28,0x0,0x1,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr5[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr6[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0xc,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr7[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0xc,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr8[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType setwd3[156] = {0x0,0xd7,0x28,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd7,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0xd7,0xd7,0xdf,0x28,0x0,0x0,0x0, 0x0,0x0,0x3,0xd7,0xd7,0xd7,0xd7,0x3, 0x2,0x0,0x3,0xd7,0xd7,0xd7,0x0,0xd7, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0xd7,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0}; SetWordType zzerr9[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr10[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd, 0x0,0x0,0x0,0x0, 0x10,0x0,0x0,0x0}; SetWordType zzerr11[20] = {0x4,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x8,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr12[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xd, 0x0,0x0,0x0,0x0, 0x10,0x0,0x0,0x0}; SetWordType zzerr13[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xc, 0x0,0x0,0x0,0x0, 0x10,0x0,0x0,0x0}; SetWordType setwd4[156] = {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,0xe2,0xe2,0xe2,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 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,0x60,0xf2,0x0,0x0,0x0,0x0,0x0, 0x0,0xe5,0x0,0xfa,0xfa,0xe2,0x0,0x0, 0xe2,0x0,0xe5,0x0,0x0,0x0,0x0,0x0, 0x0,0xe2,0xe5,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0xe4,0xe2,0x0,0xe2,0x0,0x0, 0x0,0xe2,0xe2,0x0,0x0,0xe4,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,0x80,0x0, 0xc,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr15[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0xe0, 0x0,0x0,0x0,0x0}; SetWordType zzerr16[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x80,0x0,0x0, 0x8,0x0,0x0,0x0}; SetWordType zzerr17[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4, 0x1,0x82,0x2,0x6, 0x18,0x0,0x0,0x0}; SetWordType zzerr18[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4, 0x1,0x2,0x2,0x6, 0x14,0x0,0x0,0x0}; SetWordType zzerr19[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x10,0x0,0x1,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr20[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x4, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr21[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0xc,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType setwd5[156] = {0x0,0x80,0x38,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,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,0x38,0x39,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x38,0x0,0x38,0x0,0x0,0x0,0x0,0x0, 0x0,0xf8,0xc0,0xf8,0x38,0x3a,0x0,0x1, 0x38,0x0,0xb8,0xc0,0xc0,0xc0,0xc0,0x0, 0x4,0x3a,0xb8,0xc0,0xc0,0xc0,0x0,0xc0, 0x0,0x0,0xb8,0x38,0x0,0x3a,0x0,0x0, 0x0,0x38,0x38,0x0,0x4,0xf8,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] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x50,0x0}; SetWordType zzerr23[20] = {0x2,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x40,0x50,0x0}; SetWordType zzerr24[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x7}; SetWordType zzerr25[20] = {0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x7}; SetWordType setwd6[156] = {0x0,0x4d,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,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,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,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,0x1,0x1,0x0,0x0,0x0,0x0, 0x0,0x0,0x1,0x1,0x1,0x1,0x1,0x0, 0x0,0x0,0x1,0x1,0x1,0x1,0x0,0x1, 0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x1, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2, 0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x42, 0x0,0x0,0x30,0x30,0x0}; cccc-3.1.4/pccts/antlr/fcache.c0000644000000000000000000000555007265347550014743 0ustar rootroot/* * 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 #include #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"); } cccc-3.1.4/pccts/antlr/fset.c0000644000000000000000000014761007265347575014506 0ustar rootroot/* * fset.c * * Compute FIRST and FOLLOW sets. * * 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-1998 */ #include #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" #include "limits.h" #ifdef __USE_PROTOS static void ensure_predicates_cover_ambiguous_lookahead_sequences (Junction *, Junction *, char *, Tree *); #else static void ensure_predicates_cover_ambiguous_lookahead_sequences(); #endif /* * What tokens are k tokens away from junction q? * * Follow both p1 and p2 paths (unless RuleBlk) to collect the tokens k away from this * node. * We lock the junction according to k--the lookahead. If we have been at this * junction before looking for the same, k, number of lookahead tokens, we will * do it again and again...until we blow up the stack. Locks are only used on aLoopBlk, * RuleBlk, aPlusBlk and EndRule junctions to remove/detect infinite recursion from * FIRST and FOLLOW calcs. * * If p->jtype == EndRule we are going to attempt a FOLLOW. (FOLLOWs are really defined * in terms of FIRST's, however). To proceed with the FOLLOW, p->halt cannot be * set. p->halt is set to indicate that a reference to the current rule is in progress * and the FOLLOW is not desirable. * * If we attempt a FOLLOW and find that there is no FOLLOW or REACHing beyond the EndRule * junction yields an empty set, replace the empty set with EOF. No FOLLOW means that * only EOF can follow the current rule. This normally occurs only on the start symbol * since all other rules are referenced by another rule somewhere. * * Normally, both p1 and p2 are followed. However, checking p2 on a RuleBlk node is * the same as checking the next rule which is clearly incorrect. * * Cycles in the FOLLOW sense are possible. e.g. Fo(c) requires Fo(b) which requires * Fo(c). Both Fo(b) and Fo(c) are defined to be Fo(b) union Fo(c). Let's say * Fo(c) is attempted first. It finds all of the FOLLOW symbols and then attempts * to do Fo(b) which finds of its FOLLOW symbols. So, we have: * * Fo(c) * / \ * a set Fo(b) * / \ * a set Fo(c) .....Hmmmm..... Infinite recursion! * * The 2nd Fo(c) is not attempted and Fo(b) is left deficient, but Fo(c) is now * correctly Fo(c) union Fo(b). We wish to pick up where we left off, so the fact * that Fo(b) terminated early means that we lack Fo(c) in the Fo(b) set already * laying around. SOOOOoooo, we track FOLLOW cycles. All FOLLOW computations are * cached in a hash table. After the sequence of FOLLOWs finish, we reconcile all * cycles --> correct all Fo(rule) sets in the cache. * * Confused? Good! Read my MS thesis [Purdue Technical Report TR90-30]. * TJP 8/93 -- can now read PhD thesis from Purdue. * * Also, FIRST sets are cached in the hash table. Keys are (rulename,Fi/Fo,k). * Only FIRST sets, for which the FOLLOW is not included, are stored. * * SPECIAL CASE of (...)+ blocks: * I added an optional alt so that the alts could see what * was behind the (...)+ block--thus using enough lookahead * to branch out rather than just enough to distinguish * between alts in the (...)+. However, when the FIRST("(...)+") is * is needed, must not use this last "optional" alt. This routine * turns off this path by setting a new 'ignore' flag for * the alt and then resetting it afterwards. */ set #ifdef __USE_PROTOS rJunc( Junction *p, int k, set *rk ) #else rJunc( p, k, rk ) Junction *p; int k; set *rk; #endif { set a, b; require(p!=NULL, "rJunc: NULL node"); require(p->ntype==nJunction, "rJunc: not junction"); #ifdef DBG_LL1 if ( p->jtype == RuleBlk ) fprintf(stderr, "FIRST(%s,%d) \n",((Junction *)p)->rname,k); else fprintf(stderr, "rJunc: %s in rule %s\n", decodeJType[p->jtype], ((Junction *)p)->rname); #endif /* if this is one of the added optional alts for (...)+ then return */ /* no need to pop backtrace - hasn't been pushed */ if ( p->ignore ) return empty; if (MR_MaintainBackTrace) MR_pointerStackPush(&MR_BackTraceStack,p); /* MR14 */ if (AlphaBetaTrace && p->alpha_beta_guess_end) { /* MR14 */ warnFL( /* MR14 */ "not possible to compute follow set for alpha in an \"(alpha)? beta\" block. ", /* MR14 */ FileStr[p->file],p->line); /* MR14 */ MR_alphaBetaTraceReport(); /* MR14 */ }; /* MR14 */ if (p->alpha_beta_guess_end) { /* MR14 */ if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); /* MR14 */ return empty; /* MR14 */ } /* locks are valid for aLoopBlk,aPlusBlk,RuleBlk,EndRule junctions only */ if ( p->jtype==aLoopBlk || p->jtype==RuleBlk || p->jtype==aPlusBlk || p->jtype==EndRule ) { require(p->lock!=NULL, "rJunc: lock array is NULL"); if ( p->lock[k] ) { if ( p->jtype == EndRule ) /* FOLLOW cycle? */ { #ifdef DBG_LL1 fprintf(stderr, "FOLLOW cycle to %s: panic!\n", p->rname); #endif if (! MR_AmbSourceSearch) RegisterCycle(p->rname, k); } if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return empty; } if ( p->jtype == RuleBlk && p->end->halt && ! MR_AmbSourceSearch) /* check for FIRST cache */ { CacheEntry *q = (CacheEntry *) hash_get(Fcache, Fkey(p->rname,'i',k)); if ( q != NULL ) { set_orin(rk, q->rk); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return set_dup( q->fset ); } } if ( p->jtype == EndRule && !p->halt && /* MR11 was using cache even when halt set */ ! MR_AmbSourceSearch) /* FOLLOW set cached already? */ { CacheEntry *q = (CacheEntry *) hash_get(Fcache, Fkey(p->rname,'o',k)); if ( q != NULL ) { #ifdef DBG_LL1 fprintf(stderr, "cache for FOLLOW(%s,%d):", p->rname,k); s_fprT(stderr, q->fset); if ( q->incomplete ) fprintf(stderr, " (incomplete)"); fprintf(stderr, "\n"); #endif if ( !q->incomplete ) { if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return set_dup( q->fset ); } } } p->lock[k] = TRUE; /* This rule is busy */ } a = b = empty; if ( p->jtype == EndRule ) { if (p->halt ) /* don't want FOLLOW here? */ /* unless MR10 hoisting */ { p->lock[k] = FALSE; set_orel(k, rk); /* indicate this k value needed */ if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return empty; } if (! MR_AmbSourceSearch) FoPush(p->rname, k); /* Attempting FOLLOW */ if ( p->p1 == NULL ) set_orel((TokenInd!=NULL?TokenInd[EofToken]:EofToken), &a);/* if no FOLLOW assume EOF */ #ifdef DBG_LL1 fprintf(stderr, "-->FOLLOW(%s,%d)\n", p->rname,k); #endif } if ( p->p1 != NULL ) { /* MR14 */ if (p->guess) { /* MR14 */ if (p->guess_analysis_point == NULL) { /* MR14 */ Node * guess_point; /* MR14 */ guess_point=(Node *)analysis_point(p); /* MR14 */ if (guess_point == (Node *)p) { /* MR14 */ guess_point=p->p1; /* MR14 */ } /* MR14 */ p->guess_analysis_point=guess_point; /* MR14 */ } /* MR14 */ REACH(p->guess_analysis_point, k, rk, a); } else { REACH(p->p1, k, rk, a); } } /* C a c h e R e s u l t s */ if ( p->jtype == RuleBlk && p->end->halt && ! MR_AmbSourceSearch) /* can save FIRST set? */ { CacheEntry *q = newCacheEntry( Fkey(p->rname,'i',k) ); /*fprintf(stderr, "Caching %s FIRST %d\n", p->rname, k);*/ hash_add(Fcache, Fkey(p->rname,'i',k), (Entry *)q); q->fset = set_dup( a ); q->rk = set_dup( *rk ); } if ( p->jtype == EndRule && !p->halt && /* MR11 was using cache even with halt set */ ! MR_AmbSourceSearch) /* just completed FOLLOW? */ { /* Cache Follow set */ CacheEntry *q = (CacheEntry *) hash_get(Fcache, Fkey(p->rname,'o',k)); if ( q==NULL ) { q = newCacheEntry( Fkey(p->rname,'o',k) ); hash_add(Fcache, Fkey(p->rname,'o',k), (Entry *)q); } /*fprintf(stderr, "Caching %s FOLLOW %d\n", p->rname, k);*/ if ( set_nil(a) && !q->incomplete ) { /* Don't ever save a nil set as complete. * Turn it into an eof set. */ set_orel(EofToken, &a); } set_orin(&(q->fset), a); FoPop( k ); if ( FoTOS[k] == NULL && Cycles[k] != NULL ) ResolveFoCycles(k); #ifdef DBG_LL1 fprintf(stderr, "saving FOLLOW(%s,%d):", p->rname, k); s_fprT(stderr, q->fset); if ( q->incomplete ) fprintf(stderr, " (incomplete)"); fprintf(stderr, "\n"); #endif } if (p->jtype != RuleBlk && p->p2 != NULL && /* MR14 */ ! p->guess) { REACH(p->p2, k, rk, b); } if ( p->jtype==aLoopBlk || p->jtype==RuleBlk || p->jtype==aPlusBlk || p->jtype==EndRule ) p->lock[k] = FALSE; /* unlock node */ set_orin(&a, b); set_free(b); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return a; } set #ifdef __USE_PROTOS rRuleRef( RuleRefNode *p, int k, set *rk_out ) #else rRuleRef( p, k, rk_out ) RuleRefNode *p; int k; set *rk_out; #endif { set rk; Junction *r; int k2; set a, rk2, b; int save_halt; RuleEntry *q = (RuleEntry *) hash_get(Rname, p->text); require(p!=NULL, "rRuleRef: NULL node"); require(p->ntype==nRuleRef, "rRuleRef: not rule ref"); #ifdef DBG_LL1 fprintf(stderr, "rRuleRef: %s\n", p->text); #endif if (MR_MaintainBackTrace) MR_pointerStackPush(&MR_BackTraceStack,p); if ( q == NULL ) { warnFL( eMsg1("rule %s not defined",p->text), FileStr[p->file], p->line ); REACH(p->next, k, rk_out, a); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return a; } rk2 = empty; /* MR9 Problems with rule references in guarded predicates */ /* MR9 Perhaps can use hash table to find rule ? */ /* MR9 */ if (RulePtr == NULL) { /* MR9 */ fatalFL(eMsg2("Rule %s uses rule %s via RulePtr before it has been initialized", /* MR9 */ p->rname,q->str),FileStr[p->file],p->line); /* MR9 */ }; r = RulePtr[q->rulenum]; if ( r->lock[k] ) { errNoFL( eMsg2("infinite left-recursion to rule %s from rule %s", r->rname, p->rname) ); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return empty; } save_halt = r->end->halt; r->end->halt = TRUE; /* don't let reach fall off end of rule here */ rk = empty; REACH(r, k, &rk, a); r->end->halt = save_halt; while ( !set_nil(rk) ) { k2 = set_int(rk); /* MR11 this messes up the ambiguity search routine */ set_rm(k2, rk); REACH(p->next, k2, &rk2, b); /* MR11 by changing the value of k */ set_orin(&a, b); set_free(b); } set_free(rk); /* this has no members, but free it's memory */ set_orin(rk_out, rk2); /* remember what we couldn't do */ set_free(rk2); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return a; } /* * Return FIRST sub k ( token_node ) * * TJP 10/11/93 modified this so that token nodes that are actually * ranges (T1..T2) work. */ set #ifdef __USE_PROTOS rToken( TokNode *p, int k, set *rk ) #else rToken( p, k, rk ) TokNode *p; int k; set *rk; #endif { set a; require(p!=NULL, "rToken: NULL node"); require(p->ntype==nToken, "rToken: not token node"); #ifdef DBG_LL1 fprintf(stderr, "rToken: %s\n", (TokenString(p->token)!=NULL)?TokenString(p->token): ExprString(p->token)); #endif if (MR_MaintainBackTrace) MR_pointerStackPush(&MR_BackTraceStack,p); if (MR_AmbSourceSearch && (k-1) == 0) { set localConstrain; set intersection; localConstrain=fset[maxk-k+1]; if (! set_nil(p->tset)) { intersection=set_and(localConstrain,p->tset); if (! set_nil(intersection)) { MR_backTraceReport(); }; set_free(intersection); } else { if (set_el( (unsigned) p->token,localConstrain)) { MR_backTraceReport(); } }; }; if ( k-1 == 0 ) { if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); if ( !set_nil(p->tset) ) { return set_dup(p->tset); } else { return set_of(p->token); }; } REACH(p->next, k-1, rk, a); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return a; } set #ifdef __USE_PROTOS rAction( ActionNode *p, int k, set *rk ) #else rAction( p, k, rk ) ActionNode *p; int k; set *rk; #endif { set a; require(p!=NULL, "rJunc: NULL node"); require(p->ntype==nAction, "rJunc: not action"); /* MR11 */ if (p->is_predicate && p->ampersandPred != NULL) { /* MR11 */ Predicate *pred=p->ampersandPred; /* MR11 */ if (k <= pred->k) { /* MR11 */ REACH(p->guardNodes,k,rk,a); /* MR11 */ return a; /* MR11 */ }; /* MR11 */ }; /* it might be a good idea when doing an MR_AmbSourceSearch to *not* look behind predicates under some circumstances we'll look into that later */ REACH(p->next, k, rk, a); /* ignore actions */ return a; } /* A m b i g u i t y R e s o l u t i o n */ void #ifdef __USE_PROTOS dumpAmbigMsg( set *fset, FILE *f, int want_nls ) #else dumpAmbigMsg( fset, f, want_nls ) set *fset; FILE *f; int want_nls; #endif { int i; set copy; /* MR11 */ if ( want_nls ) fprintf(f, "\n\t"); else fprintf(f, " "); for (i=1; i<=CLL_k; i++) { copy=set_dup(fset[i]); /* MR11 */ if ( i>1 ) { if ( !want_nls ) fprintf(f, ", "); } if ( set_deg(copy) > 3 && elevel == 1 ) { int e,m; fprintf(f, "{"); for (m=1; m<=3; m++) { e=set_int(copy); fprintf(f, " %s", TerminalString(e)); set_rm(e, copy); } fprintf(f, " ... }"); } else s_fprT(f, copy); if ( want_nls ) fprintf(f, "\n\t"); set_free(copy); } fprintf(f, "\n"); } static void #ifdef __USE_PROTOS verify_context(Predicate *predicate) #else verify_context(predicate) Predicate *predicate; #endif { if ( predicate == NULL ) return; if ( predicate->expr == PRED_OR_LIST || predicate->expr == PRED_AND_LIST ) { verify_context(predicate->down); verify_context(predicate->right); /* MR10 */ return; } if ( !predicate->source->ctxwarned && predicate->source->guardpred==NULL && ((predicate->k > 1 && !is_single_tuple(predicate->tcontext)) || ( predicate->k == 1 && set_deg(predicate->scontext[1])>1 )) ) { /* MR9 Suppress annoying messages caused by our own clever(?) fix */ fprintf(stderr, ErrHdr, FileStr[predicate->source->file], predicate->source->line); fprintf(stderr, " warning: predicate applied for >1 lookahead %d-sequences\n", predicate->k); fprintf(stderr, ErrHdr, FileStr[predicate->source->file], predicate->source->line); fprintf(stderr, " predicate text: \"%s\"\n", (predicate->expr == NULL ? "(null)" : predicate->expr) ); fprintf(stderr, ErrHdr, FileStr[predicate->source->file], predicate->source->line); fprintf(stderr, " You may only want one lookahead %d-sequence to apply\n", predicate->k); fprintf(stderr, ErrHdr, FileStr[predicate->source->file], predicate->source->line); fprintf(stderr, " Try using a context guard '(...)? =>'\n"); predicate->source->ctxwarned = 1; } verify_context(predicate->right); /* MR10 */ } /* * If delta is the set of ambiguous lookahead sequences, then make sure that * the predicate(s) for productions alt1,alt2 cover the sequences in delta. * * For example, * a : <>? (A B|A C) * | b * ; * b : <>? A B * | A C * ; * * This should give a warning that (A C) predicts both productions and alt2 * does not have a predicate in the production that generates (A C). * * The warning detection is simple. Let delta = LOOK(alt1) intersection LOOK(alt2). * Now, if ( delta set-difference context(predicates-for-alt1) != empty then * alt1 does not "cover" all ambiguous sequences. * * If ambig is nonempty, then ambig in LL(k) sense -> use tree info; else use fset * info. Actually, sets are used only if k=1 for this grammar. */ static void #ifdef __USE_PROTOS ensure_predicates_cover_ambiguous_lookahead_sequences ( Junction *alt1, Junction *alt2, char *sub, Tree *ambig ) #else ensure_predicates_cover_ambiguous_lookahead_sequences( alt1, alt2, sub, ambig ) Junction *alt1; Junction *alt2; char *sub; Tree *ambig; #endif { if ( !ParseWithPredicates ) return; if ( ambig!=NULL ) { Tree *non_covered = NULL; if ( alt1->predicate!=NULL ) non_covered = tdif(ambig, alt1->predicate, alt1->fset, alt2->fset); if ( (non_covered!=NULL || alt1->predicate==NULL) && WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); fprintf(stderr, " warning: alt %d %shas no predicate to resolve ambiguity", alt1->altnum, sub); if ( alt1->predicate!=NULL && non_covered!=NULL ) { fprintf(stderr, " upon"); preorder(non_covered); } else if ( alt1->predicate==NULL ) { fprintf(stderr, " upon"); preorder(ambig->down); } fprintf(stderr, "\n"); } Tfree(non_covered); non_covered = NULL; if ( alt2->predicate!=NULL ) non_covered = tdif(ambig, alt2->predicate, alt1->fset, alt2->fset); if ( (non_covered!=NULL || alt2->predicate==NULL) && WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt2->file], alt2->line); fprintf(stderr, " warning: alt %d %shas no predicate to resolve ambiguity", alt2->altnum, sub); if ( alt2->predicate!=NULL && non_covered!=NULL ) { fprintf(stderr, " upon"); preorder(non_covered); } else if ( alt2->predicate==NULL ) { fprintf(stderr, " upon"); preorder(ambig->down); } fprintf(stderr, "\n"); } Tfree(non_covered); } else if ( !set_nil(alt1->fset[1]) ) { set delta, non_covered; delta = set_and(alt1->fset[1], alt2->fset[1]); non_covered = set_dif(delta, covered_set(alt1->predicate)); if ( set_deg(non_covered)>0 && WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); fprintf(stderr, " warning: alt %d %shas no predicate to resolve ambiguity", alt1->altnum, sub); if ( alt1->predicate!=NULL ) { fprintf(stderr, " upon "); s_fprT(stderr, non_covered); } fprintf(stderr, "\n"); } set_free( non_covered ); non_covered = set_dif(delta, covered_set(alt2->predicate)); if ( set_deg(non_covered)>0 && WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt2->file], alt2->line); fprintf(stderr, " warning: alt %d %shas no predicate to resolve ambiguity", alt2->altnum, sub); if ( alt2->predicate!=NULL ) { fprintf(stderr, " upon "); s_fprT(stderr, non_covered); } fprintf(stderr, "\n"); } set_free( non_covered ); set_free( delta ); } else fatal_internal("productions have no lookahead in predicate checking routine"); } #ifdef __USE_PROTOS void MR_doPredicatesHelp(int inGuessBlock,Junction *alt1,Junction *alt2,int jtype,char *sub) #else void MR_doPredicatesHelp(inGuessBlock,alt1,alt2,jtype,sub) int inGuessBlock; Junction *alt1; Junction *alt2; int jtype; char *sub; #endif { Predicate *p1; Predicate *p2; Junction *parentRule=MR_nameToRuleBlk(alt1->rname); if (inGuessBlock && WarningLevel <= 1) return; /* let antlr give the usual error message */ if (alt1->predicate == NULL && alt2->predicate == NULL) return; if ( (jtype == RuleBlk || jtype == aSubBlk) && (alt1->predicate == NULL && alt2->predicate != NULL)) { fprintf(stderr, ErrHdr, FileStr[parentRule->file],parentRule->line); fprintf(stderr," warning: alt %d line %d and alt %d line %d of %s\n%s%s%s", alt1->altnum, alt1->line, alt2->altnum, alt2->line, sub, " These alts have ambig lookahead sequences resolved by a predicate for\n", " the second choice. The second choice may not be reachable.\n", " You may want to use a complementary predicate or rearrange the alts\n" ); return; }; /* first do the easy comparison. then do the hard one */ if (MR_comparePredicates(alt1->predicate,alt2->predicate)) { if (jtype == aLoopBegin || jtype == aPlusBlk ) { /* I'm not sure this code is reachable. Predicates following a (...)+ or (...)* block are probably considered validation predicates and therefore not participate in the predication expression */ fprintf(stderr, ErrHdr,FileStr[parentRule->file],parentRule->line); fprintf(stderr," warning: %s of %s in rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s", "the predicates used to disambiguate optional/exit paths of ", sub, CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " are identical and have no resolving power\n"); } else { fprintf(stderr, ErrHdr, FileStr[parentRule->file], parentRule->line); fprintf(stderr," warning: %s rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s", "the predicates used to disambiguate", CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " are identical and have no resolving power\n"); }; } else { p1=predicate_dup_without_context(alt1->predicate); p1=MR_unfold(p1); MR_clearPredEntry(p1); MR_simplifyInverted(p1,0); p1=MR_predSimplifyALL(p1); p2=predicate_dup_without_context(alt2->predicate); p2=MR_unfold(p2); MR_clearPredEntry(p2); MR_simplifyInverted(p2,0); p2=MR_predSimplifyALL(p2); if (MR_comparePredicates(p1,p2)) { if (jtype == aLoopBegin || jtype == aPlusBlk ) { fprintf(stderr, ErrHdr, FileStr[parentRule->file], parentRule->line); fprintf(stderr," warning: %s of %s in rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s%s", "the predicates used to disambiguate optional/exit paths of ", sub, CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " are identical when compared without context and may have no\n", " resolving power for some lookahead sequences.\n"); } else { fprintf(stderr, ErrHdr, FileStr[parentRule->file], parentRule->line); fprintf(stderr," warning: %s rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s%s", "the predicates used to disambiguate", CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " are identical when compared without context and may have no\n", " resolving power for some lookahead sequences.\n"); }; if (InfoP) { fprintf(output,"\n#if 0\n\n"); fprintf(output,"The following predicates are identical when compared without\n"); fprintf(output," lookahead context information. For some ambiguous lookahead\n"); fprintf(output," sequences they may not have any power to resolve the ambiguity.\n"); fprintf(output,"\n"); fprintf(output,"Choice 1: %s alt %d line %d file %s\n\n", MR_ruleNamePlusOffset( (Node *) alt1), alt1->altnum, alt1->line, FileStr[alt1->file]); fprintf(output," The original predicate for choice 1 with available context information:\n\n"); MR_dumpPred1(2,alt1->predicate,1); fprintf(output," The predicate for choice 1 after expansion (but without context information):\n\n"); MR_dumpPred1(2,p1,0); if (p1 == NULL) { Predicate *phelp; fprintf(output," The predicate for choice 1 after expansion (but before simplification)\n\n"); phelp=predicate_dup_without_context(alt1->predicate); phelp=MR_unfold(phelp); MR_clearPredEntry(phelp); MR_simplifyInverted(phelp,0); phelp=MR_predSimplifyALLX(phelp,1); MR_dumpPred1(2,phelp,0); predicate_free(phelp); }; fprintf(output,"\n"); fprintf(output,"Choice 2: %s alt %d line %d file %s\n\n", MR_ruleNamePlusOffset( (Node *) alt2), alt2->altnum, alt2->line, FileStr[alt2->file]); fprintf(output," The original predicate for choice 2 with available context information:\n\n"); MR_dumpPred1(1,alt2->predicate,1); fprintf(output," The predicate for choice 2 after expansion (but without context information):\n\n"); MR_dumpPred1(1,p2,0); if (p2 == NULL) { Predicate *phelp; fprintf(output," The predicate for choice 2 after expansion (but before simplification)\n\n"); phelp=predicate_dup_without_context(alt2->predicate); phelp=MR_unfold(phelp); MR_clearPredEntry(phelp); MR_simplifyInverted(phelp,0); phelp=MR_predSimplifyALLX(phelp,1); MR_dumpPred1(2,phelp,0); predicate_free(phelp); }; fprintf(output,"\n#endif\n"); }; } else if (MR_secondPredicateUnreachable(p1,p2)) { if (jtype == aLoopBegin || jtype == aPlusBlk ) { fprintf(stderr, ErrHdr, FileStr[parentRule->file], parentRule->line); fprintf(stderr," warning: %s of %s in rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s%s", "the predicate used to disambiguate the first choice of the optional/exit paths of ", sub, CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " appears to \"cover\" the second predicate when compared without context.\n", " The second predicate may have no resolving power for some lookahead sequences.\n"); } else { fprintf(stderr, ErrHdr, FileStr[parentRule->file], parentRule->line); fprintf(stderr," warning: %s rule %s\n (file %s alt %d line %d and alt %d line %d)\n%s%s", "the predicate used to disambiguate the first choice of", CurRule, FileStr[alt1->file], alt1->altnum, alt1->line, alt2->altnum, alt2->line, " appears to \"cover\" the second predicate when compared without context.\n", " The second predicate may have no resolving power for some lookahead sequences.\n"); }; if (InfoP) { fprintf(output,"\n#if 0\n\n"); fprintf(output,"The first predicate appears to \"cover\" the second predicate when they\n"); fprintf(output," are compared without lookahead context information. For some ambiguous\n"); fprintf(output," lookahead sequences the second predicate may not have any power to\n"); fprintf(output," resolve the ambiguity.\n"); fprintf(output,"\n"); fprintf(output,"Choice 1: %s alt %d line %d file %s\n\n", MR_ruleNamePlusOffset( (Node *) alt1), alt1->altnum, alt1->line, FileStr[alt1->file]); fprintf(output," The original predicate for choice 1 with available context information:\n\n"); MR_dumpPred1(2,alt1->predicate,1); fprintf(output," The predicate for choice 1 after expansion (but without context information):\n\n"); MR_dumpPred1(2,p1,0); if (p1 == NULL) { Predicate *phelp; fprintf(output," The predicate for choice 1 after expansion (but before simplification)\n\n"); phelp=predicate_dup_without_context(alt1->predicate); phelp=MR_unfold(phelp); MR_clearPredEntry(phelp); MR_simplifyInverted(phelp,0); phelp=MR_predSimplifyALLX(phelp,1); MR_dumpPred1(2,phelp,0); predicate_free(phelp); }; fprintf(output,"\n"); fprintf(output,"Choice 2: %s alt %d line %d file %s\n\n", MR_ruleNamePlusOffset( (Node *) alt2), alt2->altnum, alt2->line, FileStr[alt2->file]); fprintf(output," The original predicate for choice 2 with available context information:\n\n"); MR_dumpPred1(1,alt2->predicate,1); fprintf(output," The predicate for choice 2 after expansion (but without context information):\n\n"); MR_dumpPred1(1,p2,0); if (p2 == NULL) { Predicate *phelp; fprintf(output," The predicate for choice 2 after expansion (but before simplification)\n\n"); phelp=predicate_dup_without_context(alt2->predicate); phelp=MR_unfold(phelp); MR_clearPredEntry(phelp); MR_simplifyInverted(phelp,0); phelp=MR_predSimplifyALLX(phelp,1); MR_dumpPred1(2,phelp,0); predicate_free(phelp); }; fprintf(output,"\n#endif\n"); }; }; predicate_free(p1); predicate_free(p2); }; } static int totalOverflow=0; /* MR9 */ void #ifdef __USE_PROTOS HandleAmbiguity( Junction *block, Junction *alt1, Junction *alt2, int jtype ) #else HandleAmbiguity( block, alt1, alt2, jtype ) Junction *block; Junction *alt1; Junction *alt2; int jtype; #endif { unsigned **ftbl; set *fset, b; int i, numAmbig,n2; Tree *ambig=NULL, *t, *u; char *sub = ""; long n; int thisOverflow=0; /* MR9 */ long set_deg_value; /* MR10 */ long threshhold; /* MR10 */ require(block!=NULL, "NULL block"); require(block->ntype==nJunction, "invalid block"); /* These sets are used to constrain LL_k set, but are made CLL_k long anyway */ fset = (set *) calloc(CLL_k+1, sizeof(set)); require(fset!=NULL, "cannot allocate fset"); ftbl = (unsigned **) calloc(CLL_k+1, sizeof(unsigned *)); require(ftbl!=NULL, "cannot allocate ftbl"); /* create constraint table and count number of possible ambiguities (use<=LL_k) */ for (n=1,i=1; i<=CLL_k; i++) { b = set_and(alt1->fset[i], alt2->fset[i]); /* MR9 */ set_deg_value = set_deg(b); /* MR10 */ if (n > 0) { /* MR10 */ threshhold = LONG_MAX / n; /* MR10 */ if (set_deg_value <= threshhold) { /* MR10 */ n *= set_deg_value; /* MR10 */ } else { /* MR10 */ n=LONG_MAX; /* MR9 */ if (totalOverflow == 0) { #if 0 /* MR10 comment this out because it just makes users worry */ /* MR9 */ warnNoFL("Overflow in computing number of possible ambiguities in HandleAmbiguity\n"); #endif /* MR9 */ }; /* MR9 */ thisOverflow++; /* MR9 */ totalOverflow++; /* MR9 */ }; /* MR10 */ } else { /* MR10 */ n *= set_deg_value; /* MR9 */ }; fset[i] = set_dup(b); ftbl[i] = set_pdq(b); set_free(b); } switch ( jtype ) { case aSubBlk: sub = "of (..) "; break; case aOptBlk: sub = "of {..} "; break; case aLoopBegin: sub = "of (..)* "; break; case aLoopBlk: sub = "of (..)* "; break; case aPlusBlk: sub = "of (..)+ "; break; case RuleBlk: sub = "of the rule itself "; break; default : sub = ""; break; } /* If the block is marked as a compressed lookahead only block, then * simply return; ambiguity warning is given only at warning level 2. */ if ( block->approx>0 ) { if ( ParseWithPredicates ) { if (alt1->predicate != NULL) predicate_free(alt1->predicate); /* MR12 */ if (alt2->predicate != NULL) predicate_free(alt2->predicate); /* MR12 */ require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt1->predicate = MR_find_predicates_and_supp((Node *)alt1->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt1->predicate),"predicate alt 1 not completed"); alt1->predicate=MR_predSimplifyALL(alt1->predicate); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt2->predicate = MR_find_predicates_and_supp((Node *)alt2->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt2->predicate),"predicate alt 2 not completed"); alt2->predicate=MR_predSimplifyALL(alt2->predicate); MR_doPredicatesHelp(0,alt1,alt2,jtype,sub); if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) ) { verify_context(alt1->predicate); verify_context(alt2->predicate); } if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) && WarningLevel>1 ) ensure_predicates_cover_ambiguous_lookahead_sequences(alt1, alt2, sub, ambig); } if ( WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); if ( jtype == aLoopBegin || jtype == aPlusBlk ) fprintf(stderr, " warning: optional/exit path and alt(s) %sambiguous upon", sub); else fprintf(stderr, " warning(approx): alts %d and %d %sambiguous upon", alt1->altnum, alt2->altnum, sub); dumpAmbigMsg(fset, stderr, 0); MR_traceAmbSource(fset,alt1,alt2); } for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } /* if all sets have degree 1 for k=1 permutation; * don't bother doing full LL(k) analysis. * (This "if" block handles the LL(1) case) */ n2 = 0; for (i=1; ifset[i])+set_deg(alt2->fset[i]); /* here STARTS the special case in which the lookahead sets for alt1 and alt2 all have degree 1 for kp1)!=NULL ) { if ( WarningLevel==1 ) { for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); if ( jtype == aLoopBegin || jtype == aPlusBlk ) fprintf(stderr, " warning: optional/exit path and alt(s) %sambiguous upon", sub); else fprintf(stderr, " warning: alts %d and %d %sambiguous upon", alt1->altnum, alt2->altnum, sub); dumpAmbigMsg(fset, stderr, 0); MR_traceAmbSource(fset,alt1,alt2); } ambig = NULL; if ( LL_k>1 ) ambig = make_tree_from_sets(alt1->fset, alt2->fset); if ( ParseWithPredicates ) { if (alt1->predicate != NULL) predicate_free(alt1->predicate); /* MR12 */ if (alt2->predicate != NULL) predicate_free(alt2->predicate); /* MR12 */ require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt1->predicate = MR_find_predicates_and_supp((Node *)alt1->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt1->predicate),"predicate alt 1 not completed"); alt1->predicate=MR_predSimplifyALL(alt1->predicate); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt2->predicate = MR_find_predicates_and_supp((Node *)alt2->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt2->predicate),"predicate alt 2 not completed"); alt2->predicate=MR_predSimplifyALL(alt2->predicate); MR_doPredicatesHelp(0,alt1,alt2,jtype,sub); if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) ) { verify_context(alt1->predicate); verify_context(alt2->predicate); } if (HoistPredicateContext&&(alt1->predicate!=NULL||alt2->predicate!=NULL) && WarningLevel>1) ensure_predicates_cover_ambiguous_lookahead_sequences(alt1, alt2, sub, ambig); if ( WarningLevel == 1 && (alt1->predicate!=NULL||alt2->predicate!=NULL)) { for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); Tfree(ambig); return; } } /* end TJP (10/24/93) */ fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); if ( jtype == aLoopBegin || jtype == aPlusBlk ) fprintf(stderr, " warning: optional/exit path and alt(s) %sambiguous upon", sub); else fprintf(stderr, " warning: alts %d and %d %sambiguous upon", alt1->altnum, alt2->altnum, sub); if ( elevel == 3 && LL_k>1 ) { preorder(ambig); fprintf(stderr, "\n"); for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); Tfree(ambig); return; }; Tfree(ambig); dumpAmbigMsg(fset, stderr, 0); /* because this is a special case in which both alt1 and alt2 have lookahead sets of degree 1 for kaltnum; CurAmbigAlt2 = alt2->altnum; CurAmbigbtype = sub; CurAmbigfile = alt1->file; CurAmbigline = alt1->line; /* Don't do full LL(n) analysis if (...)? block because the block, by definition, defies LL(n) analysis. If guess (...)? block and ambiguous then don't remove anything from 2nd alt to resolve ambig. Want to predict with LL sup 1 ( n ) decision not LL(n) if guess block since it is much cheaper than LL(n). LL sup 1 ( n ) "covers" the LL(n) lookahead information. Note: LL(n) context cannot be computed for semantic predicates when followed by (..)?. If (..)? then we scream "AAAHHHH! No LL(n) analysis will help" Is 'ambig' always defined if we enter this if? I hope so because the 'ensure...()' func references it. TJP Nov 1993. */ if ( first_item_is_guess_block((Junction *)alt1->p1)!=NULL ) { if ( ParseWithPredicates ) { if (alt1->predicate != NULL) predicate_free(alt1->predicate); /* MR12 */ if (alt2->predicate != NULL) predicate_free(alt2->predicate); /* MR12 */ require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt1->predicate = MR_find_predicates_and_supp((Node *)alt1->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt1->predicate),"predicate alt 1 not completed"); alt1->predicate=MR_predSimplifyALL(alt1->predicate); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt2->predicate = MR_find_predicates_and_supp((Node *)alt2->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt2->predicate),"predicate alt 2 not completed"); alt2->predicate=MR_predSimplifyALL(alt2->predicate); MR_doPredicatesHelp(1,alt1,alt2,jtype,sub); if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) ) { verify_context(alt1->predicate); verify_context(alt2->predicate); } if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) && WarningLevel>1 ) ensure_predicates_cover_ambiguous_lookahead_sequences(alt1, alt2, sub, ambig); if ( WarningLevel==1 && (alt1->predicate!=NULL||alt2->predicate!=NULL)) { for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } } if ( WarningLevel>1 ) { fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); if ( jtype == aLoopBegin || jtype == aPlusBlk ) fprintf(stderr, " warning: optional/exit path and alt(s) %sambiguous upon", sub); else fprintf(stderr, " warning: alts %d and %d %sambiguous upon", alt1->altnum, alt2->altnum, sub); dumpAmbigMsg(fset, stderr, 0); MR_traceAmbSource(fset,alt1,alt2); } for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } /* Not resolved with (..)? block. Do full LL(n) analysis */ /* ambig is the set of k-tuples truly in common between alt 1 and alt 2 */ /* MR11 VerifyAmbig once used fset destructively */ ambig = VerifyAmbig(alt1, alt2, ftbl, fset, &t, &u, &numAmbig); /* are all things in intersection really ambigs? */ if (thisOverflow || numAmbig < n ) /* MR9 */ { Tree *v; /* remove ambig permutation from 2nd alternative to resolve ambig; * We want to compute the set of artificial tuples, arising from * LL sup 1 (n) compression, that collide with real tuples from the * 2nd alternative. This is the set of "special case" tuples that * the LL sup 1 (n) decision template maps incorrectly. */ /* when generating code in genExpr() it does * * if ( genExprSets(j->fset) && !genExprTree(j->ftree)) {... * * Sooooo the j->ftree is the tree of alt2 * after removal of conflicts, not alt1 ! */ if ( ambig!=NULL ) { /* at the top of ambig is an ALT node */ for (v=ambig->down; v!=NULL; v=v->right) { u = trm_perm(u, v); /* remove v FROM u */ } /* fprintf(stderr, "after rm alt2:"); preorder(u); fprintf(stderr, "\n");*/ } Tfree( t ); alt1->ftree = tappend(alt1->ftree, u); alt1->ftree = tleft_factor(alt1->ftree); } if ( ambig==NULL ) { for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } ambig = tleft_factor(ambig); /* TJP: * At this point, we surely have an LL(k) ambiguity. Check for predicates */ if ( ParseWithPredicates ) { if (alt1->predicate != NULL) predicate_free(alt1->predicate); /* MR12 */ if (alt2->predicate != NULL) predicate_free(alt2->predicate); /* MR12 */ require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt1->predicate = MR_find_predicates_and_supp((Node *)alt1->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt1->predicate),"predicate alt 1 not completed"); alt1->predicate=MR_predSimplifyALL(alt1->predicate); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); alt2->predicate = MR_find_predicates_and_supp((Node *)alt2->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); require (MR_predicate_context_completed(alt2->predicate),"predicate alt 2 not completed"); alt2->predicate=MR_predSimplifyALL(alt2->predicate); MR_doPredicatesHelp(0,alt1,alt2,jtype,sub); if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) ) { verify_context(alt1->predicate); verify_context(alt2->predicate); } if ( HoistPredicateContext && (alt1->predicate!=NULL||alt2->predicate!=NULL) && WarningLevel>1 ) ensure_predicates_cover_ambiguous_lookahead_sequences(alt1, alt2, sub, ambig); if ( WarningLevel==1 && (alt1->predicate!=NULL||alt2->predicate!=NULL)) { /* We found at least one pred for at least one of the alts; * If warnings are low, just return. */ Tfree(ambig); for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); return; } /* else we're gonna give a warning */ } /* end TJP addition */ fprintf(stderr, ErrHdr, FileStr[alt1->file], alt1->line); if ( jtype == aLoopBegin || jtype == aPlusBlk ) fprintf(stderr, " warning: optional/exit path and alt(s) %sambiguous upon", sub); else fprintf(stderr, " warning: alts %d and %d %sambiguous upon", alt1->altnum, alt2->altnum, sub); if ( elevel == 3 ) { preorder(ambig->down); /* <===== k>1 ambiguity message data */ fprintf(stderr, "\n"); } else { MR_skipped_e3_report=1; dumpAmbigMsg(fset, stderr, 0); }; MR_traceAmbSourceK(ambig,alt1,alt2); /* <====== k>1 ambiguity aid */ Tfree(ambig); for (i=1; i<=CLL_k; i++) set_free( fset[i] ); free((char *)fset); for (i=1; i<=CLL_k; i++) free( (char *)ftbl[i] ); free((char *)ftbl); } /* Don't analyze alpha block of (alpha)?beta; if (alpha)? then analyze * Return the 1st node of the beta block if present else return j. */ Junction * #ifdef __USE_PROTOS analysis_point( Junction *j ) #else analysis_point( j ) Junction *j; #endif { Junction *gblock; /* MR13b When there was an action/predicate preceding a guess block the guess block became invisible at the analysis_point. first_item_is_guess_block accepts any kind of node, despite the fact that the formal is a junction. But I don't want to have to change it all over the place until I know it works. */ if ( j->ntype != nJunction && j->ntype != nAction) return j; gblock = first_item_is_guess_block((Junction *)j); if ( gblock!=NULL ) { Junction *past = gblock->end; Junction *p; require(past!=NULL, "analysis_point: no end block on (...)? block"); for (p=(Junction *)past->p1; p!=NULL; ) { if ( p->ntype==nAction ) { p=(Junction *)((ActionNode *)p)->next; continue; } if ( p->ntype!=nJunction ) { past->alpha_beta_guess_end=1; /* MR14 */ return (Junction *)past->p1; } if ( p->jtype==EndBlk || p->jtype==EndRule ) { return j; } /* MR6 */ /* MR6 A guess block is of the form "(alpha)? beta" or "(alpha)?". */ /* MR6 When beta is omitted (second form) this means "(alpha)? alpha". */ /* MR6 The program does not store another copy of alpha in this case. */ /* MR6 During analysis when the program needs to know what follows the */ /* MR6 guess clause. It calls this routine. */ /* MR6 */ /* MR6 If it is of the form "(alpha)? beta" it returns a pointer to beta.*/ /* MR6 */ /* MR6 If it is of the form "(alpha)?" it returns a pointer to the guess */ /* MR6 block itself thereby reusing the junction tree. */ /* MR6 */ /* MR6 It works by searching the "next in sequence" chain (skipping actions) */ /* MR6 searching for a RuleRef or Token node. (Those are the only 4 kinds */ /* MR6 of nodes: Junctions, RuleRef, Token, and Action.) */ /* MR6 */ /* MR6 This won't work for the special case "(alpha)? ()" because it has no */ /* MR6 rule references or token nodes. It eventually encounters a */ /* MR6 junction of type EndBlk or EndRule and says to its caller: nothing */ /* MR6 more here to analyze - must be of the form "(alpha)?". */ /* MR6 */ /* MR6 In the case of "(alpha)? ()" it should return a pointer to "()" */ /* MR6 */ /* MR6 I think. */ /* MR6 */ if ( p->jtype!=Generic) { /* MR6 */ past->alpha_beta_guess_end=1; /* MR14 */ return (Junction *)past->p1; /* MR6 */ }; /* MR6 */ p=(Junction *)p->p1; } } return j; } set #ifdef __USE_PROTOS First( Junction *j, int k, int jtype, int *max_k ) #else First( j, k, jtype, max_k ) Junction *j; int k; int jtype; int *max_k; #endif { Junction *alt1, *alt2; set a, rk, fCurBlk; int savek; int p1, p2; int save_maintainBackTrace; require(j->ntype==nJunction, "First: non junction passed"); /* C o m p u t e F I R S T s e t w i t h k l o o k a h e a d */ fCurBlk = rk = empty; for (alt1=j; alt1!=NULL; alt1 = (Junction *)alt1->p2 ) { Junction *p = analysis_point((Junction *)alt1->p1); REACH(p, k, &rk, alt1->fset[k]); require(set_nil(rk), "rk != nil"); set_free(rk); set_orin(&fCurBlk, alt1->fset[k]); } /* D e t e c t A m b i g u i t i e s */ *max_k = 1; for (p1=1,alt1=j; alt1!=NULL; alt1 = (Junction *)alt1->p2, p1++) { for (p2=1,alt2=(Junction *)alt1->p2; alt2!=NULL; alt2 = (Junction *)alt2->p2, p2++) { savek = k; a = set_and(alt1->fset[k], alt2->fset[k]); while ( !set_nil(a) ) { /* if we have hit the max k requested, just give warning */ if ( j->approx==k ) { } if ( k==CLL_k ) { #ifdef NOT_USED *** int save_LL_k = LL_k; *** int save_CLL_k = CLL_k; *** /* Get new LL_k from interactive feature if enabled */ *** if ( AImode ) *** AmbiguityDialog(j, jtype, alt1, alt2, &CLL_k, &LL_k); #endif *max_k = CLL_k; save_maintainBackTrace=MR_MaintainBackTrace; if (AlphaBetaTrace) MR_MaintainBackTrace=0; HandleAmbiguity(j, alt1, alt2, jtype); MR_MaintainBackTrace=save_maintainBackTrace; break; } else { Junction *p = analysis_point((Junction *)alt1->p1); Junction *q = analysis_point((Junction *)alt2->p1); k++; /* attempt ambig alts again with more lookahead */ REACH(p, k, &rk, alt1->fset[k]); require(set_nil(rk), "rk != nil"); REACH(q, k, &rk, alt2->fset[k]); require(set_nil(rk), "rk != nil"); set_free(a); a = set_and(alt1->fset[k], alt2->fset[k]); if ( k > *max_k ) *max_k = k; } } set_free(a); k = savek; } } return fCurBlk; } cccc-3.1.4/pccts/antlr/fset2.c0000644000000000000000000015706707265347623014571 0ustar rootroot/* * fset2.c * * Compute FIRST sets for full LL(k) * * 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-1998 */ #include #include "pcctscfg.h" #include #ifdef PCCTS_USE_STDARG #include #else #include #endif #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" /* ick! globals. Used by permute() to track which elements of a set have been used */ static int *findex; set *fset; /* MR11 make global */ static unsigned **ftbl; static set *constrain; /* pts into fset. constrains tToken() to 'constrain' */ int ConstrainSearch; int maxk; /* set to initial k upon tree construction request */ /* MR11 make global */ static Tree *FreeList = NULL; #ifdef __USE_PROTOS static int tmember_of_context(Tree *, Predicate *); #else static int tmember_of_context(); #endif #if TREE_DEBUG set set_of_tnodes_in_use; int stop_on_tnode_seq_number=(-1); /* (-1) to disable */ #endif /* Do root * Then each sibling */ void #ifdef __USE_PROTOS preorder( Tree *tree ) #else preorder( tree ) Tree *tree; #endif { if ( tree == NULL ) return; if ( tree->down != NULL ) fprintf(stderr, " ("); if ( tree->token == ALT ) fprintf(stderr, " ALT"); else fprintf(stderr, " %s", TerminalString(tree->token)); if ( tree->token==EpToken ) fprintf(stderr, "(%d)", tree->v.rk); preorder(tree->down); if ( tree->down != NULL ) fprintf(stderr, " )"); preorder(tree->right); } #ifdef __USE_PROTOS int MR_tree_matches_constraints(int k,set * constrain,Tree *t) #else int MR_tree_matches_constraints(k,constrain,t) int k; set * constrain; Tree * t; #endif { int i; Tree *u; if (k == 0) return 1; /* for testing guard predicates: if the guard tree is shorter than the constraint then it is a match. The reason is that a guard of (A B) should be equivalent to a guard of (A B . . .) where "." matches every token. Thus a match which runs out of tree before constraint is a match. */ if (t == NULL) return 1; require (set_deg(constrain[0]) == 1, "MR_tree_matches_constraints: set_deg != 1"); i=set_int(constrain[0]); if (t->token != i) return 0; if (k-1 == 0) return 1; for (u=t->down; u != NULL; u=u->right) { if (MR_tree_matches_constraints(k-1,&constrain[1],u)) { return 1; }; }; return 0; } /* check the depth of each primary sibling to see that it is exactly * k deep. e.g.; * * ALT * | * A ------- B * | | * C -- D E * * Remove all branches <= k deep. * * Added by TJP 9-23-92 to make the LL(k) constraint mechanism to work. */ static int pruneCount=0; static int prunePeak=200; Tree * #ifdef __USE_PROTOS prune( Tree *t, int k ) #else prune( t, k ) Tree *t; int k; #endif { pruneCount++; if (pruneCount > prunePeak+100) { prunePeak=pruneCount; #if 0 *** fprintf(stderr,"pruneCount=%d\n",pruneCount); /*** preorder(t); ***/ *** fprintf(stderr,"\n",pruneCount); #endif }; if ( t == NULL ) { pruneCount--; return NULL; }; if ( t->token == ALT ) fatal_internal("prune: ALT node in FIRST tree"); if ( t->right!=NULL ) t->right = prune(t->right, k); if ( k>1 ) { if ( t->down!=NULL ) t->down = prune(t->down, k-1); if ( t->down == NULL ) { Tree *r = t->right; t->right = NULL; Tfree(t); pruneCount--; return r; } } pruneCount--; return t; } /* build a tree (root child1 child2 ... NULL) */ #ifdef PCCTS_USE_STDARG Tree *tmake(Tree *root, ...) #else Tree *tmake(va_alist) va_dcl #endif { Tree *w; va_list ap; Tree *child, *sibling=NULL, *tail=NULL; #ifndef __USE_PROTOS Tree *root; #endif #ifdef PCCTS_USE_STDARG va_start(ap, root); #else va_start(ap); root = va_arg(ap, Tree *); #endif child = va_arg(ap, Tree *); while ( child != NULL ) { #ifdef DUM /* added "find end of child" thing TJP March 1994 */ for (w=child; w->right!=NULL; w=w->right) {;} /* find end of child */ #else w = child; #endif if ( sibling == NULL ) {sibling = child; tail = w;} else {tail->right = child; tail = w;} child = va_arg(ap, Tree *); } /* was "root->down = sibling;" */ if ( root==NULL ) root = sibling; else root->down = sibling; va_end(ap); return root; } Tree * #ifdef __USE_PROTOS tnode( int tok ) #else tnode( tok ) int tok; #endif { Tree *p, *newblk; static int n=0; if ( FreeList == NULL ) { /*fprintf(stderr, "tnode: %d more nodes\n", TreeBlockAllocSize);*/ if ( TreeResourceLimit > 0 ) { if ( (n+TreeBlockAllocSize) >= TreeResourceLimit ) { fprintf(stderr, ErrHdr, FileStr[CurAmbigfile], CurAmbigline); fprintf(stderr, " hit analysis resource limit while analyzing alts %d and %d %s\n", CurAmbigAlt1, CurAmbigAlt2, CurAmbigbtype); exit(PCCTS_EXIT_FAILURE); } } newblk = (Tree *)calloc(TreeBlockAllocSize, sizeof(Tree)); if ( newblk == NULL ) { fprintf(stderr, ErrHdr, FileStr[CurAmbigfile], CurAmbigline); fprintf(stderr, " out of memory while analyzing alts %d and %d %s\n", CurAmbigAlt1, CurAmbigAlt2, CurAmbigbtype); exit(PCCTS_EXIT_FAILURE); } n += TreeBlockAllocSize; for (p=newblk; p<&(newblk[TreeBlockAllocSize]); p++) { p->right = FreeList; /* add all new Tree nodes to Free List */ FreeList = p; } } p = FreeList; FreeList = FreeList->right; /* remove a tree node */ p->right = NULL; /* zero out ptrs */ p->down = NULL; p->token = tok; TnodesAllocated++; /* MR10 */ TnodesInUse++; /* MR10 */ if (TnodesInUse > TnodesPeak) TnodesPeak=TnodesInUse; /* MR10 */ #ifdef TREE_DEBUG require(!p->in_use, "tnode: node in use!"); p->in_use = 1; p->seq=TnodesAllocated; set_orel( (unsigned) TnodesAllocated,&set_of_tnodes_in_use); if (stop_on_tnode_seq_number == p->seq) { fprintf(stderr,"\n*** just allocated tnode #%d ***\n", stop_on_tnode_seq_number); }; #endif return p; } static Tree * #ifdef __USE_PROTOS eofnode( int k ) #else eofnode( k ) int k; #endif { Tree *t=NULL; int i; for (i=1; i<=k; i++) { t = tmake(tnode((TokenInd!=NULL?TokenInd[EofToken]:EofToken)), t, NULL); } return t; } void #ifdef __USE_PROTOS _Tfree( Tree *t ) #else _Tfree( t ) Tree *t; #endif { if ( t!=NULL ) { #ifdef TREE_DEBUG if (t->seq == stop_on_tnode_seq_number) { fprintf(stderr,"\n*** just freed tnode #%d ***\n",t->seq); }; require(t->in_use, "_Tfree: node not in use!"); t->in_use = 0; set_rm( (unsigned) t->seq,set_of_tnodes_in_use); #endif t->right = FreeList; FreeList = t; TnodesInUse--; /* MR10 */ } } /* tree duplicate */ Tree * #ifdef __USE_PROTOS tdup( Tree *t ) #else tdup( t ) Tree *t; #endif { Tree *u; if ( t == NULL ) return NULL; u = tnode(t->token); u->v.rk = t->v.rk; u->right = tdup(t->right); u->down = tdup(t->down); return u; } /* tree duplicate (assume tree is a chain downwards) */ Tree * #ifdef __USE_PROTOS tdup_chain( Tree *t ) #else tdup_chain( t ) Tree *t; #endif { Tree *u; if ( t == NULL ) return NULL; u = tnode(t->token); u->v.rk = t->v.rk; u->down = tdup(t->down); return u; } Tree * #ifdef __USE_PROTOS tappend( Tree *t, Tree *u ) #else tappend( t, u ) Tree *t; Tree *u; #endif { Tree *w; /*** fprintf(stderr, "tappend("); *** preorder(t); fprintf(stderr, ","); *** preorder(u); fprintf(stderr, " )\n"); */ if ( t == NULL ) return u; if ( t->token == ALT && t->right == NULL ) return tappend(t->down, u); for (w=t; w->right!=NULL; w=w->right) {;} w->right = u; return t; } /* dealloc all nodes in a tree */ void #ifdef __USE_PROTOS Tfree( Tree *t ) #else Tfree( t ) Tree *t; #endif { if ( t == NULL ) return; Tfree( t->down ); Tfree( t->right ); _Tfree( t ); } /* find all children (alts) of t that require remaining_k nodes to be LL_k * tokens long. * * t-->o * | * a1--a2--...--an <-- LL(1) tokens * | | | * b1 b2 ... bn <-- LL(2) tokens * | | | * . . . * . . . * z1 z2 ... zn <-- LL(LL_k) tokens * * We look for all [Ep] needing remaining_k nodes and replace with u. * u is not destroyed or actually used by the tree (a copy is made). */ Tree * #ifdef __USE_PROTOS tlink( Tree *t, Tree *u, int remaining_k ) #else tlink( t, u, remaining_k ) Tree *t; Tree *u; int remaining_k; #endif { Tree *p; require(remaining_k!=0, "tlink: bad tree"); if ( t==NULL ) return NULL; /*fprintf(stderr, "tlink: u is:"); preorder(u); fprintf(stderr, "\n");*/ if ( t->token == EpToken && t->v.rk == remaining_k ) { require(t->down==NULL, "tlink: invalid tree"); if ( u == NULL ) { /* MR10 */ Tree *tt=t->right; /* MR10 */ _Tfree(t); /* MR10 */ return tt; }; p = tdup( u ); p->right = t->right; _Tfree( t ); return p; } t->down = tlink(t->down, u, remaining_k); t->right = tlink(t->right, u, remaining_k); return t; } /* remove as many ALT nodes as possible while still maintaining semantics */ Tree * #ifdef __USE_PROTOS tshrink( Tree *t ) #else tshrink( t ) Tree *t; #endif { if ( t == NULL ) return NULL; t->down = tshrink( t->down ); t->right = tshrink( t->right ); if ( t->down == NULL ) { if ( t->token == ALT ) { Tree *u = t->right; _Tfree(t); return u; /* remove useless alts */ } return t; } /* (? (ALT (? ...)) s) ==> (? (? ...) s) where s = sibling, ? = match any */ if ( t->token == ALT && t->down->right == NULL) { Tree *u = t->down; u->right = t->right; _Tfree( t ); return u; } /* (? (A (ALT t)) s) ==> (? (A t) s) where A is a token; s,t siblings */ if ( t->token != ALT && t->down->token == ALT && t->down->right == NULL ) { Tree *u = t->down->down; _Tfree( t->down ); t->down = u; return t; } return t; } Tree * #ifdef __USE_PROTOS tflatten( Tree *t ) #else tflatten( t ) Tree *t; #endif { if ( t == NULL ) return NULL; t->down = tflatten( t->down ); t->right = tflatten( t->right ); if ( t->down == NULL ) return t; if ( t->token == ALT ) { Tree *u; /* find tail of children */ for (u=t->down; u->right!=NULL; u=u->right) {;} u->right = t->right; u = t->down; _Tfree( t ); return u; } return t; } Tree * #ifdef __USE_PROTOS tJunc( Junction *p, int k, set *rk ) #else tJunc( p, k, rk ) Junction *p; int k; set *rk; #endif { Tree *t=NULL, *u=NULL; Junction *alt; Tree *tail=NULL, *r; #ifdef DBG_TRAV fprintf(stderr, "tJunc(%d): %s in rule %s\n", k, decodeJType[p->jtype], ((Junction *)p)->rname); #endif /* MR14 */ if (AlphaBetaTrace && p->alpha_beta_guess_end) { /* MR14 */ warnFL( /* MR14 */ "not possible to compute follow set for alpha in an \"(alpha)? beta\" block. ", /* MR14 */ FileStr[p->file],p->line); /* MR14 */ MR_alphaBetaTraceReport(); /* MR14 */ }; /* MR14 */ if (p->alpha_beta_guess_end) { /* MR14 */ return NULL; /* MR14 */ } if ( p->jtype==aLoopBlk || p->jtype==RuleBlk || p->jtype==aPlusBlk || p->jtype==aSubBlk || p->jtype==aOptBlk ) { if ( p->jtype!=aSubBlk && p->jtype!=aOptBlk ) { require(p->lock!=NULL, "rJunc: lock array is NULL"); if ( p->lock[k] ) return NULL; p->lock[k] = TRUE; } /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; TRAV(p->p1, k, rk, tail); /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; if ( p->jtype==RuleBlk ) {p->lock[k] = FALSE; return tail;} r = tmake(tnode(ALT), tail, NULL); for (alt=(Junction *)p->p2; alt!=NULL; alt = (Junction *)alt->p2) { /* if this is one of the added optional alts for (...)+ then break */ if ( alt->ignore ) break; if ( tail==NULL ) {TRAV(alt->p1, k, rk, tail); r->down = tail;} else { /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; TRAV(alt->p1, k, rk, tail->right); /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; if ( tail->right != NULL ) tail = tail->right; } } if ( p->jtype!=aSubBlk && p->jtype!=aOptBlk ) p->lock[k] = FALSE; #ifdef DBG_TREES fprintf(stderr, "blk(%s) returns:",((Junction *)p)->rname); preorder(r); fprintf(stderr, "\n"); #endif if ( r->down == NULL ) {_Tfree(r); return NULL;} return r; } if ( p->jtype==EndRule ) { if ( p->halt ) /* don't want FOLLOW here? */ { /**** if ( ContextGuardTRAV ) return NULL; ****/ set_orel( (unsigned) k, rk); /* indicate this k value needed */ /* MR10 cast */ t = tnode(EpToken); t->v.rk = k; return t; } require(p->lock!=NULL, "rJunc: lock array is NULL"); if ( p->lock[k] ) return NULL; /* if no FOLLOW assume k EOF's */ if ( p->p1 == NULL ) return eofnode(k); p->lock[k] = TRUE; } /* MR14 */ if (p->p1 != NULL && p->guess && p->guess_analysis_point == NULL) { /* MR14 */ Node * guess_point; /* MR14 */ guess_point=(Node *)analysis_point(p); /* MR14 */ if (guess_point == (Node *)p) { /* MR14 */ guess_point=p->p1; /* MR14 */ } /* MR14 */ p->guess_analysis_point=guess_point; /* MR14 */ } if ( p->p2 == NULL ) { /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; /* M14 */ if (p->guess_analysis_point != NULL) { /* M14 */ TRAV(p->guess_analysis_point, k, rk,t); /* M14 */ } else { TRAV(p->p1, k, rk,t); /* M14 */ } /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; if ( p->jtype==EndRule ) p->lock[k]=FALSE; return t; } /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; /* M14 */ if (p->guess_analysis_point != NULL) { /* M14 */ TRAV(p->guess_analysis_point, k, rk,t); /* M14 */ } else { TRAV(p->p1, k, rk,t); /* M14 */ } /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (p->jtype != Generic) MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; if ( p->jtype!=RuleBlk && /* MR14 */ !p->guess) TRAV(p->p2, k, rk, u); if ( p->jtype==EndRule ) p->lock[k] = FALSE;/* unlock node */ if ( t==NULL ) return tmake(tnode(ALT), u, NULL); return tmake(tnode(ALT), t, u, NULL); } Tree * #ifdef __USE_PROTOS tRuleRef( RuleRefNode *p, int k, set *rk_out ) #else tRuleRef( p, k, rk_out ) RuleRefNode *p; int k; set *rk_out; #endif { int k2; Tree *t=NULL, *u=NULL; Junction *r; set rk, rk2; int save_halt; RuleEntry *q = (RuleEntry *) hash_get(Rname, p->text); #ifdef DBG_TRAV fprintf(stderr, "tRuleRef: %s\n", p->text); #endif if ( q == NULL ) { TRAV(p->next, k, rk_out, t);/* ignore undefined rules */ return t; } rk = rk2 = empty; if (RulePtr == NULL) fatal("RulePtr==NULL"); r = RulePtr[q->rulenum]; if ( r->lock[k] ) return NULL; save_halt = r->end->halt; r->end->halt = TRUE; /* don't let reach fall off end of rule here */ /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; TRAV(r, k, &rk, t); /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; r->end->halt = save_halt; #ifdef DBG_TREES fprintf(stderr, "after ruleref, t is:"); preorder(t); fprintf(stderr, "\n"); #endif t = tshrink( t ); while ( !set_nil(rk) ) { /* any k left to do? if so, link onto tree */ k2 = set_int(rk); set_rm(k2, rk); /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ MR_pointerStackPush(&MR_BackTraceStack,p); /* MR10 */ }; TRAV(p->next, k2, &rk2, u); /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ MR_pointerStackPop(&MR_BackTraceStack); /* MR10 */ }; t = tlink(t, u, k2); /* any alts missing k2 toks, add u onto end */ Tfree(u); /* MR10 */ } set_free(rk); /* rk is empty, but free it's memory */ set_orin(rk_out, rk2); /* remember what we couldn't do */ set_free(rk2); return t; } Tree * #ifdef __USE_PROTOS tToken( TokNode *p, int k, set *rk ) #else tToken( p, k, rk ) TokNode *p; int k; set *rk; #endif { Tree *t=NULL, *tset=NULL, *u; if (ConstrainSearch) { if (MR_AmbSourceSearch) { require(constrain>=fset&&constrain<=&(fset[CLL_k]),"tToken: constrain is not a valid set"); } else { require(constrain>=fset&&constrain<=&(fset[LL_k]),"tToken: constrain is not a valid set"); }; constrain = &fset[maxk-k+1]; } #ifdef DBG_TRAV fprintf(stderr, "tToken(%d): %s\n", k, TerminalString(p->token)); if ( ConstrainSearch ) { fprintf(stderr, "constrain is:"); s_fprT(stderr, *constrain); fprintf(stderr, "\n"); } #endif /* is it a meta token (set of tokens)? */ if ( !set_nil(p->tset) ) { unsigned e=0; set a; Tree *n, *tail = NULL; if ( ConstrainSearch ) { a = set_and(p->tset, *constrain); if (set_nil(a)) { /* MR10 */ set_free(a); /* MR11 */ return NULL; /* MR10 */ }; /* MR10 */ } else { a = set_dup(p->tset); }; for (; !set_nil(a); set_rm(e, a)) { e = set_int(a); n = tnode(e); if ( tset==NULL ) { tset = n; tail = n; } else { tail->right = n; tail = n; } } set_free( a ); } else if ( ConstrainSearch && !set_el(p->token, *constrain) ) { /* fprintf(stderr, "ignoring token %s(%d)\n", TerminalString(p->token), k);*/ return NULL; } else { tset = tnode( p->token ); }; /* MR10 */ if (MR_MaintainBackTrace) { /* MR10 */ if (k == 1) { /* MR10 */ MR_pointerStackPush(&MR_BackTraceStack,p); /* MR13 */ if (MR_SuppressSearch) { /* MR13 */ MR_suppressSearchReport(); /* MR13 */ } else { /* MR10 */ MR_backTraceReport(); /* MR13 */ }; /* MR10 */ MR_pointerStackPop(&MR_BackTraceStack); /* MR11 */ Tfree(tset); /* MR11 */ return NULL; /* MR10 */ }; /* MR10 */ }; if ( k == 1 ) return tset; if (MR_MaintainBackTrace) { MR_pointerStackPush(&MR_BackTraceStack,p); }; TRAV(p->next, k-1, rk, t); if (MR_MaintainBackTrace) { Tfree(t); Tfree(tset); MR_pointerStackPop(&MR_BackTraceStack); return NULL; }; /* here, we are positive that, at least, this tree will not contribute * to the LL(2) tree since it will be too shallow, IF t==NULL. * If doing a context guard walk, then don't prune. */ if ( t == NULL && !ContextGuardTRAV ) /* tree will be too shallow */ { if ( tset!=NULL ) Tfree( tset ); return NULL; } #ifdef DBG_TREES fprintf(stderr, "tToken(%d)->next:",k); preorder(t); fprintf(stderr, "\n"); #endif /* if single token root, then just make new tree and return */ /* MR10 - set_nil(p->tset) isn't a good test because of ConstraintSearch */ if (tset->right == NULL) return tmake(tset, t, NULL); /* MR10 */ /* here we must make a copy of t as a child of each element of the tset; * e.g., "T1..T3 A" would yield ( nil ( T1 A ) ( T2 A ) ( T3 A ) ) */ for (u=tset; u!=NULL; u=u->right) { /* make a copy of t and hook it onto bottom of u */ u->down = tdup(t); } Tfree( t ); #ifdef DBG_TREES fprintf(stderr, "range is:"); preorder(tset); fprintf(stderr, "\n"); #endif return tset; } Tree * #ifdef __USE_PROTOS tAction( ActionNode *p, int k, set *rk ) #else tAction( p, k, rk ) ActionNode *p; int k; set *rk; #endif { Tree *t=NULL; set *save_fset=NULL; int i; /* fprintf(stderr, "tAction\n"); */ /* An MR_SuppressSearch is looking for things that can be reached even when the predicate is false. There are three kinds of predicates: plain: r1: <

    >? r2 guarded: r1: (A)? => <

    >? r2 ampersand style: r1: (A)? && <

    >? r2 Of the three kinds of predicates, only a guard predicate has things which are reachable even when the predicate is false. To be reachable the constraint must *not* match the guard. */ if (p->is_predicate && MR_SuppressSearch) { Predicate *pred=p->guardpred; if (pred == NULL) { t=NULL; goto EXIT; }; constrain = &fset[maxk-k+1]; if (pred->k == 1) { set dif; dif=set_dif(*constrain,pred->scontext[1]); if (set_nil(dif)) { set_free(dif); t=NULL; goto EXIT; }; set_free(dif); } else { if (MR_tree_matches_constraints(k,constrain,pred->tcontext)) { t=NULL; goto EXIT; }; } }; /* The ampersand predicate differs from the other predicates because its first set is a subset of the first set behind the predicate r1: (A)? && <

    >? r2 ; r2: A | B; In this case first[1] of r1 is A, even though first[1] of r2 is {A B}. */ if (p->is_predicate && p->ampersandPred != NULL) { Predicate *pred=p->ampersandPred; Tree *tAND; Tree *tset; if (k <= pred->k) { if (MR_MaintainBackTrace) MR_pointerStackPush(&MR_BackTraceStack,p); TRAV(p->guardNodes,k,rk,t); if (MR_MaintainBackTrace) MR_pointerStackPop(&MR_BackTraceStack); return t; } else { require (k>1,"tAction for ampersandpred: k <= 1"); if (ConstrainSearch) { if (MR_AmbSourceSearch) { require(constrain>=fset&&constrain<=&(fset[CLL_k]), "tToken: constrain is not a valid set"); } else { require(constrain>=fset&&constrain<=&(fset[LL_k]), "tToken: constrain is not a valid set"); }; save_fset=(set *) calloc (CLL_k+1,sizeof(set)); require (save_fset != NULL,"tAction save_fset alloc"); for (i=1; i <= CLL_k ; i++) { save_fset[i]=set_dup(fset[i]); }; if (pred->k == 1) { constrain = &fset[maxk-k+1]; set_andin(constrain,pred->scontext[1]); if (set_nil(*constrain)) { t=NULL; goto EXIT; }; } else { constrain = &fset[maxk-k+1]; if (! MR_tree_matches_constraints(pred->k,constrain,pred->tcontext)) { t=NULL; goto EXIT; }; /* end loop on i */ }; /* end loop on pred scontext/tcontext */ }; /* end if on k > pred->k */ }; /* end if on constrain search */ TRAV(p->next,k,rk,t); if (t != NULL) { t=tshrink(t); t=tflatten(t); t=tleft_factor(t); if (pred->tcontext != NULL) { tAND=MR_computeTreeAND(t,pred->tcontext); } else { tset=MR_make_tree_from_set(pred->scontext[1]); tAND=MR_computeTreeAND(t,tset); Tfree(tset); }; Tfree(t); t=tAND; }; goto EXIT; }; /* end if on ampersand predicate */ TRAV(p->next,k,rk,t); EXIT: if (save_fset != NULL) { for (i=1 ; i <= CLL_k ; i++) { set_free(fset[i]); fset[i]=save_fset[i]; }; free ( (char *) save_fset); }; return t; } /* see if e exists in s as a possible input permutation (e is always a chain) */ int #ifdef __USE_PROTOS tmember( Tree *e, Tree *s ) #else tmember( e, s ) Tree *e; Tree *s; #endif { if ( e==NULL||s==NULL ) return 0; /** fprintf(stderr, "tmember("); *** preorder(e); fprintf(stderr, ","); *** preorder(s); fprintf(stderr, " )\n"); */ if ( s->token == ALT && s->right == NULL ) return tmember(e, s->down); if ( e->token!=s->token ) { if ( s->right==NULL ) return 0; return tmember(e, s->right); } if ( e->down==NULL && s->down == NULL ) return 1; if ( tmember(e->down, s->down) ) return 1; if ( s->right==NULL ) return 0; return tmember(e, s->right); } /* see if e exists in s as a possible input permutation (e is always a chain); * Only check s to the depth of e. In other words, 'e' can be a shorter * sequence than s. */ int #ifdef __USE_PROTOS tmember_constrained( Tree *e, Tree *s) #else tmember_constrained( e, s ) Tree *e; Tree *s; #endif { if ( e==NULL||s==NULL ) return 0; /** fprintf(stderr, "tmember_constrained("); *** preorder(e); fprintf(stderr, ","); *** preorder(s); fprintf(stderr, " )\n"); **/ if ( s->token == ALT && s->right == NULL ) return tmember_constrained(e, s->down); if ( e->token!=s->token ) { if ( s->right==NULL ) return 0; return tmember_constrained(e, s->right); } if ( e->down == NULL ) return 1; /* if s is matched to depth of e return */ if ( tmember_constrained(e->down, s->down) ) return 1; if ( s->right==NULL ) return 0; return tmember_constrained(e, s->right); } /* combine (? (A t) ... (A u) ...) into (? (A t u)) */ Tree * #ifdef __USE_PROTOS tleft_factor( Tree *t ) #else tleft_factor( t ) Tree *t; #endif { Tree *u, *v, *trail, *w; /* left-factor what is at this level */ if ( t == NULL ) return NULL; for (u=t; u!=NULL; u=u->right) { trail = u; v=u->right; while ( v!=NULL ) { if ( u->token == v->token ) { if ( u->down!=NULL ) { for (w=u->down; w->right!=NULL; w=w->right) {;} w->right = v->down; /* link children together */ } else u->down = v->down; trail->right = v->right; /* unlink factored node */ _Tfree( v ); v = trail->right; } else {trail = v; v=v->right;} } } /* left-factor what is below */ for (u=t; u!=NULL; u=u->right) u->down = tleft_factor( u->down ); return t; } /* remove the permutation p from t if present */ Tree * #ifdef __USE_PROTOS trm_perm( Tree *t, Tree *p ) #else trm_perm( t, p ) Tree *t; Tree *p; #endif { /* fprintf(stderr, "trm_perm("); preorder(t); fprintf(stderr, ","); preorder(p); fprintf(stderr, " )\n"); */ if ( t == NULL || p == NULL ) return NULL; if ( t->token == ALT ) { t->down = trm_perm(t->down, p); if ( t->down == NULL ) /* nothing left below, rm cur node */ { Tree *u = t->right; _Tfree( t ); return trm_perm(u, p); } t->right = trm_perm(t->right, p); /* look for more instances of p */ return t; } if ( p->token != t->token ) /* not found, try a sibling */ { t->right = trm_perm(t->right, p); return t; } t->down = trm_perm(t->down, p->down); if ( t->down == NULL ) /* nothing left below, rm cur node */ { Tree *u = t->right; _Tfree( t ); return trm_perm(u, p); } t->right = trm_perm(t->right, p); /* look for more instances of p */ return t; } /* add the permutation 'perm' to the LL_k sets in 'fset' */ void #ifdef __USE_PROTOS tcvt( set *fset, Tree *perm ) #else tcvt( fset, perm ) set *fset; Tree *perm; #endif { if ( perm==NULL ) return; set_orel(perm->token, fset); tcvt(fset+1, perm->down); } /* for each element of ftbl[k], make it the root of a tree with permute(ftbl[k+1]) * as a child. */ Tree * #ifdef __USE_PROTOS permute( int k, int max_k ) #else permute( k, max_k ) int k, max_k; #endif { Tree *t, *u; if ( k>max_k ) return NULL; if ( ftbl[k][findex[k]] == nil ) return NULL; t = permute(k+1, max_k); if ( t==NULL&&k maxk will have to change. */ Tree * #ifdef __USE_PROTOS VerifyAmbig( Junction *alt1, Junction *alt2, unsigned **ft, set *fs, Tree **t, Tree **u, int *numAmbig ) #else VerifyAmbig( alt1, alt2, ft, fs, t, u, numAmbig ) Junction *alt1; Junction *alt2; unsigned **ft; set *fs; Tree **t; Tree **u; int *numAmbig; #endif { set rk; Tree *perm, *ambig=NULL; Junction *p; int k; int tnodes_at_start=TnodesAllocated; int tnodes_at_end; int tnodes_used; set *save_fs; int j; save_fs=(set *) calloc(CLL_k+1,sizeof(set)); require(save_fs != NULL,"save_fs calloc"); for (j=0; j <= CLL_k ; j++) save_fs[j]=set_dup(fs[j]); maxk = LL_k; /* NOTE: for now, we look for LL_k */ ftbl = ft; fset = fs; constrain = &(fset[1]); findex = (int *) calloc(LL_k+1, sizeof(int)); if ( findex == NULL ) { fprintf(stderr, ErrHdr, FileStr[CurAmbigfile], CurAmbigline); fprintf(stderr, " out of memory while analyzing alts %d and %d of %s\n", CurAmbigAlt1, CurAmbigAlt2, CurAmbigbtype); exit(PCCTS_EXIT_FAILURE); } for (k=1; k<=LL_k; k++) findex[k] = 0; rk = empty; ConstrainSearch = 1; /* consider only tokens in ambig sets */ p = analysis_point((Junction *)alt1->p1); TRAV(p, LL_k, &rk, *t); *t = tshrink( *t ); *t = tflatten( *t ); *t = tleft_factor( *t ); /* MR10 */ *t = prune(*t, LL_k); *t = tleft_factor( *t ); /*** fprintf(stderr, "after shrink&flatten&prune&left_factor:"); preorder(*t); fprintf(stderr, "\n");*/ if ( *t == NULL ) { /*** fprintf(stderr, "TreeIncomplete --> no LL(%d) ambiguity\n", LL_k);*/ Tfree( *t ); /* kill if impossible to have ambig */ *t = NULL; } p = analysis_point((Junction *)alt2->p1); TRAV(p, LL_k, &rk, *u); *u = tshrink( *u ); *u = tflatten( *u ); *t = tleft_factor( *t ); /* MR10 */ *u = prune(*u, LL_k); *u = tleft_factor( *u ); /* fprintf(stderr, "after shrink&flatten&prune&lfactor:"); preorder(*u); fprintf(stderr, "\n");*/ if ( *u == NULL ) { /* fprintf(stderr, "TreeIncomplete --> no LL(%d) ambiguity\n", LL_k);*/ Tfree( *u ); *u = NULL; } for (k=1; k<=LL_k; k++) set_clr( fs[k] ); ambig = tnode(ALT); k = 0; if ( *t!=NULL && *u!=NULL ) { while ( (perm=permute(1,LL_k))!=NULL ) { /* fprintf(stderr, "chk perm:"); preorder(perm); fprintf(stderr, "\n");*/ if ( tmember(perm, *t) && tmember(perm, *u) ) { /* fprintf(stderr, "ambig upon"); preorder(perm); fprintf(stderr, "\n");*/ k++; perm->right = ambig->down; ambig->down = perm; tcvt(&(fs[1]), perm); } else Tfree( perm ); } } for (j=0; j <= CLL_k ; j++) fs[j]=save_fs[j]; free( (char *) save_fs); tnodes_at_end=TnodesAllocated; tnodes_used=tnodes_at_end - tnodes_at_start; if (TnodesReportThreshold > 0 && tnodes_used > TnodesReportThreshold) { fprintf(stdout,"There were %d tuples whose ambiguity could not be resolved by full lookahead\n",k); fprintf(stdout,"There were %d tnodes created to resolve ambiguity between:\n\n",tnodes_used); fprintf(stdout," Choice 1: %s line %d file %s\n", MR_ruleNamePlusOffset( (Node *) alt1),alt1->line,FileStr[alt1->file]); fprintf(stdout," Choice 2: %s line %d file %s\n", MR_ruleNamePlusOffset( (Node *) alt2),alt2->line,FileStr[alt2->file]); for (j=1; j <= CLL_k ; j++) { fprintf(stdout,"\n Intersection of lookahead[%d] sets:\n",j); MR_dumpTokenSet(stdout,2,fs[j]); }; fprintf(stdout,"\n"); }; *numAmbig = k; if ( ambig->down == NULL ) {_Tfree(ambig); ambig = NULL;} free( (char *)findex ); /* fprintf(stderr, "final ambig:"); preorder(ambig); fprintf(stderr, "\n");*/ return ambig; } static Tree * #ifdef __USE_PROTOS bottom_of_chain( Tree *t ) #else bottom_of_chain( t ) Tree *t; #endif { if ( t==NULL ) return NULL; for (; t->down != NULL; t=t->down) {;} return t; } /* * Make a tree from k sets where the degree of the first k-1 sets is 1. */ Tree * #ifdef __USE_PROTOS make_tree_from_sets( set *fset1, set *fset2 ) #else make_tree_from_sets( fset1, fset2 ) set *fset1; set *fset2; #endif { set inter; int i; Tree *t=NULL, *n, *u; unsigned *p,*q; require(LL_k>1, "make_tree_from_sets: LL_k must be > 1"); /* do the degree 1 sets first */ for (i=1; i<=LL_k-1; i++) { inter = set_and(fset1[i], fset2[i]); require(set_deg(inter)==1, "invalid set to tree conversion"); n = tnode(set_int(inter)); if (t==NULL) t=n; else tmake(t, n, NULL); set_free(inter); } /* now add the chain of tokens at depth k */ u = bottom_of_chain(t); inter = set_and(fset1[LL_k], fset2[LL_k]); if ( (q=p=set_pdq(inter)) == NULL ) fatal_internal("Can't alloc space for set_pdq"); /* first one is linked to bottom, then others are sibling linked */ n = tnode(*p++); u->down = n; u = u->down; while ( *p != nil ) { n = tnode(*p); u->right = n; u = u->right; p++; } free((char *)q); return t; } /* create and return the tree of lookahead k-sequences that are in t, but not * in the context of predicates in predicate list p. */ Tree * #ifdef __USE_PROTOS tdif( Tree *ambig_tuples, Predicate *p, set *fset1, set *fset2 ) #else tdif( ambig_tuples, p, fset1, fset2 ) Tree *ambig_tuples; Predicate *p; set *fset1; set *fset2; #endif { unsigned **ft; Tree *dif=NULL; Tree *perm; set b; int i,k; if ( p == NULL ) return tdup(ambig_tuples); ft = (unsigned **) calloc(CLL_k+1, sizeof(unsigned *)); require(ft!=NULL, "cannot allocate ft"); for (i=1; i<=CLL_k; i++) { b = set_and(fset1[i], fset2[i]); ft[i] = set_pdq(b); set_free(b); } findex = (int *) calloc(LL_k+1, sizeof(int)); if ( findex == NULL ) { fatal_internal("out of memory in tdif while checking predicates"); } for (k=1; k<=LL_k; k++) findex[k] = 0; #ifdef DBG_TRAV fprintf(stderr, "tdif_%d[", p->k); preorder(ambig_tuples); fprintf(stderr, ","); preorder(p->tcontext); fprintf(stderr, "] ="); #endif ftbl = ft; while ( (perm=permute(1,p->k))!=NULL ) { #ifdef DBG_TRAV fprintf(stderr, "test perm:"); preorder(perm); fprintf(stderr, "\n"); #endif if ( tmember_constrained(perm, ambig_tuples) && !tmember_of_context(perm, p) ) { #ifdef DBG_TRAV fprintf(stderr, "satisfied upon"); preorder(perm); fprintf(stderr, "\n"); #endif k++; if ( dif==NULL ) dif = perm; else { perm->right = dif; dif = perm; } } else Tfree( perm ); } #ifdef DBG_TRAV preorder(dif); fprintf(stderr, "\n"); #endif for (i=1; i<=CLL_k; i++) free( (char *)ft[i] ); free((char *)ft); free((char *)findex); return dif; } /* is lookahead sequence t a member of any context tree for any * predicate in p? */ static int #ifdef __USE_PROTOS tmember_of_context( Tree *t, Predicate *p ) #else tmember_of_context( t, p ) Tree *t; Predicate *p; #endif { for (; p!=NULL; p=p->right) { if ( p->expr==PRED_AND_LIST || p->expr==PRED_OR_LIST ) return tmember_of_context(t, p->down); if ( tmember_constrained(t, p->tcontext) ) return 1; if ( tmember_of_context(t, p->down) ) return 1; } return 0; } int #ifdef __USE_PROTOS is_single_tuple( Tree *t ) #else is_single_tuple( t ) Tree *t; #endif { if ( t == NULL ) return 0; if ( t->right != NULL ) return 0; if ( t->down == NULL ) return 1; return is_single_tuple(t->down); } /* MR10 Check that a context guard contains only allowed things */ /* MR10 (mainly token references). */ #ifdef __USE_PROTOS int contextGuardOK(Node *p,int h,int *hmax) #else int contextGuardOK(p,h,hmax) Node *p; int h; int *hmax; #endif { Junction *j; TokNode *tn; if (p == NULL) return 1; if (p->ntype == nToken) { h++; if (h > *hmax) *hmax=h; tn=(TokNode *)p; if (tn->el_label != NULL) { warnFL(eMsg1("a label (\"%s\") for a context guard element is meaningless",tn->el_label), FileStr[p->file],p->line); }; return contextGuardOK( ( (TokNode *) p)->next,h,hmax); } else if (p->ntype == nAction) { goto Fail; } else if (p->ntype == nRuleRef) { goto Fail; } else { require (p->ntype == nJunction,"Unexpected ntype"); j=(Junction *) p; if (j->jtype != Generic && j->jtype != aSubBlk && /* pretty sure this one is allowed */ /**** j->jtype != aOptBlk && ****/ /* pretty sure this one is allowed */ /* MR11 not any more ! */ j->jtype != EndBlk) { errFL("A context guard may not contain an option block: {...} or looping block: (...)* or (...)+", FileStr[p->file],p->line); contextGuardOK(j->p1,h,hmax); return 0; }; /* do both p1 and p2 so use | rather than || */ return contextGuardOK(j->p2,h,hmax) | contextGuardOK(j->p1,h,hmax); }; Fail: errFL("A context guard may contain only Token references - guard will be ignored", FileStr[p->file],p->line); contextGuardOK( ( (ActionNode *) p)->next,h,hmax); return 0; } /* * Look at a (...)? generalized-predicate context-guard and compute * either a lookahead set (k==1) or a lookahead tree for k>1. The * k level is determined by the guard itself rather than the LL_k * variable. For example, ( A B )? is an LL(2) guard and ( ID )? * is an LL(1) guard. For the moment, you can only have a single * tuple in the guard. Physically, the block must look like this * --o-->TOKEN-->o-->o-->TOKEN-->o-- ... -->o-->TOKEN-->o-- * An error is printed for any other type. */ Predicate * #ifdef __USE_PROTOS computePredicateFromContextGuard(Graph blk,int *msgDone) /* MR10 */ #else computePredicateFromContextGuard(blk,msgDone) /* MR10 */ Graph blk; int *msgDone; /* MR10 */ #endif { Junction *junc = (Junction *)blk.left, *p; Tree *t=NULL; Predicate *pred = NULL; set scontext, rk; int ok; int hmax=0; require(junc!=NULL && junc->ntype == nJunction, "bad context guard"); /* MR10 Check for anything other than Tokens and generic junctions */ *msgDone=0; /* MR10 */ ok=contextGuardOK( (Node *)junc,0,&hmax); /* MR10 */ if (! ok) { /* MR10 */ *msgDone=1; /* MR10 */ return NULL; /* MR10 */ }; /* MR10 */ if (hmax == 0) { errFL("guard is 0 tokens long",FileStr[junc->file],junc->line); /* MR11 */ *msgDone=1; return NULL; }; if (hmax > CLL_k) { /* MR10 */ errFL(eMsgd2("guard is %d tokens long - lookahead is limited to max(k,ck)==%d", /* MR10 */ hmax,CLL_k), /* MR10 */ FileStr[junc->file],junc->line); /* MR10 */ *msgDone=1; /* MR10 */ return NULL; /* MR10 */ }; /* MR10 */ rk = empty; p = junc; pred = new_pred(); pred->k = hmax; /* MR10 should be CLL_k, not LLK ? */ if (hmax > 1 ) /* MR10 was LL_k */ { ConstrainSearch = 0; ContextGuardTRAV = 1; TRAV(p, hmax, &rk, t); /* MR10 was LL_k */ ContextGuardTRAV = 0; set_free(rk); t = tshrink( t ); t = tflatten( t ); t = tleft_factor( t ); /* fprintf(stderr, "ctx guard:"); preorder(t); fprintf(stderr, "\n"); */ pred->tcontext = t; } else { REACH(p, 1, &rk, scontext); require(set_nil(rk), "rk != nil"); set_free(rk); /* fprintf(stderr, "LL(1) ctx guard is:"); s_fprT(stderr, scontext); fprintf(stderr, "\n"); */ pred->scontext[1] = scontext; } list_add(&ContextGuardPredicateList,pred); /* MR13 */ return pred; } /* MR13 When the context guard is originally computed the meta-tokens are not known. */ #ifdef __USE_PROTOS void recomputeContextGuard(Predicate *pred) #else void recomputeContextGuard(pred) Predicate *pred; #endif { Tree * t=NULL; set scontext; set rk; ActionNode * actionNode; Junction * p; actionNode=pred->source; require (actionNode != NULL,"context predicate's source == NULL"); p=actionNode->guardNodes; require (p != NULL,"context predicate's guardNodes == NULL"); rk = empty; if (pred->k > 1 ) { ConstrainSearch = 0; ContextGuardTRAV = 1; TRAV(p, pred->k, &rk, t); ContextGuardTRAV = 0; set_free(rk); t = tshrink( t ); t = tflatten( t ); t = tleft_factor( t ); Tfree(pred->tcontext); pred->tcontext = t; } else { REACH(p, 1, &rk, scontext); require(set_nil(rk), "rk != nil"); set_free(rk); set_free(pred->scontext[1]); pred->scontext[1] = scontext; } } /* MR11 - had enough of flags yet ? */ int MR_AmbSourceSearch=0; int MR_AmbSourceSearchGroup=0; int MR_AmbSourceSearchChoice=0; int MR_AmbSourceSearchLimit=0; int MR_matched_AmbAidRule=0; static set *matchSets[2]={NULL,NULL}; static int *tokensInChain=NULL; static Junction *MR_AmbSourceSearchJ[2]; void MR_traceAmbSourceKclient() { int i; set *save_fset; int save_ConstrainSearch; set incomplete; Tree *t; if (matchSets[0] == NULL) { matchSets[0]=(set *) calloc (CLL_k+1,sizeof(set)); require (matchSets[0] != NULL,"matchSets[0] alloc"); matchSets[1]=(set *) calloc (CLL_k+1,sizeof(set)); require (matchSets[1] != NULL,"matchSets[1] alloc"); }; for (i=1 ; i <= MR_AmbSourceSearchLimit ; i++) { set_clr(matchSets[0][i]); set_orel( (unsigned) tokensInChain[i], &matchSets[0][i]); set_clr(matchSets[1][i]); set_orel( (unsigned) tokensInChain[i], &matchSets[1][i]); }; save_fset=fset; save_ConstrainSearch=ConstrainSearch; for (i=0 ; i < 2 ; i++) { #if 0 ** fprintf(stdout," Choice:%d Depth:%d ",i+1,MR_AmbSourceSearchLimit); ** fprintf(stdout,"("); ** for (j=1 ; j <= MR_AmbSourceSearchLimit ; j++) { ** if (j != 1) fprintf(stdout," "); ** fprintf(stdout,"%s",TerminalString(tokensInChain[j])); ** }; ** fprintf(stdout,")\n\n"); #endif fset=matchSets[i]; MR_AmbSourceSearch=1; MR_MaintainBackTrace=1; MR_AmbSourceSearchChoice=i; ConstrainSearch=1; maxk = MR_AmbSourceSearchLimit; incomplete=empty; t=NULL; constrain = &(fset[1]); MR_pointerStackReset(&MR_BackTraceStack); TRAV(MR_AmbSourceSearchJ[i],maxk,&incomplete,t); Tfree(t); require (set_nil(incomplete),"MR_traceAmbSourceK TRAV incomplete"); require (MR_BackTraceStack.count == 0,"K: MR_BackTraceStack.count != 0"); set_free(incomplete); }; ConstrainSearch=save_ConstrainSearch; fset=save_fset; MR_AmbSourceSearch=0; MR_MaintainBackTrace=0; MR_AmbSourceSearchChoice=0; } #ifdef __USE_PROTOS Tree *tTrunc(Tree *t,int depth) #else Tree *tTrunc(t,depth) Tree *t; #endif { Tree *u; require ( ! (t == NULL && depth > 0),"tree too short"); if (depth == 0) return NULL; if (t->token == ALT) { u=tTrunc(t->down,depth); } else { u=tnode(t->token); u->down=tTrunc(t->down,depth-1); }; if (t->right != NULL) u->right=tTrunc(t->right,depth); return u; } #ifdef __USE_PROTOS void MR_iterateOverTree(Tree *t,int chain[]) #else void MR_iterateOverTree(t,chain) Tree *t; int chain[]; #endif { if (t == NULL) return; chain[0]=t->token; if (t->down != NULL) { MR_iterateOverTree(t->down,&chain[1]); } else { MR_traceAmbSourceKclient(); }; MR_iterateOverTree(t->right,&chain[0]); chain[0]=0; } #ifdef __USE_PROTOS void MR_traceAmbSourceK(Tree *t,Junction *alt1,Junction *alt2) #else void MR_traceAmbSourceK(t,alt1,alt2) Tree *t; Junction *alt1; Junction *alt2; #endif { int i; int depth; int maxDepth; Tree *truncatedTree; if (MR_AmbAidRule == NULL) return; if ( ! ( strcmp(MR_AmbAidRule,alt1->rname) == 0 || strcmp(MR_AmbAidRule,alt2->rname) == 0 || MR_AmbAidLine==alt1->line || MR_AmbAidLine==alt2->line ) ) return; MR_matched_AmbAidRule++; /* there are no token sets in trees, only in TokNodes */ MR_AmbSourceSearchJ[0]=analysis_point( (Junction *) alt1->p1); MR_AmbSourceSearchJ[1]=analysis_point( (Junction *) alt2->p1); if (tokensInChain == NULL) { tokensInChain=(int *) calloc (CLL_k+1,sizeof(int)); require (tokensInChain != NULL,"tokensInChain alloc"); }; MR_AmbSourceSearchGroup=0; fprintf(stdout,"\n"); fprintf(stdout," Ambiguity Aid "); fprintf(stdout, (MR_AmbAidDepth <= LL_k ? "(-k %d -aa %s %s -aad %d)\n\n" : "(-k %d -aa %s %s [-k value limits -aad %d])\n\n"), LL_k, MR_AmbAidRule, (MR_AmbAidMultiple ? "-aam" : ""), MR_AmbAidDepth); for (i=0 ; i < 2 ; i++) { fprintf(stdout," Choice %d: %-25s line %d file %s\n", (i+1), MR_ruleNamePlusOffset( (Node *) MR_AmbSourceSearchJ[i]), MR_AmbSourceSearchJ[i]->line, FileStr[MR_AmbSourceSearchJ[i]->file]); }; fprintf(stdout,"\n"); if (MR_AmbAidDepth < LL_k) { maxDepth=MR_AmbAidDepth; } else { maxDepth=LL_k; }; for (depth=1 ; depth <= maxDepth; depth++) { MR_AmbSourceSearchLimit=depth; if (depth < LL_k) { truncatedTree=tTrunc(t,depth); truncatedTree=tleft_factor(truncatedTree); MR_iterateOverTree(truncatedTree,&tokensInChain[1]); /* <===== */ Tfree(truncatedTree); } else { MR_iterateOverTree(t,tokensInChain); /* <===== */ }; fflush(stdout); fflush(stderr); }; fprintf(stdout,"\n"); MR_AmbSourceSearch=0; MR_MaintainBackTrace=0; MR_AmbSourceSearchGroup=0; MR_AmbSourceSearchChoice=0; MR_AmbSourceSearchLimit=0; } /* this if for k=1 grammars only this is approximate only because of the limitations of linear approximation lookahead. Don't want to do a k=3 search when the user only specified a ck=3 grammar */ #ifdef __USE_PROTOS void MR_traceAmbSource(set *matchSets,Junction *alt1, Junction *alt2) #else void MR_traceAmbSource(matchSets,alt1,alt2) set *matchSets; Junction *alt1; Junction *alt2; #endif { set *save_fset; Junction *p[2]; int i; int j; set *dup_matchSets; set intersection; set incomplete; set tokensUsed; int depth; if (MR_AmbAidRule == NULL) return; if ( ! ( strcmp(MR_AmbAidRule,alt1->rname) == 0 || strcmp(MR_AmbAidRule,alt2->rname) == 0 || MR_AmbAidLine==alt1->line || MR_AmbAidLine==alt2->line ) ) return; MR_matched_AmbAidRule++; save_fset=fset; dup_matchSets=(set *) calloc(CLL_k+1,sizeof(set)); require (dup_matchSets != NULL,"Can't allocate dup_matchSets"); p[0]=analysis_point( (Junction *) alt1->p1); p[1]=analysis_point( (Junction *) alt2->p1); fprintf(stdout,"\n"); fprintf(stdout," Ambiguity Aid "); fprintf(stdout, (MR_AmbAidDepth <= CLL_k ? "(-ck %d -aa %s %s -aad %d)\n\n" : "(-ck %d -aa %s %s [-ck value limits -aad %d])\n\n"), CLL_k, MR_AmbAidRule, (MR_AmbAidMultiple ? "-aam" : ""), MR_AmbAidDepth); for (i=0 ; i < 2 ; i++) { fprintf(stdout," Choice %d: %-25s line %d file %s\n", (i+1), MR_ruleNamePlusOffset( (Node *) p[i]), p[i]->line,FileStr[p[i]->file]); }; for (j=1; j <= CLL_k ; j++) { fprintf(stdout,"\n Intersection of lookahead[%d] sets:\n",j); intersection=set_and(alt1->fset[j],alt2->fset[j]); MR_dumpTokenSet(stdout,2,intersection); set_free(intersection); }; fprintf(stdout,"\n"); require (1 <= MR_AmbAidDepth && MR_AmbAidDepth <= CLL_k, "illegal MR_AmbAidDepth"); MR_AmbSourceSearchGroup=0; for (depth=1; depth <= MR_AmbAidDepth; depth++) { MR_AmbSourceSearchLimit=depth; for (i=0 ; i < 2 ; i++) { /*** fprintf(stdout," Choice:%d Depth:%d\n\n",i+1,depth); ***/ for (j=0 ; j <= CLL_k ; j++) { dup_matchSets[j]=set_dup(matchSets[j]); }; fset=dup_matchSets; fflush(output); fflush(stdout); MR_AmbSourceSearch=1; MR_MaintainBackTrace=1; MR_AmbSourceSearchChoice=i; maxk = depth; tokensUsed=empty; incomplete=empty; constrain = &(fset[1]); MR_pointerStackReset(&MR_BackTraceStack); REACH(p[i],depth,&incomplete,tokensUsed); fflush(output); fflush(stdout); require (set_nil(incomplete),"MR_traceAmbSource REACH incomplete"); require (MR_BackTraceStack.count == 0,"1: MR_BackTraceStack.count != 0"); set_free(incomplete); set_free(tokensUsed); for (j=0 ; j <= CLL_k ; j++) { set_free(dup_matchSets[j]); }; }; }; fprintf(stdout,"\n"); MR_AmbSourceSearch=0; MR_MaintainBackTrace=0; MR_AmbSourceSearchGroup=0; MR_AmbSourceSearchChoice=0; MR_AmbSourceSearchLimit=0; fset=save_fset; free ( (char *) dup_matchSets); } static int itemCount; void MR_backTraceDumpItemReset() { itemCount=0; } #ifdef __USE_PROTOS void MR_backTraceDumpItem(FILE *f,int skip,Node *n) #else void MR_backTraceDumpItem(f,skip,n) FILE *f; int skip; Node *n; #endif { TokNode *tn; RuleRefNode *rrn; Junction *j; ActionNode *a; switch (n->ntype) { case nToken: itemCount++; if (skip) goto EXIT; tn=(TokNode *)n; if (set_nil(tn->tset)) { fprintf(f," %2d #token %-23s",itemCount,TerminalString(tn->token)); } else { fprintf(f," %2d #tokclass %-20s",itemCount,TerminalString(tn->token)); }; break; case nRuleRef: itemCount++; if (skip) goto EXIT; rrn=(RuleRefNode *)n; fprintf(f," %2d to %-27s",itemCount,rrn->text); break; case nAction: a=(ActionNode *)n; goto EXIT; case nJunction: j=(Junction *)n; switch (j->jtype) { case aSubBlk: if (j->guess) { itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,"in (...)? block at"); break; }; /****** fprintf(f," %2d %-32s",itemCount,"in (...) block at"); *******/ /****** break; *******/ goto EXIT; case aOptBlk: itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,"in {...} block"); break; case aLoopBlk: itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,"in (...)* block"); break; case EndBlk: if (j->alpha_beta_guess_end) { itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,"end (...)? block at"); break; }; goto EXIT; /****** fprintf(f," %2d %-32s",itemCount,"end of a block at"); *****/ /****** break; *****/ case RuleBlk: itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,j->rname); break; case Generic: goto EXIT; case EndRule: itemCount++; if (skip) goto EXIT; fprintf (f," %2d end %-26s",itemCount,j->rname); break; case aPlusBlk: itemCount++; if (skip) goto EXIT; fprintf(f," %2d %-30s",itemCount,"in (...)+ block"); break; case aLoopBegin: goto EXIT; }; break; }; fprintf(f," %-23s line %-4d %s\n",MR_ruleNamePlusOffset(n),n->line,FileStr[n->file]); EXIT: return; } static PointerStack previousBackTrace={0,0,NULL}; #ifdef __USE_PROTOS void MR_backTraceReport(void) #else void MR_backTraceReport() #endif { int i; int match; int limitMatch; Node *p; TokNode *tn; set remainder; int depth; /* Even when doing a k=2 search this routine can get called when there is only 1 token on the stack. This is because something like rRuleRef can change the search value of k from 2 to 1 temporarily. It does this because the it wants to know the k=1 first set before it does a k=2 search */ depth=0; for (i=0; i < MR_BackTraceStack.count ; i++) { p=(Node *) MR_BackTraceStack.data[i]; if (p->ntype == nToken) depth++; }; /* MR14 */ if (MR_AmbSourceSearch) { /* MR14 */ require (depth <= MR_AmbSourceSearchLimit,"depth > MR_AmbSourceSearchLimit"); /* MR14 */ } if (depth < MR_AmbSourceSearchLimit) { return; }; MR_backTraceDumpItemReset(); limitMatch=MR_BackTraceStack.count; if (limitMatch > previousBackTrace.count) { limitMatch=previousBackTrace.count; }; for (match=0; match < limitMatch; match++) { if (MR_BackTraceStack.data[match] != previousBackTrace.data[match]) { break; }; }; /* not sure at the moment why there would be duplicates */ if (match != MR_BackTraceStack.count) { fprintf(stdout," Choice:%d Depth:%d Group:%d", (MR_AmbSourceSearchChoice+1), MR_AmbSourceSearchLimit, ++MR_AmbSourceSearchGroup); depth=0; fprintf(stdout," ("); for (i=0; i < MR_BackTraceStack.count ; i++) { p=(Node *) MR_BackTraceStack.data[i]; if (p->ntype != nToken) continue; tn=(TokNode *)p; if (depth != 0) fprintf(stdout," "); fprintf(stdout,TerminalString(tn->token)); depth++; if (! MR_AmbAidMultiple) { if (set_nil(tn->tset)) { set_rm( (unsigned) tn->token,fset[depth]); } else { remainder=set_dif(fset[depth],tn->tset); set_free(fset[depth]); fset[depth]=remainder; }; }; }; fprintf(stdout,")\n"); for (i=0; i < MR_BackTraceStack.count ; i++) { MR_backTraceDumpItem(stdout, (i #include #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" #define NumExprPerLine 4 static int on1line=0; static set tokensRefdInBlock; /* T r a n s l a t i o n T a b l e s */ /* C_Trans[node type] == pointer to function that knows how to translate that node. */ #ifdef __cplusplus void (*C_Trans[NumNodeTypes+1])(...) = { NULL, NULL, /* See next table. Junctions have many types */ (void (*)(...)) genRuleRef, (void (*)(...)) genToken, (void (*)(...)) genAction }; #else void (*C_Trans[NumNodeTypes+1])() = { NULL, NULL, /* See next table. Junctions have many types */ genRuleRef, genToken, genAction }; #endif /* C_JTrans[Junction type] == pointer to function that knows how to translate that * kind of junction node. */ #ifdef __cplusplus void (*C_JTrans[NumJuncTypes+1])(...) = { NULL, (void (*)(...)) genSubBlk, (void (*)(...)) genOptBlk, (void (*)(...)) genLoopBlk, (void (*)(...)) genEndBlk, (void (*)(...)) genRule, (void (*)(...)) genJunction, (void (*)(...)) genEndRule, (void (*)(...)) genPlusBlk, (void (*)(...)) genLoopBegin }; #else void (*C_JTrans[NumJuncTypes+1])() = { NULL, genSubBlk, genOptBlk, genLoopBlk, genEndBlk, genRule, genJunction, genEndRule, genPlusBlk, genLoopBegin }; #endif #define PastWhiteSpace(s) while (*(s) == ' ' || *(s) == '\t') {s++;} static int tabs = 0; /* MR6 Got tired of text running off page when using standard tab stops */ #define TAB { int i; \ if (TabWidth==0) { \ for (i=0; irname);} else gen1("zzTRACEOUT((ANTLRChar *)\"%s\");\n", q->rname); } static void #ifdef __USE_PROTOS warn_about_using_gk_option(void) #else warn_about_using_gk_option() #endif { static int warned_already=0; if ( !DemandLookahead || warned_already ) return; warned_already = 1; warnNoFL("-gk option could cause trouble for <<...>>? predicates"); } void #ifdef __USE_PROTOS freeBlkFsets( Junction *q ) #else freeBlkFsets( q ) Junction *q; #endif { int i; Junction *alt; require(q!=NULL, "freeBlkFsets: invalid node"); for (alt=q; alt != NULL; alt= (Junction *) alt->p2 ) { for (i=1; i<=CLL_k; i++) set_free(alt->fset[i]); } } /* * Generate a local variable allocation for each token references * in this block. */ static void #ifdef __USE_PROTOS genTokenPointers( Junction *q ) #else genTokenPointers( q ) Junction *q; #endif { /* Rule refs are counted and can be referenced, but their * value is not set to anything useful ever. * * The ptrs are to be named _tij where i is the current level * and j is the element number within an alternative. */ int first=1, t=0; set a; tokensRefdInBlock = q->tokrefs; if ( set_deg(q->tokrefs) == 0 ) return; a = set_dup(q->tokrefs); gen("ANTLRTokenPtr "); for (; !set_nil(a); set_rm(t, a)) { t = set_int(a); if ( first ) first = 0; else _gen(","); if ( !DontCopyTokens ) _gen2("_tv%d%d,", BlkLevel, t); _gen2("_t%d%d", BlkLevel, t); if ( !DontCopyTokens ) {_gen2("= &_tv%d%d", BlkLevel, t);} else _gen("=NULL"); } _gen(";\n"); set_free(a); } static int #ifdef __USE_PROTOS hasDefaultException(ExceptionGroup *eg) #else hasDefaultException(eg) ExceptionGroup *eg; #endif { ListNode *q; for (q = eg->handlers->next; q!=NULL; q=q->next) { ExceptionHandler *eh = (ExceptionHandler *)q->elem; if ( strcmp("default", eh->signalname)==0 ) { return 1; } } return 0; } static void #ifdef __USE_PROTOS dumpException(ExceptionGroup *eg, int no_default_case) #else dumpException(eg, no_default_case) ExceptionGroup *eg; int no_default_case; #endif { char *outerLabel; /* MR7 */ int altHandler=0; /* MR7 */ int namedHandler=0; /* MR7 */ outerLabel=findOuterHandlerLabel(eg); /* MR7 */ if (eg->label != NULL) { /* MR7 */ namedHandler=1; /* MR7 */ } else if (eg->forRule) { /* MR7 */ /* nothing */ /* MR20 */ } else { /* MR7 */ altHandler=1; /* MR7 */ }; /* MR7 */ #if 0 ** if (! eg->used) { /* MR7 */ ** warnFL("exception group never used", /* MR7 */ ** FileStr[eg->altstart->file],eg->altstart->line); /* MR7 */ ** }; /* MR7 */ #endif if (namedHandler) { /* MR7 */ gen1("switch ( _signal ) { /* [%s] */\n",eg->label); /* MR7 */ } else { /* MR7 */ gen("switch ( _signal ) {\n"); /* MR7 */ gen("case NoSignal: break; /* MR7 */\n"); /* MR7 */ }; /* MR7 */ { ListNode *q; for (q = eg->handlers->next; q!=NULL; q=q->next) { ExceptionHandler *eh = (ExceptionHandler *)q->elem; if ( strcmp("default", eh->signalname)==0 ) { gen("default :\n"); tabs++; dumpAction(eh->action, output, tabs, -1, 1, 1); gen("_signal=NoSignal; /* MR7 */\n"); /* MR7 */ gen("break; /* MR7 */\n"); /* MR7 */ tabs--; gen("}\n"); /* copied from later code in dumpException MR7 */ if (namedHandler) { /* MR7 */ gen("if (_signal != NoSignal)"); /* MR7 */ _gen1(" goto %s_handler; /* MR7 */\n",outerLabel);/* MR7 */ } else if (altHandler) { /* MR7 */ gen1("goto %s_handler; /* MR7 */\n",outerLabel); /* MR7 */ }; return; } gen1("case %s :\n", eh->signalname); tabs++; if ( eh->action != NULL ) { dumpAction(eh->action, output, tabs, -1, 1, 1); gen("break; /* MR7 */\n"); /* MR7 */ } tabs--; } } if ( no_default_case ) return; gen("default :\n"); tabs++; /* MR7 */ gen("break; /* MR7 */\n"); /* MR7 */ tabs--; /* MR7 */ tabs++; /***** gen("*_retsignal = _signal;\n"); *****/ tabs--; gen("}\n"); if (namedHandler) { /* MR7 */ gen("if (_signal != NoSignal)"); /* MR7 */ _gen1(" goto %s_handler; /* MR7 */\n",outerLabel); /* MR7 */ } else if (altHandler) { /* MR7 */ gen1("goto %s_handler; /* MR7 */\n",outerLabel); /* MR7 */ }; } static void #ifdef __USE_PROTOS dumpExceptions(ListNode *list) #else dumpExceptions(list) ListNode *list; #endif { ListNode *p; for (p = list->next; p!=NULL; p=p->next) { ExceptionGroup *eg = (ExceptionGroup *) p->elem; _gen2("%s%s_handler:\n", eg->label==NULL?"":eg->label, eg->altID==NULL?"":eg->altID); if ( eg->altID!=NULL ) dumpException(eg, 0); else { /* This must be the rule exception handler */ dumpException(eg, 1); if ( !hasDefaultException(eg) ) { gen("default :\n"); tabs++; gen("zzdflthandlers(_signal,_retsignal);\n"); tabs--; gen("}\n"); } } } } /* For each element label that is found in a rule, generate a unique * Attribute (and AST pointer if GenAST) variable. */ void #ifdef __USE_PROTOS genElementLabels(ListNode *list) #else genElementLabels(list) ListNode *list; #endif { int first=1; ListNode *p; if ( GenCC ) {gen("ANTLRTokenPtr");} else {gen("Attrib");} for (p = list->next; p!=NULL; p=p->next) { char *ep = (char *)p->elem; if ( first ) first = 0; else _gen(","); if ( GenCC ) {_gen1(" %s=NULL",ep);} else {_gen1(" %s",ep);} } _gen(";\n"); if ( !GenAST ) return; first = 1; gen("AST"); for (p = list->next; p!=NULL; p=p->next) { char *ep = (char *)p->elem; if ( first ) first = 0; else _gen(","); _gen1(" *%s_ast=NULL",ep); } _gen(";\n"); } /* * Generate a local variable allocation for each token or rule reference * in this block. */ static void #ifdef __USE_PROTOS genASTPointers( Junction *q ) #else genASTPointers( q ) Junction *q; #endif { int first=1, t; set a; a = set_or(q->tokrefs, q->rulerefs); if ( set_deg(a) > 0 ) { gen("AST "); for (; !set_nil(a); set_rm(t, a)) { t = set_int(a); if ( first ) first = 0; else _gen(","); _gen2("*_ast%d%d=NULL", BlkLevel, t); } set_free(a); } _gen(";\n"); } static void #ifdef __USE_PROTOS BLOCK_Head( void ) #else BLOCK_Head( ) #endif { gen("{\n"); tabs++; if ( !GenCC ) gen1("zzBLOCK(zztasp%d);\n", BlkLevel); } static void #ifdef __USE_PROTOS BLOCK_Tail( void ) #else BLOCK_Tail( ) #endif { if ( !GenCC ) gen1("zzEXIT(zztasp%d);\n", BlkLevel); if ( !GenCC ) gen("}\n"); tabs--; gen("}\n"); } static void #ifdef __USE_PROTOS BLOCK_Preamble( Junction *q ) #else BLOCK_Preamble( q ) Junction *q; #endif { ActionNode *a; Junction *begin; BLOCK_Head(); if ( GenCC ) genTokenPointers(q); if ( GenCC&&GenAST ) genASTPointers(q); if ( q->jtype == aPlusBlk ) gen("int zzcnt=1;\n"); if ( q->parm != NULL && !q->predparm ) gen1("zzaPush(%s);\n", q->parm) else if ( !GenCC ) gen("zzMake0;\n"); if ( !GenCC ) gen("{\n"); if ( q->jtype == aLoopBegin ) begin = (Junction *) ((Junction *)q->p1); else begin = q; if ( has_guess_block_as_first_item(begin) ) { gen("zzGUESS_BLOCK\n"); } if ( q->jtype == aLoopBegin ) a = findImmedAction( ((Junction *)q->p1)->p1 ); /* look at aLoopBlk */ else a = findImmedAction( q->p1 ); if ( a!=NULL && !a->is_predicate) { if (!a->noHoist) dumpAction(a->action, output, tabs, a->file, a->line, 1); a->done = 1; /* remove action. We have already handled it */ } } void #ifdef __USE_PROTOS genCombinedPredTreeContextOrig( Predicate *p ) #else genCombinedPredTreeContextOrig( p ) Predicate *p; #endif { static set *ctx=NULL; /* genExprSets() is destructive, make copy*/ require(p!=NULL, "can't make context tree for NULL pred tree"); #ifdef DBG_PRED fprintf(stderr, "enter genCombinedPredTreeContextOrig(%s,0x%x) with sets:\n", p->expr, p); s_fprT(stderr, p->scontext[1]); fprintf(stderr, "\n"); #endif if ( p->down == NULL ) { /*** if ( p->k>1 && p->tcontext!=NULL ) ***/ if ( p->tcontext!=NULL ) { _gen("("); genExprTree(p->tcontext, 1); _gen(")"); } /*** else if ( p->k==1 && set_deg(p->scontext[1])>0 ) ***/ else if ( set_deg(p->scontext[1])>0 ) { if ( ctx==NULL ) ctx = (set *)calloc(CLL_k+1, sizeof(set)); require(ctx!=NULL, "ctx cannot allocate"); ctx[0]=empty; ctx[1]=set_dup(p->scontext[1]); _gen("("); genExprSets(&(ctx[0]), p->k); _gen(")"); set_free(ctx[1]); } else if ( p->expr==PRED_AND_LIST || p->expr==PRED_OR_LIST ) { fatal_internal("pred tree is orphan OR or AND list"); } else { if (! HoistPredicateContext) { _gen(" 1 /* no context: prc is off */ "); } else { fatal_internal("pred tree context is empty"); }; } return; } /* MR10 - make AND just like OR */ if ( p->expr == PRED_AND_LIST ) { Predicate *list = p->down; for (; list!=NULL; list=list->right) { genCombinedPredTreeContextOrig(list); if ( list->right!=NULL ) _gen("|| /* MR10 was wrong */ "); }; return; } if ( p->expr == PRED_OR_LIST ) { Predicate *list = p->down; for (; list!=NULL; list=list->right) { genCombinedPredTreeContextOrig(list); if ( list->right!=NULL ) _gen("||"); }; return; }; fatal("pred tree is really wacked"); } /* [genCombinedPredTreeContext] */ void #ifdef __USE_PROTOS genCombinedPredTreeContext( Predicate *p ) #else genCombinedPredTreeContext( p ) Predicate *p; #endif { Tree *t; int predDepth=0; if (0 && ! MR_usingPredNames && ! MRhoisting) { genCombinedPredTreeContextOrig(p); } else { /* MR13 */ MR_pred_depth(p,&predDepth); /* MR13 */ if (predDepth == 1) { /* MR13 */ /* MR13 */ set scontext[2]; /* MR13 */ scontext[0]=empty; /* MR13 */ scontext[1]=MR_compute_pred_set(p); /* MR13 */ if (set_nil(scontext[1])) { /* MR13 */ _gen(" 1 /* MR12 no context (-prc off) */ "); /* MR13 */ } else { /* MR13 */ _gen("("); /* MR13 */ genExprSets(&scontext[0], 1); /* MR13 */ set_free(scontext[1]); /* MR13 */ _gen(")"); /* MR13 */ }; } else { t=MR_compute_pred_tree_context(p); if (t == NULL) { _gen(" 1 /* MR12 no context (-prc off) */ "); } else { _gen("("); genExprTree(t, 1); Tfree(t); /* MR10 */ _gen(")"); }; }; }; } /* [genPredTreeGate] */ void #ifdef __USE_PROTOS genPredTreeGate( Predicate *p, int in_and_expr ) #else genPredTreeGate( p, in_and_expr ) Predicate *p; int in_and_expr; #endif { if ( in_and_expr ) { _gen("!("); genCombinedPredTreeContext(p); _gen(")||"); if ( p->down!=NULL ) _gen("\n"); } else { _gen("("); genCombinedPredTreeContext(p); _gen(")&&"); if ( p->down!=NULL ) _gen("\n"); } } #ifdef __USE_PROTOS void genPredEntry(Predicate *p,int outer) #else void genPredEntry(p,outer) Predicate *p; int outer; #endif { int inverted=0; Predicate *q; int localOuter=outer; int needRP=0; if (p == NULL) return; if (p->predEntry != NULL && p->predEntry->predLiteral != NULL) { if (p->inverted != p->predEntry->pred->inverted) { _gen("! /* inverted pred */ ("); needRP=1; } else { if (!localOuter) _gen("("); needRP=1; }; dumpAction(p->predEntry->predLiteral,output,0,p->source->file,p->source->line,0); if (needRP) _gen(")"); return; }; inverted=p->inverted; if (inverted) { _gen(" ! /* inverted pred */ ("); localOuter=1; }; if (p->expr == PRED_OR_LIST) { if (!localOuter) _gen("("); for (q=p->down; q != NULL ; q=q->right) { genPredEntry(q,0); if (q->right != NULL) _gen(" || "); }; if (!localOuter) _gen(")"); } else if (p->expr == PRED_AND_LIST) { if (!localOuter) _gen("("); for (q=p->down; q != NULL ; q=q->right) { genPredEntry(q,0); if (q->right != NULL) _gen(" && "); }; if (!localOuter) _gen(")"); } else { if (!localOuter) _gen("("); require (p->source != NULL,"predEntry->source == NULL"); require (p->source->inverted == 0,"dumpPredEntry p->source->inverted != 0"); dumpAction(p->source->action,output,0,p->source->file,p->source->line,0); if (!localOuter) _gen(")"); }; if (inverted) { _gen(")"); } } void #ifdef __USE_PROTOS dumpPredAction(ActionNode *anode, char *s,FILE *output,int tabs,int file,int line,int final_newline) #else dumpPredAction(anode, s,output,tabs,file,line,final_newline) ActionNode *anode; char *s; FILE *output; int tabs; int file; int line; int final_newline; #endif { PredEntry *predEntry=anode->predEntry; int inverted=anode->inverted; Predicate *workPred; if (predEntry == NULL) { /* inline predicate literal */ require(inverted == 0,"dumpPredAction action->inverted"); dumpAction(s,output,tabs,file,line,final_newline); } else { /* a reference to a predicate - possibly with an inverted source */ if (predEntry->predLiteral != NULL) { if (inverted) _gen("! /* inverted pred */ ("); dumpAction(predEntry->predLiteral,output,0,anode->file,anode->line,0); if (inverted) _gen(")"); } else { workPred=predicate_dup(predEntry->pred); if (inverted) workPred->inverted=!workPred->inverted; genPredEntry(workPred,1); predicate_free(workPred); }; }; } /* [genPred] */ void #ifdef __USE_PROTOS genPred(Predicate *p, Node *j,int suppress_sva) #else genPred(p,j,suppress_sva) Predicate *p; Node *j; int suppress_sva; #endif { if ( FoundException && !suppress_sva) {_gen("(_sva=(");} /* MR11 suppress_sva */ else {_gen("(");} if ( GenLineInfo && j->file != -1 ) _gen("\n"); if (p->source != NULL && p->source->ampersandPred != NULL) { if (p->source->ampersandPred->k == 1) { set ctx[2]; ctx[0]=empty; ctx[1]=set_dup(p->source->ampersandPred->scontext[1]); _gen("("); genExprSets(&(ctx[0]), p->k); _gen(") && "); set_free(ctx[1]); } else { _gen("( "); genExprTree(p->source->ampersandPred->tcontext,1); _gen(" ) && "); }; }; dumpPredAction((ActionNode *)p->source, p->expr, output, 0, -1 /*indicates no line info*/, j->line, 0); if ( FoundException && !suppress_sva) /* MR11 suppress_sva */ {_gen("),_sva)");} /* MR10 - get red of "meant ==" messages */ else {_gen(")");} } void #ifdef __USE_PROTOS MR_distinctORcontextOpt(Predicate *p,Node *j,int in_and_expr) #else MR_distinctORcontextOpt(p,j,in_and_expr) Predicate *p; Node *j; int in_and_expr; #endif { Predicate *q; _gen(" /* MR10 Distinct OR context optimization */ \n"); if (in_and_expr) { gen("zzpf=0,\n"); for (q=p->down; q != NULL; q=q->right) { gen("( "); genCombinedPredTreeContext(q); _gen(" && (zzpf=1, "); genPred(q,j,0); _gen(" )) ||\n"); }; gen("!zzpf)"); } else { require (0, "MR_distinctORcontextOpt: can't get here when using MR_predSimplify"); #if 0 ** for (q=p->down; q != NULL; q=q->right) { ** gen("( "); ** genCombinedPredTreeContext(q); ** _gen(" && "); ** genPred(q,j); ** if (q->right != NULL) { ** _gen(" ) ||\n"); ** }; ** }; ** gen(")"); #endif }; } void #ifdef __USE_PROTOS genPredTreeOrig( Predicate *p, Node *j, int in_and_expr ) #else genPredTreeOrig( p, j, in_and_expr ) Predicate *p; Node *j; int in_and_expr; #endif { /* MR10 */ int allHaveContext=1; /* MR10 */ int noneHaveContext=1; /* MR10 */ MR_predContextPresent(p,&allHaveContext,&noneHaveContext); if ( ! noneHaveContext ) /* MR10 context guards ignored when -prc off */ { _gen("("); genPredTreeGate(p, in_and_expr); } /* if leaf node, just gen predicate */ if ( p->down==NULL ) { genPred(p,j,0); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; } /* if AND list, do both preds (only two possible) */ if ( p->expr == PRED_AND_LIST ) { #if 0 ** _gen("("); ** genPredTreeOrig(p->down, j, 1); ** _gen("&&"); ** genPredTreeOrig(p->down->right, j, 1); ** _gen(")"); ** if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ ** return; #endif /* MR11 - make it work with AND with more than two children - like OR */ Predicate *list; _gen("("); list = p->down; for (; list!=NULL; list=list->right) { genPredTreeOrig(list, j, 1); if ( list->right!=NULL ) _gen("&&"); } _gen(")"); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; }; if ( p->expr == PRED_OR_LIST ) { Predicate *list; _gen("("); list = p->down; for (; list!=NULL; list=list->right) { genPredTreeOrig(list, j, 0); if ( list->right!=NULL ) _gen("||"); } _gen(")"); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; } fatal_internal("genPredTreeOrig: predicate tree is wacked"); } #if 0 ** Predicate member dummyPredDepth is no longer used in MR10 ** but we might need it again in the future ** ** if (MRhoisting) { ** if ( !noneHaveContext && ** ! in_and_expr && ** p->source != NULL && ** p->source->dummyPredicateDepth > 0 && ** p->down == NULL) { ** _gen("("); ** genCombinedPredTreeContext(p); ** _gen(" )\n"); ** return; ** }; ** }; #endif /* [genPredTree] */ /* in_and_expr what to do if the context is wrong what to do if the context is correct but the predicate is false remember: if the context is wrong it's the same as if the predicate is true as far as enabling an alternative Consider (AND p q r) if in an ... && ... expression then you don't want the entire predicate chain to fail just because the context for one component is wrong: so return true Consider (OR p q r) if in an ... || ... expression then you don't want the entire predicate chain to succeed just because the context for one component is correct when the corresponding test is false: so return false when the context is correct but the test is false. */ void #ifdef __USE_PROTOS genPredTree( Predicate *p, Node *j, int in_and_expr, int suppress_sva ) #else genPredTree( p, j, in_and_expr, suppress_sva) Predicate *p; Node *j; int in_and_expr; int suppress_sva; #endif { int allHaveContext=1; int noneHaveContext=1; Tree *groupTree; Tree *oneTree; Predicate *q; int identicalORcontextOptimization=0; int identicalANDcontextOptimization=0; if (0 && !MR_usingPredNames && !MRhoisting) { genPredTreeOrig(p,j,in_and_expr); return; }; MR_predContextPresent(p,&allHaveContext,&noneHaveContext); if ( ! noneHaveContext ) { /* MR10 context guards ignored when -prc off */ _gen("("); /* MR10 optimize OR predicates which are all leaves */ if (p->expr == PRED_OR_LIST && MR_allPredLeaves(p->down)) { groupTree=MR_compute_pred_tree_context(p); for (q=p->down ; q != NULL ; q=q->right) { oneTree=MR_compute_pred_tree_context(q); if (! MR_tree_equ(groupTree,oneTree)) { Tfree(oneTree); break; }; Tfree(oneTree); }; Tfree(groupTree); if (q == NULL) { _gen("/* MR10 individual OR gates suppressed when all predicates are leaves"); _gen(" with identical context */\n"); genPredTreeGate(p,in_and_expr); /* use the parent's in_and_expr for this gate */ identicalORcontextOptimization=1; } else { MR_distinctORcontextOpt(p,j,in_and_expr); return; }; } else if (p->expr == PRED_AND_LIST && MR_allPredLeaves(p->down)) { /* MR12 optimize AND predicates which are all leaves */ groupTree=MR_compute_pred_tree_context(p); for (q=p->down ; q != NULL ; q=q->right) { oneTree=MR_compute_pred_tree_context(q); if (! MR_tree_equ(groupTree,oneTree)) { Tfree(oneTree); break; }; Tfree(oneTree); }; Tfree(groupTree); if (q == NULL) { _gen("/* MR12 individual AND gates suppressed when all predicates are leaves"); _gen(" with identical context */\n"); genPredTreeGate(p,in_and_expr); /* use the parent's in_and_expr for this gate */ identicalANDcontextOptimization=1; } else { genPredTreeGate(p, in_and_expr); }; } else { genPredTreeGate(p, in_and_expr); }; } /* if leaf node, just gen predicate */ if ( p->down==NULL ) { genPred(p,j,suppress_sva); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; } /* if AND list, do both preds (only two possible) */ /* MR10 not any more ! */ if ( p->expr == PRED_AND_LIST ) { Predicate *list; _gen("("); list = p->down; for (; list != NULL; list=list->right) { if (identicalANDcontextOptimization) { genPred(list, j,suppress_sva); } else { genPredTree(list, j, 1, suppress_sva); /* in and context */ }; if ( list->right!=NULL ) _gen("&&"); }; _gen(")"); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; } if ( p->expr == PRED_OR_LIST ) { Predicate *list; _gen("("); list = p->down; for (; list!=NULL; list=list->right) { if (identicalORcontextOptimization) { genPred(list, j,suppress_sva); } else { genPredTree(list, j, 0, suppress_sva); }; if ( list->right!=NULL ) _gen("||"); } _gen(")"); if ( ! noneHaveContext ) _gen(")"); /* MR10 context guards ignored when -prc off */ return; } fatal_internal("predicate tree is wacked"); } /* [genPredTreeMainXX] */ Predicate * /* MR10 */ #ifdef __USE_PROTOS genPredTreeMainXX( Predicate *p, Node *j ,int in_and_expr) #else genPredTreeMainXX( p, j ,in_and_expr) Predicate *p; Node *j; int in_and_expr; #endif { int allHaveContext=1; int noneHaveContext=1; #if 0 fprintf(stderr,"Pred before\n"); dumppred(p); fprintf(stderr,"\n"); fprintf(stderr,"Pred after\n"); dumppred(p); fprintf(stderr,"\n"); #endif p=MR_predSimplifyALL(p); /* MR10 */ require (MR_predicate_context_completed(p),"predicate context is not complete"); MR_cleanup_pred_trees(p); /* MR10 */ MR_predContextPresent(p,&allHaveContext,&noneHaveContext); if (!noneHaveContext & !allHaveContext) { warnFL("predicate contains elements both with and without context", FileStr[j->file],j->line); }; if (InfoP) { _gen("\n#if 0\n\n"); MR_dumpPred(p,1); _gen("#endif\n"); }; genPredTree(p,j,in_and_expr,0); return p; } Predicate * /* MR10 */ #ifdef __USE_PROTOS genPredTreeMain( Predicate *p, Node *j) #else genPredTreeMain( p, j) Predicate *p; Node *j; #endif { return genPredTreeMainXX(p,j,1); } static void #ifdef __USE_PROTOS genExprTreeOriginal( Tree *t, int k ) #else genExprTreeOriginal( t, k ) Tree *t; int k; #endif { require(t!=NULL, "genExprTreeOriginal: NULL tree"); if ( t->token == ALT ) { _gen("("); genExprTreeOriginal(t->down, k); _gen(")"); if ( t->right!=NULL ) { _gen("||"); on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } _gen("("); genExprTreeOriginal(t->right, k); _gen(")"); } return; } if ( t->down!=NULL ) _gen("("); _gen1("LA(%d)==",k); if ( TokenString(t->token) == NULL ) _gen1("%d", t->token) else _gen1("%s", TokenString(t->token)); if ( t->down!=NULL ) { _gen("&&"); on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } _gen("("); genExprTreeOriginal(t->down, k+1); _gen(")"); } if ( t->down!=NULL ) _gen(")"); if ( t->right!=NULL ) { _gen("||"); on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } _gen("("); genExprTreeOriginal(t->right, k); _gen(")"); } } #ifdef __USE_PROTOS static void MR_LAtokenString(int k,int token) #else static void MR_LAtokenString(k,token) int k; int token; #endif { char *ts; ts=TokenString(token); if (ts == NULL) { _gen2(" LA(%d)==%d",k,token); } else { _gen2(" LA(%d)==%s",k,ts); }; } #ifdef __USE_PROTOS static int MR_countLeaves(Tree *t) #else static int MR_countLeaves(t) Tree *t; #endif { if (t == NULL) return 0; if (t->token == ALT) { return MR_countLeaves(t->down)+MR_countLeaves(t->right); } else { return 1+MR_countLeaves(t->down)+MR_countLeaves(t->right); }; } #ifdef __USE_PROTOS static void MR_genOneLine(Tree *tree,int k) #else static void MR_genOneLine(tree,k) Tree *tree; int k; #endif { if (tree == NULL) return; if (tree->token == ALT) { MR_genOneLine(tree->down,k); } else { MR_LAtokenString(k,tree->token); if (tree->down != NULL && tree->down->right == NULL) { _gen(" &&"); MR_genOneLine(tree->down,k+1); } else if (tree->down != NULL) { _gen(" && ("); MR_genOneLine(tree->down,k+1); _gen(")"); }; }; if (tree->right != NULL) { _gen(" ||"); MR_genOneLine(tree->right,k); }; } static int across; static int depth; static int lastkonline; #ifdef __USE_PROTOS static void MR_genMultiLine(Tree *tree,int k) #else static void MR_genMultiLine(tree,k) Tree *tree; int k; #endif { int i; if (tree == NULL) return; if (tree->token == ALT) { MR_genMultiLine(tree,k); } else { MR_LAtokenString(k,tree->token); lastkonline=k; across++; if (tree->down != NULL && tree->down->right == NULL) { if (across > 3) { _gen("\n"); across=0; lastkonline=0; for (i=0 ; i < depth+k ; i++) _gen(" "); _gen("&&"); } else { _gen(" &&"); }; MR_genMultiLine(tree->down,k+1); } else if (tree->down != NULL) { _gen("\n"); lastkonline=0; across=0; for (i=0 ; i < depth+k ; i++) _gen(" "); _gen("&& ("); MR_genMultiLine(tree->down,k+1); _gen(")"); }; }; if (tree->right != NULL) { if (k < lastkonline) { _gen("\n"); across=0; lastkonline=0; for (i=0; i < depth+k-1 ; i++) _gen(" "); _gen("||"); } else if (across > 3 ) { _gen("\n"); across=0; lastkonline=0; for (i=0; i < depth+k ; i++) _gen(" "); _gen("||"); } else { _gen(" ||"); }; MR_genMultiLine(tree->right,k); }; } #ifdef __USE_PROTOS static void genExprTree(Tree *tree,int k) #else static void genExprTree(tree,k) Tree *tree; int k; #endif { int count; #if 0 /* MR20 THM This was probably an error. The routine should probably reference that static "across" and this declaration hides it. */ int across; #endif require (tree != NULL,"genExprTree: tree is NULL"); require (k > 0,"genExprTree: k <= 0"); if (0 && !MRhoisting) { /* MR11 make new version standard */ genExprTreeOriginal(tree,k); } else { count=MR_countLeaves(tree); if (count < 5) { MR_genOneLine(tree,k); } else { _gen("\n"); across=0; depth=0; lastkonline=0; MR_genMultiLine(tree,k); _gen("\n"); }; }; } /* * Generate LL(k) type expressions of the form: * * (LA(1) == T1 || LA(1) == T2 || ... || LA(1) == Tn) && * (LA(2) == T1 || LA(2) == T2 || ... || LA(2) == Tn) && * ..... * (LA(k) == T1 || LA(k) == T2 || ... || LA(k) == Tn) * * If GenExprSetsOpt generate: * * (setwdi[LA(1)]&(1<= 1. * * This routine is visible only to this file and cannot answer a TRANS message. * */ /* [genExpr] */ static int #ifdef __USE_PROTOS genExpr( Junction *j ) #else genExpr( j ) Junction *j; #endif { int max_k; /* if full LL(k) is sufficient, then don't use approximate (-ck) lookahead * from CLL_k..LL_k */ { int limit; if ( j->ftree!=NULL ) limit = LL_k; else limit = CLL_k; max_k = genExprSets(j->fset, limit); } /* Do tests for real tuples from other productions that conflict with * artificial tuples generated by compression (using sets of tokens * rather than k-trees). */ if ( j->ftree != NULL ) { _gen(" && !("); genExprTree(j->ftree, 1); _gen(")"); } if ( ParseWithPredicates && j->predicate!=NULL ) { Predicate *p = j->predicate; warn_about_using_gk_option(); _gen("&&"); j->predicate=genPredTreeMain(p, (Node *)j); /* MR10 */ } return max_k; } static int #ifdef __USE_PROTOS genExprSets( set *fset, int limit ) #else genExprSets( fset, limit ) set *fset; int limit; #endif { int k = 1; int max_k = 0; unsigned *e, *g, firstTime=1; if (set_nil(fset[1])) { _gen(" 0 /* MR13 empty set expression - undefined rule ? infinite left recursion ? */ "); MR_BadExprSets++; }; if ( GenExprSetsOpt ) { while ( k <= limit && !set_nil(fset[k]) ) /* MR11 */ { if ( set_deg(fset[k])==1 ) /* too simple for a set? */ { int e; _gen1("(LA(%d)==",k); e = set_int(fset[k]); if ( TokenString(e) == NULL ) _gen1("%d)", e) else _gen1("%s)", TokenString(e)); } else { NewSet(); FillSet( fset[k] ); _gen3("(setwd%d[LA(%d)]&0x%x)", wordnum, k, 1<max_k ) max_k = k; if ( k == CLL_k ) break; k++; if ( k<=limit && !set_nil(fset[k]) ) _gen(" && "); /* MR11 */ on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } } return max_k; } while ( k<= limit && !set_nil(fset[k]) ) /* MR11 */ { if ( (e=g=set_pdq(fset[k])) == NULL ) fatal_internal("genExpr: cannot allocate IF expr pdq set"); for (; *e!=nil; e++) { if ( !firstTime ) _gen(" || ") else { _gen("("); firstTime = 0; } on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } _gen1("LA(%d)==",k); if ( TokenString(*e) == NULL ) _gen1("%d", *e) else _gen1("%s", TokenString(*e)); } free( (char *)g ); _gen(")"); if ( k>max_k ) max_k = k; if ( k == CLL_k ) break; k++; if ( k <= limit && !set_nil(fset[k]) ) { firstTime=1; _gen(" && "); } /* MR11 */ on1line++; if ( on1line > NumExprPerLine ) { on1line=0; _gen("\n"); } } return max_k; } /* * Generate code for any type of block. If the last alternative in the block is * empty (not even an action) don't bother doing it. This permits us to handle * optional and loop blocks as well. * * Only do this block, return after completing the block. * This routine is visible only to this file and cannot answer a TRANS message. */ static set #ifdef __USE_PROTOS genBlk( Junction *q, int jtype, int *max_k, int *need_right_curly ) #else genBlk( q, jtype, max_k, need_right_curly ) Junction *q; int jtype; int *max_k; int *need_right_curly; #endif { set f; Junction *alt; int a_guess_in_block = 0; require(q!=NULL, "genBlk: invalid node"); require(q->ntype == nJunction, "genBlk: not junction"); *need_right_curly=0; if ( q->p2 == NULL ) /* only one alternative? Then don't need if */ { if (first_item_is_guess_block((Junction *)q->p1)!=NULL ) { if (jtype != aLoopBlk && jtype != aOptBlk && jtype != aPlusBlk) { warnFL("(...)? as only alternative of block is unnecessary", FileStr[q->file], q->line); }; gen("zzGUESS\n"); /* guess anyway to make output code consistent */ /* MR10 disable */ /**** gen("if ( !zzrv )\n"); ****/ /* MR10 */ gen("if ( !zzrv ) {\n"); tabs++; (*need_right_curly)++; }; TRANS(q->p1); return empty; /* no decision to be made-->no error set */ } f = First(q, 1, jtype, max_k); for (alt=q; alt != NULL; alt= (Junction *) alt->p2 ) { if ( alt->p2 == NULL ) /* chk for empty alt */ { Node *p = alt->p1; if ( p->ntype == nJunction ) { /* we have empty alt */ if ( ((Junction *)p)->p1 == (Node *)q->end ) { break; /* don't do this one, quit */ } } } /* MR10 */ if (alt->p2 == NULL && /* MR10 */ ( q->jtype == aSubBlk || q->jtype == RuleBlk) ) { /* MR10 */ if (first_item_is_guess_block(alt)) { /* MR10 */ warnFL("(...)? as last alternative of block is unnecessary", /* MR10 */ FileStr[alt->file],alt->line); /* MR10 */ }; /* MR10 */ }; if ( alt != q ) gen("else ") else { if ( DemandLookahead ) if ( !GenCC ) {gen1("LOOK(%d);\n", *max_k);} else gen1("look(%d);\n", *max_k); } if ( alt!=q ) { _gen("{\n"); tabs++; (*need_right_curly)++; /* code to restore state if a prev alt didn't follow guess */ if ( a_guess_in_block ) gen("if ( !zzrv ) zzGUESS_DONE;\n"); } if ( first_item_is_guess_block((Junction *)alt->p1)!=NULL ) { a_guess_in_block = 1; gen("zzGUESS\n"); } gen("if ( "); if ( first_item_is_guess_block((Junction *)alt->p1)!=NULL ) _gen("!zzrv && "); genExpr(alt); _gen(" ) "); _gen("{\n"); tabs++; TRANS(alt->p1); --tabs; gen("}\n"); /* MR10 */ if (alt->p2 == NULL) { /* MR10 */ if (first_item_is_guess_block(alt)) { /* MR10 */ gen("/* MR10 */ else {\n"); /* MR10 */ tabs++; /* MR10 */ (*need_right_curly)++; /* MR10 */ /* code to restore state if a prev alt didn't follow guess */ /* MR10 */ gen("/* MR10 */ if ( !zzrv ) zzGUESS_DONE;\n"); /* MR10 */ gen("/* MR10 */ if (0) {} /* last alternative of block is guess block */\n"); /* MR10 */ }; /* MR10 */ }; } return f; } static int #ifdef __USE_PROTOS has_guess_block_as_first_item( Junction *q ) #else has_guess_block_as_first_item( q ) Junction *q; #endif { Junction *alt; for (alt=q; alt != NULL; alt= (Junction *) alt->p2 ) { if ( first_item_is_guess_block((Junction *)alt->p1)!=NULL ) return 1; } return 0; } static int #ifdef __USE_PROTOS has_guess_block_as_last_item( Junction *q ) #else has_guess_block_as_last_item( q ) Junction *q; #endif { Junction *alt; if (q == NULL) return 0; for (alt=q; alt->p2 != NULL && !( (Junction *) alt->p2)->ignore; alt= (Junction *) alt->p2 ) {}; return first_item_is_guess_block( (Junction *) alt->p1) != NULL; } /* return NULL if 1st item of alt is NOT (...)? block; else return ptr to aSubBlk node * of (...)?; This function ignores actions and predicates. */ Junction * #ifdef __USE_PROTOS first_item_is_guess_block( Junction *q ) #else first_item_is_guess_block( q ) Junction *q; #endif { /* MR14 Couldnt' find aSubBlock which was a guess block when it lay behind aLoopBlk. The aLoopBlk only appear in conjunction with aLoopBegin, but the routine didn't know that. I think. MR14a Added extra parentheses to clarify precedence */ while ( q!=NULL && ( ( q->ntype==nAction ) || ( q->ntype==nJunction && (q->jtype==Generic || q->jtype == aLoopBlk) ) ) ) { if ( q->ntype==nJunction ) q = (Junction *)q->p1; else q = (Junction *) ((ActionNode *)q)->next; } if ( q==NULL ) return NULL; if ( q->ntype!=nJunction ) return NULL; if ( q->jtype!=aSubBlk ) return NULL; if ( !q->guess ) return NULL; return q; } /* MR1 */ /* MR1 10-Apr-97 MR1 Routine to stringize failed semantic predicates msgs */ /* MR1 */ #define STRINGIZEBUFSIZE 1024 static char stringizeBuf[STRINGIZEBUFSIZE]; char * #ifdef __USE_PROTOS stringize(char * s) #else stringize(s) char *s; #endif { char *p; char *stop; p=stringizeBuf; stop=&stringizeBuf[1015]; if (s != 0) { while (*s != 0) { if (p >= stop) { goto stringizeStop; } else if (*s == '\n') { *p++='\\'; *p++='n'; *p++='\\'; *p++=*s++; } else if (*s == '\\') { *p++=*s; *p++=*s++; } else if (*s == '\"') { *p++='\\'; *p++=*s++; while (*s != 0) { if (p >= stop) { goto stringizeStop; } else if (*s == '\n') { *p++='\\'; *p++=*s++; } else if (*s == '\\') { *p++=*s++; *p++=*s++; } else if (*s == '\"') { *p++='\\'; *p++=*s++; break; } else { *p++=*s++; }; }; } else if (*s == '\'') { *p++=*s++; while (*s != 0) { if (p >= stop) { goto stringizeStop; } else if (*s == '\'') { *p++=*s++; break; } else if (*s == '\\') { *p++=*s++; *p++=*s++; } else if (*s == '\"') { *p++='\\'; *p++=*s++; break; } else { *p++=*s++; }; }; } else { *p++=*s++; }; }; }; goto stringizeExit; stringizeStop: *p++='.'; *p++='.'; *p++='.'; stringizeExit: *p=0; return stringizeBuf; } #ifdef __USE_PROTOS int isNullAction(char *s) #else int isNullAction(s) char *s; #endif { char *p; for (p=s; *p != '\0' ; p++) { if (*p != ';' && *p !=' ') return 0; }; return 1; } /* MR1 */ /* MR1 End of Routine to stringize code for failed predicates msgs */ /* MR1 */ /* Generate an action. Don't if action is NULL which means that it was already * handled as an init action. */ void #ifdef __USE_PROTOS genAction( ActionNode *p ) #else genAction( p ) ActionNode *p; #endif { require(p!=NULL, "genAction: invalid node and/or rule"); require(p->ntype==nAction, "genAction: not action"); if ( !p->done ) /* MR10 */ /* MR11 */ { if ( p->is_predicate) { if ( p->guardpred != NULL ) { Predicate *guardDup=predicate_dup(p->guardpred); /* MR10 */ gen("if (!"); guardDup=genPredTreeMain(guardDup, (Node *)p); predicate_free(guardDup); } /* MR10 */ else if (p->ampersandPred != NULL) { /* MR10 */ gen("if (!"); /* MR10 */ p->ampersandPred=genPredTreeMain(p->ampersandPred, (Node *)p); /* MR10 */ } else { gen("if (!("); /* make sure that '#line n' is on front of line */ if ( GenLineInfo && p->file != -1 ) _gen("\n"); dumpPredAction(p,p->action, output, 0, p->file, p->line, 0); _gen(")"); } if ( p->pred_fail != NULL ) { _gen(")\n"); tabs++; /* MR1 */ /* MR1 10-Apr-97 MR1 Put {...} envelope around failed semantic predicates */ /* MR1 */ gen1("{%s};\n", p->pred_fail); /* MR1 */ tabs--; } /* MR1 */ /* MR1 10-Apr-97 MR1 Properly stringize failed semantic predicates */ /* MR1 */ else _gen1(") {zzfailed_pred(\"%s\");}\n", /* MR1 */ stringize(p->action)); /* MR1 */ } else /* not a predicate */ { if (! isNullAction(p->action) && !p->noHoist) { if ( FoundGuessBlk ) { if ( GenCC ) { gen("if ( !guessing ) {\n"); } else { gen("zzNON_GUESS_MODE {\n"); }; }; dumpAction(p->action, output, tabs, p->file, p->line, 1); if ( FoundGuessBlk ) gen("}\n"); }; } } TRANS(p->next) } /* * if invoking rule has !noAST pass zzSTR to rule ref and zzlink it in * else pass addr of temp root ptr (&_ast) (don't zzlink it in). * * if ! modifies rule-ref, then never link it in and never pass zzSTR. * Always pass address of temp root ptr. */ void #ifdef __USE_PROTOS genRuleRef( RuleRefNode *p ) #else genRuleRef( p ) RuleRefNode *p; #endif { Junction *q; char *handler_id = ""; RuleEntry *r, *r2; char *parm = "", *exsig = ""; int genRuleRef_emittedGuessGuard=0; /* MR10 */ require(p!=NULL, "genRuleRef: invalid node and/or rule"); require(p->ntype==nRuleRef, "genRuleRef: not rule reference"); if ( p->altstart!=NULL && p->altstart->exception_label!=NULL ) handler_id = p->altstart->exception_label; r = (RuleEntry *) hash_get(Rname, p->text); if ( r == NULL ) { warnFL( eMsg1("rule %s not defined", p->text), FileStr[p->file], p->line ); return; } /* MR8 5-Aug-97 Reported by S.Bochnak@microtool.com.pl */ /* Don't do assign when no return values declared */ /* Move definition of q up and use it to guard p->assign */ q = RulePtr[r->rulenum]; /* find definition of ref'd rule */ /* MR8 */ r2 = (RuleEntry *) hash_get(Rname, p->rname); if ( r2 == NULL ) {warnNoFL("Rule hash table is screwed up beyond belief"); return;} OutLineInfo(output,p->line,FileStr[p->file]); if ( GenCC && GenAST ) { gen("_ast = NULL;\n"); } if ( FoundGuessBlk && p->assign!=NULL && q->ret != NULL ) { /* MR8 */ if ( GenCC ) { gen("if ( !guessing ) {\n"); } else { gen("zzNON_GUESS_MODE {\n"); }; tabs++; /* MR11 */ genRuleRef_emittedGuessGuard=1; /* MR11 */ }; if ( FoundException ) exsig = "&_signal"; tab(); if ( GenAST ) { if ( GenCC ) { /**** if ( r2->noAST || p->astnode==ASTexclude ) ****/ { /**** _gen("_ast = NULL;\n"); ****/ parm = "&_ast"; } /*** we always want to set just a pointer now, then set correct pointer after else { _gen("_astp = (_tail==NULL)?(&_sibling):(&(_tail->_right));\n"); parm = "_astp"; } ****/ } else { if ( r2->noAST || p->astnode==ASTexclude ) { _gen("_ast = NULL; "); parm = "&_ast"; } else parm = "zzSTR"; } if ( p->assign!=NULL && q->ret!=NULL ) /* MR8 */ { if ( !HasComma(p->assign) ) {_gen1("%s = ",p->assign);} else _gen1("{ struct _rv%d _trv; _trv = ", r->rulenum); } if ( FoundException ) { _gen5("%s%s(%s,&_signal%s%s); ", RulePrefix, p->text, parm, (p->parms!=NULL)?",":"", (p->parms!=NULL)?p->parms:""); if ( p->ex_group!=NULL ) { _gen("\n"); gen("if (_signal) {\n"); tabs++; dumpException(p->ex_group, 0); tabs--; gen("}"); } else { _gen1("if (_signal) goto %s_handler;", handler_id); } } else { _gen5("%s%s(%s%s%s);", RulePrefix, p->text, parm, (p->parms!=NULL)?",":"", (p->parms!=NULL)?p->parms:""); } if ( GenCC && (r2->noAST || p->astnode==ASTexclude) ) { /* rule has a ! or element does */ /* still need to assign to #i so we can play with it */ _gen("\n"); gen2("_ast%d%d = (AST *)_ast;", BlkLevel-1, p->elnum); } else if ( !r2->noAST && p->astnode == ASTinclude ) { /* rule doesn't have a ! and neither does element */ /* MR10 */ if (FoundGuessBlk && !genRuleRef_emittedGuessGuard) { /* MR10 */ _gen("\n"); /* MR10 */ if (GenCC) gen ("if (!guessing) { /* MR10 */") /* MR10 */ else gen ("if (!zzguessing) { /* MR10 */\n"); /* MR10 */ tabs++; /* MR10 */ }; if ( GenCC ) { _gen("\n"); gen("if ( _tail==NULL ) _sibling = _ast; else _tail->setRight(_ast);\n"); gen2("_ast%d%d = (AST *)_ast;\n", BlkLevel-1, p->elnum); tab(); } else _gen(" "); if ( GenCC ) { _gen("ASTBase::"); } else _gen("zz"); _gen("link(_root, &_sibling, &_tail);"); /* MR10 */ if (FoundGuessBlk && !genRuleRef_emittedGuessGuard) { /* MR10 */ /* MR10 */ _gen("\n"); /* MR10 */ tabs--; /* MR10 */ if (GenCC) gen ("}; /* MR10 */") /* MR10 */ else gen ("}; /* MR10 */"); /* MR10 */ }; } } else { if ( p->assign!=NULL && q->ret!=NULL ) /* MR8 */ { if ( !HasComma(p->assign) ) {_gen1("%s = ",p->assign);} else _gen1("{ struct _rv%d _trv; _trv = ", r->rulenum); } if ( FoundException ) { _gen4("%s%s(&_signal%s%s); ", RulePrefix, p->text, (p->parms!=NULL)?",":"", (p->parms!=NULL)?p->parms:""); if ( p->ex_group!=NULL ) { _gen("\n"); gen("if (_signal) {\n"); tabs++; dumpException(p->ex_group, 0); tabs--; gen("}"); } else { _gen1("if (_signal) goto %s_handler;", handler_id); } } else { _gen3("%s%s(%s);", RulePrefix, p->text, (p->parms!=NULL)?p->parms:""); } if ( p->assign!=NULL && q->ret!=NULL ) _gen("\n"); /* MR8 */ } if ( p->assign!=NULL && q->ret!=NULL) { /* MR8 */ if ( HasComma(p->assign) ) { _gen("\n"); dumpRetValAssign(p->assign, q->ret); _gen("}"); } } _gen("\n"); /* Handle element labels now */ if ( p->el_label!=NULL ) { if ( GenAST ) { if ( GenCC ) { gen3("%s_ast = _ast%d%d;\n", p->el_label, BlkLevel-1, p->elnum); } else {gen1("%s_ast = zzastCur;\n", p->el_label);} } else if (!GenCC ) { gen1("%s = zzaCur;\n", p->el_label); } } if ( FoundGuessBlk && p->assign!=NULL && q->ret!=NULL ) { /* MR8 */ /* in guessing mode, don't branch to handler upon error */ tabs--; /* MR11 */ gen("} else {\n"); tabs++; /* MR11 */ if ( FoundException ) { gen6("%s%s(%s%s&_signal%s%s);\n", RulePrefix, p->text, parm, (*parm!='\0')?",":"", (p->parms!=NULL)?",":"", (p->parms!=NULL)?p->parms:""); } else { gen5("%s%s(%s%s%s);\n", RulePrefix, p->text, parm, (p->parms!=NULL && *parm!='\0')?",":"", (p->parms!=NULL)?p->parms:""); } tabs--; /* MR11 */ gen("}\n"); } TRANS(p->next) } /* * Generate code to match a token. * * Getting the next token is tricky. We want to ensure that any action * following a token is executed before the next GetToken(); */ void #ifdef __USE_PROTOS genToken( TokNode *p ) #else genToken( p ) TokNode *p; #endif { RuleEntry *r; char *handler_id = ""; ActionNode *a; char *set_name; require(p!=NULL, "genToken: invalid node and/or rule"); require(p->ntype==nToken, "genToken: not token"); if ( p->altstart!=NULL && p->altstart->exception_label!=NULL ) handler_id = p->altstart->exception_label; r = (RuleEntry *) hash_get(Rname, p->rname); if ( r == NULL ) {warnNoFL("Rule hash table is screwed up beyond belief"); return;} OutLineInfo(output,p->line,FileStr[p->file]); if ( !set_nil(p->tset) ) /* implies '.', ~Tok, or tokenclass */ { unsigned e; set b; b = set_dup(p->tset); if ( p->tclass!=NULL ) /* token class? */ { static char buf[MaxRuleName+1]; if ( p->tclass->dumped ) e = p->tclass->setnum; else { e = DefErrSet(&b, 0, TokenString(p->token)); p->tclass->dumped = 1; /* indicate set has been created */ p->tclass->setnum = e; } sprintf(buf, "%s_set", TokenString(p->token)); set_name = buf; } else { /* wild card to ~ operator */ static char buf[sizeof("zzerr")+10]; int n = DefErrSet( &b, 0, NULL ); if ( GenCC ) sprintf(buf, "err%d", n); else sprintf(buf, "zzerr%d", n); set_name = buf; } if ( !FoundException ) {gen1("zzsetmatch(%s);", set_name);} else if ( p->ex_group==NULL ) { if ( p->use_def_MT_handler ) gen3("zzsetmatch_wdfltsig(%s,(ANTLRTokenType)%d,%s);", set_name, p->token, tokenFollowSet(p)) else gen2("zzsetmatch_wsig(%s, %s_handler);", set_name, handler_id); } else { gen1("if ( !_setmatch_wsig(%s) ) {\n", set_name); tabs++; /* MR6 */ if (FoundGuessBlk) { /* MR6 */ if ( GenCC ) {gen("if ( guessing ) goto fail;\n");} /* MR6 */ else gen("if ( zzguessing ) goto fail;\n"); /* MR6 */ }; gen("_signal=MismatchedToken;\n"); dumpException(p->ex_group, 0); tabs--; gen("}\n"); } set_free(b); } else if ( TokenString(p->token)!=NULL ) { if ( FoundException ) { if ( p->use_def_MT_handler ) gen2("zzmatch_wdfltsig(%s,%s);",TokenString(p->token),tokenFollowSet(p)) else if ( p->ex_group==NULL ) { gen2("zzmatch_wsig(%s, %s_handler);", TokenString(p->token), handler_id); } else { /* MR6 */ if (GenCC) { /* MR6 */ gen1("if ( !_match_wsig(%s) ) {\n", TokenString(p->token)); /* MR6 */ } else { /* MR6 */ gen1("if ( !_zzmatch_wsig(%s) ) {\n", TokenString(p->token)); /* MR6 */ }; tabs++; /* MR6 */ if (FoundGuessBlk) { /* MR6 */ if ( GenCC ) {gen("if ( guessing ) goto fail;\n");} /* MR6 */ else gen("if ( zzguessing ) goto fail;\n"); /* MR6 */ }; gen("_signal=MismatchedToken;\n"); dumpException(p->ex_group, 0); tabs--; gen("}\n"); } } else gen1("zzmatch(%s);", TokenString(p->token)); } else { if ( FoundException ) { if ( p->use_def_MT_handler ) gen2("zzmatch_wdfltsig((ANTLRTokenType)%d,%s);", p->token,tokenFollowSet(p)) else gen2("zzmatch_wsig(%d,%s_handler);",p->token,handler_id); } else {gen1("zzmatch(%d);", p->token);} } a = findImmedAction( p->next ); /* generate the token labels */ if ( GenCC && p->elnum>0 ) { /* If building trees in C++, always gen the LT() assigns */ if ( set_el(p->elnum, tokensRefdInBlock) || GenAST ) { /* MR10 */ if ( FoundGuessBlk ) { /* MR10 */ gen("\n"); /* MR10 */ if (p->label_used_in_semantic_pred) { /* MR10 */ gen2(" _t%d%d = (ANTLRTokenPtr)LT(1); /* MR10 */\n", BlkLevel-1, p->elnum); /* MR10 */ } else { /* MR10 */ gen("if ( !guessing ) {\n"); tab(); /* MR10 */ _gen2(" _t%d%d = (ANTLRTokenPtr)LT(1);\n", BlkLevel-1, p->elnum); /* MR10 */ _gen("}\n"); /* MR10 */ }; /* MR10 */ } else { /* MR10 */ _gen2(" _t%d%d = (ANTLRTokenPtr)LT(1);", BlkLevel-1, p->elnum); /* MR10 */ }; /* MR10 */ } if ( LL_k>1 ) if ( !DemandLookahead ) _gen(" labase++;"); _gen("\n"); tab(); } if ( GenAST ) { if ( FoundGuessBlk && !(p->astnode == ASTexclude || r->noAST) ) { if ( GenCC ) {_gen("if ( !guessing ) {\n"); tab();} else {_gen("zzNON_GUESS_MODE {\n"); tab();} } if ( !r->noAST ) { if ( GenCC && !(p->astnode == ASTexclude || r->noAST) ) { _gen("\n"); /* MR13 */ if (NewAST) { /* MR13 */ gen4("_ast%d%d = newAST(_t%d%d);\n", BlkLevel-1, p->elnum, BlkLevel-1, p->elnum); /* MR13 */ } else { /* MR13 */ gen4("_ast%d%d = new AST(_t%d%d);\n", BlkLevel-1, p->elnum, BlkLevel-1, p->elnum); /* MR13 */ } tab(); } if ( GenCC && !(p->astnode == ASTexclude || r->noAST) ) {_gen2("_ast%d%d->", BlkLevel-1, p->elnum);} else _gen(" "); if ( p->astnode==ASTchild ) { if ( !GenCC ) _gen("zz"); _gen("subchild(_root, &_sibling, &_tail);"); } else if ( p->astnode==ASTroot ) { if ( !GenCC ) _gen("zz"); _gen("subroot(_root, &_sibling, &_tail);"); } if ( GenCC && !(p->astnode == ASTexclude || r->noAST) ) { _gen("\n"); tab(); } } else if ( !GenCC ) _gen(" zzastDPush;"); if ( FoundGuessBlk && !(p->astnode == ASTexclude || r->noAST) ) {_gen("}\n"); tab();} } /* Handle element labels now */ if ( p->el_label!=NULL ) { int done_NON_GUESSMODE=0; _gen("\n"); /* MR10 */ /* do Attrib / Token ptr for token label used in semantic pred */ /* MR10 */ /* for these cases do assign even in guess mode */ /* MR10 */ /* MR10 */ if (p->label_used_in_semantic_pred) { /* MR10 */ if ( GenCC ) { /* MR10 */ if ( set_el(p->elnum, tokensRefdInBlock) || GenAST ) { /* MR10 */ gen3("%s = _t%d%d;", p->el_label, BlkLevel-1, p->elnum); /* MR10 */ } else { /* MR10 */ gen1("%s = (ANTLRTokenPtr)LT(1);\n", p->el_label); /* MR10 */ }; /* MR10 */ } else { /* MR10 */ gen1("%s = zzaCur;", p->el_label); /* MR10 */ }; /* MR10 */ if (FoundGuessBlk) _gen(" /* MR10 */"); /* MR10 */ _gen("\n"); /* MR10 */ }; /* Do Attrib / Token ptr */ /* MR10 */ if (! p->label_used_in_semantic_pred) { /* MR10 */ /* MR10 */ if ( FoundGuessBlk ) { /* MR10 */ if (! done_NON_GUESSMODE) { /* MR10 */ done_NON_GUESSMODE=1; /* MR10 */ if ( GenCC ) {gen("if ( !guessing ) {\n"); tab();} /* MR10 */ else {gen("zzNON_GUESS_MODE {\n"); tab();} /* MR10 */ }; /* MR10 */ }; /* MR10 */ /* MR10 */ if ( GenCC ) { /* MR10 */ if ( set_el(p->elnum, tokensRefdInBlock) || GenAST ) { /* MR10 */ gen3("%s = _t%d%d;\n", p->el_label, BlkLevel-1, p->elnum); /* MR10 */ } else { /* MR10 */ gen1("%s = (ANTLRTokenPtr)LT(1);\n", p->el_label); /* MR10 */ }; /* MR10 */ } else { /* MR10 */ gen1("%s = zzaCur;\n", p->el_label); /* MR10 */ }; /* MR10 */ }; /* Do AST ptr */ if ( GenAST && !(p->astnode == ASTexclude || r->noAST) ) { /* MR10 */ if ( FoundGuessBlk ) { /* MR10 */ if (! done_NON_GUESSMODE) { /* MR10 */ done_NON_GUESSMODE=1; /* MR10 */ if ( GenCC ) {gen("if ( !guessing ) {\n"); tab();} /* MR10 */ else {gen("zzNON_GUESS_MODE {\n"); tab();} /* MR10 */ }; /* MR10 */ }; if ( GenCC ) { gen3("%s_ast = _ast%d%d;\n", p->el_label, BlkLevel-1, p->elnum); } else {gen1("%s_ast = zzastCur;\n", p->el_label);} } /* MR10 */ if (done_NON_GUESSMODE) { /* MR10 */ gen("}\n"); tab(); /* MR10 */ }; } /* Handle any actions immediately following action */ if ( a != NULL ) /* MR10 */ /* MR11 */ { /* delay next token fetch until after action */ _gen("\n"); if ( a->is_predicate) { gen("if (!("); /* make sure that '#line n' is on front of line */ /* MR14 */ if ( GenLineInfo && p->file != -1 ) _gen("\n"); /* MR14 */ dumpPredAction(a,a->action, output, 0, a->file, a->line, 0); if ( a->pred_fail != NULL ) { _gen(")) {\n"); /************** if ( FoundGuessBlk ) gen("zzNON_GUESS_MODE {\n"); *****/ tabs++; /* MR1 */ /* MR1 10-Apr-97 MR1 Put {...} envelope around failed semantic predicates */ /* MR1 */ gen1("{%s};\n", a->pred_fail); tabs--; gen("}\n"); /************** if ( FoundGuessBlk ) gen("}\n"); *****/ } /* MR1 */ /* MR1 10-Apr-97 MR1 Properly stringize failed semantic predicates */ /* MR1 */ else { _gen1(")) {zzfailed_pred(\"%s\");}\n", /* MR1 */ stringize(a->action)); /* MR1 */ } } else /* MR9 a regular action - not a predicate action */ { if ( FoundGuessBlk ) if ( GenCC ) {gen("if ( !guessing ) {\n");} else gen("zzNON_GUESS_MODE {\n"); dumpAction(a->action, output, tabs, a->file, a->line, 1); if ( FoundGuessBlk ) gen("}\n"); } a->done = 1; if ( !DemandLookahead ) { if ( GenCC ) { if ( FoundException && p->use_def_MT_handler ) gen("if (!_signal)"); _gen(" consume();") if ( FoundException && p->use_def_MT_handler ) _gen(" _signal=NoSignal;"); _gen("\n"); } else { if ( FoundException && p->use_def_MT_handler ) _gen("if (!_signal)"); _gen(" zzCONSUME;\n"); if ( FoundException && p->use_def_MT_handler ) _gen(" _signal=NoSignal;"); _gen("\n"); } } else gen("\n"); TRANS( a->next ); } else { if ( !DemandLookahead ) { if ( GenCC ) { if (FoundException && p->use_def_MT_handler) _gen("if (!_signal)"); _gen(" consume();") if (FoundException&&p->use_def_MT_handler) _gen(" _signal=NoSignal;"); _gen("\n"); } else { if (FoundException && p->use_def_MT_handler) _gen("if (!_signal)"); _gen(" zzCONSUME;"); if ( FoundException && p->use_def_MT_handler ) _gen(" _signal=NoSignal;"); _gen("\n"); } } else _gen("\n"); TRANS(p->next); } } void #ifdef __USE_PROTOS genOptBlk( Junction *q ) #else genOptBlk( q ) Junction *q; #endif { int max_k; set f; int need_right_curly; set savetkref; savetkref = tokensRefdInBlock; require(q!=NULL, "genOptBlk: invalid node and/or rule"); require(q->ntype == nJunction, "genOptBlk: not junction"); require(q->jtype == aOptBlk, "genOptBlk: not optional block"); OutLineInfo(output,q->line,FileStr[q->file]); BLOCK_Preamble(q); BlkLevel++; f = genBlk(q, aOptBlk, &max_k, &need_right_curly); set_free(f); freeBlkFsets(q); BlkLevel--; if ( first_item_is_guess_block((Junction *)q->p1)!=NULL ) { gen("else if ( !zzrv ) zzGUESS_DONE;\n"); } { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } BLOCK_Tail(); tokensRefdInBlock = savetkref; if (q->end->p1 != NULL) TRANS(q->end->p1); } /* * Generate code for a loop blk of form: * * |---| * v | * --o-G-o-->o-- */ void #ifdef __USE_PROTOS genLoopBlk( Junction *begin, Junction *q, Junction *start, int max_k ) #else genLoopBlk( begin, q, start, max_k ) Junction *begin; Junction *q; Junction *start; /* where to start generating code from */ int max_k; #endif { set f; int need_right_curly; set savetkref; Junction *guessBlock; /* MR10 */ int singleAlt; /* MR10 */ savetkref = tokensRefdInBlock; require(q->ntype == nJunction, "genLoopBlk: not junction"); require(q->jtype == aLoopBlk, "genLoopBlk: not loop block"); if ( q->visited ) return; q->visited = TRUE; /* first_item_is_guess_block doesn't care what kind of node it is */ guessBlock=first_item_is_guess_block( (Junction *) q->p1); /* MR10 */ singleAlt=q->p2==NULL; /* MR10 */ if (singleAlt && !guessBlock) /* MR10 */ /* only one alternative? */ { if ( DemandLookahead ) if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);} else gen1("look(%d);\n", max_k); gen("while ( "); if ( begin!=NULL ) genExpr(begin); else genExpr(q); /* if no predicates have been hoisted for this single alt (..)* * do so now */ require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); if ( ParseWithPredicates && begin->predicate==NULL ) { Predicate *a = MR_find_predicates_and_supp((Node *)q->p1); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); if ( a!=NULL ) { _gen("&&"); a=genPredTreeMain(a, (Node *)q); /* MR10 */ } /* MR10 */ if (MRhoisting) { /* MR10 */ predicate_free(a); /* MR10 */ }; } _gen(" ) {\n"); tabs++; TRANS(q->p1); if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1); if ( DemandLookahead ) if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);} else gen1("look(%d);\n", max_k); --tabs; gen("}\n"); freeBlkFsets(q); q->visited = FALSE; tokensRefdInBlock = savetkref; return; } gen("for (;;) {\n"); /* MR20 G. Hobbelt */ tabs++; /* MR6 */ /* MR6 "begin" can never be null when called from genLoopBegin */ /* MR6 because q==(Junction *)begin->p1 and we know q is valid */ /* MR6 */ /* MR6 from genLoopBegin: */ /* MR6 */ /* MR6 if ( LL_k>1 && !set_nil(q->fset[2]) ) */ /* MR6 genLoopBlk( q, (Junction *)q->p1, q, max_k ); */ /* MR6 else genLoopBlk( q, (Junction *)q->p1, NULL, max_k ); */ /* MR6 */ if ( begin!=NULL ) { if ( DemandLookahead ) { if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);} else gen1("look(%d);\n", max_k); } /* The bypass arc of the (...)* predicts what to do when you fail, but * ONLY after having tested the loop start expression. To avoid this, * we simply break out of the (...)* loop when we find something that * is not in the prediction of the loop (all alts thereof). */ gen("if ( !("); /*** TJP says: It used to use the prediction expression for the bypass arc of the (...)*. HOWEVER, if a non LL^1(k) decision was found, this thing would miss the ftree stored in the aLoopBegin node and generate an LL^1(k) decision anyway. *** genExpr((Junction *)begin->p2); ***/ genExpr((Junction *)begin); _gen(")) break;\n"); } /* generate code for terminating loop (this is optional branch) */ f = genBlk(q, aLoopBlk, &max_k, &need_right_curly); set_free(f); freeBlkFsets(q); /* generate code for terminating loop (this is optional branch) */ /* MR6 */ /* MR6 30-May-97 Bug reported by Manuel Ornato */ /* MR6 A definite bug involving the exit from a loop block */ /* MR6 In 1.23 and later versions (including 1.33) Instead */ /* MR6 exiting the block and reporting a syntax error the */ /* MR6 code loops forever. */ /* MR6 Looking at 1.20 which generates proper code it is not */ /* MR6 clear which of two changes should be undone. */ /* MR6 This is my best guess. */ /* MR6 From earlier MR6 note we know that begin can never be */ /* MR6 null when genLoopBlk called from genLoopBegin */ /* MR6 */ /* MR6 */ if ( begin==NULL) { /* MR6 */ /* code for exiting loop "for sure" */ /* MR6 */ gen("/* Suppressed by MR6 */ /*** else break; ***/\n"); /* MR6 */ }; /* MR10 */if (singleAlt && guessBlock) { /* MR10 */ tabs--; /* MR6 */ gen("} else break; /* MR6 code for exiting loop \"for sure\" */\n"); /* MR10 */ need_right_curly--; /* MR10 */ } else { /* MR6 */ gen("else break; /* MR6 code for exiting loop \"for sure\" */\n"); /* MR10 */ }; { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1); --tabs; gen("}\n"); q->visited = FALSE; tokensRefdInBlock = savetkref; } /* * Generate code for a loop blk of form: * * |---| * v | * --o-->o-->o-G-o-->o-- * | ^ * v | * o-----------o * * q->end points to the last node (far right) in the blk. * * Note that q->end->jtype must be 'EndBlk'. * * Generate code roughly of the following form: * * do { * ... code for alternatives ... * } while ( First Set of aLoopBlk ); * * OR if > 1 alternative * * do { * ... code for alternatives ... * else break; * } while ( 1 ); */ void #ifdef __USE_PROTOS genLoopBegin( Junction *q ) #else genLoopBegin( q ) Junction *q; #endif { set f; int i; int max_k; set savetkref; savetkref = tokensRefdInBlock; require(q!=NULL, "genLoopBegin: invalid node and/or rule"); require(q->ntype == nJunction, "genLoopBegin: not junction"); require(q->jtype == aLoopBegin, "genLoopBegin: not loop block"); require(q->p2!=NULL, "genLoopBegin: invalid Loop Graph"); OutLineInfo(output,q->line,FileStr[q->file]); BLOCK_Preamble(q); BlkLevel++; f = First(q, 1, aLoopBegin, &max_k); /* If not simple LL(1), must specify to start at LoopBegin, not LoopBlk */ if ( LL_k>1 && !set_nil(q->fset[2]) ) genLoopBlk( q, (Junction *)q->p1, q, max_k ); else genLoopBlk( q, (Junction *)q->p1, NULL, max_k ); for (i=1; i<=CLL_k; i++) set_free(q->fset[i]); for (i=1; i<=CLL_k; i++) set_free(((Junction *)q->p2)->fset[i]); --BlkLevel; BLOCK_Tail(); set_free(f); tokensRefdInBlock = savetkref; if (q->end->p1 != NULL) TRANS(q->end->p1); } /* * Generate code for a loop blk of form: * * |---| * v | * --o-G-o-->o-- * * q->end points to the last node (far right) in the blk. * Note that q->end->jtype must be 'EndBlk'. * * Generate code roughly of the following form: * * do { * ... code for alternatives ... * } while ( First Set of aPlusBlk ); * * OR if > 1 alternative * * do { * ... code for alternatives ... * else if not 1st time through, break; * } while ( 1 ); */ void #ifdef __USE_PROTOS genPlusBlk( Junction *q ) #else genPlusBlk( q ) Junction *q; #endif { int max_k; set f; int need_right_curly; set savetkref; Junction *guessBlock; /* MR10 */ int singleAlt; /* MR10 */ savetkref = tokensRefdInBlock; require(q!=NULL, "genPlusBlk: invalid node and/or rule"); require(q->ntype == nJunction, "genPlusBlk: not junction"); require(q->jtype == aPlusBlk, "genPlusBlk: not Plus block"); require(q->p2 != NULL, "genPlusBlk: not a valid Plus block"); if ( q->visited ) return; q->visited = TRUE; OutLineInfo(output,q->line,FileStr[q->file]); BLOCK_Preamble(q); BlkLevel++; /* first_item_is_guess_block doesn't care what kind of node it is */ guessBlock=first_item_is_guess_block( (Junction *)q->p1); /* MR10 */ /* if the ignore flag is set on the 2nd alt and that alt is empty, * then it is the implied optional alternative that we added for (...)+ * and, hence, only 1 alt. */ /* MR10 Reported by Pulkkinen Esa (esap@cs.tut.fi) * Outer code for guess blocks ignored when there is only one alt * for a (...)+ block. * Force use of regular code rather than "optimized" code for that case */ singleAlt=( ( (Junction *) q->p2)->p2 == NULL) && ( ( (Junction *) q->p2)->ignore ); /* only one alternative? */ if (singleAlt && !guessBlock) /* MR10 */ { Predicate *a=NULL; /* if the only alt has a semantic predicate, hoist it; must test before * entering loop. */ if ( ParseWithPredicates ) { require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); a = MR_find_predicates_and_supp((Node *)q); require(MR_PredRuleRefStack.count == 0,"PredRuleRef stack not empty"); if ( a!=NULL ) { gen("if ("); a=genPredTreeMain(a, (Node *)q); /* MR10 */ _gen(") {\n"); } } gen("do {\n"); tabs++; TRANS(q->p1); if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1); f = First(q, 1, aPlusBlk, &max_k); if ( DemandLookahead ) if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);} else gen1("look(%d);\n", max_k); --tabs; gen("} while ( "); if ( q->parm!=NULL && q->predparm ) _gen1("(%s) && ", q->parm); genExpr(q); if ( ParseWithPredicates && a!=NULL ) { if (! MR_comparePredicates(q->predicate,a)) { _gen("&&"); a=genPredTreeMain(a, (Node *)q); /* MR10 */ }; } _gen(" );\n"); if ( ParseWithPredicates && a!=NULL ) gen("}\n"); --BlkLevel; BLOCK_Tail(); q->visited = FALSE; freeBlkFsets(q); set_free(f); tokensRefdInBlock = savetkref; if (q->end->p1 != NULL) TRANS(q->end->p1); /* MR10 */ if (MRhoisting) { /* MR10 */ predicate_free(a); /* MR10 */ }; return; } gen("do {\n"); tabs++; f = genBlk(q, aPlusBlk, &max_k, &need_right_curly); /* MR6 */ /* MR6 Sinan Karasu (sinan@tardis.ds.boeing.com) */ /* MR6 Failed to turn off guess mode when leaving block */ /* MR6 */ /* MR6 */ if ( has_guess_block_as_last_item(q) ) { /* MR10 */ gen("/* MR10 ()+ */ else {\n"); /* MR10 */ tabs++; /* MR10 */ need_right_curly++; /* MR10 */ gen("/* MR10 ()+ */ if ( !zzrv ) zzGUESS_DONE;\n"); /* MR6 */ gen("/* MR10 ()+ */ if ( zzcnt > 1 ) break;\n"); /* MR10 */ } else { /* MR10 */ gen("/* MR10 ()+ */ else {\n"); /* MR10 */ tabs++; /* MR10 */ need_right_curly++; /* MR10 */ gen("if ( zzcnt > 1 ) break;\n"); /* MR10 */ }; tab(); makeErrorClause(q,f,max_k); { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } freeBlkFsets(q); gen("zzcnt++;"); if ( !GenCC ) _gen1(" zzLOOP(zztasp%d);", BlkLevel-1); _gen("\n"); if ( DemandLookahead ) if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);} else gen1("look(%d);\n", max_k); --tabs; if ( q->parm!=NULL && q->predparm ) {gen1("} while (%s);\n", q->parm);} else gen("} while ( 1 );\n"); --BlkLevel; BLOCK_Tail(); q->visited = FALSE; tokensRefdInBlock = savetkref; if (q->end->p1 != NULL) TRANS(q->end->p1); } /* * Generate code for a sub blk of alternatives of form: * * --o-G1--o-- * | ^ * v /| * o-G2-o| * | ^ * v | * .......... * | ^ * v / * o-Gn-o * * q points to the 1st junction of blk (upper-left). * q->end points to the last node (far right) in the blk. * Note that q->end->jtype must be 'EndBlk'. * The last node in every alt points to q->end. * * Generate code of the following form: * if ( First(G1) ) { * ...code for G1... * } * else if ( First(G2) ) { * ...code for G2... * } * ... * else { * ...code for Gn... * } */ void #ifdef __USE_PROTOS genSubBlk( Junction *q ) #else genSubBlk( q ) Junction *q; #endif { int max_k; set f; int need_right_curly; set savetkref; savetkref = tokensRefdInBlock; require(q->ntype == nJunction, "genSubBlk: not junction"); require(q->jtype == aSubBlk, "genSubBlk: not subblock"); OutLineInfo(output,q->line,FileStr[q->file]); BLOCK_Preamble(q); BlkLevel++; f = genBlk(q, aSubBlk, &max_k, &need_right_curly); if ( q->p2 != NULL ) {tab(); makeErrorClause(q,f,max_k);} { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } freeBlkFsets(q); --BlkLevel; BLOCK_Tail(); if ( q->guess ) { gen("zzGUESS_DONE\n"); } /* must duplicate if (alpha)?; one guesses (validates), the * second pass matches */ if ( q->guess && analysis_point(q)==q ) { OutLineInfo(output,q->line,FileStr[q->file]); BLOCK_Preamble(q); BlkLevel++; f = genBlk(q, aSubBlk, &max_k, &need_right_curly); if ( q->p2 != NULL ) {tab(); makeErrorClause(q,f,max_k);} { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } freeBlkFsets(q); --BlkLevel; BLOCK_Tail(); } tokensRefdInBlock = savetkref; if (q->end->p1 != NULL) TRANS(q->end->p1); } static int TnodesAllocatedPrevRule=0; /* * Generate code for a rule. * * rule--> o-->o-Alternatives-o-->o * Or, * rule--> o-->o-Alternative-o-->o * * The 1st junction is a RuleBlk. The second can be a SubBlk or just a junction * (one alternative--no block), the last is EndRule. * The second to last is EndBlk if more than one alternative exists in the rule. * * To get to the init-action for a rule, we must bypass the RuleBlk, * and possible SubBlk. * Mark any init-action as generated so genBlk() does not regenerate it. */ void #ifdef __USE_PROTOS genRule( Junction *q ) #else genRule( q ) Junction *q; #endif { do { /* MR10 Change recursion into iteration */ int max_k; set follow, rk, f; ActionNode *a; RuleEntry *r; static int file = -1; int need_right_curly; require(q->ntype == nJunction, "genRule: not junction"); require(q->jtype == RuleBlk, "genRule: not rule"); /* MR14 */ require (MR_BackTraceStack.count == 0,"-alpha MR_BackTraceStack.count != 0"); /* MR14 */ MR_pointerStackReset(&MR_BackTraceStack); /* MR14 */ if (AlphaBetaTrace) MR_MaintainBackTrace=1; CurRule=q->rname; /* MR11 */ r = (RuleEntry *) hash_get(Rname, q->rname); if ( r == NULL ) warnNoFL("Rule hash table is screwed up beyond belief"); if ( q->file != file ) /* open new output file if need to */ { /* MR6 */ /* MR6 Simpler to debug when output goes to stdout rather than a file */ /* MR6 */ /* MR6 */ if (UseStdout) { /* MR6 */ output = stdout; /* MR6 */ } else { /* MR6 */ if ( output != NULL) fclose( output ); /* MR6 */ output = fopen(OutMetaName(outname(FileStr[q->file])), "w"); /* MR6 */ }; require(output != NULL, "genRule: can't open output file"); #ifdef SPECIAL_FOPEN special_fopen_actions(OutMetaName(outname(FileStr[q->file]))); /* MR1 */ #endif if ( file == -1 ) genHdr1(q->file); else genHdr(q->file); file = q->file; } if (InfoM) { fprintf(stderr," rule %s\n",q->rname); fflush(output); }; #if 0 if (strcmp(q->rname,"***debug***") == 0) { fprintf(stderr,"***debug*** %s reached\n",q->rname); MR_break(); }; #endif DumpFuncHeader(q,r); tabs++; if ( q->ret!=NULL ) { /* Declare the return value - and PURIFY it -ATG 6/5/95 */ /* MR7 Moved PURIFY() to after all local variables have been declared */ /* MR7 so that the generated code is valid C as well as C++ */ /* MR7 Jan Mikkelsen 10-June-1997 */ if ( HasComma(q->ret) ) { gen1("struct _rv%d _retv;\n",r->rulenum); } else { tab(); DumpType(q->ret, output); /* MR3 17-May-97 Undo change since _retv is of unpredictable type */ /* MR3 If an object it may not be possible to assign 0 or NULL */ /* MR3 Reported by Cortland Starrett (cort@shay.ecn.purdue.edu */ /* MR1 10-Apr-97 Get rid of annoying Possibly ref'd before use msgs */ gen(" _retv;\n"); /* MR1 MR3 */ } } OutLineInfo(output,q->line,FileStr[q->file]); if (InfoM) { fflush(output); }; gen("zzRULE;\n"); if ( FoundException ) { gen("int _sva=1;\n"); } if ( GenCC && GenAST ) gen("ASTBase *_ast = NULL, *_sibling = NULL, *_tail = NULL;\n"); if ( GenCC ) genTokenPointers(q); if ( GenCC&&GenAST ) genASTPointers(q); if ( q->el_labels!=NULL ) genElementLabels(q->el_labels); if ( FoundException ) gen("int _signal=NoSignal;\n"); if ( !GenCC ) gen1("zzBLOCK(zztasp%d);\n", BlkLevel); /* MR10 */ /* move zzTRACEIN to before init action */ /* MR10 */ if ( TraceGen ) /* MR10 */ if ( GenCC ) {gen1("zzTRACEIN(\"%s\");\n", q->rname);} /* MR10 */ else gen1("zzTRACEIN((ANTLRChar *)\"%s\");\n", q->rname); /* MR7 Moved PURIFY() to after all local variables have been declared */ /* MR7 so that the generated code is valid C as well as C++ */ /* MR7 Jan Mikkelsen 10-June-1997 */ if ( q->ret != NULL ) /* MR7 */ { /* MR7 */ if ( HasComma(q->ret) ) /* MR7 */ { /* MR7 */ gen1("PURIFY(_retv,sizeof(struct _rv%d))\n",r->rulenum); /* MR7 */ } /* MR7 */ else /* MR7 */ { /* MR7 */ gen("PURIFY(_retv,sizeof("); /* MR7 */ DumpType(q->ret, output); /* MR7 */ gen("))\n"); /* MR7 */ } /* MR7 */ } /* MR7 */ if ( !GenCC ) gen("zzMake0;\n"); if ( FoundException ) gen("*_retsignal = NoSignal;\n"); if ( !GenCC ) gen("{\n"); if ( has_guess_block_as_first_item((Junction *)q->p1) ) { gen("zzGUESS_BLOCK\n"); } /* L o o k F o r I n i t A c t i o n */ if ( ((Junction *)q->p1)->jtype == aSubBlk ) a = findImmedAction( ((Junction *)q->p1)->p1 ); else a = findImmedAction( q->p1 ); /* only one alternative in rule */ if ( a!=NULL && !a->is_predicate) { if (!a->noHoist) dumpAction(a->action, output, tabs, a->file, a->line, 1); a->done = 1; /* ignore action. We have already handled it */ } BlkLevel++; q->visited = TRUE; /* mark RULE as visited for FIRST/FOLLOW */ f = genBlk((Junction *)q->p1, RuleBlk, &max_k, &need_right_curly); if ( q->p1 != NULL ) if ( ((Junction *)q->p1)->p2 != NULL ) {tab(); makeErrorClause((Junction *)q->p1,f,max_k);} { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} } freeBlkFsets((Junction *)q->p1); q->visited = FALSE; --BlkLevel; if ( !GenCC ) gen1("zzEXIT(zztasp%d);\n", BlkLevel); genTraceOut(q); if ( q->ret!=NULL ) gen("return _retv;\n") else gen("return;\n"); /* E r r o r R e c o v e r y */ NewSet(); rk = empty; /* MR14 */ if (r->dontComputeErrorSet) { /* MR14 */ follow=empty; } else { MR_pointerStackReset(&MR_BackTraceStack); /* MR14 */ MR_ErrorSetComputationActive=1; REACH(q->end, 1, &rk, follow); MR_ErrorSetComputationActive=0; require (MR_BackTraceStack.count == 0,"K: MR_BackTraceStack.count != 0"); } FillSet( follow ); set_free( follow ); /* MR20 G. Hobbelt Isn't it so that "fail:" is ONLY referenced when: !FoundException || FoundGuessBlk ? Therefore add the "if" around this piece of code generation... Should guessing mode also use _handler label instead of "fail" when exception handling is active? gen can automatically put "if (guessing)" there so as to skip all kinds of user code. */ if ( !FoundException || FoundGuessBlk ) /* MR20 G. Hobbelt */ { /* MR20 G. Hobbelt */ _gen("fail:\n"); if ( !GenCC ) gen("zzEXIT(zztasp1);\n"); if ( FoundGuessBlk ) if ( !GenCC ) {gen("if ( zzguessing ) zzGUESS_FAIL;\n");} else gen("if ( guessing ) zzGUESS_FAIL;\n"); if ( q->erraction!=NULL ) dumpAction(q->erraction, output, tabs, q->file, q->line, 1); if ( GenCC ) { gen1("syn(zzBadTok, %s, zzMissSet, zzMissTok, zzErrk);\n", r->egroup==NULL?"(ANTLRChar *)\"\"":r->egroup); } else { gen1("zzsyn(zzMissText, zzBadTok, %s, zzMissSet, zzMissTok, zzErrk, zzBadText);\n", r->egroup==NULL?"(ANTLRChar *)\"\"":r->egroup); } gen3("%sresynch(setwd%d, 0x%x);\n", GenCC?"":"zz", wordnum, 1<ret!=NULL ) { genTraceOut(q); gen("return _retv;\n"); } else if ( q->exceptions!=NULL ) { genTraceOut(q); gen("return;\n"); } else if (!FoundException) { /* MR10 */ genTraceOut(q); /* MR10 */ }; } /* MR20 G. Hobbelt */ if ( !GenCC ) gen("}\n"); /* Gen code for exception handlers */ /* make sure each path out contains genTraceOut() */ if ( q->exceptions!=NULL ) { gen("/* exception handlers */\n"); dumpExceptions(q->exceptions); if ( !r->has_rule_exception ) { _gen("_handler:\n"); gen("zzdflthandlers(_signal,_retsignal);\n"); } /* MR20 G. Gobbelt The label "adios" is never referenced */ #if 0 _gen("_adios:\n"); #endif if ( q->ret!=NULL ) { genTraceOut(q); gen("return _retv;\n"); } else { genTraceOut(q); gen("return;\n"); } } else if ( FoundException ) { _gen("_handler:\n"); gen("zzdflthandlers(_signal,_retsignal);\n"); /* MR1 */ /* MR1 7-Apr-97 Fix suggested by: John Bair (jbair@iftime.com) */ /* MR1 */ if ( q->ret != NULL) { /* MR1 */ genTraceOut(q); /* MR10 */ gen("return _retv;\n"); /* MR1 */ } else { /* MR1 */ genTraceOut(q); /* MR10 */ gen("return;\n") ; /* MR1 */ }; /* MR1 */ } tabs--; gen("}\n"); /* MR10 Tired of looking at stacks that are as deep as the number of */ /* MR10 rules. Changes recursion to iteration. */ MR_releaseResourcesUsedInRule( (Node *) q ); /* MR10 */ if (InfoT) { fprintf(output,"\n/* tnodes created for rule %s: %d */\n", q->rname, (TnodesAllocated-TnodesAllocatedPrevRule) ); }; TnodesAllocatedPrevRule=TnodesAllocated; if (q->p2 == NULL) dumpAfterActions( output ); q=(Junction *)q->p2; require(q==NULL || q->jtype==RuleBlk,"RuleBlk p2 does not point to another RuleBlk"); } while (q != NULL); /**** The old code ****/ /**** if ( q->p2 != NULL ) {TRANS(q->p2);} ****/ /* generate code for next rule too */ /**** else dumpAfterActions( output ); ****/ } static void #ifdef __USE_PROTOS DumpFuncHeader( Junction *q, RuleEntry *r ) #else DumpFuncHeader( q, r ) Junction *q; RuleEntry *r; #endif { /* */ /* MR1 10-Apr-97 MR1 Simplify insertion of commas in function header */ /* */ int needComma; /* MR1 */ /* A N S I */ _gen("\n"); if ( q->ret!=NULL ) { if ( HasComma(q->ret) ) { if (GenCC) gen2("%s::_rv%d\n", CurrentClassName, r->rulenum) else gen1("struct _rv%d\n",r->rulenum); } else { DumpType(q->ret, output); gen("\n"); } } else { _gen("void\n"); } /* MR1 */ /* MR1 10-Apr-97 133MR1 Replace __STDC__ with __USE_PROTOS */ /* MR1 */ if ( !GenCC ) _gen("#ifdef __USE_PROTOS\n"); /* MR1 */ if ( !GenCC ) gen2("%s%s(", RulePrefix, q->rname) else gen3("%s::%s%s(", CurrentClassName, RulePrefix,q->rname); DumpANSIFunctionArgDef(output,q); _gen("\n"); if ( GenCC ) { gen("{\n"); return; } /* K & R */ gen("#else\n"); gen2("%s%s(", RulePrefix, q->rname); needComma=0; /* MR1 */ if ( GenAST ) /* MR1 */ { /* MR1 */ _gen("_root"); /* MR1 */ needComma=1; /* MR1 */ } /* MR1 */ if ( FoundException ) /* MR1 */ { /* MR1 */ if (needComma) {_gen(",");needComma=0;}; /* MR1 */ _gen("_retsignal"); /* MR1 */ needComma=1; /* MR1 */ } /* MR1 */ /* MR5 Change below by Jan Mikkelsen (janm@zeta.org.au) 26-May-97 MR5 */ DumpListOfParmNames( q->pdecl, output, needComma ); /* MR5 */ gen(")\n"); if ( GenAST ) gen("AST **_root;\n"); if ( FoundException ) gen("int *_retsignal;\n"); DumpOldStyleParms( q->pdecl, output ); gen("#endif\n"); gen("{\n"); } void #ifdef __USE_PROTOS DumpANSIFunctionArgDef(FILE *f, Junction *q) #else DumpANSIFunctionArgDef(f,q) FILE *f; Junction *q; #endif { if ( GenAST ) { if ( GenCC ) {fprintf(f,"ASTBase **_root");} else fprintf(f,"AST**_root"); if ( !FoundException && q->pdecl!=NULL ) fprintf(f,","); } if ( FoundException ) { if ( GenAST ) fprintf(f,","); fprintf(f,"int *_retsignal"); if ( q->pdecl!=NULL ) fprintf(f,","); } if ( q->pdecl!=NULL ) {fprintf(f,"%s", q->pdecl);} else if ( !GenAST && !FoundException ) fprintf(f,"void"); fprintf(f,")"); } void #ifdef __USE_PROTOS genJunction( Junction *q ) #else genJunction( q ) Junction *q; #endif { require(q->ntype == nJunction, "genJunction: not junction"); require(q->jtype == Generic, "genJunction: not generic junction"); if ( q->p1 != NULL ) TRANS(q->p1); if ( q->p2 != NULL ) TRANS(q->p2); } void #ifdef __USE_PROTOS genEndBlk( Junction *q ) #else genEndBlk( q ) Junction *q; #endif { } void #ifdef __USE_PROTOS genEndRule( Junction *q ) #else genEndRule( q ) Junction *q; #endif { } void #ifdef __USE_PROTOS genHdr( int file ) #else genHdr( file ) int file; #endif { int i; _gen("/*\n"); _gen(" * A n t l r T r a n s l a t i o n H e a d e r\n"); _gen(" *\n"); _gen(" * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999\n"); _gen(" * Purdue University Electrical Engineering\n"); _gen(" * With AHPCRC, University of Minnesota\n"); _gen1(" * ANTLR Version %s\n", Version); _gen(" *\n"); /* MR10 */ _gen(" * "); /* MR10 */ for (i=0 ; i < Save_argc ; i++) { /* MR10 */ _gen(" "); /* MR10 */ _gen(Save_argv[i]); /* MR10 */ }; _gen("\n"); _gen(" *\n"); _gen(" */\n\n"); if (FirstAction != NULL ) dumpAction( FirstAction, output, 0, -1, 0, 1); /* MR11 MR15b */ _gen1("#define ANTLR_VERSION %s\n", VersionDef); _gen("#include \"pcctscfg.h\"\n"); _gen("#include \"pccts_stdio.h\"\n"); if ( strcmp(ParserName, DefaultParserName)!=0 ) _gen2("#define %s %s\n", DefaultParserName, ParserName); if ( strcmp(ParserName, DefaultParserName)!=0 ) {_gen1("#include \"%s\"\n", RemapFileName);} OutLineInfo(output,1,FileStr[file]); if ( GenCC ) { if ( UserTokenDefsFile != NULL ) fprintf(output, "#include %s\n", UserTokenDefsFile); else fprintf(output, "#include \"%s\"\n", DefFileName); } if ( HdrAction != NULL ) dumpAction( HdrAction, output, 0, -1, 0, 1); if ( !GenCC && FoundGuessBlk ) { _gen("#define ZZCAN_GUESS\n"); _gen("#include \"pccts_setjmp.h\"\n"); /* MR15 K.J. Cummings (cummings@peritus.com) */ } if ( FoundException ) { _gen("#define EXCEPTION_HANDLING\n"); _gen1("#define NUM_SIGNALS %d\n", NumSignals); } if ( !GenCC && OutputLL_k > 1 ) _gen1("#define LL_K %d\n", OutputLL_k); if ( GenAST&&!GenCC ) _gen("#define GENAST\n\n"); if ( GenAST ) { if ( GenCC ) {_gen1("#include \"%s\"\n\n", ASTBASE_H);} else _gen("#include \"ast.h\"\n\n"); } if ( !GenCC && DemandLookahead ) _gen("#define DEMAND_LOOK\n\n"); #ifdef DUM if ( !GenCC && LexGen ) { _gen1("#define zzEOF_TOKEN %d\n", (TokenInd!=NULL?TokenInd[EofToken]:EofToken)); } #endif /* ###WARNING: This will have to change when SetWordSize changes */ if ( !GenCC ) _gen1("#define zzSET_SIZE %d\n", NumWords(TokenNum-1)*sizeof(unsigned)); if (TraceGen) { _gen("#ifndef zzTRACE_RULES\n"); /* MR20 */ _gen("#define zzTRACE_RULES\n"); /* MR20 */ // zzTRACE_RULES removed from #endif by TL because it causes // a warning under GCC 3.0.2 // _gen("#endif zzTRACE_RULES\n"); /* MR20 */ _gen("#endif\n"); /* MR20 */ }; if ( !GenCC ) {_gen("#include \"antlr.h\"\n");} else { _gen1("#include \"%s\"\n", APARSER_H); _gen1("#include \"%s.h\"\n", CurrentClassName); } if ( !GenCC ) { if ( UserDefdTokens ) {_gen1("#include %s\n", UserTokenDefsFile);} /* still need this one as it has the func prototypes */ _gen1("#include \"%s\"\n", DefFileName); } /* still need this one as it defines the DLG interface */ if ( !GenCC ) _gen("#include \"dlgdef.h\"\n"); if ( LexGen && GenCC ) _gen1("#include \"%s\"\n", DLEXERBASE_H); if ( GenCC ) _gen1("#include \"%s\"\n", ATOKPTR_H); if ( !GenCC && LexGen ) _gen1("#include \"%s\"\n", ModeFileName); /* MR10 Ofer Ben-Ami (gremlin@cs.huji.ac.il) */ /* MR10 Finally, a definition of the Purify macro */ _gen("#ifndef PURIFY\n"); _gen("#define PURIFY(r,s) memset((char *) &(r),'\\0',(s));\n"); _gen("#endif\n"); } void #ifdef __USE_PROTOS genHdr1( int file ) #else genHdr1( file ) int file; #endif { ListNode *p; genHdr(file); if ( GenAST ) { if ( !GenCC ) { _gen("#include \"ast.c\"\n"); _gen("zzASTgvars\n\n"); } } if ( !GenCC ) _gen("ANTLR_INFO\n"); if ( BeforeActions != NULL ) { for (p = BeforeActions->next; p!=NULL; p=p->next) { UserAction *ua = (UserAction *)p->elem; dumpAction( ua->action, output, 0, ua->file, ua->line, 1); } } if ( !FoundException ) return; if ( GenCC ) { _gen1("\nvoid %s::\n", CurrentClassName); _gen("zzdflthandlers( int _signal, int *_retsignal )\n"); _gen("{\n"); } else { _gen("\nvoid\n"); /* MR1 */ /* MR1 10-Apr-97 133MR1 Replace __STDC__ with __USE_PROTOS */ /* MR1 */ _gen("#ifdef __USE_PROTOS\n"); /* MR1 */ _gen("zzdflthandlers( int _signal, int *_retsignal )\n"); _gen("#else\n"); _gen("zzdflthandlers( _signal, _retsignal )\n"); _gen("int _signal;\n"); _gen("int *_retsignal;\n"); _gen("#endif\n"); _gen("{\n"); } tabs++; if ( DefaultExGroup!=NULL ) { dumpException(DefaultExGroup, 1); if ( !hasDefaultException(DefaultExGroup) ) { gen("default :\n"); tabs++; gen("*_retsignal = _signal;\n"); tabs--; gen("}\n"); } } else { gen("*_retsignal = _signal;\n"); } tabs--; _gen("}\n\n"); } void #ifdef __USE_PROTOS genStdPCCTSIncludeFile( FILE *f,char *gate ) /* MR10 */ #else genStdPCCTSIncludeFile( f , gate) /* MR10 */ FILE *f; char * gate; /* MR10 */ #endif { /* MR10 Ramanathan Santhanam (ps@kumaran.com) */ /* MR10 Same preprocessor symbol use to gate stdpccts.h */ /* MR10 even when two grammars are in use. */ /* MR10 Derive gate symbol from -fh filename */ if (gate == NULL) { fprintf(f,"#ifndef STDPCCTS_H\n"); /* MR10 */ fprintf(f,"#define STDPCCTS_H\n"); /* MR10 */ } else { fprintf(f,"#ifndef STDPCCTS_%s_H\n",gate); /* MR10 */ fprintf(f,"#define STDPCCTS_%s_H\n",gate); /* MR10 */ }; fprintf(f,"/*\n"); if (gate == NULL) { fprintf(f," * %s -- P C C T S I n c l u d e\n", stdpccts); } else { fprintf(f," * Standard PCCTS include file with -fh %s -- P C C T S I n c l u d e\n", stdpccts); } fprintf(f," *\n"); fprintf(f," * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999\n"); fprintf(f," * Purdue University Electrical Engineering\n"); fprintf(f," * With AHPCRC, University of Minnesota\n"); fprintf(f," * ANTLR Version %s\n", Version); fprintf(f," */\n\n"); fprintf(f,"#ifndef ANTLR_VERSION\n"); fprintf(f,"#define ANTLR_VERSION %s\n", VersionDef); fprintf(f,"#endif\n\n"); if (FirstAction != NULL ) dumpAction(FirstAction, f, 0, -1, 0, 1); /* MR11 */ fprintf(f,"#include \"pcctscfg.h\"\n"); fprintf(f,"#include \"pccts_stdio.h\"\n"); if ( GenCC ) { if ( UserDefdTokens ) fprintf(f, "#include %s\n", UserTokenDefsFile); else { fprintf(f, "#include \"%s\"\n", DefFileName); } fprintf(f, "#include \"%s\"\n", ATOKEN_H); if ( HdrAction != NULL ) dumpAction( HdrAction, f, 0, -1, 0, 1); fprintf(f, "#include \"%s\"\n", ATOKENBUFFER_H); if ( OutputLL_k > 1 ) fprintf(f,"static const unsigned LL_K=%d;\n", OutputLL_k); if ( GenAST ) { fprintf(f, "#include \"%s\"\n", ASTBASE_H); } if (TraceGen) { fprintf(f,"#ifndef zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#define zzTRACE_RULES\n"); /* MR20 */ // zzTRACE_RULES removed from #endif by TL because it causes // a warning under GCC 3.0.2 // fprintf(f,"#endif zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#endif\n"); /* MR20 */ }; fprintf(f,"#include \"%s\"\n", APARSER_H); fprintf(f,"#include \"%s.h\"\n", CurrentClassName); if ( LexGen ) fprintf(f,"#include \"%s\"\n", DLEXERBASE_H); fprintf(f, "#endif\n"); return; } if ( strcmp(ParserName, DefaultParserName)!=0 ) fprintf(f, "#define %s %s\n", DefaultParserName, ParserName); if ( strcmp(ParserName, DefaultParserName)!=0 ) fprintf(f, "#include \"%s\"\n", RemapFileName); if ( UserTokenDefsFile != NULL ) fprintf(f, "#include %s\n", UserTokenDefsFile); if ( HdrAction != NULL ) dumpAction( HdrAction, f, 0, -1, 0, 1); if ( FoundGuessBlk ) { fprintf(f,"#define ZZCAN_GUESS\n"); fprintf(f,"#include \"pccts_setjmp.h\"\n"); } if (TraceGen) { fprintf(f,"#ifndef zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#define zzTRACE_RULES\n"); /* MR20 */ // zzTRACE_RULES removed from #endif by TL because it causes // a warning under GCC 3.0.2 // fprintf(f,"#endif zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#endif\n"); /* MR20 */ }; if ( OutputLL_k > 1 ) fprintf(f,"#define LL_K %d\n", OutputLL_k); if ( GenAST ) fprintf(f,"#define GENAST\n"); if ( FoundException ) { /* MR1 7-Apr-97 1.33MR1 */ /* MR1 Fix suggested by: */ /* MR1 Francois-Xavier Fontaine (fontaine_f@istvax.ist.lu) */ fprintf(f,"#define EXCEPTION_HANDLING\n"); /* MR1 */ fprintf(f,"#define NUM_SIGNALS %d\n", NumSignals); /* MR1 */ } if ( DemandLookahead ) fprintf(f,"#define DEMAND_LOOK\n"); #ifdef DUM if ( LexGen ) fprintf(f, "#define zzEOF_TOKEN %d\n", (TokenInd!=NULL?TokenInd[EofToken]:EofToken)); #endif /* ###WARNING: This will have to change when SetWordSize changes */ fprintf(f, "#define zzSET_SIZE %d\n", NumWords(TokenNum-1)*sizeof(unsigned)); if (TraceGen) { fprintf(f,"#ifndef zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#define zzTRACE_RULES\n"); /* MR20 */ // zzTRACE_RULES removed from #endif by TL because it causes // a warning under GCC 3.0.2 // fprintf(f,"#endif zzTRACE_RULES\n"); /* MR20 */ fprintf(f,"#endif\n"); /* MR20 */ }; fprintf(f,"#include \"antlr.h\"\n"); if ( GenAST ) fprintf(f,"#include \"ast.h\"\n"); if ( UserDefdTokens ) fprintf(f, "#include %s\n", UserTokenDefsFile); /* still need this one as it has the func prototypes */ fprintf(f, "#include \"%s\"\n", DefFileName); /* still need this one as it defines the DLG interface */ fprintf(f,"#include \"dlgdef.h\"\n"); /* don't need this one unless DLG is used */ if ( LexGen ) fprintf(f,"#include \"%s\"\n", ModeFileName); fprintf(f,"#endif\n"); } /* dump action 's' to file 'output' starting at "local" tab 'tabs' Dump line information in front of action if GenLineInfo is set If file == -1 then GenLineInfo is ignored. The user may redefine the LineInfoFormatStr to his/her liking most compilers will like the default, however. June '93; changed so that empty lines are left alone so that line information is correct for the compiler/debuggers. */ void #ifdef __USE_PROTOS dumpAction( char *s, FILE *output, int tabs, int file, int line, int final_newline ) #else dumpAction( s, output, tabs, file, line, final_newline ) char *s; FILE *output; int tabs; int file; int line; int final_newline; #endif { int inDQuote, inSQuote; require(s!=NULL, "dumpAction: NULL action"); require(output!=NULL, eMsg1("dumpAction: output FILE is NULL for %s",s)); if ( GenLineInfo && file != -1 ) { OutLineInfo(output,line,FileStr[file]); } PastWhiteSpace( s ); /* don't print a tab if first non-white char is a # (preprocessor command) */ if ( *s!='#' ) {TAB;} inDQuote = inSQuote = FALSE; while ( *s != '\0' ) { if ( *s == '\\' ) { fputc( *s++, output ); /* Avoid '"' Case */ if ( *s == '\0' ) return; if ( *s == '\'' ) fputc( *s++, output ); if ( *s == '\"' ) fputc( *s++, output ); } if ( *s == '\'' ) { if ( !inDQuote ) inSQuote = !inSQuote; } if ( *s == '"' ) { if ( !inSQuote ) inDQuote = !inDQuote; } if ( *s == '\n' ) { fputc('\n', output); s++; PastWhiteSpace( s ); if ( *s == '}' ) { --tabs; TAB; fputc( *s++, output ); continue; } if ( *s == '\0' ) return; if ( *s != '#' ) /* #define, #endif etc.. start at col 1 */ { TAB; } } if ( *s == '}' && !(inSQuote || inDQuote) ) { --tabs; /* Indent one fewer */ } if ( *s == '{' && !(inSQuote || inDQuote) ) { tabs++; /* Indent one more */ } fputc( *s, output ); s++; } if ( final_newline ) fputc('\n', output); } static void #ifdef __USE_PROTOS dumpAfterActions( FILE *output ) #else dumpAfterActions( output ) FILE *output; #endif { ListNode *p; require(output!=NULL, "dumpAfterActions: output file was NULL for some reason"); if ( AfterActions != NULL ) { for (p = AfterActions->next; p!=NULL; p=p->next) { UserAction *ua = (UserAction *)p->elem; dumpAction( ua->action, output, 0, ua->file, ua->line, 1); } } fclose( output ); } /* * Find the next action in the stream of execution. Do not pass * junctions with more than one path leaving them. * Only pass generic junctions. * * Scan forward while (generic junction with p2==NULL) * If we stop on an action, return ptr to the action * else return NULL; */ static ActionNode * #ifdef __USE_PROTOS findImmedAction( Node *q ) #else findImmedAction( q ) Node *q; #endif { Junction *j; require(q!=NULL, "findImmedAction: NULL node"); require(q->ntype>=1 && q->ntype<=NumNodeTypes, "findImmedAction: invalid node"); while ( q->ntype == nJunction ) { j = (Junction *)q; if ( j->jtype != Generic || j->p2 != NULL ) return NULL; q = j->p1; if ( q == NULL ) return NULL; } if ( q->ntype == nAction ) return (ActionNode *)q; return NULL; } static void #ifdef __USE_PROTOS dumpRetValAssign( char *retval, char *ret_def ) #else dumpRetValAssign( retval, ret_def ) char *retval; char *ret_def; #endif { char *q = ret_def; tab(); while ( *retval != '\0' ) { while ( isspace((*retval)) ) retval++; while ( *retval!=',' && *retval!='\0' ) fputc(*retval++, output); fprintf(output, " = _trv."); DumpNextNameInDef(&q, output); fputc(';', output); fputc(' ', output); if ( *retval == ',' ) retval++; } } /* This function computes the set of tokens that can possibly be seen k * tokens in the future from point j */ static set #ifdef __USE_PROTOS ComputeErrorSet( Junction *j, int k ) #else ComputeErrorSet( j, k ) Junction *j; int k; #endif { Junction *alt1; set a, rk, f; require(j->ntype==nJunction, "ComputeErrorSet: non junction passed"); f = rk = empty; for (alt1=j; alt1!=NULL; alt1 = (Junction *)alt1->p2) { REACH(alt1->p1, k, &rk, a); require(set_nil(rk), "ComputeErrorSet: rk != nil"); set_free(rk); set_orin(&f, a); set_free(a); } return f; } static char * #ifdef __USE_PROTOS tokenFollowSet(TokNode *p) #else tokenFollowSet(p) TokNode *p; #endif { static char buf[100]; set rk, a; int n; rk = empty; REACH(p->next, 1, &rk, a); require(set_nil(rk), "rk != nil"); set_free(rk); n = DefErrSet( &a, 0, NULL ); set_free(a); if ( GenCC ) sprintf(buf, "err%d", n); else sprintf(buf, "zzerr%d", n); return buf; } static void #ifdef __USE_PROTOS makeErrorClause( Junction *q, set f, int max_k ) #else makeErrorClause( q, f, max_k ) Junction *q; set f; int max_k; #endif { char * handler_id=""; /* MR7 */ int nilf=0; /* MR13 */ RuleEntry *ruleEntry; /* MR14 */ if ( FoundException ) { _gen("else {\n"); tabs++; if ( FoundGuessBlk ) { if ( GenCC ) {gen("if ( guessing ) goto fail;\n");} else gen("if ( zzguessing ) goto fail;\n"); } gen("if (_sva) _signal=NoViableAlt;\n"); gen("else _signal=NoSemViableAlt;\n"); if (q->outerEG != NULL) { handler_id=q->outerEG->altID; #if 0 } else { printf("q->curAltNum=%d q->exception_label=%s\n",q->curAltNum,q->exception_label); gen("*** DEBUG *** outerEG==NULL\n"); #endif }; gen1("goto %s_handler; /* MR7 */\n",handler_id); /* MR7 */ tabs--; gen("}\n"); return; } if ( max_k == 1 ) { /* MR13 */ nilf=set_nil(f); if ( GenCC ) { _gen1("else {FAIL(1,err%d", DefErrSet1(1,&f,1,NULL)); } else { _gen1("else {zzFAIL(1,zzerr%d", DefErrSet1(1,&f,1,NULL)); }; set_free(f); } else { int i; set_free(f); if ( GenCC ) {_gen1("else {FAIL(%d", max_k);} else _gen1("else {zzFAIL(%d", max_k); ruleEntry = (RuleEntry *) hash_get(Rname,q->rname); for (i=1; i<=max_k; i++) { /* MR14 */ if (ruleEntry->dontComputeErrorSet) { /* MR14 */ f=empty; } else { f = ComputeErrorSet(q, i); } if ( GenCC ) {_gen1(",err%d", DefErrSet( &f, 1, NULL ));} else _gen1(",zzerr%d", DefErrSet( &f, 1, NULL )); set_free(f); } } _gen(",&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}\n"); /* MR13 */ if (nilf) { /* MR13 */ errFL("empty error set for alt - probably because of undefined rule or infinite left recursion", /* MR13 */ FileStr[q->file],q->line); /* MR13 */ gen(" /* MR13 empty error set for this alt - undef rule ? infinite left recursion ? */"); /* MR13 */ }; } static /* MR7 */ #ifdef __USE_PROTOS char * findOuterHandlerLabel(ExceptionGroup *eg) /* MR7 */ #else char * findOuterHandlerLabel(eg) /* MR7 */ ExceptionGroup *eg; /* MR7 */ #endif { char *label=NULL; /* MR7 */ ExceptionGroup *outerEG; /* MR7 */ if (eg->forRule == 0) { /* MR7 */ if (eg->labelEntry != NULL) { /* MR7 */ outerEG=eg->labelEntry->outerEG; /* MR7 */ if (outerEG != NULL) { /* MR7 */ label=outerEG->altID; /* MR7 */ outerEG->used=1; /* MR7 */ }; /* MR7 */ } else if (eg->outerEG != NULL) { /* MR7 */ outerEG=eg->outerEG; /* MR7 */ label=outerEG->altID; /* MR7 */ outerEG->used=1; /* MR7 */ }; /* MR7 */ }; /* MR7 */ return (label==NULL ? "" : label); /* MR7 */ } /* MR7 */ /*** debug ***/ #if 0 ** static /* MR7 */ ** #ifdef __USE_PROTOS ** char * findOuterAltHandlerLabel(Junction *startJ) /* MR7 */ ** #else ** char * findOuterAltHandlerLabel(startJ) /* MR7 */ ** Junction *startJ; /* MR7 */ ** #endif ** { /* MR7 */ ** char *label=NULL; /* MR7 */ ** Junction *alt; /* MR7 */ ** /* MR7 */ ** for (alt=startJ; alt != NULL; alt=alt->outerAltstart) { /* MR7 */ ** label=alt->exception_label; /* MR7 */ ** if (label != NULL) break; /* MR7 */ ** }; /* MR7 */ ** return (label==NULL ? "" : label); /* MR7 */ ** } /* MR7 */ #endif #ifdef __USE_PROTOS static void OutLineInfo(FILE *file,int line,char *fileName) #else static void OutLineInfo(file,line,fileName) FILE * file; int line; char * fileName; #endif { static char * prevFileName=NULL; static char * prevFileNameMS=NULL; char * p; char * q; if (! GenLineInfo) return; if (!GenLineInfoMS) { fprintf(file, LineInfoFormatStr,line,fileName); } else { if (fileName == prevFileName) { fprintf(file, LineInfoFormatStr,line,prevFileNameMS); } else { if (prevFileNameMS != NULL) free (prevFileNameMS); prevFileNameMS=(char *)calloc(1,strlen(fileName)+1); require(prevFileNameMS != NULL,"why not do this in calloc wrapper"); q=prevFileNameMS; for (p=fileName; *p != 0; p++) { *q=*p; if (*q == '\\') *q='/'; q++; } } prevFileName=fileName; }; } cccc-3.1.4/pccts/antlr/generic.h0000644000000000000000000002121707265347700015146 0ustar rootroot/* * 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-1998 */ #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 */ #ifndef ZZLEXBUFSIZE #define ZZLEXBUFSIZE 8000 #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 setnum; /* which set number is this guy? (if dumped) */ } 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) */ ListNode *el_labels;/* list of element labels ref in all of rule */ 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 cccc-3.1.4/pccts/antlr/globals.c0000644000000000000000000004044207265347707015160 0ustar rootroot/* * 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-1998 */ #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" char Version[] = "1.33MR20" ; /* PCCTS version number */ /* MRXXX */ char VersionDef[] = "13320"; /* 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; /* 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 */ /* 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 AlphaBetaTrace=0; /* MR14 */ 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 = 0; /* MR6 */ 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 */ cccc-3.1.4/pccts/antlr/hash.c0000644000000000000000000001237607265347707014465 0ustar rootroot/* * 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-1998 */ #include #include "pcctscfg.h" #include "hash.h" #ifdef __USE_PROTOS #include #else #ifdef VAXC #include #else #include #endif #endif #include #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 ); } cccc-3.1.4/pccts/antlr/hash.h0000644000000000000000000000411307265347712014454 0ustar rootroot/* * 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-1998 */ /* 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 cccc-3.1.4/pccts/antlr/lex.c0000644000000000000000000005467707373512202014324 0ustar rootroot/* * 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-1998 */ #include #include /* 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 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 */ // zzTRACE_RULES removed from end of #endif directive by TL // because it causes a warning under GCC 3.0.2. // fprintf(dlgFile,"#endif zzTRACE_RULES\n"); /* MR20 */ fprintf(dlgFile,"#endif\n"); /* MR20 */ }; 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; inext; 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; i1 ) { 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 ) { 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; irname, 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. */ 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 ) { if ( HasComma(p->ret) ) { DumpRetValStruct(f, p->ret, i); } fprintf(f, "\n#ifdef __USE_PROTOS\n"); if ( HasComma(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); 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"); if ( HasComma(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); 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 ) { if ( HasComma(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 ) { if ( HasComma(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); 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); 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. */ int #ifdef __USE_PROTOS DumpNextNameInDef( char **q, FILE *output ) #else DumpNextNameInDef( q, output ) char **q; FILE *output; #endif { char *p = *q; /* where did we leave off? */ int done=0; while ( *p!='\0' && *p!=',' ) p++; /* find end of decl */ if ( *p == '\0' ) done = 1; while ( !isalnum(*p) && *p!='_' ) --p; /* scan back until valid var character */ while ( isalnum(*p) || *p=='_' ) --p; /* scan back until beginning of variable */ p++; /* move to start of variable */ while ( isalnum(*p) || *p=='_' ) {putc(*p, output); p++;} while ( *p!='\0' && *p!=',' ) p++; /* find end of decl */ p++; /* move past this parameter */ *q = p; /* record where we left off */ return done; } /* 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 */ void #ifdef __USE_PROTOS DumpType( char *s, FILE *f ) #else DumpType( s, f ) char *s; FILE *f; #endif { char *p, *end; require(s!=NULL, "DumpType: invalid type string"); p = &s[strlen(s)-1]; /* start at end of string and work back */ /* MR11 */ /* scan back until valid variable character */ while ( !isalnum(*p) && *p!='_' ) --p; /* scan back until beginning of variable */ while ( isalnum(*p) || *p=='_' ) --p; if ( p<=s ) { warnNoFL(eMsg1("invalid parameter/return value: '%s'",s)); return; } end = p; /* here is where we stop printing alnum */ p = s; while ( p!=end ) {putc(*p, f); p++;} /* dump until just before variable */ while ( *p!='\0' ) /* dump rest w/o variable */ { if ( !isalnum(*p) && *p!='_' ) putc(*p, f); p++; } } /* 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; } int #ifdef __USE_PROTOS HasComma( char *s ) #else HasComma( s ) char *s; #endif { while (*s!='\0') if ( *s++ == ',' ) return 1; return 0; } void #ifdef __USE_PROTOS DumpRetValStruct( FILE *f, char *ret, int i ) #else DumpRetValStruct( f, ret, i ) FILE *f; char *ret; int i; #endif { fprintf(f, "\nstruct _rv%d {\n", i); while ( *ret != '\0' ) { while ( *ret==' ' || *ret=='\t' ) ret++; /* ignore white */ putc('\t', f); while ( *ret!=',' && *ret!='\0' ) {putc(*ret,f); ret++;} if ( *ret == ',' ) {putc(';', f); putc('\n', f); ret++;} } fprintf(f, ";\n};\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 ); } cccc-3.1.4/pccts/antlr/main.c0000644000000000000000000014025507373512202014444 0ustar rootroot/* * main.c -- main program for 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-1998 */ #include #include "pcctscfg.h" #include "stdpccts.h" #define MAX_INT_STACK 50 static int istack[MAX_INT_STACK]; /* Int stack */ static int isp = MAX_INT_STACK; static int DontAcceptFiles = 0; /* if stdin, don't read files */ static int DontAcceptStdin = 0; /* if files seen first, don't accept stdin */ static int tnodes_used_in_guard_predicates_etc; /* MR10 */ /* C m d - L i n e O p t i o n S t r u c t & F u n c s */ typedef struct _Opt { char *option; int arg; #ifdef __cplusplus void (*process)(...); #else void (*process)(); #endif char *descr; } Opt; #ifdef __USE_PROTOS extern void ProcessArgs(int, char **, Opt *); #else extern void ProcessArgs(); #endif #ifdef __USE_PROTOS int ci_strequ(char *a,char *b) #else 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); } static void #ifdef __USE_PROTOS pStdin( void ) #else pStdin( ) #endif { if ( DontAcceptStdin ) { warnNoFL("'-' (stdin) ignored as files were specified first"); return; } require(NumFiles 8 ) { /* MR6 */ warnNoFL("tab width must be between 1 and 8"); /* MR6 */ TabWidth=0; /* MR6 */ } /* MR6 */ } /* MR6 */ static int ambAidDepthSpecified=0; /* MR11 */ static void /* MR11 */ #ifdef __USE_PROTOS pAAd( char *s, char *t ) /* MR11 */ #else pAAd( s, t ) /* MR11 */ char *s; /* MR11 */ char *t; /* MR11 */ #endif { /* MR11 */ ambAidDepthSpecified=1; /* MR11 */ MR_AmbAidDepth = atoi(t); /* MR11 */ } /* MR11 */ static void /* MR11 */ #ifdef __USE_PROTOS pTreport( char *s, char *t ) /* MR11 */ #else pTreport( s, t ) /* MR11 */ char *s; /* MR11 */ char *t; /* MR11 */ #endif { /* MR11 */ TnodesReportThreshold = atoi(t); /* MR11 */ } /* MR11 */ #ifdef __USE_PROTOS void chkGTFlag(void) /* 7-Apr-97 MR1 */ #else void chkGTFlag() /* 7-Apr-97 MR1 */ #endif { if ( !GenAST ) warn("#-variable or other AST item referenced w/o -gt option"); } #ifdef __USE_PROTOS static void pInfo(char *s, char *t) /* MR10 */ #else static void pInfo(s,t) /* MR10 */ char *s; char *t; #endif { char *p; int q; for (p=t; *p != 0; p++) { q=tolower(*p); if (q=='t') { InfoT=1; } else if (q=='p') { InfoP=1; } else if (q=='m') { InfoM=1; } else if (q=='o') { InfoO=1; } else if (q=='0') { ; /* nothing */ } else if (q=='f') { InfoF=1; } else { warnNoFL(eMsgd("unrecognized -info option \"%c\"",(int)*p)); }; }; } #ifdef __USE_PROTOS static void pCGen(void) { CodeGen = FALSE; LexGen = FALSE; } static void pLGen(void) { LexGen = FALSE; } static void pXTGen(void){ MR_Inhibit_Tokens_h_Gen = TRUE; } static void pTGen(void) { TraceGen = TRUE; } static void pSGen(void) { GenExprSetsOpt = FALSE; } static void pPrt(void) { PrintOut = TRUE; pCGen(); pLGen(); } static void pPrtA(void) { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); } static void pAst(void) { GenAST = TRUE; } static void pANSI(void) { GenANSI = TRUE; } static void pCr(void) { GenCR = TRUE; } /*static void pCt(void) { warnNoFL("-ct option is now the default"); }*/ static void pLI(void) { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */ static void pLIms(void) { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */ static void pFr(char *s, char *t) {RemapFileName = t;} static void pFe(char *s, char *t) {ErrFileName = t;} static void pFl(char *s, char *t) {DlgFileName = t;} static void pFm(char *s, char *t) {ModeFileName = t;} static void pFt(char *s, char *t) {DefFileName = t;} static void pE1(void) { elevel = 1; } static void pE2(void) { elevel = 2; } static void pE3(void) { elevel = 3; } static void pEGen(void) { GenEClasseForRules = 1; } static void pDL(void) { DemandLookahead = 1; if ( GenCC ) { warnNoFL("-gk does not work currently in C++ mode; -gk turned off"); DemandLookahead = 0; } } static void pAA(char *s,char *t) {MR_AmbAidRule = t;} /* MR11 */ static void pAAm(char *s){MR_AmbAidMultiple = 1;} /* MR11 */ static void pGHdr(void) { GenStdPccts = 1; } static void pFHdr(char *s, char *t) { stdpccts = t; pGHdr(); } static void pW1(void) { WarningLevel = 1; } static void pNewAST(void) { NewAST = 1; } /* MR13 */ static void pAlpha(void) { AlphaBetaTrace = 1; } /* MR14 */ static void pStdout(void) {UseStdout = 1; } /* MR6 */ static void pW2(void) { WarningLevel = 2; } static void pCC(void) { GenCC = TRUE; } #else static void pCGen() { CodeGen = FALSE; LexGen = FALSE; } static void pLGen() { LexGen = FALSE; } static void pXTGen(){ MR_Inhibit_Tokens_h_Gen = TRUE; } /* MR14 */ static void pTGen() { TraceGen = TRUE; } static void pSGen() { GenExprSetsOpt = FALSE; } static void pPrt() { PrintOut = TRUE; pCGen(); pLGen(); } static void pPrtA() { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); } static void pAst() { GenAST = TRUE; } static void pANSI() { GenANSI = TRUE; } static void pCr() { GenCR = TRUE; } /*static void pCt() { warnNoFL("-ct option is now the default"); }*/ static void pLI() { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */ static void pLIms() { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */ static void pFr(s,t) char *s, *t; {RemapFileName = t;} static void pFe(s,t) char *s, *t; {ErrFileName = t;} static void pFl(s,t) char *s, *t; {DlgFileName = t;} static void pFm(s,t) char *s, *t; {ModeFileName = t;} static void pFt(s,t) char *s, *t; {DefFileName = t;} static void pE1() { elevel = 1; } static void pE2() { elevel = 2; } static void pE3() { elevel = 3; } static void pEGen() { GenEClasseForRules = 1; } static void pDL() { DemandLookahead = 1; if ( GenCC ) { warnNoFL("-gk does not work currently in C++ mode; -gk turned off"); DemandLookahead = 0; } } static void pAA(s,t) char *s; char *t; {MR_AmbAidRule = t;} /* MR11 BJS 20-Mar-98 */ static void pAAm(s) char *s; {MR_AmbAidMultiple = 1;} /* MR11 BJS 20-Mar-98 */ static void pGHdr() { GenStdPccts = 1; } static void pFHdr(s,t) char *s, *t; { stdpccts = t; pGHdr(); } static void pW1() { WarningLevel = 1; } static void pNewAST() { NewAST = 1; } /* MR13 */ static void pAlpha() { AlphaBetaTrace = 1; } /* MR14 */ static void pStdout() {UseStdout = 1; } /* MR6 */ static void pW2() { WarningLevel = 2; } static void pCC() { GenCC = TRUE; } #endif static void #ifdef __USE_PROTOS pPre( char *s, char *t ) #else pPre( s, t ) char *s; char *t; #endif { RulePrefix = t; } static void #ifdef __USE_PROTOS pOut( char *s, char *t ) #else pOut( s, t ) char *s; char *t; #endif { OutputDirectory = t; } static void #ifdef __USE_PROTOS pPred( void ) #else pPred( ) #endif { warnNoFL("-pr is no longer used (predicates employed if present); see -prc, -mrhoist, -mrhoistk"); /* ** if ( DemandLookahead ) ** warnNoFL("-gk conflicts with -pr; -gk turned off"); ** DemandLookahead = 0; ** HoistPredicateContext = 0; */ } static void #ifdef __USE_PROTOS pPredCtx( char *s, char *t ) #else pPredCtx(s,t) char *s; char *t; #endif { if ( ci_strequ(t,"on")) HoistPredicateContext = 1; else if ( ci_strequ(t,"off")) HoistPredicateContext = 0; if ( DemandLookahead ) { warnNoFL("-gk incompatible with semantic predicate usage; -gk turned off"); DemandLookahead = 0; } } static void #ifdef __USE_PROTOS pMRhoist( char *s, char *t ) #else pMRhoist(s,t) char *s; char *t; #endif { if ( ci_strequ(t,"on")) MRhoisting = 1; else if ( ci_strequ(t,"off")==0 ) MRhoisting = 0; if (MRhoisting) { fprintf(stderr,"Maintenance Release style hoisting enabled for predicates with lookahead depth = 1\n"); fprintf(stderr," No longer considered experimental\n"); fprintf(stderr," Can't consider suppression for predicates with lookahead depth > 1\n"); fprintf(stderr," Implies -prc on but does *not* imply -mrhoistk for k>1 predicates\n"); }; } static void #ifdef __USE_PROTOS pMRhoistk( char *s, char *t ) #else pMRhoistk(s,t) char *s; char *t; #endif { if ( ci_strequ(t,"on")) MRhoistingk = 1; else if ( ci_strequ(t,"off")==0 ) MRhoistingk = 0; if (MRhoistingk) { fprintf(stderr,"EXPERIMENTAL Maintenance Release style hoisting enabled\n"); fprintf(stderr," Applies to predicates with lookahead depth > 1\n"); fprintf(stderr," Implies -prc on and -mrhoist on\n"); }; } static void #ifdef __USE_PROTOS pTRes( char *s, char *t ) #else pTRes( s, t ) char *s; char *t; #endif { TreeResourceLimit = atoi(t); if ( TreeResourceLimit <= 0 ) { warnNoFL("analysis resource limit (# of tree nodes) must be greater than 0"); TreeResourceLimit = -1; /* set to no limit */ } } Opt options[] = { #ifdef __cplusplus { "-CC", 0, (void (*)(...)) pCC, "Generate C++ output (default=FALSE)"}, { "-ck", 1, (void (*)(...)) pCk, "Set compressed lookahead depth; fast approximate lookahead"}, { "-cr", 0, (void (*)(...)) pCr, "Generate cross reference (default=FALSE)"}, { "-e1", 0, (void (*)(...)) pE1, "Ambiguities/errors shown in low detail (default)"}, { "-e2", 0, (void (*)(...)) pE2, "Ambiguities/errors shown in more detail"}, { "-e3", 0, (void (*)(...)) pE3, "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"}, { "-f", 1, (void (*)(...)) pFileList,"Read names of grammar files from specified file"}, /* MR14 */ { "-fe", 1, (void (*)(...)) pFe, "Rename err.c"}, { "-fh", 1, (void (*)(...)) pFHdr, "Rename stdpccts.h header (turns on -gh)"}, { "-fl", 1, (void (*)(...)) pFl, "Rename lexical output--parser.dlg"}, { "-fm", 1, (void (*)(...)) pFm, "Rename mode.h"}, { "-fr", 1, (void (*)(...)) pFr, "Rename remap.h"}, { "-ft", 1, (void (*)(...)) pFt, "Rename tokens.h"}, { "-ga", 0, (void (*)(...)) pANSI, "Generate ANSI-compatible code (default=FALSE)"}, { "-gc", 0, (void (*)(...)) pCGen, "Do not generate output parser code (default=FALSE)"}, { "-gd", 0, (void (*)(...)) pTGen, "Generate code to trace rule invocation (default=FALSE)"}, { "-ge", 0, (void (*)(...)) pEGen, "Generate an error class for each non-terminal (default=FALSE)"}, { "-gh", 0, (void (*)(...)) pGHdr, "Generate stdpccts.h for non-ANTLR-generated-files to include"}, { "-gk", 0, (void (*)(...)) pDL, "Generate parsers that delay lookahead fetches until needed"}, { "-gl", 0, (void (*)(...)) pLI, "Generate line info about grammar actions in parser"}, { "-glms", 0, (void (*)(...)) pLIms,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"}, { "-gp", 1, (void (*)(...)) pPre, "Prefix all generated rule functions with a string"}, { "-gs", 0, (void (*)(...)) pSGen, "Do not generate sets for token expression lists (default=FALSE)"}, { "-gt", 0, (void (*)(...)) pAst, "Generate code for Abstract-Syntax-Trees (default=FALSE)"}, { "-gx", 0, (void (*)(...)) pLGen, "Do not generate lexical (dlg-related) files (default=FALSE)"}, { "-gxt",0, (void (*)(...)) pXTGen, "Do not generate tokens.h (default=FALSE)"}, { "-k", 1, (void (*)(...)) pLLK, "Set full LL(k) lookahead depth (default==1)"}, { "-o", 1, (void (*)(...)) pOut, OutputDirectoryOption}, { "-p", 0, (void (*)(...)) pPrt, "Print out the grammar w/o actions (default=no)"}, { "-pa", 0, (void (*)(...)) pPrtA, "Print out the grammar w/o actions & w/FIRST sets (default=no)"}, { "-pr",0, (void (*)(...)) pPred, "no longer used; predicates employed if present"}, { "-prc", 1, (void (*)(...)) pPredCtx,"Turn on/off computation of context for hoisted predicates"}, { "-rl", 1, (void (*)(...)) pTRes, "Limit max # of tree nodes used by grammar analysis"}, { "-stdout",0, (void (*)(...)) pStdout,"Send grammar.c/grammar.cpp to stdout"}, /* MR6 */ { "-tab", 1, (void (*)(...)) pTab, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */ { "-w1", 0, (void (*)(...)) pW1, "Set the warning level to 1 (default)"}, { "-w2", 0, (void (*)(...)) pW2, "Ambiguities yield warnings even if predicates or (...)? block"}, { "-", 0, (void (*)(...)) pStdin, "Read grammar from stdin" }, { "-mrhoist",1, (void (*)(...)) pMRhoist, /* MR9 */ "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */ { "-mrhoistk",1, (void (*)(...)) pMRhoistk, /* MR9 */ "Turn on/off EXPERIMENTAL k>1 Maintenance Release style hoisting"}, /* MR13 */ { "-aa" , 1, (void (*)(...)) pAA, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */ { "-aam" , 0, (void (*)(...)) pAAm, "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */ { "-aad" , 1, (void (*)(...)) pAAd, "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */ { "-info", 1, (void (*)(...)) pInfo, "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR12 */ { "-treport",1,(void (*)(...)) pTreport, "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */ { "-newAST", 0, (void (*)(...)) pNewAST, "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */ { "-alpha",0,(void (*)(...)) pAlpha, "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */ { "*", 0, (void (*)(...)) pFile, "" }, /* anything else is a file */ #else { "-CC", 0, pCC, "Generate C++ output (default=FALSE)"}, { "-cr", 0, pCr, "Generate cross reference (default=FALSE)"}, { "-ck", 1, pCk, "Set compressed lookahead depth; fast approximate lookahead"}, { "-e1", 0, pE1, "Ambiguities/errors shown in low detail (default)"}, { "-e2", 0, pE2, "Ambiguities/errors shown in more detail"}, { "-e3", 0, pE3, "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"}, { "-f", 1, pFileList,"Read names of grammar files from specified file"}, /* MR14 */ { "-fe", 1, pFe, "Rename err.c"}, { "-fh", 1, pFHdr, "Rename stdpccts.h header (turns on -gh)"}, { "-fl", 1, pFl, "Rename lexical output--parser.dlg"}, { "-fm", 1, pFm, "Rename mode.h"}, { "-fr", 1, pFr, "Rename remap.h"}, { "-ft", 1, pFt, "Rename tokens.h"}, { "-ga", 0, pANSI, "Generate ANSI-compatible code (default=FALSE)"}, { "-gc", 0, pCGen, "Do not generate output parser code (default=FALSE)"}, { "-gd", 0, pTGen, "Generate code to trace rule invocation (default=FALSE)"}, { "-ge", 0, pEGen, "Generate an error class for each non-terminal (default=FALSE)"}, { "-gh", 0, pGHdr, "Generate stdpccts.h for non-ANTLR-generated-files to include"}, { "-gk", 0, pDL, "Generate parsers that delay lookahead fetches until needed"}, { "-gl", 0, pLI, "Generate line info about grammar actions in C parser"}, { "-glms", 0, pLIms,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"}, { "-gp", 1, pPre, "Prefix all generated rule functions with a string"}, { "-gs", 0, pSGen, "Do not generate sets for token expression lists (default=FALSE)"}, { "-gt", 0, pAst, "Generate code for Abstract-Syntax-Trees (default=FALSE)"}, { "-gx", 0, pLGen, "Do not generate lexical (dlg-related) files (default=FALSE)"}, { "-gxt",0, pXTGen, "Do not generate tokens.h (default=FALSE)"}, { "-k", 1, pLLK, "Set full LL(k) lookahead depth (default==1)"}, { "-o", 1, pOut, OutputDirectoryOption}, { "-p", 0, pPrt, "Print out the grammar w/o actions (default=no)"}, { "-pa", 0, pPrtA, "Print out the grammar w/o actions & w/FIRST sets (default=no)"}, { "-pr",0, pPred, "no longer used; predicates employed if present"}, { "-prc", 1, pPredCtx,"Turn on/off computation of context for hoisted predicates"}, { "-rl", 1, pTRes, "Limit max # of tree nodes used by grammar analysis"}, { "-stdout",0, pStdout, "Send grammar.c/grammar.cpp to stdout"}, /* MR6 */ { "-tab", 1, pTab, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */ { "-w1", 0, pW1, "Set the warning level to 1 (default)"}, { "-w2", 0, pW2, "Ambiguities yield warnings even if predicates or (...)? block"}, { "-mrhoist",1,pMRhoist, /* MR9 */ "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */ { "-mrhoistk",1,pMRhoistk, /* MR13 */ "Turn on/off k>1 EXPERIMENTAL Maintenance Release style hoisting"}, /* MR13 */ { "-aa" ,1,pAA, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */ { "-aam" ,0,pAAm, "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */ { "-aad" ,1,pAAd, "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */ { "-info",1,pInfo, "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR11 */ { "-treport",1,pTreport, "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */ { "-newAST", 0, pNewAST, "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */ { "-alpha",0, pAlpha, "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */ { "-", 0, pStdin, "Read grammar from stdin" }, { "*", 0, pFile, "" }, /* anything else is a file */ #endif { NULL, 0, NULL } }; void readDescr(); void cleanUp(); #ifdef __USE_PROTOS static void buildRulePtr( void ); static void help( void ); static void init( void ); static void CompleteTokenSetRefs( void ); static void ensure_no_C_file_collisions(char *); static void CompleteContextGuards(void); #else static void buildRulePtr( ); static void help( ); static void init( ); static void CompleteTokenSetRefs( ); static void ensure_no_C_file_collisions(); static void CompleteContextGuards(); #endif static void #ifdef __USE_PROTOS /* */ report_numericPredLabels(ActionNode *a) #else report_numericPredLabels(a) ActionNode *a; #endif { /* MR10 */ warnFL("numeric references to attributes (e.g. $i or $i.j) in semantic pred will be null during guess mode", /* MR10 */ FileStr[a->file],a->line); /* MR10 */ } /* MR10 */ /* M a i n */ int #ifdef __USE_PROTOS main( int argc, char *argv[] ) #else main( argc, argv ) int argc; char *argv[]; #endif { int i; static char EPSTR[] = "[Ep]"; Save_argc=argc; /* MR10 */ Save_argv=argv; /* MR10 */ /* malloc_debug(8);*/ #ifdef SPECIAL_INITS special_inits(); /* MR1 */ #endif fprintf(stderr, "Antlr parser generator Version %s 1989-1999\n", Version); if ( argc == 1 ) { help(); zzDIE; } ProcessArgs(argc-1, &(argv[1]), options); /* MR14 */ if (MR_AmbAidRule && AlphaBetaTrace) { /* MR14 */ fatal("Can't specify both -aa (ambiguity aid) and -alpha (\"(alpha)? beta\" aid)"); /* MR14 */ } if (MRhoistingk) { /* MR13 */ HoistPredicateContext=1; /* MR13 */ MRhoisting=1; /* MR13 */ }; /* MR13 */ if (MRhoisting && ! HoistPredicateContext) { /*** warnNoFL("Using \"-mrhoist\" forces \"-prc on\""); ***/ HoistPredicateContext=1; }; if (HoistPredicateContext && ! MRhoisting) { warnNoFL("When using predicate context (-prc on) -mrhoist on is recommended"); } /* Fix lookahead depth */ /* Compressed lookahead must always be larger than or equal to full lookahead */ if ( CLL_k < LL_k && CLL_k>0 ) { warnNoFL("must have compressed lookahead >= full LL(k) lookahead (setting -ck to -k)"); CLL_k = LL_k; } if ( CLL_k == -1 ) CLL_k = LL_k; OutputLL_k = CLL_k; if ( ((CLL_k-1)&CLL_k)!=0 ) { /* output ll(k) must be power of 2 */ int n; for(n=1; n CLL_k || MR_AmbAidDepth <= 0) { warnNoFL(eMsgd( "Ambiguity aid depth (\"-aad ...\") must be a number between 1 and max(k,ck)=%d",CLL_k)); MR_AmbAidDepth=1; }; if (MR_AmbAidDepth == 0) { MR_AmbAidDepth=2; }; }; if (MR_AmbAidRule != NULL) MR_AmbAidLine=atoi(MR_AmbAidRule); fpTrans = &(C_Trans[0]); /* Translate to C Language */ fpJTrans = &(C_JTrans[0]); init(); lexclass(LexStartSymbol); readDescr(); LastTokenCounted = TokenNum; RemapForcedTokens(); if ( CannotContinue ) {cleanUp(); zzDIE;} if ( GenCC && no_classes_found ) fatal("required grammar class not found (exiting...)"); if ( WarningLevel>1 && HdrAction == NULL ) warnNoFL("no #header action was found"); if ( FoundAtOperator && ! FoundExceptionGroup) { warnNoFL("found the exception operator '@' - but no exception group was found"); }; EpToken = addTname(EPSTR); /* add imaginary token epsilon */ set_orel(EpToken, &imag_tokens); /* this won't work for hand-built scanners since EofToken is not * known. Forces EOF to be token type 1. */ set_orel(EofToken, &imag_tokens); set_size(NumWords(TokenNum-1)); /* compute the set of all known token types * It represents the set of tokens from 1 to last_token_num + the * reserved positions above that (if any). Don't include the set of * imaginary tokens such as the token/error classes or EOF. */ { set a; a = set_dup(reserved_positions); for (i=1; inext; p!=NULL; p=p->next) { UserAction *ua = (UserAction *)p->elem; dumpAction( ua->action, Parser_h, 0, ua->file, ua->line, 1); } } GenParser_c_Hdr(); fprintf(Parser_h, "protected:\n"); /* MR20 */ NewSetWd(); TRANS(SynDiag); /* Translate to the target language */ DumpSetWd(); GenRuleMemberDeclarationsForCC(Parser_h, SynDiag); if ( class_after_actions != NULL ) { ListNode *p; for (p = class_after_actions->next; p!=NULL; p=p->next) { UserAction *ua = (UserAction *)p->elem; dumpAction( ua->action, Parser_h, 0, ua->file, ua->line, 1); } } DumpRemainingTokSets(); fprintf(Parser_h, "};\n"); // The next line modified by TL, because GCC 3.0.2 reports // a warning if a comment appears after #endif // fprintf(Parser_h, "\n#endif /* %s_h */\n", CurrentClassName); fprintf(Parser_h, "\n#endif /* %s_h */\n", CurrentClassName); fclose( Parser_h ); fclose( Parser_c ); } } MR_orphanRules(stderr); if ( PrintOut ) { if ( SynDiag == NULL ) {warnNoFL("no grammar description recognized");} else PRINT(SynDiag); } #ifdef DBG_LL1 #endif GenRemapFile(); /* create remap.h */ /* MR10 */ if (FoundGuessBlk) { #ifdef __cplusplus__ /* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels); #else #ifdef __USE_PROTOS /* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels); #else /* MR10 */ list_apply(NumericPredLabels,report_numericPredLabels); #endif #endif /* MR10 */ }; if (InfoT && TnodesAllocated > 0) { if (TnodesPeak > 10000) { fprintf(stdout,"\nTree Nodes: peak %dk created %dk lost %d\n", (TnodesPeak/1000), (TnodesAllocated/1000), TnodesInUse-tnodes_used_in_guard_predicates_etc); } else { fprintf(stdout,"\nTree Nodes: peak %d created %d lost %d\n", TnodesPeak, TnodesAllocated, TnodesInUse-tnodes_used_in_guard_predicates_etc); }; }; if (InfoF) { DumpFcache(); }; if (MR_skipped_e3_report) { fprintf(stderr,"note: use -e3 to get exact information on ambiguous tuples\n"); }; if (MR_BadExprSets != 0) { fprintf(stderr,"note: Unreachable C or C++ code was generated for empty expression sets,\n"); fprintf(stderr," probably due to undefined rules or infinite left recursion.\n"); fprintf(stderr," To locate: search the generated code for \"empty set expression\"\n"); }; if (MR_AmbAidRule != NULL && MR_matched_AmbAidRule==0) { RuleEntry *q = (RuleEntry *) hash_get(Rname,MR_AmbAidRule); if (MR_AmbAidLine == 0 && q == NULL) { warnNoFL(eMsg2("there is no rule \"%s\" so \"-aa %s\" will never match", MR_AmbAidRule,MR_AmbAidRule)); } else { warnNoFL(eMsg1("there was no ambiguity that matched \"-aa %s\"",MR_AmbAidRule)); }; }; if (AlphaBetaTrace) { if (MR_AlphaBetaMessageCount == 0) { fprintf(stderr,"note: there were no messages about \"(alpha)? beta\" blocks added to the generated code\n"); } else { fprintf(stderr,"note: there were %d messages about \"(alpha)? beta\" blocks added to the generated code\n", MR_AlphaBetaMessageCount); } if (set_null(MR_CompromisedRules)) { fprintf(stderr,"note: the list of rules with compromised follow sets is empty\n"); } else { fprintf(stderr,"note: the following is a list of rules which *may* have incorrect\n"); fprintf(stderr," follow sets computed as a result of an \"(alpha)? beta\" block\n"); fprintf(stderr,"\n"); MR_dumpRuleSet(MR_CompromisedRules); fprintf(stderr,"\n"); } } cleanUp(); exit(PCCTS_EXIT_SUCCESS); return 0; /* MR11 make compilers happy */ } static void #ifdef __USE_PROTOS init( void ) #else init( ) #endif { SignalEntry *q; Tname = newHashTable(); Rname = newHashTable(); Fcache = newHashTable(); Tcache = newHashTable(); Sname = newHashTable(); Pname = newHashTable(); /* MR11 */ /* Add default signal names */ q = (SignalEntry *)hash_add(Sname, "NoViableAlt", (Entry *)newSignalEntry("NoViableAlt")); require(q!=NULL, "cannot alloc signal entry"); q->signum = sigNoViableAlt; q = (SignalEntry *)hash_add(Sname, "MismatchedToken", (Entry *)newSignalEntry("MismatchedToken")); require(q!=NULL, "cannot alloc signal entry"); q->signum = sigMismatchedToken; q = (SignalEntry *)hash_add(Sname, "NoSemViableAlt", (Entry *)newSignalEntry("NoSemViableAlt")); require(q!=NULL, "cannot alloc signal entry"); q->signum = sigNoSemViableAlt; reserved_positions = empty; all_tokens = empty; imag_tokens = empty; tokclasses = empty; TokenStr = (char **) calloc(TSChunk, sizeof(char *)); require(TokenStr!=NULL, "main: cannot allocate TokenStr"); FoStack = (int **) calloc(CLL_k+1, sizeof(int *)); require(FoStack!=NULL, "main: cannot allocate FoStack"); FoTOS = (int **) calloc(CLL_k+1, sizeof(int *)); require(FoTOS!=NULL, "main: cannot allocate FoTOS"); Cycles = (ListNode **) calloc(CLL_k+1, sizeof(ListNode *)); require(Cycles!=NULL, "main: cannot allocate Cycles List"); MR_CompromisedRules=empty; /* MR14 */ } static void #ifdef __USE_PROTOS help( void ) #else help( ) #endif { Opt *p = options; fprintf(stderr, "antlr [options] f1 f2 ... fn\n"); while ( *(p->option) != '*' ) { fprintf(stderr, " %-9s%s %s\n", p->option, (p->arg)?"___":" ", p->descr); p++; } } /* The RulePtr array is filled in here. RulePtr exists primarily * so that sets of rules can be maintained for the FOLLOW caching * mechanism found in rJunc(). RulePtr maps a rule num from 1 to n * to a pointer to its RuleBlk junction where n is the number of rules. */ static void #ifdef __USE_PROTOS buildRulePtr( void ) #else buildRulePtr( ) #endif { int r=1; Junction *p = SynDiag; RulePtr = (Junction **) calloc(NumRules+1, sizeof(Junction *)); require(RulePtr!=NULL, "cannot allocate RulePtr array"); while ( p!=NULL ) { require(r<=NumRules, "too many rules???"); RulePtr[r++] = p; p = (Junction *)p->p2; } } void #ifdef __USE_PROTOS dlgerror(const char *s) #else dlgerror(s) char *s; #endif { fprintf(stderr, ErrHdr, FileStr[CurFile], zzline); fprintf(stderr, " lexical error: %s (text was '%s')\n", ((s == NULL) ? "Lexical error" : s), zzlextext); } void #ifdef __USE_PROTOS readDescr( void ) #else readDescr( ) #endif { zzerr = dlgerror; input = NextFile(); if ( input==NULL ) fatal("No grammar description found (exiting...)"); ANTLR(grammar(), input); tnodes_used_in_guard_predicates_etc=TnodesInUse; /* MR10 */ } FILE * #ifdef __USE_PROTOS NextFile( void ) #else NextFile( ) #endif { FILE *f; for (;;) { CurFile++; if ( CurFile >= NumFiles ) return(NULL); if ( ci_strequ(FileStr[CurFile],"stdin")) return stdin; f = fopen(FileStr[CurFile], "r"); if ( f == NULL ) { warnNoFL( eMsg1("file %s doesn't exist; ignored", FileStr[CurFile]) ); } else { return(f); } } } /* * Return a string corresponding to the output file name associated * with the input file name passed in. * * Observe the following rules: * * f.e --> f".c" * f --> f".c" * f. --> f".c" * f.e.g --> f.e".c" * * Where f,e,g are arbitrarily long sequences of characters in a file * name. * * In other words, if a ".x" appears on the end of a file name, make it * ".c". If no ".x" appears, append ".c" to the end of the file name. * * C++ mode using .cpp not .c. * * Use malloc() for new string. */ char * #ifdef __USE_PROTOS outname( char *fs ) #else outname( fs ) char *fs; #endif { if ( GenCC) { return outnameX(fs,CPP_FILE_SUFFIX); } else { return outnameX(fs,".c"); }; } char * #ifdef __USE_PROTOS outnameX( char *fs ,char *suffix) #else outnameX( fs , suffix ) char *fs; char *suffix; #endif { static char buf[MaxFileName+1]; char *p; require(fs!=NULL&&*fs!='\0', "outname: NULL filename"); p = buf; strcpy(buf, fs); while ( *p != '\0' ) {p++;} /* Stop on '\0' */ while ( *p != '.' && p != buf ) {--p;} /* Find '.' */ if ( p != buf ) *p = '\0'; /* Found '.' */ require(strlen(buf) + 2 < (size_t)MaxFileName, "outname: filename too big"); strcat(buf,suffix); return( buf ); } void #ifdef __USE_PROTOS fatalFL( char *err_, char *f, int l ) #else fatalFL( err_, f, l ) char *err_; char *f; int l; #endif { fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " %s\n", err_); cleanUp(); exit(PCCTS_EXIT_FAILURE); } void #ifdef __USE_PROTOS fatal_intern( char *err_, char *f, int l ) #else fatal_intern( err_, f, l ) char *err_; char *f; int l; #endif { fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " #$%%*&@# internal error: %s\n", err_); fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " [complain to nearest government official\n"); fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " or send hate-mail to parrt@parr-research.com;\n"); fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " please pray to the ``bug'' gods that there is a trival fix.]\n"); cleanUp(); exit(PCCTS_EXIT_FAILURE); } void #ifdef __USE_PROTOS cleanUp( void ) #else cleanUp( ) #endif { if ( DefFile != NULL) fclose( DefFile ); } /* sprintf up to 3 strings */ char * #ifdef __USE_PROTOS eMsg3( char *s, char *a1, char *a2, char *a3 ) #else eMsg3( s, a1, a2, a3 ) char *s; char *a1; char *a2; char *a3; #endif { static char buf[250]; /* DANGEROUS as hell !!!!!! */ sprintf(buf, s, a1, a2, a3); return( buf ); } /* sprintf a decimal */ char * #ifdef __USE_PROTOS eMsgd( char *s, int d ) #else eMsgd( s, d ) char *s; int d; #endif { static char buf[250]; /* DANGEROUS as hell !!!!!! */ sprintf(buf, s, d); return( buf ); } char * #ifdef __USE_PROTOS eMsgd2( char *s, int d1,int d2) #else eMsgd2( s, d1, d2 ) char *s; int d1; int d2; #endif { static char buf[250]; /* DANGEROUS as hell !!!!!! */ sprintf(buf, s, d1, d2); return( buf ); } void #ifdef __USE_PROTOS s_fprT( FILE *f, set e ) #else s_fprT( f, e ) FILE *f; set e; #endif { register unsigned *p; unsigned *q; if ( set_nil(e) ) return; if ( (q=p=set_pdq(e)) == NULL ) fatal_internal("Can't alloc space for set_pdq"); fprintf(f, "{"); while ( *p != nil ) { fprintf(f, " %s", TerminalString(*p)); p++; } fprintf(f, " }"); free((char *)q); } /* Return the token name or regular expression for a token number. */ char * #ifdef __USE_PROTOS TerminalString( int token ) #else TerminalString( token ) int token; #endif { int j; static char imag_name[20]; /* look in all lexclasses for the token */ if ( TokenString(token) != NULL ) return TokenString(token); for (j=0; j0, "pushint: stack overflow"); istack[--isp] = i; } int #ifdef __USE_PROTOS popint( void ) #else popint( ) #endif { require(isp 0 ) { p = options; while ( p->option != NULL ) { if ( strcmp(p->option, "*") == 0 || ci_strequ(p->option, *argv) == 1 ) { if ( p->arg ) { /* MR9 26-Sep-97 Check for argv valid */ if (argc-- > 0) { (*p->process)( *argv, *(argv+1) ); argv++; } else { fprintf(stderr,"error: required argument for option %s omitted\n",*argv); exit(PCCTS_EXIT_FAILURE); }; } else (*p->process)( *argv ); break; } p++; } argv++; } } static void #ifdef __USE_PROTOS CompleteContextGuards(void) #else CompleteContextGuards() #endif { ListNode * p; Predicate * pred; if (ContextGuardPredicateList == NULL) return; for (p=ContextGuardPredicateList->next; p != NULL; p=p->next) { pred=(Predicate *)p->elem; recomputeContextGuard(pred); } } /* Go back into the syntax diagram and compute all meta tokens; i.e. * turn all '.', ranges, token class refs etc... into actual token sets */ static void #ifdef __USE_PROTOS CompleteTokenSetRefs(void) #else CompleteTokenSetRefs() #endif { ListNode *p; if ( MetaTokenNodes==NULL ) return; for (p = MetaTokenNodes->next; p!=NULL; p=p->next) { set a,b; TokNode *q = (TokNode *)p->elem; if ( q->wild_card ) { q->tset = all_tokens; } else if ( q->tclass!=NULL ) { if ( q->complement ) q->tset = set_dif(all_tokens, q->tclass->tset); else q->tset = q->tclass->tset; } else if ( q->upper_range!=0 ) { /* we have a range on our hands: make a set from q->token .. q->upper_range */ int i; a = empty; for (i=q->token; i<=q->upper_range; i++) { set_orel(i, &a); } /* MR13 */ /* MR13 */ if (q->complement) { /* MR13 */ q->tset = set_dif(all_tokens, a); /* MR13 */ set_free(a); /* MR13 */ } else { /* MR13 */ q->tset = a; /* MR13 */ } } /* at this point, it can only be a complemented single token */ else if ( q->complement ) { a = set_of(q->token); b = set_dif(all_tokens, a); set_free(a); q->tset=b; } else fatal("invalid meta token"); } } /* MR10: Jeff Vincent MR10: Changed to remove directory information from n only if MR10: if OutputDirectory was changed by user (-o option) */ char * #ifdef __USE_PROTOS OutMetaName(char *n) #else 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; } char * #ifdef __USE_PROTOS baseName(char *n) #else baseName(n) char *n; #endif { static char newname[MaxFileName+1]; static char* dir_sym = DirectorySymbol; int count = 0; char *p; p = n; while ( *p != '\0' ) {p++;} /* go to end of string */ while ( (*p != *dir_sym) && (p != n) ) {--p;} /* Find last DirectorySymbol */ while ( *p == *dir_sym) p++; /* step forward if we're on a dir symbol */ while ( *p != '\0' && *p != '.') { newname[count++] = *p; p++; } /* create a new name */ newname[count] = '\0'; return newname; } static void #ifdef __USE_PROTOS ensure_no_C_file_collisions(char *class_c_file) #else ensure_no_C_file_collisions(class_c_file) char *class_c_file; #endif { int i; for (i=0; i= NumFiles && CurFile >= 1 ) CurFile--; fprintf(stderr, ErrHdr, FileStr[CurFile], zzline); fprintf(stderr, " warning: %s\n", err); } void #ifdef __USE_PROTOS warnNoCR( char *err ) #else warnNoCR( err ) char *err; #endif { /* back up the file number if we hit an error at the end of the last file */ if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--; fprintf(stderr, ErrHdr, FileStr[CurFile], zzline); fprintf(stderr, " warning: %s", err); } void #ifdef __USE_PROTOS errNoFL(char *err) #else errNoFL(err) char *err; #endif { fprintf(stderr, "error: %s\n", err); } void #ifdef __USE_PROTOS errFL(char *err,char *f,int l) #else errFL(err,f,l) char *err; char *f; int l; #endif { fprintf(stderr, ErrHdr, f, l); fprintf(stderr, " error: %s\n", err); } void #ifdef __USE_PROTOS err(char *err) #else err(err) char *err; #endif { /* back up the file number if we hit an error at the end of the last file */ if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--; fprintf(stderr, ErrHdr, FileStr[CurFile], zzline); fprintf(stderr, " error: %s\n", err); } void #ifdef __USE_PROTOS errNoCR( char *err ) #else errNoCR( err ) char *err; #endif { /* back up the file number if we hit an error at the end of the last file */ if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--; fprintf(stderr, ErrHdr, FileStr[CurFile], zzline); fprintf(stderr, " error: %s", err); } UserAction * #ifdef __USE_PROTOS newUserAction(char *s) #else newUserAction(s) char *s; #endif { UserAction *ua = (UserAction *) calloc(1, sizeof(UserAction)); require(ua!=NULL, "cannot allocate UserAction"); ua->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char)); strcpy(ua->action, s); return ua; } /* Added by TJP September 1994 */ /* Take in file.h and return file_h; names w/o '.'s are left alone */ char * #ifdef __USE_PROTOS gate_symbol(char *name) #else gate_symbol(name) char *name; #endif { static char buf[100]; char *p; sprintf(buf, "%s", name); for (p=buf; *p!='\0'; p++) { if ( *p=='.' ) *p = '_'; } return buf; } char * #ifdef __USE_PROTOS makeAltID(int blockid, int altnum) #else makeAltID(blockid, altnum) int blockid; int altnum; #endif { static char buf[100]; char *p; sprintf(buf, "_blk%d_alt%d", blockid, altnum); p = (char *)malloc(strlen(buf)+1); strcpy(p, buf); return p; } cccc-3.1.4/pccts/antlr/makefile0000644000000000000000000001245307265347745015074 0ustar rootroot# # 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=cc ANTLR=../bin/antlr DLG=../bin/dlg OBJ_EXT=o OUT_OBJ = -o CFLAGS= -O -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) # # 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 antlr $(OBJ) mv antlr ../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 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 cccc-3.1.4/pccts/antlr/makefile.VMS0000644000000000000000000000233307265347745015534 0ustar rootroot$! File: MAKE.COM - Makefile for ANTLR 1.33 on OpenVMS, DECC $! $! History: $! --------- $! 20-Mar-1992 Fred Scholldorf Hacked together for VAX/VMS. $! 24-Mar-1992 Fred Scholldorf LINK against VAXCRTL sharable library. $! 24-Aug-1993 Fred Scholldorf Upgrade for ANTLR V1.10. $! 27-Jan-1998 J.F. Pieronne Upgrade for ANTLR V1.33, DECC $! $ set noon !Don't stop on errors. $! $ if P1 .eqs. "LINK" then goto relink $! $ define/nolog pccts_h "[-.h]" $ define/nolog support_set "[-.support.set]" $! $ delete/nolog *.obj;* !Get rid of existing .OBJ files. $! $ options = "/INCLUDE=(pccts_h,support_set)/define=(__STDC__,USER_ZZSYN)" $ CC 'options' antlr $ CC 'options' scan $ CC 'options' err $ CC 'options' bits $ CC 'options' build $ CC 'options' fset2 $ CC 'options' fset $ CC 'options' gen $ CC 'options' globals $ CC 'options' hash $ CC 'options' lex $ CC 'options' main $ CC 'options' misc $ CC 'options' pred $ CC 'options' egman $ CC 'options' mrhoist $ CC 'options' fcache $ CC 'options' [-.support.set]set $! $relink: $ LINK antlr,scan,err,bits,build, - fset2,fset,gen,globals,hash, - lex,main,misc,pred,egman,mrhoist,fcache,set, - sys$input:/options ! sys$share:vaxcrtl.exe/share $ EXIT cccc-3.1.4/pccts/antlr/makefile10000644000000000000000000000540007265347750015143 0ustar rootroot# # 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=../bin/antlr DLG=../bin/dlg OBJ_EXT=o OUT_OBJ = -o ANSI=-ansi AOTHER= CFLAGS= -O0 -g -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) $(ANSI) # # 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 ../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 cccc-3.1.4/pccts/antlr/misc.c0000644000000000000000000010757707265347771014506 0ustar rootroot/* * misc.c * * Manage tokens, regular expressions. * Print methods for debugging * Compute follow lists onto tail ends of rules. * * The following functions are visible: * * int addTname(char *); Add token name * int addTexpr(char *); Add token expression * int Tnum(char *); Get number of expr/token * void Tklink(char *, char *); Link a name with an expression * int hasAction(expr); Does expr already have action assigned? * void setHasAction(expr); Indicate that expr now has an action * Entry *newEntry(char *,int); Create new table entry with certain size * void list_add(ListNode **list, char *e) * void list_free(ListNode **list, int freeData); *** MR10 *** * void list_apply(ListNode *list, void (*f)()) * void lexclass(char *m); switch to new/old lexical class * void lexmode(int i); switch to old lexical class i * * 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-1998 */ #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" static int tsize=TSChunk; /* size of token str arrays */ static void #ifdef __USE_PROTOS RemapForcedTokensInSyntaxDiagram(Node *); #else RemapForcedTokensInSyntaxDiagram(); #endif /* T o k e n M a n i p u l a t i o n */ /* * add token 't' to the TokenStr/Expr array. Make more room if necessary. * 't' is either an expression or a token name. * * There is only one TokenStr array, but multiple ExprStr's. Therefore, * for each lex class (element of lclass) we must extend the ExprStr array. * ExprStr's and TokenStr are always all the same size. * * Also, there is a Texpr hash table for each automaton. */ static void #ifdef __USE_PROTOS Ttrack( char *t ) #else Ttrack( t ) char *t; #endif { if ( TokenNum >= tsize ) /* terminal table overflow? */ { char **p; int i, more, j; more = TSChunk * (1 + ((TokenNum-tsize) / TSChunk)); tsize += more; TokenStr = (char **) realloc((char *)TokenStr, tsize*sizeof(char *)); require(TokenStr != NULL, "Ttrack: can't extend TokenStr"); for (i=0; iexpr = e; p->lclass = CurrentLexClass; return p; } /* switch to lexical class/mode m. This amounts to creating a new * lex mode if one does not already exist and making ExprStr point * to the correct char string array. We must also switch Texpr tables. * * BTW, we need multiple ExprStr arrays because more than one automaton * may have the same label for a token, but with different expressions. * We need to track an expr for each automaton. If we disallowed this * feature, only one ExprStr would be required. */ void #ifdef __USE_PROTOS lexclass( char *m ) #else lexclass( m ) char *m; #endif { int i; TermEntry *p; static char EOFSTR[] = "\"@\""; if ( hash_get(Tname, m) != NULL ) { warn(eMsg1("lexclass name conflicts with token/errclass label '%s'",m)); } /* does m already exist? */ i = LexClassIndex(m); if ( i != -1 ) {lexmode(i); return;} /* must make new one */ NumLexClasses++; CurrentLexClass = NumLexClasses-1; require(NumLexClasses<=MaxLexClasses, "number of allowable lexclasses exceeded\nIncrease MaxLexClasses in generic.h and recompile all C files"); lclass[CurrentLexClass].classnum = m; lclass[CurrentLexClass].exprs = (char **) calloc(tsize, sizeof(char *)); require(lclass[CurrentLexClass].exprs!=NULL, "lexclass: cannot allocate ExprStr"); lclass[CurrentLexClass].htable = newHashTable(); ExprStr = lclass[CurrentLexClass].exprs; Texpr = lclass[CurrentLexClass].htable; /* define EOF for each automaton */ p = newTermEntry( EOFSTR ); p->token = EofToken; /* couldn't have remapped tokens yet, use EofToken */ hash_add(Texpr, EOFSTR, (Entry *)p); list_add(&ExprOrder, (void *)newExpr(EOFSTR)); /* note: we use the actual ExprStr array * here as TokenInd doesn't exist yet */ ExprStr[EofToken] = EOFSTR; } void #ifdef __USE_PROTOS lexmode( int i ) #else lexmode( i ) int i; #endif { require(iaction!=NULL); } void #ifdef __USE_PROTOS setHasAction( char *expr, char *action ) #else setHasAction( expr, action ) char *expr; char *action; #endif { TermEntry *p; require(expr!=NULL, "setHasAction: invalid expr"); p = (TermEntry *) hash_get(Texpr, expr); require(p!=NULL, eMsg1("setHasAction: expr '%s' doesn't exist",expr)); p->action = action; } ForcedToken * #ifdef __USE_PROTOS newForcedToken(char *token, int tnum) #else newForcedToken(token, tnum) char *token; int tnum; #endif { ForcedToken *ft = (ForcedToken *) calloc(1, sizeof(ForcedToken)); require(ft!=NULL, "out of memory"); ft->token = token; ft->tnum = tnum; return ft; } /* * Make a token indirection array that remaps token numbers and then walk * the appropriate symbol tables and SynDiag to change token numbers */ void #ifdef __USE_PROTOS RemapForcedTokens(void) #else RemapForcedTokens() #endif { ListNode *p; ForcedToken *q; int max_token_number=0; /* MR9 23-Sep-97 Removed "unsigned" */ int i; if ( ForcedTokens == NULL ) return; /* find max token num */ for (p = ForcedTokens->next; p!=NULL; p=p->next) { q = (ForcedToken *) p->elem; if ( q->tnum > max_token_number ) max_token_number = q->tnum; } fprintf(stderr, "max token number is %d\n", max_token_number); /* make token indirection array */ TokenInd = (int *) calloc(max_token_number+1, sizeof(int)); LastTokenCounted = TokenNum; TokenNum = max_token_number+1; require(TokenInd!=NULL, "RemapForcedTokens: cannot allocate TokenInd"); /* fill token indirection array and change token id htable ; swap token indices */ for (i=1; inext; p!=NULL; p=p->next) { TermEntry *te; int old_pos, t; q = (ForcedToken *) p->elem; fprintf(stderr, "%s forced to %d\n", q->token, q->tnum); te = (TermEntry *) hash_get(Tname, q->token); require(te!=NULL, "RemapForcedTokens: token not in hash table"); old_pos = te->token; fprintf(stderr, "Before: TokenInd[old_pos==%d] is %d\n", old_pos, TokenInd[old_pos]); fprintf(stderr, "Before: TokenInd[target==%d] is %d\n", q->tnum, TokenInd[q->tnum]); q = (ForcedToken *) p->elem; t = TokenInd[old_pos]; TokenInd[old_pos] = q->tnum; TokenInd[q->tnum] = t; te->token = q->tnum; /* update token type id symbol table */ fprintf(stderr, "After: TokenInd[old_pos==%d] is %d\n", old_pos, TokenInd[old_pos]); fprintf(stderr, "After: TokenInd[target==%d] is %d\n", q->tnum, TokenInd[q->tnum]); /* Change the token number in the sym tab entry for the exprs * at the old position of the token id and the target position */ /* update expr at target (if any) of forced token id */ if ( q->tnum < TokenNum ) /* is it a valid position? */ { for (i=0; itnum]!=NULL ) { /* update the symbol table for this expr */ TermEntry *e = (TermEntry *) hash_get(lclass[i].htable, lclass[i].exprs[q->tnum]); require(e!=NULL, "RemapForcedTokens: expr not in hash table"); e->token = old_pos; fprintf(stderr, "found expr '%s' at target %d in lclass[%d]; changed to %d\n", lclass[i].exprs[q->tnum], q->tnum, i, old_pos); } } } /* update expr at old position (if any) of forced token id */ for (i=0; itoken = q->tnum; fprintf(stderr, "found expr '%s' for id %s in lclass[%d]; changed to %d\n", lclass[i].exprs[old_pos], q->token, i, q->tnum); } } } /* Update SynDiag */ RemapForcedTokensInSyntaxDiagram((Node *)SynDiag); } static void #ifdef __USE_PROTOS RemapForcedTokensInSyntaxDiagram(Node *p) #else RemapForcedTokensInSyntaxDiagram(p) Node *p; #endif { Junction *j = (Junction *) p; RuleRefNode *r = (RuleRefNode *) p; TokNode *t = (TokNode *)p; if ( p==NULL ) return; require(p->ntype>=1 && p->ntype<=NumNodeTypes, "Remap...: invalid diagram node"); switch ( p->ntype ) { case nJunction : if ( j->visited ) return; if ( j->jtype == EndRule ) return; j->visited = TRUE; RemapForcedTokensInSyntaxDiagram( j->p1 ); RemapForcedTokensInSyntaxDiagram( j->p2 ); j->visited = FALSE; return; case nRuleRef : RemapForcedTokensInSyntaxDiagram( r->next ); return; case nToken : if ( t->remapped ) return; /* we've been here before */ t->remapped = 1; fprintf(stderr, "remapping %d to %d\n", t->token, TokenInd[t->token]); t->token = TokenInd[t->token]; RemapForcedTokensInSyntaxDiagram( t->next ); return; case nAction : RemapForcedTokensInSyntaxDiagram( ((ActionNode *)p)->next ); return; default : fatal_internal("invalid node type"); } } /* * Add a token name. Return the token number associated with it. If it already * exists, then return the token number assigned to it. * * Track the order in which tokens are found so that the DLG output maintains * that order. It also lets us map token numbers to strings. */ int #ifdef __USE_PROTOS addTname( char *token ) #else addTname( token ) char *token; #endif { TermEntry *p; require(token!=NULL, "addTname: invalid token name"); if ( (p=(TermEntry *)hash_get(Tname, token)) != NULL ) return p->token; p = newTermEntry( token ); Ttrack( p->str ); p->token = TokenNum++; hash_add(Tname, token, (Entry *)p); return p->token; } /* This is the same as addTname except we force the TokenNum to be tnum. * We don't have to use the Forced token stuff as no tokens will have * been defined with #tokens when this is called. This is only called * when a #tokdefs meta-op is used. */ int #ifdef __USE_PROTOS addForcedTname( char *token, int tnum ) #else addForcedTname( token, tnum ) char *token; int tnum; #endif { TermEntry *p; require(token!=NULL, "addTname: invalid token name"); if ( (p=(TermEntry *)hash_get(Tname, token)) != NULL ) return p->token; p = newTermEntry( token ); Ttrack( p->str ); p->token = tnum; hash_add(Tname, token, (Entry *)p); return p->token; } /* * Add a token expr. Return the token number associated with it. If it already * exists, then return the token number assigned to it. */ int #ifdef __USE_PROTOS addTexpr( char *expr ) #else addTexpr( expr ) char *expr; #endif { TermEntry *p; require(expr!=NULL, "addTexpr: invalid regular expression"); if ( (p=(TermEntry *)hash_get(Texpr, expr)) != NULL ) return p->token; p = newTermEntry( expr ); Ttrack( p->str ); /* track the order in which they occur */ list_add(&ExprOrder, (void *)newExpr(p->str)); p->token = TokenNum++; hash_add(Texpr, expr, (Entry *)p); return p->token; } /* return the token number of 'term'. Return 0 if no 'term' exists */ int #ifdef __USE_PROTOS Tnum( char *term ) #else Tnum( term ) char *term; #endif { TermEntry *p; require(term!=NULL, "Tnum: invalid terminal"); if ( *term=='"' ) p = (TermEntry *) hash_get(Texpr, term); else p = (TermEntry *) hash_get(Tname, term); if ( p == NULL ) return 0; else return p->token; } /* associate a Name with an expr. If both have been already assigned * token numbers, then an error is reported. Add the token or expr * that has not been added if no error. This 'represents' the #token * ANTLR pseudo-op. If both have not been defined, define them both * linked to same token number. */ void #ifdef __USE_PROTOS Tklink( char *token, char *expr ) #else Tklink( token, expr ) char *token; char *expr; #endif { TermEntry *p, *q; require(token!=NULL && expr!=NULL, "Tklink: invalid token name and/or expr"); p = (TermEntry *) hash_get(Tname, token); q = (TermEntry *) hash_get(Texpr, expr); if ( p != NULL && q != NULL ) /* both defined */ { warn( eMsg2("token name %s and rexpr %s already defined; ignored", token, expr) ); return; } if ( p==NULL && q==NULL ) /* both not defined */ { int t = addTname( token ); q = newTermEntry( expr ); hash_add(Texpr, expr, (Entry *)q); q->token = t; /* note: we use the actual ExprStr array * here as TokenInd doesn't exist yet */ ExprStr[t] = q->str; /* track the order in which they occur */ list_add(&ExprOrder, (void *)newExpr(q->str)); return; } if ( p != NULL ) /* one is defined, one is not */ { q = newTermEntry( expr ); hash_add(Texpr, expr, (Entry *)q); q->token = p->token; ExprStr[p->token] = q->str; /* both expr and token str defined now */ list_add(&ExprOrder, (void *)newExpr(q->str)); } else /* trying to associate name with expr here*/ { p = newTermEntry( token ); hash_add(Tname, token, (Entry *)p); p->token = q->token; TokenStr[p->token] = p->str;/* both expr and token str defined now */ } } /* * Given a string, this function allocates and returns a pointer to a * hash table record of size 'sz' whose "str" pointer is reset to a position * in the string table. */ Entry * #ifdef __USE_PROTOS newEntry( char *text, int sz ) #else newEntry( text, sz ) char *text; int sz; #endif { Entry *p; require(text!=NULL, "new: NULL terminal"); if ( (p = (Entry *) calloc(1,sz)) == 0 ) { fatal_internal("newEntry: out of memory for terminals\n"); exit(PCCTS_EXIT_FAILURE); } p->str = mystrdup(text); return(p); } /* * add an element to a list. * * Any non-empty list has a sentinel node whose 'elem' pointer is really * a pointer to the last element. (i.e. length(list) = #elemIn(list)+1). * Elements are appended to the list. */ void #ifdef __USE_PROTOS list_add( ListNode **list, void *e ) #else list_add( list, e ) ListNode **list; void *e; #endif { ListNode *p, *tail; require(e!=NULL, "list_add: attempting to add NULL list element"); p = newListNode; require(p!=NULL, "list_add: cannot alloc new list node"); p->elem = e; if ( *list == NULL ) { ListNode *sentinel = newListNode; require(sentinel!=NULL, "list_add: cannot alloc sentinel node"); *list=sentinel; sentinel->next = p; sentinel->elem = (char *)p; /* set tail pointer */ } else /* find end of list */ { tail = (ListNode *) (*list)->elem; /* get tail pointer */ tail->next = p; (*list)->elem = (char *) p; /* reset tail */ } } /* MR10 list_free() frees the ListNode elements in the list */ /* MR10 if freeData then free the data elements of the list too */ void #ifdef __USE_PROTOS list_free(ListNode **list,int freeData) #else list_free(list,freeData) ListNode **list; int freeData; #endif { ListNode *p; ListNode *next; if (list == NULL) return; if (*list == NULL) return; for (p=*list; p != NULL; p=next) { next=p->next; if (freeData && p->elem != NULL) { free( (char *) p->elem); }; free( (char *) p); }; *list=NULL; } void #ifdef __USE_PROTOS list_apply( ListNode *list, void (*f)(void *) ) #else list_apply( list, f ) ListNode *list; void (*f)(); #endif { ListNode *p; require(f!=NULL, "list_apply: NULL function to apply"); if ( list == NULL ) return; for (p = list->next; p!=NULL; p=p->next) (*f)( p->elem ); } /* F O L L O W C y c l e S t u f f */ /* make a key based upon (rulename, computation, k value). * Computation values are 'i'==FIRST, 'o'==FOLLOW. */ /* MR10 Make the key all characters so it can be read easily */ /* MR10 by a simple dump program. Also, separates */ /* MR10 'o' and 'i' from rule name */ char * #ifdef __USE_PROTOS Fkey( char *rule, int computation, int k ) #else Fkey( rule, computation, k ) char *rule; int computation; int k; #endif { static char key[MaxRuleName+2+2+1]; /* MR10 */ int i; if ( k > 99 ) /* MR10 */ fatal("k>99 is too big for this implementation of ANTLR!\n"); /* MR10 */ if ( (i=strlen(rule)) > MaxRuleName ) /* MR10 */ fatal( eMsgd("rule name > max of %d\n", MaxRuleName) ); /* MR10 */ strcpy(key,rule); /* MR10 */ key[i]='*'; /* MR10 */ key[i+1] = (char) computation; /* MR20 G. Hobbelt */ /* MR10 */ if (k < 10) { /* MR10 */ key[i+2] = (char) ( '0' + k); /* MR10 */ key[i+3] = '\0'; /* MR10 */ } else { /* MR10 */ key[i+2] = (char) ( '0' + k/10); /* MR10 */ key[i+3] = (char) ( '0' + k % 10); /* MR10 */ key[i+4] = '\0'; /* MR10 */ }; return key; } /* Push a rule onto the kth FOLLOW stack */ void #ifdef __USE_PROTOS FoPush( char *rule, int k ) #else FoPush( rule, k ) char *rule; int k; #endif { RuleEntry *r; require(rule!=NULL, "FoPush: tried to push NULL rule"); require(k<=CLL_k, "FoPush: tried to access non-existent stack"); /*fprintf(stderr, "FoPush(%s)\n", rule);*/ r = (RuleEntry *) hash_get(Rname, rule); if ( r == NULL ) {fatal_internal( eMsg1("rule %s must be defined but isn't", rule) );} if ( FoStack[k] == NULL ) /* Does the kth stack exist yet? */ { /*fprintf(stderr, "allocating FoStack\n");*/ FoStack[k] = (int *) calloc(FoStackSize, sizeof(int)); require(FoStack[k]!=NULL, "FoPush: cannot allocate FOLLOW stack\n"); } if ( FoTOS[k] == NULL ) { FoTOS[k]=FoStack[k]; *(FoTOS[k]) = r->rulenum; } else { #ifdef MEMCHK require(valid(FoStack[k]), "FoPush: invalid FoStack"); #endif if ( FoTOS[k] >= &(FoStack[k][FoStackSize-1]) ) fatal( eMsgd("exceeded max depth of FOLLOW recursion (%d)\n", FoStackSize) ); require(FoTOS[k]>=FoStack[k], eMsg1("FoPush: FoStack stack-ptr is playing out of its sandbox", rule)); ++(FoTOS[k]); *(FoTOS[k]) = r->rulenum; } { /* **** int *p; **** fprintf(stderr, "FoStack[k=%d]:\n", k); **** for (p=FoStack[k]; p<=FoTOS[k]; p++) **** { **** fprintf(stderr, "\t%s\n", RulePtr[*p]->rname); **** } */ } } /* Pop one rule off of the FOLLOW stack. TOS ptr is NULL if empty. */ void #ifdef __USE_PROTOS FoPop( int k ) #else FoPop( k ) int k; #endif { require(k<=CLL_k, "FoPop: tried to access non-existent stack"); /*fprintf(stderr, "FoPop\n");*/ require(FoTOS[k]>=FoStack[k]&&FoTOS[k]<=&(FoStack[k][FoStackSize-1]), "FoPop: FoStack stack-ptr is playing out of its sandbox"); if ( FoTOS[k] == FoStack[k] ) FoTOS[k] = NULL; else (FoTOS[k])--; } /* Compute FOLLOW cycle. * Mark all FOLLOW sets for rules in cycle as incomplete. * Then, save cycle on the cycle list (Cycles) for later resolution. * The Cycle is stored in the form: * (head of cycle==croot, rest of rules in cycle==cyclicDep) * * e.g. (Fo means "FOLLOW of", "-->" means requires or depends on) * * Fo(x)-->Fo(a)-->Fo(b)-->Fo(c)-->Fo(x) * ^----Infinite recursion (cycle) * * the cycle would be: x -> {a,b,c} or stored as (x,{a,b,c}). Fo(x) depends * on the FOLLOW of a,b, and c. The root of a cycle is always complete after * Fo(x) finishes. Fo(a,b,c) however are not. It turns out that all rules * in a FOLLOW cycle have the same FOLLOW set. */ void #ifdef __USE_PROTOS RegisterCycle( char *rule, int k ) #else RegisterCycle( rule, k ) char *rule; int k; #endif { CacheEntry *f; Cycle *c; int *p; RuleEntry *r; require(rule!=NULL, "RegisterCycle: tried to register NULL rule"); require(k<=CLL_k, "RegisterCycle: tried to access non-existent stack"); /*fprintf(stderr, "RegisterCycle(%s)\n", rule);*/ /* Find cycle start */ r = (RuleEntry *) hash_get(Rname, rule); require(r!=NULL,eMsg1("rule %s must be defined but isn't", rule)); require(FoTOS[k]>=FoStack[k]&&FoTOS[k]<=&(FoStack[k][FoStackSize-1]), eMsg1("RegisterCycle(%s): FoStack stack-ptr is playing out of its sandbox", rule)); /*** if ( FoTOS[k]&(FoStack[k][FoStackSize-1]) ) **** { **** fprintf(stderr, "RegisterCycle(%s): FoStack stack-ptr is playing out of its sandbox\n", **** rule); **** fprintf(stderr, "RegisterCycle: sp==0x%x out of bounds 0x%x...0x%x\n", **** FoTOS[k], FoStack[k], &(FoStack[k][FoStackSize-1])); **** exit(PCCTS_EXIT_FAILURE); **** } ****/ #ifdef MEMCHK require(valid(FoStack[k]), "RegisterCycle: invalid FoStack"); #endif for (p=FoTOS[k]; *p != r->rulenum && p >= FoStack[k]; --p) {;} require(p>=FoStack[k], "RegisterCycle: FoStack is screwed up beyond belief"); if ( p == FoTOS[k] ) return; /* don't worry about cycles to oneself */ /* compute cyclic dependents (rules in cycle except head) */ c = newCycle; require(c!=NULL, "RegisterCycle: couldn't alloc new cycle"); c->cyclicDep = empty; c->croot = *p++; /* record root of cycle */ for (; p<=FoTOS[k]; p++) { /* Mark all dependent rules as incomplete */ f = (CacheEntry *) hash_get(Fcache, Fkey(RulePtr[*p]->rname,'o',k)); if ( f==NULL ) { f = newCacheEntry( Fkey(RulePtr[*p]->rname,'o',k) ); hash_add(Fcache, Fkey(RulePtr[*p]->rname,'o',k), (Entry *)f); } f->incomplete = TRUE; set_orel(*p, &(c->cyclicDep)); /* mark rule as dependent of croot */ } list_add(&(Cycles[k]), (void *)c); } /* make all rules in cycle complete * * while ( some set has changed ) do * for each cycle do * if degree of FOLLOW set for croot > old degree then * update all FOLLOW sets for rules in cyclic dependency * change = TRUE * endif * endfor * endwhile */ void #ifdef __USE_PROTOS ResolveFoCycles( int k ) #else ResolveFoCycles( k ) int k; #endif { ListNode *p, *q; Cycle *c; int changed = 1; CacheEntry *f,*g; int r; /* int i; */ /* MR10 not useful */ unsigned d; unsigned *cursor; /* MR10 */ unsigned *origin; /* MR10 */ /*fprintf(stderr, "Resolving following cycles for %d\n", k);*/ while ( changed ) { changed = 0; /* MR10 i = 0; */ for (p = Cycles[k]->next; p!=NULL; p=p->next) { c = (Cycle *) p->elem; /*fprintf(stderr, "cycle %d: %s -->", i++, RulePtr[c->croot]->rname);*/ /*s_fprT(stderr, c->cyclicDep);*/ /*fprintf(stderr, "\n");*/ f = (CacheEntry *) hash_get(Fcache, Fkey(RulePtr[c->croot]->rname,'o',k)); require(f!=NULL, eMsg1("FOLLOW(%s) must be in cache but isn't", RulePtr[c->croot]->rname) ); if ( (d=set_deg(f->fset)) > c->deg ) { /*fprintf(stderr, "Fo(%s) has changed\n", RulePtr[c->croot]->rname);*/ changed = 1; c->deg = d; /* update cycle FOLLOW set degree */ /* MR10 */ origin=set_pdq(c->cyclicDep); /* MR10 */ for (cursor=origin; *cursor != nil; cursor++) { /* MR10 */ r=*cursor; /******** while ( !set_nil(c->cyclicDep) ) { *****/ /******** r = set_int(c->cyclicDep); *****/ /******** set_rm(r, c->cyclicDep); *****/ /*fprintf(stderr, "updating Fo(%s)\n", RulePtr[r]->rname);*/ g = (CacheEntry *) hash_get(Fcache, Fkey(RulePtr[r]->rname,'o',k)); require(g!=NULL, eMsg1("FOLLOW(%s) must be in cache but isn't", RulePtr[r]->rname) ); set_orin(&(g->fset), f->fset); g->incomplete = FALSE; } /* MR10 */ free( (char *) origin); /* MR10 */ origin=NULL; } } /* MR10 - this if statement appears to be meaningless since i is always 0 */ /* MR10 if ( i == 1 ) changed = 0; */ /* if only 1 cycle, no need to repeat */ } /* kill Cycle list */ for (q = Cycles[k]->next; q != NULL; q=p) { p = q->next; set_free( ((Cycle *)q->elem)->cyclicDep ); free((char *)q); } free( (char *)Cycles[k] ); Cycles[k] = NULL; } /* P r i n t i n g S y n t a x D i a g r a m s */ static void #ifdef __USE_PROTOS pBlk( Junction *q, int btype ) #else pBlk( q, btype ) Junction *q; int btype; #endif { int k,a; Junction *alt, *p; q->end->pvisited = TRUE; if ( btype == aLoopBegin ) { require(q->p2!=NULL, "pBlk: invalid ()* block"); PRINT(q->p1); alt = (Junction *)q->p2; PRINT(alt->p1); if ( PrintAnnotate ) { printf(" /* Opt "); k = 1; while ( !set_nil(alt->fset[k]) ) { s_fprT(stdout, alt->fset[k]); if ( k++ == CLL_k ) break; if ( !set_nil(alt->fset[k]) ) printf(", "); } printf(" */\n"); } return; } for (a=1,alt=q; alt != NULL; alt= (Junction *) alt->p2, a++) { if ( alt->p1 != NULL ) PRINT(alt->p1); if ( PrintAnnotate ) { printf( " /* [%d] ", alt->altnum); k = 1; while ( !set_nil(alt->fset[k]) ) { s_fprT(stdout, alt->fset[k]); if ( k++ == CLL_k ) break; if ( !set_nil(alt->fset[k]) ) printf(", "); } if ( alt->p2 == NULL && btype == aOptBlk ) printf( " (optional branch) */\n"); else printf( " */\n"); } /* ignore implied empty alt of Plus blocks */ if ( alt->p2 != NULL && ((Junction *)alt->p2)->ignore ) break; if ( alt->p2 != NULL && !(((Junction *)alt->p2)->p2==NULL && btype == aOptBlk) ) { if ( pLevel == 1 ) { printf("\n"); if ( a+1==pAlt1 || a+1==pAlt2 ) printf("=>"); printf("\t"); } else printf(" "); printf("|"); if ( pLevel == 1 ) { p = (Junction *) ((Junction *)alt->p2)->p1; while ( p!=NULL ) { if ( p->ntype==nAction ) { p=(Junction *)((ActionNode *)p)->next; continue; } if ( p->ntype!=nJunction ) { break; } if ( p->jtype==EndBlk || p->jtype==EndRule ) { p = NULL; break; } p = (Junction *)p->p1; } if ( p==NULL ) printf("\n\t"); /* Empty alt? */ } } } q->end->pvisited = FALSE; } /* How to print out a junction */ void #ifdef __USE_PROTOS pJunc( Junction *q ) #else pJunc( q ) Junction *q; #endif { int dum_k; int doing_rule; require(q!=NULL, "pJunc: NULL node"); require(q->ntype==nJunction, "pJunc: not junction"); if ( q->pvisited == TRUE ) return; q->pvisited = TRUE; switch ( q->jtype ) { case aSubBlk : if ( PrintAnnotate ) First(q, 1, q->jtype, &dum_k); if ( q->end->p1 != NULL && ((Junction *)q->end->p1)->ntype==nJunction && ((Junction *)q->end->p1)->jtype == EndRule ) doing_rule = 1; else doing_rule = 0; pLevel++; if ( pLevel==1 ) { if ( pAlt1==1 ) printf("=>"); printf("\t"); } else printf(" "); if ( doing_rule ) { if ( pLevel==1 ) printf(" "); pBlk(q,q->jtype); } else { printf("("); if ( pLevel==1 ) printf(" "); pBlk(q,q->jtype); if ( pLevel>1 ) printf(" "); printf(")"); } if ( q->guess ) printf("?"); pLevel--; if ( PrintAnnotate ) freeBlkFsets(q); if ( q->end->p1 != NULL ) PRINT(q->end->p1); break; case aOptBlk : if ( PrintAnnotate ) First(q, 1, q->jtype, &dum_k); pLevel++; if ( pLevel==1 ) { if ( pAlt1==1 ) printf("=>"); printf("\t"); } else printf(" "); printf("{"); if ( pLevel==1 ) printf(" "); pBlk(q,q->jtype); if ( pLevel>1 ) printf(" "); else printf("\n\t"); printf("}"); pLevel--; if ( PrintAnnotate ) freeBlkFsets(q); if ( q->end->p1 != NULL ) PRINT(q->end->p1); break; case aLoopBegin : if ( PrintAnnotate ) First(q, 1, q->jtype, &dum_k); pLevel++; if ( pLevel==1 ) { if ( pAlt1==1 ) printf("=>"); printf("\t"); } else printf(" "); printf("("); if ( pLevel==1 ) printf(" "); pBlk(q,q->jtype); if ( pLevel>1 ) printf(" "); else printf("\n\t"); printf(")*"); pLevel--; if ( PrintAnnotate ) freeBlkFsets(q); if ( q->end->p1 != NULL ) PRINT(q->end->p1); break; case aLoopBlk : if ( PrintAnnotate ) First(q, 1, q->jtype, &dum_k); pBlk(q,q->jtype); if ( PrintAnnotate ) freeBlkFsets(q); break; case aPlusBlk : if ( PrintAnnotate ) First(q, 1, q->jtype, &dum_k); pLevel++; if ( pLevel==1 ) { if ( pAlt1==1 ) printf("=>"); printf("\t"); } else printf(" "); printf("("); if ( pLevel==1 ) printf(" "); pBlk(q,q->jtype); if ( pLevel>1 ) printf(" "); printf(")+"); pLevel--; if ( PrintAnnotate ) freeBlkFsets(q); if ( q->end->p1 != NULL ) PRINT(q->end->p1); break; case EndBlk : break; case RuleBlk : printf( "\n%s :\n", q->rname); PRINT(q->p1); if ( q->p2 != NULL ) PRINT(q->p2); break; case Generic : if ( q->p1 != NULL ) PRINT(q->p1); q->pvisited = FALSE; if ( q->p2 != NULL ) PRINT(q->p2); break; case EndRule : printf( "\n\t;\n"); break; } q->pvisited = FALSE; } /* How to print out a rule reference node */ void #ifdef __USE_PROTOS pRuleRef( RuleRefNode *p ) #else pRuleRef( p ) RuleRefNode *p; #endif { require(p!=NULL, "pRuleRef: NULL node"); require(p->ntype==nRuleRef, "pRuleRef: not rule ref node"); printf( " %s", p->text); PRINT(p->next); } /* How to print out a terminal node */ void #ifdef __USE_PROTOS pToken( TokNode *p ) #else pToken( p ) TokNode *p; #endif { require(p!=NULL, "pToken: NULL node"); require(p->ntype==nToken, "pToken: not token node"); if ( p->wild_card ) printf(" ."); printf( " %s", TerminalString(p->token)); PRINT(p->next); } /* How to print out a terminal node */ void #ifdef __USE_PROTOS pAction( ActionNode *p ) #else pAction( p ) ActionNode *p; #endif { require(p!=NULL, "pAction: NULL node"); require(p->ntype==nAction, "pAction: not action node"); PRINT(p->next); } /* F i l l F o l l o w L i s t s */ /* * Search all rules for all rule reference nodes, q to rule, r. * Add q->next to follow list dangling off of rule r. * i.e. * * r: -o-R-o-->o--> Ptr to node following rule r in another rule * | * o--> Ptr to node following another reference to r. * * This is the data structure employed to avoid FOLLOW set computation. We * simply compute the FIRST (reach) of the EndRule Node which follows the * list found at the end of all rules which are referenced elsewhere. Rules * not invoked by other rules have no follow list (r->end->p1==NULL). * Generally, only start symbols are not invoked by another rule. * * Note that this mechanism also gives a free cross-reference mechanism. * * The entire syntax diagram is layed out like this: * * SynDiag * | * v * o-->R1--o * | * o-->R2--o * | * ... * | * o-->Rn--o * */ void #ifdef __USE_PROTOS FoLink( Node *p ) #else FoLink( p ) Node *p; #endif { RuleEntry *q; Junction *j = (Junction *) p; RuleRefNode *r = (RuleRefNode *) p; if ( p==NULL ) return; require(p->ntype>=1 && p->ntype<=NumNodeTypes, eMsgd("FoLink: invalid diagram node: ntype==%d",p->ntype)); switch ( p->ntype ) { case nJunction : if ( j->fvisited ) return; if ( j->jtype == EndRule ) return; j->fvisited = TRUE; FoLink( j->p1 ); FoLink( j->p2 ); /* MR14 */ /* MR14 */ /* Need to determine whether the guess block is an */ /* MR14 */ /* of the form (alpha)? beta before follow sets are */ /* MR14 */ /* computed. This is necessary to solve problem */ /* MR14 */ /* of doing follow on the alpha of an (alpha)? beta block. */ /* MR14 */ /* MR14 */ /* This is performed by analysis_point as a side-effect. */ /* MR14 */ /* MR14 */ /* MR14 */ if (j->jtype == aSubBlk && j->guess) { /* MR14 */ Junction *ignore; /* MR14 */ ignore=analysis_point(j); /* MR14 */ } /* MR14 */ return; case nRuleRef : if ( r->linked ) return; q = (RuleEntry *) hash_get(Rname, r->text); if ( q == NULL ) { warnFL( eMsg1("rule %s not defined",r->text), FileStr[r->file], r->line ); } else { if ( r->parms!=NULL && RulePtr[q->rulenum]->pdecl==NULL ) { warnFL( eMsg1("rule %s accepts no parameter(s)", r->text), FileStr[r->file], r->line ); } if ( r->parms==NULL && RulePtr[q->rulenum]->pdecl!=NULL ) { warnFL( eMsg1("rule %s requires parameter(s)", r->text), FileStr[r->file], r->line ); } if ( r->assign!=NULL && RulePtr[q->rulenum]->ret==NULL ) { warnFL( eMsg1("rule %s yields no return value(s)", r->text), FileStr[r->file], r->line ); } if ( r->assign==NULL && RulePtr[q->rulenum]->ret!=NULL ) { warnFL( eMsg1("rule %s returns a value(s)", r->text), FileStr[r->file], r->line ); } if ( !r->linked ) { addFoLink( r->next, r->rname, RulePtr[q->rulenum] ); r->linked = TRUE; } } FoLink( r->next ); return; case nToken : FoLink( ((TokNode *)p)->next ); return; case nAction : FoLink( ((ActionNode *)p)->next ); return; default : fatal_internal("invalid node type"); } } /* * Add a reference to the end of a rule. * * 'r' points to the RuleBlk node in a rule. r->end points to the last node * (EndRule jtype) in a rule. * * Initial: * r->end --> o * * After: * r->end --> o-->o--> Ptr to node following rule r in another rule * | * o--> Ptr to node following another reference to r. * * Note that the links are added to the head of the list so that r->end->p1 * always points to the most recently added follow-link. At the end, it should * point to the last reference found in the grammar (starting from the 1st rule). */ void #ifdef __USE_PROTOS addFoLink( Node *p, char *rname, Junction *r ) #else addFoLink( p, rname, r ) Node *p; char *rname; Junction *r; #endif { Junction *j; require(r!=NULL, "addFoLink: incorrect rule graph"); require(r->end!=NULL, "addFoLink: incorrect rule graph"); require(r->end->jtype==EndRule, "addFoLink: incorrect rule graph"); require(p!=NULL, "addFoLink: NULL FOLLOW link"); j = newJunction(); j->rname = rname; /* rname on follow links point to target rule */ j->p1 = p; /* link to other rule */ j->p2 = (Node *) r->end->p1;/* point to head of list */ r->end->p1 = (Node *) j; /* reset head to point to new node */ } void #ifdef __USE_PROTOS GenCrossRef( Junction *p ) #else GenCrossRef( p ) Junction *p; #endif { set a; Junction *j; RuleEntry *q; unsigned e; require(p!=NULL, "GenCrossRef: why are you passing me a null grammar?"); printf("Cross Reference:\n\n"); a = empty; for (; p!=NULL; p = (Junction *)p->p2) { printf("Rule %20s referenced by {", p->rname); /* make a set of rules for uniqueness */ for (j = (Junction *)(p->end)->p1; j!=NULL; j = (Junction *)j->p2) { q = (RuleEntry *) hash_get(Rname, j->rname); require(q!=NULL, "GenCrossRef: FoLinks are screwed up"); set_orel(q->rulenum, &a); } for (; !set_nil(a); set_rm(e, a)) { e = set_int(a); printf(" %s", RulePtr[e]->rname); } printf(" }\n"); } set_free( a ); } cccc-3.1.4/pccts/antlr/mode.h0000644000000000000000000000043407265347771014464 0ustar rootroot#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 cccc-3.1.4/pccts/antlr/mrhoist.c0000644000000000000000000023370607265350065015220 0ustar rootroot/* * mrhoist.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 #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" #include #ifdef __USE_PROTOS void dumppred(Predicate *); #else void dumppred(); #endif /* Try to determine whether predicate "first" is true for all cases where "second" is true. Comparison takes place without regard to context. Assumes that predicate symbols have been expanded. Assumes that there are no NAND or NOR nodes */ #ifdef __USE_PROTOS int MR_secondPredicateUnreachable(Predicate *first,Predicate *second) #else int MR_secondPredicateUnreachable(first,second) Predicate *first; Predicate *second; #endif { Predicate *f; Predicate *s; if (first == NULL) { return 1; } else if (second == NULL) { return 0; } else if (first->down == NULL && second->down == NULL) { if (first->source == second->source && first->inverted == second->inverted) { return 1; /* look identical - will never reach alt2 */ } else { return 0; /* look different */ }; } else if (first->down == NULL && second->down != NULL) { if (second->expr == PRED_AND_LIST) { /* unreachable if first covers any child of second */ for (s=second->down; s != NULL; s=s->right) { if (MR_secondPredicateUnreachable(first,s)) { return 1; }; }; return 0; } else if (second->expr == PRED_OR_LIST) { /* unreachable if first covers every child of second */ for (s=second->down; s != NULL; s=s->right) { if (!MR_secondPredicateUnreachable(first,s)) { return 0; }; }; return 1; } else { require (0,"Illegal pred->expr"); return 0; /* MR20 Make compiler happy */ }; } else if (first->down != NULL && second->down == NULL) { if (first->expr == PRED_AND_LIST) { /* unreachable if every child of first covers second */ for (f=first->down; f != NULL; f=f->right) { if (!MR_secondPredicateUnreachable(f,second)) { return 0; }; }; return 1; } else if (first->expr == PRED_OR_LIST) { /* unreachable if any child of first covers second */ for (f=first->down; f != NULL; f=f->right) { if (MR_secondPredicateUnreachable(f,second)) { return 1; }; }; return 0; } else { require (0,"Illegal predicate->expr"); return 0; /* MR20 Make compiler happy */ }; } else { if (first->expr == PRED_AND_LIST && second->expr == PRED_AND_LIST) { /* unreachable if each child of first covers at least one child of second */ for (f=first->down; f != NULL ; f=f->right) { for (s=second->down; s != NULL ; s=s->right) { if (MR_secondPredicateUnreachable(f,s)) goto A_next_f; }; return 0; A_next_f: continue; }; return 1; } else if (first->expr == PRED_AND_LIST && second->expr == PRED_OR_LIST) { /* unreachable if each child of first covers ALL of second's children */ for (f=first->down; f != NULL ; f=f->right) { for (s=second->down; s != NULL ; s=s->right) { if (!MR_secondPredicateUnreachable(f,s)) return 0; }; }; return 1; } else if (first->expr == PRED_OR_LIST && second->expr == PRED_AND_LIST) { /* unreachable if any child of second is covered by any child of first */ for (f=first->down; f != NULL ; f=f->right) { for (s=second->down; s != NULL ; s=s->right) { if (MR_secondPredicateUnreachable(f,s)) return 1; }; }; return 0; } else if (first->expr == PRED_OR_LIST && second->expr == PRED_OR_LIST) { /* unreachable if every child of second is covered by some child of first */ for (f=first->down; f != NULL ; f=f->right) { for (s=second->down; s != NULL ; s=s->right) { if (MR_secondPredicateUnreachable(f,s)) goto B_next_f; }; return 0; B_next_f: continue; }; return 1; } else { require (0,"Illegal predicate->expr"); return 0; /* MR20 Make compiler happy */ }; }; return 0; /* MR20 MSVC 5.0 complains about missing return statement */ } #ifdef __USE_PROTOS void MR_xxxIndent(FILE *f,int depth) #else void MR_xxxIndent(f,depth) FILE *f; int depth; #endif { int i; for (i=0; irname,rrn->line,FileStr[rrn->file],rrn->text); }; lastOne=MR_ruleReferenced(rrn); if (lastOne != NULL) { for (j=0; jrname,lastOne->line,FileStr[lastOne->file]); }; } #ifdef __USE_PROTOS void MR_dumpTreeF(FILE *f,int depth,Tree *tree,int across) #else void MR_dumpTreeF(f,depth,tree,across) FILE *f; Tree *tree; int depth; int across; #endif { int newAcross=across; if (tree == NULL ) return; if (tree->down != NULL ) { fprintf(output,"\n"); MR_outputIndent(depth); fprintf(output, "(root ="); }; if (tree->token == ALT ) { fprintf(output," %-16s","Alt"); } else if (tree->token==EpToken ) { fprintf(output,"(%d)%13s",tree->v.rk," "); } else { fprintf(output," %-16s",TerminalString(tree->token)); }; if (tree->down != NULL) { fprintf(output,"\n"); MR_outputIndent(depth+1); MR_dumpTreeF(f,depth+1,tree->down,1); newAcross=0; fprintf(output,"\n"); MR_outputIndent(depth); fprintf(output,")"); }; if (newAcross > 3) { fprintf(output,"\n"); MR_outputIndent(depth); newAcross=0; }; MR_dumpTreeF(f,depth,tree->right,newAcross+1); } #ifdef __USE_PROTOS void MR_dumpTreeX(int depth,Tree *tree,int across) #else void MR_dumpTreeX(depth,tree,across) Tree *tree; int depth; int across; #endif { MR_dumpTreeF(output,depth,tree,across); } #ifdef __USE_PROTOS void MR_dumpTokenSet(FILE *f,int depth,set s) #else void MR_dumpTokenSet(f,depth,s) FILE *f; int depth; set s; #endif { int i; int j; unsigned *pdq; if (set_nil(s)) { fprintf(f,"\n"); MR_xxxIndent(f,depth+1); fprintf(f,"nil\n"); return; }; pdq=set_pdq(s); require(pdq != NULL,"set_pdq failed"); i=0; for (i=0 ; ; i=i+4) { fprintf(f,"\n"); MR_xxxIndent(f,depth+1); for (j=0; j < 4 ; j++) { if (pdq[i+j] == nil) break; fprintf(f," %-16s",TerminalString(pdq[i+j])); }; if (pdq[i+j] == nil) break; }; fprintf(f,"\n"); free( (char *) pdq); } #ifdef __USE_PROTOS void MR_dumpPred1(int depth,Predicate *p,int withContext) #else void MR_dumpPred1(depth,p,withContext) int depth; Predicate *p; int withContext; #endif { unsigned k; if (p == NULL) { MR_outputIndent(depth); fprintf(output,"The predicate is empty (or always true)\n\n"); return; }; if (p->down != NULL) { MR_outputIndent(depth); if (p->inverted) { /* MR14a Left out print expression in fprintf Reported by Manuel Kessler (mlkessle@cip.physik.uni-wuerzburg.de) */ if (p->expr == PRED_AND_LIST) fprintf(output,"%s NAND (not AND) expr\n\n",p->expr); if (p->expr == PRED_OR_LIST) fprintf(output,"%s NOR (not OR) expr\n\n",p->expr); } else { fprintf(output,"%s expr\n\n",p->expr); }; } else { MR_outputIndent(depth); fprintf(output,"pred %s <<%s>>?\n", (p->inverted ? " *not*" : ""), (p->expr == NULL ? "null expr" : p->expr)); MR_outputIndent(depth+1); fprintf(output," "); fprintf(output," depth=k=%d",p->k); if (p->source != NULL && p->source->guardpred) { fprintf(output," (\"=>\" guard)"); } if (p->source != NULL && p->source->ampersandPred != NULL) { fprintf(output," (\"&&\" guard)"); }; k=set_int(p->completionSet); if (k != nil) { fprintf(output," Incomplete Set at k=%d !",k); }; k=set_int(p->completionTree); if (k != nil) { fprintf(output," Incomplete Tree at k=%d !",k); }; if (p->source != NULL) { fprintf(output," rule %s line %d %s", p->source->rname,p->source->line,FileStr[p->source->file]); }; fprintf(output,"\n"); if (withContext && (HoistPredicateContext || ! set_nil(p->scontext[1]) || p->tcontext != NULL)) { if (p->k == 1) { MR_outputIndent(depth+1); fprintf(output,"set context: "); MR_dumpTokenSet(output,depth+1,p->scontext[1]); } if (p->k != 1) { MR_outputIndent(depth+1); fprintf(output,"tree context:"); if (p->tcontext == NULL) { fprintf(output," null"); } else { MR_dumpTreeX(depth+2,p->tcontext,0); }; fprintf(output,"\n"); }; }; fprintf(output,"\n"); }; if (p->down != NULL) { MR_dumpPred1(depth+1,p->down,withContext); }; if (p->right != NULL) { MR_dumpPred1(depth,p->right,withContext); }; } #ifdef __USE_PROTOS void MR_dumpPred(Predicate *p,int withContext) #else void MR_dumpPred(p,withContext) Predicate *p; int withContext; #endif { MR_dumpPred1(0,p,withContext); } #ifdef __USE_PROTOS Tree * MR_make_tree_from_set(set s) #else Tree * MR_make_tree_from_set(s) set s; #endif { Tree *t=NULL; Tree *node; Tree **tp=&t; int i; unsigned *pdq=set_pdq(s); if (pdq != NULL) { for (i=0 ; pdq[i] != nil ; i++) { node=tnode( (int) pdq[i]); *tp=node; tp=&(node->right); }; *tp=NULL; free ( (char *) pdq); }; return t; } #ifdef __USE_PROTOS void MR_check_pred_too_long(Predicate *p,set completion) #else void MR_check_pred_too_long(p,completion) Predicate *p; set completion; #endif { if (p != NULL && p->source != NULL && ! p->source->predTooLong) { if ( !set_nil(completion)) { p->source->predTooLong=1; warnFL("It is unusual (but ok) for a semantic predicate to test context past the end of its own rule", FileStr[p->source->file],p->source->line); }; }; } #ifdef __USE_PROTOS int MR_predicate_context_completed(Predicate *p) #else int MR_predicate_context_completed(p) Predicate *p; #endif { if (p == NULL) return 1; if (p->expr != PRED_AND_LIST && p->expr != PRED_OR_LIST) { if ( ! set_nil(p->completionSet)) return 0; if ( ! set_nil(p->completionTree)) return 0; }; return MR_predicate_context_completed(p->down) & MR_predicate_context_completed(p->right); } #ifdef __USE_PROTOS Node * MR_advance(Node *n) #else Node * MR_advance(n) Node *n; #endif { if (n == NULL) return NULL; switch (n->ntype) { case nJunction: return ((Junction *)n)->p1; case nToken: return ((TokNode *)n)->next; case nRuleRef: return ((RuleRefNode *)n)->next; case nAction: return ((ActionNode *)n)->next; default: return NULL; }; return NULL; /* MSVC 5.0 complains about missing return statement */ } #ifdef __USE_PROTOS Junction * MR_find_endRule(Node *n) #else Junction * MR_find_endRule(n) Node *n; #endif { Node *next; if (n == NULL) return NULL; for (next=n; next != NULL; next=MR_advance(next)) { if (next->ntype == nJunction && ( (Junction *) next)->jtype == EndRule) { break; }; }; return (Junction *)next; } /* Intersection: a branch which is shorter is chosen over one which is longer: (A B C) intersect (A B) yields (A B). AND: a branch which is longer is chosen over the one which is shorter: (A B C) AND (A B) yields (A B C) */ #ifdef __USE_PROTOS Tree *MR_computeTreeIntersection(Tree *l,Tree *r) #else Tree *MR_computeTreeIntersection(l,r) Tree *l; Tree *r; #endif { Tree *result=NULL; Tree **tail; Tree *p; Tree *q; Tree *match; if (l == NULL || r == NULL) return NULL; for (p=l; p != NULL; p=p->right) { require(p->token != EpToken,"MR_computeTreeIntersection: p->EpToken unexpected\n"); require (p->token != ALT,"MR_computeTreeIntersection: p->ALT unexpected\n"); }; for (q=r; q != NULL; q=q->right) { require(q->token != EpToken,"MR_computeTreeIntersection: q->EpToken unexpected\n"); require(q->token != ALT,"MR_computeTreeIntersection: q->ALT unexpected\n"); }; result=tnode(ALT); tail=&(result->down); for (p=l; p != NULL ; p=p->right) { for (q=r; q != NULL ; q=q->right) { if (p->token == q->token) { match=tnode(p->token); match->down=MR_computeTreeIntersection(p->down,q->down); *tail=match; tail=&(match->right); }; }; }; *tail=NULL; result=tshrink(result); result=tflatten( result ); result=tleft_factor( result ); return result; } /* the predicates which are ANDed together have a common context: they must all have common roots. Thus the AND operation is more like an OR operation because branches which are longer are grafted onto shorter branches of the AND tree. For instance combining (A B C) with (A B C D) gives (A B C D). There should never be a case of (A B C) and (A B D) because they have the same context. Actually, this may not be true once one throws in guard predicates which are defined by the user, not the context. */ /* requires input trees to be in "canonical" format */ #ifdef __USE_PROTOS Tree *MR_computeTreeAND(Tree *l,Tree *r) #else Tree *MR_computeTreeAND(l,r) Tree *l; Tree *r; #endif { Tree *result=NULL; Tree **tail; Tree *p; Tree *q; Tree *match; if (l == NULL) return tdup(r); if (r == NULL) return tdup(l); for (p=l; p != NULL; p=p->right) { /**** require(p->token != EpToken,"MR_computeTreeAND: p->EpToken unexpected\n"); ****/ require (p->token != ALT,"MR_computeTreeAND: p->ALT unexpected\n"); }; for (q=r; q != NULL; q=q->right) { /**** require(q->token != EpToken,"MR_computeTreeAND: q->EpToken unexpected\n"); ****/ require(q->token != ALT,"MR_computeTreeAND: q->ALT unexpected\n"); }; result=tnode(ALT); tail=&(result->down); for (p=l; p != NULL ; p=p->right) { for (q=r; q != NULL ; q=q->right) { if (p->token == q->token) { match=tnode(p->token); match->down=MR_computeTreeAND(p->down,q->down); *tail=match; tail=&(match->right); }; }; }; *tail=NULL; result=tshrink(result); result=tflatten( result ); result=tleft_factor( result ); return result; } #ifdef __USE_PROTOS void MR_union_plain_sets1(Predicate *p,set *theUnion) #else void MR_union_plain_sets1(p,theUnion) Predicate *p; set *theUnion; #endif { if (p == NULL) return; MR_union_plain_sets1(p->down,theUnion); MR_union_plain_sets1(p->right,theUnion); set_orin(theUnion,p->plainSet); return; } #ifdef __USE_PROTOS set MR_union_plain_sets(Predicate *p) #else set MR_union_plain_sets(p) Predicate *p; #endif { set theUnion; theUnion=empty; MR_union_plain_sets1(p,&theUnion); return theUnion; } /* does NOT left factor: do not want to merge (A B) with (A) to get (A B) in fact the opposite: (A B) with (A) gives (A) */ #ifdef __USE_PROTOS Tree *MR_compute_pred_tree_ctxXX(Predicate *p) #else Tree *MR_compute_pred_tree_ctxXX(p) Predicate *p; #endif { Tree *result=NULL; Predicate *q; Tree *t; if (p == NULL) return NULL; /* this appears strange: why do we OR the context of and AND predicate ? It is because of the way that predicates are evaluated: if the context is wrong then it's the same as if the predicate was true. That means that even when one leg of an AND has unmatched context, if the other leg has matched context and is true then the predicate succeeds. It's only when all the legs have unmatched context that this one can skip evaluation of the predicates. */ if (p->expr == PRED_OR_LIST || p->expr == PRED_AND_LIST) { for (q=p->down; q != NULL ; q=q->right) { t=MR_compute_pred_tree_ctxXX(q); result=tappend(result,t); t=NULL; }; result=tshrink(result); result=tflatten( result ); /* does NOT left factor: do not want to merge (A B) with (A) to get (A B) in fact the opposite: (A B) with (A) gives (A) */ /**** result=tleft_factor( result ); ****/ return result; }; #if 0 ** if (p->expr == PRED_AND_LIST) { ** ** Predicate *l; ** Predicate *r; ** Tree *l1; ** Tree *r1; ** Tree *prevl1; ** ** l=p->down; ** require (l->right != NULL,"MR_compute_pred_tree - AND has only one child"); ** **/* l1 and r1 should already be in "canonical" format */ ** ** l1=MR_compute_pred_tree(l); ** for (r=l->right; r != NULL; r=r->right) { ** r1=MR_compute_pred_tree(r); ** prevl1=l1; ** l1=MR_computeTreeAND(l1,r1); ** Tfree(r1); ** Tfree(prevl1); ** }; ** **/* result from computeTreeAND should be in "canonical" format */ ** ** result=l1; ** **/* result of MR_computeTreeAND should be in "canonical" format */ ** ** return result; ** }; #endif if (p->k == 1) { result=MR_make_tree_from_set(p->scontext[1]); } else { result=tdup(p->tcontext); result=MR_remove_epsilon_from_tree(result); result=tshrink(result); result=tflatten(result); result=tleft_factor(result); }; return result; } #ifdef __USE_PROTOS void MR_pred_depth(Predicate *p,int *maxDepth) #else void MR_pred_depth(p,maxDepth) Predicate *p; int *maxDepth; #endif { if (p == NULL) return; if (p->expr != PRED_OR_LIST && p->expr != PRED_AND_LIST) { if (p->k > *maxDepth) *maxDepth=p->k; }; MR_pred_depth(p->down,maxDepth); MR_pred_depth(p->right,maxDepth); } /* this computes the OR of all the contexts */ #ifdef __USE_PROTOS set MR_compute_pred_set(Predicate *p) #else set MR_compute_pred_set(p) Predicate *p; #endif { set result; Predicate *q; result=empty; if (p == NULL) return empty; if (p->expr == PRED_OR_LIST || p->expr == PRED_AND_LIST) { /* yes, I do mean PRED_AND_LIST ! */ /* remember: r1: (A)? => <

    >? r2; */ /* r2: (B)? => <>? r3; */ set t; t=empty; result=empty; for (q=p->down; q != NULL; q=q->right) { t=MR_compute_pred_set(q); set_orin(&result,t); set_free(t); }; return result; } else if (p->k > 1) { return empty; } else { return set_dup(p->scontext[1]); }; } #ifdef __USE_PROTOS set MR_First(int ck,Junction *j,set *incomplete) #else set MR_First(ck,j,incomplete) int ck; Junction *j; set *incomplete; #endif { Junction *p; set tokensUsed; tokensUsed=empty; require(j->ntype==nJunction, "MR_First: non junction passed"); p = analysis_point((Junction *)j->p1); REACH(p,ck,incomplete,tokensUsed); return tokensUsed; } #ifdef __USE_PROTOS void MR_cleanup_pred_trees(Predicate *p) #else void MR_cleanup_pred_trees(p) Predicate *p; #endif { Tree *t; if (p == NULL) return; if (p->expr != PRED_OR_LIST && p->expr != PRED_AND_LIST) { t=p->tcontext; t=tshrink(t); t=tflatten(t); t=tleft_factor(t); p->tcontext=t; }; MR_cleanup_pred_trees(p->down); MR_cleanup_pred_trees(p->right); } /* does NOT return canonical tree */ #ifdef __USE_PROTOS Tree * MR_remove_epsilon_from_tree(Tree *t) #else Tree * MR_remove_epsilon_from_tree(t) Tree *t; #endif { if (t == NULL) return NULL; /* I think ALT can be ignored as a special case */ if (t->token != EpToken) { t->down=MR_remove_epsilon_from_tree(t->down); t->right=MR_remove_epsilon_from_tree(t->right); return t; } else { Tree *u; u=MR_remove_epsilon_from_tree(t->right); t->right=NULL; Tfree(t); return u; }; } #ifdef __USE_PROTOS void MR_complete_set(int predDepth,set *tokensUsed,set *incomplete) #else void MR_complete_set(predDepth,tokensUsed,incomplete) int predDepth; set *tokensUsed; set *incomplete; #endif { int i; RuleRefNode *ruleRef; set rk2; set b; int k2; Junction *save_MR_RuleBlkWithHalt; if (set_int(*incomplete) > (unsigned) predDepth) { return; }; require(MR_PredRuleRefStack.count == MR_RuleBlkWithHaltStack.count, "RuleRefStack and RuleBlkWithHaltStack not same size"); require(MR_RuleBlkWithHalt == NULL || (MR_RuleBlkWithHalt->jtype == RuleBlk && MR_RuleBlkWithHalt->end->halt == TRUE), "RuleBlkWithHalt has no halt set"); save_MR_RuleBlkWithHalt=MR_RuleBlkWithHalt; if (MR_RuleBlkWithHalt != NULL) { MR_RuleBlkWithHalt->end->halt=FALSE; }; for (i=MR_PredRuleRefStack.count-1; i >= 0 ; i--) { ruleRef=(RuleRefNode *)MR_PredRuleRefStack.data[i]; if (ruleRef == NULL) continue; MR_RuleBlkWithHalt=(Junction *)MR_RuleBlkWithHaltStack.data[i]; if (MR_RuleBlkWithHalt != NULL) MR_RuleBlkWithHalt->end->halt=TRUE; rk2=empty; b=empty; while ( !set_nil(*incomplete) ) { k2=set_int(*incomplete); if (k2 > predDepth) break; /* <=== another exit from loop */ set_rm(k2,*incomplete); REACH(ruleRef->next,k2,&rk2,b); set_orin(tokensUsed,b); set_free(b); }; if (MR_RuleBlkWithHalt != NULL) MR_RuleBlkWithHalt->end->halt=FALSE; set_orin(incomplete,rk2); /* remember what we couldn't do */ set_free(rk2); if (set_int(*incomplete) > (unsigned) predDepth) break; /* <=== another exit from loop */ }; MR_RuleBlkWithHalt=save_MR_RuleBlkWithHalt; if (MR_RuleBlkWithHalt != NULL) { MR_RuleBlkWithHalt->end->halt=TRUE; }; } #ifdef __USE_PROTOS void MR_complete_tree(int predDepth,Tree **t,set *incomplete) #else void MR_complete_tree(predDepth,t,incomplete) int predDepth; Tree **t; set *incomplete; #endif { int i; RuleRefNode *ruleRef; set rk2; Tree *u; unsigned k2; Junction *save_MR_RuleBlkWithHalt; int saveConstrainSearch; if (set_int(*incomplete) > (unsigned) predDepth) { return; }; require(MR_PredRuleRefStack.count == MR_RuleBlkWithHaltStack.count, "RuleRefStack and RuleBlkWithHaltStack not same size"); require(MR_RuleBlkWithHalt == NULL || (MR_RuleBlkWithHalt->jtype == RuleBlk && MR_RuleBlkWithHalt->end->halt == TRUE), "RuleBlkWithHalt has no halt set"); save_MR_RuleBlkWithHalt=MR_RuleBlkWithHalt; saveConstrainSearch=ConstrainSearch; ConstrainSearch=0; if (MR_RuleBlkWithHalt != NULL) { MR_RuleBlkWithHalt->end->halt=FALSE; }; for (i=MR_PredRuleRefStack.count-1; i >= 0 ; i--) { ruleRef=(RuleRefNode *)MR_PredRuleRefStack.data[i]; if (ruleRef == NULL) continue; MR_RuleBlkWithHalt=(Junction *)MR_RuleBlkWithHaltStack.data[i]; if (MR_RuleBlkWithHalt != NULL) MR_RuleBlkWithHalt->end->halt=TRUE; rk2=empty; while ( !set_nil(*incomplete) ) { k2 = set_int(*incomplete); if (k2 > (unsigned) predDepth) break; /* <=== another exit from loop */ set_rm(k2,*incomplete); u = NULL; TRAV(ruleRef->next,k2,&rk2,u); /* any subtrees missing k2 tokens, add u onto end */ *t=tlink(*t,u,k2); Tfree(u); } set_orin(incomplete,rk2); /* remember what we couldn't do */ set_free(rk2); if (MR_RuleBlkWithHalt != NULL) MR_RuleBlkWithHalt->end->halt=FALSE; if (set_int(*incomplete) > (unsigned) predDepth) break; /* <=== another exit from loop */ }; MR_RuleBlkWithHalt=save_MR_RuleBlkWithHalt; if (MR_RuleBlkWithHalt != NULL) { MR_RuleBlkWithHalt->end->halt=TRUE; }; ConstrainSearch=saveConstrainSearch; } #ifdef __USE_PROTOS void MR_complete_predicates(int predDepth,Predicate *pred) #else void MR_complete_predicates(predDepth,pred) int predDepth; Predicate *pred; #endif { if (pred == NULL) return; if (pred->expr != PRED_AND_LIST && pred->expr != PRED_OR_LIST) { MR_complete_set(predDepth,&(pred->scontext[1]),&(pred->completionSet)); MR_complete_tree(predDepth,&(pred->tcontext),&(pred->completionTree)); }; MR_complete_predicates(predDepth,pred->down); MR_complete_predicates(predDepth,pred->right); } #ifdef __USE_PROTOS Junction * MR_junctionWithoutP2(Junction *j) #else Junction * MR_junctionWithoutP2(j) Junction *j; #endif { Junction *thisAlt; /* don't want to follow p2 to the next alternative of this rule */ /* insert a generic node with null p2 if necessary */ /* however FIRST requires a junction */ thisAlt=j; if (thisAlt->p2 != NULL) { if (thisAlt->p1->ntype == nJunction) { thisAlt=(Junction *) thisAlt->p1; } else { thisAlt=newJunction(); thisAlt->p1=j->p1; thisAlt->rname=j->rname; thisAlt->file=j->file; thisAlt->line=j->line; j->p1=(Node *)thisAlt; }; }; return thisAlt; } #ifdef __USE_PROTOS int MR_tree_equ(Tree *big, Tree *small) { #else int MR_tree_equ(big,small) Tree *big; Tree *small; { #endif Tree *b; Tree *s; int bcount=0; int scount=0; if (small == NULL && big == NULL) return 1; if (small == NULL) return 0; if (big == NULL) return 0; if (small->token == ALT) { require(small->right == NULL, "MR_tree_equ: small: ALT node has siblings"); return MR_tree_equ(big,small->down); }; if (big->token == ALT) { require(big->right == NULL, "MR_tree_equ: big: ALT node has siblings"); return MR_tree_equ(big->down,small); }; for (s=small; s != NULL; s=s->right) { scount++; require(s->token != EpToken,"MR_tree_equ: s->EpToken unexpected\n"); }; for (b=big; b != NULL; b=b->right) { bcount++; require(b->token != EpToken,"MR_tree_equ: b->EpToken unexpected\n"); }; if (bcount != scount) return 0; for (s=small; s != NULL; s=s->right) { for (b=big; b!= NULL; b=b->right) { if (s->token == b->token) { if (MR_tree_equ(b->down,s->down)) goto next_s; }; }; return 0; next_s: continue; }; return 1; } /* this does not compare sources - only contexts ! */ #ifdef __USE_PROTOS int MR_identicalContext(Predicate *p,Predicate *q) #else int MR_identicalContext(p,q) Predicate *p; Predicate *q; #endif { if (p->k != q->k) return 0; require ( (p->tcontext == NULL) == (q->tcontext == NULL), "tcontext inconsistent"); if (p->k == 1) { return set_equ(p->scontext[1],q->scontext[1]); } else { return MR_tree_equ(p->tcontext,q->tcontext); }; } #ifdef __USE_PROTOS void MR_reportSetSuppression(int predDepth, set predSet,set plainSet,Junction *jPred,Junction *jPlain,Predicate *p) #else void MR_reportSetSuppression(predDepth,predSet,plainSet,jPred,jPlain,p) int predDepth; set predSet; set plainSet; Junction *jPred; Junction *jPlain; Predicate *p; #endif { if (InfoP) { fprintf(output,"\n#if 0\n\n"); fprintf(output,"Hoisting of predicate suppressed by alternative without predicate.\n"); fprintf(output,"The alt without the predicate includes all cases where the predicate is false.\n\n"); fprintf(output," WITH predicate: line %d %s\n",jPred->line,FileStr[jPred->file]); if (jPlain != NULL) { fprintf(output," WITHOUT predicate: line %d %s\n",jPlain->line,FileStr[jPlain->file]); } else { fprintf(output," WITHOUT predicate: all alternatives without predicates (combined)\n"); }; if (predDepth == 1) { fprintf(output,"\nThe context set for the predicate:\n"); MR_dumpTokenSet(output,1,predSet); }; fprintf(output,"\nThe lookahead set for the alt WITHOUT the semantic predicate:\n"); MR_dumpTokenSet(output,1,plainSet); fprintf(output,"\nThe predicate:\n\n"); MR_dumpPred1(1,p,1); fprintf(output,"Chain of referenced rules:\n\n"); MR_dumpPredRuleRefStack(output,4); fprintf(output,"\n#endif\n"); }; } #ifdef __USE_PROTOS void MR_reportSetRestriction(int predDepth,set predSet,set plainSet, Junction *jPred,Junction *jPlain,Predicate *origPred,Predicate *newPred) #else void MR_reportSetRestriction(predDepth,predSet,plainSet,jPred,jPlain,origPred,newPred) int predDepth; set predSet; set plainSet; Junction *jPred; Junction *jPlain; Predicate *origPred; Predicate *newPred; #endif { set intersect; intersect=empty; if (! InfoP) return; fprintf(output,"\n#if 0\n\n"); fprintf(output,"Restricting the context of a predicate because of overlap in the lookahead set\n"); fprintf(output," between the alternative with the semantic predicate and one without\n"); fprintf(output,"Without this restriction the alternative without the predicate could not\n"); fprintf(output," be reached when input matched the context of the predicate and the predicate\n"); fprintf(output," was false.\n\n"); fprintf(output," WITH predicate: line %d %s\n",jPred->line,FileStr[jPred->file]); if (jPlain != NULL) { fprintf(output," WITHOUT predicate: line %d %s\n",jPlain->line,FileStr[jPlain->file]); } else { fprintf(output," WITHOUT predicate: all alternatives without predicates (combined)\n"); }; if (predDepth == 1) { fprintf(output,"\nThe original context set for the predicate:\n"); MR_dumpTokenSet(output,1,predSet); }; fprintf(output,"\nThe lookahead set for the alt WITHOUT the semantic predicate:\n"); MR_dumpTokenSet(output,1,plainSet); if (predDepth == 1) { fprintf(output,"\nThe intersection of the two sets\n"); intersect=set_and(predSet,plainSet); MR_dumpTokenSet(output,1,intersect); set_free(intersect); }; fprintf(output,"\nThe original predicate:\n\n"); MR_dumpPred1(1,origPred,1); fprintf(output,"The new (modified) form of the predicate:\n\n"); MR_dumpPred1(1,newPred,1); fprintf(output,"#endif\n"); } /* don't use Pass3 by itself unless you know that inverted is not important */ #ifdef __USE_PROTOS Predicate * MR_removeRedundantPredPass3(Predicate *p) #else Predicate * MR_removeRedundantPredPass3(p) Predicate *p; #endif { Predicate *q; if (p == NULL) return NULL; p->right=MR_removeRedundantPredPass3(p->right); p->down=MR_removeRedundantPredPass3(p->down); if (p->redundant) { q=p->right; p->right=NULL; predicate_free(p); return q; }; if (p->expr == PRED_AND_LIST || p->expr == PRED_OR_LIST) { if (p->down == NULL) { q=p->right; p->right=NULL; predicate_free(p); return q; }; if (p->down != NULL && p->down->right == NULL) { q=p->down; q->right=p->right; p->right=NULL; p->down=NULL; return q; }; }; return p; } #ifdef __USE_PROTOS void MR_removeRedundantPredPass2(Predicate *p) #else void MR_removeRedundantPredPass2(p) Predicate *p; #endif { Predicate *q; if (p == NULL) return; if (p->expr == PRED_AND_LIST) { for (q=p->down ; q != NULL ; q=q->right) { MR_removeRedundantPredPass2(q); if (q->isConst) { if (q->constValue == 0) { p->isConst=1; p->constValue=0; return; } else { q->redundant=1; }; }; }; }; if (p->expr == PRED_OR_LIST) { for (q=p->down ; q != NULL ; q=q->right) { MR_removeRedundantPredPass2(q); if (q->isConst) { if (q->constValue == 0) { q->redundant=1; } else { p->isConst=1; p->constValue=1; return; }; }; }; }; return; } #if 0 this totally ignores the implications of guarded predicates in which the part after the guard could possibly cover a predicate. that would be much harder: rule : (A)? => <

    >? sub1; /* 1 */ | (B)? => <>? sub2 /* 2 */ sub1 : (A)? => <>? A B /* 3 */ | B /* 4 - suppresses line 2 */ ; #endif #ifdef __USE_PROTOS void MR_apply_restriction1(Predicate *pred,set *plainSet,int *changed) #else void MR_apply_restriction1(pred,plainSet,changed) Predicate *pred; set *plainSet; int *changed; #endif { if (pred == NULL) return; MR_apply_restriction1(pred->right,plainSet,changed); if (pred->down != NULL) { MR_apply_restriction1(pred->down,plainSet,changed); } else { set t; if (pred->k == 1) { t=set_dif(pred->scontext[1],*plainSet); if (*changed == 0 && !set_equ(t,pred->scontext[1])) { *changed=1; }; if (set_nil(t)) { pred->redundant=1; }; set_free(pred->scontext[1]); pred->scontext[1]=t; }; }; } #ifdef __USE_PROTOS void MR_orin_plainSet(Predicate *p,set plainSet) #else void MR_orin_plainSet(p,plainSet) Predicate *p; set plainSet; #endif { if (p == NULL) return; MR_orin_plainSet(p->down,plainSet); MR_orin_plainSet(p->right,plainSet); set_orin(&p->plainSet,plainSet); } Predicate *PRED_SUPPRESS; #ifdef __USE_PROTOS Predicate * MR_find_in_aSubBlk(Junction *alt) #else Predicate * MR_find_in_aSubBlk(alt) Junction *alt; #endif { Predicate *root=NULL; Predicate **tail=NULL; Junction *p; int nAlts=0; Junction **jList; Predicate **predList; int *matchList; set predSet; int i; int j; int m; int predDepth; set incomplete; set union_plainSet; set setChange; int changed; Predicate *newPred; set setDif; Predicate *origPred; int depth1=1; /* const int */ set *plainContext; set plainSet; predSet=empty; incomplete=empty; union_plainSet=empty; setChange=empty; setDif=empty; plainSet=empty; if (PRED_SUPPRESS == NULL) { PRED_SUPPRESS=new_pred(); PRED_SUPPRESS->expr="Predicate Suppressed"; }; /* this section just counts the number of "interesting" alternatives */ /* in order to allocate arrays */ for (p=alt; p!=NULL; p=(Junction *)p->p2) { /* ignore empty alts */ if ( p->p1->ntype != nJunction || ((Junction *)p->p1)->jtype != EndBlk ) { nAlts++; }; }; /* if this is a (...)+ block then don't count the last alt because it can't be taken until at least one time through the block. In other words it isn't a real choice until the (...)+ is entered at which point the hoisting issue is moot. Maybe look at "ignore" instead ? */ if (alt->jtype == aPlusBlk) { nAlts--; }; jList=(Junction **)calloc(nAlts,sizeof(Junction *)); require(jList!=NULL,"cannot allocate MR_find_in_aSubBlk jList"); plainContext=(set *)calloc(nAlts,sizeof(set)); require(plainContext!=NULL,"cannot allocate MR_find_in_aSubBlk plainContext"); for (m=0; m < nAlts; m++) plainContext[m]=empty; predList=(Predicate **)calloc(nAlts,sizeof(Predicate *)); require(predList!=NULL,"cannot allocate MR_find_in_aSubBlk predList"); matchList=(int *)calloc(nAlts,sizeof(int)); require(matchList!=NULL,"cannot allocate MR_find_in_aSubBlk matchList"); /* this section just fills in the arrays previously allocated */ /* the most interesting one is matchList[] */ /* */ /* bit 0 => this alt has a semantic pred which is "covered" */ /* by an alt without a semantic pred. Don't hoist. */ for (i=0,p=alt; p!=NULL && ip2) { /* ignore empty alts */ if ( p->p1->ntype != nJunction || ((Junction *)p->p1)->jtype != EndBlk ) { jList[i]=MR_junctionWithoutP2(p); predList[i]=find_predicates(p->p1); /* should be jList ????? */ if (predList[i] != NULL) { MR_cleanup_pred_trees(predList[i]); /* flatten & left factor */ plainContext[i]=MR_union_plain_sets(predList[i]); } else { MR_set_reuse(&plainSet); MR_set_reuse(&incomplete); plainSet=MR_First(depth1,jList[i],&incomplete); MR_complete_set(depth1,&plainSet,&incomplete); require(set_nil(incomplete),"couldn't complete k=1"); plainContext[i]=plainSet; plainSet=empty; }; set_orin(&union_plainSet,plainContext[i]); }; }; if (nAlts == 1) { goto EXIT_SIMPLE; }; /* * Looking for cases where alt i has a semantic pred and alt j does not. * Don't care about cases where lookahead for semantic predicates overlap * because normal predicate hoisting does the correct thing automatically. * Don't care about cases where lookahead for alts without semantic predicates * overlap because normal prediction does the correct thing automatically. * * When we find such a case check for one of three subcases: * * 1. if lookahead for alt i is contained in the lookahead for any * alt j then ignore semantic predicate of alt i * 2. if lookahead for alt i is not contained in the lookahead for * any alt j then add add predicate i to the OR list to be hoisted * 3. if lookahead for alt i overlaps the lookahead for some alt j then * add a dummy semantic predicate for alt j * * There is an implicit assumption that the context of all alternatives following * the rule being processed here are identical (but may vary from hoist to * hoist depending on the place where the rule was invoked that led to hoisting * these predicates. In othere words in the fragment: * * ( <>? a1 a2 a3 | <>? b1 b2 b3 ) * * both a3 and b3 have the same follow sets because they are both at the end of * alternatives in the same block. */ for (i=0; i < nAlts; i++) { if (jList[i] == NULL) continue; if (predList[i] == NULL) continue; /* if the predicate depth turns out to be one token only */ /* then it is can be easily represented as a set and */ /* compared to the junction set create by MR_First() */ predDepth=0; MR_pred_depth(predList[i],&predDepth); require (predDepth >= 1,"MR_find_in_aSubBlk: pred depth < 1"); require (predDepth <= CLL_k,"MR_find_in_aSubBlk: predDepth > CLL_k"); /* complete predicates to predDepth If completed to depth=1 then the context would be incomplete. The context would be truncated and the predicate simplify routine would have incomplete information. It would lead to either false matches of failure to find true matches. */ MR_complete_predicates(predDepth,predList[i]); if (predList[i] != NULL) { MR_cleanup_pred_trees(predList[i]); /* flatten & left factor */ }; /* If the predicate depth is 1 then it is possible to suppress a predicate completely using a single plain alt. Check for suppression by a single plain alt first because it gives better messages. If that fails try the union of all the plain alts. */ if (predDepth == 1) { MR_set_reuse(&predSet); predSet=MR_compute_pred_set(predList[i]); /* ignores k>1 predicates */ for (j=0; j < nAlts; j++) { if (jList[j] == NULL) continue; if (j == i) continue; MR_set_reuse(&setDif); setDif=set_dif(predSet,plainContext[j]); if (set_nil(setDif)) { matchList[i] |= 1; MR_reportSetSuppression(predDepth,predSet,plainContext[j],jList[i],jList[j],predList[i]); predicate_free(predList[i]); predList[i]=PRED_SUPPRESS; goto next_i; }; }; /* end loop on j */ changed=0; /* predicate_dup is only to give good error messages */ /* remember to do a predicate_free() */ origPred=predicate_dup(predList[i]); MR_apply_restriction1(predList[i],&union_plainSet,&changed); if (changed) { /* don't use Pass3 by itself unless you know that inverted is not important */ newPred=MR_removeRedundantPredPass3(predList[i]); newPred=MR_predSimplifyALL(newPred); if (newPred == NULL) { matchList[i] |= 1; MR_reportSetSuppression(predDepth,predSet,union_plainSet,jList[i], NULL,origPred); predList[i]=PRED_SUPPRESS; } else { MR_reportSetRestriction(predDepth,predSet,union_plainSet,jList[i], NULL,origPred,newPred); predList[i]=newPred; }; }; predicate_free(origPred); origPred=NULL; }; /* If the predicate depth is > 1 then it can't be suppressed completely because the code doesn't support inspection of such things. They're much messier than k=1 sets. */ if (predDepth > 1 ) { changed=0; /* predicate_dup is only to give good error messages */ /* remember to do a predicate_free() */ origPred=predicate_dup(predList[i]); MR_apply_restriction1(predList[i],&union_plainSet,&changed); if (changed) { newPred=MR_removeRedundantPredPass3(predList[i]); newPred=MR_predSimplifyALL(newPred); if (newPred == NULL) { matchList[i] |= 1; MR_reportSetSuppression(predDepth,predSet,union_plainSet,jList[i], NULL,origPred); predList[i]=PRED_SUPPRESS; } else { MR_reportSetRestriction(predDepth,predSet,union_plainSet,jList[i], NULL,origPred,newPred); predList[i]=newPred; }; }; predicate_free(origPred); origPred=NULL; }; next_i: continue; }; EXIT_SIMPLE: root = new_pred(); root->expr=PRED_OR_LIST; tail = &(root->down); for (i=0 ; i< nAlts ; i++) { if (jList[i] == NULL) continue; if (predList[i] == NULL) { continue; } else if ( (matchList[i] & 1) != 0) { if (predList[i] != PRED_SUPPRESS) { predicate_free(predList[i]); }; continue; }; /* make an OR list of predicates */ *tail=predList[i]; tail=&(predList[i]->right); }; /* if just one pred, remove OR root */ if (root->down == NULL) { predicate_free(root); root=NULL; } else if (root->down->right == NULL) { Predicate *p=root->down; root->down=NULL; predicate_free(root); root=p; } root=MR_predSimplifyALL(root); MR_orin_plainSet(root,union_plainSet); set_free(predSet); set_free(union_plainSet); set_free(incomplete); set_free(setChange); set_free(setDif); for (m=0; m < nAlts; m++) set_free(plainContext[m]); free ( (char *) jList); free ( (char *) predList); free ( (char *) matchList); free ( (char *) plainContext); return root; } #ifdef __USE_PROTOS void MR_predContextPresent(Predicate *p,int *allHaveContext,int *noneHaveContext) #else void MR_predContextPresent(p,allHaveContext,noneHaveContext) Predicate *p; int *allHaveContext; int *noneHaveContext; #endif { if (p == NULL) return; MR_predContextPresent(p->right,allHaveContext,noneHaveContext); if (p->expr != PRED_AND_LIST && p->expr != PRED_OR_LIST) { if (set_nil(p->scontext[1]) == 0 || (p->tcontext != NULL)) { *noneHaveContext=0; } else { *allHaveContext=0; }; }; MR_predContextPresent(p->down,allHaveContext,noneHaveContext); } #ifdef __USE_PROTOS int MR_pointerStackPush(PointerStack *ps,void *dataPointer) #else int MR_pointerStackPush(ps,dataPointer) PointerStack *ps; void *dataPointer; #endif { void **newStack; int newSize; int i; if (ps->count == ps->size) { newSize=20+ps->size*2; newStack=(void **)calloc(newSize,sizeof(void *)); require (newStack != NULL,"cannot allocate PointerStack"); for (i=0; i < ps->size; i++) { newStack[i]=ps->data[i]; }; if (ps->data != NULL) free( (char *) ps->data); ps->data=newStack; ps->size=newSize; }; ps->data[ps->count]=dataPointer; ps->count++; return ps->count-1; } #ifdef __USE_PROTOS void * MR_pointerStackPop(PointerStack *ps) #else void * MR_pointerStackPop(ps) PointerStack *ps; #endif { void *dataPointer; require(ps->count > 0,"MR_pointerStackPop underflow"); dataPointer=ps->data[ps->count-1]; ps->data[ps->count-1]=NULL; (ps->count)--; return dataPointer; } #ifdef __USE_PROTOS void * MR_pointerStackTop(PointerStack *ps) #else void * MR_pointerStackTop(ps) PointerStack *ps; #endif { require(ps->count > 0,"MR_pointerStackTop underflow"); return ps->data[ps->count-1]; } #ifdef __USE_PROTOS void MR_pointerStackReset(PointerStack *ps) #else void MR_pointerStackReset(ps) PointerStack *ps; #endif { int i; if (ps->data != NULL) { for (i=0; i < ps->count ; i++) { ps->data[i]=NULL; }; }; ps->count=0; } #ifdef __USE_PROTOS Junction *MR_nameToRuleBlk(char *name) #else Junction *MR_nameToRuleBlk(name) char *name; #endif { RuleEntry *q; require (RulePtr != NULL,"MR_nameToRule: RulePtr not initialized"); if (name == NULL) return NULL; q = (RuleEntry *) hash_get(Rname,name); if ( q == NULL ) { return NULL; } else { return RulePtr[q->rulenum]; }; } #ifdef __USE_PROTOS Junction * MR_ruleReferenced(RuleRefNode *rrn) #else Junction * MR_ruleReferenced(rrn) RuleRefNode *rrn; #endif { return MR_nameToRuleBlk(rrn->text); } #ifdef __USE_PROTOS void MR_comparePredLeaves(Predicate *me,Predicate *myParent,Predicate *him,Predicate *hisParent) #else void MR_comparePredLeaves(me,myParent,him,hisParent) Predicate *me; Predicate *myParent; Predicate *him; Predicate *hisParent; #endif { if (me == NULL) return; if (me == him) { MR_comparePredLeaves(me->right,myParent,him,hisParent); return; } else if (me->expr == PRED_AND_LIST || me->expr == PRED_OR_LIST) { MR_comparePredLeaves(me->down,me,him,hisParent); MR_comparePredLeaves(me->right,myParent,him,hisParent); return; } else { if (me->source != NULL) { /* predicate->invert can be set only in the predEntry predicates */ /* thus they are only visible after the predEntry predicates have been "unfolded" */ int sameSource=(me->source == him->source); int sameInvert=1 & (1 + me->inverted + him->inverted + me->source->inverted + him->source->inverted); int samePredEntry=(me->source->predEntry != NULL && him->source->predEntry != NULL && me->source->predEntry == him->source->predEntry); if (sameInvert && (sameSource || samePredEntry)) { if (MR_identicalContext(me,him)) { /* identical predicates */ if (hisParent->expr == PRED_OR_LIST && myParent->expr == PRED_OR_LIST) { me->redundant=1; } else if (hisParent->expr == PRED_AND_LIST && myParent->expr == PRED_AND_LIST) { me->redundant=1; } else if ( (hisParent->expr == PRED_OR_LIST && myParent->expr == PRED_AND_LIST) || (hisParent->expr == PRED_AND_LIST && myParent->expr == PRED_OR_LIST) ) { myParent->redundant=1; } else { require (0,"MR_comparePredLeaves: not both PRED_LIST"); }; }; }; /* end same source or same predEntrr with same invert sense */ /* same predEntry but opposite invert sense */ if (!sameInvert && (sameSource || samePredEntry)) { if (MR_identicalContext(me,him)) { if (hisParent->expr == PRED_OR_LIST && myParent->expr == PRED_OR_LIST) { myParent->isConst=1; myParent->constValue=1; } else if (hisParent->expr == PRED_AND_LIST && myParent->expr == PRED_AND_LIST) { myParent->isConst=1; myParent->constValue=0; } else if ( (hisParent->expr == PRED_OR_LIST && myParent->expr == PRED_AND_LIST) || (hisParent->expr == PRED_AND_LIST && myParent->expr == PRED_OR_LIST) ) { me->redundant=1; } else { require (0,"MR_comparePredLeaves: not both PRED_LIST"); }; }; }; /* end same predEntry with opposite invert sense */ }; MR_comparePredLeaves(me->right,myParent,him,hisParent); return; }; } #ifdef __USE_PROTOS void MR_removeRedundantPredPass1(Predicate *me,Predicate *myParent) #else void MR_removeRedundantPredPass1(me,myParent) Predicate *me; Predicate *myParent; #endif { if (me == NULL) return; if (me->redundant) { MR_removeRedundantPredPass1(me->right,myParent); return; }; if (me->expr == PRED_AND_LIST || me->expr == PRED_OR_LIST) { MR_removeRedundantPredPass1(me->down,me); MR_removeRedundantPredPass1(me->right,myParent); } else { require (me->source != NULL,"me->source == NULL"); if (myParent != NULL) { MR_comparePredLeaves(myParent->down,myParent,me,myParent); }; MR_removeRedundantPredPass1(me->right,myParent); }; } /* pretty much ignores things with the inverted bit set */ #ifdef __USE_PROTOS Predicate *MR_predFlatten(Predicate *p) #else Predicate *MR_predFlatten(p) Predicate *p; #endif { if (p == NULL) return NULL; if (p->expr == PRED_OR_LIST || p->expr == PRED_AND_LIST) { Predicate *child; Predicate *gchild; Predicate **tail; Predicate *next; char *PRED_XXX_LIST=p->expr; require (p->down != NULL,"MR_predFlatten AND/OR no child"); p->down=MR_predFlatten(p->down); p->right=MR_predFlatten(p->right); child=p->down; if (child->right == NULL) { child->right=p->right; p->right=NULL; p->down=NULL; if (p->inverted) child->inverted=!child->inverted; predicate_free(p); return child; }; /* make a single list of all children and grandchildren */ tail=&(p->down); for (child=p->down; child != NULL; child=next) { if (child->expr != PRED_XXX_LIST || child->inverted || child->predEntry != NULL) { *tail=child; tail=&(child->right); next=child->right; } else { for (gchild=child->down; gchild != NULL; gchild=gchild->right) { *tail=gchild; tail=&(gchild->right); }; next=child->right; child->right=NULL; child->down=NULL; predicate_free(child); }; }; *tail=NULL; return p; } else { p->right=MR_predFlatten(p->right); return p; }; } static char *alwaysFalseWarning=NULL; #ifdef __USE_PROTOS Predicate *checkPredicateConflict(Predicate *p) #else Predicate *checkPredicateConflict(p) Predicate *p; #endif { if (p->isConst) { if (p->constValue == 1) { predicate_free(p); return NULL; } else { if (InfoP && !p->conflictReported) { p->conflictReported=1; fprintf(output,"\n#if 0\n\n"); fprintf(output,"The following predicate expression will always be false:\n\n"); MR_dumpPred1(1,p,1); fprintf(output,"\n#endif\n"); }; if (alwaysFalseWarning != CurRule) { alwaysFalseWarning=CurRule; if (InfoP) { warnNoFL(eMsg1("one (or more) predicate expression hoisted into rule \"%s\" are always false \ - see output file for more information",CurRule)); } else { warnNoFL(eMsg1("one (or more) predicate expressions hoisted into rule \"%s\" are always false \ - use \"-info p\" for more information",CurRule)); }; }; }; }; return p; } #ifdef __USE_PROTOS int MR_countPredNodes(Predicate *p) #else int MR_countPredNodes(p) Predicate *p; #endif { if (p == NULL) return 0; return 1 + MR_countPredNodes(p->down) + MR_countPredNodes(p->right); } #ifdef __USE_PROTOS Predicate *MR_predSimplifyALLX(Predicate *p,int skipPass3) #else Predicate *MR_predSimplifyALLX(p,skipPass3) Predicate *p; int skipPass3; #endif { int countBefore; int countAfter; countAfter=MR_countPredNodes(p); do { if (p == NULL) return NULL; if (p->right == NULL && p->down == NULL) return p; countBefore=countAfter; MR_simplifyInverted(p,0); p=MR_predFlatten(p); MR_removeRedundantPredPass1(p,NULL); MR_removeRedundantPredPass2(p); if (! skipPass3) { p=checkPredicateConflict(p); p=MR_removeRedundantPredPass3(p); }; countAfter=MR_countPredNodes(p); } while (countBefore != countAfter); return p; } #ifdef __USE_PROTOS Predicate *MR_predSimplifyALL(Predicate *p) #else Predicate *MR_predSimplifyALL(p) Predicate *p; #endif { return MR_predSimplifyALLX(p,0); } #ifdef __USE_PROTOS void MR_releaseResourcesUsedInRule(Node *n) #else void MR_releaseResourcesUsedInRule(n) Node *n; #endif { Node *next; Junction *j; int i; if (n == NULL) return; if (n->ntype == nJunction) { j=(Junction *) n; if (j->predicate != NULL) { predicate_free(j->predicate); j->predicate=NULL; }; for (i=0; i< CLL_k; i++) { set_free(j->fset[i]); j->fset[i]=empty; }; if (j->ftree != NULL) { Tfree(j->ftree); j->ftree=NULL; }; if (j->jtype == EndRule) return; if (j->jtype != RuleBlk && j->jtype != EndBlk) { if (j->p2 != NULL && !j->ignore) { /* MR11 */ MR_releaseResourcesUsedInRule(j->p2); }; }; }; next=MR_advance(n); MR_releaseResourcesUsedInRule(next); } #ifdef __USE_PROTOS int MR_allPredLeaves(Predicate *p) #else int MR_allPredLeaves(p) Predicate *p; #endif { Predicate *q; if (p == NULL) return 1; for (q=p; q != NULL; q=q->right) { if (q->down != NULL) return 0; }; return 1; } /* make sure it works for the last rule in a file */ #ifdef __USE_PROTOS int MR_offsetFromRule(Node *n) #else int MR_offsetFromRule(n) Node *n; #endif { Junction *j; int offset=(-1); for (j=SynDiag; j != NULL; j=(Junction *)j->p2) { require (j->ntype == nJunction && j->jtype == RuleBlk,"Not a rule block"); if (n->file < j->file) { return offset; }; if (n->file == j->file) { if (n->line < j->line) { return (offset < 0) ? 0 : offset; } else { offset=n->line - j->line; if (offset == 0) return 0; }; }; }; return offset; } #define ruleNameMax 50 static char ruleNameStatic1[ruleNameMax]; static char ruleNameStatic2[ruleNameMax+10]; #ifdef __USE_PROTOS char * MR_ruleNamePlusOffset(Node *n) #else char * MR_ruleNamePlusOffset(n) Node *n; #endif { int offset=MR_offsetFromRule(n); strncpy(ruleNameStatic1,n->rname,ruleNameMax); if (offset < 0) { sprintf(ruleNameStatic2,"%s/?",ruleNameStatic1); } else { sprintf(ruleNameStatic2,"%s/%d",ruleNameStatic1,offset+1); }; return ruleNameStatic2; } #ifdef __USE_PROTOS int MR_max_height_of_tree(Tree *t) #else int MR_max_height_of_tree(t) Tree *t; #endif { int h; int height=0; Tree *u; if (t == NULL) return 0; require (t->token != ALT && t->token != EpToken,"MR_max_height_of_tree ALT or EpToken"); for (u=t; u != NULL; u=u->right) { h=MR_max_height_of_tree(u->down)+1; if (h > height) height=h; }; return height; } #ifdef __USE_PROTOS int MR_all_leaves_same_height(Tree *t,int depth) #else int MR_all_leaves_same_height(t,depth) Tree *t; int depth; #endif { if (t == NULL) { return (depth==0); }; require (t->token != ALT && t->token != EpToken,"MR_all_leaves_same_height ALT or EpToken"); if (depth == 0) { return 0; } else { if ( ! MR_all_leaves_same_height(t->down,depth-1)) { return 0; }; if (t->right == NULL) { return 1; } else { return MR_all_leaves_same_height(t->right,depth); }; }; } #ifdef __USE_PROTOS void MR_projectTreeOntoSet(Tree *tree,int ck,set *ckset) #else void MR_projectTreeOntoSet(tree,ck,ckset) Tree *tree; int ck; set *ckset; #endif { if (tree == NULL) return; require(tree->token != EpToken,"MR_projectTreeOntoSet: EpToken unexpected\n"); MR_projectTreeOntoSet(tree->right,ck,ckset); if (tree->token == ALT) { MR_projectTreeOntoSet(tree->down,ck,ckset); } else { if (ck > 1) { MR_projectTreeOntoSet(tree->down,ck-1,ckset); } else { set_orel(tree->token,ckset); }; }; } #ifdef __USE_PROTOS int MR_comparePredicates(Predicate *a,Predicate *b) #else int MR_comparePredicates(a,b) Predicate *a; Predicate *b; #endif { Predicate *p; Predicate *q; if (a == b) return 1; if (a == NULL || b == NULL ) return 0; if (a->down == NULL && b->down == NULL) { /* predicate->invert can be set only in the predEntry predicates */ /* thus they are only visible after the predEntry predicates have been "unfolded" */ int sameSource=(a->source == b->source); int sameInvert= 1 & (1 +a->inverted + b->inverted + a->source->inverted + b->source->inverted); int samePredEntry=(a->source->predEntry != NULL && b->source->predEntry != NULL && a->source->predEntry == b->source->predEntry); if (sameInvert && (sameSource || samePredEntry)) { if (MR_identicalContext(a,b)) { return 1; }; }; return 0; }; if (a->down == NULL || b->down == NULL) return 0; if (a->expr != b->expr) return 0; for (p=a->down; p != NULL; p=p->right) { for (q=b->down; q != NULL; q=q->right) { if (MR_comparePredicates(p,q)) goto NEXT_P; }; return 0; NEXT_P: continue; }; return 1; } /* * action->inverted can be set only when a predicate symbol appears in * a rule: "rule : <>? X". It cannot be set under any * other circumstances. In particular it cannot be set by * "#pred NotA !A" or by "#pred Nota <>?". The first case * creates a predEntry and the predicate expression of that predEntry * has inverted set. In the second case, the code for handling "!" * is only present in buildAction, which is not called by the #pred * semantic routines, only when a <<...>>? is recognized as part of * a rule definition. * * predicate->inverted can only be set by a predicate created by a #pred * expression, such as "#pred NotA !A" or "#pred NotXY ! (X && Y) or * "#pred XbarY !(X && Y)". In particular, it cannot be set by any * predicate expression occurring under any other circumstances. * The #pred predicate expresssions are stored with in predEntry->pred * and do not normally appear anywhere else until the predicates are * "unfolded" in order to recognize redundancies, conflicts, and * tautologies. * * The unfold routine expands all references to #pred expressions. * * The simplifyInvert goes through and propagates the invert bit so that * all OR and AND nodes are un-inverted. * * Note that !(A and B) => (!A or !B) * !(A or B) => (!A and !B) * * MR_unfold() is called to expand predicate symbols by replacing predicates * that reference predicate entries with the copies of the predicate entries. * Each reference receives a duplicate of the original. This is necessary * because the next phase involves simplification and removal of redundant * predicate nodes. Anyway, the point I'm making is that predicate->invert * should not be set in any predicate until it has been expanded. * * This is a recursive structure, but there is no need for "recursive expansion" * by which I mean a predicate symbol refers to other predicate symbols which * must also be expanded. * * Recursive expansion is *not* performed by this routine because it is not * necessary. Expansion of references is performed by predPrimary when * a new predicate symbol is created by referring to others in the pred expr. */ #ifdef __USE_PROTOS Predicate *MR_unfold(Predicate *pred) #else Predicate *MR_unfold(pred) Predicate *pred; #endif { Predicate *result; if (pred == NULL) return NULL; pred->right=MR_unfold(pred->right); if (pred->down == NULL) { if (pred->source->predEntry != NULL) { if (pred->source->predEntry->pred == NULL) { ; /* do nothing */ /* a reference to a literal #pred (perhaps with "!" */ } else { result=predicate_dup_without_context(pred->source->predEntry->pred); if (pred->inverted) { result->inverted=!result->inverted; }; if (pred->source->inverted) { result->inverted=!result->inverted; }; result->right=pred->right; pred->right=NULL; predicate_free(pred); /*** result=MR_unfold(result); *** not necessary */ /* recursive expansion */ return result; }; } else { ; /* do nothing */ /* an inline literal predicate */ }; } else { pred->down=MR_unfold(pred->down); }; return pred; } /* this should be called immediately after MR_unfold() and at no other times */ #ifdef __USE_PROTOS void MR_simplifyInverted(Predicate *pred,int inverted) #else void MR_simplifyInverted(pred,inverted) Predicate *pred; int inverted; #endif { int newInverted; if (pred == NULL) return; MR_simplifyInverted(pred->right,inverted); newInverted= 1 & (inverted + pred->inverted); if (pred->down == NULL) { pred->inverted=newInverted; } else { if (newInverted != 0) { if (pred->expr == PRED_AND_LIST) { pred->expr=PRED_OR_LIST; } else { pred->expr=PRED_AND_LIST; }; }; pred->inverted=0; MR_simplifyInverted(pred->down,newInverted); }; } /* only remove it from AND and OR nodes, not leaves */ #ifdef __USE_PROTOS void MR_clearPredEntry(Predicate *p) #else void MR_clearPredEntry(p) Predicate *p; #endif { if (p == NULL) return; MR_clearPredEntry(p->down); MR_clearPredEntry(p->right); if (p->down != NULL) p->predEntry=NULL; } #ifdef __USE_PROTOS void MR_orphanRules(FILE *f) #else void MR_orphanRules(f) FILE *f; #endif { set a; Junction *p; unsigned e; RuleEntry *re; a=empty; if (! InfoO) return; for (p=SynDiag; p!=NULL; p = (Junction *)p->p2) { if ( (Junction *) (p->end)->p1 == NULL) { re=(RuleEntry *) hash_get(Rname,p->rname); require (re != NULL,"RuleEntry == NULL"); set_orel(re->rulenum, &a); } } if (set_deg(a) > 1) { fprintf(f,"note: Start rules: {"); for (; !set_nil(a); set_rm(e,a)) { e=set_int(a); fprintf(f," %s",RulePtr[e]->rname); }; fprintf(f," }\n"); }; set_free( a ); } /* merge (X Y) and (X) to create (X) */ static int *mergeChain; static Tree *mergeTree; #ifdef __USE_PROTOS Tree *MR_merge_tree_contexts_client(Tree *t,int chain[]) #else Tree *MR_merge_tree_contexts_client(t,chain) Tree *t; int chain[]; #endif { if (t == NULL) return NULL; if (chain[0] == 0) { Tree *u=t->right; t->right=NULL; Tfree(t); return MR_merge_tree_contexts_client(u,&chain[0]); } if (chain[0] == t->token) { t->down=MR_merge_tree_contexts_client(t->down,&chain[1]); }; t->right=MR_merge_tree_contexts_client(t->right,&chain[0]); return t; } #ifdef __USE_PROTOS void MR_iterateOverTreeContexts(Tree *t,int chain[]) #else void MR_iterateOverTreeContexts(t,chain) Tree *t; int chain[]; #endif { if (t == NULL) return; chain[0]=t->token; if (t->down != NULL) { MR_iterateOverTreeContexts(t->down,&chain[1]); } else { MR_merge_tree_contexts_client(mergeTree,mergeChain); }; MR_iterateOverTreeContexts(t->right,&chain[0]); chain[0]=0; } #ifdef __USE_PROTOS Tree *MR_merge_tree_contexts(Tree *t) #else Tree *MR_merge_tree_contexts(t) Tree *t; #endif { int h=MR_max_height_of_tree(t); mergeTree=t; mergeChain=(int *) calloc(h+1,sizeof(int)); require (mergeChain != NULL,"MR_merge_tree_contexts: can't alloc chain"); MR_iterateOverTreeContexts(t,mergeChain); t=tshrink(t); t=tflatten(t); t=tleft_factor(t); free ( (char *) mergeChain); mergeChain=NULL; return t; } #ifdef __USE_PROTOS Tree *MR_compute_pred_tree_context(Predicate *p) #else Tree *MR_compute_pred_tree_context(p) Predicate *p; #endif { Tree *t; t=MR_compute_pred_tree_ctxXX(p); MR_merge_tree_contexts(t); return t; } #ifdef __USE_PROTOS void MR_guardPred_plainSet(ActionNode *anode,Predicate *pred) #else void MR_guardPred_plainSet(anode,pred) ActionNode *anode; Predicate *pred; #endif { Junction *j; Predicate *workPred; set maskSet; maskSet=empty; if (!MRhoisting) return; /* it doesn't really matter whether the predicate has depth k=1 or k>1 because we're not really looking at the predicate itself, just the stuff "behind" the predicate. */ /* shouldn't have to worry about REACHing off the end of the rule containing the predicate because the Rule->end->halt should have been set already by the the code which handles RuleRef nodes. We don't want to REACH off the end of the rule because this would give the "global" follow context rather than the "local" context. r1a : (A)? => <

    >? r2 (A|B) r1b : (A)? => <

    >? r2 (A|C) r2 : (); For r1a we want follow of predicate = {A B} we want plainSet = {B} For r1b we want follow of predicate = {A C} we want plainSet = {C} */ require (anode->next->ntype == nJunction,"MR_guardpred_plainSet not Junction"); j=(Junction *)(anode->next); workPred=predicate_dup_without_context(pred); workPred->k=1; workPred->scontext[1]=MR_First(1,j, &(workPred->completionSet) ); MR_complete_predicates(1,workPred); if (pred->k == 1) { maskSet=pred->scontext[1]; } else { MR_projectTreeOntoSet(pred->tcontext,1,&maskSet); } pred->plainSet=set_dif(workPred->scontext[1],maskSet); predicate_free(workPred); } /*******************************************************************************/ static Tree * suppressTree; static int * suppressChain; /* element 0 not used */ static set * suppressSets; static Node * suppressNode; static int suppressChainLength; int MR_SuppressSearch=0; static int suppressSucceeded; static Predicate * suppressPredicate; #ifdef __USE_PROTOS int MR_isChain(Tree *t) #else int MR_isChain(t) Tree *t; #endif { Tree *u; for (u=t; u != NULL; u=u->down) { if (u->right != NULL) return 0; } return 1; } #ifdef __USE_PROTOS int MR_suppressK_client(Tree *tree,int tokensInChain[]) #else int MR_suppressK_client(tree,tokensInChain) Tree *tree; int tokensInChain[]; #endif { int i; set *save_fset; int save_ConstrainSearch; set incomplete; Tree *t; suppressSucceeded=0; /* volatile */ if (suppressSets == NULL) { suppressSets=(set *) calloc (CLL_k+1,sizeof(set)); require (suppressSets != NULL,"MR_suppressK_client: suppressSets alloc"); }; for (suppressChainLength=1; tokensInChain[suppressChainLength+1] != 0; suppressChainLength++) {}; require (suppressChainLength != 0,"MR_suppressK_client: chain empty"); for (i=1 ; i <= suppressChainLength ; i++) { set_clr(suppressSets[i]); set_orel( (unsigned) tokensInChain[i], &suppressSets[i]); }; save_fset=fset; save_ConstrainSearch=ConstrainSearch; fset=suppressSets; MR_SuppressSearch=1; MR_AmbSourceSearch=1; MR_MaintainBackTrace=1; ConstrainSearch=1; maxk = suppressChainLength; incomplete=empty; t=NULL; /*** constrain = &(fset[1]); ***/ MR_setConstrainPointer(&(fset[1])); /* MR18 */ MR_pointerStackReset(&MR_BackTraceStack); TRAV(suppressNode,maxk,&incomplete,t); Tfree(t); require (set_nil(incomplete),"MR_suppressK_client TRAV incomplete"); require (MR_BackTraceStack.count == 0, "MR_suppressK_client: MR_BackTraceStack.count != 0"); set_free(incomplete); ConstrainSearch=save_ConstrainSearch; fset=save_fset; MR_AmbSourceSearch=0; MR_MaintainBackTrace=0; MR_SuppressSearch=0; return suppressSucceeded; } #ifdef __USE_PROTOS Tree * MR_iterateOverTreeSuppressK(Tree *t,int chain[]) #else Tree * MR_iterateOverTreeSuppressK(t,chain) Tree *t; int chain[]; #endif { if (t == NULL) return NULL; t->right=MR_iterateOverTreeSuppressK(t->right,&chain[0]); chain[0]=t->token; if (t->down != NULL) { t->down=MR_iterateOverTreeSuppressK(t->down,&chain[1]); if (t->down == NULL) { Tree *u=t->right; t->right=NULL; Tfree(t); chain[0]=0; return u; }; } else { MR_suppressK_client(suppressTree,suppressChain); if (suppressSucceeded) { Tree *u=t->right; t->right=NULL; Tfree(t); chain[0]=0; return u; }; }; chain[0]=0; return t; } /* @@@ */ #ifdef __USE_PROTOS Predicate * MR_suppressK(Node *j,Predicate *p) #else Predicate * MR_suppressK(j,p) Node *j; Predicate *p; #endif { Predicate *result; int guardPred=0; int ampersandPred=0; Node *nodePrime; if (! MRhoistingk) { return p; } if (! MRhoisting) return p; if (CLL_k == 1) return p; if (suppressChain == NULL) { suppressChain=(int *) calloc(CLL_k+2,sizeof(int)); require (suppressChain != NULL,"MR_suppressK: can't allocate chain"); } if (p == NULL) return NULL; if (j->ntype == nJunction) { nodePrime=(Node *) MR_junctionWithoutP2( (Junction *) j); } else { nodePrime=j; }; p->down=MR_suppressK(j,p->down); p->right=MR_suppressK(j,p->right); if (p->down != NULL) { result=p; goto EXIT; }; if (p->k == 1) { result=p; goto EXIT; }; if (p->source != NULL) { if (p->source->guardpred != NULL) guardPred=1; if (p->source->ampersandPred != NULL) ampersandPred=1; } suppressPredicate=p; suppressNode=nodePrime; /* was j*/ suppressTree=p->tcontext; if (guardPred || ampersandPred) { p->tcontext=MR_iterateOverTreeSuppressK(suppressTree,&suppressChain[1]); if (p->tcontext == NULL) { predicate_free(p); result=NULL; goto EXIT; }; } else { if (MR_isChain(p->tcontext)) { p->tcontext=MR_iterateOverTreeSuppressK(suppressTree,&suppressChain[1]); if (p->tcontext == NULL) { predicate_free(p); result=NULL; goto EXIT; }; } } result=p; EXIT: return result; } #ifdef __USE_PROTOS void MR_suppressSearchReport(void) #else void MR_suppressSearchReport() #endif { int i; Node *p; TokNode *tn; int depth; set setAnd; /* number of tokens in back trace stack matches length of chain */ depth=0; for (i=0; i < MR_BackTraceStack.count ; i++) { p=(Node *) MR_BackTraceStack.data[i]; if (p->ntype == nToken) depth++; }; require (depth == suppressChainLength,"depth > suppressChainLength"); /* token codes match chain */ depth=0; for (i=0; i < MR_BackTraceStack.count ; i++) { p=(Node *) MR_BackTraceStack.data[i]; if (p->ntype != nToken) continue; tn=(TokNode *) p; depth++; if (set_nil(tn->tset)) { require(set_el( (unsigned) tn->token,fset[depth]), "MR_suppressSearchReport: no match to #token in chain"); } else { setAnd=set_and(fset[depth],tn->tset); require(!set_nil(setAnd), "MR_suppressSearchReport: no match to #token set in chain"); set_free(setAnd); }; }; /* have a match - now remove it from the predicate */ suppressSucceeded=1; if (suppressSucceeded) { fprintf(output,"\n"); fprintf(output,"#if 0\n"); fprintf(output,"\n"); fprintf(output,"Part (or all) of predicate with depth > 1 suppressed by "); fprintf(output,"alternative without predicate\n\n"); MR_dumpPred(suppressPredicate,1); fprintf(output,"The token sequence which is suppressed:"); fprintf(output," ("); for (i=1; i <= suppressChainLength; i++) { fprintf(output," %s",TerminalString(suppressChain[i])); }; fprintf(output," )\n"); fprintf(output,"The sequence of references which generate that sequence of tokens:\n\n"); MR_backTraceDumpItemReset(); for (i=0; i < MR_BackTraceStack.count ; i++) { MR_backTraceDumpItem(output,0,(Node *) MR_BackTraceStack.data[i]); }; fprintf(output,"\n"); fprintf(output,"#endif\n"); } } #ifdef __USE_PROTOS void MR_markCompromisedRule(Node *n) #else void MR_markCompromisedRule(n) Node *n; #endif { RuleEntry *q; Node *mark=NULL; Junction *j; if (n->ntype == nRuleRef) { mark=(Node *) MR_ruleReferenced( (RuleRefNode *) n); } else if (n->ntype == nToken) { mark=n; } else if (n->ntype == nJunction) { j=(Junction *)n; switch (j->jtype) { case aOptBlk: case aLoopBlk: case RuleBlk: case EndRule: case aPlusBlk: case aLoopBegin: mark=n; break; default: break; }; } if (mark == NULL) return; require (RulePtr != NULL,"RulePtr not initialized"); q = (RuleEntry *) hash_get(Rname,mark->rname); require (q != NULL,"RuleEntry not found"); set_orel(q->rulenum,&MR_CompromisedRules); } #ifdef __USE_PROTOS void MR_alphaBetaTraceReport(void) #else void MR_alphaBetaTraceReport() #endif { int i; if (! AlphaBetaTrace) return; MR_AlphaBetaMessageCount++; fprintf(output,"\n"); fprintf(output,"#if 0\n"); fprintf(output,"\n"); fprintf(output,"Trace of references leading to attempt to compute the follow set of\n"); fprintf(output,"alpha in an \"(alpha)? beta\" block. It is not possible for antlr to\n"); fprintf(output,"compute this follow set because it is not known what part of beta has\n"); fprintf(output,"already been matched by alpha and what part remains to be matched.\n"); fprintf(output,"\n"); fprintf(output,"Rules which make use of the incorrect follow set will also be incorrect\n"); fprintf(output,"\n"); MR_backTraceDumpItemReset(); for (i=0; i < MR_BackTraceStack.count ; i++) { MR_backTraceDumpItem(output,0,(Node *) MR_BackTraceStack.data[i]); if (i < MR_BackTraceStack.count-1) { MR_markCompromisedRule( (Node *) MR_BackTraceStack.data[i]); }; }; fprintf(output,"\n"); fprintf(output,"#endif\n"); } #ifdef __USE_PROTOS void MR_dumpRuleSet(set s) #else void MR_dumpRuleSet(s) set s; #endif { unsigned *cursor; unsigned *origin=set_pdq(s); require(origin != NULL,"set_pdq failed"); if (RulePtr == NULL) { fprintf(stderr,"RulePtr[] not yet initialized"); } else { for (cursor=origin; *cursor != nil ; cursor++) { /**** if (cursor != origin) fprintf(stderr,","); ****/ fprintf(stderr," %s",RulePtr[*cursor]->rname); fprintf(stderr,"\n"); }; free( (char *) origin); }; } cccc-3.1.4/pccts/antlr/parser.dlg0000644000000000000000000004454207265350074015351 0ustar rootroot<< /* parser.dlg -- DLG Description of scanner * * Generated from: antlr.g * * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include "pcctscfg.h" #include "set.h" #include #include "syn.h" #include "hash.h" #include "generic.h" #define zzcr_attr(attr,tok,t) #include "antlr.h" #include "tokens.h" #include "dlgdef.h" LOOKAHEAD void #ifdef __USE_PROTOS zzerraction(void) #else zzerraction() #endif { (*zzerr)("invalid token"); zzadvance(); zzskip(); } >> <<%%lexaction /* maintained, but not used for now */ set AST_nodes_refd_in_actions = set_init; int inAlt = 0; set attribsRefdFromAction = set_init; /* MR20 */ int UsedOldStyleAttrib = 0; int UsedNewStyleLabel = 0; #ifdef __USE_PROTOS char *inline_set(char *); #else char *inline_set(); #endif /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ int tokenActionActive=0; /* MR1 */ >> <<%%lexaction static char * #ifdef __USE_PROTOS getFileNameFromTheLineInfo(char *toStr, char *fromStr) #else getFileNameFromTheLineInfo(toStr, fromStr) char *toStr, *fromStr; #endif { int i, j, k; if (!fromStr || !toStr) return toStr; /* find the first " */ for (i=0; (i> <<%%lexaction #ifdef __USE_PROTOS void mark_label_used_in_sem_pred(LabelEntry *le) /* MR10 */ #else void mark_label_used_in_sem_pred(le) /* MR10 */ LabelEntry *le; #endif { TokNode *tn; require (le->elem->ntype == nToken,"mark_label_used... ntype != nToken"); tn=(TokNode *)le->elem; require (tn->label != 0,"mark_label_used... TokNode has no label"); tn->label_used_in_semantic_pred=1; } >> %%START @ << NLA = Eof; /* L o o k F o r A n o t h e r F i l e */ { FILE *new_input; new_input = NextFile(); if ( new_input == NULL ) { NLA=Eof; return; } fclose( input ); input = new_input; zzrdstream( input ); zzskip(); /* Skip the Eof (@) char i.e continue */ } >> [\t\ ]+ << NLA = 76; zzskip(); >> \n|\r|\r\n << NLA = 77; zzline++; zzskip(); >> \[ << NLA = 78; zzmode(ACTIONS); zzmore(); istackreset(); pushint(']'); >> \<\< << NLA = 79; action_file=CurFile; action_line=zzline; zzmode(ACTIONS); zzmore(); list_free(&CurActionLabels,0); /* MR10 */ numericActionLabel=0; /* MR10 */ istackreset(); pushint('>'); >> \" << NLA = 80; zzmode(STRINGS); zzmore(); >> /\* << NLA = 81; zzmode(COMMENTS); zzskip(); >> \*/ << NLA = 82; warn("Missing /*; found dangling */"); zzskip(); >> // << NLA = 83; zzmode(CPP_COMMENTS); zzskip(); >> #line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n) << NLA = 84; zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); >> #line ~[\n\r]* (\n|\r|\r\n) << NLA = 85; zzline++; zzmore(); >> \>\> << NLA = 86; warn("Missing <<; found dangling \>\>"); zzskip(); >> . << NLA = WildCard; >> \@ << NLA = 88; FoundException = 1; /* MR6 */ FoundAtOperator = 1; >> {\\}#header << NLA = 92; >> {\\}#first << NLA = 93; >> {\\}#parser << NLA = 94; >> {\\}#tokdefs << NLA = 95; >> \} << NLA = 96; >> class << NLA = 97; >> \{ << NLA = 100; >> ! << NLA = 101; >> \< << NLA = 102; >> \> << NLA = 103; >> : << NLA = 104; >> ; << NLA = 105; >> {\\}#lexaction << NLA = 106; >> {\\}#lexmember << NLA = 107; >> {\\}#lexprefix << NLA = 108; >> {\\}#pred << NLA = 109; >> \|\| << NLA = 110; >> && << NLA = 111; >> \( << NLA = 112; >> \) << NLA = 113; >> {\\}#lexclass << NLA = 114; >> {\\}#errclass << NLA = 115; >> {\\}#tokclass << NLA = 116; >> .. << NLA = 117; >> {\\}#token << NLA = 118; >> = << NLA = 119; >> [0-9]+ << NLA = 120; >> \| << NLA = 121; >> \~ << NLA = 122; >> ^ << NLA = 123; >> {\\}#pragma << NLA = 124; >> approx << NLA = 125; >> LL\(1\) << NLA = 126; >> LL\(2\) << NLA = 127; >> \* << NLA = 128; >> \+ << NLA = 129; >> ? << NLA = 130; >> => << NLA = 131; >> exception << NLA = 132; >> default << NLA = 133; >> catch << NLA = 134; >> [a-z] [A-Za-z0-9_]* << NLA = NonTerminal; while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >> [A-Z] [A-Za-z0-9_]* << NLA = TokenTerm; while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; >> {\\}#[A-Za-z0-9_]* << NLA = 135; warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); >> %%STRINGS @ << NLA = Eof; >> \" << NLA = QuotedTerm; zzmode(START); >> \n|\r|\r\n << NLA = 3; zzline++; warn("eoln found in string"); zzskip(); >> \\(\n|\r|\r\n) << NLA = 4; zzline++; zzmore(); >> \\~[] << NLA = 5; zzmore(); >> ~[\n\r\"\\]+ << NLA = 6; zzmore(); >> %%ACTION_STRINGS @ << NLA = Eof; >> \" << NLA = 7; zzmode(ACTIONS); zzmore(); >> \n|\r|\r\n << NLA = 8; zzline++; warn("eoln found in string (in user action)"); zzskip(); >> \\(\n|\r|\r\n) << NLA = 9; zzline++; zzmore(); >> \\~[] << NLA = 10; zzmore(); >> ~[\n\r\"\\]+ << NLA = 11; zzmore(); >> %%ACTION_CHARS @ << NLA = Eof; >> ' << NLA = 12; zzmode(ACTIONS); zzmore(); >> \n|\r|\r\n << NLA = 13; zzline++; warn("eoln found in char literal (in user action)"); zzskip(); >> \\~[] << NLA = 14; zzmore(); >> ~[\n\r'\\]+ << NLA = 15; zzmore(); >> %%ACTION_COMMENTS @ << NLA = Eof; >> \*/ << NLA = 16; zzmode(ACTIONS); zzmore(); >> \* << NLA = 17; zzmore(); >> \n|\r|\r\n << NLA = 18; zzline++; zzmore(); DAWDLE; >> ~[\n\r\*]+ << NLA = 19; zzmore(); >> %%TOK_DEF_COMMENTS @ << NLA = Eof; >> \*/ << NLA = 20; zzmode(PARSE_ENUM_FILE); zzmore(); >> \* << NLA = 21; zzmore(); >> \n|\r|\r\n << NLA = 22; zzline++; zzmore(); DAWDLE; >> ~[\n\r\*]+ << NLA = 23; zzmore(); >> %%TOK_DEF_CPP_COMMENTS @ << NLA = Eof; >> \n|\r|\r\n << NLA = 24; zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; >> ~[\n\r]+ << NLA = 25; zzskip(); >> %%ACTION_CPP_COMMENTS @ << NLA = Eof; >> \n|\r|\r\n << NLA = 26; zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; >> ~[\n\r]+ << NLA = 27; zzmore(); >> %%CPP_COMMENTS @ << NLA = Eof; >> \n|\r|\r\n << NLA = 28; zzline++; zzmode(START); zzskip(); DAWDLE; >> ~[\n\r]+ << NLA = 29; zzskip(); >> %%COMMENTS @ << NLA = Eof; >> \*/ << NLA = 30; zzmode(START); zzskip(); >> \* << NLA = 31; zzskip(); >> \n|\r|\r\n << NLA = 32; zzline++; zzskip(); DAWDLE; >> ~[\n\r\*]+ << NLA = 33; zzskip(); >> %%ACTIONS @ << NLA = Eof; >> \>\> << NLA = Action; /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = ' '; zzbegexpr[1] = ' '; if ( zzbufovf ) { err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE)); } /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ /* MR1 Doesn't matter what kind of action it is - reset*/ tokenActionActive=0; /* MR1 */ >> \>\>? << NLA = Pred; /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = '\0'; if ( zzbufovf ) { err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE)); }; #ifdef __cplusplus__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __STDC__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __USE_PROTOS /* MRxx */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else /* MR10 */ list_apply(CurActionLabels,mark_label_used_in_sem_pred); #endif #endif #endif >> \] << NLA = PassAction; if ( topint() == ']' ) { popint(); if ( istackempty() ) /* terminate action */ { zzmode(START); NLATEXT[0] = ' '; zzbegexpr[0] = ' '; if ( zzbufovf ) { err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE)); } } else { /* terminate $[..] and #[..] */ if ( GenCC ) zzreplstr("))"); else zzreplstr(")"); zzmore(); } } else if ( topint() == '|' ) { /* end of simple [...] */ popint(); zzmore(); } else zzmore(); >> consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \) << NLA = 37; zzmore(); zzreplstr(inline_set(zzbegexpr+ strlen("consumeUntil("))); >> consumeUntil\( ~[\)]+ \) << NLA = 38; zzmore(); >> \n|\r|\r\n << NLA = 39; zzline++; zzmore(); DAWDLE; >> \> << NLA = 40; zzmore(); >> $ << NLA = 41; zzmore(); >> $$ << NLA = 42; if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();} else err("$$ use invalid in C++ mode"); >> $\[\] << NLA = 43; if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();} else err("$[] use invalid in C++ mode"); >> $\[ << NLA = 44; pushint(']'); if ( !GenCC ) zzreplstr("zzconstr_attr("); else err("$[..] use invalid in C++ mode"); zzmore(); >> $[0-9]+ << NLA = 45; { static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i attrib ref too big"); set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> $[0-9]+. << NLA = 46; { static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i.field attrib ref too big"); zzbegexpr[strlen(zzbegexpr)-1] = ' '; set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s.", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> $[0-9]+.[0-9]+ << NLA = 47; { static char buf[100]; static char i[20], j[20]; char *p,*q; numericActionLabel=1; /* MR10 */ if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big"); for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) { if ( q == &i[20] ) fatalFL("i of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; for (p++, q= &j[0]; *p!='\0'; p++) { if ( q == &j[20] ) fatalFL("j of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j); else sprintf(buf,"_t%s%s",i,j); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } >> $[_a-zA-Z][_a-zA-Z0-9]* << NLA = 48; { static char buf[300]; LabelEntry *el; zzbegexpr[0] = ' '; if ( CurRule != NULL && strcmp(CurRule, &zzbegexpr[1])==0 ) { if ( !GenCC ) zzreplstr("zzaRet"); } else if ( CurRetDef != NULL && strmember(CurRetDef, &zzbegexpr[1])) { if ( HasComma( CurRetDef ) ) { require (strlen(zzbegexpr)<=(size_t)285, "$retval attrib ref too big"); sprintf(buf,"_retv.%s",&zzbegexpr[1]); zzreplstr(buf); } else zzreplstr("_retv"); } else if ( CurParmDef != NULL && strmember(CurParmDef, &zzbegexpr[1])) { ; } else if ( Elabel==NULL ) { { err("$-variables in actions outside of rules are not allowed"); } } else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) { /* MR10 */ /* MR10 */ /* element labels might exist without an elem when */ /* MR10 */ /* it is a forward reference (to a rule) */ /* MR10 */ /* MR10 */ if ( GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) ) /* MR10 */ { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); } /* MR10 */ /* MR10 */ if ( !GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) && GenAST) { /* MR10 */ err("You can no longer use attributes returned by rules when also using ASTs"); /* MR10 */ err(" Use upward inheritance (\"rule >[Attrib a] : ... <<$a=...\>\>\")"); /* MR10 */ }; /* MR10 */ /* MR10 */ /* keep track of <<... $label ...>> for semantic predicates in guess mode */ /* MR10 */ /* element labels contain pointer to the owners node */ /* MR10 */ /* MR10 */ if (el->elem != NULL && el->elem->ntype == nToken) { /* MR10 */ list_add(&CurActionLabels,el); /* MR10 */ }; } else warn(eMsg1("$%s not parameter, return value, (defined) element label",&zzbegexpr[1])); } zzmore(); >> #0 << NLA = 49; zzreplstr("(*_root)"); zzmore(); chkGTFlag(); >> #\[\] << NLA = 50; if ( GenCC ) { if (NewAST) zzreplstr("(newAST)"); else zzreplstr("(new AST)");} else {zzreplstr("zzastnew()");} zzmore(); chkGTFlag(); >> #\(\) << NLA = 51; zzreplstr("NULL"); zzmore(); chkGTFlag(); >> #[0-9]+ << NLA = 52; { static char buf[100]; if ( strlen(zzbegexpr)>(size_t)85 ) fatal("#i AST ref too big"); if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1); else sprintf(buf,"zzastArg(%s)",zzbegexpr+1); zzreplstr(buf); zzmore(); set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions); chkGTFlag(); } >> #line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n) << NLA = 53; zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); >> #line ~[\n\r]* (\n|\r|\r\n) << NLA = 54; zzline++; zzmore(); >> #[_a-zA-Z][_a-zA-Z0-9]* << NLA = 55; if ( !(strcmp(zzbegexpr, "#ifdef")==0 || strcmp(zzbegexpr, "#if")==0 || strcmp(zzbegexpr, "#else")==0 || strcmp(zzbegexpr, "#endif")==0 || strcmp(zzbegexpr, "#ifndef")==0 || strcmp(zzbegexpr, "#define")==0 || strcmp(zzbegexpr, "#pragma")==0 || strcmp(zzbegexpr, "#undef")==0 || strcmp(zzbegexpr, "#import")==0 || strcmp(zzbegexpr, "#line")==0 || strcmp(zzbegexpr, "#include")==0 || strcmp(zzbegexpr, "#error")==0) ) { static char buf[100]; sprintf(buf, "%s_ast", zzbegexpr+1); zzreplstr(buf); chkGTFlag(); } zzmore(); >> #\[ << NLA = 56; pushint(']'); if ( GenCC ) { if (NewAST) zzreplstr("(newAST("); else zzreplstr("(new AST("); } else zzreplstr("zzmk_ast(zzastnew(),"); zzmore(); chkGTFlag(); >> #\( << NLA = 57; pushint('}'); if ( GenCC ) zzreplstr("ASTBase::tmake("); else zzreplstr("zztmake("); zzmore(); chkGTFlag(); >> # << NLA = 58; zzmore(); >> \) << NLA = 59; if ( istackempty() ) zzmore(); else if ( topint()==')' ) { popint(); } else if ( topint()=='}' ) { popint(); /* terminate #(..) */ zzreplstr(", NULL)"); } zzmore(); >> \[ << NLA = 60; pushint('|'); /* look for '|' to terminate simple [...] */ zzmore(); >> \( << NLA = 61; pushint(')'); zzmore(); >> \\\] << NLA = 62; zzreplstr("]"); zzmore(); >> \\\) << NLA = 63; zzreplstr(")"); zzmore(); >> \\> << NLA = 64; if (! tokenActionActive) zzreplstr(">"); /* MR1 */ zzmore(); /* MR1 */ >> ' << NLA = 65; zzmode(ACTION_CHARS); zzmore(); >> \" << NLA = 66; zzmode(ACTION_STRINGS); zzmore(); >> \\$ << NLA = 67; zzreplstr("$"); zzmore(); >> \\# << NLA = 68; zzreplstr("#"); zzmore(); >> \\(\n|\r|\r\n) << NLA = 69; zzline++; zzmore(); >> \\~[\]\)>$#] << NLA = 70; zzmore(); >> / << NLA = 71; zzmore(); >> /\* << NLA = 72; zzmode(ACTION_COMMENTS); zzmore(); >> \*/ << NLA = 73; warn("Missing /*; found dangling */ in action"); zzmore(); >> // << NLA = 74; zzmode(ACTION_CPP_COMMENTS); zzmore(); >> ~[\n\r\)\(\\$#\>\]\[\"'/]+ << NLA = 75; zzmore(); >> %%PARSE_ENUM_FILE @ << NLA = Eof; ; >> [\t\ ]+ << NLA = 136; zzskip(); >> \n|\r|\r\n << NLA = 137; zzline++; zzskip(); >> // << NLA = 138; zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); >> /\* << NLA = 139; zzmode(TOK_DEF_COMMENTS); zzskip(); >> #ifdef << NLA = 140; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #if << NLA = 141; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #ifndef << NLA = 142; ; >> #else << NLA = 143; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #endif << NLA = 144; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #undef << NLA = 145; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #import << NLA = 146; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >> #define << NLA = 148; >> enum << NLA = 150; >> \{ << NLA = 151; >> = << NLA = 152; >> , << NLA = 153; >> \} << NLA = 154; >> ; << NLA = 155; >> [0-9]+ << NLA = INT; >> [a-zA-Z_][_a-zA-Z0-9]* << NLA = ID; >> %% cccc-3.1.4/pccts/antlr/pred.c0000644000000000000000000004603607265350105014456 0ustar rootroot/* * 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-1998 */ #include #include "pcctscfg.h" #include "set.h" #include "syn.h" #include "hash.h" #include "generic.h" #include "dlgdef.h" #include #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 ) { 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); } max_k = 1; } /* 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 ) { 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; 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); } cccc-3.1.4/pccts/antlr/proto.h0000644000000000000000000010345207265350121014666 0ustar rootroot/* * 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-1998 */ /* 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 *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 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 AlphaBetaTrace; /* MR14 */ 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 ListNode *class_before_actions, *class_after_actions; extern char *UserTokenDefsFile; extern int UserDefdTokens; extern ListNode *MetaTokenNodes; extern char *OutputDirectory; extern int DontCopyTokens; 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 __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 * ); extern int DefErrSetForC1(int, set *, int, char * ); extern int DefErrSetForCC1(int, set *, int, char * ); 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 ); extern Graph makeBlk( Graph, int ); extern Graph makeLoop( Graph, int ); extern Graph makePlus( Graph, int ); extern Graph emptyAlt( 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 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 * ); 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 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 * baseName(char *); /* MR10 */ 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 *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 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 Tree *tmake(Tree *root, ...); 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); extern Predicate *computePredicateFromContextGuard(Graph,int *msgDone); /* MR10 */ 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 */ #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 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 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 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(); 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 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 * baseName(); /* MR10 */ 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 *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 warnNoFL(); extern void warnFL(); extern void warn(); extern void warnNoCR(); extern void errNoFL(); extern void errFL(); extern void err(); extern void errNoCR(); extern Tree *tmake(); extern void genPredTree(); extern UserAction *newUserAction(); extern char *gate_symbol(); extern char *makeAltID(); extern void DumpRemainingTokSets(); extern void DumpANSIFunctionArgDef(); extern Predicate *computePredicateFromContextGuard(); 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 */ #endif #ifdef __USE_PROTOS #include #endif /* MR20 G. Hobbelt Create proper externs for dlg variables */ extern set attribsRefdFromAction; extern int inAlt; extern int UsedOldStyleAttrib; extern int UsedNewStyleLabel; cccc-3.1.4/pccts/antlr/scan.c0000644000000000000000000041305307265350206014447 0ustar rootroot /* parser.dlg -- DLG Description of scanner * * Generated from: antlr.g * * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include "pcctscfg.h" #include "set.h" #include #include "syn.h" #include "hash.h" #include "generic.h" #define zzcr_attr(attr,tok,t) #include "antlr.h" #include "tokens.h" #include "dlgdef.h" LOOKAHEAD void #ifdef __USE_PROTOS zzerraction(void) #else zzerraction() #endif { (*zzerr)("invalid token"); zzadvance(); zzskip(); } /* * D L G tables * * Generated from: parser.dlg * * 1989-1998 by Will Cohen, Terence Parr, and Hank Dietz * Purdue University Electrical Engineering * DLG Version 1.33MR20 */ #include "mode.h" /* maintained, but not used for now */ set AST_nodes_refd_in_actions = set_init; int inAlt = 0; set attribsRefdFromAction = set_init; /* MR20 */ int UsedOldStyleAttrib = 0; int UsedNewStyleLabel = 0; #ifdef __USE_PROTOS char *inline_set(char *); #else char *inline_set(); #endif /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ int tokenActionActive=0; /* MR1 */ static char * #ifdef __USE_PROTOS getFileNameFromTheLineInfo(char *toStr, char *fromStr) #else getFileNameFromTheLineInfo(toStr, fromStr) char *toStr, *fromStr; #endif { int i, j, k; if (!fromStr || !toStr) return toStr; /* find the first " */ for (i=0; (ielem->ntype == nToken,"mark_label_used... ntype != nToken"); tn=(TokNode *)le->elem; require (tn->label != 0,"mark_label_used... TokNode has no label"); tn->label_used_in_semantic_pred=1; } static void act1() { NLA = Eof; /* L o o k F o r A n o t h e r F i l e */ { FILE *new_input; new_input = NextFile(); if ( new_input == NULL ) { NLA=Eof; return; } fclose( input ); input = new_input; zzrdstream( input ); zzskip(); /* Skip the Eof (@) char i.e continue */ } } static void act2() { NLA = 76; zzskip(); } static void act3() { NLA = 77; zzline++; zzskip(); } static void act4() { NLA = 78; zzmode(ACTIONS); zzmore(); istackreset(); pushint(']'); } static void act5() { NLA = 79; action_file=CurFile; action_line=zzline; zzmode(ACTIONS); zzmore(); list_free(&CurActionLabels,0); /* MR10 */ numericActionLabel=0; /* MR10 */ istackreset(); pushint('>'); } static void act6() { NLA = 80; zzmode(STRINGS); zzmore(); } static void act7() { NLA = 81; zzmode(COMMENTS); zzskip(); } static void act8() { NLA = 82; warn("Missing /*; found dangling */"); zzskip(); } static void act9() { NLA = 83; zzmode(CPP_COMMENTS); zzskip(); } static void act10() { NLA = 84; zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); } static void act11() { NLA = 85; zzline++; zzmore(); } static void act12() { NLA = 86; warn("Missing <<; found dangling >>"); zzskip(); } static void act13() { NLA = WildCard; } static void act14() { NLA = 88; FoundException = 1; /* MR6 */ FoundAtOperator = 1; } static void act15() { NLA = 92; } static void act16() { NLA = 93; } static void act17() { NLA = 94; } static void act18() { NLA = 95; } static void act19() { NLA = 96; } static void act20() { NLA = 97; } static void act21() { NLA = 100; } static void act22() { NLA = 101; } static void act23() { NLA = 102; } static void act24() { NLA = 103; } static void act25() { NLA = 104; } static void act26() { NLA = 105; } static void act27() { NLA = 106; } static void act28() { NLA = 107; } static void act29() { NLA = 108; } static void act30() { NLA = 109; } static void act31() { NLA = 110; } static void act32() { NLA = 111; } static void act33() { NLA = 112; } static void act34() { NLA = 113; } static void act35() { NLA = 114; } static void act36() { NLA = 115; } static void act37() { NLA = 116; } static void act38() { NLA = 117; } static void act39() { NLA = 118; } static void act40() { NLA = 119; } static void act41() { NLA = 120; } static void act42() { NLA = 121; } static void act43() { NLA = 122; } static void act44() { NLA = 123; } static void act45() { NLA = 124; } static void act46() { NLA = 125; } static void act47() { NLA = 126; } static void act48() { NLA = 127; } static void act49() { NLA = 128; } static void act50() { NLA = 129; } static void act51() { NLA = 130; } static void act52() { NLA = 131; } static void act53() { NLA = 132; } static void act54() { NLA = 133; } static void act55() { NLA = 134; } static void act56() { NLA = NonTerminal; while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; } static void act57() { NLA = TokenTerm; while ( zzchar==' ' || zzchar=='\t' ) { zzadvance(); } if ( zzchar == ':' && inAlt ) NLA = LABEL; } static void act58() { NLA = 135; warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); } static unsigned char shift0[257] = { 0, 55, 55, 55, 55, 55, 55, 55, 55, 55, 1, 2, 55, 55, 3, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 1, 34, 6, 9, 55, 55, 41, 55, 42, 43, 8, 49, 55, 55, 18, 7, 16, 14, 15, 16, 16, 16, 16, 16, 16, 16, 35, 36, 5, 44, 17, 50, 19, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 48, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 4, 20, 55, 46, 54, 55, 22, 39, 32, 23, 13, 25, 47, 21, 11, 52, 30, 10, 38, 12, 29, 28, 52, 24, 26, 27, 51, 52, 52, 37, 52, 52, 33, 40, 31, 45, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55 }; static void act59() { NLA = Eof; } static void act60() { NLA = QuotedTerm; zzmode(START); } static void act61() { NLA = 3; zzline++; warn("eoln found in string"); zzskip(); } static void act62() { NLA = 4; zzline++; zzmore(); } static void act63() { NLA = 5; zzmore(); } static void act64() { NLA = 6; zzmore(); } static unsigned char shift1[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 5, 5, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act65() { NLA = Eof; } static void act66() { NLA = 7; zzmode(ACTIONS); zzmore(); } static void act67() { NLA = 8; zzline++; warn("eoln found in string (in user action)"); zzskip(); } static void act68() { NLA = 9; zzline++; zzmore(); } static void act69() { NLA = 10; zzmore(); } static void act70() { NLA = 11; zzmore(); } static unsigned char shift2[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 5, 5, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act71() { NLA = Eof; } static void act72() { NLA = 12; zzmode(ACTIONS); zzmore(); } static void act73() { NLA = 13; zzline++; warn("eoln found in char literal (in user action)"); zzskip(); } static void act74() { NLA = 14; zzmore(); } static void act75() { NLA = 15; zzmore(); } static unsigned char shift3[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 5, 5, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act76() { NLA = Eof; } static void act77() { NLA = 16; zzmode(ACTIONS); zzmore(); } static void act78() { NLA = 17; zzmore(); } static void act79() { NLA = 18; zzline++; zzmore(); DAWDLE; } static void act80() { NLA = 19; zzmore(); } static unsigned char shift4[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act81() { NLA = Eof; } static void act82() { NLA = 20; zzmode(PARSE_ENUM_FILE); zzmore(); } static void act83() { NLA = 21; zzmore(); } static void act84() { NLA = 22; zzline++; zzmore(); DAWDLE; } static void act85() { NLA = 23; zzmore(); } static unsigned char shift5[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act86() { NLA = Eof; } static void act87() { NLA = 24; zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; } static void act88() { NLA = 25; zzskip(); } static unsigned char shift6[257] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; static void act89() { NLA = Eof; } static void act90() { NLA = 26; zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; } static void act91() { NLA = 27; zzmore(); } static unsigned char shift7[257] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; static void act92() { NLA = Eof; } static void act93() { NLA = 28; zzline++; zzmode(START); zzskip(); DAWDLE; } static void act94() { NLA = 29; zzskip(); } static unsigned char shift8[257] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; static void act95() { NLA = Eof; } static void act96() { NLA = 30; zzmode(START); zzskip(); } static void act97() { NLA = 31; zzskip(); } static void act98() { NLA = 32; zzline++; zzskip(); DAWDLE; } static void act99() { NLA = 33; zzskip(); } static unsigned char shift9[257] = { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static void act100() { NLA = Eof; } static void act101() { NLA = Action; /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = ' '; zzbegexpr[1] = ' '; if ( zzbufovf ) { err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE)); } /* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */ /* MR1 in DLG action */ /* MR1 Doesn't matter what kind of action it is - reset*/ tokenActionActive=0; /* MR1 */ } static void act102() { NLA = Pred; /* these do not nest */ zzmode(START); NLATEXT[0] = ' '; NLATEXT[1] = ' '; zzbegexpr[0] = '\0'; if ( zzbufovf ) { err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE)); }; #ifdef __cplusplus__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __STDC__ /* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else #ifdef __USE_PROTOS /* MRxx */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred); #else /* MR10 */ list_apply(CurActionLabels,mark_label_used_in_sem_pred); #endif #endif #endif } static void act103() { NLA = PassAction; if ( topint() == ']' ) { popint(); if ( istackempty() ) /* terminate action */ { zzmode(START); NLATEXT[0] = ' '; zzbegexpr[0] = ' '; if ( zzbufovf ) { err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE)); } } else { /* terminate $[..] and #[..] */ if ( GenCC ) zzreplstr("))"); else zzreplstr(")"); zzmore(); } } else if ( topint() == '|' ) { /* end of simple [...] */ popint(); zzmore(); } else zzmore(); } static void act104() { NLA = 37; zzmore(); zzreplstr(inline_set(zzbegexpr+ strlen("consumeUntil("))); } static void act105() { NLA = 38; zzmore(); } static void act106() { NLA = 39; zzline++; zzmore(); DAWDLE; } static void act107() { NLA = 40; zzmore(); } static void act108() { NLA = 41; zzmore(); } static void act109() { NLA = 42; if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();} else err("$$ use invalid in C++ mode"); } static void act110() { NLA = 43; if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();} else err("$[] use invalid in C++ mode"); } static void act111() { NLA = 44; pushint(']'); if ( !GenCC ) zzreplstr("zzconstr_attr("); else err("$[..] use invalid in C++ mode"); zzmore(); } static void act112() { NLA = 45; { static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i attrib ref too big"); set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } } static void act113() { NLA = 46; { static char buf[100]; numericActionLabel=1; /* MR10 */ if ( strlen(zzbegexpr)>(size_t)85 ) fatal("$i.field attrib ref too big"); zzbegexpr[strlen(zzbegexpr)-1] = ' '; set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction); if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).", BlkLevel-1,zzbegexpr+1); else sprintf(buf,"_t%d%s.", BlkLevel-1,zzbegexpr+1); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } } static void act114() { NLA = 47; { static char buf[100]; static char i[20], j[20]; char *p,*q; numericActionLabel=1; /* MR10 */ if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big"); for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) { if ( q == &i[20] ) fatalFL("i of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; for (p++, q= &j[0]; *p!='\0'; p++) { if ( q == &j[20] ) fatalFL("j of $i.j attrib ref too big", FileStr[CurFile], zzline ); *q++ = *p; } *q = '\0'; if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j); else sprintf(buf,"_t%s%s",i,j); zzreplstr(buf); zzmore(); UsedOldStyleAttrib = 1; if ( UsedNewStyleLabel ) err("cannot mix old-style $i with new-style labels"); } } static void act115() { NLA = 48; { static char buf[300]; LabelEntry *el; zzbegexpr[0] = ' '; if ( CurRule != NULL && strcmp(CurRule, &zzbegexpr[1])==0 ) { if ( !GenCC ) zzreplstr("zzaRet"); } else if ( CurRetDef != NULL && strmember(CurRetDef, &zzbegexpr[1])) { if ( HasComma( CurRetDef ) ) { require (strlen(zzbegexpr)<=(size_t)285, "$retval attrib ref too big"); sprintf(buf,"_retv.%s",&zzbegexpr[1]); zzreplstr(buf); } else zzreplstr("_retv"); } else if ( CurParmDef != NULL && strmember(CurParmDef, &zzbegexpr[1])) { ; } else if ( Elabel==NULL ) { { err("$-variables in actions outside of rules are not allowed"); } } else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) { /* MR10 */ /* MR10 */ /* element labels might exist without an elem when */ /* MR10 */ /* it is a forward reference (to a rule) */ /* MR10 */ /* MR10 */ if ( GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) ) /* MR10 */ { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); } /* MR10 */ /* MR10 */ if ( !GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) && GenAST) { /* MR10 */ err("You can no longer use attributes returned by rules when also using ASTs"); /* MR10 */ err(" Use upward inheritance (\"rule >[Attrib a] : ... <<$a=...>>\")"); /* MR10 */ }; /* MR10 */ /* MR10 */ /* keep track of <<... $label ...>> for semantic predicates in guess mode */ /* MR10 */ /* element labels contain pointer to the owners node */ /* MR10 */ /* MR10 */ if (el->elem != NULL && el->elem->ntype == nToken) { /* MR10 */ list_add(&CurActionLabels,el); /* MR10 */ }; } else warn(eMsg1("$%s not parameter, return value, (defined) element label",&zzbegexpr[1])); } zzmore(); } static void act116() { NLA = 49; zzreplstr("(*_root)"); zzmore(); chkGTFlag(); } static void act117() { NLA = 50; if ( GenCC ) { if (NewAST) zzreplstr("(newAST)"); else zzreplstr("(new AST)");} else {zzreplstr("zzastnew()");} zzmore(); chkGTFlag(); } static void act118() { NLA = 51; zzreplstr("NULL"); zzmore(); chkGTFlag(); } static void act119() { NLA = 52; { static char buf[100]; if ( strlen(zzbegexpr)>(size_t)85 ) fatal("#i AST ref too big"); if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1); else sprintf(buf,"zzastArg(%s)",zzbegexpr+1); zzreplstr(buf); zzmore(); set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions); chkGTFlag(); } } static void act120() { NLA = 53; zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore(); getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr); } static void act121() { NLA = 54; zzline++; zzmore(); } static void act122() { NLA = 55; if ( !(strcmp(zzbegexpr, "#ifdef")==0 || strcmp(zzbegexpr, "#if")==0 || strcmp(zzbegexpr, "#else")==0 || strcmp(zzbegexpr, "#endif")==0 || strcmp(zzbegexpr, "#ifndef")==0 || strcmp(zzbegexpr, "#define")==0 || strcmp(zzbegexpr, "#pragma")==0 || strcmp(zzbegexpr, "#undef")==0 || strcmp(zzbegexpr, "#import")==0 || strcmp(zzbegexpr, "#line")==0 || strcmp(zzbegexpr, "#include")==0 || strcmp(zzbegexpr, "#error")==0) ) { static char buf[100]; sprintf(buf, "%s_ast", zzbegexpr+1); zzreplstr(buf); chkGTFlag(); } zzmore(); } static void act123() { NLA = 56; pushint(']'); if ( GenCC ) { if (NewAST) zzreplstr("(newAST("); else zzreplstr("(new AST("); } else zzreplstr("zzmk_ast(zzastnew(),"); zzmore(); chkGTFlag(); } static void act124() { NLA = 57; pushint('}'); if ( GenCC ) zzreplstr("ASTBase::tmake("); else zzreplstr("zztmake("); zzmore(); chkGTFlag(); } static void act125() { NLA = 58; zzmore(); } static void act126() { NLA = 59; if ( istackempty() ) zzmore(); else if ( topint()==')' ) { popint(); } else if ( topint()=='}' ) { popint(); /* terminate #(..) */ zzreplstr(", NULL)"); } zzmore(); } static void act127() { NLA = 60; pushint('|'); /* look for '|' to terminate simple [...] */ zzmore(); } static void act128() { NLA = 61; pushint(')'); zzmore(); } static void act129() { NLA = 62; zzreplstr("]"); zzmore(); } static void act130() { NLA = 63; zzreplstr(")"); zzmore(); } static void act131() { NLA = 64; if (! tokenActionActive) zzreplstr(">"); /* MR1 */ zzmore(); /* MR1 */ } static void act132() { NLA = 65; zzmode(ACTION_CHARS); zzmore(); } static void act133() { NLA = 66; zzmode(ACTION_STRINGS); zzmore(); } static void act134() { NLA = 67; zzreplstr("$"); zzmore(); } static void act135() { NLA = 68; zzreplstr("#"); zzmore(); } static void act136() { NLA = 69; zzline++; zzmore(); } static void act137() { NLA = 70; zzmore(); } static void act138() { NLA = 71; zzmore(); } static void act139() { NLA = 72; zzmode(ACTION_COMMENTS); zzmore(); } static void act140() { NLA = 73; warn("Missing /*; found dangling */ in action"); zzmore(); } static void act141() { NLA = 74; zzmode(ACTION_CPP_COMMENTS); zzmore(); } static void act142() { NLA = 75; zzmore(); } static unsigned char shift10[257] = { 0, 33, 33, 33, 33, 33, 33, 33, 33, 33, 16, 19, 33, 33, 20, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 16, 33, 28, 27, 21, 33, 33, 30, 15, 18, 32, 33, 33, 33, 25, 31, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 33, 33, 33, 33, 1, 2, 33, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 11, 26, 26, 26, 26, 26, 22, 29, 3, 33, 26, 33, 26, 26, 4, 26, 10, 26, 26, 26, 13, 26, 26, 14, 9, 6, 5, 26, 26, 26, 7, 12, 8, 26, 26, 26, 26, 26, 17, 33, 34, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 }; static void act143() { NLA = Eof; ; } static void act144() { NLA = 136; zzskip(); } static void act145() { NLA = 137; zzline++; zzskip(); } static void act146() { NLA = 138; zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); } static void act147() { NLA = 139; zzmode(TOK_DEF_COMMENTS); zzskip(); } static void act148() { NLA = 140; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act149() { NLA = 141; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act150() { NLA = 142; ; } static void act151() { NLA = 143; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act152() { NLA = 144; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act153() { NLA = 145; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act154() { NLA = 146; zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); } static void act155() { NLA = 148; } static void act156() { NLA = 150; } static void act157() { NLA = 151; } static void act158() { NLA = 152; } static void act159() { NLA = 153; } static void act160() { NLA = 154; } static void act161() { NLA = 155; } static void act162() { NLA = INT; } static void act163() { NLA = ID; } static unsigned char shift11[257] = { 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 1, 2, 27, 27, 3, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 1, 27, 27, 6, 27, 27, 27, 27, 27, 27, 5, 27, 22, 27, 27, 4, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 27, 24, 27, 21, 27, 27, 27, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 26, 27, 26, 26, 26, 9, 10, 8, 26, 26, 7, 26, 26, 12, 15, 11, 17, 16, 26, 18, 13, 19, 14, 26, 26, 26, 26, 26, 20, 27, 23, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 }; #define DfaStates 422 typedef unsigned short DfaState; static DfaState st0[57] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 12, 13, 13, 13, 14, 15, 16, 17, 11, 18, 19, 11, 11, 11, 11, 11, 11, 11, 20, 21, 22, 23, 24, 25, 11, 11, 11, 26, 27, 28, 29, 30, 31, 32, 11, 33, 34, 35, 11, 11, 36, 422, 422, 422 }; static DfaState st1[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st2[57] = { 422, 2, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st3[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st4[57] = { 422, 422, 37, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st5[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st6[57] = { 422, 422, 422, 422, 422, 38, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st7[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st8[57] = { 422, 422, 422, 422, 422, 422, 422, 39, 40, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st9[57] = { 422, 422, 422, 422, 422, 422, 422, 41, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st10[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 42, 43, 43, 44, 43, 43, 43, 422, 422, 422, 422, 45, 43, 43, 43, 46, 43, 47, 48, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st11[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st12[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 50, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st13[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 13, 13, 13, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st14[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 51, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st15[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 52, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st16[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st17[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 53, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st18[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 54, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st19[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 55, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st20[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st21[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 56, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 57, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st22[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st23[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st24[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st25[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st26[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 58, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st27[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 59, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st28[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st29[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st30[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 60, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st31[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st32[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st33[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 422, 61, 422, 422, 422, 422, 61, 61, 61, 422, 422, 422, 422, 422, 422, 422, 61, 62, 422, 422, 61, 61, 61, 61, 422, 422 }; static DfaState st34[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st35[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st36[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 422, 61, 422, 422, 422, 422, 61, 61, 61, 422, 422, 422, 422, 422, 422, 422, 61, 61, 422, 422, 61, 61, 61, 61, 422, 422 }; static DfaState st37[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st38[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st39[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st40[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st41[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st42[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 63, 43, 64, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st43[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st44[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 65, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st45[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 66, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st46[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 67, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st47[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 68, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st48[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 69, 43, 70, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st49[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st50[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 71, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st51[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st52[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st53[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 72, 43, 43, 44, 43, 43, 43, 422, 422, 422, 422, 45, 43, 43, 43, 46, 43, 47, 48, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st54[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 73, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st55[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 74, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st56[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 75, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st57[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 76, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st58[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st59[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st60[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st61[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 422, 61, 422, 422, 422, 422, 61, 61, 61, 422, 422, 422, 422, 422, 422, 422, 61, 61, 422, 422, 61, 61, 61, 61, 422, 422 }; static DfaState st62[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 422, 422, 422, 422, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 422, 61, 422, 422, 422, 422, 61, 61, 61, 422, 422, 77, 422, 422, 422, 422, 61, 61, 422, 422, 61, 61, 61, 61, 422, 422 }; static DfaState st63[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 78, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st64[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 79, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st65[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 80, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st66[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 81, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st67[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 82, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st68[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 83, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st69[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 84, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st70[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 85, 43, 43, 43, 422, 422, 422, 422, 43, 86, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st71[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 87, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st72[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 64, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st73[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 88, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st74[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 89, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st75[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 90, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st76[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 91, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st77[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 92, 93, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st78[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 94, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st79[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 95, 43, 43, 43, 43, 43, 96, 43, 43, 422, 97, 422, 422, 422, 422, 43, 98, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st80[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 99, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st81[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 100, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st82[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 101, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st83[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 102, 43, 43, 43, 422, 422, 422, 422, 43, 43, 103, 43, 43, 43, 43, 43, 43, 43, 422, 104, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st84[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 105, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st85[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 106, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st86[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 107, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st87[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 108, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st88[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 109, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st89[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 110, 49, 49, 49, 422, 422 }; static DfaState st90[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 111, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st91[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 112, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st92[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 113, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st93[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 114, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st94[57] = { 422, 115, 116, 117, 118, 118, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 118, 119, 118, 118, 118, 118, 119, 119, 119, 118, 118, 118, 118, 118, 118, 118, 119, 119, 118, 118, 119, 119, 119, 119, 118, 422 }; static DfaState st95[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 121, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st96[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 122, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st97[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 123, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st98[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 124, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st99[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 125, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st100[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 126, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st101[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 127, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st102[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 128, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st103[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 129, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st104[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 130, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st105[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 131, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st106[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st107[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 132, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st108[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 133, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st109[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 134, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st110[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 135, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st111[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st112[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st113[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st114[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st115[57] = { 422, 115, 116, 117, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 136, 136, 136, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st116[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st117[57] = { 422, 422, 137, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st118[57] = { 422, 118, 116, 117, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st119[57] = { 422, 118, 116, 117, 118, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 118, 119, 118, 118, 118, 118, 119, 119, 119, 118, 118, 118, 118, 118, 118, 118, 119, 119, 118, 118, 119, 119, 119, 119, 118, 422 }; static DfaState st120[57] = { 422, 138, 139, 140, 118, 118, 141, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 118, 119, 118, 118, 118, 118, 119, 119, 119, 118, 118, 118, 118, 118, 118, 118, 119, 119, 118, 118, 119, 119, 119, 119, 118, 422 }; static DfaState st121[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 142, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st122[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 143, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st123[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 144, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st124[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 145, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st125[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 146, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st126[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 147, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st127[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st128[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st129[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 148, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st130[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 149, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st131[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 150, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st132[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 151, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st133[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 152, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st134[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st135[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 153, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st136[57] = { 422, 138, 139, 140, 118, 118, 141, 118, 118, 118, 118, 118, 118, 118, 136, 136, 136, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st137[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st138[57] = { 422, 138, 116, 117, 118, 118, 141, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st139[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st140[57] = { 422, 422, 154, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st141[57] = { 422, 155, 156, 157, 155, 155, 118, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 422 }; static DfaState st142[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 158, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st143[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 159, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st144[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 160, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st145[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 161, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st146[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 162, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st147[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st148[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 163, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st149[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 164, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st150[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st151[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st152[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 165, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st153[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st154[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st155[57] = { 422, 155, 156, 157, 155, 155, 166, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 422 }; static DfaState st156[57] = { 422, 167, 167, 167, 167, 167, 168, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 422 }; static DfaState st157[57] = { 422, 167, 169, 167, 167, 167, 168, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 422 }; static DfaState st158[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 170, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st159[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 171, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st160[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 172, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st161[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 173, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st162[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 174, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st163[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st164[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 175, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st165[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 176, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st166[57] = { 422, 177, 139, 140, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 178, 178, 178, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st167[57] = { 422, 167, 167, 167, 167, 167, 168, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 422 }; static DfaState st168[57] = { 422, 179, 180, 181, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 182, 182, 182, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st169[57] = { 422, 167, 167, 167, 167, 167, 168, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 422 }; static DfaState st170[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 183, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st171[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 184, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st172[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st173[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 185, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st174[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st175[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st176[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 422, 422, 422, 422, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 422, 49, 422, 422, 422, 422, 49, 49, 49, 422, 422, 422, 422, 422, 422, 422, 49, 49, 422, 422, 49, 49, 49, 49, 422, 422 }; static DfaState st177[57] = { 422, 177, 139, 140, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 178, 178, 178, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st178[57] = { 422, 177, 139, 140, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 178, 178, 178, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 422 }; static DfaState st179[57] = { 422, 179, 180, 181, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 182, 182, 182, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st180[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st181[57] = { 422, 422, 186, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st182[57] = { 422, 179, 180, 181, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 182, 182, 182, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st183[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st184[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st185[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 422, 422, 422, 422, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 422, 43, 422, 422, 422, 422, 43, 43, 43, 422, 422, 422, 422, 422, 422, 422, 43, 43, 422, 422, 43, 43, 43, 43, 422, 422 }; static DfaState st186[57] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st187[7] = { 188, 189, 190, 191, 192, 193, 422 }; static DfaState st188[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st189[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st190[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st191[7] = { 422, 422, 194, 422, 422, 422, 422 }; static DfaState st192[7] = { 422, 195, 196, 197, 195, 195, 422 }; static DfaState st193[7] = { 422, 422, 422, 422, 422, 193, 422 }; static DfaState st194[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st195[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st196[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st197[7] = { 422, 422, 198, 422, 422, 422, 422 }; static DfaState st198[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st199[7] = { 200, 201, 202, 203, 204, 205, 422 }; static DfaState st200[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st201[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st202[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st203[7] = { 422, 422, 206, 422, 422, 422, 422 }; static DfaState st204[7] = { 422, 207, 208, 209, 207, 207, 422 }; static DfaState st205[7] = { 422, 422, 422, 422, 422, 205, 422 }; static DfaState st206[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st207[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st208[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st209[7] = { 422, 422, 210, 422, 422, 422, 422 }; static DfaState st210[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st211[7] = { 212, 213, 214, 215, 216, 217, 422 }; static DfaState st212[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st213[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st214[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st215[7] = { 422, 422, 218, 422, 422, 422, 422 }; static DfaState st216[7] = { 422, 219, 219, 219, 219, 219, 422 }; static DfaState st217[7] = { 422, 422, 422, 422, 422, 217, 422 }; static DfaState st218[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st219[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st220[7] = { 221, 222, 223, 224, 225, 223, 422 }; static DfaState st221[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st222[7] = { 422, 422, 226, 422, 422, 422, 422 }; static DfaState st223[7] = { 422, 422, 223, 422, 422, 223, 422 }; static DfaState st224[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st225[7] = { 422, 422, 422, 227, 422, 422, 422 }; static DfaState st226[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st227[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st228[7] = { 229, 230, 231, 232, 233, 231, 422 }; static DfaState st229[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st230[7] = { 422, 422, 234, 422, 422, 422, 422 }; static DfaState st231[7] = { 422, 422, 231, 422, 422, 231, 422 }; static DfaState st232[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st233[7] = { 422, 422, 422, 235, 422, 422, 422 }; static DfaState st234[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st235[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st236[5] = { 237, 238, 239, 240, 422 }; static DfaState st237[5] = { 422, 422, 422, 422, 422 }; static DfaState st238[5] = { 422, 422, 422, 422, 422 }; static DfaState st239[5] = { 422, 241, 422, 422, 422 }; static DfaState st240[5] = { 422, 422, 422, 240, 422 }; static DfaState st241[5] = { 422, 422, 422, 422, 422 }; static DfaState st242[5] = { 243, 244, 245, 246, 422 }; static DfaState st243[5] = { 422, 422, 422, 422, 422 }; static DfaState st244[5] = { 422, 422, 422, 422, 422 }; static DfaState st245[5] = { 422, 247, 422, 422, 422 }; static DfaState st246[5] = { 422, 422, 422, 246, 422 }; static DfaState st247[5] = { 422, 422, 422, 422, 422 }; static DfaState st248[5] = { 249, 250, 251, 252, 422 }; static DfaState st249[5] = { 422, 422, 422, 422, 422 }; static DfaState st250[5] = { 422, 422, 422, 422, 422 }; static DfaState st251[5] = { 422, 253, 422, 422, 422 }; static DfaState st252[5] = { 422, 422, 422, 252, 422 }; static DfaState st253[5] = { 422, 422, 422, 422, 422 }; static DfaState st254[7] = { 255, 256, 257, 258, 259, 257, 422 }; static DfaState st255[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st256[7] = { 422, 422, 260, 422, 422, 422, 422 }; static DfaState st257[7] = { 422, 422, 257, 422, 422, 257, 422 }; static DfaState st258[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st259[7] = { 422, 422, 422, 261, 422, 422, 422 }; static DfaState st260[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st261[7] = { 422, 422, 422, 422, 422, 422, 422 }; static DfaState st262[36] = { 263, 264, 265, 266, 267, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 268, 265, 265, 269, 270, 271, 272, 273, 265, 265, 265, 265, 274, 275, 276, 277, 278, 279, 265, 265, 422 }; static DfaState st263[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st264[36] = { 422, 280, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st265[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st266[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st267[36] = { 422, 422, 265, 422, 265, 281, 265, 265, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st268[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st269[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st270[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st271[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 282, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st272[36] = { 422, 422, 422, 422, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 422, 422, 422, 422, 422, 422, 284, 285, 286, 286, 422, 283, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st273[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st274[36] = { 422, 422, 422, 422, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 288, 289, 422, 422, 422, 422, 422, 422, 290, 291, 292, 422, 287, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st275[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st276[36] = { 422, 293, 294, 295, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 296, 297, 298, 299, 294, 294, 294, 294, 294, 300, 294, 294, 294, 294, 294, 294, 294, 422 }; static DfaState st277[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st278[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 301, 302, 422, 422, 422 }; static DfaState st279[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 303, 265, 265, 265, 422 }; static DfaState st280[36] = { 422, 422, 304, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st281[36] = { 422, 422, 265, 422, 265, 265, 305, 265, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st282[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st283[36] = { 422, 422, 422, 422, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 422, 422, 422, 422, 422, 422, 422, 422, 306, 306, 422, 306, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st284[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st285[36] = { 422, 422, 422, 307, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st286[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 286, 286, 308, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st287[36] = { 422, 422, 422, 422, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 422, 422, 422, 422, 422, 422, 422, 422, 309, 309, 422, 309, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st288[36] = { 422, 422, 422, 422, 309, 309, 309, 309, 309, 309, 309, 309, 309, 310, 309, 422, 422, 422, 422, 422, 422, 422, 422, 309, 309, 422, 309, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st289[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 311, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st290[36] = { 422, 422, 422, 312, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st291[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 292, 292, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st292[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 292, 292, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st293[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st294[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st295[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st296[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st297[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st298[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 313, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st299[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st300[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st301[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st302[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st303[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st304[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st305[36] = { 422, 422, 265, 422, 265, 265, 265, 314, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st306[36] = { 422, 422, 422, 422, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 306, 422, 422, 422, 422, 422, 422, 422, 422, 306, 306, 422, 306, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st307[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st308[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 315, 315, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st309[36] = { 422, 422, 422, 422, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 309, 422, 422, 422, 422, 422, 422, 422, 422, 309, 309, 422, 309, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st310[36] = { 422, 422, 422, 422, 309, 309, 316, 309, 309, 309, 309, 309, 309, 309, 309, 422, 422, 422, 422, 422, 422, 422, 422, 309, 309, 422, 309, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st311[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st312[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st313[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st314[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 317, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st315[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 315, 315, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st316[36] = { 422, 422, 422, 422, 309, 309, 309, 309, 309, 309, 318, 309, 309, 309, 309, 422, 422, 422, 422, 422, 422, 422, 422, 309, 309, 422, 309, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st317[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 319, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st318[36] = { 422, 320, 320, 320, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 320, 322, 320, 320, 323, 324, 320, 320, 325, 325, 320, 321, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st319[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 326, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st320[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 323, 324, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st321[36] = { 422, 320, 320, 320, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 320, 320, 320, 320, 323, 324, 320, 320, 321, 321, 320, 321, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st322[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 322, 320, 320, 323, 324, 320, 320, 327, 327, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st323[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st324[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 328, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st325[36] = { 422, 320, 320, 320, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 321, 320, 329, 320, 320, 330, 331, 320, 320, 325, 325, 320, 321, 320, 332, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st326[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 333, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st327[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 329, 320, 320, 330, 331, 320, 320, 327, 327, 320, 320, 320, 332, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st328[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st329[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 329, 320, 320, 323, 324, 320, 320, 320, 320, 320, 320, 320, 332, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st330[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st331[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 334, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st332[36] = { 422, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 336, 337, 335, 335, 335, 335, 335, 335, 335, 320, 335, 335, 335, 335, 335, 335, 422 }; static DfaState st333[36] = { 422, 422, 265, 422, 265, 265, 338, 265, 265, 265, 265, 265, 265, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st334[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st335[36] = { 422, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 336, 337, 335, 335, 335, 335, 335, 335, 335, 339, 335, 335, 335, 335, 335, 335, 422 }; static DfaState st336[36] = { 422, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 341, 340, 340, 340, 340, 340, 340, 422 }; static DfaState st337[36] = { 422, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 342, 340, 340, 340, 340, 340, 340, 340, 340, 341, 340, 340, 340, 340, 340, 340, 422 }; static DfaState st338[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 343, 265, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st339[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 344, 320, 320, 330, 331, 320, 320, 345, 345, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st340[36] = { 422, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 341, 340, 340, 340, 340, 340, 340, 422 }; static DfaState st341[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 346, 422, 422, 347, 348, 422, 422, 349, 349, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st342[36] = { 422, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 340, 341, 340, 340, 340, 340, 340, 340, 422 }; static DfaState st343[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 265, 350, 265, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st344[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 344, 320, 320, 330, 331, 320, 320, 345, 345, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st345[36] = { 422, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 344, 320, 320, 330, 331, 320, 320, 345, 345, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320, 422 }; static DfaState st346[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 346, 422, 422, 347, 348, 422, 422, 349, 349, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st347[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st348[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 351, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st349[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 346, 422, 422, 347, 348, 422, 422, 349, 349, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st350[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 352, 422, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st351[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st352[36] = { 422, 422, 265, 422, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 353, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 265, 422, 422, 422, 422, 422, 265, 265, 265, 422 }; static DfaState st353[36] = { 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 355, 356, 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 422 }; static DfaState st354[36] = { 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 357, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 422 }; static DfaState st355[36] = { 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 355, 356, 357, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 422 }; static DfaState st356[36] = { 422, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 359, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 354, 422 }; static DfaState st357[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st358[36] = { 422, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 359, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 358, 360, 422 }; static DfaState st359[36] = { 422, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 362, 422 }; static DfaState st360[36] = { 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 363, 354, 364, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 422 }; static DfaState st361[36] = { 422, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 362, 422 }; static DfaState st362[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 365, 422, 366, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st363[36] = { 422, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 363, 354, 364, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 422 }; static DfaState st364[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st365[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 365, 422, 366, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st366[36] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st367[28] = { 368, 369, 370, 371, 372, 422, 373, 374, 374, 374, 375, 374, 374, 374, 374, 374, 374, 374, 374, 374, 376, 377, 378, 379, 380, 381, 374, 422 }; static DfaState st368[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st369[28] = { 422, 369, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st370[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st371[28] = { 422, 422, 382, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st372[28] = { 422, 422, 422, 422, 383, 384, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st373[28] = { 422, 422, 422, 422, 422, 422, 422, 385, 422, 386, 387, 422, 422, 422, 388, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st374[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st375[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 390, 389, 389, 389, 389, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st376[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st377[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st378[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st379[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st380[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st381[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 381, 422, 422 }; static DfaState st382[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st383[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st384[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st385[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 391, 422, 422, 422, 422, 422, 422, 392, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st386[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 393, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st387[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 394, 395, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st388[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 396, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st389[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st390[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 389, 389, 389, 397, 389, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st391[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 398, 422, 399, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st392[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 400, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st393[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 401, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st394[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 402, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st395[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 403, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st396[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 404, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st397[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 389, 389, 389, 389, 405, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st398[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 406, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st399[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 407, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st400[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 408, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st401[28] = { 422, 422, 422, 422, 422, 422, 422, 409, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st402[28] = { 422, 422, 422, 422, 422, 422, 422, 410, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st403[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 411, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st404[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 412, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st405[28] = { 422, 422, 422, 422, 422, 422, 422, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 422, 422, 422, 422, 422, 389, 389, 422 }; static DfaState st406[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 413, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st407[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 414, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st408[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 415, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st409[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 416, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st410[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 417, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st411[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st412[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 418, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st413[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st414[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 419, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st415[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 420, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st416[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 421, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st417[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st418[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st419[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st420[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; static DfaState st421[28] = { 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422 }; DfaState *dfa[422] = { st0, st1, st2, st3, st4, st5, st6, st7, st8, st9, st10, st11, st12, st13, st14, st15, st16, st17, st18, st19, st20, st21, st22, st23, st24, st25, st26, st27, st28, st29, st30, st31, st32, st33, st34, st35, st36, st37, st38, st39, st40, st41, st42, st43, st44, st45, st46, st47, st48, st49, st50, st51, st52, st53, st54, st55, st56, st57, st58, st59, st60, st61, st62, st63, st64, st65, st66, st67, st68, st69, st70, st71, st72, st73, st74, st75, st76, st77, st78, st79, st80, st81, st82, st83, st84, st85, st86, st87, st88, st89, st90, st91, st92, st93, st94, st95, st96, st97, st98, st99, st100, st101, st102, st103, st104, st105, st106, st107, st108, st109, st110, st111, st112, st113, st114, st115, st116, st117, st118, st119, st120, st121, st122, st123, st124, st125, st126, st127, st128, st129, st130, st131, st132, st133, st134, st135, st136, st137, st138, st139, st140, st141, st142, st143, st144, st145, st146, st147, st148, st149, st150, st151, st152, st153, st154, st155, st156, st157, st158, st159, st160, st161, st162, st163, st164, st165, st166, st167, st168, st169, st170, st171, st172, st173, st174, st175, st176, st177, st178, st179, st180, st181, st182, st183, st184, st185, st186, st187, st188, st189, st190, st191, st192, st193, st194, st195, st196, st197, st198, st199, st200, st201, st202, st203, st204, st205, st206, st207, st208, st209, st210, st211, st212, st213, st214, st215, st216, st217, st218, st219, st220, st221, st222, st223, st224, st225, st226, st227, st228, st229, st230, st231, st232, st233, st234, st235, st236, st237, st238, st239, st240, st241, st242, st243, st244, st245, st246, st247, st248, st249, st250, st251, st252, st253, st254, st255, st256, st257, st258, st259, st260, st261, st262, st263, st264, st265, st266, st267, st268, st269, st270, st271, st272, st273, st274, st275, st276, st277, st278, st279, st280, st281, st282, st283, st284, st285, st286, st287, st288, st289, st290, st291, st292, st293, st294, st295, st296, st297, st298, st299, st300, st301, st302, st303, st304, st305, st306, st307, st308, st309, st310, st311, st312, st313, st314, st315, st316, st317, st318, st319, st320, st321, st322, st323, st324, st325, st326, st327, st328, st329, st330, st331, st332, st333, st334, st335, st336, st337, st338, st339, st340, st341, st342, st343, st344, st345, st346, st347, st348, st349, st350, st351, st352, st353, st354, st355, st356, st357, st358, st359, st360, st361, st362, st363, st364, st365, st366, st367, st368, st369, st370, st371, st372, st373, st374, st375, st376, st377, st378, st379, st380, st381, st382, st383, st384, st385, st386, st387, st388, st389, st390, st391, st392, st393, st394, st395, st396, st397, st398, st399, st400, st401, st402, st403, st404, st405, st406, st407, st408, st409, st410, st411, st412, st413, st414, st415, st416, st417, st418, st419, st420, st421 }; DfaState accepts[423] = { 0, 1, 2, 3, 3, 4, 23, 6, 0, 49, 58, 56, 56, 41, 24, 13, 14, 0, 56, 56, 19, 56, 21, 22, 25, 26, 42, 0, 33, 34, 40, 43, 44, 57, 50, 51, 57, 3, 5, 9, 7, 8, 58, 58, 58, 58, 58, 58, 58, 56, 56, 12, 38, 58, 56, 56, 56, 56, 31, 32, 52, 57, 57, 58, 58, 58, 58, 58, 58, 58, 58, 56, 58, 56, 56, 56, 56, 0, 58, 58, 58, 58, 58, 58, 58, 58, 58, 56, 56, 56, 56, 56, 0, 0, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 30, 58, 56, 56, 56, 20, 55, 47, 48, 0, 11, 11, 0, 58, 58, 58, 58, 58, 58, 58, 58, 16, 39, 58, 58, 58, 58, 56, 46, 56, 0, 11, 0, 10, 10, 0, 58, 58, 58, 58, 58, 15, 58, 58, 17, 45, 56, 54, 10, 0, 11, 11, 58, 58, 58, 58, 58, 18, 58, 56, 0, 0, 0, 11, 58, 58, 35, 58, 36, 37, 53, 0, 0, 0, 10, 10, 0, 27, 29, 28, 10, 0, 59, 60, 61, 61, 0, 64, 61, 63, 62, 62, 62, 0, 65, 66, 67, 67, 0, 70, 67, 69, 68, 68, 68, 0, 71, 72, 73, 73, 0, 75, 73, 74, 0, 76, 78, 80, 79, 79, 77, 79, 0, 81, 83, 85, 84, 84, 82, 84, 0, 86, 87, 87, 88, 87, 0, 89, 90, 90, 91, 90, 0, 92, 93, 93, 94, 93, 0, 95, 97, 99, 98, 98, 96, 98, 0, 100, 107, 142, 103, 142, 128, 126, 106, 106, 108, 127, 125, 133, 0, 132, 138, 142, 101, 142, 106, 115, 109, 111, 112, 122, 122, 124, 123, 116, 119, 131, 137, 129, 130, 136, 136, 134, 135, 141, 139, 140, 102, 142, 115, 110, 113, 122, 122, 118, 117, 136, 142, 114, 122, 142, 122, 142, 0, 122, 0, 121, 121, 122, 142, 0, 121, 0, 120, 120, 0, 142, 120, 0, 121, 121, 142, 0, 0, 0, 121, 142, 0, 0, 0, 120, 120, 0, 142, 120, 142, 0, 0, 0, 0, 105, 0, 105, 0, 0, 0, 0, 104, 0, 104, 0, 143, 144, 145, 145, 0, 0, 163, 163, 157, 158, 159, 160, 161, 162, 145, 146, 147, 0, 0, 0, 0, 163, 163, 149, 0, 0, 0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 156, 0, 0, 0, 0, 0, 151, 0, 148, 0, 0, 0, 152, 153, 150, 154, 155, 0 }; void (*actions[164])() = { zzerraction, act1, act2, act3, act4, act5, act6, act7, act8, act9, act10, act11, act12, act13, act14, act15, act16, act17, act18, act19, act20, act21, act22, act23, act24, act25, act26, act27, act28, act29, act30, act31, act32, act33, act34, act35, act36, act37, act38, act39, act40, act41, act42, act43, act44, act45, act46, act47, act48, act49, act50, act51, act52, act53, act54, act55, act56, act57, act58, act59, act60, act61, act62, act63, act64, act65, act66, act67, act68, act69, act70, act71, act72, act73, act74, act75, act76, act77, act78, act79, act80, act81, act82, act83, act84, act85, act86, act87, act88, act89, act90, act91, act92, act93, act94, act95, act96, act97, act98, act99, act100, act101, act102, act103, act104, act105, act106, act107, act108, act109, act110, act111, act112, act113, act114, act115, act116, act117, act118, act119, act120, act121, act122, act123, act124, act125, act126, act127, act128, act129, act130, act131, act132, act133, act134, act135, act136, act137, act138, act139, act140, act141, act142, act143, act144, act145, act146, act147, act148, act149, act150, act151, act152, act153, act154, act155, act156, act157, act158, act159, act160, act161, act162, act163 }; static DfaState dfa_base[] = { 0, 187, 199, 211, 220, 228, 236, 242, 248, 254, 262, 367 }; static unsigned char *b_class_no[] = { shift0, shift1, shift2, shift3, shift4, shift5, shift6, shift7, shift8, shift9, shift10, shift11 }; #define ZZSHIFT(c) (b_class_no[zzauto][1+c]) #define MAX_MODE 12 #include "dlgauto.h" cccc-3.1.4/pccts/antlr/stdpccts.h0000644000000000000000000000114407265350206015351 0ustar rootroot#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-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #ifndef ANTLR_VERSION #define ANTLR_VERSION 13320 #endif #include "pcctscfg.h" #include "pccts_stdio.h" #include "pcctscfg.h" #include "set.h" #include #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 cccc-3.1.4/pccts/antlr/syn.h0000644000000000000000000003315607265350211014337 0ustar rootroot/* * 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-1998 */ #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)? && <

    >? */ 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)? && <

    >? expr */ #ifdef __cplusplus Junction *guardNodes; /* MR11 */ #else struct _junct *guardNodes; /* MR11 */ #endif struct _PredEntry *predEntry; /* MR11 */ int inverted; /* MR11 <>? */ #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 */ #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; cccc-3.1.4/pccts/antlr/tokens.h0000644000000000000000000000710107265350214015023 0ustar rootroot#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-1999 * Purdue University Electrical Engineering * ANTLR Version 1.33MR20 */ #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 NonTerminal 98 #define TokenTerm 99 #define ID 147 #define INT 149 #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 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 setwd1[]; extern SetWordType zzerr3[]; extern SetWordType setwd2[]; extern SetWordType zzerr4[]; extern SetWordType zzerr5[]; extern SetWordType zzerr6[]; extern SetWordType zzerr7[]; extern SetWordType zzerr8[]; extern SetWordType setwd3[]; extern SetWordType zzerr9[]; extern SetWordType zzerr10[]; extern SetWordType zzerr11[]; extern SetWordType zzerr12[]; extern SetWordType zzerr13[]; extern SetWordType setwd4[]; 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 setwd5[]; extern SetWordType zzerr22[]; extern SetWordType zzerr23[]; extern SetWordType zzerr24[]; extern SetWordType zzerr25[]; extern SetWordType setwd6[]; cccc-3.1.4/pccts/antlr/watantlr.mak0000644000000000000000000000216007265350214015675 0ustar rootrootSET=..\support\set PCCTS_H=..\h # # Watcom # CC=wcl386 ANTLR=..\bin\antlr DLG=..\bin\dlg CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DPC OUT_OBJ = -o OBJ_EXT = obj LINK = wcl386 .c.obj : $(CC) -c $[* $(CFLAGS) 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 $(LINK) -fe=antlr.exe *.obj -k14336 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 set.$(OBJ_EXT) $(SET)\set.c # # ****** These next targets are common to UNIX and PC world ******** # #clean up all the intermediate files clean: del *.obj #remove everything in clean plus the PCCTS files generated scrub: del $(PCCTS_GEN) del *.$(OBJ_EXT) cccc-3.1.4/pccts/CHANGES_FROM_131.txt0000644000000000000000000003724707265347223015273 0ustar rootrootCHANGES 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 instead of ====================================================================== 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 : <>? 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 : <>? 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 : <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)? => <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 )? => <>? 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 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 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 : <> 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 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 ). 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." 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. cccc-3.1.4/pccts/CHANGES_FROM_133.txt0000644000000000000000000012476107265347243015275 0ustar rootroot======================================================================= List of Implemented Fixes and Changes for Maintenance Releases of PCCTS ======================================================================= DISCLAIMER The software and these notes are provided "as is". They may include typographical or technical errors and their authors disclaims all liability of any kind or nature for damages due to error, fault, defect, or deficiency regardless of cause. All warranties of any kind, either express or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. ------------------------------------------------------- Note: Items #153 to #1 are now in a separate file named CHANGES_FROM_133_BEFORE_MR13.txt ------------------------------------------------------- #234. (Changed in MR21) Implicit int for function return value ATokenBuffer:bufferSize() did not specify a type for the return value. Reported by Hai Vo-Ba (hai@fc.hp.com). #233. (Changed in MR20) Converted to MSVC 6.0 Due to external circumstances I have had to convert to MSVC 6.0 The MSVC 5.0 project files (.dsw and .dsp) have been retained as xxx50.dsp and xxx50.dsw. The MSVC 6.0 files are named xxx60.dsp and xxx60.dsw (where xxx is the related to the directory/project). #232. (Changed in MR20) Make setwd bit vectors protected in parser.h The access for the setwd array in the parser header was not specified. As a result, it would depend on the code which preceded it. In MR20 it will always have access "protected". Reported by Piotr Eljasiak (eljasiak@zt.gdansk.tpsa.pl). #231. (Changed in MR20) Error in token buffer debug code. When token buffer debugging is selected via the pre-processor symbol DEBUG_TOKENBUFFER there is an erroneous check in AParser.cpp: #ifdef DEBUG_TOKENBUFFER if (i >= inputTokens->bufferSize() || inputTokens->minTokens() < LLk ) /* MR20 Was "<=" */ ... #endif Reported by David Wigg (wiggjd@sbu.ac.uk). #230. (Changed in MR20) Fixed problem with #define for -gd option There was an error in setting zzTRACE_RULES for the -gd (trace) option. Reported by Gary Funck (gary@intrepid.com). #229. (Changed in MR20) Additional "const" for literals "const" was added to the token name literal table. "const" was added to some panic() and similar routine #228. (Changed in MR20) dlg crashes on "()" The following token defintion will cause DLG to crash. #token "()" When there is a syntax error in a regular expression many of the dlg routines return a structure which has null pointers. When this is accessed by callers it generates the crash. I have attempted to fix the more common cases. Reported by Mengue Olivier (dolmen@bigfoot.com). #227. (Changed in MR20) Array overwrite Steveh Hand (sassth@unx.sas.com) reported a problem which was traced to a temporary array which was not properly resized for deeply nested blocks. This has been fixed. #226. (Changed in MR20) -pedantic conformance G. Hobbelt (i_a@mbh.org) and THM made many, many minor changes to create prototypes for all the functions and bring antlr, dlg, and sorcerer into conformance with the gcc -pedantic option. This may require uses to add pccts/h/pcctscfg.h to some files or makefiles in order to have __USE_PROTOS defined. #225 (Changed in MR20) AST stack adjustment in C mode The fix in #214 for AST stack adjustment in C mode missed some cases. Reported with fix by Ger Hobbelt (i_a@mbh.org). #224 (Changed in MR20) LL(1) and LL(2) with #pragma approx This may take a record for the oldest, most trival, lexical error in pccts. The regular expressions for LL(1) and LL(2) lacked an escape for the left and right parenthesis. Reported by Ger Hobbelt (i_a@mbh.org). #223 (Changed in MR20) Addition of IBM_VISUAL_AGE directory Build files for antlr, dlg, and sorcerer under IBM Visual Age have been contributed by Anton Sergeev (ags@mlc.ru). They have been placed in the pccts/IBM_VISUAL_AGE directory. #222 (Changed in MR20) Replace __STDC__ with __USE_PROTOS Most occurrences of __STDC__ replaced with __USE_PROTOS due to complaints from several users. #221 (Changed in MR20) Added #include for DLexerBase.h to PBlackBox. Added #include for DLexerBase.h to PBlackBox. #220 (Changed in MR19) strcat arguments reversed in #pred parse The arguments to strcat are reversed when creating a print name for a hash table entry for use with #pred feature. Problem diagnosed and fix reported by Scott Harrington (seh4@ix.netcom.com). #219. (Changed in MR19) C Mode routine zzfree_ast Changes to reduce use of recursion for AST trees with only right links or only left links in the C mode routine zzfree_ast. Implemented by SAKAI Kiyotaka (ksakai@isr.co.jp). #218. (Changed in MR19) Changes to support unsigned char in C mode Changes to antlr.h and err.h to fix omissions in use of zzchar_t Implemented by SAKAI Kiyotaka (ksakai@isr.co.jp). #217. (Changed in MR19) Error message when dlg -i and -CC options selected The parsers generated by pccts in C++ mode are not able to support the interactive lexer option (except, perhaps, when using the deferred fetch parser option.(Item #216). DLG now warns when both -i and -CC are selected. This warning was suggested by David Venditti (07751870267-0001@t-online.de). #216. (Changed in MR19) Defer token fetch for C++ mode Implemented by Volker H. Simonis (simonis@informatik.uni-tuebingen.de) Normally, pccts keeps the lookahead token buffer completely filled. This requires max(k,ck) tokens of lookahead. For some applications this can cause deadlock problems. For example, there may be cases when the parser can't tell when the input has been completely consumed until the parse is complete, but the parse can't be completed because the input routines are waiting for additional tokens to fill the lookahead buffer. When the ANTLRParser class is built with the pre-processor option ZZDEFER_FETCH defined, the fetch of new tokens by consume() is deferred until LA(i) or LT(i) is called. To test whether this option has been built into the ANTLRParser class use "isDeferFetchEnabled()". This is experimental. The interaction with guess mode (syntactic predicates)is not known. #215. (Changed in MR19) Addition of reset() to DLGLexerBase There was no obvious way to reset the lexer for reuse. The reset() method now does this. Suggested by David Venditti (07751870267-0001@t-online.de). #214. (Changed in MR19) C mode: Adjust AST stack pointer at exit In C mode the AST stack pointer needs to be reset if there will be multiple calls to the ANTLRx macros. Reported with fix by Paul D. Smith (psmith@baynetworks.com). #213. (Changed in MR18) Fatal error with -mrhoistk (k>1 hoisting) When rearranging code I forgot to un-comment a critical line of code that handles hoisting of predicates with k>1 lookahead. This is now fixed. Reported by Reinier van den Born (reinier@vnet.ibm.com). #212. (Changed in MR17) Mac related changes by Kenji Tanaka Kenji Tanaka (kentar@osa.att.ne.jp) has made a number of changes for Macintosh users. a. The following Macintosh MPW files aid in installing pccts on Mac: pccts/MPW_Read_Me pccts/install68K.mpw pccts/installPPC.mpw pccts/antlr/antlr.r pccts/antlr/antlr68K.make pccts/antlr/antlrPPC.make pccts/dlg/dlg.r pccts/dlg/dlg68K.make pccts/dlg/dlgPPC.make pccts/sorcerer/sor.r pccts/sorcerer/sor68K.make pccts/sorcerer/sorPPC.make They completely replace the previous Mac installation files. b. The most significant is a change in the MAC_FILE_CREATOR symbol in pcctscfg.h: old: #define MAC_FILE_CREATOR 'MMCC' /* Metrowerks C/C++ Text files */ new: #define MAC_FILE_CREATOR 'CWIE' /* Metrowerks C/C++ Text files */ c. Added calls to special_fopen_actions() where necessary. #211. (Changed in MR16a) C++ style comment in dlg This has been fixed. #210. (Changed in MR16a) Sor accepts \r\n, \r, or \n for end-of-line A user requested that Sorcerer be changed to accept other forms of end-of-line. #209. (Changed in MR16) Name of files changed. Old: CHANGES_FROM_1.33 New: CHANGES_FROM_133.txt Old: KNOWN_PROBLEMS New: KNOWN_PROBLEMS.txt #208. (Changed in MR16) Change in use of pccts #include files There were problems with MS DevStudio when mixing Sorcerer and PCCTS in the same source file. The problem is caused by the redefinition of setjmp in the MS header file setjmp.h. In setjmp.h the pre-processor symbol setjmp was redefined to be _setjmp. A later effort to execute #include resulted in an effort to #include <_setjmp.h>. I'm not sure whether this is a bug or a feature. In any case, I decided to fix it by avoiding the use of pre-processor symbols in #include statements altogether. This has the added benefit of making pre-compiled headers work again. I've replaced statements: old: #include PCCTS_SETJMP_H new: #include "pccts_setjmp.h" Where pccts_setjmp.h contains: #ifndef __PCCTS_SETJMP_H__ #define __PCCTS_SETJMP_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif A similar change has been made for other standard header files required by pccts and sorcerer: stdlib.h, stdarg.h, stdio.h, etc. Reported by Jeff Vincent (JVincent@novell.com) and Dale Davis (DalDavis@spectrace.com). #207. (Changed in MR16) dlg reports an invalid range for: [\0x00-\0xff] dlg will report that this is an invalid range. Diagnosed by Piotr Eljasiak (eljasiak@no-spam.zt.gdansk.tpsa.pl): I think this problem is not specific to unsigned chars because dlg reports no error for the range [\0x00-\0xfe]. I've found that information on range is kept in field letter (unsigned char) of Attrib struct. Unfortunately the letter value internally is for some reasons increased by 1, so \0xff is represented here as 0. That's why dlg complains about the range [\0x00-\0xff] in dlg_p.g: if ($$.letter > $2.letter) { error("invalid range ", zzline); } The fix is: if ($$.letter > $2.letter && 255 != $$2.letter) { error("invalid range ", zzline); } #206. (Changed in MR16) Free zzFAILtext in ANTLRParser destructor The ANTLRParser destructor now frees zzFAILtext. Problem and fix reported by Manfred Kogler (km@cast.uni-linz.ac.at). #205. (Changed in MR16) DLGStringReset argument now const Changed: void DLGStringReset(DLGChar *s) {...} To: void DLGStringReset(const DLGChar *s) {...} Suggested by Dale Davis (daldavis@spectrace.com) #204. (Changed in MR15a) Change __WATCOM__ to __WATCOMC__ in pcctscfg.h Reported by Oleg Dashevskii (olegdash@my-dejanews.com). #203. (Changed in MR15) Addition of sorcerer to distribution kit I have finally caved in to popular demand. The pccts 1.33mr15 kit will include sorcerer. The separate sorcerer kit will be discontinued. #202. (Changed) in MR15) Organization of MS Dev Studio Projects in Kit Previously there was one workspace that contained projects for all three parts of pccts: antlr, dlg, and sorcerer. Now each part (and directory) has its own workspace/project and there is an additional workspace/project to build a library from the .cpp files in the pccts/h directory. The library build will create pccts_debug.lib or pccts_release.lib according to the configuration selected. If you don't want to build pccts 1.33MR15 you can download a ready-to-run kit for win32 from http://www.polhode.com/win32.zip. The ready-to-run for win32 includes executables, a pre-built static library for the .cpp files in the pccts/h directory, and a sample application You will need to define the environment variable PCCTS to point to the root of the pccts directory hierarchy. #201. (Changed in MR15) Several fixes by K.J. Cummings (cummings@peritus.com) Generation of SETJMP rather than SETJMP_H in gen.c. (Sor B19) Declaration of ref_vars_inits for ref_var_inits in pccts/sorcerer/sorcerer.h. #200. (Changed in MR15) Remove operator=() in AToken.h User reported that WatCom couldn't handle use of explicit operator =(). Replace with equivalent using cast operator. #199. (Changed in MR15) Don't allow use of empty #tokclass Change antlr.g to disallow empty #tokclass sets. Reported by Manfred Kogler (km@cast.uni-linz.ac.at). #198. Revised ANSI C grammar due to efforts by Manuel Kessler Manuel Kessler (mlkessler@cip.physik.uni-wuerzburg.de) Allow trailing ... in function parameter lists. Add bit fields. Allow old-style function declarations. Support cv-qualified pointers. Better checking of combinations of type specifiers. Release of memory for local symbols on scope exit. Allow input file name on command line as well as by redirection. and other miscellaneous tweaks. This is not part of the pccts distribution kit. It must be downloaded separately from: http://www.polhode.com/ansi_mr15.zip #197. (Changed in MR14) Resetting the lookahead buffer of the parser Explanation and fix by Sinan Karasu (sinan.karasu@boeing.com) Consider the code used to prime the lookahead buffer LA(i) of the parser when init() is called: void ANTLRParser:: prime_lookahead() { int i; for(i=1;i<=LLk; i++) consume(); dirty=0; //lap = 0; // MR14 - Sinan Karasu (sinan.karusu@boeing.com) //labase = 0; // MR14 labase=lap; // MR14 } When the parser is instantiated, lap=0,labase=0 is set. The "for" loop runs LLk times. In consume(), lap = lap +1 (mod LLk) is computed. Therefore, lap(before the loop) == lap (after the loop). Now the only problem comes in when one does an init() of the parser after an Eof has been seen. At that time, lap could be non zero. Assume it was lap==1. Now we do a prime_lookahead(). If LLk is 2, then consume() { NLA = inputTokens->getToken()->getType(); dirty--; lap = (lap+1)&(LLk-1); } or expanding NLA, token_type[lap&(LLk-1)]) = inputTokens->getToken()->getType(); dirty--; lap = (lap+1)&(LLk-1); so now we prime locations 1 and 2. In prime_lookahead it used to set lap=0 and labase=0. Now, the next token will be read from location 0, NOT 1 as it should have been. This was never caught before, because if a parser is just instantiated, then lap and labase are 0, the offending assignment lines are basically no-ops, since the for loop wraps around back to 0. #196. (Changed in MR14) Problems with "(alpha)? beta" guess Consider the following syntactic predicate in a grammar with 2 tokens of lookahead (k=2 or ck=2): rule : ( alpha )? beta ; alpha : S t ; t : T U | T ; beta : S t Z ; When antlr computes the prediction expression with one token of lookahead for alts 1 and 2 of rule t it finds an ambiguity. Because the grammar has a lookahead of 2 it tries to compute two tokens of lookahead for alts 1 and 2 of t. Alt 1 clearly has a lookahead of (T U). Alt 2 is one token long so antlr tries to compute the follow set of alt 2, which means finding the things which can follow rule t in the context of (alpha)?. This cannot be computed, because alpha is only part of a rule, and antlr can't tell what part of beta is matched by alpha and what part remains to be matched. Thus it impossible for antlr to properly determine the follow set of rule t. Prior to 1.33MR14, the follow of (alpha)? was computed as FIRST(beta) as a result of the internal representation of guess blocks. With MR14 the follow set will be the empty set for that context. Normally, one expects a rule appearing in a guess block to also appear elsewhere. When the follow context for this other use is "ored" with the empty set, the context from the other use results, and a reasonable follow context results. However if there is *no* other use of the rule, or it is used in a different manner then the follow context will be inaccurate - it was inaccurate even before MR14, but it will be inaccurate in a different way. For the example given earlier, a reasonable way to rewrite the grammar: rule : ( alpha )? beta alpha : S t ; t : T U | T ; beta : alpha Z ; If there are no other uses of the rule appearing in the guess block it will generate a test for EOF - a workaround for representing a null set in the lookahead tests. If you encounter such a problem you can use the -alpha option to get additional information: line 2: error: not possible to compute follow set for alpha in an "(alpha)? beta" block. With the antlr -alpha command line option the following information is inserted into the generated file: #if 0 Trace of references leading to attempt to compute the follow set of alpha in an "(alpha)? beta" block. It is not possible for antlr to compute this follow set because it is not known what part of beta has already been matched by alpha and what part remains to be matched. Rules which make use of the incorrect follow set will also be incorrect 1 #token T alpha/2 line 7 brief.g 2 end alpha alpha/3 line 8 brief.g 2 end (...)? block at start/1 line 2 brief.g #endif At the moment, with the -alpha option selected the program marks any rules which appear in the trace back chain (above) as rules with possible problems computing follow set. Reported by Greg Knapen (gregory.knapen@bell.ca). #195. (Changed in MR14) #line directive not at column 1 Under certain circunstances a predicate test could generate a #line directive which was not at column 1. Reported with fix by David Kågedal (davidk@lysator.liu.se) (http://www.lysator.liu.se/~davidk/). #194. (Changed in MR14) (C Mode only) Demand lookahead with #tokclass In C mode with the demand lookahead option there is a bug in the code which handles matches for #tokclass (zzsetmatch and zzsetmatch_wsig). The bug causes the lookahead pointer to get out of synchronization with the current token pointer. The problem was reported with a fix by Ger Hobbelt (hobbelt@axa.nl). #193. (Changed in MR14) Use of PCCTS_USE_NAMESPACE_STD The pcctscfg.h now contains the following definitions: #ifdef PCCTS_USE_NAMESPACE_STD #define PCCTS_STDIO_H #define PCCTS_STDLIB_H #define PCCTS_STDARG_H #define PCCTS_SETJMP_H #define PCCTS_STRING_H #define PCCTS_ASSERT_H #define PCCTS_ISTREAM_H #define PCCTS_IOSTREAM_H #define PCCTS_NAMESPACE_STD namespace std {}; using namespace std; #else #define PCCTS_STDIO_H #define PCCTS_STDLIB_H #define PCCTS_STDARG_H #define PCCTS_SETJMP_H #define PCCTS_STRING_H #define PCCTS_ASSERT_H #define PCCTS_ISTREAM_H #define PCCTS_IOSTREAM_H #define PCCTS_NAMESPACE_STD #endif The runtime support in pccts/h uses these pre-processor symbols consistently. Also, antlr and dlg have been changed to generate code which uses these pre-processor symbols rather than having the names of the #include files hard-coded in the generated code. This required the addition of "#include pcctscfg.h" to a number of files in pccts/h. It appears that this sometimes causes problems for MSVC 5 in combination with the "automatic" option for pre-compiled headers. In such cases disable the "automatic" pre-compiled headers option. Suggested by Hubert Holin (Hubert.Holin@Bigfoot.com). #192. (Changed in MR14) Change setText() to accept "const ANTLRChar *" Changed ANTLRToken::setText(ANTLRChar *) to setText(const ANTLRChar *). This allows literal strings to be used to initialize tokens. Since the usual token implementation (ANTLRCommonToken) makes a copy of the input string, this was an unnecessary limitation. Suggested by Bob McWhirter (bob@netwrench.com). #191. (Changed in MR14) HP/UX aCC compiler compatibility problem Needed to explicitly declare zzINF_DEF_TOKEN_BUFFER_SIZE and zzINF_BUFFER_TOKEN_CHUNK_SIZE as ints in pccts/h/AParser.cpp. Reported by David Cook (dcook@bmc.com). #190. (Changed in MR14) IBM OS/2 CSet compiler compatibility problem Name conflict with "_cs" in pccts/h/ATokenBuffer.cpp Reported by David Cook (dcook@bmc.com). #189. (Changed in MR14) -gxt switch in C mode The -gxt switch in C mode didn't work because of incorrect initialization. Reported by Sinan Karasu (sinan@boeing.com). #188. (Changed in MR14) Added pccts/h/DLG_stream_input.h This is a DLG stream class based on C++ istreams. Contributed by Hubert Holin (Hubert.Holin@Bigfoot.com). #187. (Changed in MR14) Rename config.h to pcctscfg.h The PCCTS configuration file has been renamed from config.h to pcctscfg.h. The problem with the original name is that it led to name collisions when pccts parsers were combined with other software. All of the runtime support routines in pccts/h/* have been changed to use the new name. Existing software can continue to use pccts/h/config.h. The contents of pccts/h/config.h is now just "#include "pcctscfg.h". I don't have a record of the user who suggested this. #186. (Changed in MR14) Pre-processor symbol DllExportPCCTS class modifier Classes in the C++ runtime support routines are now declared: class DllExportPCCTS className .... By default, the pre-processor symbol is defined as the empty string. This if for use by MSVC++ users to create DLL classes. Suggested by Manfred Kogler (km@cast.uni-linz.ac.at). #185. (Changed in MR14) Option to not use PCCTS_AST base class for ASTBase Normally, the ASTBase class is derived from PCCTS_AST which contains functions useful to Sorcerer. If these are not necessary then the user can define the pre-processor symbol "PCCTS_NOT_USING_SOR" which will cause the ASTBase class to replace references to PCCTS_AST with references to ASTBase where necessary. The class ASTDoublyLinkedBase will contain a pure virtual function shallowCopy() that was formerly defined in class PCCTS_AST. Suggested by Bob McWhirter (bob@netwrench.com). #184. (Changed in MR14) Grammars with no tokens generate invalid tokens.h Reported by Hubert Holin (Hubert.Holin@bigfoot.com). #183. (Changed in MR14) -f to specify file with names of grammar files In DEC/VMS it is difficult to specify very long command lines. The -f option allows one to place the names of the grammar files in a data file in order to bypass limitations of the DEC/VMS command language interpreter. Addition supplied by Bernard Giroud (b_giroud@decus.ch). #182. (Changed in MR14) Output directory option for DEC/VMS Fix some problems with the -o option under DEC/VMS. Fix supplied by Bernard Giroud (b_giroud@decus.ch). #181. (Changed in MR14) Allow chars > 127 in DLGStringInput::nextChar() Changed DLGStringInput to cast the character using (unsigned char) so that languages with character codes greater than 127 work without changes. Suggested by Manfred Kogler (km@cast.uni-linz.ac.at). #180. (Added in MR14) ANTLRParser::getEofToken() Added "ANTLRToken ANTLRParser::getEofToken() const" to match the setEofToken routine. Requested by Manfred Kogler (km@cast.uni-linz.ac.at). #179. (Fixed in MR14) Memory leak for BufFileInput subclass of DLGInputStream The BufFileInput class described in Item #142 neglected to release the allocated buffer when an instance was destroyed. Reported by Manfred Kogler (km@cast.uni-linz.ac.at). #178. (Fixed in MR14) Bug in "(alpha)? beta" guess blocks first sets In 1.33 vanilla, and all maintenance releases prior to MR14 there is a bug in the handling of guess blocks which use the "long" form: (alpha)? beta inside a (...)*, (...)+, or {...} block. This problem does *not* apply to the case where beta is omitted or when the syntactic predicate is on the leading edge of an alternative. The problem is that both alpha and beta are stored in the syntax diagram, and that some analysis routines would fail to skip the alpha portion when it was not on the leading edge. Consider the following grammar with -ck 2: r : ( (A)? B )* C D | A B /* forces -ck 2 computation for old antlr */ /* reports ambig for alts 1 & 2 */ | B C /* forces -ck 2 computation for new antlr */ /* reports ambig for alts 1 & 3 */ ; The prediction expression for the first alternative should be LA(1)={B C} LA(2)={B C D}, but previous versions of antlr would compute the prediction expression as LA(1)={A C} LA(2)={B D} Reported by Arpad Beszedes (beszedes@inf.u-szeged.hu) who provided a very clear example of the problem and identified the probable cause. #177. (Changed in MR14) #tokdefs and #token with regular expression In MR13 the change described by Item #162 caused an existing feature of antlr to fail. Prior to the change it was possible to give regular expression definitions and actions to tokens which were defined via the #tokdefs directive. This now works again. Reported by Manfred Kogler (km@cast.uni-linz.ac.at). #176. (Changed in MR14) Support for #line in antlr source code Note: this was implemented by Arpad Beszedes (beszedes@inf.u-szeged.hu). In 1.33MR14 it is possible for a pre-processor to generate #line directives in the antlr source and have those line numbers and file names used in antlr error messages and in the #line directives generated by antlr. The #line directive may appear in the following forms: #line ll "sss" xx xx ... where ll represents a line number, "sss" represents the name of a file enclosed in quotation marks, and xxx are arbitrary integers. The following form (without "line") is not supported at the moment: # ll "sss" xx xx ... The result: zzline is replaced with ll from the # or #line directive FileStr[CurFile] is updated with the contents of the string (if any) following the line number Note ---- The file-name string following the line number can be a complete name with a directory-path. Antlr generates the output files from the input file name (by replacing the extension from the file-name with .c or .cpp). If the input file (or the file-name from the line-info) contains a path: "../grammar.g" the generated source code will be placed in "../grammar.cpp" (i.e. in the parent directory). This is inconvenient in some cases (even the -o switch can not be used) so the path information is removed from the #line directive. Thus, if the line-info was #line 2 "../grammar.g" then the current file-name will become "grammar.g" In this way, the generated source code according to the grammar file will always be in the current directory, except when the -o switch is used. #175. (Changed in MR14) Bug when guess block appears at start of (...)* In 1.33 vanilla and all maintenance releases prior to 1.33MR14 there is a bug when a guess block appears at the start of a (...)+. Consider the following k=1 (ck=1) grammar: rule : ( (STAR)? ZIP )* ID ; Prior to 1.33MR14, the generated code resembled: ... zzGUESS_BLOCK while ( 1 ) { if ( ! LA(1)==STAR) break; zzGUESS if ( !zzrv ) { zzmatch(STAR); zzCONSUME; zzGUESS_DONE zzmatch(ZIP); zzCONSUME; ... Note that the routine uses STAR for the prediction expression rather than ZIP. With 1.33MR14 the generated code resembles: ... while ( 1 ) { if ( ! LA(1)==ZIP) break; ... This problem existed only with (...)* blocks and was caused by the slightly more complicate graph which represents (...)* blocks. This caused the analysis routine to compute the first set for the alpha part of the "(alpha)? beta" rather than the beta part. Both (...)+ and {...} blocks handled the guess block correctly. Reported by Arpad Beszedes (beszedes@inf.u-szeged.hu) who provided a very clear example of the problem and identified the probable cause. #174. (Changed in MR14) Bug when action precedes syntactic predicate In 1.33 vanilla, and all maintenance releases prior to MR14, there was a bug when a syntactic predicate was immediately preceded by an action. Consider the following -ck 2 grammar: rule : <> (alpha)? beta C | A B ; alpha : A ; beta : A B; Prior to MR14, the code generated for the first alternative resembled: ... zzGUESS if ( !zzrv && LA(1)==A && LA(2)==A) { alpha(); zzGUESS_DONE beta(); zzmatch(C); zzCONSUME; } else { ... The prediction expression (i.e. LA(1)==A && LA(2)==A) is clearly wrong because LA(2) should be matched to B (first[2] of beta is {B}). With 1.33MR14 the prediction expression is: ... if ( !zzrv && LA(1)==A && LA(2)==B) { alpha(); zzGUESS_DONE beta(); zzmatch(C); zzCONSUME; } else { ... This will only affect users in which alpha is shorter than than max(k,ck) and there is an action immediately preceding the syntactic predicate. This problem was reported by reported by Arpad Beszedes (beszedes@inf.u-szeged.hu) who provided a very clear example of the problem and identified the presence of the init-action as the likely culprit. #173. (Changed in MR13a) -glms for Microsoft style filenames with -gl With the -gl option antlr generates #line directives using the exact name of the input files specified on the command line. An oddity of the Microsoft C and C++ compilers is that they don't accept file names in #line directives containing "\" even though these are names from the native file system. With -glms option, the "\" in file names appearing in #line directives is replaced with a "/" in order to conform to Microsoft compiler requirements. Reported by Erwin Achermann (erwin.achermann@switzerland.org). #172. (Changed in MR13) \r\n in antlr source counted as one line Some MS software uses \r\n to indicate a new line. Antlr now recognizes this in counting lines. Reported by Edward L. Hepler (elh@ece.vill.edu). #171. (Changed in MR13) #tokclass L..U now allowed The following is now allowed: #tokclass ABC { A..B C } Reported by Dave Watola (dwatola@amtsun.jpl.nasa.gov) #170. (Changed in MR13) Suppression for predicates with lookahead depth >1 In MR12 the capability for suppression of predicates with lookahead depth=1 was introduced. With MR13 this had been extended to predicates with lookahead depth > 1 and released for use by users on an experimental basis. Consider the following grammar with -ck 2 and the predicate in rule "a" with depth 2: r1 : (ab)* "@" ; ab : a | b ; a : (A B)? => <>? A B C ; b : A B C ; Normally, the predicate would be hoisted into rule r1 in order to determine whether to call rule "ab". However it should *not* be hoisted because, even if p is false, there is a valid alternative in rule b. With "-mrhoistk on" the predicate will be suppressed. If "-info p" command line option is present the following information will appear in the generated code: while ( (LA(1)==A) #if 0 Part (or all) of predicate with depth > 1 suppressed by alternative without predicate pred << p(LATEXT(2))>>? depth=k=2 ("=>" guard) rule a line 8 t1.g tree context: (root = A B ) The token sequence which is suppressed: ( A B ) The sequence of references which generate that sequence of tokens: 1 to ab r1/1 line 1 t1.g 2 ab ab/1 line 4 t1.g 3 to b ab/2 line 5 t1.g 4 b b/1 line 11 t1.g 5 #token A b/1 line 11 t1.g 6 #token B b/1 line 11 t1.g #endif A slightly more complicated example: r1 : (ab)* "@" ; ab : a | b ; a : (A B)? => <>? (A B | D E) ; b : <>? D E ; In this case, the sequence (D E) in rule "a" which lies behind the guard is used to suppress the predicate with context (D E) in rule b. while ( (LA(1)==A || LA(1)==D) #if 0 Part (or all) of predicate with depth > 1 suppressed by alternative without predicate pred << q(LATEXT(2))>>? depth=k=2 rule b line 11 t2.g tree context: (root = D E ) The token sequence which is suppressed: ( D E ) The sequence of references which generate that sequence of tokens: 1 to ab r1/1 line 1 t2.g 2 ab ab/1 line 4 t2.g 3 to a ab/1 line 4 t2.g 4 a a/1 line 8 t2.g 5 #token D a/1 line 8 t2.g 6 #token E a/1 line 8 t2.g #endif && #if 0 pred << p(LATEXT(2))>>? depth=k=2 ("=>" guard) rule a line 8 t2.g tree context: (root = A B ) #endif (! ( LA(1)==A && LA(2)==B ) || p(LATEXT(2)) ) { ab(); ... #169. (Changed in MR13) Predicate test optimization for depth=1 predicates When the MR12 generated a test of a predicate which had depth 1 it would use the depth >1 routines, resulting in correct but inefficient behavior. In MR13, a bit test is used. #168. (Changed in MR13) Token expressions in context guards The token expressions appearing in context guards such as: (A B)? => <>? someRule are computed during an early phase of antlr processing. As a result, prior to MR13, complex expressions such as: ~B L..U ~L..U TokClassName ~TokClassName were not computed properly. This resulted in incorrect context being computed for such expressions. In MR13 these context guards are verified for proper semantics in the initial phase and then re-evaluated after complex token expressions have been computed in order to produce the correct behavior. Reported by Arpad Beszedes (beszedes@inf.u-szeged.hu). #167. (Changed in MR13) ~L..U Prior to MR13, the complement of a token range was not properly computed. #166. (Changed in MR13) token expression L..U The token U was represented as an unsigned char, restricting the use of L..U to cases where U was assigned a token number less than 256. This is corrected in MR13. #165. (Changed in MR13) option -newAST To create ASTs from an ANTLRTokenPtr antlr usually calls "new AST(ANTLRTokenPtr)". This option generates a call to "newAST(ANTLRTokenPtr)" instead. This allows a user to define a parser member function to create an AST object. Similar changes for ASTBase::tmake and ASTBase::link were not thought necessary since they do not create AST object, only use existing ones. #164. (Changed in MR13) Unused variable _astp For many compilations, we have lived with warnings about the unused variable _astp. It turns out that this varible can *never* be used because the code which references it was commented out. This investigation was sparked by a note from Erwin Achermann (erwin.achermann@switzerland.org). #163. (Changed in MR13) Incorrect makefiles for testcpp examples All the examples in pccts/testcpp/* had incorrect definitions in the makefiles for the symbol "CCC". Instead of CCC=CC they had CC=$(CCC). There was an additional problem in testcpp/1/test.g due to the change in ANTLRToken::getText() to a const member function (Item #137). Reported by Maurice Mass (maas@cuci.nl). #162. (Changed in MR13) Combining #token with #tokdefs When it became possible to change the print-name of a #token (Item #148) it became useful to give a #token statement whose only purpose was to giving a print name to the #token. Prior to this change this could not be combined with the #tokdefs feature. #161. (Changed in MR13) Switch -gxt inhibits generation of tokens.h #160. (Changed in MR13) Omissions in list of names for remap.h When a user selects the -gp option antlr creates a list of macros in remap.h to rename some of the standard antlr routines from zzXXX to userprefixXXX. There were number of omissions from the remap.h name list related to the new trace facility. This was reported, along with a fix, by Bernie Solomon (bernard@ug.eds.com). #159. (Changed in MR13) Violations of classic C rules There were a number of violations of classic C style in the distribution kit. This was reported, along with fixes, by Bernie Solomon (bernard@ug.eds.com). #158. (Changed in MR13) #header causes problem for pre-processors A user who runs the C pre-processor on antlr source suggested that another syntax be allowed. With MR13 such directives such as #header, #pragma, etc. may be written as "\#header", "\#pragma", etc. For escaping pre-processor directives inside a #header use something like the following: \#header << \#include >> #157. (Fixed in MR13) empty error sets for rules with infinite recursion When the first set for a rule cannot be computed due to infinite left recursion and it is the only alternative for a block then the error set for the block would be empty. This would result in a fatal error. Reported by Darin Creason (creason@genedax.com) #156. (Changed in MR13) DLGLexerBase::getToken() now public #155. (Changed in MR13) Context behind predicates can suppress With -mrhoist enabled the context behind a guarded predicate can be used to suppress other predicates. Consider the following grammar: r0 : (r1)+; r1 : rp | rq ; rp : <

    >? B ; rq : (A)? => <>? (A|B); In earlier versions both predicates "p" and "q" would be hoisted into rule r0. With MR12c predicate p is suppressed because the context which follows predicate q includes "B" which can "cover" predicate "p". In other words, in trying to decide in r0 whether to call r1, it doesn't really matter whether p is false or true because, either way, there is a valid choice within r1. #154. (Changed in MR13) Making hoist suppression explicit using <> A common error, even among experienced pccts users, is to code an init-action to inhibit hoisting rather than a leading action. An init-action does not inhibit hoisting. This was coded: rule1 : <<;>> rule2 This is what was meant: rule1 : <<;>> <<;>> rule2 With MR13, the user can code: rule1 : <<;>> <> rule2 The following will give an error message: rule1 : <> rule2 If the <> appears as an init-action rather than a leading action an error message is issued. The meaning of an init-action containing "nohoist" is unclear: does it apply to just one alternative or to all alternatives ? ------------------------------------------------------- Note: Items #153 to #1 are now in a separate file named CHANGES_FROM_133_BEFORE_MR13.txt ------------------------------------------------------- cccc-3.1.4/pccts/CHANGES_FROM_133_BEFORE_MR13.txt0000644000000000000000000042145607265347332017061 0ustar rootroot ------------------------------------------------------------ This is the second part of a two part file. This is a list of changes to pccts 1.33 prior to MR13 For more recent information see CHANGES_FROM_133.txt ------------------------------------------------------------ DISCLAIMER The software and these notes are provided "as is". They may include typographical or technical errors and their authors disclaims all liability of any kind or nature for damages due to error, fault, defect, or deficiency regardless of cause. All warranties of any kind, either express or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. #153. (Changed in MR12b) Bug in computation of -mrhoist suppression set Consider the following grammar with k=1 and "-mrhoist on": r1 : (A)? => ((p>>? x /* l1 */ | r2 /* l2 */ ; r2 : A /* l4 */ | (B)? => <>? y /* l5 */ ; In earlier versions the mrhoist routine would see that both l1 and l2 contained predicates and would assume that this prevented either from acting to suppress the other predicate. In the example above it didn't realize the A at line l4 is capable of suppressing the predicate at l1 even though alt l2 contains (indirectly) a predicate. This is fixed in MR12b. Reported by Reinier van den Born (reinier@vnet.ibm.com) #153. (Changed in MR12a) Bug in computation of -mrhoist suppression set An oversight similar to that described in Item #152 appeared in the computation of the set that "covered" a predicate. If a predicate expression included a term such as p=AND(q,r) the context of p was taken to be context(q) & context(r), when it should have been context(q) | context(r). This is fixed in MR12a. #152. (Changed in MR12) Bug in generation of predicate expressions The primary purpose for MR12 is to make quite clear that MR11 is obsolete and to fix the bug related to predicate expressions. In MR10 code was added to optimize the code generated for predicate expression tests. Unfortunately, there was a significant oversight in the code which resulted in a bug in the generation of code for predicate expression tests which contained predicates combined using AND: r0 : (r1)* "@" ; r1 : (AAA)? => <

    >? r2 ; r2 : (BBB)? => <>? Q | (BBB)? => <>? Q ; In MR11 (and MR10 when using "-mrhoist on") the code generated for r0 to predict r1 would be equivalent to: if ( LA(1)==Q && (LA(1)==AAA && LA(1)==BBB) && ( p && ( q || r )) ) { This is incorrect because it expresses the idea that LA(1) *must* be AAA in order to attempt r1, and *must* be BBB to attempt r2. The result was that r1 became unreachable since both condition can not be simultaneously true. The general philosophy of code generation for predicates can be summarized as follows: a. If the context is true don't enter an alt for which the corresponding predicate is false. If the context is false then it is okay to enter the alt without evaluating the predicate at all. b. A predicate created by ORing of predicates has context which is the OR of their individual contexts. c. A predicate created by ANDing of predicates has (surprise) context which is the OR of their individual contexts. d. Apply these rules recursively. e. Remember rule (a) The correct code should express the idea that *if* LA(1) is AAA then p must be true to attempt r1, but if LA(1) is *not* AAA then it is okay to attempt r1, provided that *if* LA(1) is BBB then one of q or r must be true. if ( LA(1)==Q && ( !(LA(1)==AAA || LA(1)==BBB) || ( ! LA(1) == AAA || p) && ( ! LA(1) == BBB || q || r ) ) ) { I believe this is fixed in MR12. Reported by Reinier van den Born (reinier@vnet.ibm.com) #151a. (Changed in MR12) ANTLRParser::getLexer() As a result of several requests, I have added public methods to get a pointer to the lexer belonging to a parser. ANTLRTokenStream *ANTLRParser::getLexer() const Returns a pointer to the lexer being used by the parser. ANTLRTokenStream is the base class of DLGLexer ANTLRTokenStream *ANTLRTokenBuffer::getLexer() const Returns a pointer to the lexer being used by the ANTLRTokenBuffer. ANTLRTokenStream is the base class of DLGLexer You must manually cast the ANTLRTokenStream to your program's lexer class. Because the name of the lexer's class is not fixed. Thus it is impossible to incorporate it into the DLGLexerBase class. #151b.(Changed in MR12) ParserBlackBox member getLexer() The template class ParserBlackBox now has a member getLexer() which returns a pointer to the lexer. #150. (Changed in MR12) syntaxErrCount and lexErrCount now public See Item #127 for more information. #149. (Changed in MR12) antlr option -info o (letter o for orphan) If there is more than one rule which is not referenced by any other rule then all such rules are listed. This is useful for alerting one to rules which are not used, but which can still contribute to ambiguity. For example: start : a Z ; unused: a A ; a : (A)+ ; will cause an ambiguity report for rule "a" which will be difficult to understand if the user forgets about rule "unused" simply because it is not used in the grammar. #148. (Changed in MR11) #token names appearing in zztokens,token_tbl In a #token statement like the following: #token Plus "\+" the string "Plus" appears in the zztokens array (C mode) and token_tbl (C++ mode). This string is used in most error messages. In MR11 one has the option of using some other string, (e.g. "+") in those tables. In MR11 one can write: #token Plus ("+") "\+" #token RP ("(") "\(" #token COM ("comment begin") "/\*" A #token statement is allowed to appear in more than one #lexclass with different regular expressions. However, the token name appears only once in the zztokens/token_tbl array. This means that only one substitute can be specified for a given #token name. The second attempt to define a substitute name (different from the first) will result in an error message. #147. (Changed in MR11) Bug in follow set computation There is a bug in 1.33 vanilla and all maintenance releases prior to MR11 in the computation of the follow set. The bug is different than that described in Item #82 and probably more common. It was discovered in the ansi.g grammar while testing the "ambiguity aid" (Item #119). The search for a bug started when the ambiguity aid was unable to discover the actual source of an ambiguity reported by antlr. The problem appears when an optimization of the follow set computation is used inappropriately. The result is that the follow set used is the "worst case". In other words, the error can lead to false reports of ambiguity. The good news is that if you have a grammar in which you have addressed all reported ambiguities you are ok. The bad news is that you may have spent time fixing ambiguities that were not real, or used k=2 when ck=2 might have been sufficient, and so on. The following grammar demonstrates the problem: ------------------------------------------------------------ expr : ID ; start : stmt SEMI ; stmt : CASE expr COLON | expr SEMI | plain_stmt ; plain_stmt : ID COLON ; ------------------------------------------------------------ When compiled with k=1 and ck=2 it will report: warning: alts 2 and 3 of the rule itself ambiguous upon { IDENTIFIER }, { COLON } When antlr analyzes "stmt" it computes the first[1] set of all alternatives. It finds an ambiguity between alts 2 and 3 for ID. It then computes the first[2] set for alternatives 2 and 3 to resolve the ambiguity. In computing the first[2] set of "expr" (which is only one token long) it needs to determine what could follow "expr". Under a certain combination of circumstances antlr forgets that it is trying to analyze "stmt" which can only be followed by SEMI and adds to the first[2] set of "expr" the "global" follow set (including "COLON") which could follow "expr" (under other conditions) in the phrase "CASE expr COLON". #146. (Changed in MR11) Option -treport for locating "difficult" alts It can be difficult to determine which alternatives are causing pccts to work hard to resolve an ambiguity. In some cases the ambiguity is successfully resolved after much CPU time so there is no message at all. A rough measure of the amount of work being peformed which is independent of the CPU speed and system load is the number of tnodes created. Using "-info t" gives information about the total number of tnodes created and the peak number of tnodes. Tree Nodes: peak 1300k created 1416k lost 0 It also puts in the generated C or C++ file the number of tnodes created for a rule (at the end of the rule). However this information is not sufficient to locate the alternatives within a rule which are causing the creation of tnodes. Using: antlr -treport 100000 .... causes antlr to list on stdout any alternatives which require the creation of more than 100,000 tnodes, along with the lookahead sets for those alternatives. The following is a trivial case from the ansi.g grammar which shows the format of the report. This report might be of more interest in cases where 1,000,000 tuples were created to resolve the ambiguity. ------------------------------------------------------------------------- There were 0 tuples whose ambiguity could not be resolved by full lookahead There were 157 tnodes created to resolve ambiguity between: Choice 1: statement/2 line 475 file ansi.g Choice 2: statement/3 line 476 file ansi.g Intersection of lookahead[1] sets: IDENTIFIER Intersection of lookahead[2] sets: LPARENTHESIS COLON AMPERSAND MINUS STAR PLUSPLUS MINUSMINUS ONESCOMPLEMENT NOT SIZEOF OCTALINT DECIMALINT HEXADECIMALINT FLOATONE FLOATTWO IDENTIFIER STRING CHARACTER ------------------------------------------------------------------------- #145. (Documentation) Generation of Expression Trees Item #99 was misleading because it implied that the optimization for tree expressions was available only for trees created by predicate expressions and neglected to mention that it required the use of "-mrhoist on". The optimization applies to tree expressions created for grammars with k>1 and for predicates with lookahead depth >1. In MR11 the optimized version is always used so the -mrhoist on option need not be specified. #144. (Changed in MR11) Incorrect test for exception group In testing for a rule's exception group the label a pointer is compared against '\0'. The intention is "*pointer". Reported by Jeffrey C. Fried (Jeff@Fried.net). #143. (Changed in MR11) Optional ";" at end of #token statement Fixes problem of: #token X "x" << parser action >> Being confused with: #token X "x" <> #142. (Changed in MR11) class BufFileInput subclass of DLGInputStream Alexey Demakov (demakov@kazbek.ispras.ru) has supplied class BufFileInput derived from DLGInputStream which provides a function lookahead(char *string) to test characters in the input stream more than one character ahead. The default amount of lookahead is specified by the constructor and defaults to 8 characters. This does *not* include the one character of lookahead maintained internally by DLG in member "ch" and which is not available for testing via BufFileInput::lookahead(). This is a useful class for overcoming the one-character-lookahead limitation of DLG without resorting to a lexer capable of backtracking (like flex) which is not integrated with antlr as is DLG. There are no restrictions on copying or using BufFileInput.* except that the authorship and related information must be retained in the source code. The class is located in pccts/h/BufFileInput.* of the kit. #141. (Changed in MR11) ZZDEBUG_CONSUME for ANTLRParser::consume() A debug aid has been added to file ANTLRParser::consume() in file AParser.cpp: #ifdef ZZDEBUG_CONSUME_ACTION zzdebug_consume_action(); #endif Suggested by Sramji Ramanathan (ps@kumaran.com). #140. (Changed in MR11) #pred to define predicates +---------------------------------------------------+ | Note: Assume "-prc on" for this entire discussion | +---------------------------------------------------+ A problem with predicates is that each one is regarded as unique and capable of disambiguating cases where two alternatives have identical lookahead. For example: rule : <>? A | <>? A ; will not cause any error messages or warnings to be issued by earlier versions of pccts. To compare the text of the predicates is an incomplete solution. In 1.33MR11 I am introducing the #pred statement in order to solve some problems with predicates. The #pred statement allows one to give a symbolic name to a "predicate literal" or a "predicate expression" in order to refer to it in other predicate expressions or in the rules of the grammar. The predicate literal associated with a predicate symbol is C or C++ code which can be used to test the condition. A predicate expression defines a predicate symbol in terms of other predicate symbols using "!", "&&", and "||". A predicate symbol can be defined in terms of a predicate literal, a predicate expression, or *both*. When a predicate symbol is defined with both a predicate literal and a predicate expression, the predicate literal is used to generate code, but the predicate expression is used to check for two alternatives with identical predicates in both alternatives. Here are some examples of #pred statements: #pred IsLabel <>? #pred IsLocalVar <>? #pred IsGlobalVar <>? #pred IsVar <>? IsLocalVar || IsGlobalVar #pred IsScoped <>? IsLabel || IsLocalVar I hope that the use of EBNF notation to describe the syntax of the #pred statement will not cause problems for my readers (joke). predStatement : "#pred" CapitalizedName ( "<>?" | "<>?" predOrExpr | predOrExpr ) ; predOrExpr : predAndExpr ( "||" predAndExpr ) * ; predAndExpr : predPrimary ( "&&" predPrimary ) * ; predPrimary : CapitalizedName | "!" predPrimary | "(" predOrExpr ")" ; What is the purpose of this nonsense ? To understand how predicate symbols help, you need to realize that predicate symbols are used in two different ways with two different goals. a. Allow simplification of predicates which have been combined during predicate hoisting. b. Allow recognition of identical predicates which can't disambiguate alternatives with common lookahead. First we will discuss goal (a). Consider the following rule: rule0: rule1 | ID | ... ; rule1: rule2 | rule3 ; rule2: <>? ID ; rule3: <>? ID ; When the predicates in rule2 and rule3 are combined by hoisting to create a prediction expression for rule1 the result is: if ( LA(1)==ID && ( isX(LATEXT(1) || !isX(LATEXT(1) ) ) { rule1(); ... This is inefficient, but more importantly, can lead to false assumptions that the predicate expression distinguishes the rule1 alternative with some other alternative with lookahead ID. In MR11 one can write: #pred IsX <>? ... rule2: <>? ID ; rule3: <>? ID ; During hoisting MR11 recognizes this as a special case and eliminates the predicates. The result is a prediction expression like the following: if ( LA(1)==ID ) { rule1(); ... Please note that the following cases which appear to be equivalent *cannot* be simplified by MR11 during hoisting because the hoisting logic only checks for a "!" in the predicate action, not in the predicate expression for a predicate symbol. *Not* equivalent and is not simplified during hoisting: #pred IsX <>? #pred NotX <>? ... rule2: <>? ID ; rule3: <>? ID ; *Not* equivalent and is not simplified during hoisting: #pred IsX <>? #pred NotX !IsX ... rule2: <>? ID ; rule3: <>? ID ; Now we will discuss goal (b). When antlr discovers that there is a lookahead ambiguity between two alternatives it attempts to resolve the ambiguity by searching for predicates in both alternatives. In the past any predicate would do, even if the same one appeared in both alternatives: rule: <>? X | <>? X ; The #pred statement is a start towards solving this problem. During ambiguity resolution (*not* predicate hoisting) the predicates for the two alternatives are expanded and compared. Consider the following example: #pred Upper <>? #pred Lower <>? #pred Alpha <>? Upper || Lower rule0: rule1 | <>? ID ; rule1: | rule2 | rule3 ... ; rule2: <>? ID; rule3: <>? ID; The definition of #pred Alpha expresses: a. to test the predicate use the C code "isAlpha(LATEXT(1))" b. to analyze the predicate use the information that Alpha is equivalent to the union of Upper and Lower, During ambiguity resolution the definition of Alpha is expanded into "Upper || Lower" and compared with the predicate in the other alternative, which is also "Upper || Lower". Because they are identical MR11 will report a problem. ------------------------------------------------------------------------- t10.g, line 5: warning: the predicates used to disambiguate rule rule0 (file t10.g alt 1 line 5 and alt 2 line 6) are identical when compared without context and may have no resolving power for some lookahead sequences. ------------------------------------------------------------------------- If you use the "-info p" option the output file will contain: +----------------------------------------------------------------------+ |#if 0 | | | |The following predicates are identical when compared without | | lookahead context information. For some ambiguous lookahead | | sequences they may not have any power to resolve the ambiguity. | | | |Choice 1: rule0/1 alt 1 line 5 file t10.g | | | | The original predicate for choice 1 with available context | | information: | | | | OR expr | | | | pred << Upper>>? | | depth=k=1 rule rule2 line 14 t10.g | | set context: | | ID | | | | pred << Lower>>? | | depth=k=1 rule rule3 line 15 t10.g | | set context: | | ID | | | | The predicate for choice 1 after expansion (but without context | | information): | | | | OR expr | | | | pred << isUpper(LATEXT(1))>>? | | depth=k=1 rule line 1 t10.g | | | | pred << isLower(LATEXT(1))>>? | | depth=k=1 rule line 2 t10.g | | | | | |Choice 2: rule0/2 alt 2 line 6 file t10.g | | | | The original predicate for choice 2 with available context | | information: | | | | pred << Alpha>>? | | depth=k=1 rule rule0 line 6 t10.g | | set context: | | ID | | | | The predicate for choice 2 after expansion (but without context | | information): | | | | OR expr | | | | pred << isUpper(LATEXT(1))>>? | | depth=k=1 rule line 1 t10.g | | | | pred << isLower(LATEXT(1))>>? | | depth=k=1 rule line 2 t10.g | | | | | |#endif | +----------------------------------------------------------------------+ The comparison of the predicates for the two alternatives takes place without context information, which means that in some cases the predicates will be considered identical even though they operate on disjoint lookahead sets. Consider: #pred Alpha rule1: <>? ID | <>? Label ; Because the comparison of predicates takes place without context these will be considered identical. The reason for comparing without context is that otherwise it would be necessary to re-evaluate the entire predicate expression for each possible lookahead sequence. This would require more code to be written and more CPU time during grammar analysis, and it is not yet clear whether anyone will even make use of the new #pred facility. A temporary workaround might be to use different #pred statements for predicates you know have different context. This would avoid extraneous warnings. The above example might be termed a "false positive". Comparison without context will also lead to "false negatives". Consider the following example: #pred Alpha #pred Beta rule1: <>? A | rule2 ; rule2: <>? A | <>? B ; The predicate used for alt 2 of rule1 is (Alpha || Beta). This appears to be different than the predicate Alpha used for alt1. However, the context of Beta is B. Thus when the lookahead is A Beta will have no resolving power and Alpha will be used for both alternatives. Using the same predicate for both alternatives isn't very helpful, but this will not be detected with 1.33MR11. To properly handle this the predicate expression would have to be evaluated for each distinct lookahead context. To determine whether two predicate expressions are identical is difficult. The routine may fail to identify identical predicates. The #pred feature also compares predicates to see if a choice between alternatives which is resolved by a predicate which makes the second choice unreachable. Consider the following example: #pred A <>? #pred B <>? #pred A_or_B A || B r : s | t ; s : <>? ID ; t : <>? ID ; ---------------------------------------------------------------------------- t11.g, line 5: warning: the predicate used to disambiguate the first choice of rule r (file t11.g alt 1 line 5 and alt 2 line 6) appears to "cover" the second predicate when compared without context. The second predicate may have no resolving power for some lookahead sequences. ---------------------------------------------------------------------------- #139. (Changed in MR11) Problem with -gp in C++ mode The -gp option to add a prefix to rule names did not work in C++ mode. This has been fixed. Reported by Alexey Demakov (demakov@kazbek.ispras.ru). #138. (Changed in MR11) Additional makefiles for non-MSVC++ MS systems Sramji Ramanathan (ps@kumaran.com) has supplied makefiles for building antlr and dlg with Win95/NT development tools that are not based on MSVC5. They are pccts/antlr/AntlrMS.mak and pccts/dlg/DlgMS.mak. The first line of the makefiles require a definition of PCCTS_HOME. These are in additiion to the AntlrMSVC50.* and DlgMSVC50.* supplied by Jeff Vincent (JVincent@novell.com). #137. (Changed in MR11) Token getType(), getText(), getLine() const members -------------------------------------------------------------------- If you use ANTLRCommonToken this change probably does not affect you. -------------------------------------------------------------------- For a long time it has bothered me that these accessor functions in ANTLRAbstractToken were not const member functions. I have refrained from changing them because it require users to modify existing token class definitions which are derived directly from ANTLRAbstractToken. I think it is now time. For those who are not used to C++, a "const member function" is a member function which does not modify its own object - the thing to which "this" points. This is quite different from a function which does not modify its arguments Most token definitions based on ANTLRAbstractToken have something like the following in order to create concrete definitions of the pure virtual methods in ANTLRAbstractToken: class MyToken : public ANTLRAbstractToken { ... ANTLRTokenType getType() {return _type; } int getLine() {return _line; } ANTLRChar * getText() {return _text; } ... } The required change is simply to put "const" following the function prototype in the header (.h file) and the definition file (.cpp if it is not inline): class MyToken : public ANTLRAbstractToken { ... ANTLRTokenType getType() const {return _type; } int getLine() const {return _line; } ANTLRChar * getText() const {return _text; } ... } This was originally proposed a long time ago by Bruce Guenter (bruceg@qcc.sk.ca). #136. (Changed in MR11) Added getLength() to ANTLRCommonToken Classes ANTLRCommonToken and ANTLRCommonTokenNoRefCountToken now have a member function: int getLength() const { return strlen(getText()) } Suggested by Sramji Ramanathan (ps@kumaran.com). #135. (Changed in MR11) Raised antlr's own default ZZLEXBUFSIZE to 8k #134a. (ansi_mr10.zip) T.J. Parr's ANSI C grammar made 1.33MR11 compatible There is a typographical error in the definition of BITWISEOREQ: #token BITWISEOREQ "!=" should be "\|=" When this change is combined with the bugfix to the follow set cache problem (Item #147) and a minor rearrangement of the grammar (Item #134b) it becomes a k=1 ck=2 grammar. #134b. (ansi_mr10.zip) T.J. Parr's ANSI C grammar made 1.33MR11 compatible The following changes were made in the ansi.g grammar (along with using -mrhoist on): ansi.g ====== void tracein(char *) ====> void tracein(const char *) void traceout(char *) ====> void traceout(const char *) getType()==IDENTIFIER ? isTypeName(LT(1)->getText()) : 1>>? ====> <getText())>>? <<(LT(1)->getType()==LPARENTHESIS && LT(2)->getType()==IDENTIFIER) ? \ isTypeName(LT(2)->getText()) : 1>>? ====> (LPARENTHESIS IDENTIFIER)? => <getText())>>? <<(LT(1)->getType()==LPARENTHESIS && LT(2)->getType()==IDENTIFIER) ? \ isTypeName(LT(2)->getText()) : 1>>? ====> (LPARENTHESIS IDENTIFIER)? => <getText())>>? added to init(): traceOptionValueDefault=0; added to init(): traceOption(-1); change rule "statement": statement : plain_label_statement | case_label_statement | <<;>> expression SEMICOLON | compound_statement | selection_statement | iteration_statement | jump_statement | SEMICOLON ; plain_label_statement : IDENTIFIER COLON statement ; case_label_statement : CASE constant_expression COLON statement | DEFAULT COLON statement ; support.cpp =========== void tracein(char *) ====> void tracein(const char *) void traceout(char *) ====> void traceout(const char *) added to tracein(): ANTLRParser::tracein(r); // call superclass method added to traceout(): ANTLRParser::traceout(r); // call superclass method Makefile ======== added to AFLAGS: -mrhoist on -prc on #133. (Changed in 1.33MR11) Make trace options public in ANTLRParser In checking T.J. Parr's ANSI C grammar for compatibility with 1.33MR11 discovered that it was inconvenient to have the trace facilities with protected access. #132. (Changed in 1.33MR11) Recognition of identical predicates in alts Prior to 1.33MR11, there would be no ambiguity warning when the very same predicate was used to disambiguate both alternatives: test: ref B | ref C ; ref : <>? A In 1.33MR11 this will cause the warning: warning: the predicates used to disambiguate rule test (file v98.g alt 1 line 1 and alt 2 line 2) are identical and have no resolving power ----------------- Note ----------------- This is different than the following case test: <>? A B | <>? A C ; In this case there are two distinct predicates which have exactly the same text. In the first example there are two references to the same predicate. The problem represented by this grammar will be addressed later. #131. (Changed in 1.33MR11) Case insensitive command line options Command line switches like "-CC" and keywords like "on", "off", and "stdin" are no longer case sensitive in antlr, dlg, and sorcerer. #130. (Changed in 1.33MR11) Changed ANTLR_VERSION to int from string The ANTLR_VERSION was not an integer, making it difficult to perform conditional compilation based on the antlr version. Henceforth, ANTLR_VERSION will be: (base_version * 10000) + release number thus 1.33MR11 will be: 133*100+11 = 13311 Suggested by Rainer Janssen (Rainer.Janssen@Informatik.Uni-Oldenburg.DE). #129. (Changed in 1.33MR11) Addition of ANTLR_VERSION to .h The following code is now inserted into .h amd stdpccts.h: #ifndef ANTLR_VERSION #define ANTLR_VERSION 13311 #endif Suggested by Rainer Janssen (Rainer.Janssen@Informatik.Uni-Oldenburg.DE) #128. (Changed in 1.33MR11) Redundant predicate code in (<>? ...)+ Prior to 1.33MR11, the following grammar would generate redundant tests for the "while" condition. rule2 : (<>? X)+ X | B ; The code would resemble: if (LA(1)==X) { if (pred) { do { if (!pred) {zzfailed_pred(" pred");} zzmatch(X); zzCONSUME; } while (LA(1)==X && pred && pred); } else {... With 1.33MR11 the redundant predicate test is omitted. #127. (Changed in 1.33MR11) Count Syntax Errors Count DLG Errors ------------------- ---------------- C++ mode ANTLRParser:: DLGLexerBase:: syntaxErrCount lexErrCount C mode zzSyntaxErrCount zzLexErrCount The C mode variables are global and initialized to 0. They are *not* reset to 0 automatically when antlr is restarted. The C++ mode variables are public. They are initialized to 0 by the constructors. They are *not* reset to 0 by the ANTLRParser::init() method. Suggested by Reinier van den Born (reinier@vnet.ibm.com). #126. (Changed in 1.33MR11) Addition of #first <<...>> The #first <<...>> inserts the specified text in the output files before any other #include statements required by pccts. The only things before the #first text are comments and a #define ANTLR_VERSION. Requested by and Esa Pulkkinen (esap@cs.tut.fi) and Alexin Zoltan (alexin@inf.u-szeged.hu). #125. (Changed in 1.33MR11) Lookahead for (guard)? && <

    >? predicates When implementing the new style of guard predicate (Item #113) in 1.33MR10 I decided to temporarily ignore the problem of computing the "narrowest" lookahead context. Consider the following k=1 grammar: start : a | b ; a : (A)? && <>? ab ; b : (B)? && <>? ab ; ab : A | B ; In MR10 the context for both "a" and "b" was {A B} because this is the first set of rule "ab". Normally, this is not a problem because the predicate which follows the guard inhibits any ambiguity report by antlr. In MR11 the first set for rule "a" is {A} and for rule "b" it is {B}. #124. A Note on the New "&&" Style Guarded Predicates I've been asked several times, "What is the difference between the old "=>" style guard predicates and the new style "&&" guard predicates, and how do you choose one over the other" ? The main difference is that the "=>" does not apply the predicate if the context guard doesn't match, whereas the && form always does. What is the significance ? If you have a predicate which is not on the "leading edge" it is cannot be hoisted. Suppose you need a predicate that looks at LA(2). You must introduce it manually. The classic example is: castExpr : LP typeName RP | .... ; typeName : <>? ID | STRUCT ID ; The problem is that isTypeName() isn't on the leading edge of typeName, so it won't be hoisted into castExpr to help make a decision on which production to choose. The *first* attempt to fix it is this: castExpr : <>? LP typeName RP | .... ; Unfortunately, this won't work because it ignores the problem of STRUCT. The solution is to apply isTypeName() in castExpr if LA(2) is an ID and don't apply it when LA(2) is STRUCT: castExpr : (LP ID)? => <>? LP typeName RP | .... ; In conclusion, the "=>" style guarded predicate is useful when: a. the tokens required for the predicate are not on the leading edge b. there are alternatives in the expression selected by the predicate for which the predicate is inappropriate If (b) were false, then one could use a simple predicate (assuming "-prc on"): castExpr : <>? LP typeName RP | .... ; typeName : <>? ID ; So, when do you use the "&&" style guarded predicate ? The new-style "&&" predicate should always be used with predicate context. The context guard is in ADDITION to the automatically computed context. Thus it useful for predicates which depend on the token type for reasons other than context. The following example is contributed by Reinier van den Born (reinier@vnet.ibm.com). +-------------------------------------------------------------------------+ | This grammar has two ways to call functions: | | | | - a "standard" call syntax with parens and comma separated args | | - a shell command like syntax (no parens and spacing separated args) | | | | The former also allows a variable to hold the name of the function, | | the latter can also be used to call external commands. | | | | The grammar (simplified) looks like this: | | | | fun_call : ID "(" { expr ("," expr)* } ")" | | /* ID is function name */ | | | "@" ID "(" { expr ("," expr)* } ")" | | /* ID is var containing fun name */ | | ; | | | | command : ID expr* /* ID is function name */ | | | path expr* /* path is external command name */ | | ; | | | | path : ID /* left out slashes and such */ | | | "@" ID /* ID is environment var */ | | ; | | | | expr : .... | | | "(" expr ")"; | | | | call : fun_call | | | command | | ; | | | | Obviously the call is wildly ambiguous. This is more or less how this | | is to be resolved: | | | | A call begins with an ID or an @ followed by an ID. | | | | If it is an ID and if it is an ext. command name -> command | | if followed by a paren -> fun_call | | otherwise -> command | | | | If it is an @ and if the ID is a var name -> fun_call | | otherwise -> command | | | | One can implement these rules quite neatly using && predicates: | | | | call : ("@" ID)? && <>? fun_call | | | (ID)? && <>? command | | | (ID "(")? fun_call | | | command | | ; | | | | This can be done better, so it is not an ideal example, but it | | conveys the principle. | +-------------------------------------------------------------------------+ #123. (Changed in 1.33MR11) Correct definition of operators in ATokPtr.h The return value of operators in ANTLRTokenPtr: changed: unsigned ... operator !=(...) to: int ... operator != (...) changed: unsigned ... operator ==(...) to: int ... operator == (...) Suggested by R.A. Nelson (cowboy@VNET.IBM.COM) #122. (Changed in 1.33MR11) Member functions to reset DLG in C++ mode void DLGFileReset(FILE *f) { input = f; found_eof = 0; } void DLGStringReset(DLGChar *s) { input = s; p = &input[0]; } Supplied by R.A. Nelson (cowboy@VNET.IBM.COM) #121. (Changed in 1.33MR11) Another attempt to fix -o (output dir) option Another attempt is made to improve the -o option of antlr, dlg, and sorcerer. This one by JVincent (JVincent@novell.com). The current rule: a. If -o is not specified than any explicit directory names are retained. b. If -o is specified than the -o directory name overrides any explicit directory names. c. The directory name of the grammar file is *not* stripped to create the main output file. However it is stil subject to override by the -o directory name. #120. (Changed in 1.33MR11) "-info f" output to stdout rather than stderr Added option 0 (e.g. "-info 0") which is a noop. #119. (Changed in 1.33MR11) Ambiguity aid for grammars The user can ask for additional information on ambiguities reported by antlr to stdout. At the moment, only one ambiguity report can be created in an antlr run. This feature is enabled using the "-aa" (Ambiguity Aid) option. The following options control the reporting of ambiguities: -aa ruleName Selects reporting by name of rule -aa lineNumber Selects reporting by line number (file name not compared) -aam Selects "multiple" reporting for a token in the intersection set of the alternatives. For instance, the token ID may appear dozens of times in various paths as the program explores the rules which are reachable from the point of an ambiguity. With option -aam every possible path the search program encounters is reported. Without -aam only the first encounter is reported. This may result in incomplete information, but the information may be sufficient and much shorter. -aad depth Selects the depth of the search. The default value is 1. The number of paths to be searched, and the size of the report can grow geometrically with the -ck value if a full search for all contributions to the source of the ambiguity is explored. The depth represents the number of tokens in the lookahead set which are matched against the set of ambiguous tokens. A depth of 1 means that the search stops when a lookahead sequence of just one token is matched. A k=1 ck=6 grammar might generate 5,000 items in a report if a full depth 6 search is made with the Ambiguity Aid. The source of the problem may be in the first token and obscured by the volume of data - I hesitate to call it information. When the user selects a depth > 1, the search is first performed at depth=1 for both alternatives, then depth=2 for both alternatives, etc. Sample output for rule grammar in antlr.g itself: +---------------------------------------------------------------------+ | Ambiguity Aid | | | | Choice 1: grammar/70 line 632 file a.g | | Choice 2: grammar/82 line 644 file a.g | | | | Intersection of lookahead[1] sets: | | | | "\}" "class" "#errclass" "#tokclass" | | | | Choice:1 Depth:1 Group:1 ("#errclass") | | 1 in (...)* block grammar/70 line 632 a.g | | 2 to error grammar/73 line 635 a.g | | 3 error error/1 line 894 a.g | | 4 #token "#errclass" error/2 line 895 a.g | | | | Choice:1 Depth:1 Group:2 ("#tokclass") | | 2 to tclass grammar/74 line 636 a.g | | 3 tclass tclass/1 line 937 a.g | | 4 #token "#tokclass" tclass/2 line 938 a.g | | | | Choice:1 Depth:1 Group:3 ("class") | | 2 to class_def grammar/75 line 637 a.g | | 3 class_def class_def/1 line 669 a.g | | 4 #token "class" class_def/3 line 671 a.g | | | | Choice:1 Depth:1 Group:4 ("\}") | | 2 #token "\}" grammar/76 line 638 a.g | | | | Choice:2 Depth:1 Group:5 ("#errclass") | | 1 in (...)* block grammar/83 line 645 a.g | | 2 to error grammar/93 line 655 a.g | | 3 error error/1 line 894 a.g | | 4 #token "#errclass" error/2 line 895 a.g | | | | Choice:2 Depth:1 Group:6 ("#tokclass") | | 2 to tclass grammar/94 line 656 a.g | | 3 tclass tclass/1 line 937 a.g | | 4 #token "#tokclass" tclass/2 line 938 a.g | | | | Choice:2 Depth:1 Group:7 ("class") | | 2 to class_def grammar/95 line 657 a.g | | 3 class_def class_def/1 line 669 a.g | | 4 #token "class" class_def/3 line 671 a.g | | | | Choice:2 Depth:1 Group:8 ("\}") | | 2 #token "\}" grammar/96 line 658 a.g | +---------------------------------------------------------------------+ For a linear lookahead set ambiguity (where k=1 or for k>1 but when all lookahead sets [i] with i>? A ; c : A ; Prior to 1.33MR10 the code generated for "start" would resemble: while { if (LA(1)==A && (!LA(1)==A || isUpper())) { a(); } }; This code is wrong because it makes rule "c" unreachable from "start". The essence of the problem is that antlr fails to recognize that there can be a valid alternative within "a" even when the predicate <>? is false. In 1.33MR10 with -mrhoist the hoisting of the predicate into "start" is suppressed because it recognizes that "c" can cover all the cases where the predicate is false: while { if (LA(1)==A) { a(); } }; With the antlr "-info p" switch the user will receive information about the predicate suppression in the generated file: -------------------------------------------------------------- #if 0 Hoisting of predicate suppressed by alternative without predicate. The alt without the predicate includes all cases where the predicate is false. WITH predicate: line 7 v1.g WITHOUT predicate: line 7 v1.g The context set for the predicate: A The lookahead set for the alt WITHOUT the semantic predicate: A The predicate: pred << isUpper(LATEXT(1))>>? depth=k=1 rule b line 9 v1.g set context: A tree context: null Chain of referenced rules: #0 in rule start (line 5 v1.g) to rule a #1 in rule a (line 7 v1.g) #endif -------------------------------------------------------------- A predicate can be suppressed by a combination of alternatives which, taken together, cover a predicate: start : (a)* "@" ; a : b | ca | cb | cc ; b : <>? ( A | B | C ) ; ca : A ; cb : B ; cc : C ; Consider a more complex example in which "c" covers only part of a predicate: start : (a)* "@" ; a : b | c ; b : <>? ( A | X ); c : A ; Prior to 1.33MR10 the code generated for "start" would resemble: while { if ( (LA(1)==A || LA(1)==X) && (! (LA(1)==A || LA(1)==X) || isUpper()) { a(); } }; With 1.33MR10 and -mrhoist the predicate context is restricted to the non-covered lookahead. The code resembles: while { if ( (LA(1)==A || LA(1)==B) && (! (LA(1)==X) || isUpper()) { a(); } }; With the antlr "-info p" switch the user will receive information about the predicate restriction in the generated file: -------------------------------------------------------------- #if 0 Restricting the context of a predicate because of overlap in the lookahead set between the alternative with the semantic predicate and one without Without this restriction the alternative without the predicate could not be reached when input matched the context of the predicate and the predicate was false. WITH predicate: line 11 v4.g WITHOUT predicate: line 12 v4.g The original context set for the predicate: A X The lookahead set for the alt WITHOUT the semantic predicate: A The intersection of the two sets A The original predicate: pred << isUpper(LATEXT(1))>>? depth=k=1 rule b line 15 v4.g set context: A X tree context: null The new (modified) form of the predicate: pred << isUpper(LATEXT(1))>>? depth=k=1 rule b line 15 v4.g set context: X tree context: null #endif -------------------------------------------------------------- The bad news about -mrhoist: (a) -mrhoist does not analyze predicates with lookahead depth > 1. (b) -mrhoist does not look past a guarded predicate to find context which might cover other predicates. For these cases you might want to use syntactic predicates. When a semantic predicate fails during guess mode the guess fails and the next alternative is tried. Limitation (a) is illustrated by the following example: start : (stmt)* EOF ; stmt : cast | expr ; cast : <>? LP ID RP ; expr : LP ID RP ; This is not much different from the first example, except that it requires two tokens of lookahead context to determine what to do. This predicate is NOT suppressed because the current version is unable to handle predicates with depth > 1. A predicate can be combined with other predicates during hoisting. In those cases the depth=1 predicates are still handled. Thus, in the following example the isUpper() predicate will be suppressed by line #4 when hoisted from "bizarre" into "start", but will still be present in "bizarre" in order to predict "stmt". start : (bizarre)* EOF ; // #1 // #2 bizarre : stmt // #3 | A // #4 ; stmt : cast | expr ; cast : <>? LP ID RP ; expr : LP ID RP ; | <>? A Limitation (b) is illustrated by the following example of a context guarded predicate: rule : (A)? <

    >? // #1 (A // #2 |B // #3 ) // #4 | <> B // #5 ; Recall that this means that when the lookahead is NOT A then the predicate "p" is ignored and it attempts to match "A|B". Ideally, the "B" at line #3 should suppress predicate "q". However, the current version does not attempt to look past the guard predicate to find context which might suppress other predicates. In some cases -mrhoist will lead to the reporting of ambiguities which were not visible before: start : (a)* "@"; a : bc | d; bc : b | c ; b : <>? A; c : A ; d : A ; In this case there is a true ambiguity in "a" between "bc" and "d" which can both match "A". Without -mrhoist the predicate in "b" is hoisted into "a" and there is no ambiguity reported. However, with -mrhoist, the predicate in "b" is suppressed by "c" (as it should be) making the ambiguity in "a" apparent. The motivations for these changes were hoisting problems reported by Reinier van den Born (reinier@vnet.ibm.com) and several others. #116. (Changed in 1.33MR10) C++ mode: tracein/traceout rule name is (const char *) The prototype for C++ mode routine tracein (and traceout) has changed from "char *" to "const char *". #115. (Changed in 1.33MR10) Using guess mode with exception handlers in C mode The definition of the C mode macros zzmatch_wsig and zzsetmatch_wsig neglected to consider guess mode. When control passed to the rule's parse exception handler the routine would exit without ever closing the guess block. This would lead to unpredictable behavior. In 1.33MR10 the behavior of exceptions in C mode and C++ mode should be identical. #114. (Changed in 1.33MR10) difference in [zz]resynch() between C and C++ modes There was a slight difference in the way C and C++ mode resynchronized following a parsing error. The C routine would sometimes skip an extra token before attempting to resynchronize. The C routine was changed to match the C++ routine. #113. (Changed in 1.33MR10) new context guarded pred: (g)? && <

    >? expr The existing context guarded predicate: rule : (guard)? => <

    >? expr | next_alternative ; generates code which resembles: if (lookahead(expr) && (!guard || pred)) { expr() } else .... This is not suitable for some applications because it allows expr() to be invoked when the predicate is false. This is intentional because it is meant to mimic automatically computed predicate context. The new context guarded predicate uses the guard information differently because it has a different goal. Consider: rule : (guard)? && <

    >? expr | next_alternative ; The new style of context guarded predicate is equivalent to: rule : <>? expr | next_alternative ; It generates code which resembles: if (lookahead(expr) && guard && pred) { expr(); } else ... Both forms of guarded predicates severely restrict the form of the context guard: it can contain no rule references, no (...)*, no (...)+, and no {...}. It may contain token and token class references, and alternation ("|"). Addition for 1.33MR11: in the token expression all tokens must be at the same height of the token tree: (A ( B | C))? && ... is ok (all height 2) (A ( B | ))? && ... is not ok (some 1, some 2) (A B C D | E F G H)? && ... is ok (all height 4) (A B C D | E )? && ... is not ok (some 4, some 1) This restriction is required in order to properly compute the lookahead set for expressions like: rule1 : (A B C)? && <>? rule2 ; rule2 : (A|X) (B|Y) (C|Z); This addition was suggested by Rienier van den Born (reinier@vnet.ibm.com) #112. (Changed in 1.33MR10) failed validation predicate in C guess mode John Lilley (jlilley@empathy.com) suggested that failed validation predicates abort a guess rather than reporting a failed error. This was installed in C++ mode (Item #4). Only now was it noticed that the fix was never installed for C mode. #111. (Changed in 1.33MR10) moved zzTRACEIN to before init action When the antlr -gd switch is present antlr generates calls to zzTRACEIN at the start of a rule and zzTRACEOUT at the exit from a rule. Prior to 1.33MR10 Tthe call to zzTRACEIN was after the init-action, which could cause confusion because the init-actions were reported with the name of the enclosing rule, rather than the active rule. #110. (Changed in 1.33MR10) antlr command line copied to generated file The antlr command line is now copied to the generated file near the start. #109. (Changed in 1.33MR10) improved trace information The quality of the trace information provided by the "-gd" switch has been improved significantly. Here is an example of the output from a test program. It shows the rule name, the first token of lookahead, the call depth, and the guess status: exit rule gusxx {"?"} depth 2 enter rule gusxx {"?"} depth 2 enter rule gus1 {"o"} depth 3 guessing guess done - returning to rule gus1 {"o"} at depth 3 (guess mode continues - an enclosing guess is still active) guess done - returning to rule gus1 {"Z"} at depth 3 (guess mode continues - an enclosing guess is still active) exit rule gus1 {"Z"} depth 3 guessing guess done - returning to rule gusxx {"o"} at depth 2 (guess mode ends) enter rule gus1 {"o"} depth 3 guess done - returning to rule gus1 {"o"} at depth 3 (guess mode ends) guess done - returning to rule gus1 {"Z"} at depth 3 (guess mode ends) exit rule gus1 {"Z"} depth 3 line 1: syntax error at "Z" missing SC ... Rule trace reporting is controlled by the value of the integer [zz]traceOptionValue: when it is positive tracing is enabled, otherwise it is disabled. Tracing during guess mode is controlled by the value of the integer [zz]traceGuessOptionValue. When it is positive AND [zz]traceOptionValue is positive rule trace is reported in guess mode. The values of [zz]traceOptionValue and [zz]traceGuessOptionValue can be adjusted by subroutine calls listed below. Depending on the presence or absence of the antlr -gd switch the variable [zz]traceOptionValueDefault is set to 0 or 1. When the parser is initialized or [zz]traceReset() is called the value of [zz]traceOptionValueDefault is copied to [zz]traceOptionValue. The value of [zz]traceGuessOptionValue is always initialzed to 1, but, as noted earlier, nothing will be reported unless [zz]traceOptionValue is also positive. When the parser state is saved/restored the value of the trace variables are also saved/restored. If a restore causes a change in reporting behavior from on to off or vice versa this will be reported. When the -gd option is selected, the macro "#define zzTRACE_RULES" is added to appropriate output files. C++ mode -------- int traceOption(int delta) int traceGuessOption(int delta) void traceReset() int traceOptionValueDefault C mode -------- int zzTraceOption(int delta) int zzTraceGuessOption(int delta) void zzTraceReset() int zzTraceOptionValueDefault The argument "delta" is added to the traceOptionValue. To turn on trace when inside a particular rule one: rule : <> ( rest-of-rule ) <> ; /* fail clause */ <> One can use the same idea to turn *off* tracing within a rule by using a delta of (-1). An improvement in the rule trace was suggested by Sramji Ramanathan (ps@kumaran.com). #108. A Note on Deallocation of Variables Allocated in Guess Mode NOTE ------------------------------------------------------ This mechanism only works for heap allocated variables ------------------------------------------------------ The rewrite of the trace provides the machinery necessary to properly free variables or undo actions following a failed guess. The macro zzUSER_GUESS_HOOK(guessSeq,zzrv) is expanded as part of the zzGUESS macro. When a guess is opened the value of zzrv is 0. When a longjmp() is executed to undo the guess, the value of zzrv will be 1. The macro zzUSER_GUESS_DONE_HOOK(guessSeq) is expanded as part of the zzGUESS_DONE macro. This is executed whether the guess succeeds or fails as part of closing the guess. The guessSeq is a sequence number which is assigned to each guess and is incremented by 1 for each guess which becomes active. It is needed by the user to associate the start of a guess with the failure and/or completion (closing) of a guess. Guesses are nested. They must be closed in the reverse of the order that they are opened. In order to free memory used by a variable during a guess a user must write a routine which can be called to register the variable along with the current guess sequence number provided by the zzUSER_GUESS_HOOK macro. If the guess fails, all variables tagged with the corresponding guess sequence number should be released. This is ugly, but it would require a major rewrite of antlr 1.33 to use some mechanism other than setjmp()/longjmp(). The order of calls for a *successful* guess would be: zzUSER_GUESS_HOOK(guessSeq,0); zzUSER_GUESS_DONE_HOOK(guessSeq); The order of calls for a *failed* guess would be: zzUSER_GUESS_HOOK(guessSeq,0); zzUSER_GUESS_HOOK(guessSeq,1); zzUSER_GUESS_DONE_HOOK(guessSeq); The default definitions of these macros are empty strings. Here is an example in C++ mode. The zzUSER_GUESS_HOOK and zzUSER_GUESS_DONE_HOOK macros and myGuessHook() routine can be used without change in both C and C++ versions. ---------------------------------------------------------------------- << #include "AToken.h" typedef ANTLRCommonToken ANTLRToken; #include "DLGLexer.h" int main() { { DLGFileInput in(stdin); DLGLexer lexer(&in,2000); ANTLRTokenBuffer pipe(&lexer,1); ANTLRCommonToken aToken; P parser(&pipe); lexer.setToken(&aToken); parser.init(); parser.start(); }; fclose(stdin); fclose(stdout); return 0; } >> << char *s=NULL; #undef zzUSER_GUESS_HOOK #define zzUSER_GUESS_HOOK(guessSeq,zzrv) myGuessHook(guessSeq,zzrv); #undef zzUSER_GUESS_DONE_HOOK #define zzUSER_GUESS_DONE_HOOK(guessSeq) myGuessHook(guessSeq,2); void myGuessHook(int guessSeq,int zzrv) { if (zzrv == 0) { fprintf(stderr,"User hook: starting guess #%d\n",guessSeq); } else if (zzrv == 1) { free (s); s=NULL; fprintf(stderr,"User hook: failed guess #%d\n",guessSeq); } else if (zzrv == 2) { free (s); s=NULL; fprintf(stderr,"User hook: ending guess #%d\n",guessSeq); }; } >> #token A "a" #token "[\t \ \n]" <> class P { start : (top)+ ; top : (which) ? <> | other <> ; <> which : which2 ; which2 : which3 ; which3 : (label)? <> | (global)? <> | (exclamation)? <> ; label : <getText());>> A ":" ; global : <getText());>> A "::" ; exclamation : <getText());>> A "!" ; other : <getText());>> "other" ; } ---------------------------------------------------------------------- This is a silly example, but illustrates the idea. For the input "a ::" with tracing enabled the output begins: ---------------------------------------------------------------------- enter rule "start" depth 1 enter rule "top" depth 2 User hook: starting guess #1 enter rule "which" depth 3 guessing enter rule "which2" depth 4 guessing enter rule "which3" depth 5 guessing User hook: starting guess #2 enter rule "label" depth 6 guessing guess failed User hook: failed guess #2 guess done - returning to rule "which3" at depth 5 (guess mode continues - an enclosing guess is still active) User hook: ending guess #2 User hook: starting guess #3 enter rule "global" depth 6 guessing exit rule "global" depth 6 guessing guess done - returning to rule "which3" at depth 5 (guess mode continues - an enclosing guess is still active) User hook: ending guess #3 enter rule "global" depth 6 guessing exit rule "global" depth 6 guessing exit rule "which3" depth 5 guessing exit rule "which2" depth 4 guessing exit rule "which" depth 3 guessing guess done - returning to rule "top" at depth 2 (guess mode ends) User hook: ending guess #1 enter rule "which" depth 3 ..... ---------------------------------------------------------------------- Remember: (a) Only init-actions are executed during guess mode. (b) A rule can be invoked multiple times during guess mode. (c) If the guess succeeds the rule will be called once more without guess mode so that normal actions will be executed. This means that the init-action might need to distinguish between guess mode and non-guess mode using the variable [zz]guessing. #107. (Changed in 1.33MR10) construction of ASTs in guess mode Prior to 1.33MR10, when using automatic AST construction in C++ mode for a rule, an AST would be constructed for elements of the rule even while in guess mode. In MR10 this no longer occurs. #106. (Changed in 1.33MR10) guess variable confusion In C++ mode a guess which failed always restored the parser state using zzGUESS_DONE as part of zzGUESS_FAIL. Prior to 1.33MR10, C mode required an explicit call to zzGUESS_DONE after the call to zzGUESS_FAIL. Consider: rule : (alpha)? beta | ... ; The generated code resembles: zzGUESS if (!zzrv && LA(1)==ID) { <==== line #1 alpha zzGUESS_DONE beta } else { if (! zzrv) zzGUESS_DONE <==== line #2a .... However, in some cases line #2 was rendered: if (guessing) zzGUESS_DONE <==== line #2b This would work for simple test cases, but would fail in some cases where there was a guess while another guess was active. One kind of failure would be to match up the zzGUESS_DONE at line #2b with the "outer" guess which was still active. The outer guess would "succeed" when only the inner guess should have succeeded. In 1.33MR10 the behavior of zzGUESS and zzGUESS_FAIL in C and and C++ mode should be identical. The same problem appears in 1.33 vanilla in some places. For example: start : { (sub)? } ; or: start : ( B | ( sub )? | C )+ ; generates incorrect code. The general principle is: (a) use [zz]guessing only when deciding between a call to zzFAIL or zzGUESS_FAIL (b) use zzrv in all other cases This problem was discovered while testing changes to item #105. I believe this is now fixed. My apologies. #105. (Changed in 1.33MR10) guess block as single alt of (...)+ Prior to 1.33MR10 the following constructs: rule_plus : ( (sub)? )+ ; rule_star : ( (sub)? )* ; generated incorrect code for the guess block (which could result in runtime errors) because of an incorrect optimization of a block with only a single alternative. The fix caused some changes to the fix described in Item #49 because there are now three code generation sequences for (...)+ blocks containing a guess block: a. single alternative which is a guess block b. multiple alternatives in which the last is a guess block c. all other cases Forms like "rule_star" can have unexpected behavior when there is a syntax error: if the subrule "sub" is not matched *exactly* then "rule_star" will consume no tokens. Reported by Esa Pulkkinen (esap@cs.tut.fi). #104. (Changed in 1.33MR10) -o option for dlg There was problem with the code added by item #74 to handle the -o option of dlg. This should fix it. #103. (Changed in 1.33MR10) ANDed semantic predicates Rescinded. The optimization was a mistake. The resulting problem is described in Item #150. #102. (Changed in 1.33MR10) allow "class parser : .... {" The syntax of the class statement ("class parser-name {") has been extended to allow for the specification of base classes. An arbirtrary number of tokens may now appear between the class name and the "{". They are output again when the class declaration is generated. For example: class Parser : public MyBaseClassANTLRparser { This was suggested by a user, but I don't have a record of who it was. #101. (Changed in 1.33MR10) antlr -info command line switch -info p - extra predicate information in generated file t - information about tnode use: at the end of each rule in generated file summary on stderr at end of program m - monitor progress prints name of each rule as it is started flushes output at start of each rule f - first/follow set information to stdout 0 - no operation (added in 1.33MR11) The options may be combined and may appear in any order. For example: antlr -info ptm -CC -gt -mrhoist on mygrammar.g #100a. (Changed in 1.33MR10) Predicate tree simplification When the same predicates can be referenced in more than one alternative of a block large predicate trees can be formed. The difference that these optimizations make is so dramatic that I have decided to use it even when -mrhoist is not selected. Consider the following grammar: start : ( all )* ; all : a | d | e | f ; a : c A B | c A C ; c : <>? ; d : <>? B C ; e : <>? B C ; f : e X Y ; In rule "a" there is a reference to rule "c" in both alternatives. The length of the predicate AAA is k=2 and it can be followed in alternative 1 only by (A B) while in alternative 2 it can be followed only by (A C). Thus they do not have identical context. In rule "all" the alternatives which refer to rules "e" and "f" allow elimination of the duplicate reference to predicate CCC. The table below summarized the kind of simplification performed by 1.33MR10. In the table, X and Y stand for single predicates (not trees). (OR X (OR Y (OR Z))) => (OR X Y Z) (AND X (AND Y (AND Z))) => (AND X Y Z) (OR X (... (OR X Y) ... )) => (OR X (... Y ... )) (AND X (... (AND X Y) ... )) => (AND X (... Y ... )) (OR X (... (AND X Y) ... )) => (OR X (... ... )) (AND X (... (OR X Y) ... )) => (AND X (... ... )) (AND X) => X (OR X) => X In a test with a complex grammar for a real application, a predicate tree with six OR nodes and 12 leaves was reduced to "(OR X Y Z)". In 1.33MR10 there is a greater effort to release memory used by predicates once they are no longer in use. #100b. (Changed in 1.33MR10) Suppression of extra predicate tests The following optimizations require that -mrhoist be selected. It is relatively easy to optimize the code generated for predicate gates when they are of the form: (AND X Y Z ...) or (OR X Y Z ...) where X, Y, Z, and "..." represent individual predicates (leaves) not predicate trees. If the predicate is an AND the contexts of the X, Y, Z, etc. are ANDed together to create a single Tree context for the group and context tests for the individual predicates are suppressed: -------------------------------------------------- Note: This was incorrect. The contexts should be ORed together. This has been fixed. A more complete description is available in item #152. --------------------------------------------------- Optimization 1: (AND X Y Z ...) Suppose the context for Xtest is LA(1)==LP and the context for Ytest is LA(1)==LP && LA(2)==ID. Without the optimization the code would resemble: if (lookaheadContext && !(LA(1)==LP && LA(1)==LP && LA(2)==ID) || ( (! LA(1)==LP || Xtest) && (! (LA(1)==LP || LA(2)==ID) || Xtest) )) {... With the -mrhoist optimization the code would resemble: if (lookaheadContext && ! (LA(1)==LP && LA(2)==ID) || (Xtest && Ytest) {... Optimization 2: (OR X Y Z ...) with identical contexts Suppose the context for Xtest is LA(1)==ID and for Ytest the context is also LA(1)==ID. Without the optimization the code would resemble: if (lookaheadContext && ! (LA(1)==ID || LA(1)==ID) || (LA(1)==ID && Xtest) || (LA(1)==ID && Ytest) {... With the -mrhoist optimization the code would resemble: if (lookaheadContext && (! LA(1)==ID) || (Xtest || Ytest) {... Optimization 3: (OR X Y Z ...) with distinct contexts Suppose the context for Xtest is LA(1)==ID and for Ytest the context is LA(1)==LP. Without the optimization the code would resemble: if (lookaheadContext && ! (LA(1)==ID || LA(1)==LP) || (LA(1)==ID && Xtest) || (LA(1)==LP && Ytest) {... With the -mrhoist optimization the code would resemble: if (lookaheadContext && (zzpf=0, (LA(1)==ID && (zzpf=1) && Xtest) || (LA(1)==LP && (zzpf=1) && Ytest) || !zzpf) { These may appear to be of similar complexity at first, but the non-optimized version contains two tests of each context while the optimized version contains only one such test, as well as eliminating some of the inverted logic (" !(...) || "). Optimization 4: Computation of predicate gate trees When generating code for the gates of predicate expressions antlr 1.33 vanilla uses a recursive procedure to generate "&&" and "||" expressions for testing the lookahead. As each layer of the predicate tree is exposed a new set of "&&" and "||" expressions on the lookahead are generated. In many cases the lookahead being tested has already been tested. With -mrhoist a lookahead tree is computed for the entire lookahead expression. This means that predicates with identical context or context which is a subset of another predicate's context disappear. This is especially important for predicates formed by rules like the following: uppperCaseVowel : <>? vowel; vowel: : <>? LETTERS; These predicates are combined using AND since both must be satisfied for rule upperCaseVowel. They have identical context which makes this optimization very effective. The affect of Items #100a and #100b together can be dramatic. In a very large (but real world) grammar one particular predicate expression was reduced from an (unreadable) 50 predicate leaves, 195 LA(1) terms, and 5500 characters to an (easily comprehensible) 3 predicate leaves (all different) and a *single* LA(1) term. #99. (Changed in 1.33MR10) Code generation for expression trees Expression trees are used for k>1 grammars and predicates with lookahead depth >1. This optimization must be enabled using "-mrhost on". (Clarification added for 1.33MR11). In the processing of expression trees, antlr can generate long chains of token comparisons. Prior to 1.33MR10 there were many redundant parenthesis which caused problems for compilers which could handle expressions of only limited complexity. For example, to test an expression tree (root R A B C D), antlr would generate something resembling: (LA(1)==R && (LA(2)==A || (LA(2)==B || (LA(2)==C || LA(2)==D))))) If there were twenty tokens to test then there would be twenty parenthesis at the end of the expression. In 1.33MR10 the generated code for tree expressions resembles: (LA(1)==R && (LA(2)==A || LA(2)==B || LA(2)==C || LA(2)==D)) For "complex" expressions the output is indented to reflect the LA number being tested: (LA(1)==R && (LA(2)==A || LA(2)==B || LA(2)==C || LA(2)==D || LA(2)==E || LA(2)==F) || LA(1)==S && (LA(2)==G || LA(2)==H)) Suggested by S. Bochnak (S.Bochnak@@microTool.com.pl), #98. (Changed in 1.33MR10) Option "-info p" When the user selects option "-info p" the program will generate detailed information about predicates. If the user selects "-mrhoist on" additional detail will be provided explaining the promotion and suppression of predicates. The output is part of the generated file and sandwiched between #if 0/#endif statements. Consider the following k=1 grammar: start : ( all ) * ; all : ( a | b ) ; a : c B ; c : <>? | B ; b : <>? X ; Below is an excerpt of the output for rule "start" for the three predicate options (off, on, and maintenance release style hoisting). For those who do not wish to use the "-mrhost on" option for code generation the option can be used in a "diagnostic" mode to provide valuable information: a. where one should insert null actions to inhibit hoisting b. a chain of rule references which shows where predicates are being hoisted ====================================================================== Example of "-info p" with "-mrhoist on" ====================================================================== #if 0 Hoisting of predicate suppressed by alternative without predicate. The alt without the predicate includes all cases where the predicate is false. WITH predicate: line 11 v36.g WITHOUT predicate: line 12 v36.g The context set for the predicate: B The lookahead set for alt WITHOUT the semantic predicate: B The predicate: pred << LATEXT(1)>>? depth=k=1 rule c line 11 v36.g set context: B tree context: null Chain of referenced rules: #0 in rule start (line 1 v36.g) to rule all #1 in rule all (line 3 v36.g) to rule a #2 in rule a (line 8 v36.g) to rule c #3 in rule c (line 11 v36.g) #endif && #if 0 pred << LATEXT(1)>>? depth=k=1 rule b line 15 v36.g set context: X tree context: null #endif ====================================================================== Example of "-info p" with the default -prc setting ( "-prc off") ====================================================================== #if 0 OR pred << LATEXT(1)>>? depth=k=1 rule c line 11 v36.g set context: nil tree context: null pred << LATEXT(1)>>? depth=k=1 rule b line 15 v36.g set context: nil tree context: null #endif ====================================================================== Example of "-info p" with "-prc on" and "-mrhoist off" ====================================================================== #if 0 OR pred << LATEXT(1)>>? depth=k=1 rule c line 11 v36.g set context: B tree context: null pred << LATEXT(1)>>? depth=k=1 rule b line 15 v36.g set context: X tree context: null #endif ====================================================================== #97. (Fixed in 1.33MR10) "Predicate applied for more than one ... " In 1.33 vanilla, the grammar listed below produced this message for the first alternative (only) of rule "b": warning: predicate applied for >1 lookahead 1-sequences [you may only want one lookahead 1-sequence to apply. Try using a context guard '(...)? =>' In 1.33MR10 the message is issued for both alternatives. top : (a)*; a : b | c ; b : <>? ( AAA | BBB ) | <>? ( XXX | YYY ) ; c : AAA | XXX; #96. (Fixed in 1.33MR10) Guard predicates ignored when -prc off Prior to 1.33MR10, guard predicate code was not generated unless "-prc on" was selected. This was incorrect, since "-prc off" (the default) is supposed to disable only AUTOMATIC computation of predicate context, not the programmer specified context supplied by guard predicates. #95. (Fixed in 1.33MR10) Predicate guard context length was k, not max(k,ck) Prior to 1.33MR10, predicate guards were computed to k tokens rather than max(k,ck). Consider the following grammar: a : ( A B C)? => <>? (A|X) (B|Y) (C|Z) ; The code generated by 1.33 vanilla with "-k 1 -ck 3 -prc on" for the predicate in "a" resembles: if ( (! LA(1)==A) || AAA(LATEXT(1))) {... With 1.33MR10 and the same options the code resembles: if ( (! (LA(1)==A && LA(2)==B && LA(3)==C) || AAA(LATEXT(1))) {... #94. (Fixed in 1.33MR10) Predicates followed by rule references Prior to 1.33MR10, a semantic predicate which referenced a token which was off the end of the rule caused an incomplete context to be computed (with "-prc on") for the predicate under some circum- stances. In some cases this manifested itself as illegal C code (e.g. "LA(2)==[Ep](1)" in the k=2 examples below: all : ( a ) *; a : <>? ID X | <>? Y | Z ; This might also occur when the semantic predicate was followed by a rule reference which was shorter than the length of the semantic predicate: all : ( a ) *; a : <>? ID X | <>? y | Z ; y : Y ; Depending on circumstance, the resulting context might be too generous because it was too short, or too restrictive because of missing alternatives. #93. (Changed in 1.33MR10) Definition of Purify macro Ofer Ben-Ami (gremlin@cs.huji.ac.il) has supplied a definition for the Purify macro: #define PURIFY(r, s) memset((char *) &(r), '\0', (s)); Note: 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 an empty macro in the #header or #first actions. #92. (Fixed in 1.33MR10) Guarded predicates and hoisting When a guarded predicate participates in hoisting it is linked into a predicate expression tree. Prior to 1.33MR10 this link was never cleared and the next time the guard was used to construct a new tree the link could contain a spurious reference to another element which had previosly been joined to it in the semantic predicate tree. For example: start : ( all ) *; all : ( a | b ) ; start2 : ( all2 ) *; all2 : ( a ) ; a : (A)? => <>? A ; b : (B)? => <>? B ; Prior to 1.33MR10 the code for "start2" would include a spurious reference to the BBB predicate which was left from constructing the predicate tree for rule "start" (i.e. or(AAA,BBB) ). In 1.33MR10 this problem is avoided by cloning the original guard each time it is linked into a predicate tree. #91. (Changed in 1.33MR10) Extensive changes to semantic pred hoisting ============================================ This has been rendered obsolete by Item #117 ============================================ #90. (Fixed in 1.33MR10) Semantic pred with LT(i) and i>max(k,ck) There is a bug in antlr 1.33 vanilla and all maintenance releases prior to 1.33MR10 which allows semantic predicates to reference an LT(i) or LATEXT(i) where i is larger than max(k,ck). When this occurs antlr will attempt to mark the ith element of an array in which there are only max(k,ck) elements. The result cannot be predicted. Using LT(i) or LATEXT(i) for i>max(k,ck) is reported as an error in 1.33MR10. #89. Rescinded #88. (Fixed in 1.33MR10) Tokens used in semantic predicates in guess mode Consider the behavior of a semantic predicate during guess mode: rule : a:A ( <>? b:B | c:C ); Prior to MR10 the assignment of the token or attribute to $a did not occur during guess mode, which would cause the semantic predicate to misbehave because $a would be null. In 1.33MR10 a semantic predicate with a reference to an element label (such as $a) forces the assignment to take place even in guess mode. In order to work, this fix REQUIRES use of the $label format for token pointers and attributes referenced in semantic predicates. The fix does not apply to semantic predicates using the numeric form to refer to attributes (e.g. <>?). The user will receive a warning for this case. Reported by Rob Trout (trout@mcs.cs.kent.edu). #87. (Fixed in 1.33MR10) Malformed guard predicates Context guard predicates may contain only references to tokens. They may not contain references to (...)+ and (...)* blocks. This is now checked. This replaces the fatal error message in item #78 with an appropriate (non-fatal) error messge. In theory, context guards should be allowed to reference rules. However, I have not had time to fix this. Evaluation of the guard takes place before all rules have been read, making it difficult to resolve a forward reference to rule "zzz" - it hasn't been read yet ! To postpone evaluation of the guard until all rules have been read is too much for the moment. #86. (Fixed in 1.33MR10) Unequal set size in set_sub Routine set_sub() in pccts/support/set/set.h did not work correctly when the sets were of unequal sizes. Rewrote set_equ to make it simpler and remove unnecessary and expensive calls to set_deg(). This routine was not used in 1.33 vanila. #85. (Changed in 1.33MR10) Allow redefinition of MaxNumFiles Raised the maximum number of input files to 99 from 20. Put a #ifndef/#endif around the "#define MaxNumFiles 99". #84. (Fixed in 1.33MR10) Initialize zzBadTok in macro zzRULE Initialize zzBadTok to NULL in zzRULE macro of AParser.h. in order to get rid of warning messages. #83. (Fixed in 1.33MR10) False warnings with -w2 for #tokclass When -w2 is selected antlr gives inappropriate warnings about #tokclass names not having any associated regular expressions. Since a #tokclass is not a "real" token it will never have an associated regular expression and there should be no warning. Reported by Derek Pappas (derek.pappas@eng.sun.com) #82. (Fixed in 1.33MR10) Computation of follow sets with multiple cycles Reinier van den Born (reinier@vnet.ibm.com) reported a problem in the computation of follow sets by antlr. The problem (bug) exists in 1.33 vanilla and all maintenance releases prior to 1.33MR10. The problem involves the computation of follow sets when there are cycles - rules which have mutual references. I believe the problem is restricted to cases where there is more than one cycle AND elements of those cycles have rules in common. Even when this occurs it may not affect the code generated - but it might. It might also lead to undetected ambiguities. There were no changes in antlr or dlg output from the revised version. The following fragment demonstates the problem by giving different follow sets (option -pa) for var_access when built with k=1 and ck=2 on 1.33 vanilla and 1.33MR10: echo_statement : ECHO ( echo_expr )* ; echo_expr : ( command )? | expression ; command : IDENTIFIER { concat } ; expression : operand ( OPERATOR operand )* ; operand : value | START command END ; value : concat | TYPE operand ; concat : var_access { CONCAT value } ; var_access : IDENTIFIER { INDEX } ; #81. (Changed in 1.33MR10) C mode use of attributes and ASTs Reported by Isaac Clark (irclark@mindspring.com). C mode code ignores attributes returned by rules which are referenced using element labels when ASTs are enabled (-gt option). 1. start : r:rule t:Token <<$start=$r;>> The $r refrence will not work when combined with the -gt option. 2. start : t:Token <<$start=$t;>> The $t reference works in all cases. 3. start : rule <<$0=$1;>> Numeric labels work in all cases. With MR10 the user will receive an error message for case 1 when the -gt option is used. #80. (Fixed in 1.33MR10) (...)? as last alternative of block A construct like the following: rule : a | (b)? ; does not make sense because there is no alternative when the guess block fails. This is now reported as a warning to the user. Previously, there was a code generation error for this case: the guess block was not "closed" when the guess failed. This could cause an infinite loop or other problems. This is now fixed. Example problem: #header<< #include #include "charptr.h" >> << #include "charptr.c" main () { ANTLR(start(),stdin); } >> #token "[\ \t]+" << zzskip(); >> #token "[\n]" << zzline++; zzskip(); >> #token Word "[a-z]+" #token Number "[0-9]+" start : (test1)? | (test2)? ; test1 : (Word Word Word Word)? | (Word Word Word Number)? ; test2 : (Word Word Number Word)? | (Word Word Number Number)? ; Test data which caused infinite loop: a 1 a a #79. (Changed in 1.33MR10) Use of -fh with multiple parsers Previously, antlr always used the pre-processor symbol STDPCCTS_H as a gate for the file stdpccts.h. This caused problems when there were multiple parsers defined because they used the same gate symbol. In 1.33MR10, the -fh filename is used to generate the gate file for stdpccts.h. For instance: antlr -fh std_parser1.h generates the pre-processor symbol "STDPCCTS_std_parser1_H". Reported by Ramanathan Santhanam (ps@kumaran.com). #78. (Changed in 1.33MR9) Guard predicates that refer to rules ------------------------ Please refer to Item #87 ------------------------ Guard predicates are processed during an early phase of antlr (during parsing) before all data structures are completed. There is an apparent bug in earlier versions of 1.33 which caused guard predicates which contained references to rules (rather than tokens) to reference a structure which hadn't yet been initialized. In some cases (perhaps all cases) references to rules in guard predicates resulted in the use of "garbage". #79. (Changed in 1.33MR9) Jeff Vincent (JVincent@novell.com) Previously, the maximum length file name was set arbitrarily to 300 characters in antlr, dlg, and sorcerer. The config.h file now attempts to define the maximum length filename using _MAX_PATH from stdlib.h before falling back to using the value 300. #78. (Changed in 1.33MR9) Jeff Vincent (JVincent@novell.com) Put #ifndef/#endif around definition of ZZLEXBUFSIZE in antlr. #77. (Changed in 1.33MR9) Arithmetic overflow for very large grammars In routine HandleAmbiguities() antlr attempts to compute the number of possible elements in a set that is order of number-of-tokens raised to the number-of-lookahead-tokens power. For large grammars or large lookahead (e.g. -ck 7) this can cause arithmetic overflow. With 1.33MR9, arithmetic overflow in this computation is reported the first time it happens. The program continues to run and the program branches based on the assumption that the computed value is larger than any number computed by counting actual cases because 2**31 is larger than the number of bits in most computers. Before 1.33MR9 overflow was not reported. The behavior following overflow is not predictable by anyone but the original author. NOTE In 1.33MR10 the warning message is suppressed. The code which detects the overflow allows the computation to continue without an error. The error message itself made made users worry. #76. (Changed in 1.33MR9) Jeff Vincent (JVincent@novell.com) Jeff Vincent has convinced me to make ANTLRCommonToken and ANTLRCommonNoRefCountToken use variable length strings allocated from the heap rather than fixed length strings. By suitable definition of setText(), the copy constructor, and operator =() it is possible to maintain "copy" semantics. By "copy" semantics I mean that when a token is copied from an existing token it receives its own, distinct, copy of the text allocated from the heap rather than simply a pointer to the original token's text. ============================================================ W * A * R * N * I * N * G ============================================================ It is possible that this may cause problems for some users. For those users I have included the old version of AToken.h as pccts/h/AToken_traditional.h. #75. (Changed in 1.33MR9) Bruce Guenter (bruceg@qcc.sk.ca) Make DLGStringInput const correct. Since this is infrequently subclassed, it should affect few users, I hope. #74. (Changed in 1.33MR9) -o (output directory) option Antlr does not properly handle the -o output directory option when the filename of the grammar contains a directory part. For example: antlr -o outdir pccts_src/myfile.g causes antlr create a file called "outdir/pccts_src/myfile.cpp. It SHOULD create outdir/myfile.cpp The suggested code fix has been installed in antlr, dlg, and Sorcerer. #73. (Changed in 1.33MR9) Hoisting of semantic predicates and -mrhoist ============================================ This has been rendered obsolete by Item #117 ============================================ #72. (Changed in 1.33MR9) virtual saveState()/restoreState()/guess_XXX The following methods in ANTLRParser were made virtual at the request of S. Bochnak (S.Bochnak@microTool.com.pl): saveState() and restoreState() guess(), guess_fail(), and guess_done() #71. (Changed in 1.33MR9) Access to omitted command line argument If a switch requiring arguments is the last thing on the command line, and the argument is omitted, antlr would core. antlr test.g -prc instead of antlr test.g -prc off #70. (Changed in 1.33MR9) Addition of MSVC .dsp and .mak build files 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/PCCTSMSVC50.dsw pccts/antlr/AntlrMSVC50.dsp pccts/antlr/AntlrMSVC50.mak pccts/dlg/DlgMSVC50.dsp pccts/dlg/DlgMSVC50.mak pccts/support/msvc.dsp Sorcerer Distribution Kit ------------------------- pccts/sorcerer/SorcererMSVC50.dsp pccts/sorcerer/SorcererMSVC50.mak pccts/sorcerer/lib/msvc.dsp #69. (Changed in 1.33MR9) Change "unsigned int" to plain "int" Declaration of max_token_num in misc.c as "unsigned int" caused comparison between signed and unsigned ints giving warning message without any special benefit. #68. (Changed in 1.33MR9) Add void return for dlg internal_error() Get rid of "no return value" message in internal_error() in file dlg/support.c and dlg/dlg.h. #67. (Changed in Sor) sor.g: lisp() has no return value Added a "void" for the return type. #66. (Added to Sor) sor.g: ZZLEXBUFSIZE enclosed in #ifndef/#endif A user needed to be able to change the ZZLEXBUFSIZE for sor. Put the definition of ZZLEXBUFSIZE inside #ifndef/#endif #65. (Changed in 1.33MR9) PCCTSAST::deepCopy() and ast_dup() bug Jeff Vincent (JVincent@novell.com) found that deepCopy() made new copies of only the direct descendents. No new copies were made of sibling nodes, Sibling pointers are set to zero by shallowCopy(). PCCTS_AST::deepCopy() has been changed to make a deep copy in the traditional sense. The deepCopy() routine depends on the behavior of shallowCopy(). In all sor examples I've found, shallowCopy() zeroes the right and down pointers. Original Tree Original deepCopy() Revised deepCopy ------------- ------------------- ---------------- a->b->c A A | | | d->e->f D D->E->F | | | g->h->i G G->H->I | | j->k J->K While comparing deepCopy() for C++ mode with ast_dup for C mode I found a problem with ast_dup(). Routine ast_dup() has been changed to make a deep copy in the traditional sense. Original Tree Original ast_dup() Revised ast_dup() ------------- ------------------- ---------------- a->b->c A->B->C A | | | d->e->f D->E->F D->E->F | | | g->h->i G->H->I G->H->I | | | j->k J->K J->K I believe this affects transform mode sorcerer programs only. #64. (Changed in 1.33MR9) anltr/hash.h prototype for killHashTable() #63. (Changed in 1.33MR8) h/charptr.h does not zero pointer after free The charptr.h routine now zeroes the pointer after free(). Reported by Jens Tingleff (jensting@imaginet.fr) #62. (Changed in 1.33MR8) ANTLRParser::resynch had static variable The static variable "consumed" in ANTLRParser::resynch was changed into an instance variable of the class with the name "resynchConsumed". Reported by S.Bochnak@microTool.com.pl #61. (Changed in 1.33MR8) Using rule>[i,j] when rule has no return values Previously, the following code would cause antlr to core when it tried to generate code for rule1 because rule2 had no return values ("upward inheritance"): rule1 : <> rule2 > [i,j] ; rule2 : Anything ; Reported by S.Bochnak@microTool.com.pl Verified correct operation of antlr MR8 when missing or extra inheritance arguments for all combinations. When there are missing or extra arguments code will still be generated even though this might cause the invocation of a subroutine with the wrong number of arguments. #60. (Changed in 1.33MR7) Major changes to exception handling There were significant problems in the handling of exceptions in 1.33 vanilla. The general problem is that it can only process one level of exception handler. For example, a named exception handler, an exception handler for an alternative, or an exception for a subrule always went to the rule's exception handler if there was no "catch" which matched the exception. In 1.33MR7 the exception handlers properly "nest". If an exception handler does not have a matching "catch" then the nextmost outer exception handler is checked for an appropriate "catch" clause, and so on until an exception handler with an appropriate "catch" is found. There are still undesirable features in the way exception handlers are implemented, but I do not have time to fix them at the moment: The exception handlers for alternatives are outside the block containing the alternative. This makes it impossible to access variables declared in a block or to resume the parse by "falling through". The parse can still be easily resumed in other ways, but not in the most natural fashion. This results in an inconsistentcy between named exception handlers and exception handlers for alternatives. When an exception handler for an alternative "falls through" it goes to the nextmost outer handler - not the "normal action". A major difference between 1.33MR7 and 1.33 vanilla is the default action after an exception is caught: 1.33 Vanilla ------------ In 1.33 vanilla the signal value is set to zero ("NoSignal") and the code drops through to the code following the exception. For named exception handlers this is the "normal action". For alternative exception handlers this is the rule's handler. 1.33MR7 ------- In 1.33MR7 the signal value is NOT automatically set to zero. There are two cases: For named exception handlers: if the signal value has been set to zero the code drops through to the "normal action". For all other cases the code branches to the nextmost outer exception handler until it reaches the handler for the rule. The following macros have been defined for convenience: C/C++ Mode Name -------------------- (zz)suppressSignal set signal & return signal arg to 0 ("NoSignal") (zz)setSignal(intValue) set signal & return signal arg to some value (zz)exportSignal copy the signal value to the return signal arg I'm not sure why PCCTS make a distinction between the local signal value and the return signal argument, but I'm loathe to change the code. The burden of copying the local signal value to the return signal argument can be given to the default signal handler, I suppose. #59. (Changed in 1.33MR7) Prototypes for some functions Added prototypes for the following functions to antlr.h zzconsumeUntil() zzconsumeUntilToken() #58. (Changed in 1.33MR7) Added defintion of zzbufsize to dlgauto.h #57. (Changed in 1.33MR7) Format of #line directive Previously, the -gl directive for line 1234 would resemble: "# 1234 filename.g". This caused problems for some compilers/pre-processors. In MR7 it generates "#line 1234 filename.g". #56. (Added in 1.33MR7) Jan Mikkelsen Move PURIFY macro invocaton to after rule's init action. #55. (Fixed in 1.33MR7) Unitialized variables in ANTLRParser Member variables inf_labase and inf_last were not initialized. (See item #50.) #54. (Fixed in 1.33MR6) Brad Schick (schick@interacess.com) Previously, the following constructs generated the same code: rule1 : (A B C)? | something-else ; rule2 : (A B C)? () | something-else ; In all versions of pccts rule1 guesses (A B C) and then consume all three tokens if the guess succeeds. In MR6 rule2 guesses (A B C) but consumes NONE of the tokens when the guess succeeds because "()" matches epsilon. #53. (Explanation for 1.33MR6) What happens after an exception is caught ? The Book is silent about what happens after an exception is caught. The following code fragment prints "Error Action" followed by "Normal Action". test : Word ex:Number <> exception[ex] catch NoViableAlt: <> ; The reason for "Normal Action" is that the normal flow of the program after a user-written exception handler is to "drop through". In the case of an exception handler for a rule this results in the exection of a "return" statement. In the case of an exception handler attached to an alternative, rule, or token this is the code that would have executed had there been no exception. The user can achieve the desired result by using a "return" statement. test : Word ex:Number <> exception[ex] catch NoViableAlt: <> ; The most powerful mechanism for recovery from parse errors in pccts is syntactic predicates because they provide backtracking. Exceptions allow "return", "break", "consumeUntil(...)", "goto _handler", "goto _fail", and changing the _signal value. #52. (Fixed in 1.33MR6) Exceptions without syntactic predicates The following generates bad code in 1.33 if no syntactic predicates are present in the grammar. test : Word ex:Number <> exception[ex] catch NoViableAlt: <> There is a reference to a guess variable. In C mode this causes a compiler error. In C++ mode it generates an extraneous check on member "guessing". In MR6 correct code is generated for both C and C++ mode. #51. (Added to 1.33MR6) Exception operator "@" used without exceptions In MR6 added a warning when the exception operator "@" is used and no exception group is defined. This is probably a case where "\@" or "@" is meant. #50. (Fixed in 1.33MR6) Gunnar Rxnning (gunnar@candleweb.no) http://www.candleweb.no/~gunnar/ Routines zzsave_antlr_state and zzrestore_antlr_state don't save and restore all the data needed when switching states. Suggested patch applied to antlr.h and err.h for MR6. #49. (Fixed in 1.33MR6) Sinan Karasu (sinan@boeing.com) Generated code failed to turn off guess mode when leaving a (...)+ block which contained a guess block. The result was an infinite loop. For example: rule : ( (x)? | y )+ Suggested code fix implemented in MR6. Replaced ... else if (zzcnt>1) break; with: C++ mode: ... else if (zzcnt>1) {if (!zzrv) zzGUESS_DONE; break;}; C mode: ... else if (zzcnt>1) {if (zzguessing) zzGUESS_DONE; break;}; #48. (Fixed in 1.33MR6) Invalid exception element causes core A label attached to an invalid construct can cause pccts to crash while processing the exception associated with the label. For example: rule : t:(B C) exception[t] catch MismatchedToken: <> Version MR6 generates the message: reference in exception handler to undefined label 't' #47. (Fixed in 1.33MR6) Manuel Ornato Under some circumstances involving a k >1 or ck >1 grammar and a loop block (i.e. (...)* ) pccts will fail to detect a syntax error and loop indefinitely. The problem did not exist in 1.20, but has existed from 1.23 to the present. Fixed in MR6. --------------------------------------------------- Complete test program --------------------------------------------------- #header<< #include #include "charptr.h" >> << #include "charptr.c" main () { ANTLR(global(),stdin); } >> #token "[\ \t]+" << zzskip(); >> #token "[\n]" << zzline++; zzskip(); >> #token B "b" #token C "c" #token D "d" #token E "e" #token LP "\(" #token RP "\)" #token ANTLREOF "@" global : ( (E liste) | liste | listed ) ANTLREOF ; listeb : LP ( B ( B | C )* ) RP ; listec : LP ( C ( B | C )* ) RP ; listed : LP ( D ( B | C )* ) RP ; liste : ( listeb | listec )* ; --------------------------------------------------- Sample data causing infinite loop --------------------------------------------------- e (d c) --------------------------------------------------- #46. (Fixed in 1.33MR6) Robert Richter (Robert.Richter@infotech.tu-chemnitz.de) This item from the list of known problems was fixed by item #18 (below). #45. (Fixed in 1.33MR6) Brad Schick (schick@interaccess.com) The dependency scanner in VC++ mistakenly sees a reference to an MPW #include file even though properly #ifdef/#endif in config.h. The suggested workaround has been implemented: #ifdef MPW ..... #define MPW_CursorCtl_Header #include MPW_CursorCtl_Header ..... #endif #44. (Fixed in 1.33MR6) cast malloc() to (char *) in charptr.c Added (char *) cast for systems where malloc returns "void *". #43. (Added to 1.33MR6) Bruce Guenter (bruceg@qcc.sk.ca) Add setLeft() and setUp methods to ASTDoublyLinkedBase for symmetry with setRight() and setDown() methods. #42. (Fixed in 1.33MR6) Jeff Katcher (jkatcher@nortel.ca) C++ style comment in antlr.c corrected. #41. (Added in 1.33MR6) antlr -stdout Using "antlr -stdout ..." forces the text that would normally go to the grammar.c or grammar.cpp file to stdout. #40. (Added in 1.33MR6) antlr -tab to change tab stops Using "antlr -tab number ..." changes the tab stops for the grammar.c or grammar.cpp file. The number must be between 0 and 8. Using 0 gives tab characters, values between 1 and 8 give the appropriate number of space characters. #39. (Fixed in 1.33MR5) Jan Mikkelsen Commas in function prototype still not correct under some circumstances. Suggested code fix installed. #38. (Fixed in 1.33MR5) ANTLRTokenBuffer constructor Have ANTLRTokenBuffer ctor initialize member "parser" to null. #37. (Fixed in 1.33MR4) Bruce Guenter (bruceg@qcc.sk.ca) In ANTLRParser::FAIL(int k,...) released memory pointed to by f[i] (as well as f itself. Should only free f itself. #36. (Fixed in 1.33MR3) Cortland D. Starrett (cort@shay.ecn.purdue.edu) Neglected to properly declare isDLGmaxToken() when fixing problem reported by Andreas Magnusson. Undo "_retv=NULL;" change which caused problems for return values from rules whose return values weren't pointers. Failed to create bin directory if it didn't exist. #35. (Fixed in 1.33MR2) Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) Repair bug introduced by 1.33MR1 for #tokdefs. The original fix placed "DLGmaxToken=9999" and "DLGminToken=0" in the TokenType enum in order to fix a problem with an aggresive compiler assigning an 8 bit enum which might be too narrow. This caused #tokdefs to assume that there were 9999 real tokens. The repair to the fix causes antlr to ignore TokenTypes "DLGmaxToken" and "DLGminToken" in a #tokdefs file. #34. (Added to 1.33MR1) Add public DLGLexerBase::set_line(int newValue) Previously there was no public function for changing the line number maintained by the lexer. #33. (Fixed in 1.33MR1) Franklin Chen (chen@adi.com) Accidental use of EXIT_FAILURE rather than PCCTS_EXIT_FAILURE in pccts/h/AParser.cpp. #32. (Fixed in 1.33MR1) Franklin Chen (chen@adi.com) In PCCTSAST.cpp lines 405 and 466: Change free (t) to free ( (char *)t ); to match prototype. #31. (Added to 1.33MR1) Pointer to parser in ANTLRTokenBuffer Pointer to parser in DLGLexerBase The ANTLRTokenBuffer class now contains a pointer to the parser which is using it. This is established by the ANTLRParser constructor calling ANTLRTokenBuffer:: setParser(ANTLRParser *p). When ANTLRTokenBuffer::setParser(ANTLRParser *p) is called it saves the pointer to the parser and then calls ANTLRTokenStream::setParser(ANTLRParser *p) so that the lexer can also save a pointer to the parser. There is also a function getParser() in each class with the obvious purpose. It is possible that these functions will return NULL under some circumstances (e.g. a non-DLG lexer is used). #30. (Added to 1.33MR1) function tokenName(int token) standard The generated parser class now includes the function: static const ANTLRChar * tokenName(int token) which returns a pointer to the "name" corresponding to the token. The base class (ANTLRParser) always includes the member function: const ANTLRChar * parserTokenName(int token) which can be accessed by objects which have a pointer to an ANTLRParser, but do not know the name of the parser class (e.g. ANTLRTokenBuffer and DLGLexerBase). #29. (Added to 1.33MR1) Debugging DLG lexers If the pre-processor symbol DEBUG_LEXER is defined then DLexerBase will include code for printing out key information about tokens which are recognized. The debug feature of the lexer is controlled by: int previousDebugValue=lexer.debugLexer(newValue); a value of 0 disables output a value of 1 enables output Even if the lexer debug code is compiled into DLexerBase it must be enabled before any output is generated. For example: DLGFileInput in(stdin); MyDLG lexer(&in,2000); lexer.setToken(&aToken); #if DEBUG_LEXER lexer.debugLexer(1); // enable debug information #endif #28. (Added to 1.33MR1) More control over DLG header Version 1.33MR1 adds the following directives to PCCTS for C++ mode: #lexprefix <> Adds source code to the DLGLexer.h file after the #include "DLexerBase.h" but before the start of the class definition. #lexmember <> Adds source code to the DLGLexer.h file as part of the DLGLexer class body. It appears immediately after the start of the class and a "public: statement. #27. (Fixed in 1.33MR1) Comments in DLG actions Previously, DLG would not recognize comments as a special case. Thus, ">>" in the comments would cause errors. This is fixed. #26. (Fixed in 1.33MR1) Removed static variables from error routines Previously, the existence of statically allocated variables in some of the parser's member functions posed a danger when there was more than one parser active. Replaced with dynamically allocated/freed variables in 1.33MR1. #25. (Fixed in 1.33MR1) Use of string literals in semantic predicates Previously, it was not possible to place a string literal in a semantic predicate because it was not properly "stringized" for the report of a failed predicate. #24. (Fixed in 1.33MR1) Continuation lines for semantic predicates Previously, it was not possible to continue semantic predicates across a line because it was not properly "stringized" for the report of a failed predicate. rule : <>?[ a very long statement ] #23. (Fixed in 1.33MR1) {...} envelope for failed semantic predicates Previously, there was a code generation error for failed semantic predicates: rule : <>?[ stmt1; stmt2; ] which generated code which resembled: if (! xyz()) stmt1; stmt2; It now puts the statements in a {...} envelope: if (! xyz()) { stmt1; stmt2; }; #22. (Fixed in 1.33MR1) Continuation of #token across lines using "\" Previously, it was not possible to continue a #token regular expression across a line. The trailing "\" and newline caused a newline to be inserted into the regular expression by DLG. Fixed in 1.33MR1. #21. (Fixed in 1.33MR1) Use of ">>" (right shift operator in DLG actions It is now possible to use the C++ right shift operator ">>" in DLG actions by using the normal escapes: #token "shift-right" << value=value \>\> 1;>> #20. (Version 1.33/19-Jan-97 Karl Eccleson P.A. Keller (P.A.Keller@bath.ac.uk) There is a problem due to using exceptions with the -gh option. Suggested fix now in 1.33MR1. #19. (Fixed in 1.33MR1) Tom Piscotti and John Lilley There were problems suppressing messages to stdin and stdout when running in a window environment because some functions which uses fprint were not virtual. Suggested change now in 1.33MR1. I believe all functions containing error messages (excluding those indicating internal inconsistency) have been placed in functions which are virtual. #18. (Version 1.33/ 22-Nov-96) John Bair (jbair@iftime.com) Under some combination of options a required "return _retv" is not generated. Suggested fix now in 1.33MR1. #17. (Version 1.33/3-Sep-96) Ron House (house@helios.usq.edu.au) The routine ASTBase::predorder_action omits two "tree->" prefixes, which results in the preorder_action belonging to the wrong node to be invoked. Suggested fix now in 1.33MR1. #16. (Version 1.33/7-Jun-96) Eli Sternheim Routine consumeUntilToken() does not check for end-of-file condition. Suggested fix now in 1.33MR1. #15. (Version 1.33/8 Apr 96) Asgeir Olafsson Problem with tree duplication of doubly linked ASTs in ASTBase.cpp. Suggested fix now in 1.33MR1. #14. (Version 1.33/28-Feb-96) Andreas.Magnusson@mailbox.swipnet.se Problem with definition of operator = (const ANTLRTokenPtr rhs). Suggested fix now in 1.33MR1. #13. (Version 1.33/13-Feb-96) Franklin Chen (chen@adi.com) Sun C++ Compiler 3.0.1 can't compile testcpp/1 due to goto in block with destructors. Apparently fixed. Can't locate "goto". #12. (Version 1.33/10-Nov-95) Minor problems with 1.33 code The following items have been fixed in 1.33MR1: 1. pccts/antlr/main.c line 142 "void" appears in classic C code 2. no makefile in support/genmk 3. EXIT_FAILURE/_SUCCESS instead of PCCTS_EXIT_FAILURE/_SUCCESS pccts/h/PCCTSAST.cpp pccts/h/DLexerBase.cpp pccts/testcpp/6/test.g 4. use of "signed int" isn't accepted by AT&T cfront pccts/h/PCCTSAST.h line 42 5. in call to ANTLRParser::FAIL the var arg err_k is passed as "int" but is declared "unsigned int". 6. I believe that a failed validation predicate still does not get put in a "{...}" envelope, despite the release notes. 7. The #token ">>" appearing in the DLG grammar description causes DLG to generate the string literal "\>\>" which is non-conforming and will cause some compilers to complain (scan.c function act10 line 143 of source code). #11. (Version 1.32b6) Dave Kuhlman (dkuhlman@netcom.com) Problem with file close in gen.c. Already fixed in 1.33. #10. (Version 1.32b6/29-Aug-95) pccts/antlr/main.c contains a C++ style comments on lines 149 and 176 which causes problems for most C compilers. Already fixed in 1.33. #9. (Version 1.32b4/14-Mar-95) dlgauto.h #include "config.h" The file pccts/h/dlgauto.h should probably contain a #include "config.h" as it uses the #define symbol __USE_PROTOS. Added to 1.33MR1. #8. (Version 1.32b4/6-Mar-95) Michael T. Richter (mtr@igs.net) In C++ output mode anonymous tokens from in-line regular expressions can create enum values which are too wide for the datatype of the enum assigned by the C++ compiler. Fixed in 1.33MR1. #7. (Version 1.32b4/6-Mar-95) C++ does not imply __STDC__ In err.h the combination of # directives assumes that a C++ compiler has __STDC__ defined. This is not necessarily true. This problem also appears in the use of __USE_PROTOS which is appropriate for both Standard C and C++ in antlr/gen.c and antlr/lex.c Fixed in 1.33MR1. #6. (Version 1.32 ?/15-Feb-95) Name conflict for "TokenType" Already fixed in 1.33. #5. (23-Jan-95) Douglas_Cuthbertson.JTIDS@jtids_qmail.hanscom.af.mil The fail action following a semantic predicate is not enclosed in "{...}". This can lead to problems when the fail action contains more than one statement. Fixed in 1.33MR1. #4 . (Version 1.33/31-Mar-96) jlilley@empathy.com (John Lilley) Put briefly, a semantic predicate ought to abort a guess if it fails. Correction suggested by J. Lilley has been added to 1.33MR1. #3 . (Version 1.33) P.A.Keller@bath.ac.uk Extra commas are placed in the K&R style argument list for rules when using both exceptions and ASTs. Fixed in 1.33MR1. #2. (Version 1.32b6/2-Oct-95) Brad Schick Construct #[] generates zzastnew() in C++ mode. Already fixed in 1.33. #1. (Version 1.33) Bob Bailey (robert@oakhill.sps.mot.com) Previously, config.h assumed that all PC systems required "short" file names. The user can now override that assumption with "#define LONGFILENAMES". Added to 1.33MR1. cccc-3.1.4/pccts/KNOWN_PROBLEMS.txt0000644000000000000000000001200407265347347015202 0ustar rootroot ======================================================= Known Problems In PCCTS - Last revised 14 November 1998 ======================================================= #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: /* * ::= ( '|' {} )* * * 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. cccc-3.1.4/pccts/MPW_Read_Me0000644000000000000000000000076707265347347014221 0ustar rootroot 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. cccc-3.1.4/pccts/NOTES.OS20000644000000000000000000002022307265347360013454 0ustar rootroot14 April 94 Version 1.20 of pccts At the moment this help file is available via anonymous FTP at Node: marvin.ecn.purdue.edu File: pub/pccts/1.20/NOTES.OS2 Mail corrections or additions to Steve Robenalt =============================================================================== Notes on building PCCTS under OS/2 2.X with the C Set compilers. The supplied makefiles can be used to build PCCTS under OS/2 with minimal trouble. First you need to edit the makefiles such that the Unix specific defaults are commented out, then uncomment the lines which are specific to OS/2 and C Set/2 compilers as originally set up by Ed Harfmann. Note also that you need to use the target list which reflects the appropriate naming conventions. Some of the lines now need to be changed to reflect differences in conventions between the operating systems: 1) change forward slashes in directories to backslashes, 2) change command line parameters from -option to /option (note that this applies to C Set, not ANTLR and DLG options), and 3) change rm to del for clean and scrub targets. To build ANTLR for the first time: note: I tried various combinations of "touch"ing files to try to prevent nmake from using ANTLR to rebuild itself, and was unsuccessful. In the section labelled "Target list of PC machines", comment out the scan.c and antlr.c dependencies. This prevents nmake from trying to invoke ANTLR to build itself. After you have built ANTLR successfully for the first time, you can uncomment these lines and it will build itself normally. (If you had a working 1.10 installation before, you can also use the older binaries when building the new ones.) An example of the resulting makefile, with all the extra baggage for Unix, DOS, and OS/2 1.X is shown here: ----- cut here ----- # # Makefile for ANTLR 1.20 # # 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.20 # Terence Parr # Purdue University # With AHPCRC, University of Minnesota # 1989-1994 # # Ported to Borland C++, IBM C-Set/2 and Microsoft 6.0 by # Ed Harfmann # Micro Data Base Systems # Lafayette, Indiana # - With updates by Steve Robenalt 4/94 # SET=..\support\set PCCTS_H=..\h # # 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 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 dialog.obj link386 @<< $** /NOI $@ /STACK:32768 $(LIBS: = +^ ) $(DEF_FILE) $(LFLAGS) ; << 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 # # 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 dialog.c # # ****** These next targets are common to UNIX and PC world ******** # #clean up all the intermediate files clean: del *.$(OBJ_EXT) #remove everything in clean plus the PCCTS files generated scrub: del $(PCCTS_GEN) *.$(OBJ_EXT) ----- cut here ----- To build DLG for the first time: Follow the same steps as were used to build ANTLR, changing the slashes and commands, targets, and extensions for OS/2. Comment out the dependencies for dlg_p.c and dlg_a.c to prevent nmake from trying to invoke ANTLR and DLG to build DLG (unless you have 1.10 binaries). An example of the resulting makefile, with all the extra baggage for Unix, DOS, and OS/2 1.X is shown here: ----- cut here ----- # # Makefile for DLG 1.20 # Terence Parr # Purdue University # 1989-1993 # # Ported to IBM C-Set/2 and Microsoft 6.0 by # Ed Harfmann # Micro Data Base Systems # Lafayette, Indiana # - With updates by Steve Robenalt 4/94 # SET=..\support\set PCCTS_H=..\h # # C-Set/2 for OS/2 # CC=icc CFLAGS= /I. /I$(SET) /I$(PCCTS_H) /Sa /W3 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 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: del *.$(OBJ_EXT) ----- cut here ----- Once you have built ANTLR and DLG successfully, you will also want to build the genmk utility, located at ~\pccts\support\genmk. The makefile in this directory is relatively simple to modify, so I won't repeat it here. At this point, you can test the executables by building one of the sample programs, such as the Pascal or C example under ~pccts\lang. The prototype makefile which is in these directories will work fine as a base, with OS/2 specific modifications as noted above. Note that the /Sa flag defines the ANSI C mode of the compiler which is not the default. The default mode does not define __STDC__ and will lead to lots of errors. A sample pascal makefile is shown below: ----- cut here ----- GRM =pascal.g LEX_FILE =pscan.dlg GSRC=pascal.c err.c pscan.c ttree.c adebug.c GOBJ=pascal.obj err.obj pscan.obj ttree.obj adebug.obj PCCTS_GEN= pascal.c err.c $(LEX_FILE) pscan.c mode.h tokens.h SRC =$(GSRC) pmain.c sym.c OBJ =$(GOBJ) pmain.obj sym.obj INCL = ..\..\h SYM = ..\..\support\sym ANTLR = ..\..\bin\antlr DLG = ..\..\bin\dlg CFLAGS=/I. /I$(INCL) /Sa AFLAGS= -fl $(LEX_FILE) -gh pascal.exe : $(OBJ) $(CC) $(CFLAGS) /Fopascal.exe $(OBJ) pascal.c $(LEX_FILE) : $(GRM) $(ANTLR) $(AFLAGS) $(GRM) mode.h pscan.c : $(LEX_FILE) $(DLG) -C2 $(LEX_FILE) pscan.c pmain.obj : pmain.c pascal.h pascal.obj : pascal.c mode.h tokens.h sym.obj : $(SYM)\sym.c icc /c /Fo sym.obj $(CFLAGS) $(SYM)\sym.c err.obj : err.c clean: del $(PCCTS_GEN) *.obj ----- cut here ----- The C example can be built in much the same way. If you have problems compiling anything, I would appreciate hearing about it. I was able to get everything built and working without changing any of the supplied or generated C code, so if you find that you need to make changes to any code, I've probably written something up incorrectly. Please post comments to the mailing list for PCCTS at: pccts-users@ahpcrc.umn.edu since I am most likely to see them there. - Steve Robenalt cccc-3.1.4/pccts/NOTES.bcc0000644000000000000000000001224607265347352013607 0ustar rootrootMarch 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) ===================================== cccc-3.1.4/pccts/NOTES.msvc0000644000000000000000000001572207265347355014035 0ustar rootroot 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 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. =============================================================================== cccc-3.1.4/pccts/NOTES.watcom0000644000000000000000000000537707265347360014360 0ustar rootrootFrom Tom Zougas, zougas@civ.utoronto.ca These are the changes I had to make to get ANTLR to compile under Watcom C 10.0 32-bit mode. I'm including the makefiles for antlr and dlg: [Warning from T. Parr: I think that I may have expanded the tabs by mistake in this file. You might have to convert them back to tabs to have this file work correctly.] antlr.mak: ----------------------------------------------------------------------- SET=..\support\set PCCTS_H=..\h # # Watcom # CC=wcl386 ANTLR=..\bin\antlr DLG=..\bin\dlg CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DPC OUT_OBJ = -o OBJ_EXT = obj LINK = wcl386 .c.obj : $(CC) -c $[* $(CFLAGS) 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 $(LINK) -fe=antlr.exe *.obj -k14336 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 set.$(OBJ_EXT) $(SET)\set.c # # ****** These next targets are common to UNIX and PC world ******** # #clean up all the intermediate files clean: del *.obj #remove everything in clean plus the PCCTS files generated scrub: del $(PCCTS_GEN) del *.$(OBJ_EXT) --------------------------------------------------------------------- dlg.mak: --------------------------------------------------------------------- SET=..\support\set PCCTS_H=..\h # # Watcom # CC=wcl386 ANTLR=..\bin\antlr DLG=..\bin\dlg CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DPC LIBS= OBJ_EXT = obj LINK = wcl386 .c.obj : $(CC) -c $[* $(CFLAGS) dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj & output.obj relabel.obj automata.obj $(LINK) -fe=dlg.exe *.obj -k14336 copy *.exe ..\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 #clean up all the intermediate files clean: del *.$(OBJ_EXT) cccc-3.1.4/pccts/README0000644000000000000000000001146007265347366013130 0ustar rootroot--------------------------------------------------------------------------------- README for pccts 1.33mr20 (Maintenance Release #20) release date 5 August 1999 --------------------------------------------------------------------------------- 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 There is a newsgroup dedicated to pccts 1.33 and related topics: comp.compilers.tools.pccts You may also want to register for the antlr-interest mailing list which is provided gratis by the following service: http://www.onesite.com 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.33mr7 so is a little bit out-of-date. The section on semantic predicates is very out of date, but I have not had time to revise it. 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. 2. cd to the main pccts directory. 3. make This will create: antlr.exe dlg.exe sorcerer.exe genmk.exe 4. 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 example\calcAST\* example\simple\* 2. Define the environment variable PCCTS to point to the main pccts directory. 3. Try building the simple project: example\simple\simple50.dsw or simple60.dsw. 4. Try building the complex project: example\calcAST\calcAST50.dsw or calcAST60.dsw. 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. cccc-3.1.4/pccts/RIGHTS0000644000000000000000000000216307265347366013173 0ustar rootroot 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 cccc-3.1.4/pccts/history.ps0000644000000000000000000004752407265347342014321 0ustar rootroot%!PS-Adobe-3.0 %%Creator: groff version 1.06 %%DocumentNeededResources: font Times-Roman %%+ font Times-Italic %%+ font Courier %%DocumentSuppliedResources: procset grops 1.06 0 %%Pages: 3 %%PageOrder: Ascend %%Orientation: Portrait %%EndComments %%BeginProlog %%BeginResource: procset grops 1.06 0 /setpacking where { pop currentpacking true setpacking } if /grops 120 dict dup begin % The ASCII code of the space character. /SC 32 def /A /show load def /B { 0 SC 3 -1 roll widthshow } bind def /C { 0 exch ashow } bind def /D { 0 exch 0 SC 5 2 roll awidthshow } bind def /E { 0 rmoveto show } bind def /F { 0 rmoveto 0 SC 3 -1 roll widthshow } bind def /G { 0 rmoveto 0 exch ashow } bind def /H { 0 rmoveto 0 exch 0 SC 5 2 roll awidthshow } bind def /I { 0 exch rmoveto show } bind def /J { 0 exch rmoveto 0 SC 3 -1 roll widthshow } bind def /K { 0 exch rmoveto 0 exch ashow } bind def /L { 0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow } bind def /M { rmoveto show } bind def /N { rmoveto 0 SC 3 -1 roll widthshow } bind def /O { rmoveto 0 exch ashow } bind def /P { rmoveto 0 exch 0 SC 5 2 roll awidthshow } bind def /Q { moveto show } bind def /R { moveto 0 SC 3 -1 roll widthshow } bind def /S { moveto 0 exch ashow } bind def /T { moveto 0 exch 0 SC 5 2 roll awidthshow } bind def % name size font SF - /SF { findfont exch [ exch dup 0 exch 0 exch neg 0 0 ] makefont dup setfont [ exch /setfont cvx ] cvx bind def } bind def % name a c d font MF - /MF { findfont [ 5 2 roll 0 3 1 roll % b neg 0 0 ] makefont dup setfont [ exch /setfont cvx ] cvx bind def } bind def /level0 0 def /RES 0 def /PL 0 def /LS 0 def % Guess the page length. % This assumes that the imageable area is vertically centered on the page. % PLG - length /PLG { gsave newpath clippath pathbbox grestore exch pop add exch pop } bind def % BP - /BP { /level0 save def 1 setlinecap 1 setlinejoin 72 RES div dup scale LS { 90 rotate } { 0 PL translate } ifelse 1 -1 scale } bind def /EP { level0 restore showpage } bind def % centerx centery radius startangle endangle DA - /DA { newpath arcn stroke } bind def % x y SN - x' y' % round a position to nearest (pixel + (.25,.25)) /SN { transform .25 sub exch .25 sub exch round .25 add exch round .25 add exch itransform } bind def % endx endy startx starty DL - % we round the endpoints of the line, so that parallel horizontal % and vertical lines will appear even /DL { SN moveto SN lineto stroke } bind def % centerx centery radius DC - /DC { newpath 0 360 arc closepath } bind def /TM matrix def % width height centerx centery DE - /DE { TM currentmatrix pop translate scale newpath 0 0 .5 0 360 arc closepath TM setmatrix } bind def % these are for splines /RC /rcurveto load def /RL /rlineto load def /ST /stroke load def /MT /moveto load def /CL /closepath load def % fill the last path % amount FL - /FL { currentgray exch setgray fill setgray } bind def % fill with the ``current color'' /BL /fill load def /LW /setlinewidth load def % new_font_name encoding_vector old_font_name RE - /RE { findfont dup maxlength dict begin { 1 index /FID ne { def } { pop pop } ifelse } forall /Encoding exch def dup /FontName exch def currentdict end definefont pop } bind def /DEFS 0 def % hpos vpos EBEGIN - /EBEGIN { moveto DEFS begin } bind def /EEND /end load def /CNT 0 def /level1 0 def % llx lly newwid wid newht ht newllx newlly PBEGIN - /PBEGIN { /level1 save def translate div 3 1 roll div exch scale neg exch neg exch translate % set the graphics state to default values 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin 10 setmiterlimit [] 0 setdash /setstrokeadjust where { pop false setstrokeadjust } if /setoverprint where { pop false setoverprint } if newpath /CNT countdictstack def userdict begin /showpage {} def } bind def /PEND { clear countdictstack CNT sub { end } repeat level1 restore } bind def end def /setpacking where { pop setpacking } if %%EndResource %%IncludeResource: font Times-Roman %%IncludeResource: font Times-Italic %%IncludeResource: font Courier grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL 792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron/zcaron /Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space /exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft /parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four /five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C /D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash /bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q /r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase /guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger /daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut /dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash /quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar /section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus /registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu /paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright /onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde /Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute /Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis /multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls /agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute /ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve /oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex /udieresis/yacute/thorn/ydieresis]def/Courier@0 ENC0/Courier RE/Times-Italic@0 ENC0/Times-Italic RE/Times-Roman@0 ENC0/Times-Roman RE %%EndProlog %%Page: 1 1 %%BeginPageSetup BP %%EndPageSetup /F0 13/Times-Roman@0 SF(The History of PCCTS)228.232 84 Q/F1 11/Times-Roman@0 SF(The Purdue Compiler)190.468 108 Q(-Construction T)-.22 E(ool Set)-.88 E/F2 10/Times-Italic@0 SF -.92(Te)262.245 144 S -.37(re).92 G(nce P).37 E(arr)-.8 E /F3 10/Times-Roman@0 SF -.15(Pa)234.755 156 S(rr Research Corporation).15 E (Minneapolis, Minnesota)239.39 168 Q(and)280.78 180 Q(Uni)239.315 192 Q -.15 (ve)-.25 G(rsity of Minnesota).15 E (Army High Performance Computing Research Center)180.38 204 Q F2 ([Updated 8-7-94])252.31 228 Q F1 .084(The PCCTS project be)97 259.6 R -.055 (ga)-.165 G 2.834(na).055 G 2.833(sap)220.547 259.6 S(arser)240.876 259.6 Q .083(-generator project for a graduate course at Purdue Uni-)-.22 F -.165(ve)72 275.6 S 1.085(rsity in the F).165 F 1.086 (all of 1988 taught by Hank Dietz\212 translator)-.165 F 1.086 (-writing systems.)-.22 F 1.086(Under the guid-)6.586 F .627 (ance of Professor Dietz, the parser generator)72 291.6 R 3.377(,A)-.44 G .626 (NTLR \(originally called YUCC\), continued after)285.18 291.6 R .253 (the termination of the course and e)72 307.6 R -.165(ve)-.275 G .254 (ntually became the subject of T).165 F .254(erence P)-.77 F(arr')-.165 E 3.004 (sM)-.605 G(aster')445.083 307.6 Q 3.004(st)-.605 G(hesis.)479.25 307.6 Q (Originally)72 323.6 Q 4.092(,l)-.715 G -.165(ex)126.406 323.6 S 1.342 (ical analysis w).165 F 1.342(as performed via ALX which w)-.11 F 1.342 (as soon replaced by W)-.11 F 1.341(ill Cohen')-.44 F(s)-.605 E .594 (DLG in the F)72 339.6 R .594(all of 1989 \(DF)-.165 F .595(A-based le)-.814 F .595(xical-analyzer generator)-.165 F 3.345(,a)-.44 G .595(lso an of)367.188 339.6 R .595(fshoot of the graduate)-.275 F(translation course\).)72 355.6 Q .877(The alpha v)97 375.2 R .877(ersion of ANTLR w)-.165 F .877(as totally re) -.11 F .876(written resulting in 1.00B.)-.275 F -1.221(Ve)6.376 G .876 (rsion 1.00B w)1.221 F(as)-.11 E 1.577(released via an internet ne)72 391.2 R 1.577(wsgroup \(comp.compilers\) posting in February of 1990 and quickly)-.275 F -.055(ga)72 407.2 S .356(thered a lar).055 F .356(ge follo)-.198 F 3.106 (wing. 1.00B)-.275 F .356(generated only LL\(1\) parsers, b)3.106 F .356 (ut allo)-.22 F .356(wed the mer)-.275 F .356(ged descrip-)-.198 F 1.859 (tion of le)72 423.2 R 1.859(xical and syntactic analysis.)-.165 F 1.86 (It had rudimentary attrib)7.359 F 1.86(ute handling similar to that of)-.22 F -.55 -1.32(YA C)72 439.2 T 3.549(Ca)1.32 G .799 (nd did not incorporate rule parameters or return v)109.231 439.2 R .798 (alues; do)-.275 F(wnw)-.275 E .798(ard inheritance w)-.11 F .798(as v)-.11 F (ery)-.165 E -.165(aw)72 455.2 S(kw).165 E 6.433(ard. 1.00B-generated)-.11 F 3.684(parsers terminated upon the \214rst syntax error)6.433 F 9.184(.L)-.605 G -.165(ex)440.916 455.2 S 3.684(ical classes).165 F(\(modes\) were not allo)72 471.2 Q(wed and DLG did not ha)-.275 E .33 -.165(ve a)-.22 H 2.75(ni).165 G (nteracti)305.959 471.2 Q .33 -.165(ve m)-.275 H(ode.).165 E .831 (Upon starting his Ph.D. at Purdue in the F)97 490.8 R .83(all of 1990, T)-.165 F .83(erence P)-.77 F .83(arr be)-.165 F -.055(ga)-.165 G 3.58(nt).055 G .83 (he second total)436.351 490.8 R(re)72 506.8 Q 1.646(write of ANTLR.)-.275 F 1.646(The method by which grammars may be practically analyzed to generate) 7.146 F/F4 11/Times-Italic@0 SF(LL)72.638 522.8 Q F1(\().583 E F4(k).396 E F1 3.849(\)l).737 G 1.099(ookahead information w)105.703 522.8 R 1.099(as disco) -.11 F -.165(ve)-.165 G 1.099(red in August of 1990 just before his return.) .165 F -1.221(Ve)6.598 G(rsion)1.221 E .626 (1.00 incorporated this algorithm and included the AST mechanism, le)72 538.8 R .626(xical classes, error classes,)-.165 F .354(and automatic error reco)72 554.8 R -.165(ve)-.165 G .353(ry; code quality and portability were higher).165 F 5.853(.I)-.605 G 3.103(nF)395.965 554.8 S .353(ebruary of 1992 1.00)410.684 554.8 R -.11(wa)72 570.8 S 2.76(sr).11 G .01 (eleased via an article in SIGPLAN Notices.)95.418 570.8 R .01 (Peter Dahl, Ph.D. candidate, and Professor Matt)5.51 F(O'K)72 586.8 Q 2.074 (eefe \(both at the Uni)-.275 F -.165(ve)-.275 G 2.073 (rsity of Minnesota\) tested this v).165 F 2.073(ersion e)-.165 F(xtensi)-.165 E -.165(ve)-.275 G(ly).165 E 7.573(.D)-.715 G 2.073(ana Hogg)448.522 586.8 R (att)-.055 E .078(\(Micro Data Base Systems, Inc.\) came up with the idea of e\ rror grouping \(strings attached to non-)72 602.8 R (terminals\) and tested 1.00 hea)72 618.8 Q(vily)-.22 E(.)-.715 E -1.221(Ve)97 638.4 S .878(rsion 1.06 w)1.221 F .877 (as released in December 1992 and represented a lar)-.11 F .877 (ge feature enhancement)-.198 F -.165(ove)72 654.4 S 3.648(r1).165 G 3.648 (.00. F)100.365 654.4 R .898(or e)-.165 F .899 (xample, rudimentary semantic predicates were introduced, error messages were) -.165 F 2.281(signi\214cantly impro)72 670.4 R -.165(ve)-.165 G 5.031(df).165 G (or)181.953 670.4 Q F4(k)5.427 E F1 2.281 (>1 lookahead and ANTLR parsers could indicate that lookahead).737 F 1.381 (fetches were to occur only when necessary for the parse \(normally)72 686.4 R 4.131(,t)-.715 G 1.381(he lookahead `)387.051 686.4 R(`pipe')-.814 E 4.132('w) -.814 G(as)494.837 686.4 Q 1.182(constantly full\).)72 702.4 R 1.182 (Russell Quong joined the project in the Spring of 1992 to aid in the semantic) 6.682 F .681(predicate design.)72 718.4 R(Be)6.181 E .681(ginning and adv)-.165 F .682(anced tutorials were created and released as well.)-.275 F 3.432(Am) 6.182 G(ak)485.179 718.4 Q(e-)-.11 E .993(\214le generator w)72 734.4 R .993 (as included that sets up dependencies and such correctly for ANTLR and DLG.) -.11 F EP %%Page: 2 2 %%BeginPageSetup BP %%EndPageSetup /F0 11/Times-Roman@0 SF 2.75(-2-)278.837 52 S -1.221(Ve)72 88 S 1.414(ry fe) 1.221 F 4.164(w1)-.275 G 1.414(.00 incompatibilities were introduced \(1.00 w) 122.81 88 R 1.415(as quite dif)-.11 F 1.415(ferent from 1.00B in some)-.275 F (areas\).)72 104 Q 1.089(1.10 w)97 123.6 R 1.088 (as released on August 31, 1993 and incorporated b)-.11 F 1.088(ug \214x)-.22 F 1.088(es, a fe)-.165 F 3.838(wf)-.275 G 1.088(eature enhance-)433.59 123.6 R 3.112(ments and a major ne)72 139.6 R 5.863(wc)-.275 G(apability \212)196.957 139.6 Q 3.113(an arbitrary lookahead operator \(syntactic predicate\),)5.863 F /F1 11/Courier@0 SF(\(alpha\)?beta)72 155.6 Q F0 6.754(.T)C 1.254 (his feature w)167.425 155.6 R 1.254 (as co-designed with Professor Russell Quong also at Purdue.)-.11 F 3.297 -.88 (To s)72 171.6 T 1.537 (upport in\214nite lookahead, a preprocessor \215ag, ZZINF_LOOK, w).88 F 1.537 (as created that forced the)-.11 F .21(ANTLR\(\) macro to tok)72 187.6 R .21 (enize all input prior to parsing.)-.11 F .209(Hence, at an)5.709 F 2.959(ym) -.165 G .209(oment, an action or predi-)389.215 187.6 R .936 (cate can see the entire input sentence.)72 203.6 R .936 (The predicate mechanism of 1.06 w)6.436 F .937(as e)-.11 F .937 (xtended to allo)-.165 F(w)-.275 E .55 (multiple predicates to be hoisted; the syntactic conte)72 219.6 R .55 (xt of a predicate w)-.165 F .55(as also mo)-.11 F -.165(ve)-.165 G 3.299(da) .165 G .549(long with)461.585 219.6 R(the predicate.)72 235.6 Q .754 (In February of 1994, SORCERER \(a simple tree-parser generator\) w)97 255.2 R .755(as released.)-.11 F .755(This tool)6.255 F(allo)72 271.2 Q .6(ws the user\ to parse child-sibling trees by specifying a grammar rather than b)-.275 F .599(uilding a recur)-.22 F(-)-.22 E(si)72 287.2 Q -.165(ve)-.275 G 1.39 (-descent tree w).165 F(alk)-.11 E 1.391(er by hand.)-.11 F -.88(Wo)6.891 G 1.391(rk to).88 F -.11(wa)-.275 G 1.391 (rds a library of tree transformations is underw).11 F(ay)-.11 E(.)-.715 E .581 (Aaron Sa)72 303.2 R(wde)-.165 E 3.331(ya)-.165 G 3.331(tT)145.531 303.2 S .581 (he Uni)158.641 303.2 R -.165(ve)-.275 G .58 (rsity of Minnesota became a second author of SORCERER after the).165 F (initial release.)72 319.2 Q .627(On April 1, 1994, PCCTS 1.20 w)97 338.8 R .627(as released.)-.11 F .627(This w)6.127 F .627(as the \214rst v)-.11 F .627 (ersion to acti)-.165 F -.165(ve)-.275 G .627(ly support).165 F 1.664 (C++ output.)72 354.8 R 1.664(It also included important \214x)7.164 F 1.663 (es re)-.165 F -.055(ga)-.165 G 1.663 (rding semantic predicates and \(..\)+ subrules.).055 F(This v)72 370.8 Q (ersion also introduced tok)-.165 E(en classes, the `)-.11 E(`)-.814 E/F2 11 /Times-Italic@0 SF(not)A F0 1.628 -.814('' o)D(perator).814 E 2.75(,a)-.44 G (nd tok)355.294 370.8 Q(en ranges.)-.11 E .764 (On June 19, 1994, SORCERER 1.00B9 w)97 390.4 R .765(as released.)-.11 F .765 (Gary Funck of Intrepid T)6.265 F(echnology)-.77 E .807 (joined the SORCERER team and pro)72 406.4 R .807(vided v)-.165 F .807(ery v) -.165 F .807(aluable suggestions re)-.275 F -.055(ga)-.165 G .806(rding the `) .055 F(`transform')-.814 E(')-.814 E(mode of SORCERER.)72 422.4 Q 1.137 (On August 8, 1994, PCCTS 1.21 w)97 442 R 1.137(as released.)-.11 F 1.138 (It mainly cleaned up the C++ output and)6.637 F(included a number of b)72 458 Q(ug \214x)-.22 E(es.)-.165 E .316(From the 1.21 release forw)97 477.6 R .316 (ard, the maintenance and support of all PCCTS tools will be pri-)-.11 F 1.557 (marily pro)72 493.6 R 1.557(vided by P)-.165 F 1.557 (arr Research Corporation, Minneapolis MN---an or)-.165 F -.055(ga)-.198 G 1.558(nization founded on).055 F 1.616(the principles of e)72 509.6 R 1.616 (xcellence in research and inte)-.165 F 1.616(grity in b)-.165 F 1.616 (usiness; we are de)-.22 F -.22(vo)-.275 G 1.616(ted to pro).22 F(viding)-.165 E 1.202(really cool softw)72 525.6 R 1.202(are tools.)-.11 F 1.202 (Please see \214le PCCTS.FUTURE for more information.)6.702 F 1.203(All PCCTS) 6.703 F(tools currently in the public domain will continue to be in the public\ domain.)72 541.6 Q 1.198(Looking to)97 561.2 R -.11(wa)-.275 G 1.198 (rds the future, a graphical user).11 F(-interf)-.22 E 1.197 (ace is in the design phase.)-.11 F 1.197(This w)6.697 F(ould)-.11 E(allo)72 577.2 Q 2.753(wu)-.275 G .003(sers to vie)104.42 577.2 R 2.753(wt)-.275 G .004 (he syntax diagram representation of their grammars and w)162.509 577.2 R .004 (ould highlight non-)-.11 F 1.181(deterministic productions.)72 593.2 R -.165 (Pa)6.681 G 1.18(rsing can be traced graphically as well.).165 F 1.18 (This system will be b)6.68 F(uilt)-.22 E .167(using a multiplatform windo)72 609.2 R 2.917(wl)-.275 G(ibrary)211.73 609.2 Q 5.667(.W)-.715 G 2.917(ea) 255.204 609.2 S .168(lso anticipate the introduction of a sophisticated error) 267.889 609.2 R(handling mechanism called `)72 625.2 Q(`parser e)-.814 E (xception handling')-.165 E 2.75('i)-.814 G 2.75(nan)327.431 625.2 S (ear future release.)348.815 625.2 Q(Currently)97 644.8 Q 3.019(,P)-.715 G .269 (CCTS is used at o)150.333 644.8 R -.165(ve)-.165 G 3.019(r1).165 G .269 (000 kno)253.098 644.8 R .268(wn academic, go)-.275 F -.165(ve)-.165 G .268 (rnment, and commercial sites).165 F .859(in 37 countries.)72 660.8 R .859 (Of course, the true number of users is unkno)6.359 F .859(wn due to the lar) -.275 F .859(ge number of ftp)-.198 F(sites.)72 676.8 Q EP %%Page: 3 3 %%BeginPageSetup BP %%EndPageSetup /F0 11/Times-Roman@0 SF 2.75(-3-)278.837 52 S(Credits)272.11 88 Q .44 LW 472.162 103.75 103.838 103.75 DL(Idea/T)134.236 117 Q 52.987(ool Coder)-.88 F (Co-designer\(s\))345.436 117 Q 281.334 103.75 281.334 124.75 DL 209.273 103.75 209.273 124.75 DL 209.273 124.75 103.838 124.75 DL 103.838 126.75 209.273 126.75 DL 281.334 124.75 209.273 124.75 DL 209.273 126.75 281.334 126.75 DL 472.162 124.75 281.334 124.75 DL 281.334 126.75 472.162 126.75 DL(ANTLR 1.00A) 109.338 140 Q -.77(Te)217.523 140 S(rence P).77 E 13.75(arr Hank)-.165 F(Dietz) 2.75 E 82.83(ALX T)109.338 156 R(erence P)-.77 E 13.75(arr Hank)-.165 F(Dietz) 2.75 E(ANTLR 1.00B)109.338 172 Q -.77(Te)217.523 172 S(rence P).77 E 13.75 (arr Hank)-.165 F(Dietz, W)2.75 E(ill Cohen)-.44 E(DLG 1.00B)109.338 188 Q -.44 (Wi)217.523 188 S(ll Cohen).44 E -.77(Te)289.584 188 S(rence P).77 E(arr)-.165 E 2.75(,H)-.44 G(ank Dietz)358.147 188 Q(NF)109.338 204 Q 2.75(AR)-.814 G 30.778(elabelling W)140.611 204 R(ill Cohen)-.44 E/F1 11/Times-Italic@0 SF(LL) 109.976 220 Q F0(\().583 E F1(k).396 E F0 2.75(\)a).737 G 40.447(nalysis T) 143.768 220 R(erence P)-.77 E 13.75(arr Hank)-.165 F(Dietz)2.75 E(ANTLR 1.00) 109.338 236 Q -.77(Te)217.523 236 S(rence P).77 E 13.75(arr Hank)-.165 F (Dietz, W)2.75 E(ill Cohen)-.44 E(DLG 1.00)109.338 252 Q -.44(Wi)217.523 252 S (ll Cohen).44 E -.77(Te)289.584 252 S(rence P).77 E(arr)-.165 E 2.75(,H)-.44 G (ank Dietz)358.147 252 Q(ANTLR 1.06)109.338 268 Q -.77(Te)217.523 268 S (rence P).77 E 13.75(arr W)-.165 F(ill Cohen, Russell Quong, Hank Dietz)-.44 E (DLG 1.06)109.338 284 Q -.44(Wi)217.523 284 S(ll Cohen).44 E -.77(Te)289.584 284 S(rence P).77 E(arr)-.165 E 2.75(,H)-.44 G(ank Dietz)358.147 284 Q (ANTLR 1.10)109.338 300 Q -.77(Te)217.523 300 S(rence P).77 E 13.75(arr W)-.165 F(ill Cohen, Russell Quong)-.44 E(ANTLR 1.20)109.338 316 Q -.77(Te)217.523 316 S(rence P).77 E 13.75(arr W)-.165 F(ill Cohen, Russell Quong)-.44 E(ANTLR 1.21) 109.338 332 Q -.77(Te)217.523 332 S(rence P).77 E 13.75(arr Russell)-.165 F (Quong)2.75 E(DLG 1.10)109.338 348 Q -.44(Wi)217.523 348 S(ll Cohen).44 E -.77 (Te)289.584 348 S(rence P).77 E(arr)-.165 E(DLG 1.20)109.338 364 Q -.44(Wi) 217.523 364 S(ll Cohen).44 E -.77(Te)289.584 364 S(rence P).77 E(arr)-.165 E (DLG 1.21)109.338 380 Q -.77(Te)217.523 380 S(rence P).77 E(arr)-.165 E (Semantic predicates)109.338 396 Q -.77(Te)217.523 396 S(rence P).77 E 13.75 (arr Russell)-.165 F(Quonq)2.75 E(Syntactic predicates)109.338 412 Q -.77(Te) 217.523 412 S(rence P).77 E 13.75(arr Russell)-.165 F(Quonq)2.75 E (SORCERER 1.00A)109.338 428 Q -.77(Te)217.523 428 S(rence P).77 E(arr)-.165 E (SORCERER 1.00B)109.338 444 Q -.77(Te)217.523 444 S(rence P).77 E 13.75 (arr Aaron)-.165 F(Sa)2.75 E(wde)-.165 E(y)-.165 E(SORCERER 1.00B9)109.338 460 Q -.77(Te)217.523 460 S(rence P).77 E 13.75(arr Aaron)-.165 F(Sa)2.75 E(wde) -.165 E 1.43 -.715(y, G)-.165 H(ary Funck).715 E 472.162 467.75 103.838 467.75 DL 472.162 103.75 472.162 467.75 DL 103.838 103.75 103.838 467.75 DL EP %%Trailer end %%EOF cccc-3.1.4/pccts/history.txt0000644000000000000000000002036707265347344014514 0ustar rootroot The History of PCCTS The Purdue Compiler-Construction Tool Set Terence Parr Parr Research Corporation Minneapolis, Minnesota and University of Minnesota Army High Performance Computing Research Center [Updated 8-7-94] The PCCTS project began as a parser-generator project for a gra- duate course at Purdue University in the Fall of 1988 taught by Hank Dietz- translator-writing systems. Under the guidance of Professor Dietz, the parser generator, ANTLR (originally called YUCC), continued after the termination of the course and eventually became the subject of Terence Parr's Master's thesis. Originally, lexical analysis was performed via ALX which was soon replaced by Will Cohen's DLG in the Fall of 1989 (DFA-based lexical-analyzer generator, also an offshoot of the graduate translation course). The alpha version of ANTLR was totally rewritten resulting in 1.00B. Version 1.00B was released via an internet newsgroup (comp.compilers) posting in February of 1990 and quickly gathered a large following. 1.00B generated only LL(1) parsers, but allowed the merged description of lexical and syntactic analysis. It had rudimen- tary attribute handling similar to that of YACC and did not incor- porate rule parameters or return values; downward inheritance was very awkward. 1.00B-generated parsers terminated upon the first syntax error. Lexical classes (modes) were not allowed and DLG did not have an interactive mode. Upon starting his Ph.D. at Purdue in the Fall of 1990, Terence Parr began the second total rewrite of ANTLR. The method by which grammars may be practically analyzed to generate LL(k) lookahead information was discovered in August of 1990 just before his return. Version 1.00 incorporated this algorithm and included the AST mechan- ism, lexical classes, error classes, and automatic error recovery; code quality and portability were higher. In February of 1992 1.00 was released via an article in SIGPLAN Notices. Peter Dahl, Ph.D. candidate, and Professor Matt O'Keefe (both at the University of Min- nesota) tested this version extensively. Dana Hoggatt (Micro Data Base Systems, Inc.) came up with the idea of error grouping (strings attached to non-terminals) and tested 1.00 heavily. Version 1.06 was released in December 1992 and represented a large feature enhancement over 1.00. For example, rudimentary seman- tic predicates were introduced, error messages were significantly improved for k>1 lookahead and ANTLR parsers could indicate that loo- kahead fetches were to occur only when necessary for the parse Page 1 PCCTS (normally, the lookahead "pipe" was constantly full). Russell Quong joined the project in the Spring of 1992 to aid in the semantic predi- cate design. Beginning and advanced tutorials were created and released as well. A makefile generator was included that sets up dependencies and such correctly for ANTLR and DLG. Very few 1.00 incompatibilities were introduced (1.00 was quite different from 1.00B in some areas). 1.10 was released on August 31, 1993 and incorporated bug fixes, a few feature enhancements and a major new capability - an arbitrary lookahead operator (syntactic predicate), (alpha)?beta. This feature was co-designed with Professor Russell Quong also at Purdue. To sup- port infinite lookahead, a preprocessor flag, ZZINF_LOOK, was created that forced the ANTLR() macro to tokenize all input prior to parsing. Hence, at any moment, an action or predicate can see the entire input sentence. The predicate mechanism of 1.06 was extended to allow mul- tiple predicates to be hoisted; the syntactic context of a predicate was also moved along with the predicate. In February of 1994, SORCERER (a simple tree-parser generator) was released. This tool allows the user to parse child-sibling trees by specifying a grammar rather than building a recursive-descent tree walker by hand. Work towards a library of tree transformations is underway. Aaron Sawdey at The University of Minnesota became a second author of SORCERER after the initial release. On April 1, 1994, PCCTS 1.20 was released. This was the first version to actively support C++ output. It also included important fixes regarding semantic predicates and (..)+ subrules. This version also introduced token classes, the "not" operator, and token ranges. On June 19, 1994, SORCERER 1.00B9 was released. Gary Funck of Intrepid Technology joined the SORCERER team and provided very valu- able suggestions regarding the "transform" mode of SORCERER. On August 8, 1994, PCCTS 1.21 was released. It mainly cleaned up the C++ output and included a number of bug fixes. From the 1.21 release forward, the maintenance and support of all PCCTS tools will be primarily provided by Parr Research Corporation, Minneapolis MN---an organization founded on the principles of excel- lence in research and integrity in business; we are devoted to provid- ing really cool software tools. Please see file PCCTS.FUTURE for more information. All PCCTS tools currently in the public domain will con- tinue to be in the public domain. Looking towards the future, a graphical user-interface is in the design phase. This would allow users to view the syntax diagram representation of their grammars and would highlight nondeterministic productions. Parsing can be traced graphically as well. This system will be built using a multiplatform window library. We also antici- pate the introduction of a sophisticated error handling mechanism called "parser exception handling" in a near future release. Page 2 PCCTS Currently, PCCTS is used at over 1000 known academic, government, and commercial sites in 37 countries. Of course, the true number of users is unknown due to the large number of ftp sites. Credits _____________________________________________________________________________ _____________________________________________________________________________ |ANTLR 1.00A Terence Parr Hank Dietz | |ALX Terence Parr Hank Dietz | |ANTLR 1.00B Terence Parr Hank Dietz, Will Cohen | |DLG 1.00B Will Cohen Terence Parr, Hank Dietz | |NFA Relabelling Will Cohen | |LL(k) analysis Terence Parr Hank Dietz | |ANTLR 1.00 Terence Parr Hank Dietz, Will Cohen | |DLG 1.00 Will Cohen Terence Parr, Hank Dietz | |ANTLR 1.06 Terence Parr Will Cohen, Russell Quong, Hank Dietz| |DLG 1.06 Will Cohen Terence Parr, Hank Dietz | |ANTLR 1.10 Terence Parr Will Cohen, Russell Quong | |ANTLR 1.20 Terence Parr Will Cohen, Russell Quong | |ANTLR 1.21 Terence Parr Russell Quong | |DLG 1.10 Will Cohen Terence Parr | |DLG 1.20 Will Cohen Terence Parr | |DLG 1.21 Terence Parr | |Semantic predicates Terence Parr Russell Quonq | |Syntactic predicates Terence Parr Russell Quonq | |SORCERER 1.00A Terence Parr | |SORCERER 1.00B Terence Parr Aaron Sawdey | |SORCERER 1.00B9 Terence Parr Aaron Sawdey, Gary Funck | |___________________________________________________________________________| Page 3 cccc-3.1.4/pccts/install68K.mpw0000644000000000000000000000400307265347344014723 0ustar rootroot# # File name install68K.mpw # # Description This script builds 68K version of antlr, dlg and sor. # and install them into Tools folder in your MPW. # They have commando interfaces. # # Installation Set Directory to the directory containing this file. # Enter "install68K.mpw" and press enter key. # # Requirements SC compiler # http://developer.apple.com/dev/tools/mpw-tools/compilers/index.html # # Author Kenji Tanaka (kentar@osa.att.ne.jp) # http://www.geocities.com/SiliconValley/Platform/5502/pccts # Created 06/16/98 # Modified 12/14/98 # Echo "# `Date -t` ----- Building 68K version of PCCTS tools." # Make 'Macintosh' folders to hold object files. Echo "# `Date -t` ----- Making Object File Folders." If (!`exists :dlg:Obj:`) NewFolder :dlg:Obj: End If (!`exists :antlr:Obj:`) NewFolder :antlr:Obj: End If (!`exists :sorcerer:Obj:`) NewFolder :sorcerer:Obj: End Echo "# `Date -t` ----- Done." Echo "#" # DLG build commands Echo "# `Date -t` ----- Building DLG." Echo "# `Date -t` ----- Analyzing dependencies." Directory :dlg: Begin Echo "Set Echo 1" Make Install -f dlg68K.make End > dlg.makeout Echo "# `Date -t` ----- Executing build commands." dlg.makeout Delete dlg.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # ANTLR build commands Echo "# `Date -t` ----- Building ANTLR." Echo "# `Date -t` ----- Analyzing dependencies." Directory :antlr: Begin Echo "Set Echo 1" Make Install -f antlr68K.make End > antlr.makeout antlr.makeout Delete antlr.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # SORCERER build commands Echo "# `Date -t` ----- Building SORCERER." Echo "# `Date -t` ----- Analyzing dependencies." Directory :sorcerer: Begin Echo "Set Echo 1" Make Install -f sor68K.make End > sorcerer.makeout sorcerer.makeout Delete sorcerer.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # Done Echo "# `Date -t` ----- Done Building 68K version of PCCTS tools." cccc-3.1.4/pccts/installPPC.mpw0000644000000000000000000000401007265347347014776 0ustar rootroot# File name installPPC.mpw # # Description This script builds PPC version of antlr, dlg and sor. # and install them into Tools folder in your MPW. # They have commando interfaces. # # Installation Set Directory to the directory containing this file. # Enter "installPPC.mpw" and press enter key. # # Requirements MrC(for PPC) compiler # http://developer.apple.com/dev/tools/mpw-tools/compilers/index.html # # Author Kenji Tanaka (kentar@osa.att.ne.jp) # http://www.geocities.com/SiliconValley/Platform/5502/pccts # Created 06/16/98 # Modified 12/14/98 Echo "# `Date -t` ----- Building PPC version of PCCTS tools." # Make 'Macintosh' folders to hold object files. Echo "# `Date -t` ----- Making Object File Folders." If (!`exists :dlg:Obj:`) NewFolder :dlg:Obj: End If (!`exists :antlr:Obj:`) NewFolder :antlr:Obj: End If (!`exists :sorcerer:Obj:`) NewFolder :sorcerer:Obj: End Echo "# `Date -t` ----- Done." Echo "#" # DLG build commands Echo "# `Date -t` ----- Building DLG." Echo "# `Date -t` ----- Analyzing dependencies." Directory :dlg: Begin Echo "Set Echo 1" Make Install -f dlgPPC.make End > dlg.makeout Echo "# `Date -t` ----- Executing build commands." dlg.makeout Delete dlg.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # ANTLR build commands Echo "# `Date -t` ----- Building ANTLR." Echo "# `Date -t` ----- Analyzing dependencies." Directory :antlr: Begin Echo "Set Echo 1" Make Install -f antlrPPC.make End > antlr.makeout antlr.makeout Delete antlr.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # SORCERER build commands Echo "# `Date -t` ----- Building SORCERER." Echo "# `Date -t` ----- Analyzing dependencies." Directory :sorcerer: Begin Echo "Set Echo 1" Make Install -f sorPPC.make End > sorcerer.makeout sorcerer.makeout Delete sorcerer.makeout Delete -y Obj Echo "# `Date -t` ----- Done." Echo "#" Directory :: # Done Echo "# `Date -t` ----- Done Building PPC version of PCCTS tools." cccc-3.1.4/pccts/makefile0000644000000000000000000000272207273557631013746 0ustar rootroot# # Main makefile for PCCTS 1.33MR20 /* MRXXX */ # # Terence Parr # Parr Research Corporation # # verbosity versus silence... PSss= # # this can be set to /user/local/bin etc... BINDIR=bin # This part added by Thomas Herter, M"unchen, Germany. See also manpages # target. MANDIR=$(HOME)/man MANEXT=1 MANFILES=pccts.1 dlg/dlg.1 antlr/antlr.1 #CC=cc .SILENT: pccts: echo " " echo " Welcome to PCCTS 1.33MR20a installation" echo " " echo " (Version 1.33 Maintenance Release #20a)" echo " " echo " Released 10 August 1999" echo " " echo " Featuring" echo " ANTLR -- ANother Tool for Language Recognition" echo " DLG -- DFA-based Lexical Analyzer Generator" echo " SORCERER -- Source-to-source translator (tree walker)" echo " " echo " http://www.antlr.org" echo " " echo " Trouble reports to tmoog@polhode.com" echo " Additional PCCTS 1.33 information at" echo " http://www.polhode.com" echo # if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi echo Making executables... (cd antlr; make -s) echo antlr executable now in $(BINDIR) (cd dlg; make -s) echo dlg executable now in $(BINDIR) echo echo " PCCTS 1.33MR20 installation complete" clean: (cd antlr; make -s clean) (cd dlg; make -s clean) manpages: if [ ! -d $(MANDIR) ] ; then mkdir $(MANDIR) ; fi cp -p $(MANFILES) $(MANDIR)/man$(MANEXT) cccc-3.1.4/pccts/old_README0000644000000000000000000001636107265347363013770 0ustar rootroot Welcome to PCCTS 1.33 October 5, 1995 Parr Research Corporation with Purdue University Electrical Engineering and University of Minnesota, AHPCRC Terence Parr Russell Quong Will Cohen Hank Dietz [The "NOTES for new users" by Tom Moog is available now via web browser at http:www.mcs.net/~tmoog and via anonymous ftp at ftp.mcs.net/mcsnet.users/tmoog.] [We've removed PCCTS.FUTURE from the distribution and added file SERVICES, which describes the services of Parr Research Corporation.] INSTALLATION This document describes the installation of PCCTS 1.33 on UNIX and non-UNIX machines. The UNIX installation is trivial while the non-UNIX folks have a bit more work to do as an install script explicitly for there machine will not exist--they will have to interpret the install script. PCCTS 1.33 includes a number of different programs and examples in the software release package -- most of which like to live in their own directories. The install script will build a standard hierarchy. Or, if you get the tar file off the ftp site, the hierarchy will be constructed automatically by tar. The PCCTS executables (antlr, dlg) may be placed anywhere the user wishes but the install script places them in the bin directory created during installation. 1.0. UNIX USERS This section is for UNIX users and describes the most convenient installation procedure. 1.1. FORMAT: pccts.tar To begin installation, place the pccts.tar file into the directory where you want to place a pccts subdirectory. Untar the file with tar xvf pccts.tar and cd into it. To install PCCTS, simply type make which will build the standard PCCTS directory hierarchy (under the directory where you ran the install script) and build executable versions of antlr and dlg. 1.2. FORMAT: pccts.bag To begin installation, the user should create a directory (usually called pccts) where the PCCTS source subtree is to be created. Place the pccts.bag file and the install script into this directory and cd into it. To install PCCTS, simply type sh install which will build the standard PCCTS directory hierarchy (under the directory where you ran the install script), "unbag" all of the files and build executable versions of antlr and dlg. If you do not have the 'sh' shell, you'll need the install.unbag.reqd file. NOTE: If you are using the later SGI C++ compilers, use -woff 3262 to get rid of a bunch of noise by the compiler (warnings). 2.0. NON-UNIX USERS ANTLR was written using portable (we hope), vanilla K&R-style C, ANSI C, and C++. It has been successfully ported to a variety of environments. We do not provide an installation script explicitly for non-Unix users. You must interpret the install script and perform the analogous operations on your machine. There is an install script, install.mpw, for Macintosh programmers. IMPORTANT NOTE: For PC users: You must create the parser.dlg and "touch" scan.c in antlr and dlg directories or the makefiles will try to execute antlr and dlg, which don't exist yet. The first time, you want only to compile the C files in order to obtain an executable for antlr and dlg. From this point, a change in antlr.g or dlg_p.g will force antlr/dlg to regenerate themselves. You must define symbol PC if you want things to work out right for use on a DOS, OS/2, Windows machine. This affects the config.h file, which you can change as you wish. For Mac programmers using MPW (Macintosh Programmer's Workshop), define symbol MPW to get the correct config.h stuff included. 3.0. EMAIL VERSION RECIPIENTS If you received PCCTS via email response from pccts@ecn.purdue.edu you have one additional installation step to perform over the ftp folks (and pccts.tar is unavailable). You will have received a number of bite-size chunks of pccts which are small enough to be emailed (~1500 lines each). You must reconstruct the PCCTS files before you can begin installation. In order to rebuild an original file, you must have "one.c" which will take the chunks and pack them together. If you are a non-UNIX type, you must have the "unbag.c" file which unbags the bags created by our mail archiver. UNIX folks use the shell to unbag as they would for shar files (this will be done automatically by the install script). To install PCCTS, place all PCCTS mail messages into a pccts directory, remove the mail headers from one.c. Then compile one.c with: cc -o one one.c and then type: ./one f1 f2 ... fn where f1..fn are the parts of PCCTS source sent as chunks (i.e. these files will be all the files you received NOT including one.c, unbag.c, README, install and the request acknowledge banner). There is no need to remove mail headers from the chunk files and they may appear in any order. The subject line of the mail will identify it as a chunk and a chunk of what file. The "one" program should be used to put pccts.bag back together. You are now in a position to begin normal PCCTS installation. All files you receive should go into a pccts directory. Note that all files which arrive in "chunks" must be put back together using "one". Beware that you do not mix chunks from more than one original file. For instance, do not specify all chunks that you collect from the PCCTS mailbot on the "one" command line unless you have requested only one original file that was split into multiple files. Each chunk knows which original file it is a part of, where it goes in that file and how many total chunks are required to rebuild that original. 4.0. WORD SIZE AND PC USERS The config.h file now sets up the word size for your compiler automatically. TUTORIAL The advanced tutorial should be placed in a directory at the same level as antlr, dlg, support etc... Do a sh advtut.bag to unbag (or use the unbag program) and then type make -s all which will create executables called tut1-tut4. Naturally, if you got the tutorials from the ftp site, the tar format of the tutorials can be obtained for easier installation. Unfortunately, the tutorials have changed little since the 1.06 release. With luck, these will be enhanced and an AST tutorial will appear. MACHINE COMPATIBILITY PCCTS is known to compile "out of the box" on the following machines and/or operating systems: [didn't have time to retest on all these machines, but seems to be highly portable still]. o DECSTATION 5000 o SGI; use "-woff 3262" in your CFLAGS make variable o Sun SparcStation (cc, gcc, g++, Cfront, acc) o VAX C under VMS o Linux SLS 0.99, gcc/g++ o 386 PC, NetBSD 0.9, gcc 2.4.5 o HP 9000/755, HP-UX 9.01, HP cc o 486 PC, OS/2 2.1 (w/long filenames), IBM C Set++ 2.1 o NeXTStep 3.2 running g++/gcc 2.6.3 (pentium-90) INCOMPATIBILITIES Please see the release notes. CREDITS Please see the history.ps or history.txt. cccc-3.1.4/pccts/IBM_VISUAL_AGE_PROJECTS/0000755000000000000000000000000010357462315015711 5ustar rootrootcccc-3.1.4/pccts/IBM_VISUAL_AGE_PROJECTS/antlr.icc0000644000000000000000000000120307265350456017513 0ustar rootrootoption ProjectOptions = define("USER_ZZSYN", ), define("__USE_PROTOS", ), incl(searchpath, "..\\h"), incl(searchpath, "..\\support\\set"), link(pmtype, vio) { target "..\\bin\\antlr.exe" { option incl(searchpath, "..\\antlr") { source type("c") "antlr.c","bits.c","build.c","dumpcycles.c", "dumpnode.c","egman.c","main.c","err.c", "fcache.c","fset.c","fset2.c","gen.c", "globals.c","hash.c","lex.c","main.c", "misc.c","mrhoist.c","pred.c","scan.c"} option incl(searchpath, "..\\support\\set") source type("c") "set.c" } } cccc-3.1.4/pccts/IBM_VISUAL_AGE_PROJECTS/dlg.icc0000644000000000000000000000104407265350456017144 0ustar rootrootoption ProjectOptions = define("USER_ZZSYN", ), define("__USE_PROTOS", ), incl(searchpath, "..\\h"), incl(searchpath, "..\\support\\set"), link(pmtype, vio) { target "..\\bin\\dlg.exe" { source type("c") "..\\dlg\\automata.c", "..\\dlg\\dlg_a.c", "..\\dlg\\dlg_p.c", "..\\dlg\\err.c", "..\\dlg\\main.c", "..\\dlg\\output.c", "..\\dlg\\relabel.c", "..\\dlg\\support.c", "..\\support\\set\\set.c" } } cccc-3.1.4/pccts/IBM_VISUAL_AGE_PROJECTS/sorcerer.icc0000644000000000000000000000102107265350461020211 0ustar rootroot0ption ProjectOptions = define("__USE_PROTOS", ), incl(searchpath, "..\\sorcerer\\h"), incl(searchpath, "..\\h"), incl(searchpath, "..\\support\\set"), link(pmtype, vio) { target "..\\bin\\sorcerer.exe" { option incl(searchpath, "..\\sorcerer") { source type("c") 'sor.c','scan.c','err.c','main.c','globals.c','gen.c','hash.c','look.c','cpp.c' } option incl(searchpath, "..\\support\\set") { source type("c") "set.c" } } } cccc-3.1.4/pccts/dlg/0000755000000000000000000000000010357462375013006 5ustar rootrootcccc-3.1.4/pccts/dlg/DlgMS.mak0000644000000000000000000000473007345450742014450 0ustar rootroot# PCCTS directory PCCTS_HOME=.. DLG_SRC=$(PCCTS_HOME)\dlg PCCTS_H=$(PCCTS_HOME)\h # Support directories SET=$(PCCTS_HOME)\support\set # Compiler stuff CC = cl CFLAGS = -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \ -D "ZZLEXBUFSIZE=65536" /D "LONGFILENAMES" /W3 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 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 cccc-3.1.4/pccts/dlg/DlgMSVC50.dsp0000644000000000000000000001067507267567717015107 0ustar rootroot# Microsoft Developer Studio Project File - Name="DLG" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=DLG - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "DlgMSVC50.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "DlgMSVC50.mak" CFG="DLG - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "DLG - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "DLG - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "DLG - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /O2 /I "..\h" /I "..\support\set" /D "__STDC__" /D "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"./Dlg.exe" # Begin Special Build Tool TargetPath=.\Dlg.exe SOURCE="$(InputPath)" PostBuild_Desc=Copying to ../bin PostBuild_Cmds=mkdir ..\bin copy $(TargetPath) ..\bin # End Special Build Tool !ELSEIF "$(CFG)" == "DLG - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /Gm /ZI /Od /I "..\h" /I "..\support\set" /D "__STDC__" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"./Dlg.exe" /pdbtype:sept # Begin Special Build Tool TargetPath=.\Dlg.exe SOURCE="$(InputPath)" PostBuild_Desc=Copying to ../bin PostBuild_Cmds=mkdir ..\bin copy $(TargetPath) ..\bin # End Special Build Tool !ENDIF # Begin Target # Name "DLG - Win32 Release" # Name "DLG - Win32 Debug" # Begin Source File SOURCE=.\automata.c # End Source File # Begin Source File SOURCE=.\dlg_a.c # End Source File # Begin Source File SOURCE=.\dlg_p.c !IF "$(CFG)" == "DLG - Win32 Release" !ELSEIF "$(CFG)" == "DLG - Win32 Debug" # SUBTRACT CPP /YX !ENDIF # End Source File # Begin Source File SOURCE=.\err.c # End Source File # Begin Source File SOURCE=.\main.c # End Source File # Begin Source File SOURCE=.\output.c # End Source File # Begin Source File SOURCE=.\relabel.c # End Source File # Begin Source File SOURCE=..\support\set\set.c # End Source File # Begin Source File SOURCE=.\support.c # End Source File # End Target # End Project cccc-3.1.4/pccts/dlg/DlgMSVC50.dsw0000644000000000000000000000077207265350233015070 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 5.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "DLG"=.\DlgMSVC50.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/dlg/DlgMSVC60.dsp0000644000000000000000000001362307265350236015064 0ustar rootroot# Microsoft Developer Studio Project File - Name="DLG" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=DLG - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "DlgMSVC60.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "DlgMSVC60.mak" CFG="DLG - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "DLG - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "DLG - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "DLG - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /O2 /I "..\h" /I "..\support\set" /D "__STDC__" /D "NDEBUG" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"./Dlg.exe" # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy to ..\bin directory PostBuild_Cmds=mkdir ..\bin copy ..\bin\dlg.exe dlg_old.exe copy dlg.exe ..\bin\. # End Special Build Tool !ELSEIF "$(CFG)" == "DLG - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "." # PROP Intermediate_Dir "." # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /Gm /ZI /Od /I "..\h" /I "..\support\set" /D "__STDC__" /D "LONGFILENAMES" /D "PC" /D "USER_ZZSYN" /D ZZLEXBUFSIZE=65536 /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"./Dlg.exe" /pdbtype:sept # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy to ..\bin directory PostBuild_Cmds=mkdir ..\bin copy ..\bin\dlg.exe dlg_old.exe copy dlg.exe ..\bin\. # End Special Build Tool !ENDIF # Begin Target # Name "DLG - Win32 Release" # Name "DLG - Win32 Debug" # Begin Source File SOURCE=.\automata.c # End Source File # Begin Source File SOURCE=.\dlg_a.c # End Source File # Begin Source File SOURCE=.\dlg_p.c !IF "$(CFG)" == "DLG - Win32 Release" !ELSEIF "$(CFG)" == "DLG - Win32 Debug" # SUBTRACT CPP /YX !ENDIF # End Source File # Begin Source File SOURCE=.\dlg_p.g !IF "$(CFG)" == "DLG - Win32 Release" # Begin Custom Build - Building DLG Parser from ANTLR Grammar InputPath=.\dlg_p.g InputName=dlg_p BuildCmds= \ ..\bin\antlr $(InputName).g -gh \ ..\bin\dlg -C2 parser.dlg dlg_a.c \ "dlg_a.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "dlg_p.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "err.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "mode.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "parser.dlg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "tokens.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "stdpccts.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) # End Custom Build !ELSEIF "$(CFG)" == "DLG - Win32 Debug" # Begin Custom Build - Building DLG Parser from ANTLR Grammar InputPath=.\dlg_p.g InputName=dlg_p BuildCmds= \ ..\bin\antlr $(InputName).g -gh \ ..\bin\dlg -C2 parser.dlg dlg_a.c \ "dlg_a.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "dlg_p.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "err.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "mode.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "parser.dlg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "tokens.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) "stdpccts.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" $(BuildCmds) # End Custom Build !ENDIF # End Source File # Begin Source File SOURCE=.\err.c # End Source File # Begin Source File SOURCE=.\main.c # End Source File # Begin Source File SOURCE=.\output.c # End Source File # Begin Source File SOURCE=.\relabel.c # End Source File # Begin Source File SOURCE=..\support\set\set.c # End Source File # Begin Source File SOURCE=.\support.c # End Source File # End Target # End Project cccc-3.1.4/pccts/dlg/DlgMSVC60.dsw0000644000000000000000000000077207265350236015074 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "DLG"=.\DlgMSVC60.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/dlg/automata.c0000644000000000000000000001766607265350217015000 0ustar rootroot/* 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-1999 */ #include #include "pcctscfg.h" #include "dlg.h" #ifdef MEMCHK #include "trax.h" #else #ifdef __STDC__ #include #else #include #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; itrans[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; jtrans[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; at, 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; inext; } 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); } } cccc-3.1.4/pccts/dlg/dlg.10000644000000000000000000000656407265350217013644 0ustar rootroot.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 cccc-3.1.4/pccts/dlg/dlg.h0000644000000000000000000002214407265350225013722 0ustar rootroot/* 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-1999 */ /* 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 cccc-3.1.4/pccts/dlg/dlg.r0000644000000000000000000001130607265350225013732 0ustar rootroot/* 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." } } } }; cccc-3.1.4/pccts/dlg/dlg1.txt0000644000000000000000000000737207265350230014375 0ustar rootroot 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 cccc-3.1.4/pccts/dlg/dlg68K.make0000644000000000000000000000424107265350230014673 0ustar rootroot# File: dlg68K.make # Target: dlg68K # 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 10:58:10 PM # Author: Kenji Tanaka MAKEFILE = dlg68K.make ¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified Includes = ¶ -i "::h:" ¶ -i "::support:set:" Sym¥68K = ObjDir¥68K = ":Obj:" COptions = {Includes} {Sym¥68K} -model far -mc68020 -w off -d MPW -d __STDC__=1 -d USER_ZZSYN Objects¥68K = ¶ "{ObjDir¥68K}automata.c.o" ¶ "{ObjDir¥68K}dlg_a.c.o" ¶ "{ObjDir¥68K}dlg_p.c.o" ¶ "{ObjDir¥68K}err.c.o" ¶ "{ObjDir¥68K}main.c.o" ¶ "{ObjDir¥68K}output.c.o" ¶ "{ObjDir¥68K}relabel.c.o" ¶ "{ObjDir¥68K}support.c.o" ¶ "{ObjDir¥68K}set.c.o" dlg68K ÄÄ {¥MondoBuild¥} {Objects¥68K} Link ¶ -o {Targ} -d {Sym¥68K} ¶ {Objects¥68K} ¶ -t 'MPST' ¶ -c 'MPS ' ¶ -model far ¶ -mf ¶ -br ON ¶ -srtsg ALL ¶ "{Libraries}Stubs.o" ¶ "{Libraries}MathLib.o" ¶ #"{CLibraries}Complex.o" ¶ "{CLibraries}StdCLib.o" ¶ "{Libraries}MacRuntime.o" ¶ "{Libraries}IntEnv.o" ¶ "{Libraries}ToolLibs.o" ¶ "{Libraries}Interface.o" "{ObjDir¥68K}automata.c.o" Ä {¥MondoBuild¥} automata.c {C} automata.c -o {Targ} {COptions} "{ObjDir¥68K}dlg_a.c.o" Ä {¥MondoBuild¥} dlg_a.c {C} dlg_a.c -o {Targ} {COptions} "{ObjDir¥68K}dlg_p.c.o" Ä {¥MondoBuild¥} dlg_p.c {C} dlg_p.c -o {Targ} {COptions} "{ObjDir¥68K}err.c.o" Ä {¥MondoBuild¥} err.c {C} err.c -o {Targ} {COptions} "{ObjDir¥68K}main.c.o" Ä {¥MondoBuild¥} main.c {C} main.c -o {Targ} {COptions} "{ObjDir¥68K}output.c.o" Ä {¥MondoBuild¥} output.c {C} output.c -o {Targ} {COptions} "{ObjDir¥68K}relabel.c.o" Ä {¥MondoBuild¥} relabel.c {C} relabel.c -o {Targ} {COptions} "{ObjDir¥68K}support.c.o" Ä {¥MondoBuild¥} support.c {C} support.c -o {Targ} {COptions} "{ObjDir¥68K}set.c.o" Ä {¥MondoBuild¥} "::support:set:set.c" {C} "::support:set:set.c" -o {Targ} {COptions} dlg68K ÄÄ dlg.r Rez dlg.r -o dlg68K -a Install Ä dlg68K Duplicate -y dlg68K "{MPW}"Tools:dlg cccc-3.1.4/pccts/dlg/dlgPPC.make0000644000000000000000000000421007265350236014747 0ustar rootroot# 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 ¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified Includes = ¶ -i "::h:" ¶ -i "::support:set:" Sym¥PPC = ObjDir¥PPC = ":Obj:" PPCCOptions = {Includes} {Sym¥PPC} -w off -d MPW -d __STDC__=1 -d USER_ZZSYN Objects¥PPC = ¶ "{ObjDir¥PPC}automata.c.x" ¶ "{ObjDir¥PPC}dlg_a.c.x" ¶ "{ObjDir¥PPC}dlg_p.c.x" ¶ "{ObjDir¥PPC}err.c.x" ¶ "{ObjDir¥PPC}main.c.x" ¶ "{ObjDir¥PPC}output.c.x" ¶ "{ObjDir¥PPC}relabel.c.x" ¶ "{ObjDir¥PPC}support.c.x" ¶ "{ObjDir¥PPC}set.c.x" dlgPPC ÄÄ {¥MondoBuild¥} {Objects¥PPC} PPCLink ¶ -o {Targ} {Sym¥PPC} ¶ {Objects¥PPC} ¶ -t 'MPST' ¶ -c 'MPS ' ¶ "{SharedLibraries}InterfaceLib" ¶ "{SharedLibraries}StdCLib" ¶ "{SharedLibraries}MathLib" ¶ "{PPCLibraries}StdCRuntime.o" ¶ "{PPCLibraries}PPCCRuntime.o" ¶ "{PPCLibraries}PPCToolLibs.o" "{ObjDir¥PPC}automata.c.x" Ä {¥MondoBuild¥} automata.c {PPCC} automata.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}dlg_a.c.x" Ä {¥MondoBuild¥} dlg_a.c {PPCC} dlg_a.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}dlg_p.c.x" Ä {¥MondoBuild¥} dlg_p.c {PPCC} dlg_p.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}err.c.x" Ä {¥MondoBuild¥} err.c {PPCC} err.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}main.c.x" Ä {¥MondoBuild¥} main.c {PPCC} main.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}output.c.x" Ä {¥MondoBuild¥} output.c {PPCC} output.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}relabel.c.x" Ä {¥MondoBuild¥} relabel.c {PPCC} relabel.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}support.c.x" Ä {¥MondoBuild¥} support.c {PPCC} support.c -o {Targ} {PPCCOptions} "{ObjDir¥PPC}set.c.x" Ä {¥MondoBuild¥} "::support:set:set.c" {PPCC} "::support:set:set.c" -o {Targ} {PPCCOptions} dlgPPC ÄÄ dlg.r Rez dlg.r -o dlgPPC -a Install Ä dlgPPC Duplicate -y dlgPPC "{MPW}"Tools:dlg cccc-3.1.4/pccts/dlg/dlg_a.c0000644000000000000000000007036107265350247014225 0ustar rootroot /* parser.dlg -- DLG Description of scanner * * Generated from: dlg_p.g * * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include #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(); } /* * D L G tables * * Generated from: parser.dlg * * 1989-1998 by Will Cohen, Terence Parr, and Hank Dietz * Purdue University Electrical Engineering * DLG Version 1.33MR20 */ #include "mode.h" 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 */ static void act1() { NLA = 1; } static void act2() { NLA = 2; zzskip(); } static void act3() { NLA = 3; zzline++; zzskip(); DAWDLE; } static void act4() { NLA = L_EOF; } static void act5() { NLA = PER_PER; } static void act6() { NLA = NAME_PER_PER; p_mode_def(&zzlextext[2],lex_mode_counter++); } static void act7() { NLA = LEXMEMBER; lexMember=1; /* MR1 */ if (firstLexMember != 0) { /* MR1 */ firstLexMember=0; /* MR1 */ p_class_def1(); /* MR1 */ }; /* MR1 */ zzmode(ACT); /* MR1 */ } static void act8() { NLA = LEXACTION; lexAction=1;zzmode(ACT); } static void act9() { NLA = PARSERCLASS; parserClass=1; /* MR1 */ zzmode(ACT); /* MR1 */ } static void act10() { NLA = LEXPREFIX; lexPrefix=1;zzmode(ACT); } static void act11() { 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(); } static void act12() { NLA = GREAT_GREAT; } static void act13() { NLA = L_BRACE; } static void act14() { NLA = R_BRACE; } static void act15() { NLA = L_PAR; } static void act16() { NLA = R_PAR; } static void act17() { NLA = L_BRACK; } static void act18() { NLA = R_BRACK; } static void act19() { NLA = ZERO_MORE; } static void act20() { NLA = ONE_MORE; } static void act21() { NLA = OR; } static void act22() { NLA = RANGE; } static void act23() { NLA = NOT; } static void act24() { NLA = OCTAL_VALUE; {int t; sscanf(&zzlextext[1],"%o",&t); zzlextext[0] = t;} } static void act25() { NLA = HEX_VALUE; {int t; sscanf(&zzlextext[3],"%x",&t); zzlextext[0] = t;} } static void act26() { NLA = DEC_VALUE; {int t; sscanf(&zzlextext[1],"%d",&t); zzlextext[0] = t;} } static void act27() { NLA = TAB; zzlextext[0] = '\t'; } static void act28() { NLA = NL; zzlextext[0] = '\n'; } static void act29() { NLA = CR; zzlextext[0] = '\r'; } static void act30() { NLA = BS; zzlextext[0] = '\b'; } static void act31() { NLA = CONTINUATION; zzline++; zzskip(); } static void act32() { NLA = LIT; zzlextext[0] = zzlextext[1]; } static void act33() { NLA = REGCHAR; } static unsigned char shift0[257] = { 0, 40, 40, 40, 40, 40, 40, 40, 40, 40, 1, 2, 40, 40, 1, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 1, 40, 40, 40, 40, 4, 40, 40, 30, 31, 34, 35, 40, 37, 40, 40, 23, 24, 24, 24, 24, 24, 24, 24, 25, 25, 40, 40, 26, 40, 27, 40, 3, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 20, 22, 22, 32, 39, 33, 40, 22, 40, 11, 9, 12, 21, 6, 19, 22, 22, 14, 22, 22, 5, 8, 16, 15, 17, 22, 10, 18, 13, 22, 22, 22, 7, 22, 22, 28, 36, 29, 38, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 }; static void act34() { NLA = 1; error("unterminated action", zzline); zzmode(START); } static void act35() { 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; } static void act36() { NLA = 34; xxputc(zzlextext[0]); zzskip(); } static void act37() { NLA = 35; xxputc('>'); zzskip(); } static void act38() { NLA = 36; xxputc('\\'); zzskip(); } static void act39() { NLA = 37; xxputc(zzlextext[0]); ++zzline; zzskip(); } static void act40() { NLA = 38; zzmode(ACTION_COMMENTS); /* MR1 */ xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */ } static void act41() { NLA = 39; zzmode(ACTION_CPP_COMMENTS); /* MR1 */ xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */ } static void act42() { NLA = 40; xxputc(zzlextext[0]); zzskip(); } static unsigned char shift1[257] = { 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }; static void act43() { NLA = 1; } static void act44() { NLA = 41; zzmode(ACT); /* MR1 */ xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */ } static void act45() { NLA = 42; zzline++; xxputc(zzlextext[0]); zzskip(); } static void act46() { NLA = 43; xxputc(zzlextext[0]); zzskip(); } static unsigned char shift2[257] = { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; static void act47() { NLA = 1; } static void act48() { NLA = 44; zzmode(ACT); zzline++; /* MR1 */ xxprintf("%s", &(zzlextext[0])); zzskip(); /* MR1 */ } static void act49() { NLA = 45; xxputc(zzlextext[0]); zzskip(); } static unsigned char shift3[257] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; #define DfaStates 94 typedef unsigned char DfaState; static DfaState st0[42] = { 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 6, 94 }; static DfaState st1[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st2[42] = { 94, 21, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st3[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st4[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st5[42] = { 94, 94, 94, 94, 22, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st6[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st7[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 23, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st8[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 24, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st9[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st10[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st11[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st12[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st13[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st14[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st15[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st16[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st17[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st18[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st19[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st20[42] = { 94, 25, 26, 25, 25, 25, 25, 25, 25, 27, 28, 25, 25, 29, 25, 25, 30, 25, 25, 25, 25, 25, 25, 31, 32, 32, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 94 }; static DfaState st21[42] = { 94, 21, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st22[42] = { 94, 94, 94, 94, 94, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st23[42] = { 94, 94, 94, 94, 34, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st24[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st25[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st26[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st27[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st28[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st29[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st30[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st31[42] = { 94, 94, 94, 94, 94, 94, 94, 35, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 35, 94, 94, 36, 36, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st32[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 37, 37, 37, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st33[42] = { 94, 94, 94, 94, 94, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st34[42] = { 94, 94, 94, 94, 39, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st35[42] = { 94, 94, 94, 94, 94, 94, 40, 94, 94, 40, 94, 40, 40, 94, 94, 94, 94, 94, 94, 40, 94, 40, 94, 40, 40, 40, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st36[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 36, 36, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st37[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 37, 37, 37, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st38[42] = { 94, 94, 94, 94, 94, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st39[42] = { 94, 94, 94, 94, 94, 41, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 42, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st40[42] = { 94, 94, 94, 94, 94, 94, 40, 94, 94, 40, 94, 40, 40, 94, 94, 94, 94, 94, 94, 40, 94, 40, 94, 40, 40, 40, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st41[42] = { 94, 94, 94, 94, 94, 94, 43, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st42[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 44, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st43[42] = { 94, 94, 94, 94, 94, 94, 94, 45, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st44[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 46, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st45[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 47, 94, 94, 48, 94, 94, 94, 94, 94, 49, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st46[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 50, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st47[42] = { 94, 94, 94, 94, 94, 94, 51, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st48[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 52, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st49[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 53, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st50[42] = { 94, 94, 94, 94, 94, 94, 54, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st51[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 55, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st52[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 56, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st53[42] = { 94, 94, 94, 94, 94, 94, 57, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st54[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 58, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st55[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 59, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st56[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 60, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st57[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 61, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st58[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 62, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st59[42] = { 94, 94, 94, 94, 94, 94, 63, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st60[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 64, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st61[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 65, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st62[42] = { 94, 94, 94, 94, 94, 66, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st63[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 67, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st64[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 68, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st65[42] = { 94, 94, 94, 94, 94, 94, 94, 69, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st66[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 70, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st67[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st68[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st69[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st70[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 71, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st71[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 72, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st72[42] = { 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st73[8] = { 74, 75, 76, 77, 78, 79, 79, 94 }; static DfaState st74[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st75[8] = { 94, 80, 94, 94, 94, 94, 94, 94 }; static DfaState st76[8] = { 94, 81, 94, 94, 94, 94, 94, 94 }; static DfaState st77[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st78[8] = { 94, 94, 94, 94, 82, 83, 94, 94 }; static DfaState st79[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st80[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st81[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st82[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st83[8] = { 94, 94, 94, 94, 94, 94, 94, 94 }; static DfaState st84[6] = { 85, 86, 87, 88, 87, 94 }; static DfaState st85[6] = { 94, 94, 94, 94, 94, 94 }; static DfaState st86[6] = { 94, 94, 89, 94, 94, 94 }; static DfaState st87[6] = { 94, 94, 94, 94, 94, 94 }; static DfaState st88[6] = { 94, 94, 94, 94, 94, 94 }; static DfaState st89[6] = { 94, 94, 94, 94, 94, 94 }; static DfaState st90[4] = { 91, 92, 93, 94 }; static DfaState st91[4] = { 94, 94, 94, 94 }; static DfaState st92[4] = { 94, 94, 94, 94 }; static DfaState st93[4] = { 94, 94, 94, 94 }; DfaState *dfa[94] = { st0, st1, st2, st3, st4, st5, st6, st7, st8, st9, st10, st11, st12, st13, st14, st15, st16, st17, st18, st19, st20, st21, st22, st23, st24, st25, st26, st27, st28, st29, st30, st31, st32, st33, st34, st35, st36, st37, st38, st39, st40, st41, st42, st43, st44, st45, st46, st47, st48, st49, st50, st51, st52, st53, st54, st55, st56, st57, st58, st59, st60, st61, st62, st63, st64, st65, st66, st67, st68, st69, st70, st71, st72, st73, st74, st75, st76, st77, st78, st79, st80, st81, st82, st83, st84, st85, st86, st87, st88, st89, st90, st91, st92, st93 }; DfaState accepts[95] = { 0, 1, 2, 3, 4, 33, 33, 33, 33, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 2, 5, 11, 12, 32, 31, 30, 29, 27, 28, 24, 26, 6, 0, 0, 24, 26, 6, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 10, 0, 0, 9, 0, 34, 36, 38, 39, 42, 42, 35, 37, 41, 40, 0, 43, 46, 46, 45, 44, 0, 47, 48, 49, 0 }; void (*actions[50])() = { zzerraction, act1, act2, act3, act4, act5, act6, act7, act8, act9, act10, act11, act12, act13, act14, act15, act16, act17, act18, act19, act20, act21, act22, act23, act24, act25, act26, act27, act28, act29, act30, act31, act32, act33, act34, act35, act36, act37, act38, act39, act40, act41, act42, act43, act44, act45, act46, act47, act48, act49 }; static DfaState dfa_base[] = { 0, 73, 84, 90 }; static unsigned char *b_class_no[] = { shift0, shift1, shift2, shift3 }; #define ZZSHIFT(c) (b_class_no[zzauto][1+c]) #define MAX_MODE 4 #include "dlgauto.h" cccc-3.1.4/pccts/dlg/dlg_p.c0000644000000000000000000004377607265350260014251 0ustar rootroot/* * 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-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 * * ..\bin\antlr dlg_p.g -gh * */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include #include "dlg.h" #define zzSET_SIZE 8 #include "antlr.h" #include "tokens.h" #include "dlgdef.h" #include "mode.h" #ifndef PURIFY #define 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; } } } } 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,zzerr1,&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,zzerr2,&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); 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,zzerr3,&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; (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(); (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; (zzaRet.r)->trans[0] = zzaRet.l; t1 = new_nfa_node(); t2 = new_nfa_node(); t1->trans[0]=zzaRet.l; t1->trans[1]=t2; (zzaRet.r)->trans[1]=t2; zzaRet.l=t1;zzaRet.r=t2; } zzCONSUME; } else { if ( (LA(1)==ONE_MORE) ) { zzmatch(ONE_MORE); (zzaRet.r)->trans[0] = zzaRet.l; zzCONSUME; } } 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,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd2, 0x40); } } 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); (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); (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); (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); (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 ( (setwd2[LA(1)]&0x80) ) { atom(); (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,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;} } } } } zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x1); } } 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)]&0x2) ) { 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, 0x4); } } 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 */ 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)); } } zzEXIT(zztasp2); } } zzEXIT(zztasp1); return; fail: zzEXIT(zztasp1); zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText); zzresynch(setwd3, 0x8); } } 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, 0x10); } } 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,zzerr6,&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, 0x20); } } /* 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"); } cccc-3.1.4/pccts/dlg/dlg_p.g0000644000000000000000000004053407265350274014247 0ustar rootroot/* 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 #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 */ <> /* MR1 */ #token LEXACTION "\<\<\%\%lexaction" /* MR1 */ <> /* MR1 */ #token PARSERCLASS "\<\<\%\%parserclass" /* MR1 */ <> /* MR1 */ #token LEXPREFIX "\<\<\%\%lexprefix" /* MR1 */ <> /* 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 */ <> 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 : <> 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 <<$$.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; ($$.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 <<($$.r)->trans[1]=$1.l; $$.r=$1.r;>>)* ; repeat_expr : expr <<$$.l=$1.l; $$.r=$1.r;>> { ZERO_MORE <<{ nfa_node *t1,*t2; ($$.r)->trans[0] = $$.l; t1 = new_nfa_node(); t2 = new_nfa_node(); t1->trans[0]=$$.l; t1->trans[1]=t2; ($$.r)->trans[1]=t2; $$.l=t1;$$.r=t2; } >> | ONE_MORE <<($$.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 << ($$.l)->trans[0] = $$.r; ($$.l)->label = set_dup($2.label); set_orin(&used_chars,($$.l)->label); >> | NOT L_BRACK atom_list R_BRACK << ($$.l)->trans[0] = $$.r; ($$.l)->label = set_dif(normal_chars,$3.label); set_orin(&used_chars,($$.l)->label); >> | L_PAR reg_expr R_PAR << ($$.l)->trans[0] = $2.l; if ($2.r) { ($2.r)->trans[1] = $$.r; /* MR20 */ } >> | L_BRACE reg_expr R_BRACE << ($$.l)->trans[0] = $2.l; ($$.l)->trans[1] = $$.r; if ($2.r) { ($2.r)->trans[1] = $$.r; /* MR20 */ } >> | atom << ($$.l)->trans[0] = $$.r; ($$.l)->label = set_dup($1.label); set_orin(&used_chars,($$.l)->label); >> ; atom_list : << set_free($$.label); >> (near_atom <>)* ; 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 */ 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;>> ; <> #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"); } >> cccc-3.1.4/pccts/dlg/err.c0000644000000000000000000000501607265350274013742 0ustar rootroot/* * 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-1999 * Parr Research Corporation * with Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include #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] = {0x60,0x0,0x0,0x0, 0x0,0x0,0x0,0x0}; SetWordType zzerr2[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 zzerr3[8] = {0x10,0xa8,0x9a,0x7f, 0x3,0x0,0x0,0x0}; SetWordType zzerr4[8] = {0x10,0xa0,0x9a,0x7f, 0x3,0x0,0x0,0x0}; SetWordType zzerr5[8] = {0x10,0xa0,0x82,0x7f, 0x3,0x0,0x0,0x0}; SetWordType setwd2[46] = {0x0,0x0,0x0,0x0,0xeb,0x2,0x2, 0x0,0x0,0x0,0x0,0x56,0x0,0x6b,0x54, 0x6b,0x54,0x6b,0x0,0x4b,0x4b,0x50,0x0, 0x6b,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb,0xeb, 0x0,0xeb,0xeb,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0}; SetWordType zzerr6[8] = {0x10,0x0,0x0,0x7f, 0x3,0x0,0x0,0x0}; SetWordType setwd3[46] = {0x0,0x0,0x0,0x0,0x3b,0x0,0x0, 0x0,0x0,0x0,0x0,0x31,0x0,0x31,0x31, 0x31,0x31,0x31,0x2c,0x31,0x31,0x31,0x20, 0x31,0x3b,0x3b,0x3b,0x3b,0x3b,0x3b,0x3b, 0x0,0x3b,0x3b,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0}; cccc-3.1.4/pccts/dlg/main.c0000644000000000000000000001672707265350274014111 0ustar rootroot/* 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-1999 */ #include #include "stdpccts.h" char program[] = "dlg"; char version[] = "1.33MR20"; /* 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-1999\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"); 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"); } 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 #include #include "dlg.h" #ifdef MEMCHK #include "trax.h" #else #ifdef __STDC__ #include #else #include #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-1999 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> */ /* 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-1999 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_C); 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 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]; itrans[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=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+1] = {\n", ClassName("::"), dfa_allocated); 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; itrans[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 cccc-3.1.4/pccts/dlg/parser.dlg0000644000000000000000000001323607265350311014765 0ustar rootroot<< /* parser.dlg -- DLG Description of scanner * * Generated from: dlg_p.g * * Terence Parr, Will Cohen, and Hank Dietz: 1989-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #define ANTLR_VERSION 13320 #include "pcctscfg.h" #include "pccts_stdio.h" #include #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(); >> %% cccc-3.1.4/pccts/dlg/relabel.c0000644000000000000000000001312507265350314014553 0ustar rootroot/* 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-1999 */ #include #include "dlg.h" #ifdef MEMCHK #include "trax.h" #else #ifdef __STDC__ #include #else #include #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,¤t_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; ilabel)) 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]); } } cccc-3.1.4/pccts/dlg/stdpccts.h0000644000000000000000000000076707265350314015011 0ustar rootroot#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-1999 * Purdue University Electrical Engineering * With AHPCRC, University of Minnesota * ANTLR Version 1.33MR20 */ #ifndef ANTLR_VERSION #define ANTLR_VERSION 13320 #endif #include "pcctscfg.h" #include "pccts_stdio.h" #include #include "dlg.h" #define zzSET_SIZE 8 #include "antlr.h" #include "tokens.h" #include "dlgdef.h" #include "mode.h" #endif cccc-3.1.4/pccts/dlg/support.c0000644000000000000000000001176607265350314014672 0ustar rootroot/* * 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-1999 */ #include #include #include "dlg.h" #ifdef MEMCHK #include "trax.h" #else #ifdef __STDC__ #include #else #include #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; } cccc-3.1.4/pccts/dlg/tokens.h0000644000000000000000000000411307265350317014455 0ustar rootroot#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-1999 * Purdue University Electrical Engineering * ANTLR Version 1.33MR20 */ #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 setwd1[]; extern SetWordType zzerr3[]; extern SetWordType zzerr4[]; extern SetWordType zzerr5[]; extern SetWordType setwd2[]; extern SetWordType zzerr6[]; extern SetWordType setwd3[]; cccc-3.1.4/pccts/dlg/watdlg.mak0000644000000000000000000000164207265350317014761 0ustar rootrootSET=..\support\set PCCTS_H=..\h # # Watcom # CC=wcl386 ANTLR=..\bin\antlr DLG=..\bin\dlg CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DPC LIBS= OBJ_EXT = obj LINK = wcl386 .c.obj : $(CC) -c $[* $(CFLAGS) dlg.exe : dlg_p.obj dlg_a.obj main.obj err.obj set.obj support.obj & output.obj relabel.obj automata.obj $(LINK) -fe=dlg.exe *.obj -k14336 copy *.exe ..\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 #clean up all the intermediate files clean: del *.$(OBJ_EXT) cccc-3.1.4/pccts/h/0000755000000000000000000000000010357462410012455 5ustar rootrootcccc-3.1.4/pccts/h/AParser.cpp0000644000000000000000000005167607265350346014545 0ustar rootroot/* 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-1998 */ #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; } int ANTLRParser:: guess(ANTLRParserState *st) { saveState(st); guessing = 1; return setjmp(guess_start.state); } 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 (traceOptionValue > 0) { fprintf(stderr,"trace enable restored in rule %s depth %d\n",traceCurrentRuleName,traceDepth); }; if (traceOptionValue <= 0) { fprintf(stderr,"trace disable restored in rule %s depth %d\n",traceCurrentRuleName,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) { if ( dirty==LLk ) { consume(); } if ( !set_el(LA(1), tset) ) { *MissText=NULL; *MissTok= (ANTLRTokenType)0; *BadTok=LT(1); *MissSet=tset; 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. */ void ANTLRParser:: syn(_ANTLRTokenPtr tok, ANTLRChar *egroup, SetWordType *eset, ANTLRTokenType etok, int k) { int line; line = LT(1)->getLine(); syntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\"", line, LT(1)->getText()); if ( !etok && !eset ) {fprintf(stderr, "\n"); return;} if ( k==1 ) fprintf(stderr, " missing"); else { fprintf(stderr, "; \"%s\" not", LT(1)->getText()); if ( set_deg(eset)>1 ) fprintf(stderr, " in"); } if ( set_deg(eset)>0 ) edecode(eset); else fprintf(stderr, " %s", token_tbl[etok]); if ( strlen(egroup) > 0 ) fprintf(stderr, " in %s", egroup); fprintf(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 ) fprintf(stderr, " {"); do { register SetWordType t = *p; register SetWordType *b = &(bitmask[0]); do { if ( t & *b ) fprintf(stderr, " %s", token_tbl[e]); e++; } while (++b < &(bitmask[sizeof(SetWordType)*8])); } while (++p < endp); if ( set_deg(a)>1 ) fprintf(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 } /* fprintf(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 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", LT(1)->getLine(), (LA(1)==eofToken)?"":LT(1)->getText(), 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 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", LT(1)->getLine(), (LA(1)==eofToken)?"":LT(1)->getText(), 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 { fprintf(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) { fprintf(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) { fprintf(stderr," (guess mode continues - an enclosing guess is still active)"); } else { fprintf(stderr," (guess mode ends)"); }; fprintf(stderr,"\n"); }; } void ANTLRParser::traceGuessFail() { int doIt=0; if (traceOptionValue <= 0) { doIt=0; } else if (guessing && traceGuessOptionValue <= 0) { doIt=0; } else { doIt=1; }; if (doIt) { fprintf(stderr,"guess failed\n"); }; } /* 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) { fprintf(stderr,"enter rule %s {\"%s\"} depth %d", rule, LT(1)->getType() == eofToken ? "@" : LT(1)->getText(), traceDepth); if (guessing) fprintf(stderr," guessing"); fprintf(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) { fprintf(stderr,"exit rule %s {\"%s\"} depth %d", rule, LT(1)->getType() == eofToken ? "@" : LT(1)->getText(), traceDepth+1); if (guessing) fprintf(stderr," guessing"); fprintf(stderr,"\n"); }; } int ANTLRParser::traceOption(int delta) { int prevValue=traceOptionValue; traceOptionValue=traceOptionValue+delta; if (traceCurrentRuleName != NULL) { if (prevValue <= 0 && traceOptionValue > 0) { fprintf(stderr,"trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth); }; if (prevValue > 0 && traceOptionValue <= 0) { fprintf(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) { fprintf(stderr,"guess trace enabled in rule %s depth %d\n",traceCurrentRuleName,traceDepth); }; if (prevValue > 0 && traceGuessOptionValue <= 0) { fprintf(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 } cccc-3.1.4/pccts/h/AParser.h0000644000000000000000000003057407265350354014203 0ustar rootroot/* 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-1998 */ #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(); #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 #ifndef zzTRACE_RULES #define zzTRACEdata #else #ifndef zzTRACEdata #define zzTRACEdata const ANTLRChar *zzTracePrevRuleName; #endif #endif #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 **); int _match_wsig(ANTLRTokenType); int _setmatch_wsig(SetWordType *); virtual void consume(); void resynch(SetWordType *wd,SetWordType mask); 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 *); 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 }; #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) \ if ( !_setmatch(_ts, &zzMissText, &zzMissTok, \ (_ANTLRTokenPtr *) &zzBadTok, &zzMissSet) ) 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 // MR1 in guess mode. // MR1 Identification and correction due to J. Lilley #ifndef zzfailed_pred #define zzfailed_pred(_p) \ if (guessing) { \ zzGUESS_FAIL; \ } else { \ fprintf(stdout,"line %d: semantic error; failed predicate: '%s'\n", \ LT(1)->getLine(), _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 cccc-3.1.4/pccts/h/ASTBase.cpp0000644000000000000000000001365207265350362014420 0ustar rootroot/* 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-1998 */ #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() { ASTBase *tree = this; while ( tree!= NULL ) { if ( tree->_down != NULL ) { tree->preorder_before_action(); // MR1 }; tree->preorder_action(); if ( tree->_down!=NULL ) { tree->_down->preorder(); tree->preorder_after_action(); // 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, *w; va_start(ap, root); if ( root != NULL ) if ( root->_down != NULL ) 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); } cccc-3.1.4/pccts/h/ASTBase.h0000644000000000000000000000700507265350362014060 0ustar rootroot/* 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-1998 */ #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(); static ASTBase *tmake(ASTBase *, ...); static void link(ASTBase **, ASTBase **, ASTBase **); void subchild(ASTBase **, ASTBase **, ASTBase **); void subroot(ASTBase **, ASTBase **, ASTBase **); virtual void preorder_action() { ; } virtual void preorder_before_action() { printf(" ("); } virtual void preorder_after_action() { printf(" )"); } }; 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 cccc-3.1.4/pccts/h/ATokPtr.cpp0000644000000000000000000000412107265350401014503 0ustar rootroot/* ATokPtr.C * * 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-1998 */ #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; } cccc-3.1.4/pccts/h/ATokPtr.h0000644000000000000000000000576007265350401014162 0ustar rootroot/* 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-1998 */ #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 cccc-3.1.4/pccts/h/AToken.h0000644000000000000000000002204207265350370014014 0ustar rootroot/* 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-1998 */ #ifndef ATOKEN_H_GATE #define ATOKEN_H_GATE #include "pcctscfg.h" #include "pccts_string.h" #include "pccts_stdio.h" #include "pccts_stdlib.h" 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 { fprintf(stderr, "ANTLRAbstractToken panic: %s\n", msg); exit(PCCTS_EXIT_FAILURE); } }; /* 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: ANTLRRefCountToken(ANTLRTokenType t, const ANTLRChar *s) #ifndef DBG_REFCOUNTTOKEN { refcnt_ = 0; } #else { ctor++; refcnt_ = 0; if ( t==1 ) sprintf(object,"tok_EOF"); else sprintf(object,"tok_%s",s); fprintf(stderr, "ctor %s #%d\n",object,ctor); } #endif ANTLRRefCountToken() #ifndef DBG_REFCOUNTTOKEN { refcnt_ = 0; } #else { ctor++; refcnt_ = 0; sprintf(object,"tok_blank"); fprintf(stderr, "ctor %s #%d\n",object,ctor); } virtual ~ANTLRRefCountToken() { dtor++; if ( dtor>ctor ) fprintf(stderr, "WARNING: dtor>ctor\n"); fprintf(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, ANTLRChar *txt, int line) { 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 cccc-3.1.4/pccts/h/ATokenBuffer.cpp0000644000000000000000000002216607265350373015513 0ustar rootroot/* ANTLRTokenBuffer.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-1998 */ typedef int ANTLRTokenType; // fool AToken.h into compiling class ANTLRParser; /* MR1 */ #define ANTLR_SUPPORT_CODE #include "pcctscfg.h" #include ATOKENBUFFER_H typedef ANTLRAbstractToken *_ANTLRTokenPtr; #if defined(DBG_TBUF)||defined(DBG_TBUF_MARK_REW) static unsigned char test[1000]; #endif #ifdef DBG_REFCOUNTTOKEN int ANTLRCommonToken::ctor = 0; int ANTLRCommonToken::dtor = 0; #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*(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 fprintf(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 fprintf(stderr,"getToken: next > threshold (high water is %d)\n", threshold-buffer); #endif makeRoom(); } } else { if ( next > end_of_buffer ) { #ifdef DBG_TBUF fprintf(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) fprintf(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]++; fprintf(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 fprintf(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 fprintf(stderr, "in makeRoom.................\n"); fprintf(stderr, "num_markers==%d\n", num_markers); #endif /* if ( num_markers == 0 ) { */ #ifdef DBG_TBUF fprintf(stderr, "moving lookahead and resetting next\n"); _ANTLRTokenPtr *r; fprintf(stderr, "tbuf = ["); for (r=buffer; r<=last; r++) { if ( *r==NULL ) fprintf(stderr, " xxx"); else fprintf(stderr, " '%s'", ((ANTLRCommonToken *)*r)->getText()); } fprintf(stderr, " ]\n"); fprintf(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 fprintf(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 fprintf(stderr, "lookahead buffer = ["); #endif for (int i=1; i<=(k-1); i++) { *p++ = *q++; #ifdef DBG_TBUF fprintf(stderr, " '%s'", ((ANTLRCommonToken *)buffer[i-1])->getText()); #endif } #ifdef DBG_TBUF fprintf(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 fprintf(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 fprintf(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 /* to avoid having to link in another file just for the smart token ptr * stuff, we include it here. Ugh. */ #include ATOKPTR_C cccc-3.1.4/pccts/h/ATokenBuffer.h0000644000000000000000000000755707265350373015167 0ustar rootroot/* 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-1998 */ #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) { exit(PCCTS_EXIT_FAILURE); } /* MR20 const */ protected: // MR1 ANTLRParser *parser; // MR1 public: // MR1 ANTLRParser *setParser(ANTLRParser *p); // MR1 ANTLRParser *getParser(); // MR1 ANTLRTokenStream *getLexer() const { // MR12 return input;} // MR12 }; #endif cccc-3.1.4/pccts/h/ATokenStream.h0000644000000000000000000000367007265350373015201 0ustar rootroot/* 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-1998 */ #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) {return 0; }; // MR12 virtual ANTLRParser * getParser() { return 0; }; // MR12 }; #endif cccc-3.1.4/pccts/h/AToken_traditional.h0000644000000000000000000001420707265350376016420 0ustar rootroot/* 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-1998 */ #ifndef ATOKEN_H_GATE #define ATOKEN_H_GATE #include "pcctscfg.h" #include "pccts_string.h" #include "pccts_stdio.h" #include "pccts_stdlib.h" PCCTS_NAMESPACE_STD #ifndef ANTLRCommonTokenTEXTSIZE #define ANTLRCommonTokenTEXTSIZE 100 #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 "pcctscfg.h" //#include ATOKPTR_H not tested yet, leave out class ANTLRAbstractToken; typedef ANTLRAbstractToken *_ANTLRTokenPtr; class DllExportPCCTS ANTLRAbstractToken { public: virtual ~ANTLRAbstractToken() {;} virtual ANTLRTokenType getType() = 0; virtual void setType(ANTLRTokenType t) = 0; virtual int getLine() = 0; virtual void setLine(int line) = 0; virtual ANTLRChar *getText() = 0; virtual void setText(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() { return 1; } virtual void ref() {;} virtual void deref() {;} virtual void panic(char *msg) { fprintf(stderr, "ANTLRAbstractToken panic: %s\n", msg); exit(PCCTS_EXIT_FAILURE); } }; /* This class should be subclassed. It cannot store token type or text */ class DllExportPCCTS 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: ANTLRRefCountToken(ANTLRTokenType t, ANTLRChar *s) #ifndef DBG_REFCOUNTTOKEN { refcnt_ = 0; } #else { ctor++; refcnt_ = 0; if ( t==1 ) sprintf(object,"tok_EOF"); else sprintf(object,"tok_%s",s); fprintf(stderr, "ctor %s #%d\n",object,ctor); } #endif ANTLRRefCountToken() #ifndef DBG_REFCOUNTTOKEN { refcnt_ = 0; } #else { ctor++; refcnt_ = 0; sprintf(object,"tok_blank"); fprintf(stderr, "ctor %s #%d\n",object,ctor); } virtual ~ANTLRRefCountToken() { dtor++; if ( dtor>ctor ) fprintf(stderr, "WARNING: dtor>ctor\n"); fprintf(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() { return refcnt_; } virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt, ANTLRChar *txt, int line) { panic("call to ANTLRRefCountToken::makeToken()\n"); return NULL; } }; class DllExportPCCTS ANTLRCommonNoRefCountToken : public ANTLRAbstractToken { protected: ANTLRTokenType _type; int _line; ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1]; public: ANTLRCommonNoRefCountToken(ANTLRTokenType t, ANTLRChar *s) { setType(t); _line = 0; setText(s); } ANTLRCommonNoRefCountToken() { setType((ANTLRTokenType)0); _line = 0; setText(""); } ANTLRTokenType getType() { return _type; } void setType(ANTLRTokenType t) { _type = t; } virtual int getLine() { return _line; } void setLine(int line) { _line = line; } ANTLRChar *getText() { return _text; } void setText(ANTLRChar *s) { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); } virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt, ANTLRChar *txt, int line) { ANTLRAbstractToken *t = new ANTLRCommonNoRefCountToken; t->setType(tt); t->setText(txt); t->setLine(line); return t; } }; class DllExportPCCTS ANTLRCommonToken : public ANTLRRefCountToken { protected: ANTLRTokenType _type; int _line; ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1]; public: ANTLRCommonToken(ANTLRTokenType t, ANTLRChar *s) : ANTLRRefCountToken(t,s) { setType(t); _line = 0; setText(s); } ANTLRCommonToken() { setType((ANTLRTokenType)0); _line = 0; setText(""); } virtual ~ANTLRCommonToken() {;} ANTLRTokenType getType() { return _type; } void setType(ANTLRTokenType t) { _type = t; } virtual int getLine() { return _line; } void setLine(int line) { _line = line; } ANTLRChar *getText() { return _text; } void setText(ANTLRChar *s) { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); } virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt, ANTLRChar *txt, int line) { ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt); t->setLine(line); return t; } }; // used for backward compatibility typedef ANTLRCommonToken ANTLRCommonBacktrackingToken; #endif cccc-3.1.4/pccts/h/BufFileInput.cpp0000644000000000000000000000373207265350401015522 0ustar rootroot// 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 cccc-3.1.4/pccts/h/BufFileInput.h0000644000000000000000000000237307265350401015167 0ustar rootroot// 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 cccc-3.1.4/pccts/h/DLG_stream_input.h0000644000000000000000000000354307265350420016034 0ustar rootroot /************************************************************/ /* */ /* 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 > class DLG_stream_input : public DLGInputStream { public: DLG_stream_input(::std::basic_istream * 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 * input; private: void purge() { // nothing to do! }; }; #endif /* _DLG_STREAM_INPUT_H */ cccc-3.1.4/pccts/h/DLexer.cpp0000644000000000000000000001115707265350407014357 0ustar rootroot/* DLexer.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-1998 */ #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*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 */ printf("\ntoken name=%s",parser->parserTokenName(tk)); /* MR1 */ } else { /* MR1 */ printf("\ntoken nnumber=%d",tk); /* MR1 */ }; /* MR1 */ printf(" lextext=(%s) mode=%d", /* MR1 */ (_lextext[0]=='\n' && _lextext[1]==0) ? /* MR1 */ "newline" : _lextext, /* MR1 */ automaton); /* MR1 */ if (interactive && !charfull) { /* MR1 */ printf(" char=empty"); /* MR1 */ } else { /* MR1 */ if (ch=='\n') { /* MR1 */ printf(" char=newline"); /* MR1 */ } else { /* MR1 */ printf(" char=(%c)",ch); /* MR1 */ }; /* MR1 */ }; /* MR1 */ printf(" %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; } cccc-3.1.4/pccts/h/DLexerBase.cpp0000644000000000000000000001475707265350407015163 0ustar rootroot/* 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-1998 */ #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 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; nextpos = _begexpr + 1; } /* replace the string s for the reg. expr last matched and in the buffer */ 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; } void DLGLexerBase:: errstd(const char *s) /* MR20 const */ { lexErrCount++; /* MR11 */ fprintf(stderr, "%s near line %d (text was '%s')\n", ((s == NULL) ? "Lexical error" : s), _line,_lextext); } int DLGLexerBase:: err_in() { fprintf(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 */ { fprintf(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 cccc-3.1.4/pccts/h/DLexerBase.h0000644000000000000000000001362507265350412014615 0ustar rootroot/* 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-1998 */ #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 }; #endif cccc-3.1.4/pccts/h/PBlackBox.h0000644000000000000000000000501207265350435014440 0ustar rootroot#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-1998 */ #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 DllExportPCCTS ParserBlackBox { protected: DLGFileInput *in; Lexer *scan; _ANTLRTokenPtr tok; ANTLRTokenBuffer *pipe; Parser *_parser; FILE *file; public: ParserBlackBox(FILE *f) { 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) { FILE *f = fopen(fname, "r"); if ( f==NULL ) {cerr << "cannot open " << fname << "\n"; return;} else { 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; fclose(file); } Parser *parser() { return _parser; } Lexer *getLexer() { return scan; } }; #endif cccc-3.1.4/pccts/h/PCCTSAST.cpp0000644000000000000000000003735307265350445014430 0ustar rootroot/* * 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-1998 */ #define ANTLR_SUPPORT_CODE #include "pcctscfg.h" #include "PCCTSAST.h" #include "pccts_stdarg.h" PCCTS_NAMESPACE_STD #include //#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 ) fprintf(f," ("); lisp_action(f); if ( down()!=NULL ) down()->lisp(f); if ( down() != NULL ) fprintf(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, *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]; static int tsp = MaxTreeStackDepth; static int nesting = 0; 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 ) if ( u!=NULL ) return 0; else return 1; 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; } /* 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; } 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 ) { // MR1 fprintf(stderr, "out of mem\n"); // MR1 exit(PCCTS_EXIT_FAILURE); // MR1 }; // MR1 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; 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) { static 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]; static char ebuf[100]; while ( isspace(scanner->c) ) { stringscan_advance(scanner); } if ( isdigit(scanner->c) ) { int tok = __INT; while ( isdigit(scanner->c) ) { *index++ = scanner->c; 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 ""; else return ""; } cccc-3.1.4/pccts/h/PCCTSAST.h0000644000000000000000000001075207265350445014067 0ustar rootroot/* 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-1998 */ #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) {;} 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) {;} 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 { fprintf(stderr, "PCCTS_AST: %s\n", err); exit(PCCTS_EXIT_FAILURE); } }; #endif /* PCCTSAST_H */ cccc-3.1.4/pccts/h/SList.h0000644000000000000000000000414207265350456013677 0ustar rootroot#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-1998 */ #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){ fprintf(stderr, "SList panic: %s\n", err); exit(PCCTS_EXIT_FAILURE); } }; #endif cccc-3.1.4/pccts/h/antlr.h0000644000000000000000000005656307265350340013767 0ustar rootroot/* 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-1998 */ #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 #else #include #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 2000 #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) \ if (zzguessing) { \ zzGUESS_FAIL; \ } else { \ fprintf(stderr, "semantic error; failed predicate: '%s'\n",_p); \ } #else #define zzfailed_pred(_p) \ fprintf(stderr, "semantic error; failed predicate: '%s'\n",_p) #endif #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) \ if ( !_zzsetmatch(_es, &zzBadText, &zzMissText, &zzMissTok, &zzBadTok, &zzMissSet) ) goto fail; #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 **); 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; #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 /* 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 zzFAIL(int k, ...); 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 zzFAIL(); 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 cccc-3.1.4/pccts/h/ast.c0000644000000000000000000001702707265350357013431 0ustar rootroot/* 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-1998 */ #include "pcctscfg.h" #ifdef PCCTS_USE_STDARG #include "pccts_stdarg.h" #else #include #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 */ 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 ); } zzfree_ast( tree->down ); zzfree_ast( tree->right ); zztfree( tree ); } /* 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 cccc-3.1.4/pccts/h/ast.h0000644000000000000000000000667607265350357013446 0ustar rootroot/* 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-1998 */ #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[]; #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 *zztmake(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 *zztmake(); AST *zzdup_ast(); void zztfree(); void zzdouble_link(); #endif #endif cccc-3.1.4/pccts/h/charbuf.h0000644000000000000000000000304707265350401014244 0ustar rootroot/* 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-1998 */ #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 cccc-3.1.4/pccts/h/charptr.c0000644000000000000000000000337407265350404014276 0ustar rootroot/* * 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-1998 */ #include "pcctscfg.h" #ifdef __STDC__ #include "pccts_stdlib.h" #else #include #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); } cccc-3.1.4/pccts/h/charptr.h0000644000000000000000000000330107265350404014271 0ustar rootroot/* * * 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-1998 */ /* * 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 cccc-3.1.4/pccts/h/config.h0000644000000000000000000000002607265350404014074 0ustar rootroot#include "pcctscfg.h" cccc-3.1.4/pccts/h/dlgauto.h0000644000000000000000000002502007265350415014271 0ustar rootroot/* 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-1998 */ #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 #include /* */ /* 7-Apr-97 133MR1 */ /* Proper choice of STDC and cplusplus pre-processor symbols (?) */ /* */ #include "pccts_string.h" #ifdef PCCTS_USE_STDARG #include "pccts_stdarg.h" #else #include #endif #ifdef DUM /* Define usable bits per unsigned int word (used for set stuff) */ #ifdef PC #define BSETWORDSIZE 16 #define BSETLOGWORDSIZE 4 #else #define BSETWORDSIZE 32 #define BSETLOGWORDSIZE 5 #endif #endif #define BSETWORDSIZE 8 #define BSETLOGWORDSIZE 3 /* SetWordType is 8bits */ #define BSETMODWORD(x) ((x) & (BSETWORDSIZE-1)) /* x % BSETWORDSIZE */ #define BSETDIVWORD(x) ((x) >> BSETLOGWORDSIZE) /* x / BSETWORDSIZE */ /* This is not put into the global pccts_parser structure because it is * hidden and does not need to be saved during a "save state" operation */ /* maximum of 32 bits/unsigned int and must be 8 bits/byte */ static SetWordType bitmask[] = { 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080 }; #ifdef zzTRACE_RULES int zzTraceOptionValueDefault=1; int zzTraceOptionValue=1; int zzTraceGuessOptionValue=1; char *zzTraceCurrentRuleName=NULL; int zzTraceDepth=0; #endif int zzGuessSeq=0; /* MR10 */ int zzSyntaxErrCount=0; /* MR11 */ int zzLexErrCount=0; /* MR11 */ void #ifdef __USE_PROTOS zzresynch(SetWordType *wd,SetWordType mask) #else zzresynch(wd,mask) SetWordType *wd, mask; #endif { static int consumed = 1; /* if you enter here without having consumed a token from last resynch * force a token consumption. */ if ( !consumed ) {zzCONSUME; consumed=1; return;} /* MR10 */ /* if current token is in resynch set, we've got what we wanted */ if ( wd[LA(1)]&mask || LA(1) == zzEOF_TOKEN ) {consumed=0; return;} /* scan until we find something in the resynch set */ while ( !(wd[LA(1)]&mask) && LA(1) != zzEOF_TOKEN ) {zzCONSUME;} consumed=1; } /* */ /* 7-Apr-97 133MR1 for C++ and MR7 for C */ /* Change suggested by Eli Sternheim (eli@interhdl.com) */ /* */ void #ifdef __USE_PROTOS zzconsumeUntil(SetWordType *st) #else zzconsumeUntil(st) SetWordType *st; #endif { int tmp; /* MR7 */ while ( !zzset_el( (tmp=LA(1)), st) && tmp!=1 /* Eof */) { /* MR7 */ zzCONSUME; } /* MR7 */ } /* */ /* 7-Apr-97 133MR1 for C++ and MR7 for C */ /* Change suggested by Eli Sternheim (eli@interhdl.com) */ /* */ void #ifdef __USE_PROTOS zzconsumeUntilToken(int t) #else zzconsumeUntilToken(t) int t; #endif { int tmp; /* MR7 */ while ( (tmp=LA(1)) !=t && tmp!=1 /* Eof */) { zzCONSUME; } /* MR7 */ } /* input looks like: * zzFAIL(k, e1, e2, ...,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText) * where the zzMiss stuff is set here to the token that did not match * (and which set wasn't it a member of). */ #ifdef PCCTS_USE_STDARG void zzFAIL(int k, ...) #else void zzFAIL(va_alist) va_dcl #endif { #ifdef LL_K static char text[LL_K*ZZLEXBUFSIZE+1]; SetWordType *f[LL_K]; #else static char text[ZZLEXBUFSIZE+1]; SetWordType *f[1]; #endif SetWordType **miss_set; char **miss_text; int *bad_tok; char **bad_text; int *err_k; int i; va_list ap; #ifndef PCCTS_USE_STDARG /* MR20 */ int k; #endif #ifdef PCCTS_USE_STDARG /* MR20 */ va_start(ap, k); #else va_start(ap); k = va_arg(ap, int); /* how many lookahead sets? */ #endif assert(k <= sizeof(f)/sizeof(f[0])); /* MR20 G. Hobbelt */ text[0] = '\0'; 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(text, " "); strcat(text, LATEXT(i)); if ( !zzset_el((unsigned)LA(i), f[i-1]) ) break; } miss_set = va_arg(ap, SetWordType **); miss_text = va_arg(ap, char **); bad_tok = va_arg(ap, int *); bad_text = va_arg(ap, char **); err_k = va_arg(ap, int *); 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 = zzlextext; *bad_tok = LA(1); *bad_text = LATEXT(1); *err_k = k; return; } /* fprintf(stderr, "%s not in %dth set\n", zztokens[LA(i)], i);*/ *miss_set = f[i-1]; *miss_text = text; *bad_tok = LA(i); *bad_text = LATEXT(i); if ( i==1 ) *err_k = 1; else *err_k = k; } #ifdef __USE_PROTOS void zzTraceGuessDone(zzantlr_state *state) #else void zzTraceGuessDone(state) zzantlr_state *state; #endif { #ifdef zzTRACE_RULES #ifdef ZZCAN_GUESS int doIt=0; if (zzTraceCurrentRuleName == NULL) return; if (zzTraceOptionValue <= 0) { doIt=0; } else if (zzTraceGuessOptionValue <= 0) { doIt=0; } else { doIt=1; }; if (doIt) { fprintf(stderr,"guess done - returning to rule %s {\"%s\"} at depth %d", state->traceCurrentRuleName, LATEXT(1), state->traceDepth); if (state->guessing != 0) { fprintf(stderr," (guess mode continues - an enclosing guess is still active)"); } else { fprintf(stderr," (guess mode ends)"); }; fprintf(stderr,"\n"); }; #endif #endif } void #ifdef __USE_PROTOS zzsave_antlr_state(zzantlr_state *buf) #else zzsave_antlr_state(buf) zzantlr_state *buf; #endif { #ifdef LL_K int i; #endif #ifdef ZZCAN_GUESS buf->guess_start = zzguess_start; buf->guessing = zzguessing; #endif buf->asp = zzasp; #ifdef GENAST buf->ast_sp = zzast_sp; #endif #ifdef ZZINF_LOOK buf->inf_labase = zzinf_labase; buf->inf_last = zzinf_last; /* MR6 Gunnar Rxnning (gunnar@candleweb.no) */ /* MR6 Additional state needs to be saved/restored */ buf->inf_tokens = zzinf_tokens; /* MR6 */ buf->inf_text = zzinf_text; /* MR6 */ buf->inf_text_buffer = zzinf_text_buffer; /* MR6 */ buf->inf_line = zzinf_line; /* MR6 */ #endif #ifdef DEMAND_LOOK buf->dirty = zzdirty; #endif #ifdef LL_K for (i=0; itokenLA[i] = zztokenLA[i]; for (i=0; itextLA[i], zztextLA[i]); buf->lap = zzlap; buf->labase = zzlabase; #else buf->token = zztoken; strcpy(buf->text, zzlextext); #endif #ifdef zzTRACE_RULES /* MR10 */ buf->traceOptionValue=zzTraceOptionValue; buf->traceGuessOptionValue=zzTraceGuessOptionValue; buf->traceCurrentRuleName=zzTraceCurrentRuleName; buf->traceDepth=zzTraceDepth; #endif } void #ifdef __USE_PROTOS zzrestore_antlr_state(zzantlr_state *buf) #else zzrestore_antlr_state(buf) zzantlr_state *buf; #endif { #ifdef zzTRACE_RULES int prevTraceOptionValue; #endif #ifdef LL_K int i; #endif #ifdef ZZCAN_GUESS zzguess_start = buf->guess_start; zzguessing = buf->guessing; #endif zzasp = buf->asp; #ifdef GENAST zzast_sp = buf->ast_sp; #endif #ifdef ZZINF_LOOK zzinf_labase = buf->inf_labase; zzinf_last = buf->inf_last; /* MR6 Gunnar Rxnning (gunnar@candleweb.no) */ /* MR6 Additional state needs to be saved/restored */ zzinf_tokens = buf->inf_tokens; /* MR6 */ zzinf_text = buf->inf_text; /* MR6 */ zzinf_text_buffer = buf->inf_text_buffer; /* MR6 */ zzinf_line = buf->inf_line; /* MR6 */ #endif #ifdef DEMAND_LOOK zzdirty = buf->dirty; #endif #ifdef LL_K for (i=0; itokenLA[i]; for (i=0; itextLA[i]); zzlap = buf->lap; zzlabase = buf->labase; #else zztoken = buf->token; strcpy(zzlextext, buf->text); #endif #ifdef zzTRACE_RULES prevTraceOptionValue=zzTraceOptionValue; zzTraceOptionValue=buf->traceOptionValue; if ( (prevTraceOptionValue > 0) != (zzTraceOptionValue > 0)) { if (zzTraceOptionValue > 0) { fprintf(stderr,"trace enable restored in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; if (zzTraceOptionValue <= 0) { fprintf(stderr,"trace disable restored in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; }; zzTraceOptionValue=buf->traceOptionValue; /* MR10 */ zzTraceGuessOptionValue=buf->traceGuessOptionValue; /* MR10 */ zzTraceCurrentRuleName=buf->traceCurrentRuleName; /* MR10 */ zzTraceDepth=buf->traceDepth; /* MR10 */ zzTraceGuessDone(buf); /* MR10 */ #endif } void #ifdef __USE_PROTOS zzedecode(SetWordType *a) #else zzedecode(a) SetWordType *a; #endif { register SetWordType *p = a; register SetWordType *endp = &(p[zzSET_SIZE]); register unsigned e = 0; if ( zzset_deg(a)>1 ) fprintf(stderr, " {"); do { register SetWordType t = *p; register SetWordType *b = &(bitmask[0]); do { if ( t & *b ) fprintf(stderr, " %s", zztokens[e]); e++; } while (++b < &(bitmask[sizeof(SetWordType)*8])); } while (++p < endp); if ( zzset_deg(a)>1 ) fprintf(stderr, " }"); } #ifndef USER_ZZSYN /* standard error reporting function */ 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 { zzSyntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\"", zzline, (tok==zzEOF_TOKEN)?"EOF":bad_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) > 0 ) fprintf(stderr, " in %s", egroup); fprintf(stderr, "\n"); } #endif /* is b an element of set p? */ int #ifdef __USE_PROTOS zzset_el(unsigned b, SetWordType *p) #else zzset_el(b,p) unsigned b; SetWordType *p; #endif { return( p[BSETDIVWORD(b)] & bitmask[BSETMODWORD(b)] ); } int #ifdef __USE_PROTOS zzset_deg(SetWordType *a) #else zzset_deg(a) SetWordType *a; #endif { /* 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[zzSET_SIZE]); 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); } #ifdef DEMAND_LOOK #ifdef LL_K int #ifdef __USE_PROTOS _zzmatch(int _t, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet) #else _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet) int _t; char **zzBadText; char **zzMissText; int *zzMissTok, *zzBadTok; SetWordType **zzMissSet; #endif { if ( zzdirty==LL_K ) { zzCONSUME; } if ( LA(1)!=_t ) { *zzBadText = *zzMissText=LATEXT(1); *zzMissTok= _t; *zzBadTok=LA(1); *zzMissSet=NULL; return 0; } zzMakeAttr zzdirty++; zzlabase++; return 1; } int #ifdef __USE_PROTOS _zzmatch_wsig(int _t) #else _zzmatch_wsig(_t) int _t; #endif { if ( zzdirty==LL_K ) { zzCONSUME; } if ( LA(1)!=_t ) { return 0; } zzMakeAttr zzdirty++; zzlabase++; return 1; } #else int #ifdef __USE_PROTOS _zzmatch(int _t, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet) #else _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet) int _t; char **zzBadText; char **zzMissText; int *zzMissTok, *zzBadTok; SetWordType **zzMissSet; #endif { if ( zzdirty ) {zzCONSUME;} if ( LA(1)!=_t ) { *zzBadText = *zzMissText=LATEXT(1); *zzMissTok= _t; *zzBadTok=LA(1); *zzMissSet=NULL; return 0; } zzdirty = 1; zzMakeAttr return 1; } int #ifdef __USE_PROTOS _zzmatch_wsig(int _t) #else _zzmatch_wsig(_t) int _t; #endif { if ( zzdirty ) {zzCONSUME;} if ( LA(1)!=_t ) { return 0; } zzdirty = 1; zzMakeAttr return 1; } #endif /*LL_K*/ #else int #ifdef __USE_PROTOS _zzmatch(int _t, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet) #else _zzmatch(_t, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet) int _t; char **zzBadText; char **zzMissText; int *zzMissTok, *zzBadTok; SetWordType **zzMissSet; #endif { if ( LA(1)!=_t ) { *zzBadText = *zzMissText=LATEXT(1); *zzMissTok= _t; *zzBadTok=LA(1); *zzMissSet=NULL; return 0; } zzMakeAttr return 1; } int #ifdef __USE_PROTOS _zzmatch_wsig(int _t) #else _zzmatch_wsig(_t) int _t; #endif { if ( LA(1)!=_t ) return 0; zzMakeAttr return 1; } #endif /*DEMAND_LOOK*/ #ifdef ZZINF_LOOK void #ifdef __USE_PROTOS _inf_zzgettok(void) #else _inf_zzgettok() #endif { if ( zzinf_labase >= zzinf_last ) {NLA = zzEOF_TOKEN; strcpy(NLATEXT, "");} else { NLA = zzinf_tokens[zzinf_labase]; zzline = zzinf_line[zzinf_labase]; /* wrong in 1.21 */ strcpy(NLATEXT, zzinf_text[zzinf_labase]); zzinf_labase++; } } #endif #ifdef ZZINF_LOOK /* allocate default size text,token and line arrays; * then, read all of the input reallocing the arrays as needed. * Once the number of total tokens is known, the LATEXT(i) array (zzinf_text) * is allocated and it's pointers are set to the tokens in zzinf_text_buffer. */ void #ifdef __USE_PROTOS zzfill_inf_look(void) #else zzfill_inf_look() #endif { int tok, line; int zzinf_token_buffer_size = ZZINF_DEF_TOKEN_BUFFER_SIZE; int zzinf_text_buffer_size = ZZINF_DEF_TEXT_BUFFER_SIZE; int zzinf_text_buffer_index = 0; int zzinf_lap = 0; /* allocate text/token buffers */ zzinf_text_buffer = (char *) malloc(zzinf_text_buffer_size); if ( zzinf_text_buffer == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d bytes)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_tokens = (int *) calloc(zzinf_token_buffer_size,sizeof(int)); if ( zzinf_tokens == NULL ) { fprintf(stderr, "cannot allocate token buffer (%d tokens)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_line = (int *) calloc(zzinf_token_buffer_size,sizeof(int)); if ( zzinf_line == NULL ) { fprintf(stderr, "cannot allocate line buffer (%d ints)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } /* get tokens, copying text to text buffer */ zzinf_text_buffer_index = 0; do { zzgettok(); line = zzreal_line; while ( zzinf_lap>=zzinf_token_buffer_size ) { zzinf_token_buffer_size += ZZINF_BUFFER_TOKEN_CHUNK_SIZE; zzinf_tokens = (int *) realloc(zzinf_tokens, zzinf_token_buffer_size*sizeof(int)); if ( zzinf_tokens == NULL ) { fprintf(stderr, "cannot allocate lookahead token buffer (%d tokens)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_line = (int *) realloc(zzinf_line, zzinf_token_buffer_size*sizeof(int)); if ( zzinf_line == NULL ) { fprintf(stderr, "cannot allocate lookahead line buffer (%d ints)\n", zzinf_token_buffer_size); exit(PCCTS_EXIT_FAILURE); } } while ( (zzinf_text_buffer_index+strlen(NLATEXT)+1) >= zzinf_text_buffer_size ) { zzinf_text_buffer_size += ZZINF_BUFFER_TEXT_CHUNK_SIZE; zzinf_text_buffer = (char *) realloc(zzinf_text_buffer, zzinf_text_buffer_size); if ( zzinf_text_buffer == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d bytes)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } } /* record token and text and line of input symbol */ tok = zzinf_tokens[zzinf_lap] = NLA; strcpy(&zzinf_text_buffer[zzinf_text_buffer_index], NLATEXT); zzinf_text_buffer_index += strlen(NLATEXT)+1; zzinf_line[zzinf_lap] = line; zzinf_lap++; } while (tok!=zzEOF_TOKEN); zzinf_labase = 0; zzinf_last = zzinf_lap-1; /* allocate ptrs to text of ith token */ zzinf_text = (char **) calloc(zzinf_last+1,sizeof(char *)); if ( zzinf_text == NULL ) { fprintf(stderr, "cannot allocate lookahead text buffer (%d)\n", zzinf_text_buffer_size); exit(PCCTS_EXIT_FAILURE); } zzinf_text_buffer_index = 0; zzinf_lap = 0; /* set ptrs so that zzinf_text[i] is the text of the ith token found on input */ while (zzinf_lap<=zzinf_last) { zzinf_text[zzinf_lap++] = &zzinf_text_buffer[zzinf_text_buffer_index]; zzinf_text_buffer_index += strlen(&zzinf_text_buffer[zzinf_text_buffer_index])+1; } } #endif int #ifdef __USE_PROTOS _zzsetmatch(SetWordType *e, char **zzBadText, char **zzMissText, int *zzMissTok, int *zzBadTok, SetWordType **zzMissSet) #else _zzsetmatch(e, zzBadText, zzMissText, zzMissTok, zzBadTok, zzMissSet) SetWordType *e; char **zzBadText; char **zzMissText; int *zzMissTok, *zzBadTok; SetWordType **zzMissSet; #endif { #ifdef DEMAND_LOOK #ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;} #else if ( zzdirty ) {zzCONSUME;} #endif #endif if ( !zzset_el((unsigned)LA(1), e) ) { *zzBadText = LATEXT(1); *zzMissText=NULL; *zzMissTok= 0; *zzBadTok=LA(1); *zzMissSet=e; return 0; } zzMakeAttr /* MR14 Ger Hobbelt (hobbelt@axa.nl) */ #ifdef DEMAND_LOOK #ifdef LL_K zzdirty++; zzlabase++; /* MR14 Ger Hobbelt (hobbelt@axa.nl) */ #else zzdirty = 1; #endif #endif return 1; } int #ifdef __USE_PROTOS _zzmatch_wdfltsig(int tokenWanted, SetWordType *whatFollows) #else _zzmatch_wdfltsig(tokenWanted, whatFollows) int tokenWanted; SetWordType *whatFollows; #endif { #ifdef DEMAND_LOOK #ifdef LL_K if ( zzdirty==LL_K ) { zzCONSUME; } #else if ( zzdirty ) {zzCONSUME;} #endif #endif if ( LA(1)!=tokenWanted ) { zzSyntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", zzline, (LA(1)==zzEOF_TOKEN)?"":(char *)LATEXT(1), zztokens[tokenWanted]); zzconsumeUntil( whatFollows ); return 0; } else { zzMakeAttr #ifdef DEMAND_LOOK #ifdef LL_K zzdirty++; zzlabase++; #else zzdirty = 1; #endif #else /* zzCONSUME; consume if not demand lookahead */ #endif return 1; } } int #ifdef __USE_PROTOS _zzsetmatch_wdfltsig(SetWordType *tokensWanted, int tokenTypeOfSet, SetWordType *whatFollows) #else _zzsetmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows) SetWordType *tokensWanted; int tokenTypeOfSet; SetWordType *whatFollows; #endif { #ifdef DEMAND_LOOK #ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;} #else if ( zzdirty ) {zzCONSUME;} #endif #endif if ( !zzset_el((unsigned)LA(1), tokensWanted) ) { zzSyntaxErrCount++; /* MR11 */ fprintf(stderr, "line %d: syntax error at \"%s\" missing %s\n", zzline, (LA(1)==zzEOF_TOKEN)?"":(char *)LATEXT(1), zztokens[tokenTypeOfSet]); zzconsumeUntil( whatFollows ); return 0; } else { zzMakeAttr #ifdef DEMAND_LOOK #ifdef LL_K zzdirty++; zzlabase++; #else zzdirty = 1; #endif #else /* zzCONSUME; consume if not demand lookahead */ #endif return 1; } } int #ifdef __USE_PROTOS _zzsetmatch_wsig(SetWordType *e) #else _zzsetmatch_wsig(e) SetWordType *e; #endif { #ifdef DEMAND_LOOK #ifdef LL_K if ( zzdirty==LL_K ) {zzCONSUME;} #else if ( zzdirty ) {zzCONSUME;} #endif #endif if ( !zzset_el((unsigned)LA(1), e) ) return 0; zzMakeAttr /* MR14 Ger Hobbelt (hobbelt@axa.nl) */ #ifdef DEMAND_LOOK #ifdef LL_K zzdirty++; zzlabase++; /* MR14 Ger Hobbelt (hobbelt@axa.nl) */ #else zzdirty = 1; #endif #endif return 1; } #ifdef USER_ZZMODE_STACK static int zzmstk[ZZMAXSTK] = { -1 }; static int zzmdep = 0; static char zzmbuf[70]; void #ifdef __USE_PROTOS zzmpush( int m ) #else zzmpush( m ) int m; #endif { if(zzmdep == ZZMAXSTK - 1) { sprintf(zzmbuf, "Mode stack overflow "); zzerr(zzmbuf); } else { zzmstk[zzmdep++] = zzauto; zzmode(m); } } void #ifdef __USE_PROTOS zzmpop( void ) #else zzmpop( ) #endif { if(zzmdep == 0) { sprintf(zzmbuf, "Mode stack underflow "); zzerr(zzmbuf); } else { zzmdep--; zzmode(zzmstk[zzmdep]); } } void #ifdef __USE_PROTOS zzsave_mode_stack( int modeStack[], int *modeLevel ) #else zzsave_mode_stack( modeStack, modeLevel ) int modeStack[]; int *modeLevel; #endif { int i; memcpy(modeStack, zzmstk, sizeof(zzmstk)); *modeLevel = zzmdep; zzmdep = 0; return; } void #ifdef __USE_PROTOS zzrestore_mode_stack( int modeStack[], int *modeLevel ) #else zzrestore_mode_stack( modeStack, modeLevel ) int modeStack[]; int *modeLevel; #endif { int i; memcpy(zzmstk, modeStack, sizeof(zzmstk)); zzmdep = *modeLevel; return; } #endif /* USER_ZZMODE_STACK */ #ifdef __USE_PROTOS void zzTraceReset(void) #else void zzTraceReset() #endif { #ifdef zzTRACE_RULES zzTraceOptionValue=zzTraceOptionValueDefault; zzTraceGuessOptionValue=1; zzTraceCurrentRuleName=NULL; zzTraceDepth=0; #endif } #ifdef __USE_PROTOS void zzTraceGuessFail(void) #else void zzTraceGuessFail() #endif { #ifdef zzTRACE_RULES #ifdef ZZCAN_GUESS int doIt=0; if (zzTraceOptionValue <= 0) { doIt=0; } else if (zzguessing && zzTraceGuessOptionValue <= 0) { doIt=0; } else { doIt=1; }; if (doIt) { fprintf(stderr,"guess failed\n"); }; #endif #endif } /* zzTraceOption: zero value turns off trace */ #ifdef __USE_PROTOS void zzTraceIn(char * rule) #else void zzTraceIn(rule) char *rule; #endif { #ifdef zzTRACE_RULES int doIt=0; zzTraceDepth++; zzTraceCurrentRuleName=rule; if (zzTraceOptionValue <= 0) { doIt=0; #ifdef ZZCAN_GUESS } else if (zzguessing && zzTraceGuessOptionValue <= 0) { doIt=0; #endif } else { doIt=1; }; if (doIt) { fprintf(stderr,"enter rule %s {\"%s\"} depth %d", rule, LA(1)==1 ? "@" : (char *) LATEXT(1), /* MR19 */ zzTraceDepth); #ifdef ZZCAN_GUESS if (zzguessing) fprintf(stderr," guessing"); #endif fprintf(stderr,"\n"); }; #endif return; } #ifdef __USE_PROTOS void zzTraceOut(char * rule) #else void zzTraceOut(rule) char *rule; #endif { #ifdef zzTRACE_RULES int doIt=0; zzTraceDepth--; if (zzTraceOptionValue <= 0) { doIt=0; #ifdef ZZCAN_GUESS } else if (zzguessing && zzTraceGuessOptionValue <= 0) { doIt=0; #endif } else { doIt=1; }; if (doIt) { fprintf(stderr,"exit rule %s {\"%s\"} depth %d", rule, LA(1)==1 ? "@" : (char *) LATEXT(1), /* MR19 */ zzTraceDepth+1); #ifdef ZZCAN_GUESS if (zzguessing) fprintf(stderr," guessing"); #endif fprintf(stderr,"\n"); }; #endif } #ifdef __USE_PROTOS int zzTraceOption(int delta) #else int zzTraceOption(delta) int delta; #endif { #ifdef zzTRACE_RULES int prevValue=zzTraceOptionValue; zzTraceOptionValue=zzTraceOptionValue+delta; if (zzTraceCurrentRuleName != NULL) { if (prevValue <= 0 && zzTraceOptionValue > 0) { fprintf(stderr,"trace enabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; if (prevValue > 0 && zzTraceOptionValue <= 0) { fprintf(stderr,"trace disabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; }; return prevValue; #else return 0; #endif } #ifdef __USE_PROTOS int zzTraceGuessOption(int delta) #else int zzTraceGuessOption(delta) int delta; #endif { #ifdef zzTRACE_RULES #ifdef ZZCAN_GUESS int prevValue=zzTraceGuessOptionValue; zzTraceGuessOptionValue=zzTraceGuessOptionValue+delta; if (zzTraceCurrentRuleName != NULL) { if (prevValue <= 0 && zzTraceGuessOptionValue > 0) { fprintf(stderr,"guess trace enabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; if (prevValue > 0 && zzTraceGuessOptionValue <= 0) { fprintf(stderr,"guess trace disabled in rule %s depth %d\n", zzTraceCurrentRuleName,zzTraceDepth); }; }; return prevValue; #else return 0; #endif #else return 0; #endif } #endif /* ERR_H */ cccc-3.1.4/pccts/h/int.h0000644000000000000000000000253307265350435013432 0ustar rootroot/* ANTLR attribute definition -- long integers * * 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-1998 */ #ifndef ZZINT_H #define ZZINT_H typedef long Attrib; #define zzcr_attr(a,tok,t) *(a) = atol(t); #endif cccc-3.1.4/pccts/h/pccts_assert.h0000644000000000000000000000022207265350453015326 0ustar rootroot#ifndef __PCCTS_ASSERT_H__ #define __PCCTS_ASSERT_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_iostream.h0000644000000000000000000000023107265350456015653 0ustar rootroot#ifndef __PCCTS_IOSTREAM_H__ #define __PCCTS_IOSTREAM_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_istream.h0000644000000000000000000000022507265350456015477 0ustar rootroot#ifndef __PCCTS_ISTREAM_H__ #define __PCCTS_ISTREAM_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_setjmp.h0000644000000000000000000000022207265350456015332 0ustar rootroot#ifndef __PCCTS_SETJMP_H__ #define __PCCTS_SETJMP_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_stdarg.h0000644000000000000000000000022207265350456015314 0ustar rootroot#ifndef __PCCTS_STDARG_H__ #define __PCCTS_STDARG_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_stdio.h0000644000000000000000000000021607265350456015155 0ustar rootroot#ifndef __PCCTS_STDIO_H__ #define __PCCTS_STDIO_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_stdlib.h0000644000000000000000000000022207265350456015311 0ustar rootroot#ifndef __PCCTS_STDLIB_H__ #define __PCCTS_STDLIB_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pccts_string.h0000644000000000000000000000022207265350456015336 0ustar rootroot#ifndef __PCCTS_STRING_H__ #define __PCCTS_STRING_H__ #ifdef PCCTS_USE_NAMESPACE_STD #include #else #include #endif #endif cccc-3.1.4/pccts/h/pcctscfg.h0000644000000000000000000002104107265350453014427 0ustar rootroot#ifndef PCCTS_CONFIG_H #define PCCTS_CONFIG_H /* * pcctscfg.h (formerly config.h) (for ANTLR, DLG, and SORCERER) * * This is a simple configuration file that doesn't have config stuff * in it, but it's a start. * * 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. * * Used by PCCTS 1.33 (SORCERER 1.00B11 and up) * Terence Parr * Parr Research Corporation * with Purdue University and AHPCRC, University of Minnesota * 1989-1998 */ /* This file knows about the following ``environments'' UNIX (default) DOS (use #define PC) MAC (use #define MPW; has a few things for THINK C, Metrowerks) MS/C++ (MR14 Microsoft Visual C++ environment uses symbol _MSC_VER) */ /* should test __STDC__ for 1, but some compilers don't set value, just def */ #ifndef __USE_PROTOS #ifdef __STDC__ #define __USE_PROTOS #endif #ifdef __cplusplus #define __USE_PROTOS #endif #endif #ifdef PCCTS_USE_NAMESPACE_STD #define PCCTS_NAMESPACE_STD namespace std {}; using namespace std; #else #define PCCTS_NAMESPACE_STD #endif #include "pccts_stdio.h" #include "pccts_stdlib.h" /* largest file name size */ #ifdef _MAX_PATH #define MaxFileName _MAX_PATH /* MR9 RJV: MAX_PATH defined in stdlib.h (MSVC++ 5.0) */ #else #define MaxFileName 300 #endif /* * Define PC32 if in a 32-bit PC environment (e.g. extended DOS or Win32). * The macros tested here are defined by Watcom, Microsoft, Borland, * and djgpp, respectively, when they are used as 32-bit compilers. * Users of these compilers *must* be sure to define PC in their * makefiles for this to work correctly. */ #ifdef PC # if (defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__) || \ defined(__GNUC__) || defined(__GNUG__)) # ifndef PC32 # define PC32 # endif # endif #endif /* MR1 10-Apr-97 Default for PC is short file names */ /* MR1 Default for non-PC is long file names */ /* MR1 Can override via command line option LONGFILENAMES */ #ifndef LONGFILENAMES #ifndef PC #define LONGFILENAMES #endif #endif #ifndef LONGFILENAMES #define ATOKEN_H "AToken.h" #define ATOKPTR_H "ATokPtr.h" #define ATOKPTR_C "ATokPtr.cpp" #define ATOKENBUFFER_H "ATokBuf.h" #define ATOKENBUFFER_C "ATokBuf.cpp" #define ATOKENSTREAM_H "ATokStr.h" #define APARSER_H "AParser.h" #define APARSER_C "AParser.cpp" #define ASTBASE_H "ASTBase.h" #define ASTBASE_C "ASTBase.cpp" #define PCCTSAST_C "PCCTSAST.cpp" #define LIST_C "List.cpp" #define DLEXERBASE_H "DLexBase.h" #define DLEXERBASE_C "DLexBase.cpp" #define DLEXER_C "DLexer.cpp" #define STREESUPPORT_C "STreeSup.C" #else #define ATOKEN_H "AToken.h" #define ATOKPTR_H "ATokPtr.h" #define ATOKPTR_C "ATokPtr.cpp" #define ATOKENBUFFER_H "ATokenBuffer.h" #define ATOKENBUFFER_C "ATokenBuffer.cpp" #define ATOKENSTREAM_H "ATokenStream.h" #define APARSER_H "AParser.h" #define APARSER_C "AParser.cpp" #define ASTBASE_H "ASTBase.h" #define ASTBASE_C "ASTBase.cpp" #define PCCTSAST_C "PCCTSAST.cpp" #define LIST_C "List.cpp" #define DLEXERBASE_H "DLexerBase.h" #define DLEXERBASE_C "DLexerBase.cpp" #define DLEXER_C "DLexer.cpp" #define STREESUPPORT_C "STreeSupport.cpp" #endif /* SORCERER Stuff */ /* MR8 6-Aug-97 Change from ifdef PC to ifndef LONGFILENAMES */ #ifndef LONGFILENAMES #define STPARSER_H "STreePar.h" #define STPARSER_C "STreePar.C" #else #define STPARSER_H "STreeParser.h" #define STPARSER_C "STreeParser.cpp" #endif #ifdef MPW #define CPP_FILE_SUFFIX ".cp" #define CPP_FILE_SUFFIX_NO_DOT "cp" #define OBJ_FILE_SUFFIX ".o" #else #ifdef PC #define CPP_FILE_SUFFIX ".cpp" #define CPP_FILE_SUFFIX_NO_DOT "cpp" #define OBJ_FILE_SUFFIX ".obj" #else #ifdef __VMS #define CPP_FILE_SUFFIX ".cpp" #define CPP_FILE_SUFFIX_NO_DOT "cpp" #define OBJ_FILE_SUFFIX ".obj" #else #define CPP_FILE_SUFFIX ".cpp" #define CPP_FILE_SUFFIX_NO_DOT "cpp" #define OBJ_FILE_SUFFIX ".o" #endif #endif #endif /* User may redefine how line information looks */ /* make it #line MR7 */ #define LineInfoFormatStr "#line %d \"%s\"\n" #ifdef MPW /* Macintosh Programmer's Workshop */ #define ErrHdr "File \"%s\"; Line %d #" #else #ifdef _MSC_VER /* MR14 Microsoft Visual C++ environment */ #define ErrHdr "%s(%d) :" #else #define ErrHdr "%s, line %d:" /* default */ #endif #endif /* must assume old K&R cpp here, can't use #if defined(..)... */ #ifdef MPW #define TopDirectory ":" #define DirectorySymbol ":" #define OutputDirectoryOption "Directory where all output files should go (default=\":\")" #else #ifdef PC #define TopDirectory "." #define DirectorySymbol "\\" #define OutputDirectoryOption "Directory where all output files should go (default=\".\")" #else #ifdef __VMS #define TopDirectory "[000000]" #define DirectorySymbol "]" #define OutputDirectoryOption "Directory where all output files should go (default=\"[]\")" #else #define TopDirectory "." #define DirectorySymbol "/" #define OutputDirectoryOption "Directory where all output files should go (default=\".\")" #endif #endif #endif #ifdef MPW /* Make sure we have prototypes for all functions under MPW */ #include "pccts_string.h" #include "pccts_stdlib.h" /* MR6 2-Jun-97 Fixes false dependency caused by VC++ #include scanner */ /* MR6 Reported by Brad Schick (schick@interaccess.com) */ #define MPW_CursorCtl_Header #include MPW_CursorCtl_Header #ifdef __cplusplus extern "C" { #endif extern void fsetfileinfo (const char *filename, unsigned long newcreator, unsigned long newtype); #ifdef __cplusplus } #endif /* File creators for various popular development environments */ #define MAC_FILE_CREATOR 'MPS ' /* MPW Text files */ #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 #endif #ifdef MPW #define DAWDLE SpinCursor(1) #else #define DAWDLE #endif #ifdef MPW #define SPECIAL_INITS #define SPECIAL_FOPEN #endif #ifdef MPW #ifdef __cplusplus inline #else static #endif void special_inits() { InitCursorCtl((acurHandle) 0); } #endif #ifdef MPW #ifdef __cplusplus inline #else static #endif void special_fopen_actions(char * s) { fsetfileinfo (s, MAC_FILE_CREATOR, 'TEXT'); } #endif /* Define usable bits for set.c stuff */ #define BytesPerWord sizeof(unsigned) #define WORDSIZE (sizeof(unsigned)*8) #define LogWordSize (WORDSIZE==16?4:5) #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #if defined(VAXC) || defined(__VMS) #include #define PCCTS_EXIT_SUCCESS 1 #define PCCTS_EXIT_FAILURE SS$_ABORT #define zzDIE return SS$_ABORT; #define zzDONE return 1; #else /* !VAXC and !__VMS */ #define PCCTS_EXIT_SUCCESS 0 #define PCCTS_EXIT_FAILURE 1 #define zzDIE return 1; #define zzDONE return 0; #endif #ifdef USER_ZZMODE_STACK # ifndef ZZSTACK_MAX_MODE # define ZZSTACK_MAX_MODE 32 # endif # define ZZMAXSTK (ZZSTACK_MAX_MODE * 2) #endif #ifndef DllExportPCCTS #define DllExportPCCTS #endif #ifdef PC #ifndef PCCTS_CASE_INSENSITIVE_FILE_NAME #define PCCTS_CASE_INSENSITIVE_FILE_NAME #endif #endif #ifdef PC32 #ifndef PCCTS_CASE_INSENSITIVE_FILE_NAME #define PCCTS_CASE_INSENSITIVE_FILE_NAME #endif #endif #ifdef __VMS #ifndef PCCTS_CASE_INSENSITIVE_FILE_NAME #define PCCTS_CASE_INSENSITIVE_FILE_NAME #endif #endif #ifdef __USE_PROTOS #ifndef PCCTS_USE_STDARG #define PCCTS_USE_STDARG #endif #endif #ifdef __STDC__ #ifndef PCCTS_USE_STDARG #define PCCTS_USE_STDARG #endif #endif #ifdef __cplusplus #ifndef PCCTS_USE_STDARG #define PCCTS_USE_STDARG #endif #endif #endif cccc-3.1.4/pccts/h/pcctslib50.dsp0000644000000000000000000000612007265350453015143 0ustar rootroot# Microsoft Developer Studio Project File - Name="pcctslib" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Static Library" 0x0104 CFG=pcctslib - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "pcctslib50.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "pcctslib50.mak" CFG="pcctslib - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "pcctslib - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "pcctslib - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE # Begin Project # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe !IF "$(CFG)" == "pcctslib - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /FD /c # SUBTRACT CPP /YX BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo /out:"pccts_release.lib" # Begin Special Build Tool SOURCE=$(InputPath) PostBuild_Desc=Copy to ..\lib PostBuild_Cmds=mkdir ..\lib copy pccts_release.lib ..\lib\pccts_release.lib # End Special Build Tool !ELSEIF "$(CFG)" == "pcctslib - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /Z7 /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /FD /c # SUBTRACT CPP /YX BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo /out:"pccts_debug.lib" # Begin Special Build Tool SOURCE=$(InputPath) PostBuild_Desc=Copy to ..\lib PostBuild_Cmds=mkdir ..\lib copy pccts_debug.lib ..\lib\pccts_debug.lib # End Special Build Tool !ENDIF # Begin Target # Name "pcctslib - Win32 Release" # Name "pcctslib - Win32 Debug" # Begin Source File SOURCE=.\AParser.cpp # End Source File # Begin Source File SOURCE=.\ASTBase.cpp # End Source File # Begin Source File SOURCE=.\ATokenBuffer.cpp # End Source File # Begin Source File SOURCE=.\BufFileInput.cpp # End Source File # Begin Source File SOURCE=.\DLexerBase.cpp # End Source File # Begin Source File SOURCE=.\PCCTSAST.cpp # End Source File # Begin Source File SOURCE=.\SList.cpp # End Source File # End Target # End Project cccc-3.1.4/pccts/h/pcctslib50.dsw0000644000000000000000000000100007265350453015142 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 5.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "pcctslib"=.\pcctslib50.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/h/pcctslib60.dsp0000644000000000000000000000633107265350453015150 0ustar rootroot# Microsoft Developer Studio Project File - Name="pcctslib" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Static Library" 0x0104 CFG=pcctslib - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "pcctslib60.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "pcctslib60.mak" CFG="pcctslib - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "pcctslib - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "pcctslib - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "pcctslib - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo /out:"pccts_release.lib" # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy to ..\lib PostBuild_Cmds=mkdir ..\lib copy pccts_release.lib ..\lib\pccts_release.lib # End Special Build Tool !ELSEIF "$(CFG)" == "pcctslib - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /Z7 /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo /out:"pccts_debug.lib" # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy to ..\lib PostBuild_Cmds=mkdir ..\lib copy pccts_debug.lib ..\lib\pccts_debug.lib # End Special Build Tool !ENDIF # Begin Target # Name "pcctslib - Win32 Release" # Name "pcctslib - Win32 Debug" # Begin Source File SOURCE=.\AParser.cpp # End Source File # Begin Source File SOURCE=.\ASTBase.cpp # End Source File # Begin Source File SOURCE=.\ATokenBuffer.cpp # End Source File # Begin Source File SOURCE=.\BufFileInput.cpp # End Source File # Begin Source File SOURCE=.\DLexerBase.cpp # End Source File # Begin Source File SOURCE=.\PCCTSAST.cpp # End Source File # Begin Source File SOURCE=.\SList.cpp # End Source File # End Target # End Project cccc-3.1.4/pccts/h/pcctslib60.dsw0000644000000000000000000000100007265350453015143 0ustar rootrootMicrosoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "pcctslib"=.\pcctslib60.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### cccc-3.1.4/pccts/h/pcnames.bat0000755000000000000000000000043107265350456014606 0ustar rootrootren aparser.c aparser.cpp ren astbase.c astbase.cpp ren atokenbu.c atokbuf.cpp ren atokenbu.h atokbuf.h ren atokenst.h atokstr.h ren dlexerba.c dlexbase.cpp ren dlexerba.h dlexbase.h ren dlexer.c dlexer.cpp ren list.c list.cpp ren pblackbo.h pblckbox.h ren pcctsast.c pcctsast.cpp cccc-3.1.4/pccts/h/slist.cpp0000644000000000000000000000507307265350456014336 0ustar rootroot/* * SList.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. * * PCCTS 1.33 * Terence Parr * Parr Research Corporation * with Purdue University and AHPCRC, University of Minnesota * 1992-1998 */ #define ANTLR_SUPPORT_CODE #include "SList.h" /* Iterate over a list of elements; returns ptr to a new element * in list upon every call and NULL when no more are left. * Very useful like this: * * cursor = mylist; * while ( (p=mylist->iterate(&cursor)) ) { * // place with element p * } * * The cursor must be initialized to point to the list to iterate over. */ void *SList:: iterate(SListNode **cursor) { void *e; if ( cursor == NULL || *cursor==NULL ) return NULL; if ( head == *cursor ) { *cursor = (*cursor)->next(); } e = (*cursor)->elem(); (*cursor) = (*cursor)->next(); return e; } /* add an element to end of list. */ void SList:: add(void *e) { SListNode *p, *tail=NULL; require(e!=NULL, "slist_add: attempting to add NULL list element"); p = new SListNode; require(p!=NULL, "add: cannot alloc new list node"); p->setElem(e); if ( head == NULL ) { head = tail = p; } else /* find end of list */ { tail->setNext(p); tail = p; } } void SList:: lfree() { SListNode *p,*q; if ( head==NULL ) return; /* empty list */ for (p = head; p!=NULL; p=q) { q = p->next(); free(p); } } PCCTS_AST *SList:: to_ast(SList list) { PCCTS_AST *t=NULL, *last=NULL; SListNode *p; for (p = head; p!=NULL; p=p->next()) { PCCTS_AST *u = (PCCTS_AST *)p->elem(); if ( last==NULL ) last = t = u; else { last->setRight(u); last = u; } } return t; } cccc-3.1.4/pccts/support/0000755000000000000000000000000010357462414013746 5ustar rootrootcccc-3.1.4/pccts/support/DECmms/0000755000000000000000000000000010357462412015054 5ustar rootrootcccc-3.1.4/pccts/support/DECmms/genmms.c0000644000000000000000000004354107341735540016521 0ustar rootroot/* * genmms -- a program to make VMS makefiles for PCCTS * * ANTLR 1.33MR10 * Terence John Parr 1989 - 1998 * Purdue University * U of MN * * * VMS version from J.F. Pieronne */ #include #include #include "pcctscfg.h" /* be sensitive to what ANTLR/DLG call the files */ #define DIE return SS$_ABORT; #define DONE return 1; #ifndef require #define require(expr, err) {if ( !(expr) ) fatal(err);} #endif #define MAX_FILES 50 #define MAX_CLASSES 50 char *RENAME_OBJ_FLAG="/obj=", *RENAME_EXE_FLAG="/exe="; char *dlg = "parser.dlg"; char *err = "err.c"; char *hdr = "stdpccts.h"; char *tok = "tokens.h"; char *mode = "mode.h"; char *scan = "scan"; char ATOKENBUFFER_O[100]; char APARSER_O[100]; char ASTBASE_O[100]; char PCCTSAST_O[100]; char LIST_O[100]; char DLEXERBASE_O[100]; /* Option flags */ static char *project="t", *files[MAX_FILES], *classes[MAX_CLASSES]; static int num_files = 0; static int num_classes = 0; static int user_lexer = 0; static char *user_token_types = NULL; static int gen_CPP = 0; static char *outdir="."; static char *dlg_class = "DLGLexer"; static int gen_trees = 0; static int gen_hoist = 0; typedef struct _Opt { char *option; int arg; #ifdef __cplusplus void (*process)(...); #else void (*process)(); #endif char *descr; } Opt; #ifdef __STDC__ static void ProcessArgs(int, char **, Opt *); #else static void ProcessArgs(); #endif static void pProj( s, t ) char *s; char *t; { project = t; } static void pUL( s ) char *s; { user_lexer = 1; } static void pCPP( s ) char *s; { gen_CPP = 1; } static void pUT( s, t ) char *s; char *t; { user_token_types = t; } static void pTrees( s ) char *s; { gen_trees = 1; } static void pHoist( s ) char *s; { gen_hoist = 1; } static void #ifdef __STDC__ pFile( char *s ) #else pFile( s ) char *s; #endif { if ( *s=='-' ) { fprintf(stderr, "invalid option: '%s'; ignored...",s); return; } require(num_files0 ) { warn("can't define classes w/o C++ mode; turning on C++ mode...\n"); gen_CPP=1; } if ( gen_CPP && num_classes==0 ) { fatal("must define classes >0 grammar classes in C++ mode\n"); } mk(project, files, num_files, argc, argv); DONE; } help() { Opt *p = options; static char buf[1000+1]; fprintf(stderr, "genmk [options] f1.g ... fn.g\n"); while ( p->option!=NULL && *(p->option) != '*' ) { buf[0]='\0'; if ( p->arg ) sprintf(buf, "%s ___", p->option); else strcpy(buf, p->option); fprintf(stderr, "\t%-16s %s\n", buf, p->descr); p++; } } mk(project, files, n, argc, argv) char *project; char **files; int n; int argc; char **argv; { int i; printf("!\n"); printf("! PCCTS makefile for: "); pfiles(files, n, NULL); printf("\n"); printf("!\n"); printf("! Created from:"); for (i=0; i0 ) { char *p = &(*files)[strlen(*files)-1]; if ( !first ) putchar(' '); first=0; while ( p > *files && *p != '.' ) --p; if ( p == *files ) { fprintf(stderr, "genmk: filenames must be file.suffix format: %s\n", *files); exit(-1); } if ( suffix == NULL ) printf("%s", *files); else { *p = '\0'; printf("%s", DIR()); if ( strcmp(suffix, "o")==0 ) printf("%s%s", *files, OBJ_FILE_SUFFIX); else printf("%s.%s", *files, suffix); *p = '.'; } files++; --n; } } pclasses(classes, n, suffix) char **classes; int n; char *suffix; { int first=1; while ( n>0 ) { if ( !first ) putchar(' '); first=0; if ( suffix == NULL ) printf("%s", *classes); else { printf("%s", DIR()); if ( strcmp(suffix, "o")==0 ) printf("%s%s", *classes, OBJ_FILE_SUFFIX); else printf("%s.%s", *classes, suffix); } classes++; --n; } } static void #ifdef __STDC__ ProcessArgs( int argc, char **argv, Opt *options ) #else ProcessArgs( argc, argv, options ) int argc; char **argv; Opt *options; #endif { Opt *p; require(argv!=NULL, "ProcessArgs: command line NULL"); while ( argc-- > 0 ) { p = options; while ( p->option != NULL ) { if ( strcmp(p->option, "*") == 0 || strcmp(p->option, *argv) == 0 ) { if ( p->arg ) { (*p->process)( *argv, *(argv+1) ); argv++; argc--; } else (*p->process)( *argv ); break; } p++; } argv++; } } fatal( err_) char *err_; { fprintf(stderr, "genmk: %s\n", err_); exit(1); } warn( err_) char *err_; { fprintf(stderr, "genmk: %s\n", err_); } char *DIR() { static char buf[200+1]; if ( strcmp(outdir,TopDirectory)==0 ) return ""; sprintf(buf, "%s", outdir); return buf; } cccc-3.1.4/pccts/support/DECmms/makefile.VMS0000644000000000000000000000065007341735540017225 0ustar rootroot$! File: MAKE.COM - Makefile for genmms OpenVMS $! $! History: $! --------- $! 28-Jan-1998 J.F. Pieronne V1.0. $! $ set noon !Don't stop on errors. $! $ if P1 .eqs. "LINK" then goto relink $! $! $ delete/nolog *.obj;* !Get rid of existing .OBJ files. $! $ options = "/INCLUDE=([--.h])/define=(__STDC__)" $ CC 'options' genmms $! $relink: $ LINK genmms, sys$input:/options ! sys$share:vaxcrtl.exe/share $ EXIT cccc-3.1.4/pccts/support/msvc.dsp0000644000000000000000000001260007341735537015435 0ustar rootroot# Microsoft Developer Studio Project File - Name="support" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Static Library" 0x0104 CFG=support - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "support.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "support.mak" CFG="support - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "support - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "support - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE # Begin Project # PROP Scc_ProjName ""$/pccts/support", YGABAAAA" # PROP Scc_LocalPath "." CPP=cl.exe !IF "$(CFG)" == "support - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /I "..\h" /I "..\support\set" /I "..\support" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "USER_ZZSYN" /D "PC" /D "__STDC__" /YX /FD /c BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo !ELSEIF "$(CFG)" == "support - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\h" /I "..\support\set" /I "..\support" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "USER_ZZSYN" /D "PC" /D "__STDC__" /YX /FD /c BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo !ENDIF # Begin Target # Name "support - Win32 Release" # Name "support - Win32 Debug" # Begin Group "Headers" # PROP Default_Filter ".h" # Begin Source File SOURCE=.\errout.h # End Source File # Begin Source File SOURCE=.\set\set.h # End Source File # End Group # Begin Group "Source" # PROP Default_Filter "c,cpp" # Begin Source File SOURCE=.\errout.c # End Source File # Begin Source File SOURCE=.\set\set.c # End Source File # End Group # Begin Group "PCCTS' clients files" # PROP Default_Filter "" # Begin Source File SOURCE=..\h\antlr.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\AParser.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\AParser.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ast.c # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ast.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ASTBase.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ASTBase.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\AToken.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ATokenBuffer.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ATokenBuffer.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ATokenStream.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ATokPtr.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\ATokPtr.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\charbuf.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\charptr.c # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\charptr.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\pcctscfg.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\DLexer.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\DLexerBase.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\DLexerBase.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\dlgauto.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\dlgdef.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\err.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\int.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\PBlackBox.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\PCCTSAST.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\PCCTSAST.h # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\SList.cpp # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=..\h\SList.h # PROP Exclude_From_Build 1 # End Source File # End Group # End Target # End Project cccc-3.1.4/pccts/support/genmk/0000755000000000000000000000000010357462412015045 5ustar rootrootcccc-3.1.4/pccts/support/genmk/makefile0000644000000000000000000000105607341735540016553 0ustar rootroot## ## 7-Apr-97 ## added support/genmk/makefile to pccts 1.33MR1 distribution kit ## (support/genmk/makefile" omitted from 1.33 distribution kit) ## SRC=genmk.c OBJ=genmk.o # Define PC if you use a PC OS (changes directory symbol and object file extension) # see pccts/h/pcctscfg.h #CFLAGS=-I../../h -DPC CFLAGS=-I../../h CC=cc BAG=../../bin/bag genmk: $(OBJ) $(SRC) ../../h/pcctscfg.h $(CC) -o genmk $(OBJ) clean: rm -rf core *.o scrub: rm -rf genmk core *.o shar: shar genmk.c makefile > genmk.shar archive: $(BAG) genmk.c makefile > genmk.bag cccc-3.1.4/pccts/support/genmk/genmk.c0000644000000000000000000004067407341735540016331 0ustar rootroot/* * genmk -- a program to make makefiles for PCCTS * * ANTLR 1.33MR10 * Terence John Parr 1989 - 1998 * Purdue University * U of MN */ #include #include "pcctscfg.h" /* be sensitive to what ANTLR/DLG call the files */ #ifdef VAXC #define DIE return 0; #define DONE return 1; #else #define DIE return 1; #define DONE return 0; #endif #ifndef require #define require(expr, err) {if ( !(expr) ) fatal(err);} #endif #define MAX_FILES 50 #define MAX_CLASSES 50 char *RENAME_OBJ_FLAG="-o", *RENAME_EXE_FLAG="-o"; char *dlg = "parser.dlg"; char *err = "err.c"; char *hdr = "stdpccts.h"; char *tok = "tokens.h"; char *mode = "mode.h"; char *scan = "scan"; char ATOKENBUFFER_O[100]; char APARSER_O[100]; char ASTBASE_O[100]; char PCCTSAST_O[100]; char LIST_O[100]; char DLEXERBASE_O[100]; /* Option flags */ static char *project="t", *files[MAX_FILES], *classes[MAX_CLASSES]; static int num_files = 0; static int num_classes = 0; static int user_lexer = 0; static char *user_token_types = NULL; static int gen_CPP = 0; static char *outdir="."; static char *dlg_class = "DLGLexer"; static int gen_trees = 0; static int gen_hoist = 0; typedef struct _Opt { char *option; int arg; #ifdef __cplusplus void (*process)(...); #else void (*process)(); #endif char *descr; } Opt; #ifdef __STDC__ static void ProcessArgs(int, char **, Opt *); #else static void ProcessArgs(); #endif static void pProj( s, t ) char *s; char *t; { project = t; } static void pUL( s ) char *s; { user_lexer = 1; } static void pCPP( s ) char *s; { gen_CPP = 1; } static void pUT( s, t ) char *s; char *t; { user_token_types = t; } static void pTrees( s ) char *s; { gen_trees = 1; } static void pHoist( s ) char *s; { gen_hoist = 1; } static void #ifdef __STDC__ pFile( char *s ) #else pFile( s ) char *s; #endif { if ( *s=='-' ) { fprintf(stderr, "invalid option: '%s'; ignored...",s); return; } require(num_files0 ) { warn("can't define classes w/o C++ mode; turning on C++ mode...\n"); gen_CPP=1; } if ( gen_CPP && num_classes==0 ) { fatal("must define classes >0 grammar classes in C++ mode\n"); } mk(project, files, num_files, argc, argv); DONE; } help() { Opt *p = options; static char buf[1000+1]; fprintf(stderr, "genmk [options] f1.g ... fn.g\n"); while ( p->option!=NULL && *(p->option) != '*' ) { buf[0]='\0'; if ( p->arg ) sprintf(buf, "%s ___", p->option); else strcpy(buf, p->option); fprintf(stderr, "\t%-16s %s\n", buf, p->descr); p++; } } mk(project, files, n, argc, argv) char *project; char **files; int n; int argc; char **argv; { int i; printf("#\n"); printf("# PCCTS makefile for: "); pfiles(files, n, NULL); printf("\n"); printf("#\n"); printf("# Created from:"); for (i=0; i0 ) { char *p = &(*files)[strlen(*files)-1]; if ( !first ) putchar(' '); first=0; while ( p > *files && *p != '.' ) --p; if ( p == *files ) { fprintf(stderr, "genmk: filenames must be file.suffix format: %s\n", *files); exit(-1); } if ( suffix == NULL ) printf("%s", *files); else { *p = '\0'; printf("%s", DIR()); if ( strcmp(suffix, "o")==0 ) printf("%s%s", *files, OBJ_FILE_SUFFIX); else printf("%s.%s", *files, suffix); *p = '.'; } files++; --n; } } pclasses(classes, n, suffix) char **classes; int n; char *suffix; { int first=1; while ( n>0 ) { if ( !first ) putchar(' '); first=0; if ( suffix == NULL ) printf("%s", *classes); else { printf("%s", DIR()); if ( strcmp(suffix, "o")==0 ) printf("%s%s", *classes, OBJ_FILE_SUFFIX); else printf("%s.%s", *classes, suffix); } classes++; --n; } } static void #ifdef __STDC__ ProcessArgs( int argc, char **argv, Opt *options ) #else ProcessArgs( argc, argv, options ) int argc; char **argv; Opt *options; #endif { Opt *p; require(argv!=NULL, "ProcessArgs: command line NULL"); while ( argc-- > 0 ) { p = options; while ( p->option != NULL ) { if ( strcmp(p->option, "*") == 0 || strcmp(p->option, *argv) == 0 ) { if ( p->arg ) { (*p->process)( *argv, *(argv+1) ); argv++; argc--; } else (*p->process)( *argv ); break; } p++; } argv++; } } fatal( err_) char *err_; { fprintf(stderr, "genmk: %s\n", err_); exit(1); } warn( err_) char *err_; { fprintf(stderr, "genmk: %s\n", err_); } char *DIR() { static char buf[200+1]; if ( strcmp(outdir,TopDirectory)==0 ) return ""; sprintf(buf, "%s%s", outdir, DirectorySymbol); return buf; } cccc-3.1.4/pccts/support/genmk/watgenmk.mak0000644000000000000000000000070507341735540017362 0ustar rootrootSET=..\..\support\set PCCTS_H=..\..\h # # Watcom # CC=wcl386 ANTLR=..\..\bin\antlr DLG=..\..\bin\dlg CFLAGS= -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DPC OUT_OBJ = -o OBJ_EXT = obj LINK = wcl386 .c.obj : $(CC) -c $[* $(CFLAGS) genmk.exe: genmk.obj $(LINK) -fe=genmk.exe *.obj -k14336 copy *.exe ..\..\bin #clean up all the intermediate files clean: del *.obj #remove everything in clean plus the PCCTS files generated scrub: del *.$(OBJ_EXT) cccc-3.1.4/pccts/support/rexpr/0000755000000000000000000000000010357462413015105 5ustar rootrootcccc-3.1.4/pccts/support/rexpr/makefile0000644000000000000000000000044607341735540016614 0ustar rootrootBAG=../../bin/bag SRC=test.c rexpr.c OBJ=test.o rexpr.o CFLAGS = -g test: $(OBJ) $(SRC) cc -g -o texpr $(OBJ) shar: shar makefile test.c rexpr.c rexpr.h > rexpr.shar archive: $(BAG) makefile test.c rexpr.c rexpr.h > rexpr.bag clean: rm -rf *.o core texpr scrub: rm -rf *.o core texpr cccc-3.1.4/pccts/support/rexpr/rexpr.c0000644000000000000000000002720307341735540016420 0ustar rootroot/* * This file contains code for * * int rexpr(char *expr, char *s); * * which answers * * 1 if 's' is in the language described by the regular expression 'expr' * 0 if it is not * -1 if the regular expression is invalid * * Language membership is determined by constructing a non-deterministic * finite automata (NFA) from the regular expression. A depth- * first-search is performed on the NFA (graph) to check for a match of 's'. * Each non-epsilon arc consumes one character from 's'. Backtracking is * performed to check all possible paths through the NFA. * * Regular expressions follow the meta-language: * * ::= ( '|' )* * * ::= ( )* * * ::= {'~'} '[' ']' * | '(' ')' * | '{' '}' * | * * ::= { '*' | '+' } * * ::= ( )* * | { } '-' { } * * ::= Token[Atom] * * Notes: * ~ means complement the set in [..]. i.e. all characters not listed * * means match 0 or more times (can be on expression or atom) * + means match 1 or more times (can be on expression or atom) * {} optional * () grouping * [] set of atoms * x-y all characters from x to y (found only in [..]) * \xx the character with value xx * * Examples: * [a-z]+ * match 1 or more lower-case letters (e.g. variable) * * 0x[0-9A-Fa-f]+ * match a hex number with 0x on front (e.g. 0xA1FF) * * [0-9]+.[0-9]+{e[0-9]+} * match a floating point number (e.g. 3.14e21) * * Code example: * if ( rexpr("[a-zA-Z][a-zA-Z0-9]+", str) ) then str is keyword * * Terence Parr * Purdue University * April 1991 */ #include #include #ifdef __STDC__ #include #else #include #endif #include "rexpr.h" #ifdef __USE_PROTOS static int regExpr( GraphPtr g ); static int andExpr( GraphPtr g ); static int expr( GraphPtr g ); static int repeatSymbol( GraphPtr g ); static int atomList( char *p, int complement ); static void next( void ); static ArcPtr newGraphArc( void ); static NodePtr newNode( void ); static int ArcBetweenGraphNode( NodePtr i, NodePtr j, int label ); static Graph BuildNFA_atom( int label ); static Graph BuildNFA_AB( Graph A, Graph B ); static Graph BuildNFA_AorB( Graph A, Graph B ); static Graph BuildNFA_set( char *s ); static Graph BuildNFA_Astar( Graph A ); static Graph BuildNFA_Aplus( Graph A ); static Graph BuildNFA_Aoptional( Graph A ); #else static int regExpr(); static int andExpr(); static int expr(); static int repeatSymbol(); static int atomList(); static void next(); static ArcPtr newGraphArc(); static NodePtr newNode(); static int ArcBetweenGraphNode(); static Graph BuildNFA_atom(); static Graph BuildNFA_AB(); static Graph BuildNFA_AorB(); static Graph BuildNFA_set(); static Graph BuildNFA_Astar(); static Graph BuildNFA_Aplus(); static Graph BuildNFA_Aoptional(); #endif static char *_c; static int token, tokchar; static NodePtr accept; static NodePtr freelist = NULL; /* * return 1 if s in language described by expr * 0 if s is not * -1 if expr is an invalid regular expression */ #ifdef __USE_PROTOS static int rexpr(char *expr,char *s) #else static int rexpr(expr, s) char *expr, *s; #endif { NodePtr p,q; Graph nfa; int result; fprintf(stderr, "rexpr(%s,%s);\n", expr,s); freelist = NULL; _c = expr; next(); if ( regExpr(&nfa) == -1 ) return -1; accept = nfa.right; result = match(nfa.left, s); /* free all your memory */ p = q = freelist; while ( p!=NULL ) { q = p->track; free(p); p = q; } return result; } /* * do a depth-first-search on the NFA looking for a path from start to * accept state labelled with the characters of 's'. */ #ifdef __USE_PROTOS static int match(NodePtr automaton,char *s) #else static int match(automaton, s) NodePtr automaton; char *s; #endif { ArcPtr p; if ( automaton == accept && *s == '\0' ) return 1; /* match */ for (p=automaton->arcs; p!=NULL; p=p->next) /* try all arcs */ { if ( p->label == Epsilon ) { if ( match(p->target, s) ) return 1; } else if ( p->label == *s ) if ( match(p->target, s+1) ) return 1; } return 0; } /* * ::= ( '|' {} )* * * Return -1 if syntax error * Return 0 if none found * Return 1 if a regExrp was found */ #ifdef __USE_PROTOS static int regExpr(GraphPtr g) #else static int regExpr(g) GraphPtr g; #endif { 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; *g = g1; return 1; } /* * ::= ( )* */ #ifdef __USE_PROTOS static int andExpr(GraphPtr g) #else static int andExpr(g) GraphPtr g; #endif { Graph g1, g2; if ( expr(&g1) == -1 ) { return -1; } while ( token==Atom || token=='{' || token=='(' || token=='~' || token=='[' ) { if (expr(&g2) == -1) return -1; g1 = BuildNFA_AB(g1, g2); } *g = g1; return 1; } /* * ::= {'~'} '[' ']' * | '(' ')' * | '{' '}' * | */ #ifdef __USE_PROTOS static int expr(GraphPtr g) #else static int expr(g) GraphPtr g; #endif { int complement = 0; char s[257]; /* alloc space for string of char in [] */ if ( token == '~' || token == '[' ) { if ( token == '~' ) {complement = 1; next();} if ( token != '[' ) return -1; next(); if ( atomList( s, complement ) == -1 ) return -1; *g = BuildNFA_set( s ); if ( token != ']' ) return -1; next(); repeatSymbol( g ); return 1; } if ( token == '(' ) { next(); if ( regExpr( g ) == -1 ) return -1; if ( token != ')' ) return -1; next(); repeatSymbol( g ); return 1; } if ( token == '{' ) { next(); if ( regExpr( g ) == -1 ) return -1; if ( token != '}' ) return -1; next(); /* S p e c i a l C a s e O p t i o n a l { } */ if ( token != '*' && token != '+' ) { *g = BuildNFA_Aoptional( *g ); } repeatSymbol( g ); return 1; } if ( token == Atom ) { *g = BuildNFA_atom( tokchar ); next(); repeatSymbol( g ); return 1; } return -1; } /* * ::= { '*' | '+' } */ #ifdef __USE_PROTOS static int repeatSymbol(GraphPtr g) #else static int repeatSymbol(g) GraphPtr g; #endif { switch ( token ) { case '*' : *g = BuildNFA_Astar( *g ); next(); break; case '+' : *g = BuildNFA_Aplus( *g ); next(); break; } return 1; } /* * ::= { }* * { } '-' { } * * a-b is same as ab * q-a is same as q */ #ifdef __USE_PROTOS static int atomList(char *p, int complement) #else static int atomList(p, complement) char *p; int complement; #endif { static unsigned char set[256]; /* no duplicates */ int first, last, i; char *s = p; if ( token != Atom ) return -1; for (i=0; i<256; i++) set[i] = 0; while ( token == Atom ) { if ( !set[tokchar] ) *s++ = tokchar; set[tokchar] = 1; /* Add atom to set */ next(); if ( token == '-' ) /* have we found '-' */ { first = *(s-1); /* Get last char */ next(); if ( token != Atom ) return -1; else { last = tokchar; } for (i = first+1; i <= last; i++) { if ( !set[tokchar] ) *s++ = i; set[i] = 1; /* Add atom to set */ } next(); } } *s = '\0'; if ( complement ) { for (i=0; i<256; i++) set[i] = !set[i]; for (i=1,s=p; i<256; i++) if ( set[i] ) *s++ = i; *s = '\0'; } return 1; } /* a somewhat stupid lexical analyzer */ #ifdef __USE_PROTOS static void next(void) #else static void next() #endif { while ( *_c==' ' || *_c=='\t' || *_c=='\n' ) _c++; if ( *_c=='\\' ) { _c++; if ( isdigit(*_c) ) { int n=0; while ( isdigit(*_c) ) { n = n*10 + (*_c++ - '0'); } if ( n>255 ) n=255; tokchar = n; } else { switch (*_c) { case 'n' : tokchar = '\n'; break; case 't' : tokchar = '\t'; break; case 'r' : tokchar = '\r'; break; default : tokchar = *_c; } _c++; } token = Atom; } else if ( isgraph(*_c) && *_c!='[' && *_c!='(' && *_c!='{' && *_c!='-' && *_c!='}' && *_c!=')' && *_c!=']' && *_c!='+' && *_c!='*' && *_c!='~' && *_c!='|' ) { token = Atom; tokchar = *_c++; } else { token = tokchar = *_c++; } } /* N F A B u i l d i n g R o u t i n e s */ #ifdef __USE_PROTOS static ArcPtr newGraphArc(void) #else static ArcPtr newGraphArc() #endif { ArcPtr p; p = (ArcPtr) calloc(1, sizeof(Arc)); if ( p==NULL ) {fprintf(stderr,"rexpr: out of memory\n"); exit(-1);} if ( freelist != NULL ) p->track = (ArcPtr) freelist; freelist = (NodePtr) p; return p; } #ifdef __USE_PROTOS static NodePtr newNode(void) #else static NodePtr newNode() #endif { NodePtr p; p = (NodePtr) calloc(1, sizeof(Node)); if ( p==NULL ) {fprintf(stderr,"rexpr: out of memory\n"); exit(-1);} if ( freelist != NULL ) p->track = freelist; freelist = p; return p; } #ifdef __USE_PROTOS static void ArcBetweenGraphNodes(NodePtr i,NodePtr j,int label) #else static void ArcBetweenGraphNodes(i, j, label) NodePtr i, j; int label; #endif { ArcPtr a; a = newGraphArc(); if ( i->arcs == NULL ) i->arctail = i->arcs = a; else {(i->arctail)->next = a; i->arctail = a;} a->label = label; a->target = j; } #ifdef __USE_PROTOS static Graph BuildNFA_atom(int label) #else static Graph BuildNFA_atom(label) int label; #endif { Graph g; g.left = newNode(); g.right = newNode(); ArcBetweenGraphNodes(g.left, g.right, label); return( g ); } #ifdef __USE_PROTOS static Graph BuildNFA_AB(Graph A,Graph B) #else static Graph BuildNFA_AB(A, B) Graph A, B; #endif { Graph g; ArcBetweenGraphNodes(A.right, B.left, Epsilon); g.left = A.left; g.right = B.right; return( g ); } #ifdef __USE_PROTOS static Graph BuildNFA_AorB(Graph A,Graph B) #else static Graph BuildNFA_AorB(A, B) Graph A, B; #endif { Graph g; g.left = newNode(); ArcBetweenGraphNodes(g.left, A.left, Epsilon); ArcBetweenGraphNodes(g.left, B.left, Epsilon); g.right = newNode(); ArcBetweenGraphNodes(A.right, g.right, Epsilon); ArcBetweenGraphNodes(B.right, g.right, Epsilon); return( g ); } #ifdef __USE_PROTOS static Graph BuildNFA_set(char *s) #else static Graph BuildNFA_set( s ) char *s; #endif { Graph g; if ( s == NULL ) return g; g.left = newNode(); g.right = newNode(); while ( *s != '\0' ) { ArcBetweenGraphNodes(g.left, g.right, *s++); } return g; } #ifdef __USE_PROTOS static Graph BuildNFA_Astar(Graph A) #else static Graph BuildNFA_Astar( A ) Graph A; #endif { Graph g; g.left = newNode(); g.right = newNode(); ArcBetweenGraphNodes(g.left, A.left, Epsilon); ArcBetweenGraphNodes(g.left, g.right, Epsilon); ArcBetweenGraphNodes(A.right, g.right, Epsilon); ArcBetweenGraphNodes(A.right, A.left, Epsilon); return( g ); } #ifdef __USE_PROTOS static Graph BuildNFA_Aplus(Graph A) #else static Graph BuildNFA_Aplus( A ) Graph A; #endif { ArcBetweenGraphNodes(A.right, A.left, Epsilon); return( A ); } #ifdef __USE_PROTOS static Graph BuildNFA_Aoptional(Graph A) #else static Graph BuildNFA_Aoptional( A ) Graph A; #endif { Graph g; g.left = newNode(); g.right = newNode(); ArcBetweenGraphNodes(g.left, A.left, Epsilon); ArcBetweenGraphNodes(g.left, g.right, Epsilon); ArcBetweenGraphNodes(A.right, g.right, Epsilon); return( g ); } cccc-3.1.4/pccts/support/rexpr/rexpr.h0000644000000000000000000000117507341735540016425 0ustar rootroot#define Atom 256 /* token Atom (an impossible char value) */ #define Epsilon 257 /* epsilon arc (an impossible char value) */ /* track field must be same for all node types */ typedef struct _a { struct _a *track; /* track mem allocation */ int label; struct _a *next; struct _n *target; } Arc, *ArcPtr; typedef struct _n { struct _n *track; ArcPtr arcs, arctail; } Node, *NodePtr; typedef struct { NodePtr left, right; } Graph, *GraphPtr; #ifdef __USE_PROTOS int rexpr( char *expr, char *s ); int match( NodePtr automaton, char *s ); #else int rexpr(); int match(); #endif cccc-3.1.4/pccts/support/rexpr/test.c0000644000000000000000000000063407341735540016236 0ustar rootroot#include #include "rexpr.h" /* * test for rexpr(). * To make this test: * cc -o rexpr test.c rexpr.c * Then from command line type: * rexpr r string * where r is the regular expression that decribes a language * and string is the string to verify. */ main(argc,argv) int argc; char *argv[]; { if ( argc!=3 ) fprintf(stderr,"rexpr: expr s\n"); else printf("%d\n", rexpr(argv[1], argv[2])); } cccc-3.1.4/pccts/support/set/0000755000000000000000000000000010357462414014541 5ustar rootrootcccc-3.1.4/pccts/support/set/set.c0000644000000000000000000003637307341735540015516 0ustar rootroot/* set.c The following is a general-purpose set library originally developed by Hank Dietz and enhanced by Terence Parr to allow dynamic sets. Sets are now structs containing the #words in the set and a pointer to the actual set words. Generally, sets need not be explicitly allocated. They are created/extended/shrunk when appropriate (e.g. in set_of()). HOWEVER, sets need to be destroyed (free()ed) when they go out of scope or are otherwise no longer needed. A routine is provided to free a set. Sets can be explicitly created with set_new(s, max_elem). Sets can be declared to have minimum size to reduce realloc traffic. Default minimum size = 1. Sets can be explicitly initialized to have no elements (set.n == 0) by using the 'empty' initializer: Examples: set a = empty; -- set_deg(a) == 0 return( empty ); Example set creation and destruction: set set_of2(e,g) unsigned e,g; { set a,b,c; b = set_of(e); -- Creates space for b and sticks in e set_new(c, g); -- set_new(); set_orel() ==> set_of() set_orel(g, &c); a = set_or(b, c); . . . set_free(b); set_free(c); return( a ); } 1987 by Hank Dietz Modified by: Terence Parr Purdue University October 1989 Made it smell less bad to C++ 7/31/93 -- TJP */ #include #include "pcctscfg.h" #ifdef __STDC__ #include #else #include #endif #include #include "set.h" #define MIN(i,j) ( (i) > (j) ? (j) : (i)) #define MAX(i,j) ( (i) < (j) ? (j) : (i)) /* elems can be a maximum of 32 bits */ static unsigned bitmask[] = { 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000, #if !defined(PC) || defined(PC32) 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000 #endif }; set empty = set_init; static unsigned min=1; #define StrSize 200 #ifdef MEMCHK #define CHK(a) \ if ( a.setword != NULL ) \ if ( !valid(a.setword) ) \ {fprintf(stderr, "%s(%d): invalid set\n",__FILE__,__LINE__); exit(-1);} #else #define CHK(a) #endif /* * Set the minimum size (in words) of a set to reduce realloc calls */ void #ifdef __USE_PROTOS set_size( unsigned n ) #else set_size( n ) unsigned n; #endif { min = n; } unsigned int #ifdef __USE_PROTOS set_deg( set a ) #else set_deg( a ) set a; #endif { /* Fast compute degree of a set... the number of elements present in the set. Assumes that all word bits are used in the set and that SETSIZE(a) is a multiple of WORDSIZE. */ register unsigned *p = &(a.setword[0]); register unsigned *endp = &(a.setword[a.n]); register unsigned degree = 0; CHK(a); if ( a.n == 0 ) return(0); while ( p < endp ) { register unsigned t = *p; register unsigned *b = &(bitmask[0]); do { if (t & *b) ++degree; } while (++b < &(bitmask[WORDSIZE])); p++; } return(degree); } set #ifdef __USE_PROTOS set_or( set b, set c ) #else set_or( b, c ) set b; set c; #endif { /* Fast set union operation */ /* resultant set size is max(b, c); */ set *big; set t; unsigned int m,n; register unsigned *r, *p, *q, *endp; CHK(b); CHK(c); t = empty; if (b.n > c.n) {big= &b; m=b.n; n=c.n;} else {big= &c; m=c.n; n=b.n;} set_ext(&t, m); r = t.setword; /* Or b,c until max of smaller set */ q = c.setword; p = b.setword; endp = &(b.setword[n]); while ( p < endp ) *r++ = *p++ | *q++; /* Copy rest of bigger set into result */ p = &(big->setword[n]); endp = &(big->setword[m]); while ( p < endp ) *r++ = *p++; return(t); } set #ifdef __USE_PROTOS set_and( set b, set c ) #else set_and( b, c ) set b; set c; #endif { /* Fast set intersection operation */ /* resultant set size is min(b, c); */ set t; unsigned int n; register unsigned *r, *p, *q, *endp; CHK(b); CHK(c); t = empty; n = (b.n > c.n) ? c.n : b.n; if ( n == 0 ) return t; /* TJP 4-27-92 fixed for empty set */ set_ext(&t, n); r = t.setword; /* & b,c until max of smaller set */ q = c.setword; p = b.setword; endp = &(b.setword[n]); while ( p < endp ) *r++ = *p++ & *q++; return(t); } set #ifdef __USE_PROTOS set_dif( set b, set c ) #else set_dif( b, c ) set b; set c; #endif { /* Fast set difference operation b - c */ /* resultant set size is size(b) */ set t; unsigned int n; register unsigned *r, *p, *q, *endp; CHK(b); CHK(c); t = empty; n = (b.n <= c.n) ? b.n : c.n ; if ( b.n == 0 ) return t; /* TJP 4-27-92 fixed for empty set */ /* WEC 12-1-92 fixed for c.n = 0 */ set_ext(&t, b.n); r = t.setword; /* Dif b,c until smaller set size */ q = c.setword; p = b.setword; endp = &(b.setword[n]); while ( p < endp ) *r++ = *p++ & (~ *q++); /* Copy rest of b into result if size(b) > c */ if ( b.n > n ) { p = &(b.setword[n]); endp = &(b.setword[b.n]); while ( p < endp ) *r++ = *p++; } return(t); } set #ifdef __USE_PROTOS set_of( unsigned b ) #else set_of( b ) unsigned b; #endif { /* Fast singleton set constructor operation */ static set a; if ( b == nil ) return( empty ); set_new(a, b); a.setword[DIVWORD(b)] = bitmask[MODWORD(b)]; return(a); } /* * Extend (or shrink) the set passed in to have n words. * * if n is smaller than the minimum, boost n to have the minimum. * if the new set size is the same as the old one, do nothing. * * TJP 4-27-92 Fixed so won't try to alloc 0 bytes */ void #ifdef __USE_PROTOS set_ext( set *a, unsigned int n ) #else set_ext( a, n ) set *a; unsigned int n; #endif { register unsigned *p; register unsigned *endp; unsigned int size; CHK((*a)); if ( a->n == 0 ) { if ( n == 0 ) return; if (a->setword != NULL) { free (a->setword); /* MR20 */ } a->setword = (unsigned *) calloc(n, BytesPerWord); if ( a->setword == NULL ) { fprintf(stderr, "set_ext(%d words): cannot allocate set\n", n); exit(-1); } a->n = n; return; } if ( n < min ) n = min; if ( a->n == n || n == 0 ) return; size = a->n; a->n = n; a->setword = (unsigned *) realloc( (char *)a->setword, (n*BytesPerWord) ); if ( a->setword == NULL ) { fprintf(stderr, "set_ext(%d words): cannot allocate set\n", n); exit(-1); } p = &(a->setword[size]); /* clear from old size to new size */ endp = &(a->setword[a->n]); do { *p++ = 0; } while ( p < endp ); } set #ifdef __USE_PROTOS set_not( set a ) #else set_not( a ) set a; #endif { /* Fast not of set a (assumes all bits used) */ /* size of resultant set is size(a) */ /* ~empty = empty cause we don't know how bit to make set */ set t; register unsigned *r; register unsigned *p = a.setword; register unsigned *endp = &(a.setword[a.n]); CHK(a); t = empty; if ( a.n == 0 ) return( empty ); set_ext(&t, a.n); r = t.setword; do { *r++ = (~ *p++); } while ( p < endp ); return(t); } int #ifdef __USE_PROTOS set_equ( set a, set b ) #else set_equ( a, b ) set a; set b; #endif { /* 8-Nov-97 Make it work with sets of different sizes */ /* Easy to understand, too. Probably faster. */ /* Check for a equal to b */ unsigned int count; /* MR11 */ unsigned int i; /* MR11 */ CHK(a); CHK(b); count=MIN(a.n,b.n); if (count == 0) return 1; for (i=0; i < count; i++) { if (a.setword[i] != b.setword[i]) return 0; }; if (a.n < b.n) { for (i=count; i < b.n; i++) { if (b.setword[i] != 0) return 0; } return 1; } else if (a.n > b.n) { for (i=count; i < a.n; i++) { if (a.setword[i] != 0) return 0; } return 1; } else { return 1; }; } int #ifdef __USE_PROTOS set_sub( set a, set b ) #else set_sub( a, b ) set a; set b; #endif { /* 8-Nov-97 Make it work with sets of different sizes */ /* Easy to understand, too. Probably faster. */ /* Check for a is a PROPER subset of b */ unsigned int count; unsigned int i; CHK(a); CHK(b); if (a.n == 0) return 1; count=MIN(a.n,b.n); for (i=0; i < count; i++) { if (a.setword[i] & ~b.setword[i]) return 0; }; if (a.n <= b.n) { return 1; } else { for (i=count; i a.n ) return(0); /* Otherwise, we have to check */ return( a.setword[DIVWORD(b)] & bitmask[MODWORD(b)] ); } int #ifdef __USE_PROTOS set_nil( set a ) #else set_nil( a ) set a; #endif { /* Fast check for nil set */ register unsigned *p = a.setword; register unsigned *endp; CHK(a); if ( a.n == 0 ) return(1); endp = &(a.setword[a.n]); /* The set is not empty if any word used to store the set is non-zero. This means one must be a bit careful about doing things like negation. */ do { if (*p) return(0); } while (++p < endp); return(1); } char * #ifdef __USE_PROTOS set_str( set a ) #else set_str( a ) set a; #endif { /* Fast convert set a into ASCII char string... assumes that all word bits are used in the set and that SETSIZE is a multiple of WORDSIZE. Trailing 0 bits are removed from the string. if no bits are on or set is empty, "" is returned. */ register unsigned *p = a.setword; register unsigned *endp = &(a.setword[a.n]); static char str_tmp[StrSize+1]; register char *q = &(str_tmp[0]); CHK(a); if ( a.n==0 ) {*q=0; return( &(str_tmp[0]) );} do { register unsigned t = *p; register unsigned *b = &(bitmask[0]); do { *(q++) = (char) ((t & *b) ? '1' : '0'); } while (++b < &(bitmask[WORDSIZE])); } while (++p < endp); /* Trim trailing 0s & NULL terminate the string */ while ((q > &(str_tmp[0])) && (*(q-1) != '1')) --q; *q = 0; return(&(str_tmp[0])); } set #ifdef __USE_PROTOS set_val( register char *s ) #else set_val( s ) register char *s; #endif { /* Fast convert set ASCII char string into a set. If the string ends early, the remaining set bits are all made zero. The resulting set size is just big enough to hold all elements. */ static set a; register unsigned *p, *endp; set_new(a, strlen(s)); p = a.setword; endp = &(a.setword[a.n]); do { register unsigned *b = &(bitmask[0]); /* Start with a word with no bits on */ *p = 0; do { if (*s) { if (*s == '1') { /* Turn-on this bit */ *p |= *b; } ++s; } } while (++b < &(bitmask[WORDSIZE])); } while (++p < endp); return(a); } /* * Or element e into set a. a can be empty. */ void #ifdef __USE_PROTOS set_orel( unsigned e, set *a ) #else set_orel( e, a ) unsigned e; set *a; #endif { CHK((*a)); if ( e == nil ) return; if ( NumWords(e) > a->n ) set_ext(a, NumWords(e)); a->setword[DIVWORD(e)] |= bitmask[MODWORD(e)]; } /* * Or set b into set a. a can be empty. does nothing if b empty. */ void #ifdef __USE_PROTOS set_orin( set *a, set b ) #else set_orin( a, b ) set *a; set b; #endif { /* Fast set union operation */ /* size(a) is max(a, b); */ unsigned int m; register unsigned *p, *q = b.setword, *endq; /* MR20 */ CHK((*a)); CHK(b); if ( b.n == 0 ) return; endq = &(b.setword[b.n]); /* MR20 */ m = (a->n > b.n) ? a->n : b.n; set_ext(a, m); p = a->setword; do { *p++ |= *q++; } while ( q < endq ); } /* * And set b into set a. a can be empty. does nothing if b empty. */ void #ifdef __USE_PROTOS set_andin( set *a, set b ) #else set_andin( a, b ) set *a; set b; #endif { /* Fast set intersection operation */ /* size(a) is max(a, b); */ unsigned int m; register unsigned *p, *q = b.setword, *endq = &(b.setword[b.n]); CHK((*a)); CHK(b); if ( b.n == 0 ) return; m = (a->n > b.n) ? a->n : b.n; set_ext(a, m); p = a->setword; do { *p++ &= *q++; } while ( q < endq ); } void #ifdef __USE_PROTOS set_rm( unsigned e, set a ) #else set_rm( e, a ) unsigned e; set a; #endif { /* Does not effect size of set */ CHK(a); if ( (e == nil) || (NumWords(e) > a.n) ) return; a.setword[DIVWORD(e)] ^= (a.setword[DIVWORD(e)]&bitmask[MODWORD(e)]); } void #ifdef __USE_PROTOS set_clr( set a ) #else set_clr( a ) set a; #endif { /* Does not effect size of set */ register unsigned *p = a.setword; register unsigned *endp; CHK(a); if ( a.n == 0 ) return; endp = &(a.setword[a.n]); do { *p++ = 0; } while ( p < endp ); } set #ifdef __USE_PROTOS set_dup( set a ) #else set_dup( a ) set a; #endif { set b; register unsigned *p, *q = a.setword, *endq; /* MR20 */ CHK(a); b = empty; if ( a.n == 0 ) return( empty ); endq = &(a.setword[a.n]); /* MR20 */ set_ext(&b, a.n); p = b.setword; do { *p++ = *q++; } while ( q < endq ); return(b); } /* * Return a nil terminated list of unsigned ints that represents all * "on" bits in the bit set. * * e.g. {011011} --> {1, 2, 4, 5, nil} * * _set_pdq and set_pdq are useful when an operation is required on each element * of a set. Normally, the sequence is: * * while ( set_deg(a) > 0 ) { * e = set_int(a); * set_rm(e, a); * ...process e... * } * Now, * * t = e = set_pdq(a); * while ( *e != nil ) { * ...process *e... * e++; * } * free( t ); * * We have saved many set calls and have not destroyed set a. */ void #ifdef __USE_PROTOS _set_pdq( set a, register unsigned *q ) #else _set_pdq( a, q ) set a; register unsigned *q; #endif { register unsigned *p = a.setword, *endp = &(a.setword[a.n]); register unsigned e=0; CHK(a); /* are there any space (possibility of elements)? */ if ( a.n == 0 ) return; do { register unsigned t = *p; register unsigned *b = &(bitmask[0]); do { if ( t & *b ) *q++ = e; ++e; } while (++b < &(bitmask[WORDSIZE])); } while (++p < endp); *q = nil; } /* * Same as _set_pdq except allocate memory. set_pdq is the natural function * to use. */ unsigned * #ifdef __USE_PROTOS set_pdq( set a ) #else set_pdq( a ) set a; #endif { unsigned *q; int max_deg; CHK(a); max_deg = WORDSIZE*a.n; /* assume a.n!=0 & no elements is rare, but still ok */ if ( a.n == 0 ) return(NULL); q = (unsigned *) malloc((max_deg+1)*BytesPerWord); if ( q == NULL ) return( NULL ); _set_pdq(a, q); return( q ); } /* a function that produces a hash number for the set */ unsigned int #ifdef __USE_PROTOS set_hash( set a, register unsigned int mod ) #else set_hash( a, mod ) set a; register unsigned int mod; #endif { /* Fast hash of set a (assumes all bits used) */ register unsigned *p = &(a.setword[0]); register unsigned *endp = &(a.setword[a.n]); register unsigned i = 0; CHK(a); while (p> LogWordSize) /* x / WORDSIZE */ #define nil (~((unsigned) 0)) /* An impossible set member all bits on (big!) */ typedef struct _set { unsigned int n; /* Number of words in set */ unsigned *setword; } set; #define set_init {0, NULL} #define set_null(a) ((a).setword==NULL) #define NumBytes(x) (((x)>>3)+1) /* Num bytes to hold x */ #define NumWords(x) ((((unsigned)(x))>>LogWordSize)+1) /* Num words to hold x */ /* M a c r o s */ /* make arg1 a set big enough to hold max elem # of arg2 */ #define set_new(a,_max) \ if (((a).setword=(unsigned *)calloc(NumWords(_max),BytesPerWord))==NULL) \ fprintf(stderr, "set_new: Cannot allocate set with max of %d\n", _max); \ (a).n = NumWords(_max); #define set_free(a) \ {if ( (a).setword != NULL ) free((char *)((a).setword)); \ (a) = empty;} #ifdef __USE_PROTOS extern void set_size( unsigned ); extern unsigned int set_deg( set ); extern set set_or( set, set ); extern set set_and( set, set ); extern set set_dif( set, set ); extern set set_of( unsigned ); extern void set_ext( set *, unsigned int ); extern set set_not( set ); extern int set_equ( set, set ); extern int set_sub( set, set ); extern unsigned set_int( set ); extern int set_el( unsigned, set ); extern int set_nil( set ); extern char * set_str( set ); extern set set_val( register char * ); extern void set_orel( unsigned, set * ); extern void set_orin( set *, set ); extern void set_andin( set *, set ); extern void set_rm( unsigned, set ); extern void set_clr( set ); extern set set_dup( set ); extern void set_PDQ( set, register unsigned * ); extern unsigned *set_pdq( set ); extern void _set_pdq( set a, register unsigned *q ); extern unsigned int set_hash( set, register unsigned int ); #else extern void set_size(); extern unsigned int set_deg(); extern set set_or(); extern set set_and(); extern set set_dif(); extern set set_of(); extern void set_ext(); extern set set_not(); extern int set_equ(); extern int set_sub(); extern unsigned set_int(); extern int set_el(); extern int set_nil(); extern char * set_str(); extern set set_val(); extern void set_orel(); extern void set_orin(); extern void set_andin(); extern void set_rm(); extern void set_clr(); extern set set_dup(); extern void set_PDQ(); extern unsigned *set_pdq(); extern void _set_pdq(); extern unsigned int set_hash(); #endif extern set empty; #endif cccc-3.1.4/pccts/support/sym/0000755000000000000000000000000010357462415014557 5ustar rootrootcccc-3.1.4/pccts/support/sym/template.h0000644000000000000000000000155107341735540016546 0ustar rootroot/* T e m p l a t e F o r S y m b o l T a b l e M a n a g e r */ /* define some hash function */ #ifndef HASH #define HASH(p, h) while ( *p != '\0' ) h = (h<<1) + *p++; #endif /* minimum symbol table record */ typedef struct _sym { char *symbol; struct _sym *next, *prev, **head, *scope; unsigned int hash; } Sym, *SymPtr; #ifdef __USE_PROTOS void zzs_init(int, int); void zzs_done(void); void zzs_add(char *, Sym *); Sym *zzs_get(char *); void zzs_del(Sym *); void zzs_keydel(char *); Sym **zzs_scope(Sym **); Sym *zzs_rmscope(Sym **); void zzs_stat(void); Sym *zzs_new(char *); Sym *zzs_newadd(char *); char *zzs_strdup(char *); #else void zzs_init(); void zzs_done(); void zzs_add(); Sym *zzs_get(); void zzs_del(); void zzs_keydel(); Sym **zzs_scope(); Sym *zzs_rmscope(); void zzs_stat(); Sym *zzs_new(); Sym *zzs_newadd(); char *zzs_strdup(); #endif cccc-3.1.4/pccts/support/sym/sym.c0000644000000000000000000002303007341735540015532 0ustar rootroot/* * Simple symbol table manager using coalesced chaining to resolve collisions * * Doubly-linked lists are used for fast removal of entries. * * 'sym.h' must have a definition for typedef "Sym". Sym must include at * minimum the following fields: * * ... * char *symbol; * struct ... *next, *prev, **head, *scope; * unsigned int hash; * ... * * 'template.h' can be used as a template to create a 'sym.h'. * * 'head' is &(table[hash(itself)]). * The hash table is not resizable at run-time. * The scope field is used to link all symbols of a current scope together. * Scope() sets the current scope (linked list) to add symbols to. * Any number of scopes can be handled. The user passes the address of * a pointer to a symbol table * entry (INITIALIZED TO NULL first time). * * Available Functions: * * zzs_init(s1,s2) -- Create hash table with size s1, string table size s2. * zzs_done() -- Free hash and string table created with zzs_init(). * zzs_add(key,rec)-- Add 'rec' with key 'key' to the symbol table. * zzs_newadd(key) -- create entry; add using 'key' to the symbol table. * zzs_get(key) -- Return pointer to last record entered under 'key' * Else return NULL * zzs_del(p) -- Unlink the entry associated with p. This does * NOT free 'p' and DOES NOT remove it from a scope * list. If it was a part of your intermediate code * tree or another structure. It will still be there. * It is only removed from further consideration * by the symbol table. * zzs_keydel(s) -- Unlink the entry associated with key s. * Calls zzs_del(p) to unlink. * zzs_scope(sc) -- Specifies that everything added to the symbol * table with zzs_add() is added to the list (scope) * 'sc'. 'sc' is of 'Sym **sc' type and must be * initialized to NULL before trying to add anything * to it (passing it to zzs_scope()). Scopes can be * switched at any time and merely links a set of * symbol table entries. If a NULL pointer is * passed, the current scope is returned. * zzs_rmscope(sc) -- Remove (zzs_del()) all elements of scope 'sc' * from the symbol table. The entries are NOT * free()'d. A pointer to the first * element in the "scope" is returned. The user * can then manipulate the list as he/she chooses * (such as freeing them all). NOTE that this * function sets your scope pointer to NULL, * but returns a pointer to the list for you to use. * zzs_stat() -- Print out the symbol table and some relevant stats. * zzs_new(key) -- Create a new record with calloc() of type Sym. * Add 'key' to the string table and make the new * records 'symbol' pointer point to it. * zzs_strdup(s) -- Add s to the string table and return a pointer * to it. Very fast allocation routine * and does not require strlen() nor calloc(). * * Example: * * #include * #include "sym.h" * * main() * { * Sym *scope1=NULL, *scope2=NULL, *a, *p; * * zzs_init(101, 100); * * a = zzs_new("Apple"); zzs_add(a->symbol, a); -- No scope * zzs_scope( &scope1 ); -- enter scope 1 * a = zzs_new("Plum"); zzs_add(a->symbol, a); * zzs_scope( &scope2 ); -- enter scope 2 * a = zzs_new("Truck"); zzs_add(a->symbol, a); * * p = zzs_get("Plum"); * if ( p == NULL ) fprintf(stderr, "Hmmm...Can't find 'Plum'\n"); * * p = zzs_rmscope(&scope1) * for (; p!=NULL; p=p->scope) {printf("Scope1: %s\n", p->symbol);} * p = zzs_rmscope(&scope2) * for (; p!=NULL; p=p->scope) {printf("Scope2: %s\n", p->symbol);} * } * * Terence Parr * Purdue University * February 1990 * * CHANGES * * Terence Parr * May 1991 * Renamed functions to be consistent with ANTLR * Made HASH macro * Added zzs_keydel() * Added zzs_newadd() * Fixed up zzs_stat() * * July 1991 * Made symbol table entry save its hash code for fast comparison * during searching etc... */ #include #if defined(__STDC__) || defined(__USE_PROTOS) #include #include #else #include #endif #include "sym.h" #define StrSame 0 static Sym **CurScope = NULL; static unsigned size = 0; static Sym **table=NULL; static char *strings; static char *strp; static int strsize = 0; #ifdef __USE_PROTOS void zzs_init(int sz,int strs) #else void zzs_init(sz, strs) int sz, strs; #endif { if ( sz <= 0 || strs <= 0 ) return; table = (Sym **) calloc(sz, sizeof(Sym *)); if ( table == NULL ) { fprintf(stderr, "Cannot allocate table of size %d\n", sz); exit(1); } strings = (char *) calloc(strs, sizeof(char)); if ( strings == NULL ) { fprintf(stderr, "Cannot allocate string table of size %d\n", strs); exit(1); } size = sz; strsize = strs; strp = strings; } #ifdef __USE_PROTOS void zzs_done(void) #else void zzs_done() #endif { if ( table != NULL ) free( table ); if ( strings != NULL ) free( strings ); } #ifdef __USE_PROTOS void zzs_add(char *key,Sym rec) #else void zzs_add(key, rec) char *key; register Sym *rec; #endif { register unsigned int h=0; register char *p=key; HASH(p, h); rec->hash = h; /* save hash code for fast comp later */ h %= size; if ( CurScope != NULL ) {rec->scope = *CurScope; *CurScope = rec;} rec->next = table[h]; /* Add to doubly-linked list */ rec->prev = NULL; if ( rec->next != NULL ) (rec->next)->prev = rec; table[h] = rec; rec->head = &(table[h]); } #ifdef __USE_PROTOS Sym * zzs_get(char *key) #else Sym * zzs_get(key) char *key; #endif { register unsigned int h=0; register char *p=key; register Sym *q; HASH(p, h); for (q = table[h%size]; q != NULL; q = q->next) { if ( q->hash == h ) /* do we even have a chance of matching? */ if ( strcmp(key, q->symbol) == StrSame ) return( q ); } return( NULL ); } /* * Unlink p from the symbol table. Hopefully, it's actually in the * symbol table. * * If p is not part of a bucket chain of the symbol table, bad things * will happen. * * Will do nothing if all list pointers are NULL */ #ifdef __USE_PROTOS void zzs_del(Sym *p) #else void zzs_del(p) register Sym *p; #endif { if ( p == NULL ) {fprintf(stderr, "zzs_del(NULL)\n"); exit(1);} if ( p->prev == NULL ) /* Head of list */ { register Sym **t = p->head; if ( t == NULL ) return; /* not part of symbol table */ (*t) = p->next; if ( (*t) != NULL ) (*t)->prev = NULL; } else { (p->prev)->next = p->next; if ( p->next != NULL ) (p->next)->prev = p->prev; } p->next = p->prev = NULL; /* not part of symbol table anymore */ p->head = NULL; } #ifdef __USE_PROTOS void zzs_keydel(char *key) #else void zzs_keydel(key) char *key; #endif { Sym *p = zzs_get(key); if ( p != NULL ) zzs_del( p ); } /* S c o p e S t u f f */ /* Set current scope to 'scope'; return current scope if 'scope' == NULL */ #ifdef __USE_PROTOS Sym ** zzs_scope(Sym **scope) #else Sym ** zzs_scope(scope) Sym **scope; #endif { if ( scope == NULL ) return( CurScope ); CurScope = scope; return( scope ); } /* Remove a scope described by 'scope'. Return pointer to 1st element in scope */ #ifdef __USE_PROTOS Sym * zzs_rmscope(Sym **scope) #else Sym * zzs_rmscope(scope) register Sym **scope; #endif { register Sym *p; Sym *start; if ( scope == NULL ) return(NULL); start = p = *scope; for (; p != NULL; p=p->scope) { zzs_del( p ); } *scope = NULL; return( start ); } #ifdef __USE_PROTOS void zzs_stat(void) #else void zzs_stat() #endif { static unsigned short count[20]; unsigned int i,n=0,low=0, hi=0; register Sym **p; float avg=0.0; for (i=0; i<20; i++) count[i] = 0; for (p=table; p<&(table[size]); p++) { register Sym *q = *p; unsigned int len; if ( q != NULL && low==0 ) low = p-table; len = 0; if ( q != NULL ) printf("[%d]", p-table); while ( q != NULL ) { len++; n++; printf(" %s", q->symbol); q = q->next; if ( q == NULL ) printf("\n"); } if ( len>=20 ) printf("zzs_stat: count table too small\n"); else count[len]++; if ( *p != NULL ) hi = p-table; } printf("Storing %d recs used %d hash positions out of %d\n", n, size-count[0], size); printf("%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; printf("Buckets of len %d == %d (%f %% of recs)\n", i, count[i], 100.0*((float)(i*count[i]))/((float)n)); } } printf("Avg bucket length %f\n", avg); printf("Range of hash function: %d..%d\n", low, hi); } /* * Given a string, this function allocates and returns a pointer to a * symbol table record whose "symbol" pointer is reset to a position * in the string table. */ #ifdef __USE_PROTOS Sym * zzs_new(char *text) #else Sym * zzs_new(text) char *text; #endif { Sym *p; if ( (p = (Sym *) calloc(1,sizeof(Sym))) == 0 ) { fprintf(stderr,"Out of memory\n"); exit(1); } p->symbol = zzs_strdup(text); return p; } /* create a new symbol table entry and add it to the symbol table */ #ifdef __USE_PROTOS Sym * zzs_newadd(char *text) #else Sym * zzs_newadd(text) char *text; #endif { Sym *p = zzs_new(text); if ( p != NULL ) zzs_add(text, p); return p; } /* Add a string to the string table and return a pointer to it. * Bump the pointer into the string table to next avail position. */ #ifdef __USE_PROTOS char * zzs_strdup(char *s) #else char * zzs_strdup(s) register char *s; #endif { register char *start=strp; while ( *s != '\0' ) { if ( strp >= &(strings[strsize-2]) ) { fprintf(stderr, "sym: string table overflow (%d chars)\n", strsize); exit(-1); } *strp++ = *s++; } *strp++ = '\0'; return( start ); } cccc-3.1.4/test/0000755000000000000000000000000010357462453012100 5ustar rootrootcccc-3.1.4/test/diff.bat0000755000000000000000000000131710171515300013465 0ustar rootroot@echo off rem DIFF.BAT rem This script should simulate the behaviour of Unix diff. rem As it stands it simply uses the FC.EXE command which rem is part of DOS. This does not give a useful return rem value, so the script must check the output using the rem for /f "usebackq" structure. if not "%2" == "" goto AfterUsage :usage echo DIFF [file1] [file2] goto :end :afterUsage set DIFFLEN= set CMD=fc %1 %2 set DIFF_STATUS=0 for /f "usebackq" %%l in ( `%CMD%` ) do ( if "%%l"=="Comparing" ( rem This is expected ) else if "%%l"=="FC:" ( rem This is also expected ) else ( rem If anything else comes out, the comparison found a difference set DIFF_STATUS=1 ) ) exit /b %DIFF_STATUS% cccc-3.1.4/test/posix.mak0000644000000000000000000000042507345717727013747 0ustar rootroot# Makefile to control testing of CCCC on POSIX platforms # Define the variables used by the platform-independent rules. CP=cp RMDIR=rm -rf MV=mv ECHO=echo DIFF=diff PATHSEP=/ CCCC=../cccc/cccc # include the file containing the platform independent rules. include rules.mak cccc-3.1.4/test/prn1.cc0000644000000000000000000000022207265351225013261 0ustar rootroot/* static */ int yadda(STATIC* new_static, ssim_func_port_handle func_port) { #if !KC_USE_STATICS_VECTOR return X; #else return Y; #endif } cccc-3.1.4/test/prn1.dbref0000644000000000000000000000150507724312663013766 0ustar rootrootCCCC_Module@anonymous@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@anonymous@yadda@@(STATIC *,ssim_func_port_handle)@ CCCC_MemExt@anonymous@yadda@@(STATIC *,ssim_func_port_handle)@prn1.cc@1@definition@F????@LOC:5 COM:1 MVG:2@?@d@ CCCC_RejExt@prn1.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn1.htmlref0000644000000000000000000002717307724312663014356 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 5 5.000
    McCabe's Cyclomatic NumberMVG 2 2.000
    Lines of CommentCOM 1 1.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    anonymous 5 2 1------------

    Procedural Metrics Detail

    anonymous

    LOCMVGCOML_CM_C
    yadda(  STATIC *,  ssim_func_port_handle )
    definition   prn1.cc:1

    5 2 1------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    anonymous 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    anonymous 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    anonymous    

    Other Extents

    LocationTextLOCCOMMVG
    prn1.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn1.xmlref0000644000000000000000000000567307724312663014213 0ustar rootroot anonymous anonymous yadda(STATIC *,ssim_func_port_handle) definition anonymous anonymous anonymous <file scope items> cccc-3.1.4/test/prn10.cc0000644000000000000000000000054307401205042013332 0ustar rootroot// prn10.cc // SourceForge bugtracker item 233584 // submitted by Victor B Putz // Tests handling of data members and globals specified as // 'const static' and 'static const' as both are accepted by GCC. const static char csNonMember; static const char scNonMember; class A { const static char csMember; static const char scMember; }; cccc-3.1.4/test/prn10.dbref0000644000000000000000000000133407724312663014046 0ustar rootrootCCCC_Module@A@class@ CCCC_ModExt@A@class@prn10.cc@10@definition@?T??2@LOC:5 COM:0 MVG:0@2@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_RejExt@prn10.cc@1@@?T??2@LOC:2 COM:5 MVG:0@2@r@ cccc-3.1.4/test/prn10.htmlref0000644000000000000000000002666707724312663014445 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 7 7.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 5 5.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 2 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    A 5 0 0------------

    Procedural Metrics Detail

    A
    definition   prn10.cc:10

    LOCMVGCOML_CM_C
    No member functions have been identified for this module

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    A 0 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    A 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    A    

    Other Extents

    LocationTextLOCCOMMVG
    prn10.cc:1
    <file scope items> 2 5 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn10.xmlref0000644000000000000000000000505307724312663014263 0ustar rootroot A A definition A A A <file scope items> cccc-3.1.4/test/prn11.cc0000644000000000000000000000044507401205042013334 0ustar rootroot// prn11.cc // SourceForge bug tracker item 233585 // Submitted by Victor B Putz // Tests parsing of namespace declarations // I am not confident that the present counting rules applying // to this construct are optimal yet. namespace A { void b( void ); }; void A::b( void ) { } cccc-3.1.4/test/prn11.dbref0000644000000000000000000000160207724312663014045 0ustar rootrootCCCC_Module@A@@ CCCC_Module@anonymous@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@A@b@@(void)@ CCCC_MemExt@A@b@@(void)@prn11.cc@13@definition@F????@LOC:3 COM:0 MVG:0@?@d@ CCCC_Member@anonymous@b@@(void)@ CCCC_MemExt@anonymous@b@@(void)@prn11.cc@10@declaration@F????@LOC:1 COM:0 MVG:0@?@D@ CCCC_RejExt@prn11.cc@1@@F????@LOC:3 COM:6 MVG:0@?@r@ cccc-3.1.4/test/prn11.htmlref0000644000000000000000000003171307715623450014431 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 2 
    Lines of CodeLOC 7 3.500
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 6 3.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 3 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    A 3 0 0------------
    anonymous 1 0 0------------

    Procedural Metrics Detail

    A

    LOCMVGCOML_CM_C
    b(  void )
    definition   prn11.cc:13

    3 0 0------------
    anonymous

    LOCMVGCOML_CM_C
    b(  void )
    declaration   prn11.cc:10

    1 0 0------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    A 1 0 0 0 0
    anonymous 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    A 0 0 0 0 0 0 0 0 0
    anonymous 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    A    
    anonymous    

    Other Extents

    LocationTextLOCCOMMVG
    prn11.cc:1
    <file scope items> 3 6 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn11.xmlref0000644000000000000000000001064207715610506014261 0ustar rootroot A anonymous A b(void) definition anonymous b(void) declaration A anonymous A anonymous A anonymous <file scope items> cccc-3.1.4/test/prn12.cc0000644000000000000000000000031107401205042013325 0ustar rootroot// prn12.cc // SourceForge bug tracker item 233587 // Submitted by Victor B Putz // Tests parsing of negative numbers as initializers. class C { int a; C( void ) : e( -1 ) {}; }; cccc-3.1.4/test/prn12.dbref0000644000000000000000000000147707401205042014040 0ustar rootrootCCCC_Module@C@class@ CCCC_ModExt@C@class@prn12.cc@6@definition@F???2@LOC:5 COM:4 MVG:0@2@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@C@C@@(void)@ CCCC_MemExt@C@C@@(void)@prn12.cc@9@definition@F???2@LOC:1 COM:0 MVG:0@2@d@ CCCC_RejExt@prn12.cc@1@@F???2@LOC:0 COM:0 MVG:0@2@r@ cccc-3.1.4/test/prn12.htmlref0000644000000000000000000002717007715623450014434 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 6 6.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 4 4.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    C 6 0 4------------

    Procedural Metrics Detail

    C
    definition   prn12.cc:6

    LOCMVGCOML_CM_C
    C(  void )
    definition   prn12.cc:9

    1 0 0------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    C 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    C 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    C    

    Other Extents

    LocationTextLOCCOMMVG
    prn12.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn12.xmlref0000644000000000000000000000573607715610506014272 0ustar rootroot C C definition C(void) definition C C C <file scope items> cccc-3.1.4/test/prn13.dbref0000644000000000000000000001606407724312663014057 0ustar rootrootCCCC_Module@AnimatingControlsSurface@@ CCCC_Module@BasicStroke@@ CCCC_Module@BufferedImage@@ CCCC_Module@ChangeEvent@@ CCCC_Module@ChangeListener@@ CCCC_Module@Component@@ CCCC_Module@CustomControls@@ CCCC_Module@DemoControls@class@ CCCC_ModExt@DemoControls@class@prn13.java@350@definition@?????@LOC:5 COM:1 MVG:0@?@d@ CCCC_Module@Dimension@@ CCCC_Module@FadeAnim@class@ CCCC_ModExt@FadeAnim@class@prn13.java@54@definition@?????@LOC:36 COM:4 MVG:0@?@d@ CCCC_Module@Font@@ CCCC_Module@Graphics2D@@ CCCC_Module@JSlider@@ CCCC_Module@Object@@ CCCC_Module@ObjectData@class@ CCCC_ModExt@ObjectData@class@prn13.java@257@definition@?????@LOC:11 COM:0 MVG:0@?@d@ CCCC_Module@Paint@@ CCCC_Module@String@@ CCCC_Module@TextData@class@ CCCC_ModExt@TextData@class@prn13.java@241@definition@?????@LOC:5 COM:0 MVG:0@?@d@ CCCC_Module@TexturePaint@@ CCCC_Module@Vector@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@DemoControls@DemoControls@@(FadeAnim)@ CCCC_MemExt@DemoControls@DemoControls@@(FadeAnim)@prn13.java@356@definition@????0@LOC:39 COM:0 MVG:0@?@d@ CCCC_Member@DemoControls@getPreferredSize@Dimension@()@ CCCC_MemExt@DemoControls@getPreferredSize@Dimension@()@prn13.java@422@definition@????0@LOC:3 COM:0 MVG:0@?@d@ CCCC_Member@DemoControls@run@void@()@ CCCC_MemExt@DemoControls@run@void@()@prn13.java@427@definition@????0@LOC:8 COM:0 MVG:0@?@d@ CCCC_Member@DemoControls@stateChanged@void@(ChangeEvent)@ CCCC_MemExt@DemoControls@stateChanged@void@(ChangeEvent)@prn13.java@401@definition@????0@LOC:19 COM:0 MVG:4@?@d@ CCCC_Member@FadeAnim@FadeAnim@@()@ CCCC_MemExt@FadeAnim@FadeAnim@@()@prn13.java@92@definition@????0@LOC:8 COM:0 MVG:0@?@d@ CCCC_Member@FadeAnim@main@void@(String[])@ CCCC_MemExt@FadeAnim@main@void@(String[])@prn13.java@236@definition@????0@LOC:3 COM:0 MVG:0@?@d@ CCCC_Member@FadeAnim@render@void@(int,int,Graphics2D)@ CCCC_MemExt@FadeAnim@render@void@(int,int,Graphics2D)@prn13.java@209@definition@????0@LOC:24 COM:0 MVG:6@?@d@ CCCC_Member@FadeAnim@reset@void@(int,int)@ CCCC_MemExt@FadeAnim@reset@void@(int,int)@prn13.java@195@definition@????0@LOC:5 COM:0 MVG:1@?@d@ CCCC_Member@FadeAnim@setImages@void@(int)@ CCCC_MemExt@FadeAnim@setImages@void@(int)@prn13.java@102@definition@????0@LOC:29 COM:0 MVG:5@?@d@ CCCC_Member@FadeAnim@setShapes@void@(int)@ CCCC_MemExt@FadeAnim@setShapes@void@(int)@prn13.java@161@definition@????0@LOC:31 COM:0 MVG:19@?@d@ CCCC_Member@FadeAnim@setStrings@void@(int)@ CCCC_MemExt@FadeAnim@setStrings@void@(int)@prn13.java@134@definition@????0@LOC:24 COM:0 MVG:4@?@d@ CCCC_Member@FadeAnim@step@void@(int,int)@ CCCC_MemExt@FadeAnim@step@void@(int,int)@prn13.java@202@definition@????0@LOC:5 COM:0 MVG:1@?@d@ CCCC_Member@ObjectData@ObjectData@@(Object,Paint)@ CCCC_MemExt@ObjectData@ObjectData@@(Object,Paint)@prn13.java@268@definition@????0@LOC:11 COM:0 MVG:2@?@d@ CCCC_Member@ObjectData@getRandomXY@void@(int,int)@ CCCC_MemExt@ObjectData@getRandomXY@void@(int,int)@prn13.java@281@definition@????2@LOC:14 COM:0 MVG:4@?@d@ CCCC_Member@ObjectData@reset@void@(int,int)@ CCCC_MemExt@ObjectData@reset@void@(int,int)@prn13.java@297@definition@????0@LOC:28 COM:0 MVG:9@?@d@ CCCC_Member@ObjectData@step@void@(int,int)@ CCCC_MemExt@ObjectData@step@void@(int,int)@prn13.java@327@definition@????0@LOC:20 COM:0 MVG:6@?@d@ CCCC_Member@TextData@TextData@@(String,Font,Component)@ CCCC_MemExt@TextData@TextData@@(String,Font,Component)@prn13.java@247@definition@????0@LOC:7 COM:0 MVG:0@?@d@ CCCC_UseRel@ChangeEvent@DemoControls@ CCCC_UseExt@ChangeEvent@DemoControls@prn13.java@401@normal parameter@????0@*@?@p@ CCCC_UseRel@ChangeListener@DemoControls@ CCCC_UseExt@ChangeListener@DemoControls@prn13.java@350@implements@????0@*@?@I@ CCCC_UseRel@CustomControls@DemoControls@ CCCC_UseExt@CustomControls@DemoControls@prn13.java@350@extends@????0@*@?@I@ CCCC_UseRel@Dimension@DemoControls@ CCCC_UseExt@Dimension@DemoControls@prn13.java@422@return type@????0@*@?@p@ CCCC_UseRel@FadeAnim@DemoControls@ CCCC_UseExt@FadeAnim@DemoControls@prn13.java@352@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@FadeAnim@DemoControls@prn13.java@356@normal parameter@????0@*@?@p@ CCCC_UseRel@Font@DemoControls@ CCCC_UseExt@Font@DemoControls@prn13.java@354@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@JSlider@DemoControls@ CCCC_UseExt@JSlider@DemoControls@prn13.java@353@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@AnimatingControlsSurface@FadeAnim@ CCCC_UseExt@AnimatingControlsSurface@FadeAnim@prn13.java@54@extends@????0@*@?@I@ CCCC_UseRel@BasicStroke@FadeAnim@ CCCC_UseExt@BasicStroke@FadeAnim@prn13.java@72@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@Font@FadeAnim@ CCCC_UseExt@Font@FadeAnim@prn13.java@73@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@Graphics2D@FadeAnim@ CCCC_UseExt@Graphics2D@FadeAnim@prn13.java@209@normal parameter@????0@*@?@p@ CCCC_UseRel@Paint@FadeAnim@ CCCC_UseExt@Paint@FadeAnim@prn13.java@84@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@String@FadeAnim@ CCCC_UseExt@String@FadeAnim@prn13.java@79@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@String@FadeAnim@prn13.java@82@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@String@FadeAnim@prn13.java@236@normal parameter@????0@*@?@p@ CCCC_UseRel@TexturePaint@FadeAnim@ CCCC_UseExt@TexturePaint@FadeAnim@prn13.java@56@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@Vector@FadeAnim@ CCCC_UseExt@Vector@FadeAnim@prn13.java@88@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@BufferedImage@ObjectData@ CCCC_UseExt@BufferedImage@ObjectData@prn13.java@261@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@Object@ObjectData@ CCCC_UseExt@Object@ObjectData@prn13.java@257@extends@????0@*@?@I@ CCCC_UseExt@Object@ObjectData@prn13.java@260@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@Object@ObjectData@prn13.java@268@normal parameter@????0@*@?@p@ CCCC_UseRel@Paint@ObjectData@ CCCC_UseExt@Paint@ObjectData@prn13.java@262@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@Paint@ObjectData@prn13.java@268@normal parameter@????0@*@?@p@ CCCC_UseRel@Component@TextData@ CCCC_UseExt@Component@TextData@prn13.java@247@normal parameter@????0@*@?@p@ CCCC_UseRel@Font@TextData@ CCCC_UseExt@Font@TextData@prn13.java@244@member variable@????0@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@Font@TextData@prn13.java@247@normal parameter@????0@*@?@p@ CCCC_UseRel@Object@TextData@ CCCC_UseExt@Object@TextData@prn13.java@241@extends@????0@*@?@I@ CCCC_UseRel@String@TextData@ CCCC_UseExt@String@TextData@prn13.java@243@member variable@????0@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@String@TextData@prn13.java@247@normal parameter@????0@*@?@p@ CCCC_RejExt@prn13.java@1@@?????@LOC:11 COM:32 MVG:0@?@r@ cccc-3.1.4/test/prn13.htmlref0000644000000000000000000013765607724312663014451 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 20 
    Lines of CodeLOC 34617.300
    McCabe's Cyclomatic NumberMVG 61 3.050
    Lines of CommentCOM 37 1.850
    LOC/COML_C 9.351 
    MVG/COMM_C 1.649 
    Information Flow measure (  inclusive )IF4 64 3.200
    Information Flow measure (  visible )IF4v 64 3.200
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 11 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    AnimatingControlsSurface 0 0 0------------
    BasicStroke 0 0 0------------
    BufferedImage 0 0 0------------
    ChangeEvent 0 0 0------------
    ChangeListener 0 0 0------------
    Component 0 0 0------------
    CustomControls 0 0 0------------
    DemoControls 74 4 174.000------
    Dimension 0 0 0------------
    FadeAnim 165 36 441.250 9.000
    Font 0 0 0------------
    Graphics2D 0 0 0------------
    JSlider 0 0 0------------
    Object 0 0 0------------
    ObjectData 84 21 0************
    Paint 0 0 0------------
    String 0 0 0------------
    TextData 12 0 0------------
    TexturePaint 0 0 0------------
    Vector 0 0 0------------

    Procedural Metrics Detail

    AnimatingControlsSurface

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    BasicStroke

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    BufferedImage

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ChangeEvent

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ChangeListener

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Component

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    CustomControls

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    DemoControls
    definition   prn13.java:350

    LOCMVGCOML_CM_C
    DemoControls(  FadeAnim )
    definition   prn13.java:356

    39 0 0******------
    getPreferredSize(   )
    definition   prn13.java:422

    3 0 0------------
    run(   )
    definition   prn13.java:427

    8 0 0------------
    stateChanged(  ChangeEvent )
    definition   prn13.java:401

    19 4 0------------
    Dimension

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    FadeAnim
    definition   prn13.java:54

    LOCMVGCOML_CM_C
    FadeAnim(   )
    definition   prn13.java:92

    8 0 0------------
    main(  String[] )
    definition   prn13.java:236

    3 0 0------------
    render(  int,  int,  Graphics2D )
    definition   prn13.java:209

    24 6 0************
    reset(  int,  int )
    definition   prn13.java:195

    5 1 0------------
    setImages(  int )
    definition   prn13.java:102

    29 5 0************
    setShapes(  int )
    definition   prn13.java:161

    31 19 0************
    setStrings(  int )
    definition   prn13.java:134

    24 4 0******------
    step(  int,  int )
    definition   prn13.java:202

    5 1 0------------
    Font

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Graphics2D

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    JSlider

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Object

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ObjectData
    definition   prn13.java:257

    LOCMVGCOML_CM_C
    ObjectData(  Object,  Paint )
    definition   prn13.java:268

    11 2 0------------
    getRandomXY(  int,  int )
    definition   prn13.java:281

    14 4 0------------
    reset(  int,  int )
    definition   prn13.java:297

    28 9 0************
    step(  int,  int )
    definition   prn13.java:327

    20 6 0************
    Paint

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    String

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    TextData
    definition   prn13.java:241

    LOCMVGCOML_CM_C
    TextData(  String,  Font,  Component )
    definition   prn13.java:247

    7 0 0------------
    TexturePaint

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Vector

    LOCMVGCOML_CM_C
    No member functions have been identified for this module

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    AnimatingControlsSurface 0 0 0 1 1
    BasicStroke 0 0 0 0 1
    BufferedImage 0 0 0 0 1
    ChangeEvent 0 0 0 0 1
    ChangeListener 0 0 0 1 1
    Component 0 0 0 0 1
    CustomControls 0 0 0 1 1
    DemoControls 4 0 1 0 7
    Dimension 0 0 0 0 1
    FadeAnim 8 0 1 0 9
    Font 0 0 0 0 3
    Graphics2D 0 0 0 0 1
    JSlider 0 0 0 0 1
    Object 0 0 0 2 2
    ObjectData 4 0 1 0 3
    Paint 0 0 0 0 2
    String 0 0 0 0 2
    TextData 1 0 1 0 4
    TexturePaint 0 0 0 0 1
    Vector 0 0 0 0 1

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    AnimatingControlsSurface 1 1 1 0 0 0 0 0 0
    BasicStroke 1 0 1 0 0 0 0 0 0
    BufferedImage 1 0 1 0 0 0 0 0 0
    ChangeEvent 1 0 1 0 0 0 0 0 0
    ChangeListener 1 1 1 0 0 0 0 0 0
    Component 1 0 1 0 0 0 0 0 0
    CustomControls 1 1 1 0 0 0 0 0 0
    DemoControls 0 0 0 7 2 7 0 0 0
    Dimension 1 0 1 0 0 0 0 0 0
    FadeAnim 1 0 1 8 1 8 64 0 64
    Font 3 0 3 0 0 0 0 0 0
    Graphics2D 1 0 1 0 0 0 0 0 0
    JSlider 1 0 1 0 0 0 0 0 0
    Object 2 2 2 0 0 0 0 0 0
    ObjectData 0 0 0 3 1 3 0 0 0
    Paint 2 0 2 0 0 0 0 0 0
    String 2 0 2 0 0 0 0 0 0
    TextData 0 0 0 4 1 4 0 0 0
    TexturePaint 1 0 1 0 0 0 0 0 0
    Vector 1 0 1 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    AnimatingControlsSurface FadeAnim [CV]
    extends   prn13.java:54


     
     
    BasicStroke FadeAnim [V]
    member variable   prn13.java:72


     
     
    BufferedImage ObjectData [V]
    member variable   prn13.java:261


     
     
    ChangeEvent DemoControls [V]
    normal parameter   prn13.java:401


     
     
    ChangeListener DemoControls [CV]
    implements   prn13.java:350


     
     
    Component TextData [V]
    normal parameter   prn13.java:247


     
     
    CustomControls DemoControls [CV]
    extends   prn13.java:350


     
     
    DemoControls   ChangeEvent [V]
    normal parameter   prn13.java:401


    ChangeListener [CV]
    implements   prn13.java:350


    CustomControls [CV]
    extends   prn13.java:350


    Dimension [V]
    return type   prn13.java:422


    FadeAnim [V]
    member variable   prn13.java:352
    normal parameter   prn13.java:356


    Font [V]
    member variable   prn13.java:354


    JSlider [V]
    member variable   prn13.java:353


     
    Dimension DemoControls [V]
    return type   prn13.java:422


     
     
    FadeAnim DemoControls [V]
    member variable   prn13.java:352
    normal parameter   prn13.java:356


     
    AnimatingControlsSurface [CV]
    extends   prn13.java:54


    BasicStroke [V]
    member variable   prn13.java:72


    Font [V]
    member variable   prn13.java:73


    Graphics2D [V]
    normal parameter   prn13.java:209


    Paint [V]
    member variable   prn13.java:84


    String [V]
    member variable   prn13.java:79
    member variable   prn13.java:82
    normal parameter   prn13.java:236


    TexturePaint [V]
    member variable   prn13.java:56


    Vector [V]
    member variable   prn13.java:88


     
    Font DemoControls [V]
    member variable   prn13.java:354


    FadeAnim [V]
    member variable   prn13.java:73


    TextData [V]
    member variable   prn13.java:244
    normal parameter   prn13.java:247


     
     
    Graphics2D FadeAnim [V]
    normal parameter   prn13.java:209


     
     
    JSlider DemoControls [V]
    member variable   prn13.java:353


     
     
    Object ObjectData [CV]
    extends   prn13.java:257
    member variable   prn13.java:260
    normal parameter   prn13.java:268


    TextData [CV]
    extends   prn13.java:241


     
     
    ObjectData   BufferedImage [V]
    member variable   prn13.java:261


    Object [CV]
    extends   prn13.java:257
    member variable   prn13.java:260
    normal parameter   prn13.java:268


    Paint [V]
    member variable   prn13.java:262
    normal parameter   prn13.java:268


     
    Paint FadeAnim [V]
    member variable   prn13.java:84


    ObjectData [V]
    member variable   prn13.java:262
    normal parameter   prn13.java:268


     
     
    String FadeAnim [V]
    member variable   prn13.java:79
    member variable   prn13.java:82
    normal parameter   prn13.java:236


    TextData [V]
    member variable   prn13.java:243
    normal parameter   prn13.java:247


     
     
    TextData   Component [V]
    normal parameter   prn13.java:247


    Font [V]
    member variable   prn13.java:244
    normal parameter   prn13.java:247


    Object [CV]
    extends   prn13.java:241


    String [V]
    member variable   prn13.java:243
    normal parameter   prn13.java:247


     
    TexturePaint FadeAnim [V]
    member variable   prn13.java:56


     
     
    Vector FadeAnim [V]
    member variable   prn13.java:88


     
     

    Other Extents

    LocationTextLOCCOMMVG
    prn13.java:1
    <file scope items> 11 32 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn13.java0000644000000000000000000004010207463513245013703 0ustar rootroot// prn13.java // This file is based on the FadeAnim.java source sample distributed // as part of Sun's Java Tutorial. /* * @(#)FadeAnim.java 1.30 99/09/07 * * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */ package demos.Composite; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import java.awt.event.*; import java.util.Vector; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import AnimatingControlsSurface; import CustomControls; /** * Animation of compositing shapes, text and images fading in and out. */ public class FadeAnim extends AnimatingControlsSurface { private static TexturePaint texture; static { int w = 10; int h = 10; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D gi = bi.createGraphics(); Color oc = Color.blue; Color ic = Color.green; gi.setPaint(new GradientPaint(0,0,oc,w*.35f,h*.35f,ic)); gi.fillRect(0, 0, w/2, h/2); gi.setPaint(new GradientPaint(w,0,oc,w*.65f,h*.35f,ic)); gi.fillRect(w/2, 0, w/2, h/2); gi.setPaint(new GradientPaint(0,h,oc,w*.35f,h*.65f,ic)); gi.fillRect(0, h/2, w/2, h/2); gi.setPaint(new GradientPaint(w,h,oc,w*.65f,h*.65f,ic)); gi.fillRect(w/2, h/2, w/2, h/2); texture = new TexturePaint(bi,new Rectangle(0,0,w,h)); } private static BasicStroke bs = new BasicStroke(6); private static Font fonts[] = { new Font("Times New Roman", Font.PLAIN, 64), new Font("serif", Font.BOLD + Font.ITALIC, 24), new Font("Courier", Font.BOLD, 36), new Font("Arial", Font.BOLD + Font.ITALIC, 48), new Font("Helvetica", Font.PLAIN, 52)}; private static String strings[] = { "Alpha", "Composite", "Src", "SrcOver", "SrcIn", "SrcOut", "Clear", "DstOver", "DstIn" }; private static String imgs[] = { "jumptojavastrip.png", "duke.gif", "star7.gif" }; private static Paint paints[] = { Color.red, Color.blue, Color.green, Color.magenta, Color.orange, Color.pink, Color.cyan, texture, Color.yellow, Color.lightGray, Color.white}; private Vector vector = new Vector(20); private int numShapes, numStrings, numImages; public FadeAnim() { setBackground(Color.black); setStrings(2); setImages(3); setShapes(8); setControls(new Component[] { new DemoControls(this) }); setConstraints(new String[] { BorderLayout.EAST }); } public void setImages(int num) { if (num < numImages) { Vector v = new Vector(vector.size()); for (int i = 0; i < vector.size(); i++) { if (((ObjectData) vector.get(i)).object instanceof Image) { v.addElement(vector.get(i)); } } vector.removeAll(v); v.setSize(num); vector.addAll(v); } else { Dimension d = getSize(); for (int i = numImages; i < num; i++) { Object obj = getImage(imgs[i % imgs.length]); if (imgs[i % imgs.length].equals("jumptojavastrip.png")) { int iw = ((Image) obj).getWidth(null); int ih = ((Image) obj).getHeight(null); BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); bimg.createGraphics().drawImage((Image) obj, 0, 0, null); obj = bimg; } ObjectData od = new ObjectData(obj, Color.black); od.reset(d.width, d.height); vector.addElement(od); } } numImages = num; } public void setStrings(int num) { if (num < numStrings) { Vector v = new Vector(vector.size()); for (int i = 0; i < vector.size(); i++) { if (((ObjectData) vector.get(i)).object instanceof TextData) { v.addElement(vector.get(i)); } } vector.removeAll(v); v.setSize(num); vector.addAll(v); } else { Dimension d = getSize(); for (int i = numStrings; i < num; i++) { int j = i % fonts.length; int k = i % strings.length; Object obj = new TextData(strings[k], fonts[j], this); ObjectData od = new ObjectData(obj, paints[i%paints.length]); od.reset(d.width, d.height); vector.addElement(od); } } numStrings = num; } public void setShapes(int num) { if (num < numShapes) { Vector v = new Vector(vector.size()); for (int i = 0; i < vector.size(); i++) { if (((ObjectData) vector.get(i)).object instanceof Shape) { v.addElement(vector.get(i)); } } vector.removeAll(v); v.setSize(num); vector.addAll(v); } else { Dimension d = getSize(); for (int i = numShapes; i < num; i++) { Object obj = null; switch (i % 7) { case 0 : obj = new GeneralPath(); break; case 1 : obj = new Rectangle2D.Double(); break; case 2 : obj = new Ellipse2D.Double(); break; case 3 : obj = new Arc2D.Double(); break; case 4 : obj = new RoundRectangle2D.Double(); break; case 5 : obj = new CubicCurve2D.Double(); break; case 6 : obj = new QuadCurve2D.Double(); break; } ObjectData od = new ObjectData(obj, paints[i%paints.length]); od.reset(d.width, d.height); vector.addElement(od); } } numShapes = num; } public void reset(int w, int h) { for (int i = 0; i < vector.size(); i++) { ((ObjectData) vector.get(i)).reset(w, h); } } public void step(int w, int h) { for (int i = 0; i < vector.size(); i++) { ((ObjectData) vector.get(i)).step(w, h); } } public void render(int w, int h, Graphics2D g2) { for (int i = 0; i < vector.size(); i++) { ObjectData od = (ObjectData) vector.get(i); AlphaComposite ac = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, od.alpha); g2.setComposite(ac); g2.setPaint(od.paint); g2.translate(od.x, od.y); if (od.object instanceof Image) { g2.drawImage((Image) od.object, 0, 0, this); } else if (od.object instanceof TextData) { g2.setFont(((TextData) od.object).font); g2.drawString(((TextData) od.object).string, 0, 0); } else if (od.object instanceof QuadCurve2D || od.object instanceof CubicCurve2D) { g2.setStroke(bs); g2.draw((Shape) od.object); } else if (od.object instanceof Shape) { g2.fill((Shape) od.object); } g2.translate(-od.x, -od.y); } } public static void main(String argv[]) { createDemoFrame(new FadeAnim()); } static class TextData extends Object { public String string; public Font font; public int width, height; public TextData(String str, Font font, Component cmp) { string = str; this.font = font; FontMetrics fm = cmp.getFontMetrics(font); width = fm.stringWidth(str); height = fm.getHeight(); } } static class ObjectData extends Object { final int UP = 0; final int DOWN = 1; Object object; BufferedImage bimg; Paint paint; double x, y; float alpha; int alphaDirection; int imgX; public ObjectData(Object object, Paint paint) { this.object = object; this.paint = paint; if (object instanceof BufferedImage) { bimg = (BufferedImage) object; this.object = bimg.getSubimage(0, 0, 80, 80); } getRandomXY(300, 250); alpha = (float) Math.random(); alphaDirection = Math.random() > 0.5 ? UP : DOWN; } private void getRandomXY(int w, int h) { if (object instanceof TextData) { x = Math.random() * (w - ((TextData) object).width); y = Math.random() * h; y = y < ((TextData) object).height ? ((TextData) object).height : y; } else if (object instanceof Image) { x = Math.random() * (w - ((Image) object).getWidth(null)); y = Math.random() * (h - ((Image) object).getHeight(null)); } else if (object instanceof Shape) { Rectangle bounds = ((Shape) object).getBounds(); x = Math.random() * (w - bounds.width); y = Math.random() * (h - bounds.height); } } public void reset(int w, int h) { getRandomXY(w, h); double ww = 20 + Math.random()*((w == 0 ? 400 : w)/4); double hh = 20 + Math.random()*((h == 0 ? 300 : h)/4); if (object instanceof Ellipse2D) { ((Ellipse2D) object).setFrame(0, 0, ww, hh); } else if (object instanceof Rectangle2D) { ((Rectangle2D) object).setRect(0, 0, ww, ww); } else if (object instanceof RoundRectangle2D) { ((RoundRectangle2D) object).setRoundRect(0, 0, hh, hh, 20, 20); } else if (object instanceof Arc2D) { ((Arc2D) object).setArc(0, 0, hh, hh, 45, 270, Arc2D.PIE); } else if (object instanceof QuadCurve2D) { ((QuadCurve2D) object).setCurve(0, 0, w*.2, h*.4, w*.4, 0); } else if (object instanceof CubicCurve2D) { ((CubicCurve2D) object).setCurve(0,0,30,-60,60,60,90,0); } else if (object instanceof GeneralPath) { GeneralPath p = new GeneralPath(); float size = (float) ww; p.moveTo(- size / 2.0f, - size / 8.0f); p.lineTo(+ size / 2.0f, - size / 8.0f); p.lineTo(- size / 4.0f, + size / 2.0f); p.lineTo(+ 0.0f, - size / 2.0f); p.lineTo(+ size / 4.0f, + size / 2.0f); p.closePath(); object = p; } } public void step(int w, int h) { if (object instanceof BufferedImage) { if ((imgX += 80) == 800) { imgX = 0; } object = bimg.getSubimage(imgX, 0, 80, 80); } if (alphaDirection == UP) { if ((alpha += 0.05) > .99) { alphaDirection = DOWN; alpha = 1.0f; } } else if (alphaDirection == DOWN) { if ((alpha -= .05) < 0.01) { alphaDirection = UP; alpha = 0; getRandomXY(w, h); } } } } static class DemoControls extends CustomControls implements ChangeListener { FadeAnim demo; JSlider shapeSlider, stringSlider, imageSlider; Font font = new Font("serif", Font.PLAIN, 10); public DemoControls(FadeAnim demo) { super(demo.name); this.demo = demo; setBackground(Color.gray); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(Box.createVerticalStrut(5)); JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); toolbar.setBackground(Color.gray); toolbar.setFloatable(false); shapeSlider = new JSlider(JSlider.HORIZONTAL,0,20,demo.numShapes); shapeSlider.addChangeListener(this); TitledBorder tb = new TitledBorder(new EtchedBorder()); tb.setTitleFont(font); tb.setTitle(String.valueOf(demo.numShapes) + " Shapes"); shapeSlider.setBorder(tb); shapeSlider.setPreferredSize(new Dimension(80,45)); toolbar.addSeparator(); toolbar.add(shapeSlider); toolbar.addSeparator(); stringSlider = new JSlider(JSlider.HORIZONTAL,0,10,demo.numStrings); stringSlider.addChangeListener(this); tb = new TitledBorder(new EtchedBorder()); tb.setTitleFont(font); tb.setTitle(String.valueOf(demo.numStrings) + " Strings"); stringSlider.setBorder(tb); stringSlider.setPreferredSize(new Dimension(80,45)); toolbar.add(stringSlider); toolbar.addSeparator(); imageSlider = new JSlider(JSlider.HORIZONTAL,0,10,demo.numImages); imageSlider.addChangeListener(this); tb = new TitledBorder(new EtchedBorder()); tb.setTitleFont(font); tb.setTitle(String.valueOf(demo.numImages) + " Images"); imageSlider.setBorder(tb); imageSlider.setPreferredSize(new Dimension(80,45)); toolbar.add(imageSlider); toolbar.addSeparator(); add(toolbar); } public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); int value = slider.getValue(); TitledBorder tb = (TitledBorder) slider.getBorder(); if (slider.equals(shapeSlider)) { tb.setTitle(String.valueOf(value) + " Shapes"); demo.setShapes(value); } else if (slider.equals(stringSlider)) { tb.setTitle(String.valueOf(value) + " Strings"); demo.setStrings(value); } else if (slider.equals(imageSlider)) { tb.setTitle(String.valueOf(value) + " Images"); demo.setImages(value); } slider.repaint(); if (demo.animating.thread == null) { demo.repaint(); } } public Dimension getPreferredSize() { return new Dimension(80,0); } public void run() { try { thread.sleep(999); } catch (InterruptedException e) { return; } shapeSlider.setValue((int) (Math.random() * 5)); stringSlider.setValue(10); thread = null; } } // End DemoControls } // End FadeAnim cccc-3.1.4/test/prn13.xmlref0000644000000000000000000012247107724312663014272 0ustar rootroot AnimatingControlsSurface BasicStroke BufferedImage ChangeEvent ChangeListener Component CustomControls DemoControls Dimension FadeAnim Font Graphics2D JSlider Object ObjectData Paint String TextData TexturePaint Vector AnimatingControlsSurface BasicStroke BufferedImage ChangeEvent ChangeListener Component CustomControls DemoControls definition DemoControls(FadeAnim) definition getPreferredSize() definition run() definition stateChanged(ChangeEvent) definition Dimension FadeAnim definition FadeAnim() definition main(String[]) definition render(int,int,Graphics2D) definition reset(int,int) definition setImages(int) definition setShapes(int) definition setStrings(int) definition step(int,int) definition Font Graphics2D JSlider Object ObjectData definition ObjectData(Object,Paint) definition getRandomXY(int,int) definition reset(int,int) definition step(int,int) definition Paint String TextData definition TextData(String,Font,Component) definition TexturePaint Vector AnimatingControlsSurface BasicStroke BufferedImage ChangeEvent ChangeListener Component CustomControls DemoControls Dimension FadeAnim Font Graphics2D JSlider Object ObjectData Paint String TextData TexturePaint Vector AnimatingControlsSurface BasicStroke BufferedImage ChangeEvent ChangeListener Component CustomControls DemoControls Dimension FadeAnim Font Graphics2D JSlider Object ObjectData Paint String TextData TexturePaint Vector AnimatingControlsSurface FadeAnim true true extends BasicStroke FadeAnim true false member variable BufferedImage ObjectData true false member variable ChangeEvent DemoControls true false normal parameter ChangeListener DemoControls true true implements Component TextData true false normal parameter CustomControls DemoControls true true extends DemoControls ChangeEvent true false normal parameter ChangeListener true true implements CustomControls true true extends Dimension true false return type FadeAnim true false member variable normal parameter Font true false member variable JSlider true false member variable Dimension DemoControls true false return type FadeAnim DemoControls true false member variable normal parameter AnimatingControlsSurface true true extends BasicStroke true false member variable Font true false member variable Graphics2D true false normal parameter Paint true false member variable String true false member variable member variable normal parameter TexturePaint true false member variable Vector true false member variable Font DemoControls true false member variable FadeAnim true false member variable TextData true false member variable normal parameter Graphics2D FadeAnim true false normal parameter JSlider DemoControls true false member variable Object ObjectData true true extends member variable normal parameter TextData true true extends ObjectData BufferedImage true false member variable Object true true extends member variable normal parameter Paint true false member variable normal parameter Paint FadeAnim true false member variable ObjectData true false member variable normal parameter String FadeAnim true false member variable member variable normal parameter TextData true false member variable normal parameter TextData Component true false normal parameter Font true false member variable normal parameter Object true true extends String true false member variable normal parameter TexturePaint FadeAnim true false member variable Vector FadeAnim true false member variable <file scope items> cccc-3.1.4/test/prn14.dbref0000644000000000000000000001103507463526205014050 0ustar rootrootCCCC_Module@ActionEvent@@ CCCC_Module@ActionListener@@ CCCC_Module@BufferedImage@@ CCCC_Module@BufferedImageOp@@ CCCC_Module@ChangeEvent@@ CCCC_Module@ChangeListener@@ CCCC_Module@ControlsSurface@@ CCCC_Module@CustomControls@@ CCCC_Module@DemoControls@class@ CCCC_ModExt@DemoControls@class@prn14.java@176@definition@?????@LOC:5 COM:1 MVG:0@?@d@ CCCC_Module@Dimension@@ CCCC_Module@Font@@ CCCC_Module@Graphics2D@@ CCCC_Module@ImageOps@class@ CCCC_ModExt@ImageOps@class@prn14.java@52@definition@?????@LOC:45 COM:9 MVG:2@?@d@ CCCC_Module@JComboBox@@ CCCC_Module@JSlider@@ CCCC_Module@String@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@DemoControls@DemoControls@@(ImageOps)@ CCCC_MemExt@DemoControls@DemoControls@@(ImageOps)@prn14.java@182@definition@????0@LOC:17 COM:0 MVG:2@?@d@ CCCC_Member@DemoControls@actionPerformed@void@(ActionEvent)@ CCCC_MemExt@DemoControls@actionPerformed@void@(ActionEvent)@prn14.java@201@definition@????0@LOC:22 COM:0 MVG:4@?@d@ CCCC_Member@DemoControls@getPreferredSize@Dimension@()@ CCCC_MemExt@DemoControls@getPreferredSize@Dimension@()@prn14.java@225@definition@????0@LOC:3 COM:0 MVG:0@?@d@ CCCC_Member@DemoControls@run@void@()@ CCCC_MemExt@DemoControls@run@void@()@prn14.java@230@definition@????0@LOC:24 COM:0 MVG:5@?@d@ CCCC_Member@ImageOps@ImageOps@@()@ CCCC_MemExt@ImageOps@ImageOps@@()@prn14.java@100@definition@????0@LOC:19 COM:0 MVG:1@?@d@ CCCC_Member@ImageOps@main@void@(String[])@ CCCC_MemExt@ImageOps@main@void@(String[])@prn14.java@171@definition@????0@LOC:3 COM:0 MVG:0@?@d@ CCCC_Member@ImageOps@render@void@(int,int,Graphics2D)@ CCCC_MemExt@ImageOps@render@void@(int,int,Graphics2D)@prn14.java@136@definition@????0@LOC:7 COM:0 MVG:0@?@d@ CCCC_Member@ImageOps@stateChanged@void@(ChangeEvent)@ CCCC_MemExt@ImageOps@stateChanged@void@(ChangeEvent)@prn14.java@145@definition@????0@LOC:21 COM:2 MVG:4@?@d@ CCCC_Member@ImageOps@thresholdOp@void@(int,int)@ CCCC_MemExt@ImageOps@thresholdOp@void@(int,int)@prn14.java@121@definition@????0@LOC:13 COM:0 MVG:3@?@d@ CCCC_UseRel@ActionEvent@DemoControls@ CCCC_UseExt@ActionEvent@DemoControls@prn14.java@201@normal parameter@????0@*@?@p@ CCCC_UseRel@ActionListener@DemoControls@ CCCC_UseExt@ActionListener@DemoControls@prn14.java@176@implements@????0@*@?@I@ CCCC_UseRel@CustomControls@DemoControls@ CCCC_UseExt@CustomControls@DemoControls@prn14.java@176@extends@????0@*@?@I@ CCCC_UseRel@Dimension@DemoControls@ CCCC_UseExt@Dimension@DemoControls@prn14.java@225@return type@????0@*@?@p@ CCCC_UseRel@Font@DemoControls@ CCCC_UseExt@Font@DemoControls@prn14.java@180@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@ImageOps@DemoControls@ CCCC_UseExt@ImageOps@DemoControls@prn14.java@178@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@ImageOps@DemoControls@prn14.java@182@normal parameter@????0@*@?@p@ CCCC_UseRel@JComboBox@DemoControls@ CCCC_UseExt@JComboBox@DemoControls@prn14.java@179@member variable@?????@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@BufferedImage@ImageOps@ CCCC_UseExt@BufferedImage@ImageOps@prn14.java@56@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@BufferedImageOp@ImageOps@ CCCC_UseExt@BufferedImageOp@ImageOps@prn14.java@60@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@ChangeEvent@ImageOps@ CCCC_UseExt@ChangeEvent@ImageOps@prn14.java@145@normal parameter@????0@*@?@p@ CCCC_UseRel@ChangeListener@ImageOps@ CCCC_UseExt@ChangeListener@ImageOps@prn14.java@52@implements@????0@*@?@I@ CCCC_UseRel@ControlsSurface@ImageOps@ CCCC_UseExt@ControlsSurface@ImageOps@prn14.java@52@extends@????0@*@?@I@ CCCC_UseRel@Graphics2D@ImageOps@ CCCC_UseExt@Graphics2D@ImageOps@prn14.java@136@normal parameter@????0@*@?@p@ CCCC_UseRel@JSlider@ImageOps@ CCCC_UseExt@JSlider@ImageOps@prn14.java@54@member variable@????1@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseRel@String@ImageOps@ CCCC_UseExt@String@ImageOps@prn14.java@55@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@String@ImageOps@prn14.java@57@member variable@????2@LOC:0 COM:0 MVG:0@?@h@ CCCC_UseExt@String@ImageOps@prn14.java@171@normal parameter@????0@*@?@p@ CCCC_RejExt@prn14.java@1@@?????@LOC:9 COM:32 MVG:0@?@r@ cccc-3.1.4/test/prn14.htmlref0000644000000000000000000011300607715623450014430 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 16 
    Lines of CodeLOC 18811.750
    McCabe's Cyclomatic NumberMVG 21 1.312
    Lines of CommentCOM 44 2.750
    LOC/COML_C 4.273 
    MVG/COMM_C 0.477 
    Information Flow measure (  inclusive )IF4 64 4.000
    Information Flow measure (  visible )IF4v 64 4.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 9 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    ActionEvent 0 0 0------------
    ActionListener 0 0 0------------
    BufferedImage 0 0 0------------
    BufferedImageOp 0 0 0------------
    ChangeEvent 0 0 0------------
    ChangeListener 0 0 0------------
    ControlsSurface 0 0 0------------
    CustomControls 0 0 0------------
    DemoControls 71 11 171.00011.000
    Dimension 0 0 0------------
    Font 0 0 0------------
    Graphics2D 0 0 0------------
    ImageOps 108 10 11 9.818 0.909
    JComboBox 0 0 0------------
    JSlider 0 0 0------------
    String 0 0 0------------

    Procedural Metrics Detail

    ActionEvent

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ActionListener

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    BufferedImage

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    BufferedImageOp

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ChangeEvent

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ChangeListener

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ControlsSurface

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    CustomControls

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    DemoControls
    definition   prn14.java:176

    LOCMVGCOML_CM_C
    DemoControls(  ImageOps )
    definition   prn14.java:182

    17 2 0------------
    actionPerformed(  ActionEvent )
    definition   prn14.java:201

    22 4 0******------
    getPreferredSize(   )
    definition   prn14.java:225

    3 0 0------------
    run(   )
    definition   prn14.java:230

    24 5 0************
    Dimension

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Font

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Graphics2D

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    ImageOps
    definition   prn14.java:52

    LOCMVGCOML_CM_C
    ImageOps(   )
    definition   prn14.java:100

    19 1 0------------
    main(  String[] )
    definition   prn14.java:171

    3 0 0------------
    render(  int,  int,  Graphics2D )
    definition   prn14.java:136

    7 0 0------------
    stateChanged(  ChangeEvent )
    definition   prn14.java:145

    21 4 210.500------
    thresholdOp(  int,  int )
    definition   prn14.java:121

    13 3 0------------
    JComboBox

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    JSlider

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    String

    LOCMVGCOML_CM_C
    No member functions have been identified for this module

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    ActionEvent 0 0 0 0 1
    ActionListener 0 0 0 1 1
    BufferedImage 0 0 0 0 1
    BufferedImageOp 0 0 0 0 1
    ChangeEvent 0 0 0 0 1
    ChangeListener 0 0 0 1 1
    ControlsSurface 0 0 0 1 1
    CustomControls 0 0 0 1 1
    DemoControls 4 0 1 0 7
    Dimension 0 0 0 0 1
    Font 0 0 0 0 1
    Graphics2D 0 0 0 0 1
    ImageOps 5 0 1 0 9
    JComboBox 0 0 0 0 1
    JSlider 0 0 0 0 1
    String 0 0 0 0 1

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    ActionEvent 1 0 1 0 0 0 0 0 0
    ActionListener 1 1 1 0 0 0 0 0 0
    BufferedImage 1 0 1 0 0 0 0 0 0
    BufferedImageOp 1 0 1 0 0 0 0 0 0
    ChangeEvent 1 0 1 0 0 0 0 0 0
    ChangeListener 1 1 1 0 0 0 0 0 0
    ControlsSurface 1 1 1 0 0 0 0 0 0
    CustomControls 1 1 1 0 0 0 0 0 0
    DemoControls 0 0 0 7 2 7 0 0 0
    Dimension 1 0 1 0 0 0 0 0 0
    Font 1 0 1 0 0 0 0 0 0
    Graphics2D 1 0 1 0 0 0 0 0 0
    ImageOps 1 0 1 8 2 8 64 0 64
    JComboBox 1 0 1 0 0 0 0 0 0
    JSlider 1 0 1 0 0 0 0 0 0
    String 1 0 1 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    ActionEvent DemoControls [V]
    normal parameter   prn14.java:201


     
     
    ActionListener DemoControls [CV]
    implements   prn14.java:176


     
     
    BufferedImage ImageOps [V]
    member variable   prn14.java:56


     
     
    BufferedImageOp ImageOps [V]
    member variable   prn14.java:60


     
     
    ChangeEvent ImageOps [V]
    normal parameter   prn14.java:145


     
     
    ChangeListener ImageOps [CV]
    implements   prn14.java:52


     
     
    ControlsSurface ImageOps [CV]
    extends   prn14.java:52


     
     
    CustomControls DemoControls [CV]
    extends   prn14.java:176


     
     
    DemoControls   ActionEvent [V]
    normal parameter   prn14.java:201


    ActionListener [CV]
    implements   prn14.java:176


    CustomControls [CV]
    extends   prn14.java:176


    Dimension [V]
    return type   prn14.java:225


    Font [V]
    member variable   prn14.java:180


    ImageOps [V]
    member variable   prn14.java:178
    normal parameter   prn14.java:182


    JComboBox [V]
    member variable   prn14.java:179


     
    Dimension DemoControls [V]
    return type   prn14.java:225


     
     
    Font DemoControls [V]
    member variable   prn14.java:180


     
     
    Graphics2D ImageOps [V]
    normal parameter   prn14.java:136


     
     
    ImageOps DemoControls [V]
    member variable   prn14.java:178
    normal parameter   prn14.java:182


     
    BufferedImage [V]
    member variable   prn14.java:56


    BufferedImageOp [V]
    member variable   prn14.java:60


    ChangeEvent [V]
    normal parameter   prn14.java:145


    ChangeListener [CV]
    implements   prn14.java:52


    ControlsSurface [CV]
    extends   prn14.java:52


    Graphics2D [V]
    normal parameter   prn14.java:136


    JSlider [V]
    member variable   prn14.java:54


    String [V]
    member variable   prn14.java:55
    member variable   prn14.java:57
    normal parameter   prn14.java:171


     
    JComboBox DemoControls [V]
    member variable   prn14.java:179


     
     
    JSlider ImageOps [V]
    member variable   prn14.java:54


     
     
    String ImageOps [V]
    member variable   prn14.java:55
    member variable   prn14.java:57
    normal parameter   prn14.java:171


     
     

    Other Extents

    LocationTextLOCCOMMVG
    prn14.java:1
    <file scope items> 9 32 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn14.java0000644000000000000000000002355207463524073013717 0ustar rootroot// prn14.java // This file is based on the ImageOps.java source sample distributed // as part of Sun's Java Tutorial. /* * @(#)ImageOps.java 1.24 99/09/07 * * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */ package demos.Images; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.awt.geom.AffineTransform; import javax.swing.*; import javax.swing.event.*; import ControlsSurface; import CustomControls; /** * Images drawn using operators such as ConvolveOp LowPass & Sharpen, * LookupOp and RescaleOp. */ public class ImageOps extends ControlsSurface implements ChangeListener { protected JSlider slider1, slider2; private static String imgName[] = { "bld.jpg", "boat.png" }; private static BufferedImage img[] = new BufferedImage[imgName.length]; private static String opsName[] = { "Threshold", "RescaleOp" ,"Invert", "Yellow Invert", "3x3 Blur", "3x3 Sharpen", "3x3 Edge", "5x5 Edge"}; private static BufferedImageOp biop[] = new BufferedImageOp[opsName.length]; private static int rescaleFactor = 128; private static float rescaleOffset = 0; private static int low = 100, high = 200; private int opsIndex, imgIndex; static { thresholdOp(low, high); int i = 1; biop[i++] = new RescaleOp(1.0f, 0, null); byte invert[] = new byte[256]; byte ordered[] = new byte[256]; for (int j = 0; j < 256 ; j++) { invert[j] = (byte) (256-j); ordered[j] = (byte) j; } biop[i++] = new LookupOp(new ByteLookupTable(0,invert), null); byte[][] yellowInvert = new byte[][] { invert, invert, ordered }; biop[i++] = new LookupOp(new ByteLookupTable(0,yellowInvert), null); int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}}; float data[][] = { {0.1f, 0.1f, 0.1f, // 3x3 blur 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f}, {-1.0f, -1.0f, -1.0f, // 3x3 sharpen -1.0f, 9.0f, -1.0f, -1.0f, -1.0f, -1.0f}, { 0.f, -1.f, 0.f, // 3x3 edge -1.f, 5.f, -1.f, 0.f, -1.f, 0.f}, {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, // 5x5 edge -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 24.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}}; for (int j = 0; j < data.length; j++, i++) { biop[i] = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j])); } } public ImageOps() { setBackground(Color.white); for (int i = 0; i < imgName.length; i++) { Image image = getImage(imgName[i]); int iw = image.getWidth(this); int ih = image.getHeight(this); img[i] = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); img[i].createGraphics().drawImage(image,0,0,null); } slider1 = new JSlider(JSlider.VERTICAL, 0, 255, low); slider1.setPreferredSize(new Dimension(15, 100)); slider1.addChangeListener(this); slider2 = new JSlider(JSlider.VERTICAL, 0, 255, high); slider2.setPreferredSize(new Dimension(15, 100)); slider2.addChangeListener(this); setControls(new Component[]{new DemoControls(this),slider1,slider2}); setConstraints(new String[] { BorderLayout.NORTH, BorderLayout.WEST, BorderLayout.EAST }); } public static void thresholdOp(int low, int high) { byte threshold[] = new byte[256]; for (int j = 0; j < 256 ; j++) { if (j > high) { threshold[j] = (byte) 255; } else if (j < low) { threshold[j] = (byte) 0; } else { threshold[j] = (byte) j; } } biop[0] = new LookupOp(new ByteLookupTable(0,threshold), null); } public void render(int w, int h, Graphics2D g2) { int iw = img[imgIndex].getWidth(null); int ih = img[imgIndex].getHeight(null); BufferedImage bi = new BufferedImage(iw,ih,BufferedImage.TYPE_INT_RGB); biop[opsIndex].filter(img[imgIndex], bi); g2.drawImage(bi,0,0,w,h,null); } public void stateChanged(ChangeEvent e) { // when using these sliders use double buffering, which means // ignoring when DemoSurface.imageType = 'On Screen' if (getImageType() <= 1) { setImageType(2); } if (e.getSource().equals(slider1)) { if (opsIndex == 0) { thresholdOp(slider1.getValue(), high); } else { rescaleFactor = slider1.getValue(); biop[1] = new RescaleOp((float)rescaleFactor/128.0f, rescaleOffset, null); } } else { if (opsIndex == 0) { thresholdOp(low, slider2.getValue()); } else { rescaleOffset = (float) slider2.getValue(); biop[1] = new RescaleOp((float)rescaleFactor/128.0f, rescaleOffset, null); } } repaint(); } public static void main(String s[]) { createDemoFrame(new ImageOps()); } static class DemoControls extends CustomControls implements ActionListener { ImageOps demo; JComboBox imgCombo, opsCombo; Font font = new Font("serif", Font.PLAIN, 10); public DemoControls(ImageOps demo) { super(demo.name); this.demo = demo; setBackground(Color.gray); add(imgCombo = new JComboBox()); imgCombo.setFont(font); for (int i = 0; i < ImageOps.imgName.length; i++) { imgCombo.addItem(ImageOps.imgName[i]); } imgCombo.addActionListener(this); add(opsCombo = new JComboBox()); opsCombo.setFont(font); for (int i = 0; i < ImageOps.opsName.length; i++) { opsCombo.addItem(ImageOps.opsName[i]); } opsCombo.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource().equals(opsCombo)) { demo.opsIndex = opsCombo.getSelectedIndex(); if (demo.opsIndex == 0) { demo.slider1.setValue(demo.low); demo.slider2.setValue(demo.high); demo.slider1.setEnabled(true); demo.slider2.setEnabled(true); } else if (demo.opsIndex == 1) { demo.slider1.setValue(demo.rescaleFactor); demo.slider2.setValue((int) demo.rescaleOffset); demo.slider1.setEnabled(true); demo.slider2.setEnabled(true); } else { demo.slider1.setEnabled(false); demo.slider2.setEnabled(false); } } else if (e.getSource().equals(imgCombo)) { demo.imgIndex = imgCombo.getSelectedIndex(); } demo.repaint(10); } public Dimension getPreferredSize() { return new Dimension(200,32); } public void run() { try { thread.sleep(1111); } catch (Exception e) { return; } Thread me = Thread.currentThread(); while (thread == me) { for (int i = 0; i < ImageOps.imgName.length; i++) { imgCombo.setSelectedIndex(i); for (int j = 0; j < ImageOps.opsName.length; j++) { opsCombo.setSelectedIndex(j); if (j <= 1) { for (int k = 50; k <= 200; k+=10) { demo.slider1.setValue(k); try { thread.sleep(200); } catch (InterruptedException e) { return; } } } try { thread.sleep(4444); } catch (InterruptedException e) { return; } } } } thread = null; } } // End DemoControls } // End ImageOps cccc-3.1.4/test/prn14.xmlref0000644000000000000000000007313007715610506014265 0ustar rootroot ActionEvent ActionListener BufferedImage BufferedImageOp ChangeEvent ChangeListener ControlsSurface CustomControls DemoControls Dimension Font Graphics2D ImageOps JComboBox JSlider String ActionEvent ActionListener BufferedImage BufferedImageOp ChangeEvent ChangeListener ControlsSurface CustomControls DemoControls definition DemoControls(ImageOps) definition actionPerformed(ActionEvent) definition getPreferredSize() definition run() definition Dimension Font Graphics2D ImageOps definition ImageOps() definition main(String[]) definition render(int,int,Graphics2D) definition stateChanged(ChangeEvent) definition thresholdOp(int,int) definition JComboBox JSlider String ActionEvent ActionListener BufferedImage BufferedImageOp ChangeEvent ChangeListener ControlsSurface CustomControls DemoControls Dimension Font Graphics2D ImageOps JComboBox JSlider String ActionEvent ActionListener BufferedImage BufferedImageOp ChangeEvent ChangeListener ControlsSurface CustomControls DemoControls Dimension Font Graphics2D ImageOps JComboBox JSlider String ActionEvent DemoControls true false normal parameter ActionListener DemoControls true true implements BufferedImage ImageOps true false member variable BufferedImageOp ImageOps true false member variable ChangeEvent ImageOps true false normal parameter ChangeListener ImageOps true true implements ControlsSurface ImageOps true true extends CustomControls DemoControls true true extends DemoControls ActionEvent true false normal parameter ActionListener true true implements CustomControls true true extends Dimension true false return type Font true false member variable ImageOps true false member variable normal parameter JComboBox true false member variable Dimension DemoControls true false return type Font DemoControls true false member variable Graphics2D ImageOps true false normal parameter ImageOps DemoControls true false member variable normal parameter BufferedImage true false member variable BufferedImageOp true false member variable ChangeEvent true false normal parameter ChangeListener true true implements ControlsSurface true true extends Graphics2D true false normal parameter JSlider true false member variable String true false member variable member variable normal parameter JComboBox DemoControls true false member variable JSlider ImageOps true false member variable String ImageOps true false member variable member variable normal parameter <file scope items> cccc-3.1.4/test/prn15.dbref0000644000000000000000000000173407724312663014057 0ustar rootrootCCCC_Module@Image@@ CCCC_Module@Prn15@class@ CCCC_ModExt@Prn15@class@prn15.java@9@definition@?????@LOC:3 COM:5 MVG:0@?@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Prn15@get_image@Image@(int)@ CCCC_MemExt@Prn15@get_image@Image@(int)@prn15.java@11@definition@????0@LOC:61 COM:0 MVG:42@?@d@ CCCC_UseRel@Image@Prn15@ CCCC_UseExt@Image@Prn15@prn15.java@11@return type@????0@*@?@p@ CCCC_RejExt@prn15.java@1@@?????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn15.htmlref0000644000000000000000000003252107724312663014434 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 2 
    Lines of CodeLOC 6432.000
    McCabe's Cyclomatic NumberMVG 4221.000
    Lines of CommentCOM 5 2.500
    LOC/COML_C12.800 
    MVG/COMM_C 8.400 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    Image 0 0 0------------
    Prn15 64 42 512.800 8.400

    Procedural Metrics Detail

    Image

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Prn15
    definition   prn15.java:9

    LOCMVGCOML_CM_C
    get_image(  int )
    definition   prn15.java:11

    61 42 0************

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    Image 0 0 0 0 1
    Prn15 1 0 0 0 1

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    Image 1 0 1 0 0 0 0 0 0
    Prn15 0 0 0 1 0 1 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    Image Prn15 [V]
    return type   prn15.java:11


     
     
    Prn15   Image [V]
    return type   prn15.java:11


     

    Other Extents

    LocationTextLOCCOMMVG
    prn15.java:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn15.java0000644000000000000000000000444307573403176013720 0ustar rootroot// prn15.java // This test case looks at the effect of large // numbers of degenerate case labels. // It is based on a sample submitted by Jordan Zimmerman // which was apparently causing CCCC to hang. public class Prn15 { public Image get_image(int image_code) { switch ( image_code ) { case cc_def.IMAGE_BUTTON_SUBMIT: case cc_def.IMAGE_BUTTON_SIGN_IN: case cc_def.IMAGE_BUTTON_SEARCH: case cc_def.IMAGE_BUTTON_SEARCH_CATEGORIES: case cc_def.IMAGE_BUTTON_PREVIOUS: case cc_def.IMAGE_BUTTON_PREVIOUS_GRAY: case cc_def.IMAGE_BUTTON_NEXT: case cc_def.IMAGE_BUTTON_NEXT_GRAY: case cc_def.IMAGE_BUTTON_GO_NAV: case cc_def.IMAGE_BUTTON_SIGN_IN_SECURE: case cc_def.IMAGE_BUTTON_GO_CONTENT: case cc_def.IMAGE_BUTTON_OK: case cc_def.IMAGE_CCMOS_BUTTON_OK: case cc_def.IMAGE_CCMOS_BUTTON_CANCEL: case cc_def.IMAGE_BUTTON_CANCEL: case cc_def.IMAGE_BUTTON_ADD_TO_CART: case cc_def.IMAGE_BUTTON_SAVE_TO_REGISTRY: case cc_def.IMAGE_BUTTON_ADD_CREDIT_CARD: case cc_def.IMAGE_BUTTON_ADD_REMINDER: case cc_def.IMAGE_BUTTON_UPDATE_REMINDER: case cc_def.IMAGE_BUTTON_CANCEL_REMINDER: case cc_def.IMAGE_BUTTON_SUGGEST_GIFTS: case cc_def.IMAGE_BUTTON_CONTINUE_SHOPPING_SMALL: case cc_def.IMAGE_BUTTON_CREATE_REGISTRY: case cc_def.IMAGE_BUTTON_UPDATE_REGISTRY: case cc_def.IMAGE_BUTTON_DELETE_REGISTRY: case cc_def.IMAGE_BUTTON_CONTINUE_SECURE: case cc_def.IMAGE_BUTTON_SEND_EMAIL: case cc_def.IMAGE_BUTTON_REDEEM_COUPON: case cc_def.IMAGE_BUTTON_REDEEM_CERTIFICATE: case cc_def.IMAGE_BUTTON_SHOW_CREDIT_BALANCE: case cc_def.IMAGE_BUTTON_HELP: case cc_def.IMAGE_BUTTON_CONTINUE: case cc_def.IMAGE_BUTTON_BACK: case cc_def.IMAGE_BUTTON_SHIP_IT: case cc_def.IMAGE_BUTTON_SKIP_TOUR: case cc_def.IMAGE_BUTTON_ECARD_PERSONALIZE: case cc_def.IMAGE_BUTTON_ECARD_VIEW: case cc_def.IMAGE_BUTTON_ECARD_SEND: case cc_def.IMAGE_BUTTON_ENTER: case cc_def.IMAGE_BUTTON_ADD_ADDRESS: { try { return get_dynamic_button(image_code); } catch ( ServletException the_exception ) { the_exception.printStackTrace(); return null; } } default: return null; } return null; } } cccc-3.1.4/test/prn15.xmlref0000644000000000000000000001071007724312663014264 0ustar rootroot Image Prn15 Image Prn15 definition get_image(int) definition Image Prn15 Image Prn15 Image Prn15 true false return type Prn15 Image true false return type <file scope items> cccc-3.1.4/test/prn16.dbref0000644000000000000000000000155210020121651014030 0ustar rootrootCCCC_Module@ImageOps@class@ CCCC_ModExt@ImageOps@class@prn16.java@35@definition@?????@LOC:3 COM:30 MVG:0@?@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@ImageOps@ImageOps@@()@ CCCC_MemExt@ImageOps@ImageOps@@()@prn16.java@37@definition@????0@LOC:1 COM:0 MVG:1@?@d@ CCCC_RejExt@prn16.java@1@@?????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn16.htmlref0000644000000000000000000002730110020121651014407 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 4 4.000
    McCabe's Cyclomatic NumberMVG 1 1.000
    Lines of CommentCOM 3030.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    ImageOps 4 1 30------------

    Procedural Metrics Detail

    ImageOps
    definition   prn16.java:35

    LOCMVGCOML_CM_C
    ImageOps(   )
    definition   prn16.java:37

    1 1 0------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    ImageOps 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    ImageOps 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    ImageOps    

    Other Extents

    LocationTextLOCCOMMVG
    prn16.java:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn16.java0000644000000000000000000000300307724305720013702 0ustar rootroot// prn16.java // This file is a minimal test case for a problem // reported by Colin Watson (maintainer of CCCC for // the Debian Linux distribution). // The problem reported by Colin related to unit test // prn14, for which the generated .db file differed // from the reference copy on some (but not all) // architecture platforms. The difference was the // inclusion in the .db file of a line which read: // CCCC_Module@@@ // This line implies that a module with an empty string // as its name has been added to the internal database // for some reason. // Colin was kind enough to investigate the problem and // come up with a minimal sample which triggered the problem // which the code of this example is based on. // On investigation, I found that the addition of the // module with the empty name is occurring as a result // of the parser executing the action associated with // the 'implementsClause' rule defined in java.g // despite the fact that the 'implements' keyword // does not appear (outside the comment) in the sample // code. The action for this rule contains a call // to ParseStore::record_userel_extent. // For the moment, I lack the energy to work out why // the generated parser code is executing this action, // however I have modified the code of record_userel_extent // to check client and server name and do // nothing if either is the empty string. public class ImageOps /* implements ChangeListener */ { public ImageOps() { for (int i = 0;;) {} } } cccc-3.1.4/test/prn16.xmlref0000644000000000000000000000601710020121651014244 0ustar rootroot ImageOps ImageOps definition ImageOps() definition ImageOps ImageOps ImageOps <file scope items> cccc-3.1.4/test/prn2.cc0000644000000000000000000000061407265351232013265 0ustar rootroot/* * A L F _ PRINT. C X X * * This file contains print routines for ALF. * * Copyright (c) 1998, Sente Inc. * * $Id: prn2.cc,v 1.1.1.1 2001/04/12 16:06:50 tim_littlefair Exp $ */ #include #include "utils.h" #include "AlfObject.hxx" void alfPrintSpaces(int numTabs, FILE* fp) { int numBlanks; for (numBlanks = 0; numBlanks < 4*numTabs; numBlanks++) fprintf(fp,"%c",' '); } cccc-3.1.4/test/prn2.dbref0000644000000000000000000000146007724312663013767 0ustar rootrootCCCC_Module@anonymous@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@anonymous@alfPrintSpaces@@(int,FILE *)@ CCCC_MemExt@anonymous@alfPrintSpaces@@(int,FILE *)@prn2.cc@15@definition@F????@LOC:6 COM:9 MVG:1@?@d@ CCCC_RejExt@prn2.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn2.htmlref0000644000000000000000000002716107724312663014354 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 6 6.000
    McCabe's Cyclomatic NumberMVG 1 1.000
    Lines of CommentCOM 9 9.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    anonymous 6 1 9------------

    Procedural Metrics Detail

    anonymous

    LOCMVGCOML_CM_C
    alfPrintSpaces(  int,  FILE * )
    definition   prn2.cc:15

    6 1 9------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    anonymous 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    anonymous 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    anonymous    

    Other Extents

    LocationTextLOCCOMMVG
    prn2.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn2.xmlref0000644000000000000000000000566107724312663014211 0ustar rootroot anonymous anonymous alfPrintSpaces(int,FILE *) definition anonymous anonymous anonymous <file scope items> cccc-3.1.4/test/prn3.cc0000644000000000000000000000570407265351241013273 0ustar rootroot/* From: Ruppert Reply-To: Ruppert To: tim_littlefair@hotmail.com Save Address CC: ru@swb.siemens.de Save Address Subject: cccc-3.pre39: Parser errors Date: Tue, 23 May 2000 09:23:16 +0200 (MET DST) Hi, I have just played around a bit with cccc-3.pre39 and tried to analyze a large body of C++ code with it. It worked quite well, and the results look quite useful. The parser emits, however, a number of syntax errors, which I could track to a few specific code constructs. These constructs are legal C/C++, but the cccc parser generates "syntax error" messages. I have stripped down the problems to the constructs in question; I enclose a small test program which exhibits all of them. I hope this is useful for fixing this. Best Regards Dr. D.Ruppert RTS GmbH Schwieberdingen/Germany ru@swb.siemens.de */ /* Problem with inline attribute in class header: Processing test.cc as C/C++ (c++.ansi) test.cc(9) syntax error at token inline Parser context: test.cc(9): trying to match class_block_item_list at 'inline */ class InlFunc { public: InlFunc(); ~InlFunc(); inline getFunc(); }; /* Problem with Initialization by function invoc. at file scope: Processing test.cc as C/C++ (c++.ansi) test.cc(2) syntax error at token ( Parser context: test.cc(2): trying to match instance_declaration at 'const */ static const double d = sqrt(1.0 / 0.003); /* Problem with function pointer as class member: test.cc(6) syntax error at token int Parser context: test.cc(6): trying to match class_block_item_list at 'int */ int getInt(); class FP { public: int (*getInt)(); }; /* Problem with anonymous struct type: test.cc(5) syntax error at token struct Parser context: test.cc(5): trying to match class_block_item_list at 'struct */ struct A { int a; struct { double d; float e; } myS; }; /* Problem with / in initializer for int: Processing test.cc as C/C++ (c++.ansi) test.cc(1) syntax error at token / Parser context: test.cc(1): trying to match instance_declaration at 'const */ const int myInt = 10 / 4; /* Problem with literal 0. in float-Initializer: invalid token near line 2 (text was '0.') test.cc(2) syntax error at token ; */ float f = 0. ; /* Problem with anonymous union: Processing test.cc as C/C++ (c++.ansi) test.cc(6) syntax error at token union Parser context: test.cc(6): trying to match class_block_item_list at 'union */ class Hugo_2 { public: Hugo_2(); ~Hugo_2(); union { int a; double b; }; }; /* Problem with anonymous enum: Processing test.cc as C/C++ (c++.ansi) test.cc(7) syntax error at token enum Parser context: test.cc(7): trying to match class_block_item_list at 'enum ... */ class Hugo { public: Hugo(); ~Hugo(); enum { START, STOP }; }; cccc-3.1.4/test/prn3.dbref0000644000000000000000000000403207724312663013766 0ustar rootrootCCCC_Module@A@struct@ CCCC_ModExt@A@struct@prn3.cc@93@definition@FT??0@LOC:9 COM:6 MVG:0@0@d@ CCCC_Module@FP@class@ CCCC_ModExt@FP@class@prn3.cc@77@definition@FT??2@LOC:5 COM:0 MVG:0@2@d@ CCCC_Module@Hugo@class@ CCCC_ModExt@Hugo@class@prn3.cc@156@definition@FT??2@LOC:9 COM:9 MVG:0@2@d@ CCCC_Module@Hugo_2@class@ CCCC_ModExt@Hugo_2@class@prn3.cc@134@definition@FT??2@LOC:9 COM:8 MVG:0@2@d@ CCCC_Module@InlFunc@class@ CCCC_ModExt@InlFunc@class@prn3.cc@47@definition@F???2@LOC:4 COM:43 MVG:0@2@d@ CCCC_Module@anonymous@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Hugo@Hugo@@()@ CCCC_MemExt@Hugo@Hugo@@()@prn3.cc@159@declaration@FT??0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Hugo@~Hugo@@()@ CCCC_MemExt@Hugo@~Hugo@@()@prn3.cc@160@declaration@FT??0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Hugo_2@Hugo_2@@()@ CCCC_MemExt@Hugo_2@Hugo_2@@()@prn3.cc@137@declaration@FT??0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Hugo_2@~Hugo_2@@()@ CCCC_MemExt@Hugo_2@~Hugo_2@@()@prn3.cc@138@declaration@FT??0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@InlFunc@InlFunc@@()@ CCCC_MemExt@InlFunc@InlFunc@@()@prn3.cc@50@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@InlFunc@getFunc@@()@ CCCC_MemExt@InlFunc@getFunc@@()@prn3.cc@52@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@InlFunc@~InlFunc@@()@ CCCC_MemExt@InlFunc@~InlFunc@@()@prn3.cc@51@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@anonymous@getInt@@()@ CCCC_MemExt@anonymous@getInt@@()@prn3.cc@76@declaration@FT??2@LOC:1 COM:6 MVG:0@2@D@ CCCC_RejExt@prn3.cc@1@@FT??2@LOC:3 COM:21 MVG:0@2@r@ cccc-3.1.4/test/prn3.htmlref0000644000000000000000000004562007724312663014355 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 5 
    Lines of CodeLOC 47 9.400
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 9318.600
    LOC/COML_C 0.505 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 3 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    FP 5 0 0------------
    Hugo 11 0 9------------
    Hugo_2 11 0 8------------
    InlFunc 7 0 43------------
    anonymous 1 0 6------------

    Procedural Metrics Detail

    A
    definition   prn3.cc:93

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    FP
    definition   prn3.cc:77

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Hugo
    definition   prn3.cc:156

    LOCMVGCOML_CM_C
    Hugo(   )
    declaration   prn3.cc:159

    1 0 0------------
    ~Hugo(   )
    declaration   prn3.cc:160

    1 0 0------------
    Hugo_2
    definition   prn3.cc:134

    LOCMVGCOML_CM_C
    Hugo_2(   )
    declaration   prn3.cc:137

    1 0 0------------
    ~Hugo_2(   )
    declaration   prn3.cc:138

    1 0 0------------
    InlFunc
    definition   prn3.cc:47

    LOCMVGCOML_CM_C
    InlFunc(   )
    declaration   prn3.cc:50

    1 0 0------------
    getFunc(   )
    declaration   prn3.cc:52

    1 0 0------------
    ~InlFunc(   )
    declaration   prn3.cc:51

    1 0 0------------
    anonymous

    LOCMVGCOML_CM_C
    getInt(   )
    declaration   prn3.cc:76

    1 0 6------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    FP 0 0 0 0 0
    Hugo 2 2 0 0 0
    Hugo_2 2 2 0 0 0
    InlFunc 3 3 0 0 0
    anonymous 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    FP 0 0 0 0 0 0 0 0 0
    Hugo 0 0 0 0 0 0 0 0 0
    Hugo_2 0 0 0 0 0 0 0 0 0
    InlFunc 0 0 0 0 0 0 0 0 0
    anonymous 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    FP    
    Hugo    
    Hugo_2    
    InlFunc    
    anonymous    

    Other Extents

    LocationTextLOCCOMMVG
    prn3.cc:1
    <file scope items> 3 21 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn3.xmlref0000644000000000000000000002551007724312663014205 0ustar rootroot FP Hugo Hugo_2 InlFunc anonymous A definition FP definition Hugo definition Hugo() declaration ~Hugo() declaration Hugo_2 definition Hugo_2() declaration ~Hugo_2() declaration InlFunc definition InlFunc() declaration getFunc() declaration ~InlFunc() declaration anonymous getInt() declaration FP Hugo Hugo_2 InlFunc anonymous FP Hugo Hugo_2 InlFunc anonymous FP Hugo Hugo_2 InlFunc anonymous <file scope items> cccc-3.1.4/test/prn4.cc0000644000000000000000000000063707265351252013276 0ustar rootroot// prn4.cc // Classes with namespace qualifiers should have their name // reduced to the final component. In versions prior to 3.pre45 // this did not happen. On Unix systems the result was reports // with names like std::string.html. On Win32, the colon is not // legal in file names and the report generation process terminates early. void MyClass::someFunction(const std::string& s) { // do nothing } cccc-3.1.4/test/prn4.dbref0000644000000000000000000000164207265351252013770 0ustar rootrootCCCC_Module@MyClass@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@string@@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@MyClass@someFunction@@(const string &)@ CCCC_MemExt@MyClass@someFunction@@(const string &)@prn4.cc@9@definition@F????@LOC:3 COM:7 MVG:0@?@d@ CCCC_UseRel@string@MyClass@ CCCC_UseExt@string@MyClass@prn4.cc@9@pass by reference@?????@*@?@p@ CCCC_RejExt@prn4.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn4.htmlref0000644000000000000000000003205607715623450014354 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 2 
    Lines of CodeLOC 3 1.500
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 7 3.500
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    MyClass 3 0 7------------
    string 0 0 0------------

    Procedural Metrics Detail

    MyClass

    LOCMVGCOML_CM_C
    someFunction(  const string & )
    definition   prn4.cc:9

    3 0 7------------
    string

    LOCMVGCOML_CM_C
    No member functions have been identified for this module

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    MyClass 1 0 0 0 1
    string 0 0 0 0 1

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    MyClass 0 0 0 1 0 1 0 0 0
    string 1 0 1 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    MyClass   string [V]
    pass by reference   prn4.cc:9


     
    string MyClass [V]
    pass by reference   prn4.cc:9


     
     

    Other Extents

    LocationTextLOCCOMMVG
    prn4.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn4.xmlref0000644000000000000000000001057207715610506014205 0ustar rootroot MyClass string MyClass someFunction(const string &) definition string MyClass string MyClass string MyClass string true false pass by reference string MyClass true false pass by reference <file scope items> cccc-3.1.4/test/prn5.cc0000644000000000000000000000036307265351260013272 0ustar rootroot// prn5.cc // Prior to version 3.pre45, use of builtin types like char, int // in parameter lists led to spurious relationships being registered // to non-existent types 'char ', 'int '. void MyClass::someFunction(char c) { // do nothing } cccc-3.1.4/test/prn5.dbref0000644000000000000000000000143107265351260013764 0ustar rootrootCCCC_Module@MyClass@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@MyClass@someFunction@@(char)@ CCCC_MemExt@MyClass@someFunction@@(char)@prn5.cc@6@definition@F????@LOC:3 COM:5 MVG:0@?@d@ CCCC_RejExt@prn5.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn5.htmlref0000644000000000000000000002712107715623450014352 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 3 3.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 5 5.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    MyClass 3 0 5------------

    Procedural Metrics Detail

    MyClass

    LOCMVGCOML_CM_C
    someFunction(  char )
    definition   prn5.cc:6

    3 0 5------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    MyClass 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    MyClass 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    MyClass    

    Other Extents

    LocationTextLOCCOMMVG
    prn5.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn5.xmlref0000644000000000000000000000563607715610507014214 0ustar rootroot MyClass MyClass someFunction(char) definition MyClass MyClass MyClass <file scope items> cccc-3.1.4/test/prn6.cc0000644000000000000000000000031707265351263013275 0ustar rootroot int64 bbb::mbr = aaa::b01 | aaa::b02 | aaa::b02 | aaa::b03 | aaa::b04 | aaa::b05 | aaa::b06 | aaa::b07 | aaa::b08 | aaa::b09 | aaa::b10 | aaa::b11 | aaa::b12 | aaa::b13 | aaa::b14; cccc-3.1.4/test/prn6.dbref0000644000000000000000000000117707724312663014000 0ustar rootrootCCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_RejExt@prn6.cc@1@@?????@LOC:16 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn6.htmlref0000644000000000000000000002431107724312663014352 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 0 
    Lines of CodeLOC 16******
    McCabe's Cyclomatic NumberMVG 0******
    Lines of CommentCOM 0******
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0********
    Information Flow measure (  visible )IF4v 0********
    Information Flow measure (  concrete )IF4c 0********
    Lines of Code rejected by parserREJ 16 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C

    Procedural Metrics Detail

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc

    Structural Metrics Detail

    Module NameClientsSuppliers

    Other Extents

    LocationTextLOCCOMMVG
    prn6.cc:1
    <file scope items> 16 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn6.xmlref0000644000000000000000000000260507724312663014210 0ustar rootroot <file scope items> cccc-3.1.4/test/prn7.c0000755000000000000000000000335007271572210013130 0ustar rootroot// prn7.c // Test case submitted by Larry Peters of ATI // ******************************************************************** // * // * cccc Sample code // * // ******************************************************************** #include /////////////////////////////////////////////////////////////////////// // First issue has to do with struct typedefs using the ugly MS style // of declaring pointer typedefs for the struct following the struct // definition: typedef struct MY_STRUCT { int _iVal; long _lVal; char *_pszVal; } MYSTRUCT,*PMYSTRUCT,*LPMYSTRUCT; // These last two cause errors! /////////////////////////////////////////////////////////////////////// // The second issue has to do with multiple line string literals. // There are two problems here: the first is handling multiple line // literals -- should just be a grammar change (see below). The second // problem I think may require a pre-processor (yuck). Take a look and // let me know what you think: char szSimpleOne[] = "Test 1" "This is OK too" "so is this!"; // Ugly but legal... /* // This one is too hard for the time being. // I can't see a way to fix it without going against the // design rule that CCCC does not run (or fake) the preprocessor #define MY_STR "BLAH!" char szDifficultOne[] = "Test 1" MY_STR "yuck!"; // Again, ugly but legal... */ /////////////////////////////////////////////////////////////////////// // This last one involves using the sizeof operator in the "global" // scope. // This one fails long lVal = sizeof( long ); void main() { // This one works! long lVal2 = sizeof( long ); } cccc-3.1.4/test/prn7.dbref0000644000000000000000000000140707724312663013775 0ustar rootrootCCCC_Module@anonymous@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@anonymous@main@@()@ CCCC_MemExt@anonymous@main@@()@prn7.c@49@definition@F???0@LOC:4 COM:1 MVG:0@0@d@ CCCC_RejExt@prn7.c@1@@F???0@LOC:9 COM:33 MVG:0@0@r@ cccc-3.1.4/test/prn7.htmlref0000644000000000000000000002712207715623450014355 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 1313.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 3434.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 9 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    anonymous 4 0 1------------

    Procedural Metrics Detail

    anonymous

    LOCMVGCOML_CM_C
    main(   )
    definition   prn7.c:49

    4 0 1------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    anonymous 1 1 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    anonymous 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    anonymous    

    Other Extents

    LocationTextLOCCOMMVG
    prn7.c:1
    <file scope items> 9 33 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn7.xmlref0000644000000000000000000000564007715610507014211 0ustar rootroot anonymous anonymous main() definition anonymous anonymous anonymous <file scope items> cccc-3.1.4/test/prn8.dbref0000644000000000000000000000163507724312663014001 0ustar rootrootCCCC_Module@EwoisErrorHandler@class@ CCCC_ModExt@EwoisErrorHandler@class@prn8.java@5@definition@?????@LOC:5 COM:3 MVG:0@?@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@EwoisErrorHandler@handleError@void@(int)@ CCCC_MemExt@EwoisErrorHandler@handleError@void@(int)@prn8.java@7@definition@????0@LOC:15 COM:0 MVG:5@?@d@ CCCC_RejExt@prn8.java@1@@?????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/prn8.htmlref0000644000000000000000000002740707724312663014365 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 2020.000
    McCabe's Cyclomatic NumberMVG 5 5.000
    Lines of CommentCOM 3 3.000
    LOC/COML_C 6.667 
    MVG/COMM_C 1.667 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    EwoisErrorHandler 20 5 3 6.667 1.667

    Procedural Metrics Detail

    EwoisErrorHandler
    definition   prn8.java:5

    LOCMVGCOML_CM_C
    handleError(  int )
    definition   prn8.java:7

    15 5 0------******

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    EwoisErrorHandler 1 0 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    EwoisErrorHandler 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    EwoisErrorHandler    

    Other Extents

    LocationTextLOCCOMMVG
    prn8.java:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn8.java0000644000000000000000000000071107401205042013612 0ustar rootroot// prn8.java // SF Bugtracker bug #226676 // reported by Eric Pischel public class EwoisErrorHandler { public synchronized void handleError( int fehlertyp ) { String lvTyp = ""; switch (fehlertyp) { case WARNING: lvTyp = "Warnung"; break; case LOGINFO: lvTyp = "LogInfo"; break; } StringBuffer buffer = new StringBuffer(lvTyp); buffer.append("Zeit: ").append(""); } int WARNING = 1; int LOGINFO = 2; } cccc-3.1.4/test/prn8.out0000644000000000000000000010264107401205042013505 0ustar rootrootCCCC - a code counter for C and C++ =================================== A program to analyse C and C++ source code and report on some simple software metrics Version Copyright Tim Littlefair, 1995, 1996, 1997, 1998, 1999, 2000 with contributions from Bill McLean, Herman Hueni, Lynn Wilson Peter Bell, Thomas Hieber and Kenneth H. Cox. The development of this program was heavily dependent on the Purdue Compiler Construction Tool Set (PCCTS) by Terence Parr, Will Cohen, Hank Dietz, Russel Quoung, Tom Moog and others. This software is provided with NO WARRANTY Parsing Processing prn8.java as Java TOK: public 0 0 makeToken(tt=>101, txt=>public,line=>5) TOK: class 0 0 makeToken(tt=>76, txt=>class,line=>5) 5 101public -> compilationUnit 5 101 public -> typeDefinition 5 101 public -> modifiers 5 101 public -> modifier TOK: EwoisErrorHandler 0 0 makeToken(tt=>121, txt=>EwoisErrorHandler,line=>5) 5 76 class <- modifier 5 76 class <- modifiers 5 76 class -> classDefinition TOK: { 0 0 makeToken(tt=>7, txt=>{,line=>6) TOK: public 0 0 makeToken(tt=>101, txt=>public,line=>7) 6 7 { -> superClassClause 6 7 { <- superClassClause 6 7 { -> implementsClause 6 7 { <- implementsClause 6 7 { -> classBlock TOK: synchronized 0 0 makeToken(tt=>109, txt=>synchronized,line=>7) 7 101 public -> field 7 101 public -> modifiers 7 101 public -> modifier TOK: void 0 0 makeToken(tt=>118, txt=>void,line=>7) 7 109 synchronized <- modifier 7 109 synchronized -> modifier TOK: handleError 0 0 makeToken(tt=>121, txt=>handleError,line=>7) 7 118 void <- modifier 7 118 void <- modifiers 7 118 void -> typeSpec2 7 118 void -> builtInTypeSpec2 7 118 void -> builtInType TOK: ( 0 0 makeToken(tt=>3, txt=>(,line=>7) 7 121 handleError <- builtInType 7 121 handleError <- builtInTypeSpec2 7 121 handleError <- typeSpec2 7 121 handleError -> typedDeclaration 7 121 handleError -> methodDefinition TOK: int 0 0 makeToken(tt=>92, txt=>int,line=>7) TOK: fehlertyp 0 0 makeToken(tt=>121, txt=>fehlertyp,line=>7) 7 92 int -> parameterDeclarationList 7 92 int -> parameterDeclaration 7 92 int -> parameterModifier 7 92 int <- parameterModifier 7 92 int -> typeSpec2 7 92 int -> builtInTypeSpec2 7 92 int -> builtInType TOK: ) 0 0 makeToken(tt=>4, txt=>),line=>7) 7 121 fehlertyp <- builtInType 7 121 fehlertyp <- builtInTypeSpec2 7 121 fehlertyp <- typeSpec2 TOK: { 0 0 makeToken(tt=>7, txt=>{,line=>8) 7 4 ) -> parameterDeclaratorBrackets 7 4 ) <- parameterDeclaratorBrackets 7 4 ) <- parameterDeclaration 7 4 ) <- parameterDeclarationList TOK: String 0 0 makeToken(tt=>121, txt=>String,line=>9) 8 7 { -> returnTypeBrackersOnEndOfMethodHead 8 7 { <- returnTypeBrackersOnEndOfMethodHead 8 7 { -> compoundStatement TOK: lvTyp 0 0 makeToken(tt=>121, txt=>lvTyp,line=>9) 9 121 String -> statement 9 121 String -> ?declaration 9 121 String -> ?modifiers 9 121 String <- ?modifiers 9 121 String -> ?typeSpec 9 121 String -> ?classTypeSpec 9 121 String -> ?identifier TOK: = 0 0 makeToken(tt=>12, txt=>=,line=>9) 9 121 lvTyp <- ?identifier 9 121 lvTyp <- ?classTypeSpec 9 121 lvTyp <- ?typeSpec 9 121 lvTyp -> ?variableDefinitions 9 121 lvTyp -> ?variableDeclarator TOK: " 0 0 makeToken(tt=>64, txt=>",line=>9) 9 12 = -> ?declaratorBrackets 9 12 = <- ?declaratorBrackets 9 12 = -> ?varInitializer TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>9) 9 64 " -> ?initializer 9 64 " -> ?expression 9 64 " -> ?assignmentExpression 9 64 " -> ?conditionalExpression 9 64 " -> ?logicalOrExpression 9 64 " -> ?logicalAndExpression 9 64 " -> ?inclusiveOrExpression 9 64 " -> ?exclusiveOrExpression 9 64 " -> ?andExpression 9 64 " -> ?equalityExpression 9 64 " -> ?relationalExpression 9 64 " -> ?shiftExpression 9 64 " -> ?additiveExpression 9 64 " -> ?multiplicativeExpression 9 64 " -> ?unaryExpression 9 64 " -> ?unaryExpressionNotPlusMinus 9 64 " -> ?postfixExpression 9 64 " -> ?primaryExpression 9 64 " -> ?constant TOK: switch 0 0 makeToken(tt=>108, txt=>switch,line=>10) 9 47 ; <- ?constant 9 47 ; <- ?primaryExpression 9 47 ; <- ?postfixExpression 9 47 ; <- ?unaryExpressionNotPlusMinus 9 47 ; <- ?unaryExpression 9 47 ; <- ?multiplicativeExpression 9 47 ; <- ?additiveExpression 9 47 ; <- ?shiftExpression 9 47 ; <- ?relationalExpression 9 47 ; <- ?equalityExpression 9 47 ; <- ?andExpression 9 47 ; <- ?exclusiveOrExpression 9 47 ; <- ?inclusiveOrExpression 9 47 ; <- ?logicalAndExpression 9 47 ; <- ?logicalOrExpression 9 47 ; <- ?conditionalExpression 9 47 ; <- ?assignmentExpression 9 47 ; <- ?expression 9 47 ; <- ?initializer 9 47 ; <- ?varInitializer 9 47 ; <- ?variableDeclarator 9 47 ; <- ?variableDefinitions 9 47 ; <- ?declaration 9 121 String -> declaration 9 121 String -> modifiers 9 121 String <- modifiers 9 121 String -> typeSpec 9 121 String -> classTypeSpec 9 121 String -> identifier 9 121 lvTyp <- identifier 9 121 lvTyp <- classTypeSpec 9 121 lvTyp <- typeSpec 9 121 lvTyp -> variableDefinitions 9 121 lvTyp -> variableDeclarator 9 12 = -> declaratorBrackets 9 12 = <- declaratorBrackets 9 12 = -> varInitializer 9 64 " -> initializer 9 64 " -> expression 9 64 " -> assignmentExpression 9 64 " -> conditionalExpression 9 64 " -> logicalOrExpression 9 64 " -> logicalAndExpression 9 64 " -> inclusiveOrExpression 9 64 " -> exclusiveOrExpression 9 64 " -> andExpression 9 64 " -> equalityExpression 9 64 " -> relationalExpression 9 64 " -> shiftExpression 9 64 " -> additiveExpression 9 64 " -> multiplicativeExpression 9 64 " -> unaryExpression 9 64 " -> unaryExpressionNotPlusMinus 9 64 " -> postfixExpression 9 64 " -> primaryExpression 9 64 " -> constant 9 47 ; <- constant 9 47 ; <- primaryExpression 9 47 ; <- postfixExpression 9 47 ; <- unaryExpressionNotPlusMinus 9 47 ; <- unaryExpression 9 47 ; <- multiplicativeExpression 9 47 ; <- additiveExpression 9 47 ; <- shiftExpression 9 47 ; <- relationalExpression 9 47 ; <- equalityExpression 9 47 ; <- andExpression 9 47 ; <- exclusiveOrExpression 9 47 ; <- inclusiveOrExpression 9 47 ; <- logicalAndExpression 9 47 ; <- logicalOrExpression 9 47 ; <- conditionalExpression 9 47 ; <- assignmentExpression 9 47 ; <- expression 9 47 ; <- initializer 9 47 ; <- varInitializer 9 47 ; <- variableDeclarator 9 47 ; <- variableDefinitions 9 47 ; <- declaration TOK: ( 0 0 makeToken(tt=>3, txt=>(,line=>10) 10 108 switch <- statement 10 108 switch -> statement 10 108 switch -> switchStatement TOK: fehlertyp 0 0 makeToken(tt=>121, txt=>fehlertyp,line=>10) TOK: ) 0 0 makeToken(tt=>4, txt=>),line=>10) 10 121 fehlertyp -> expression 10 121 fehlertyp -> assignmentExpression 10 121 fehlertyp -> conditionalExpression 10 121 fehlertyp -> logicalOrExpression 10 121 fehlertyp -> logicalAndExpression 10 121 fehlertyp -> inclusiveOrExpression 10 121 fehlertyp -> exclusiveOrExpression 10 121 fehlertyp -> andExpression 10 121 fehlertyp -> equalityExpression 10 121 fehlertyp -> relationalExpression 10 121 fehlertyp -> shiftExpression 10 121 fehlertyp -> additiveExpression 10 121 fehlertyp -> multiplicativeExpression 10 121 fehlertyp -> unaryExpression 10 121 fehlertyp -> unaryExpressionNotPlusMinus 10 121 fehlertyp -> postfixExpression 10 121 fehlertyp -> primaryExpression TOK: { 0 0 makeToken(tt=>7, txt=>{,line=>11) 10 4 ) <- primaryExpression 10 4 ) <- postfixExpression 10 4 ) <- unaryExpressionNotPlusMinus 10 4 ) <- unaryExpression 10 4 ) <- multiplicativeExpression 10 4 ) <- additiveExpression 10 4 ) <- shiftExpression 10 4 ) <- relationalExpression 10 4 ) <- equalityExpression 10 4 ) <- andExpression 10 4 ) <- exclusiveOrExpression 10 4 ) <- inclusiveOrExpression 10 4 ) <- logicalAndExpression 10 4 ) <- logicalOrExpression 10 4 ) <- conditionalExpression 10 4 ) <- assignmentExpression 10 4 ) <- expression TOK: case 0 0 makeToken(tt=>121, txt=>case,line=>12) TOK: WARNING 0 0 makeToken(tt=>121, txt=>WARNING,line=>12) prn8.java(12): syntax error at token case prn8.java(10): trying to match switchStatement at 'switch' 12 121 case <- switchStatement 12 121 case <- statement 12 121 case -> statement 12 121 case -> ?declaration 12 121 case -> ?modifiers 12 121 case <- ?modifiers 12 121 case -> ?typeSpec 12 121 case -> ?classTypeSpec 12 121 case -> ?identifier TOK: : 0 0 makeToken(tt=>9, txt=>:,line=>12) 12 121 WARNING <- ?identifier 12 121 WARNING <- ?classTypeSpec 12 121 WARNING <- ?typeSpec 12 121 WARNING -> ?variableDefinitions 12 121 WARNING -> ?variableDeclarator TOK: lvTyp 0 0 makeToken(tt=>121, txt=>lvTyp,line=>13) 12 9 : -> ?declaratorBrackets 12 9 : <- ?declaratorBrackets 12 9 : -> ?varInitializer 12 9 : <- ?varInitializer 12 9 : <- ?variableDeclarator 12 9 : <- ?variableDefinitions 12 9 : <- ?declaration 12 121 case -> declaration 12 121 case -> modifiers 12 121 case <- modifiers 12 121 case -> typeSpec 12 121 case -> classTypeSpec 12 121 case -> identifier 12 121 WARNING <- identifier 12 121 WARNING <- classTypeSpec 12 121 WARNING <- typeSpec 12 121 WARNING -> variableDefinitions 12 121 WARNING -> variableDeclarator 12 9 : -> declaratorBrackets 12 9 : <- declaratorBrackets 12 9 : -> varInitializer 12 9 : <- varInitializer 12 9 : <- variableDeclarator 12 9 : <- variableDefinitions 12 9 : <- declaration prn8.java(12): syntax error at token : prn8.java(12): trying to match statement at 'case' freeing token public on line 5 c1:1 c2:27 c3:0 freed:1 freeing token class on line 5 c1:1 c2:27 c3:0 freed:2 freeing token { on line 6 c1:1 c2:27 c3:0 freed:3 freeing token public on line 7 c1:1 c2:27 c3:0 freed:4 freeing token synchronized on line 7 c1:1 c2:27 c3:0 freed:5 freeing token void on line 7 c1:1 c2:27 c3:0 freed:6 freeing token ( on line 7 c1:1 c2:27 c3:0 freed:7 freeing token int on line 7 c1:1 c2:27 c3:0 freed:8 freeing token fehlertyp on line 7 c1:1 c2:27 c3:0 freed:9 freeing token ) on line 7 c1:1 c2:27 c3:0 freed:10 freeing token { on line 8 c1:1 c2:27 c3:0 freed:11 freeing token String on line 9 c1:1 c2:27 c3:0 freed:12 freeing token lvTyp on line 9 c1:1 c2:27 c3:0 freed:13 freeing token = on line 9 c1:1 c2:27 c3:0 freed:14 freeing token " on line 9 c1:1 c2:27 c3:0 freed:15 freeing token ; on line 9 c1:1 c2:27 c3:0 freed:16 freeing token switch on line 10 c1:1 c2:27 c3:0 freed:17 freeing token ( on line 10 c1:1 c2:27 c3:0 freed:18 freeing token fehlertyp on line 10 c1:1 c2:27 c3:0 freed:19 freeing token ) on line 10 c1:1 c2:27 c3:0 freed:20 freeing token { on line 11 c1:1 c2:27 c3:0 freed:21 freeing token case on line 12 c1:1 c2:27 c3:0 freed:22 freeing token WARNING on line 12 c1:1 c2:27 c3:0 freed:23 freeing token : on line 12 c1:1 c2:27 c3:0 freed:24 TOK: = 0 0 makeToken(tt=>12, txt=>=,line=>13) 13 121 lvTyp <- statement 13 121 lvTyp -> statement 13 121 lvTyp -> expression 13 121 lvTyp -> assignmentExpression 13 121 lvTyp -> conditionalExpression 13 121 lvTyp -> logicalOrExpression 13 121 lvTyp -> logicalAndExpression 13 121 lvTyp -> inclusiveOrExpression 13 121 lvTyp -> exclusiveOrExpression 13 121 lvTyp -> andExpression 13 121 lvTyp -> equalityExpression 13 121 lvTyp -> relationalExpression 13 121 lvTyp -> shiftExpression 13 121 lvTyp -> additiveExpression 13 121 lvTyp -> multiplicativeExpression 13 121 lvTyp -> unaryExpression 13 121 lvTyp -> unaryExpressionNotPlusMinus 13 121 lvTyp -> postfixExpression 13 121 lvTyp -> primaryExpression TOK: " 0 0 makeToken(tt=>64, txt=>",line=>13) 13 12 = <- primaryExpression 13 12 = <- postfixExpression 13 12 = <- unaryExpressionNotPlusMinus 13 12 = <- unaryExpression 13 12 = <- multiplicativeExpression 13 12 = <- additiveExpression 13 12 = <- shiftExpression 13 12 = <- relationalExpression 13 12 = <- equalityExpression 13 12 = <- andExpression 13 12 = <- exclusiveOrExpression 13 12 = <- inclusiveOrExpression 13 12 = <- logicalAndExpression 13 12 = <- logicalOrExpression 13 12 = <- conditionalExpression TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>13) 13 64 " -> assignmentExpression 13 64 " -> conditionalExpression 13 64 " -> logicalOrExpression 13 64 " -> logicalAndExpression 13 64 " -> inclusiveOrExpression 13 64 " -> exclusiveOrExpression 13 64 " -> andExpression 13 64 " -> equalityExpression 13 64 " -> relationalExpression 13 64 " -> shiftExpression 13 64 " -> additiveExpression 13 64 " -> multiplicativeExpression 13 64 " -> unaryExpression 13 64 " -> unaryExpressionNotPlusMinus 13 64 " -> postfixExpression 13 64 " -> primaryExpression 13 64 " -> constant TOK: break 0 0 makeToken(tt=>72, txt=>break,line=>14) 13 47 ; <- constant 13 47 ; <- primaryExpression 13 47 ; <- postfixExpression 13 47 ; <- unaryExpressionNotPlusMinus 13 47 ; <- unaryExpression 13 47 ; <- multiplicativeExpression 13 47 ; <- additiveExpression 13 47 ; <- shiftExpression 13 47 ; <- relationalExpression 13 47 ; <- equalityExpression 13 47 ; <- andExpression 13 47 ; <- exclusiveOrExpression 13 47 ; <- inclusiveOrExpression 13 47 ; <- logicalAndExpression 13 47 ; <- logicalOrExpression 13 47 ; <- conditionalExpression 13 47 ; <- assignmentExpression 13 47 ; <- assignmentExpression 13 47 ; <- expression TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>14) 14 72 break <- statement 14 72 break -> statement 14 72 break -> breakStatement TOK: case 0 0 makeToken(tt=>121, txt=>case,line=>15) TOK: LOGINFO 0 0 makeToken(tt=>121, txt=>LOGINFO,line=>15) 15 121 case <- breakStatement 15 121 case <- statement 15 121 case -> statement 15 121 case -> ?declaration 15 121 case -> ?modifiers 15 121 case <- ?modifiers 15 121 case -> ?typeSpec 15 121 case -> ?classTypeSpec 15 121 case -> ?identifier TOK: : 0 0 makeToken(tt=>9, txt=>:,line=>15) 15 121 LOGINFO <- ?identifier 15 121 LOGINFO <- ?classTypeSpec 15 121 LOGINFO <- ?typeSpec 15 121 LOGINFO -> ?variableDefinitions 15 121 LOGINFO -> ?variableDeclarator TOK: lvTyp 0 0 makeToken(tt=>121, txt=>lvTyp,line=>16) 15 9 : -> ?declaratorBrackets 15 9 : <- ?declaratorBrackets 15 9 : -> ?varInitializer 15 9 : <- ?varInitializer 15 9 : <- ?variableDeclarator 15 9 : <- ?variableDefinitions 15 9 : <- ?declaration 15 121 case -> declaration 15 121 case -> modifiers 15 121 case <- modifiers 15 121 case -> typeSpec 15 121 case -> classTypeSpec 15 121 case -> identifier 15 121 LOGINFO <- identifier 15 121 LOGINFO <- classTypeSpec 15 121 LOGINFO <- typeSpec 15 121 LOGINFO -> variableDefinitions 15 121 LOGINFO -> variableDeclarator 15 9 : -> declaratorBrackets 15 9 : <- declaratorBrackets 15 9 : -> varInitializer 15 9 : <- varInitializer 15 9 : <- variableDeclarator 15 9 : <- variableDefinitions 15 9 : <- declaration prn8.java(15): syntax error at token : prn8.java(15): trying to match statement at 'case' TOK: = 0 0 makeToken(tt=>12, txt=>=,line=>16) 16 121 lvTyp <- statement 16 121 lvTyp -> statement 16 121 lvTyp -> expression 16 121 lvTyp -> assignmentExpression 16 121 lvTyp -> conditionalExpression 16 121 lvTyp -> logicalOrExpression 16 121 lvTyp -> logicalAndExpression 16 121 lvTyp -> inclusiveOrExpression 16 121 lvTyp -> exclusiveOrExpression 16 121 lvTyp -> andExpression 16 121 lvTyp -> equalityExpression 16 121 lvTyp -> relationalExpression 16 121 lvTyp -> shiftExpression 16 121 lvTyp -> additiveExpression 16 121 lvTyp -> multiplicativeExpression 16 121 lvTyp -> unaryExpression 16 121 lvTyp -> unaryExpressionNotPlusMinus 16 121 lvTyp -> postfixExpression 16 121 lvTyp -> primaryExpression TOK: " 0 0 makeToken(tt=>64, txt=>",line=>16) 16 12 = <- primaryExpression 16 12 = <- postfixExpression 16 12 = <- unaryExpressionNotPlusMinus 16 12 = <- unaryExpression 16 12 = <- multiplicativeExpression 16 12 = <- additiveExpression 16 12 = <- shiftExpression 16 12 = <- relationalExpression 16 12 = <- equalityExpression 16 12 = <- andExpression 16 12 = <- exclusiveOrExpression 16 12 = <- inclusiveOrExpression 16 12 = <- logicalAndExpression 16 12 = <- logicalOrExpression 16 12 = <- conditionalExpression TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>16) 16 64 " -> assignmentExpression 16 64 " -> conditionalExpression 16 64 " -> logicalOrExpression 16 64 " -> logicalAndExpression 16 64 " -> inclusiveOrExpression 16 64 " -> exclusiveOrExpression 16 64 " -> andExpression 16 64 " -> equalityExpression 16 64 " -> relationalExpression 16 64 " -> shiftExpression 16 64 " -> additiveExpression 16 64 " -> multiplicativeExpression 16 64 " -> unaryExpression 16 64 " -> unaryExpressionNotPlusMinus 16 64 " -> postfixExpression 16 64 " -> primaryExpression 16 64 " -> constant TOK: break 0 0 makeToken(tt=>72, txt=>break,line=>17) 16 47 ; <- constant 16 47 ; <- primaryExpression 16 47 ; <- postfixExpression 16 47 ; <- unaryExpressionNotPlusMinus 16 47 ; <- unaryExpression 16 47 ; <- multiplicativeExpression 16 47 ; <- additiveExpression 16 47 ; <- shiftExpression 16 47 ; <- relationalExpression 16 47 ; <- equalityExpression 16 47 ; <- andExpression 16 47 ; <- exclusiveOrExpression 16 47 ; <- inclusiveOrExpression 16 47 ; <- logicalAndExpression 16 47 ; <- logicalOrExpression 16 47 ; <- conditionalExpression 16 47 ; <- assignmentExpression 16 47 ; <- assignmentExpression 16 47 ; <- expression TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>17) 17 72 break <- statement 17 72 break -> statement 17 72 break -> breakStatement TOK: } 0 0 makeToken(tt=>8, txt=>},line=>18) TOK: StringBuffer 0 0 makeToken(tt=>121, txt=>StringBuffer,line=>19) 18 8 } <- breakStatement 18 8 } <- statement TOK: buffer 0 0 makeToken(tt=>121, txt=>buffer,line=>19) 19 121 StringBuffer <- compoundStatement 19 121 StringBuffer <- methodDefinition freeing token handleError on line 7 c1:1 c2:44 c3:0 freed:25 19 121 StringBuffer <- typedDeclaration 19 121 StringBuffer <- field 19 121 StringBuffer -> field 19 121 StringBuffer -> modifiers 19 121 StringBuffer <- modifiers 19 121 StringBuffer -> typeSpec2 19 121 StringBuffer -> classTypeSpec2 19 121 StringBuffer -> identifier2 TOK: = 0 0 makeToken(tt=>12, txt=>=,line=>19) 19 121 buffer <- identifier2 19 121 buffer <- classTypeSpec2 19 121 buffer <- typeSpec2 19 121 buffer -> typedDeclaration 19 121 buffer -> variableDefinitions 19 121 buffer -> variableDeclarator TOK: new 0 0 makeToken(tt=>96, txt=>new,line=>19) 19 12 = -> declaratorBrackets 19 12 = <- declaratorBrackets 19 12 = -> varInitializer TOK: StringBuffer 0 0 makeToken(tt=>121, txt=>StringBuffer,line=>19) 19 96 new -> initializer 19 96 new -> expression 19 96 new -> assignmentExpression 19 96 new -> conditionalExpression 19 96 new -> logicalOrExpression 19 96 new -> logicalAndExpression 19 96 new -> inclusiveOrExpression 19 96 new -> exclusiveOrExpression 19 96 new -> andExpression 19 96 new -> equalityExpression 19 96 new -> relationalExpression 19 96 new -> shiftExpression 19 96 new -> additiveExpression 19 96 new -> multiplicativeExpression 19 96 new -> unaryExpression 19 96 new -> unaryExpressionNotPlusMinus 19 96 new -> postfixExpression 19 96 new -> primaryExpression 19 96 new -> newExpression TOK: ( 0 0 makeToken(tt=>3, txt=>(,line=>19) 19 121 StringBuffer -> type 19 121 StringBuffer -> identifier TOK: lvTyp 0 0 makeToken(tt=>121, txt=>lvTyp,line=>19) 19 3 ( <- identifier 19 3 ( <- type TOK: ) 0 0 makeToken(tt=>4, txt=>),line=>19) 19 121 lvTyp -> argList 19 121 lvTyp -> expressionList 19 121 lvTyp -> expression 19 121 lvTyp -> assignmentExpression 19 121 lvTyp -> conditionalExpression 19 121 lvTyp -> logicalOrExpression 19 121 lvTyp -> logicalAndExpression 19 121 lvTyp -> inclusiveOrExpression 19 121 lvTyp -> exclusiveOrExpression 19 121 lvTyp -> andExpression 19 121 lvTyp -> equalityExpression 19 121 lvTyp -> relationalExpression 19 121 lvTyp -> shiftExpression 19 121 lvTyp -> additiveExpression 19 121 lvTyp -> multiplicativeExpression 19 121 lvTyp -> unaryExpression 19 121 lvTyp -> unaryExpressionNotPlusMinus 19 121 lvTyp -> postfixExpression 19 121 lvTyp -> primaryExpression TOK: ; 0 0 makeToken(tt=>47, txt=>;,line=>19) 19 4 ) <- primaryExpression 19 4 ) <- postfixExpression 19 4 ) <- unaryExpressionNotPlusMinus 19 4 ) <- unaryExpression 19 4 ) <- multiplicativeExpression 19 4 ) <- additiveExpression 19 4 ) <- shiftExpression 19 4 ) <- relationalExpression 19 4 ) <- equalityExpression 19 4 ) <- andExpression 19 4 ) <- exclusiveOrExpression 19 4 ) <- inclusiveOrExpression 19 4 ) <- logicalAndExpression 19 4 ) <- logicalOrExpression 19 4 ) <- conditionalExpression 19 4 ) <- assignmentExpression 19 4 ) <- expression 19 4 ) <- expressionList 19 4 ) <- argList TOK: buffer 0 0 makeToken(tt=>121, txt=>buffer,line=>20) 19 47 ; <- newExpression 19 47 ; <- primaryExpression 19 47 ; <- postfixExpression 19 47 ; <- unaryExpressionNotPlusMinus 19 47 ; <- unaryExpression 19 47 ; <- multiplicativeExpression 19 47 ; <- additiveExpression 19 47 ; <- shiftExpression 19 47 ; <- relationalExpression 19 47 ; <- equalityExpression 19 47 ; <- andExpression 19 47 ; <- exclusiveOrExpression 19 47 ; <- inclusiveOrExpression 19 47 ; <- logicalAndExpression 19 47 ; <- logicalOrExpression 19 47 ; <- conditionalExpression 19 47 ; <- assignmentExpression 19 47 ; <- expression 19 47 ; <- initializer 19 47 ; <- varInitializer 19 47 ; <- variableDeclarator 19 47 ; <- variableDefinitions freeing token lvTyp on line 13 c1:1 c2:52 c3:0 freed:26 freeing token = on line 13 c1:1 c2:52 c3:0 freed:27 freeing token " on line 13 c1:1 c2:52 c3:0 freed:28 freeing token ; on line 13 c1:1 c2:52 c3:0 freed:29 freeing token break on line 14 c1:1 c2:52 c3:0 freed:30 freeing token ; on line 14 c1:1 c2:52 c3:0 freed:31 freeing token case on line 15 c1:1 c2:52 c3:0 freed:32 freeing token LOGINFO on line 15 c1:1 c2:52 c3:0 freed:33 freeing token : on line 15 c1:1 c2:52 c3:0 freed:34 freeing token lvTyp on line 16 c1:1 c2:52 c3:0 freed:35 freeing token = on line 16 c1:1 c2:52 c3:0 freed:36 freeing token " on line 16 c1:1 c2:52 c3:0 freed:37 freeing token ; on line 16 c1:1 c2:52 c3:0 freed:38 freeing token break on line 17 c1:1 c2:52 c3:0 freed:39 freeing token ; on line 17 c1:1 c2:52 c3:0 freed:40 freeing token } on line 18 c1:1 c2:52 c3:0 freed:41 freeing token StringBuffer on line 19 c1:1 c2:52 c3:0 freed:42 freeing token buffer on line 19 c1:1 c2:52 c3:0 freed:43 freeing token = on line 19 c1:1 c2:52 c3:0 freed:44 freeing token new on line 19 c1:1 c2:52 c3:0 freed:45 freeing token StringBuffer on line 19 c1:1 c2:52 c3:0 freed:46 freeing token ( on line 19 c1:1 c2:52 c3:0 freed:47 freeing token lvTyp on line 19 c1:1 c2:52 c3:0 freed:48 freeing token ) on line 19 c1:1 c2:52 c3:0 freed:49 freeing token ; on line 19 c1:1 c2:52 c3:0 freed:50 TOK: . 0 0 makeToken(tt=>11, txt=>.,line=>20) 20 121 buffer <- typedDeclaration 20 121 buffer <- field 20 121 buffer -> field 20 121 buffer -> modifiers 20 121 buffer <- modifiers 20 121 buffer -> typeSpec2 20 121 buffer -> classTypeSpec2 20 121 buffer -> identifier2 TOK: append 0 0 makeToken(tt=>121, txt=>append,line=>20) TOK: ( 0 0 makeToken(tt=>3, txt=>(,line=>20) TOK: " 0 0 makeToken(tt=>64, txt=>",line=>20) 20 3 ( <- identifier2 20 3 ( <- classTypeSpec2 20 3 ( <- typeSpec2 20 3 ( -> typedDeclaration prn8.java(20): syntax error at token ( prn8.java(20): trying to match typedDeclaration at '(' TOK: ) 0 0 makeToken(tt=>4, txt=>),line=>20) TOK: . 0 0 makeToken(tt=>11, txt=>.,line=>20) TOK: append 0 0 makeToken(tt=>121, txt=>append,line=>20) TOK: ( 0 0 makeToken(tt=>3, txt=>(,line=>20) 20 121 append <- typedDeclaration 20 121 append <- field 20 121 append -> field 20 121 append -> modifiers 20 121 append <- modifiers 20 121 append -> ctorDefinition Assertion failed: className==LT(1)->getText(), file java.cpp, line 1278 abnormal program termination make: *** [prn8.do_the_test] Error 3 cccc-3.1.4/test/prn8.xmlref0000644000000000000000000000607207724312663014214 0ustar rootroot EwoisErrorHandler EwoisErrorHandler definition handleError(int) definition EwoisErrorHandler EwoisErrorHandler EwoisErrorHandler <file scope items> cccc-3.1.4/test/prn9.cc0000644000000000000000000000045207401205042013261 0ustar rootroot// PRN9.cc // SourceForge bug tracker item 233548 // Submitted by Victor B Putz // Tests handling of inheritance relationships specified as 'public virtual' // and 'virtual public' as both are accepted by GCC. class A { }; class B : public virtual A { }; class C : virtual public A { }; cccc-3.1.4/test/prn9.dbref0000644000000000000000000000203307401205042013753 0ustar rootrootCCCC_Module@A@class@ CCCC_ModExt@A@class@prn9.cc@7@definition@????2@LOC:3 COM:5 MVG:0@2@d@ CCCC_Module@B@class@ CCCC_ModExt@B@class@prn9.cc@11@definition@????0@LOC:3 COM:0 MVG:0@0@d@ CCCC_Module@C@class@ CCCC_ModExt@C@class@prn9.cc@15@definition@????0@LOC:3 COM:0 MVG:0@0@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_UseRel@A@B@ CCCC_UseExt@A@B@prn9.cc@11@inheritance@????0@*@0@I@ CCCC_UseRel@A@C@ CCCC_UseExt@A@C@prn9.cc@15@inheritance@????0@*@0@I@ CCCC_RejExt@prn9.cc@1@@????0@LOC:0 COM:0 MVG:0@0@r@ cccc-3.1.4/test/prn9.htmlref0000644000000000000000000003462407715623450014364 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 3 
    Lines of CodeLOC 9 3.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 5 1.667
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    A 3 0 5------------
    B 3 0 0------------
    C 3 0 0------------

    Procedural Metrics Detail

    A
    definition   prn9.cc:7

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    B
    definition   prn9.cc:11

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    C
    definition   prn9.cc:15

    LOCMVGCOML_CM_C
    No member functions have been identified for this module

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    A 0 0 0 2 2
    B 0 0 1 0 1
    C 0 0 1 0 1

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    A 2 2 2 0 0 0 0 0 0
    B 0 0 0 1 1 1 0 0 0
    C 0 0 0 1 1 1 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    A B [CV]
    inheritance   prn9.cc:11


    C [CV]
    inheritance   prn9.cc:15


     
     
    B   A [CV]
    inheritance   prn9.cc:11


     
    C   A [CV]
    inheritance   prn9.cc:15


     

    Other Extents

    LocationTextLOCCOMMVG
    prn9.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/prn9.xmlref0000644000000000000000000001306207715610507014210 0ustar rootroot A B C A definition B definition C definition A B C A B C A B true true inheritance C true true inheritance B A true true inheritance C A true true inheritance <file scope items> cccc-3.1.4/test/rules.mak0000644000000000000000000001004510020121651013677 0ustar rootroot # rules.mak # This file contains cross-platform rules to support testing of CCCC # it is intended to be included by a platform specific makefile. # Before this file is included the following variables need to be # defined: # CP= # RM= # RMDIR= # MV= # ECHO= # DIFF= # PATHSEP= # CCCC= # We may also want to define CCCC_DEBUG_FLAGS on the command line # if we would like to see some or all of the debug output available # from CCCC. # CCCC_DEBUG_FLAGS= --debug_mask=0xFF # We define a phony target extensions to enable us to force execution of tests # under normal and debugging conditions and also to provide a shortcut way # of 'blessing' the results of a run as the reference values .SUFFIXES : .do_the_test .cc .c .java all : unit_tests regression_tests @$(ECHO) ================ @$(ECHO) All tests passed @$(ECHO) ================ # The --report_mask qualifier controls which parts of the HTML report are # generated. We choose to generate all information in the main file, # but not the separate HTML reports on each module or the source listing. # We also supress the generation date, so that reports generated at different # times can be compared. # At this stage we are happy if the numbers in the generated report look OK: # some day soon we need to tidy up the code so that when a selective report # like this is generated it does not contain loose HTML HREF tags. .cc.do_the_test : $(CCCC) --report_mask=cspPrRojh --db_outfile=$*.db --html_outfile=$*.html --xml_outfile=$*.xml $(CCCC_DEBUG_FLAGS) $< $(DIFF) $*.db $*.dbref $(DIFF) $*.html $*.htmlref $(DIFF) $*.xml $*.xmlref .c.do_the_test : $(CCCC) --report_mask=cspPrRojh --db_outfile=$*.db --html_outfile=$*.html --xml_outfile=$*.xml $(CCCC_DEBUG_FLAGS) $< $(DIFF) $*.db $*.dbref $(DIFF) $*.html $*.htmlref $(DIFF) $*.xml $*.xmlref .java.do_the_test : $(CCCC) --report_mask=cspPrRojh --db_outfile=$*.db --html_outfile=$*.html --xml_outfile=$*.xml $(CCCC_DEBUG_FLAGS) $< $(DIFF) $*.db $*.dbref $(DIFF) $*.html $*.htmlref $(DIFF) $*.xml $*.xmlref # The command line for test4 is slightly different so it needs # an explicit rule test4.do_the_test : $(CCCC) --opt_infile=test4.opt --report_mask=cspPrRojh --db_outfile=test4.db --html_outfile=test4.html --xml_outfile=test4.xml $(CCCC_DEBUG_FLAGS) test4.cc $(DIFF) $*.db $*.dbref $(DIFF) $*.html $*.htmlref $(DIFF) $*.xml $*.xmlref # the first test case is exercises the logic for procedural metrics # the second test case is exercises the logic for structural metrics # the third test case is exercises the logic for metrics arising out of the # work of Chidamber and Kemerer # the fourth test case applies to the ability to specify an option # file to control CCCC's policies for parsing and presentation unit_tests : test1.do_the_test test2.do_the_test test3.do_the_test \ test4.do_the_test # regression tests # PRN1 and PRN2 sent in by Kenneth H. Cox # PRN3 sent in by Dr D. Ruppert, against CCCC 3.pre39 # PRN4 prepared by TL to check for problems with classes being mapped # to modules via their qualified name (CCCC policy is that the simple name # is used) # PRN5 prepared by TL to check for problem due to relationships being # created involving built-in types # PRN6 based on a test case reported by ??? # PRN7 based on a test case reported by Larry Peters of ATI # PRN8 based on a test case reported by Eric Pischel # PRN9-PRN12 based on test cases reported by Victor B Putz # PRN13-PRN14 based on example programs from Sun's Java Tutorial. # PRN15 based on a test case reported by Jordan Zimmerman # PRN16 based on a test case reported by Colin Watson regression_tests : \ prn1.do_the_test prn2.do_the_test prn3.do_the_test \ prn4.do_the_test prn5.do_the_test prn6.do_the_test \ prn7.do_the_test prn8.do_the_test prn9.do_the_test \ prn10.do_the_test prn11.do_the_test prn12.do_the_test \ prn13.do_the_test prn14.do_the_test prn15.do_the_test \ prn16.do_the_test cccc-3.1.4/test/run_test.bat0000644000000000000000000000452010171515300014414 0ustar rootroot@rem run_test.bat @rem This script replaces the action of the make program in running @rem the tests described in rules.mak as there is no make provided @rem with Microsoft Visual C++ Toolkit 2003. @rem the first test case is exercises the logic for procedural metrics @rem the second test case is exercises the logic for structural metrics @rem the third test case is exercises the logic for metrics arising out of the @rem work of Chidamber and Kemerer @rem the fourth test case applies to the ability to specify an option @rem file to control CCCC's policies for parsing and presentation @rem regression tests @rem PRN1 and PRN2 sent in by Kenneth H. Cox @rem PRN3 sent in by Dr D. Ruppert, against CCCC 3.pre39 @rem PRN4 prepared by TL to check for problems with classes being mapped @rem to modules via their qualified name (CCCC policy is that the simple name @rem is used) @rem PRN5 prepared by TL to check for problem due to relationships being @rem created involving built-in types @rem PRN6 based on a test case reported by ??? @rem PRN7 based on a test case reported by Larry Peters of ATI @rem PRN8 based on a test case reported by Eric Pischel @rem PRN9-PRN12 based on test cases reported by Victor B Putz @rem PRN13-PRN14 based on example programs from Sun's Java Tutorial. @rem PRN15 based on a test case reported by Jordan Zimmerman @rem PRN16 based on a test case reported by Colin Watson @echo off set MODE=%1 set TEST=%2 set CCCC=..\cccc\cccc.exe set DIFF=call diff.bat set RM=del set RMDIR=rmdir set MV=rename set ECHO=echo if "%TEST%"=="" then goto :usage if "%MODE%"=="c" ( call run_test_c.bat goto :checkStatus ) else if "%MODE%"=="cc" ( call run_test_cc.bat goto :checkStatus ) else if "%MODE%"=="java" ( call run_test_java.bat goto :checkStatus ) else if "%MODE%"=="test4" ( call run_test_test4.bat goto :checkStatus ) else goto :usage :checkStatus set OVERALL_STATUS=%CCCC_STATUS%%DBDIFF_STATUS%%HTMLDIFF_STATUS%%XMLDIFF_STATUS% if not "%OVERALL_STATUS%"=="0000" ( echo Problem found: echo CCCC returned %CCCC_STATUS% echo DB diff returned %DBDIFF_STATUS% echo HTML diff returned %HTMLDIFF_STATUS% echo XML diff returned %XMLDIFF_STATUS% pause ) else ( echo test %TEST% passed ) goto :end :usage echo run_test [mode] [test] echo [mode] is one of c, cc, java, test4 echo [test] is one of test1..test4, prn1..prn16 goto :end :end cccc-3.1.4/test/run_test_c.bat0000644000000000000000000000067410171515300014724 0ustar rootroot@rem run_test_c.bat @rem This script depends on environment variables set up in run_test.bat %CCCC% --report_mask=cspPrRojh --db_outfile=%TEST%.db --html_outfile=%TEST%.html --xml_outfile=%TEST%.xml %TEST%.c set CCCC_STATUS=%ERRORLEVEL% %DIFF% %TEST%.db %TEST%.dbref set DBDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.html %TEST%.htmlref set HTMLDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.xml %TEST%.xmlref set XMLDIFF_STATUS=%DIFF_STATUS% cccc-3.1.4/test/run_test_cc.bat0000644000000000000000000000067210171515300015065 0ustar rootroot@rem run_test_cc.bat @This script depends on environment variables set up in run_test.bat %CCCC% --report_mask=cspPrRojh --db_outfile=%TEST%.db --html_outfile=%TEST%.html --xml_outfile=%TEST%.xml %TEST%.cc set CCCC_STATUS=%ERRORLEVEL% %DIFF% %TEST%.db %TEST%.dbref set DBDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.html %TEST%.htmlref set HTMLDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.xml %TEST%.xmlref set XMLDIFF_STATUS=%DIFF_STATUS% cccc-3.1.4/test/run_test_java.bat0000644000000000000000000000067610171515300015425 0ustar rootroot@rem run_test_java.bat @This script depends on environment variables set up in run_test.bat %CCCC% --report_mask=cspPrRojh --db_outfile=%TEST%.db --html_outfile=%TEST%.html --xml_outfile=%TEST%.xml %TEST%.java set CCCC_STATUS=%ERRORLEVEL% %DIFF% %TEST%.db %TEST%.dbref set DBDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.html %TEST%.htmlref set HTMLDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.xml %TEST%.xmlref set XMLDIFF_STATUS=%DIFF_STATUS% cccc-3.1.4/test/run_test_test4.bat0000644000000000000000000000072210171515300015537 0ustar rootroot@rem run_test_test4.bat @This script depends on environment variables set up in run_test.bat %CCCC% --opt_infile=test4.opt --report_mask=cspPrRojh --db_outfile=test4.db --html_outfile=test4.html --xml_outfile=test4.xml %TEST%.cc set CCCC_STATUS=%DIFF_STATUS% %DIFF% %TEST%.db %TEST%.dbref set DBDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.html %TEST%.htmlref set HTMLDIFF_STATUS=%DIFF_STATUS% %DIFF% %TEST%.xml %TEST%.xmlref set XMLDIFF_STATUS=%DIFF_STATUS% cccc-3.1.4/test/test.dsp0000644000000000000000000001167607272040214013567 0ustar rootroot# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) External Target" 0x0106 CFG=test - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "test.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "test - Win32 Release" (based on "Win32 (x86) External Target") !MESSAGE "test - Win32 Debug" (based on "Win32 (x86) External Target") !MESSAGE # Begin Project # PROP Scc_ProjName "" # PROP Scc_LocalPath "" !IF "$(CFG)" == "test - Win32 Release" # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Cmd_Line "NMAKE /f test.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "test.exe" # PROP BASE Bsc_Name "test.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Cmd_Line "nmake -f win32_nmake.mak" # PROP Rebuild_Opt "/a" # PROP Bsc_Name "" # PROP Target_Dir "" !ELSEIF "$(CFG)" == "test - Win32 Debug" # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Cmd_Line "NMAKE /f test.mak" # PROP BASE Rebuild_Opt "/a" # PROP BASE Target_File "test.exe" # PROP BASE Bsc_Name "test.bsc" # PROP BASE Target_Dir "" # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Cmd_Line "nmake -f win32_nmake.mak" # PROP Rebuild_Opt "/a" # PROP Target_File "test.exe" # PROP Bsc_Name "test.bsc" # PROP Target_Dir "" !ENDIF # Begin Target # Name "test - Win32 Release" # Name "test - Win32 Debug" !IF "$(CFG)" == "test - Win32 Release" !ELSEIF "$(CFG)" == "test - Win32 Debug" !ENDIF # Begin Group "makefiles" # PROP Default_Filter "*.mak" # Begin Source File SOURCE=.\diff.bat # End Source File # Begin Source File SOURCE=.\posix.mak # End Source File # Begin Source File SOURCE=.\rules.mak # End Source File # Begin Source File SOURCE=.\win32_nmake.mak # End Source File # End Group # Begin Group "test1" # PROP Default_Filter "" # Begin Source File SOURCE=.\test1.cc # End Source File # Begin Source File SOURCE=.\test1.dbref # End Source File # Begin Source File SOURCE=.\test1.htmlref # End Source File # End Group # Begin Group "test2" # PROP Default_Filter "" # Begin Source File SOURCE=.\test2.cc # End Source File # Begin Source File SOURCE=.\test2.dbref # End Source File # Begin Source File SOURCE=.\test2.htmlref # End Source File # End Group # Begin Group "test3" # PROP Default_Filter "" # Begin Source File SOURCE=.\test3.cc # End Source File # Begin Source File SOURCE=.\test3.dbref # End Source File # Begin Source File SOURCE=.\test3.htmlref # End Source File # End Group # Begin Group "test4" # PROP Default_Filter "" # Begin Source File SOURCE=.\test4.cc # End Source File # Begin Source File SOURCE=.\test4.dbref # End Source File # Begin Source File SOURCE=.\test4.htmlref # End Source File # End Group # Begin Group "prn1" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn1.cc # End Source File # Begin Source File SOURCE=.\prn1.dbref # End Source File # Begin Source File SOURCE=.\prn1.htmlref # End Source File # End Group # Begin Group "prn2" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn2.cc # End Source File # Begin Source File SOURCE=.\prn2.dbref # End Source File # Begin Source File SOURCE=.\prn2.htmlref # End Source File # End Group # Begin Group "prn3" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn3.cc # End Source File # Begin Source File SOURCE=.\prn3.dbref # End Source File # Begin Source File SOURCE=.\prn3.htmlref # End Source File # End Group # Begin Group "prn4" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn4.cc # End Source File # Begin Source File SOURCE=.\prn4.dbref # End Source File # Begin Source File SOURCE=.\prn4.htmlref # End Source File # End Group # Begin Group "prn5" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn5.cc # End Source File # Begin Source File SOURCE=.\prn5.dbref # End Source File # Begin Source File SOURCE=.\prn5.htmlref # End Source File # End Group # Begin Group "prn6" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn6.cc # End Source File # Begin Source File SOURCE=.\prn6.dbref # End Source File # Begin Source File SOURCE=.\prn6.htmlref # End Source File # End Group # Begin Group "prn7" # PROP Default_Filter "" # Begin Source File SOURCE=.\prn7.c # End Source File # Begin Source File SOURCE=.\prn7.dbref # End Source File # Begin Source File SOURCE=.\prn7.htmlref # End Source File # End Group # End Target # End Project cccc-3.1.4/test/test1.cc0000644000000000000000000000570107265351304013446 0ustar rootroot//## test1.cc //## test case illustrating simple procedural metrics //## Lines starting //## are ignored by CCCC so they will be used in this //## file for explanatory comments (as opposed to comments which we wish //## to count). //## The file is annotated along the way with comment lines like these //## scope/comment LOC COM MVG //## definition of class Test1 (start) 0 0 0 //## running totals 0 0 0 //## definition of class Test1 (end) 0 0 0 //## Note that extents nest, so there is effectively a stack of //## running totals for each extent open at a particular point in a file //## definition of class Test1 (start) 0 0 0 // Leading comment for class. class Test1 { //## running totals 2 1 0 // Internal comment for class. // This should not be associated with the following function due to // the intervening visibility declaration. //## running totals 2 4 0 public: //## running totals for definition of class Test1 (push) 3 4 0 //## definition of method Test1::method1 (start) 0 0 0 // Leading comment for inline method void method1() { //## running totals 2 1 0 int s=1; switch(s) //## running totals 4 1 1 { case 1: break; //## running totals 7 1 2 case 2: break; //## running totals 9 1 3 default: break; //## running totals 11 1 4 } } //## definition of method Test1::method1 (end) 13 1 4 //## running totals for definition of class Test1 (pop+push) 3 4 0 //## declaration of method Test1::method2 (start) 0 0 0 void method2(); //## declaration of method Test1::method2 (end) 1 0 0 //## running totals for definition of class Test1 (pop) 3 4 0 }; //## definition of class Test1 (end) 4 4 0 //## definition of method Test1::method2 (start) 0 0 0 void Test1::method2() { if(1) { // do nothing } } //## definition of method Test1::method2 (end) 6 1 1 //## after processing the whole file we expect to find the following //## extents recognized and mentioned in the .db file //## definition of class Test1 LOC:4 COM:4 MVG:0 //## definition of method Test1::method1 LOC:13 COM:1 MVG:4 //## declaration of method Test1::method2 LOC:1 COM:0 MVG:0 //## definition of method Test1::method2 LOC:6 COM:1 MVG:1 cccc-3.1.4/test/test1.dbref0000644000000000000000000000203207265351304014135 0ustar rootrootCCCC_Module@Test1@class@ CCCC_ModExt@Test1@class@test1.cc@16@definition@F???2@LOC:4 COM:4 MVG:0@2@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Test1@method1@@()@ CCCC_MemExt@Test1@method1@@()@test1.cc@27@definition@F???0@LOC:13 COM:1 MVG:4@0@d@ CCCC_Member@Test1@method2@@()@ CCCC_MemExt@Test1@method2@@()@test1.cc@48@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_MemExt@Test1@method2@@()@test1.cc@55@definition@F????@LOC:6 COM:1 MVG:1@?@d@ CCCC_RejExt@test1.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/test1.htmlref0000644000000000000000000003002607715623450014524 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 2424.000
    McCabe's Cyclomatic NumberMVG 5 5.000
    Lines of CommentCOM 6 6.000
    LOC/COML_C 4.000 
    MVG/COMM_C 0.833 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    Test1 24 5 6 4.000 0.833

    Procedural Metrics Detail

    Test1
    definition   test1.cc:16

    LOCMVGCOML_CM_C
    method1(   )
    definition   test1.cc:27

    13 4 1------------
    method2(   )
    declaration   test1.cc:48
    definition   test1.cc:55

    7 1 1------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    Test1 2 2 0 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    Test1 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    Test1    

    Other Extents

    LocationTextLOCCOMMVG
    test1.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/test1.xmlref0000644000000000000000000000702607715610507014363 0ustar rootroot Test1 Test1 definition method1() definition method2() declaration definition Test1 Test1 Test1 <file scope items> cccc-3.1.4/test/test2.cc0000644000000000000000000000424207265351307013451 0ustar rootroot//## test2.cc //## test source file for the structural metrics measured by CCCC. //## //## This file defines the following classes: //## Test2a //## Test2b //## Test2c //## It also defines the following method //## Test2e::Test2e(const Test2a&) //## The following relationships should be visible in the code: //## Test2a uses Test2e by inheritance with public visibility //## Test2a uses Test2b by containment by reference with public visibility //## Test2a uses Test2b by parameter passing by value with private visibility //## Test2c uses uses Test2d by containment by value with protected visibility //## Test2e uses Test2a by parameter passing by value with unknown visibility class Test2a : public Test2e { public: Test2b *m_2b; private: void doSomething(Test2b); }; class Test2c { protected: Test2d m_2d; }; //## The extent record for the following class definition would normally be //## brought into the database alongside the extent record for the declaration //## of the method within the class definition, allowing the visibility to be //## known. In this case, we are choosing to analyze this definition without //## that knowledge, hence the visibility of the method cannot be inferred and //## the analyzer should assume that it is of the less desirable visible //## classification. Test2e::Test2e(const Test2a&) { } //## The code above should give rise to the following relationships //## The annotations [], [C], [V], [CV] show how the relationship is //## classified on the two scales concrete/abstract and visible/hidden //## where abstract relationships are ones where the supplier is treated //## as an opaque type for the purposes of the interface (i.e. containment //## or parameter passing by reference), and hidden ones are where the //## supplier is known not to appear in the protected or public interface of //## the client. //## Class Clients Suppliers //## Test2a Test2d[V] Test2e[V],Test2b[CV] //## Test2b Test2a[CV] //## Test2c Test2d[CV] //## Test2d Test2d[CV] Test2a[V] //## Test2e Test2a[CV] cccc-3.1.4/test/test2.dbref0000644000000000000000000000316607265351307014152 0ustar rootrootCCCC_Module@Test2a@class@ CCCC_ModExt@Test2a@class@test2.cc@18@definition@F???0@LOC:6 COM:0 MVG:0@0@d@ CCCC_Module@Test2b@@ CCCC_Module@Test2c@class@ CCCC_ModExt@Test2c@class@test2.cc@26@definition@F???2@LOC:5 COM:0 MVG:0@2@d@ CCCC_Module@Test2d@@ CCCC_Module@Test2e@@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Test2a@doSomething@@(Test2b)@ CCCC_MemExt@Test2a@doSomething@@(Test2b)@test2.cc@23@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test2e@Test2e@@(const Test2a &)@ CCCC_MemExt@Test2e@Test2e@@(const Test2a &)@test2.cc@39@definition@F????@LOC:3 COM:0 MVG:0@?@d@ CCCC_UseRel@Test2b@Test2a@ CCCC_UseExt@Test2b@Test2a@test2.cc@21@has by reference@????0@LOC:0 COM:0 MVG:0@0@h@ CCCC_UseExt@Test2b@Test2a@test2.cc@23@pass by value@F???2@*@2@P@ CCCC_UseRel@Test2e@Test2a@ CCCC_UseExt@Test2e@Test2a@test2.cc@18@inheritance@????0@*@0@I@ CCCC_UseRel@Test2d@Test2c@ CCCC_UseExt@Test2d@Test2c@test2.cc@29@has by value@F???1@LOC:0 COM:0 MVG:0@1@H@ CCCC_UseRel@Test2a@Test2e@ CCCC_UseExt@Test2a@Test2e@test2.cc@39@pass by reference@F????@*@?@p@ CCCC_RejExt@test2.cc@1@@F????@LOC:0 COM:0 MVG:0@?@r@ cccc-3.1.4/test/test2.htmlref0000644000000000000000000004374607715623450014542 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 5 
    Lines of CodeLOC 15 3.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 0 0.000
    LOC/COML_C------ 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 5 1.000
    Information Flow measure (  visible )IF4v 5 1.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    Test2a 7 0 0------------
    Test2b 0 0 0------------
    Test2c 5 0 0------------
    Test2d 0 0 0------------
    Test2e 3 0 0------------

    Procedural Metrics Detail

    Test2a
    definition   test2.cc:18

    LOCMVGCOML_CM_C
    doSomething(  Test2b )
    declaration   test2.cc:23

    1 0 0------------
    Test2b

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test2c
    definition   test2.cc:26

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test2d

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test2e

    LOCMVGCOML_CM_C
    Test2e(  const Test2a & )
    definition   test2.cc:39

    3 0 0------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    Test2a 1 0 1 0 3
    Test2b 0 0 0 0 1
    Test2c 0 0 0 0 1
    Test2d 0 0 0 0 1
    Test2e 1 0 0 1 2

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    Test2a 1 0 1 2 2 2 4 0 4
    Test2b 1 1 1 0 0 0 0 0 0
    Test2c 0 0 0 1 1 1 0 0 0
    Test2d 1 1 1 0 0 0 0 0 0
    Test2e 1 1 1 1 0 1 1 0 1

    Structural Metrics Detail

    Module NameClientsSuppliers
    Test2a Test2e [V]
    pass by reference   test2.cc:39


     
    Test2b [CV]
    has by reference   test2.cc:21
    pass by value   test2.cc:23


    Test2e [CV]
    inheritance   test2.cc:18


     
    Test2b Test2a [CV]
    has by reference   test2.cc:21
    pass by value   test2.cc:23


     
     
    Test2c   Test2d [CV]
    has by value   test2.cc:29


     
    Test2d Test2c [CV]
    has by value   test2.cc:29


     
     
    Test2e Test2a [CV]
    inheritance   test2.cc:18


     
    Test2a [V]
    pass by reference   test2.cc:39


     

    Other Extents

    LocationTextLOCCOMMVG
    test2.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/test2.xmlref0000644000000000000000000002306307715610507014363 0ustar rootroot Test2a Test2b Test2c Test2d Test2e Test2a definition doSomething(Test2b) declaration Test2b Test2c definition Test2d Test2e Test2e(const Test2a &) definition Test2a Test2b Test2c Test2d Test2e Test2a Test2b Test2c Test2d Test2e Test2a Test2e true false pass by reference Test2b true true has by reference pass by value Test2e true true inheritance Test2b Test2a true true has by reference pass by value Test2c Test2d true true has by value Test2d Test2c true true has by value Test2e Test2a true true inheritance Test2a true false pass by reference <file scope items> cccc-3.1.4/test/test3.cc0000644000000000000000000000310507265351320013442 0ustar rootroot//## test3.cc //## This file is intended to test the performance of CCCC in measurement //## of the metrics described in the papers by Chidamber and Kemerer //## about 'a metrics suite for object oriented design'. //## Test3a attempts to check the values for WMC1 and WMCv //## When I was originally writing this class I found some bugs in the //## handling of operator functions, hence the fact that they are //## extensively used in this item. class Test3a { public: Test3a(); ~Test3a(); operator new(); operator delete[](); protected: operator!=(); operator unsigned long int(); private: operator==(); operator ()(); operator [](); operator*(); operator.*(); do_something(); do_something_else(); }; //## Manual count of the above definition yields WMC1=13, WMCv=6 (including //## protected functions which we treat as visible). //## Test3b1 to Test3b5 attempt to test the logic for DIT, NOC and CBO. class Test3b1 : public Test3b0 {}; class Test3b2 : public Test3b1 {}; class Test3b4 : public Test3b3, public Test3b0, public Test3b2 {}; class Test3b5 { public: Test3b5(Test3b3); private: Test3b0 m_3b0; }; //## Should get the following values: //## class DIT NOC CBO //## Test3b0 0 2 3 //## Test3b1 1 1 2 //## Test3b2 2 1 2 //## Test3b3 0 1 2 //## Test3b4 3 0 3 //## Test3b5 0 0 2 cccc-3.1.4/test/test3.dbref0000644000000000000000000000706507265351320014150 0ustar rootrootCCCC_Module@Test3a@class@ CCCC_ModExt@Test3a@class@test3.cc@10@definition@F???2@LOC:6 COM:0 MVG:0@2@d@ CCCC_Module@Test3b0@@ CCCC_Module@Test3b1@class@ CCCC_ModExt@Test3b1@class@test3.cc@33@definition@F???0@LOC:1 COM:0 MVG:0@0@d@ CCCC_Module@Test3b2@class@ CCCC_ModExt@Test3b2@class@test3.cc@34@definition@F???0@LOC:1 COM:0 MVG:0@0@d@ CCCC_Module@Test3b3@@ CCCC_Module@Test3b4@class@ CCCC_ModExt@Test3b4@class@test3.cc@35@definition@F???0@LOC:1 COM:0 MVG:0@0@d@ CCCC_Module@Test3b5@class@ CCCC_ModExt@Test3b5@class@test3.cc@36@definition@F???2@LOC:6 COM:0 MVG:0@2@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Test3a@Test3a@@()@ CCCC_MemExt@Test3a@Test3a@@()@test3.cc@13@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Test3a@do_something@@()@ CCCC_MemExt@Test3a@do_something@@()@test3.cc@26@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@do_something_else@@()@ CCCC_MemExt@Test3a@do_something_else@@()@test3.cc@27@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator !=@@()@ CCCC_MemExt@Test3a@operator !=@@()@test3.cc@18@declaration@F???1@LOC:1 COM:0 MVG:0@1@D@ CCCC_Member@Test3a@operator ()@@()@ CCCC_MemExt@Test3a@operator ()@@()@test3.cc@22@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator *@@()@ CCCC_MemExt@Test3a@operator *@@()@test3.cc@24@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator .*@@()@ CCCC_MemExt@Test3a@operator .*@@()@test3.cc@25@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator ==@@()@ CCCC_MemExt@Test3a@operator ==@@()@test3.cc@21@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator []@@()@ CCCC_MemExt@Test3a@operator []@@()@test3.cc@23@declaration@F???2@LOC:1 COM:0 MVG:0@2@D@ CCCC_Member@Test3a@operator delete[]@@()@ CCCC_MemExt@Test3a@operator delete[]@@()@test3.cc@16@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Test3a@operator int@@()@ CCCC_MemExt@Test3a@operator int@@()@test3.cc@19@declaration@F???1@LOC:1 COM:0 MVG:0@1@D@ CCCC_Member@Test3a@operator new@@()@ CCCC_MemExt@Test3a@operator new@@()@test3.cc@15@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Test3a@~Test3a@@()@ CCCC_MemExt@Test3a@~Test3a@@()@test3.cc@14@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_Member@Test3b5@Test3b5@@(Test3b3)@ CCCC_MemExt@Test3b5@Test3b5@@(Test3b3)@test3.cc@39@declaration@F???0@LOC:1 COM:0 MVG:0@0@D@ CCCC_UseRel@Test3b0@Test3b1@ CCCC_UseExt@Test3b0@Test3b1@test3.cc@33@inheritance@F???0@*@0@I@ CCCC_UseRel@Test3b1@Test3b2@ CCCC_UseExt@Test3b1@Test3b2@test3.cc@34@inheritance@F???0@*@0@I@ CCCC_UseRel@Test3b0@Test3b4@ CCCC_UseExt@Test3b0@Test3b4@test3.cc@35@inheritance@F???0@*@0@I@ CCCC_UseRel@Test3b2@Test3b4@ CCCC_UseExt@Test3b2@Test3b4@test3.cc@35@inheritance@F???0@*@0@I@ CCCC_UseRel@Test3b3@Test3b4@ CCCC_UseExt@Test3b3@Test3b4@test3.cc@35@inheritance@F???0@*@0@I@ CCCC_UseRel@Test3b0@Test3b5@ CCCC_UseExt@Test3b0@Test3b5@test3.cc@41@has by value@F???2@LOC:0 COM:0 MVG:0@2@H@ CCCC_UseRel@Test3b3@Test3b5@ CCCC_UseExt@Test3b3@Test3b5@test3.cc@39@pass by value@F???0@*@0@P@ CCCC_RejExt@test3.cc@1@@F???2@LOC:0 COM:0 MVG:0@2@r@ cccc-3.1.4/test/test3.htmlref0000644000000000000000000006121307715623450014530 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 7 
    Lines of CodeLOC 29 4.143
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 0 0.000
    LOC/COML_C****** 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 2 0.286
    Information Flow measure (  visible )IF4v 2 0.286
    Information Flow measure (  concrete )IF4c 2 0.286
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    Test3a 19 0 0------------
    Test3b0 0 0 0------------
    Test3b1 1 0 0------------
    Test3b2 1 0 0------------
    Test3b3 0 0 0------------
    Test3b4 1 0 0------------
    Test3b5 7 0 0------------

    Procedural Metrics Detail

    Test3a
    definition   test3.cc:10

    LOCMVGCOML_CM_C
    Test3a(   )
    declaration   test3.cc:13

    1 0 0------------
    do_something(   )
    declaration   test3.cc:26

    1 0 0------------
    do_something_else(   )
    declaration   test3.cc:27

    1 0 0------------
    operator !=(   )
    declaration   test3.cc:18

    1 0 0------------
    operator (   )(   )
    declaration   test3.cc:22

    1 0 0------------
    operator *(   )
    declaration   test3.cc:24

    1 0 0------------
    operator .*(   )
    declaration   test3.cc:25

    1 0 0------------
    operator ==(   )
    declaration   test3.cc:21

    1 0 0------------
    operator [](   )
    declaration   test3.cc:23

    1 0 0------------
    operator delete[](   )
    declaration   test3.cc:16

    1 0 0------------
    operator int(   )
    declaration   test3.cc:19

    1 0 0------------
    operator new(   )
    declaration   test3.cc:15

    1 0 0------------
    ~Test3a(   )
    declaration   test3.cc:14

    1 0 0------------
    Test3b0

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test3b1
    definition   test3.cc:33

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test3b2
    definition   test3.cc:34

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test3b3

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test3b4
    definition   test3.cc:35

    LOCMVGCOML_CM_C
    No member functions have been identified for this module
    Test3b5
    definition   test3.cc:36

    LOCMVGCOML_CM_C
    Test3b5(  Test3b3 )
    declaration   test3.cc:39

    1 0 0------------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    Test3a 13 6 0 0 0
    Test3b0 0 0 0 2 3
    Test3b1 0 0 1 1 2
    Test3b2 0 0 2 1 2
    Test3b3 0 0 0 1 2
    Test3b4 0 0 3 0 3
    Test3b5 1 1 0 0 2

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    Test3a 0 0 0 0 0 0 0 0 0
    Test3b0 2 3 3 0 0 0 0 0 0
    Test3b1 1 1 1 1 1 1 1 1 1
    Test3b2 1 1 1 1 1 1 1 1 1
    Test3b3 2 2 2 0 0 0 0 0 0
    Test3b4 0 0 0 3 3 3 0 0 0
    Test3b5 0 0 0 1 2 2 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    Test3a    
    Test3b0 Test3b1 [CV]
    inheritance   test3.cc:33


    Test3b4 [CV]
    inheritance   test3.cc:35


    Test3b5 [C]
    has by value   test3.cc:41


     
     
    Test3b1 Test3b2 [CV]
    inheritance   test3.cc:34


     
    Test3b0 [CV]
    inheritance   test3.cc:33


     
    Test3b2 Test3b4 [CV]
    inheritance   test3.cc:35


     
    Test3b1 [CV]
    inheritance   test3.cc:34


     
    Test3b3 Test3b4 [CV]
    inheritance   test3.cc:35


    Test3b5 [CV]
    pass by value   test3.cc:39


     
     
    Test3b4   Test3b0 [CV]
    inheritance   test3.cc:35


    Test3b2 [CV]
    inheritance   test3.cc:35


    Test3b3 [CV]
    inheritance   test3.cc:35


     
    Test3b5   Test3b0 [C]
    has by value   test3.cc:41


    Test3b3 [CV]
    pass by value   test3.cc:39


     

    Other Extents

    LocationTextLOCCOMMVG
    test3.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/test3.xmlref0000644000000000000000000004413307715610507014365 0ustar rootroot Test3a Test3b0 Test3b1 Test3b2 Test3b3 Test3b4 Test3b5 Test3a definition Test3a() declaration do_something() declaration do_something_else() declaration operator !=() declaration operator ()() declaration operator *() declaration operator .*() declaration operator ==() declaration operator []() declaration operator delete[]() declaration operator int() declaration operator new() declaration ~Test3a() declaration Test3b0 Test3b1 definition Test3b2 definition Test3b3 Test3b4 definition Test3b5 definition Test3b5(Test3b3) declaration Test3a Test3b0 Test3b1 Test3b2 Test3b3 Test3b4 Test3b5 Test3a Test3b0 Test3b1 Test3b2 Test3b3 Test3b4 Test3b5 Test3a Test3b0 Test3b1 true true inheritance Test3b4 true true inheritance Test3b5 false true has by value Test3b1 Test3b2 true true inheritance Test3b0 true true inheritance Test3b2 Test3b4 true true inheritance Test3b1 true true inheritance Test3b3 Test3b4 true true inheritance Test3b5 true true pass by value Test3b4 Test3b0 true true inheritance Test3b2 true true inheritance Test3b3 true true inheritance Test3b5 Test3b0 false true has by value Test3b3 true true pass by value <file scope items> cccc-3.1.4/test/test4.cc0000644000000000000000000000226307271572210013447 0ustar rootroot//## test4.cc //## This file is intended to test the operation of the CCCC feature //## of being able to define an options file which affects the //## execution of CCCC in a number of ways. //## There is a companion file test4.opt which modifies the behaviour //## of CCCC in the following ways: //## display format of L_C has one decimal place; //## threshold for L_C to be displayed in red is 3.0 //## default dialect assignment for extension .cc is set to c++.test4 //## treatment of the pseudo-keyword TEST4_EXT in dialect c++.test4 is //## to be ignored. //## Ultimately, the format of the opt file needs to be documented, //## for the time being users keen to try the facility out may be //## able to infer enough to apply it to their needs by reading //## rules.mak to see how to invoke cccc with the opt file //## output, and by diffing test4.opt against vanilla.opt, //## which contains the version of the opt file obtained when //## the compiled-in default options (see cccc_opt.cc) are //## exported using 'cccc --opt_outfile=vanilla.opt' class Test4a { public: TEST4_EXT void dummy() { // Comment line one // Comment line two int i; i = 1; i = 2; i = 3; } }; cccc-3.1.4/test/test4.dbref0000644000000000000000000000152507271572210014144 0ustar rootrootCCCC_Module@Test4a@class@ CCCC_ModExt@Test4a@class@test4.cc@21@definition@F???2@LOC:4 COM:0 MVG:0@2@d@ CCCC_Module@char@builtin@ CCCC_ModExt@char@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@double@builtin@ CCCC_ModExt@double@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@float@builtin@ CCCC_ModExt@float@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@int@builtin@ CCCC_ModExt@int@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@long@builtin@ CCCC_ModExt@long@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Module@void@builtin@ CCCC_ModExt@void@builtin@@0@builtin definition@d?????@@0@d@ CCCC_Member@Test4a@dummy@@()@ CCCC_MemExt@Test4a@dummy@@()@test4.cc@24@definition@F???0@LOC:7 COM:2 MVG:0@0@d@ CCCC_RejExt@test4.cc@1@@F???2@LOC:0 COM:0 MVG:0@2@r@ cccc-3.1.4/test/test4.htmlref0000644000000000000000000002737207715623450014541 0ustar rootroot Report on software metrics
    CCCC Software Metrics Report

    Project Summary

    Summary table of high level measures summed over all files processed in the current run.

    Procedural Metrics Summary

    Table of procedural measures (i.e. lines of code, lines of comment, McCabe's cyclomatic complexity summed over each module.

    Procedural Metrics Detail

    The same procedural metrics as in the procedural metrics summary, reported for individual functions, grouped by module.

    Object Oriented Design

    Table of four of the 6 metrics proposed by Chidamber and Kemerer in their various papers on 'a metrics suite for object oriented design'.

    Structural Metrics Summary

    Structural metrics based on the relationships of each module with others. Includes fan-out (i.e. number of other modules the current module uses), fan-in (number of other modules which use the current module), and the Information Flow measure suggested by Henry and Kafura, which combines these to give a measure of coupling for the module.

    Structural Metrics Detail

    The names of the modules included as clients and suppliers in the counts for the Structural Metrics Summary.

    Other Extents

    Lexical counts for parts of submitted source files which the analyser was unable to assign to a module. Each record in this table relates to either a part of the code which triggered a parse failure, or to the residual lexical counts relating to parts of a file not associated with a specific module.

    About CCCC

    A description of the CCCC program.

    Project Summary

    This table shows measures over the project as a whole.
    • NOM = Number of modules
      Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
    • LOC = Lines of Code
      Number of non-blank, non-comment lines of source code counted by the analyser.
    • COM = Lines of Comments
      Number of lines of comment identified by the analyser
    • MVG = McCabe's Cyclomatic Complexity
      A measure of the decision complexity of the functions which make up the program.The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
    • L_C = Lines of code per line of comment
      Indicates density of comments with respect to textual size of program
    • M_C = Cyclomatic Complexity per line of comment
      Indicates density of comments with respect to logical complexity of program
    • IF4 = Information Flow measure
      Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.
    Two variants on the information flow measure IF4 are also presented, one (IF4v) calculated using only relationships in the visible part of the module interface, and the other (IF4c) calculated using only those relationships which imply that changes to the client must be recompiled of the supplier's definition changes.
    MetricTagOverallPer Module
    Number of modulesNOM 1 
    Lines of CodeLOC 1111.000
    McCabe's Cyclomatic NumberMVG 0 0.000
    Lines of CommentCOM 2 2.000
    LOC/COML_C 5.5 
    MVG/COMM_C------ 
    Information Flow measure (  inclusive )IF4 0 0.000
    Information Flow measure (  visible )IF4v 0 0.000
    Information Flow measure (  concrete )IF4c 0 0.000
    Lines of Code rejected by parserREJ 0 

    Procedural Metrics Summary

    For descriptions of each of these metrics see the information preceding the project summary table. The label cell for each row in this table provides a link to the functions table in the detailed report for the module in question
    Module NameLOCMVGCOML_CM_C
    Test4a 11 0 2 5.5------

    Procedural Metrics Detail

    Test4a
    definition   test4.cc:21

    LOCMVGCOML_CM_C
    dummy(   )
    definition   test4.cc:24

    7 0 2 3.5------

    Object Oriented Design

    • WMC = Weighted methods per class
      The sum of a weighting function over the functions of the module. Two different weighting functions are applied: WMC1 uses the nominal weight of 1 for each function, and hence measures the number of functions, WMCv uses a weighting function which is 1 for functions accessible to other modules, 0 for private functions.
    • DIT = Depth of inheritance tree
      The length of the longest path of inheritance ending at the current module. The deeper the inheritance tree for a module, the harder it may be to predict its behaviour. On the other hand, increasing depth gives the potential of greater reuse by the current module of behaviour defined for ancestor classes.
    • NOC = Number of children
      The number of modules which inherit directly from the current module. Moderate values of this measure indicate scope for reuse, however high values may indicate an inappropriate abstraction in the design.
    • CBO = Coupling between objects
      The number of other modules which are coupled to the current module either as a client or a supplier. Excessive coupling indicates weakness of module encapsulation and may inhibit reuse.
    The label cell for each row in this table provides a link to the module summary table in the detailed report for the module in question
    Module NameWMC1WMCvDITNOCCBO
    Test4a 1 10 0 0

    Structural Metrics Summary

    • FI = Fan-in
      The number of other modules which pass information into the current module.
    • FO = Fan-out
      The number of other modules into which the current module passes information
    • IF4 = Information Flow measure
      A composite measure of structural complexity, calculated as the square of the product of the fan-in and fan-out of a single module. Proposed by Henry and Kafura.
    Note that the fan-in and fan-out are calculated by examining the interface of each module. As noted above, three variants of each each of these measures are presented: a count restricted to the part of the interface which is externally visible, a count which only includes relationships which imply the client module needs to be recompiled if the supplier's implementation changes, and an inclusive count The label cell for each row in this table provides a link to the relationships table in the detailed report for the module in question
    Module Name Fan-out Fan-in IF4
    visconincvisconinclvisconinc
    Test4a 0 0 0 0 0 0 0 0 0

    Structural Metrics Detail

    Module NameClientsSuppliers
    Test4a    

    Other Extents

    LocationTextLOCCOMMVG
    test4.cc:1
    <file scope items> 0 0 0

    About CCCC

    This report was generated by the program CCCC, which is FREELY REDISTRIBUTABLE but carries NO WARRANTY.

    CCCC was developed by Tim Littlefair. as part of a PhD research project. This project is now completed and descriptions of the findings can be accessed at http://www.chs.ecu.edu.au/~tlittlef.

    User support for CCCC can be obtained by mailing the list cccc-users@lists.sourceforge.net.

    Please also visit the CCCC development website at http://cccc.sourceforge.net. cccc-3.1.4/test/test4.opt0000644000000000000000000000605707271572210013671 0ustar rootrootCCCC_FileExt@.ADA@ada.95@ CCCC_FileExt@.ADB@ada.95@ CCCC_FileExt@.ADS@ada.95@ CCCC_FileExt@.C@c++.ansi@ CCCC_FileExt@.CC@c++.ansi@ CCCC_FileExt@.CPP@c++.ansi@ CCCC_FileExt@.CXX@c++.ansi@ CCCC_FileExt@.H@c++.ansi@ CCCC_FileExt@.H++@c++.ansi@ CCCC_FileExt@.HH@c++.ansi@ CCCC_FileExt@.HPP@c++.ansi@ CCCC_FileExt@.HXX@c++.ansi@ CCCC_FileExt@.J@java@ CCCC_FileExt@.JAV@java@ CCCC_FileExt@.JAVA@java@ CCCC_FileExt@.ada@ada.95@ CCCC_FileExt@.adb@ada.95@ CCCC_FileExt@.ads@ada.95@ CCCC_FileExt@.c@c.ansi@ CCCC_FileExt@.c++@c++.ansi@ CCCC_FileExt@.cc@c++.test4@ CCCC_FileExt@.cpp@c++.ansi@ CCCC_FileExt@.cxx@c++.ansi@ CCCC_FileExt@.h@c++.ansi@ CCCC_FileExt@.h++@c++.ansi@ CCCC_FileExt@.hh@c++.ansi@ CCCC_FileExt@.hpp@c++.ansi@ CCCC_FileExt@.hxx@c++.ansi@ CCCC_FileExt@.j@java@ CCCC_FileExt@.jav@java@ CCCC_FileExt@.java@java@ CCCC_MetTmnt@8.3@999999.000000@999999.000000@0@8@3@General format for fixed precision 3 d.p.@ CCCC_MetTmnt@CBO@12.000000@30.000000@0@6@0@Coupling between objects@ CCCC_MetTmnt@COM@999999.000000@999999.000000@0@6@0@Comment lines@ CCCC_MetTmnt@COMper@999999.000000@999999.000000@0@6@3@Comment lines (averaged)@ CCCC_MetTmnt@DIT@3.000000@6.000000@0@1@0@Depth of Inheritance Tree@ CCCC_MetTmnt@FI@12.000000@20.000000@0@6@0@Fan in (overall)@ CCCC_MetTmnt@FIc@6.000000@12.000000@0@6@0@Fan in (concrete uses only)@ CCCC_MetTmnt@FIv@6.000000@12.000000@0@6@0@Fan in (visible uses only)@ CCCC_MetTmnt@FO@12.000000@20.000000@0@6@0@Fan out (overall)@ CCCC_MetTmnt@FOc@6.000000@12.000000@0@6@0@Fan out (concrete uses only)@ CCCC_MetTmnt@FOv@6.000000@12.000000@0@6@0@Fan out (visible uses only)@ CCCC_MetTmnt@IF4@100.000000@1000.000000@0@6@0@Henry-Kafura/Shepperd measure (overall)@ CCCC_MetTmnt@IF4c@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (concrete)@ CCCC_MetTmnt@IF4v@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (visible)@ CCCC_MetTmnt@LOCf@30.000000@100.000000@0@6@0@Lines of code/function@ CCCC_MetTmnt@LOCm@500.000000@2000.000000@0@6@0@Lines of code/single module@ CCCC_MetTmnt@LOCp@999999.000000@999999.000000@0@6@0@Lines of code/project@ CCCC_MetTmnt@LOCper@500.000000@2000.000000@0@6@3@Lines of code/average module@ CCCC_MetTmnt@L_C@1.000000@3.000000@5@6@1@LOC/COM Lines of code/comment line@ CCCC_MetTmnt@MVGf@10.000000@30.000000@0@6@0@Cyclomatic complexity/function@ CCCC_MetTmnt@MVGm@200.000000@1000.000000@0@6@0@Cyclomatic complexity/single module@ CCCC_MetTmnt@MVGp@999999.000000@999999.000000@0@6@0@Cyclomatic complexity/project@ CCCC_MetTmnt@MVGper@200.000000@1000.000000@0@6@3@Cyclomatic complexity/average module@ CCCC_MetTmnt@M_C@5.000000@10.000000@5@6@3@MVG/COM McCabe/comment line@ CCCC_MetTmnt@NOC@4.000000@15.000000@0@6@0@Number of children@ CCCC_MetTmnt@WMC1@30.000000@100.000000@0@6@0@Weighting function=1 unit per method@ CCCC_MetTmnt@WMCv@10.000000@30.000000@0@6@0@Weighting function=1 unit per visible method@ CCCC_Dialect@c++.mfc@BEGIN_MESSAGE_MAP@start_skipping@ CCCC_Dialect@c++.mfc@END_MESSAGE_MAP@stop_skipping@ CCCC_Dialect@c++.stl@__STL_BEGIN_NAMESPACE@ignore@ CCCC_Dialect@c++.stl@__STL_END_NAMESPACE@ignore@ CCCC_Dialect@c++.test4@TEST4_EXT@ignore@ cccc-3.1.4/test/test4.xmlref0000644000000000000000000000576307715610507014374 0ustar rootroot Test4a Test4a definition dummy() definition Test4a Test4a Test4a <file scope items> cccc-3.1.4/test/vanilla.opt0000644000000000000000000000600707271572210014247 0ustar rootrootCCCC_FileExt@.ADA@ada.95@ CCCC_FileExt@.ADB@ada.95@ CCCC_FileExt@.ADS@ada.95@ CCCC_FileExt@.C@c++.ansi@ CCCC_FileExt@.CC@c++.ansi@ CCCC_FileExt@.CPP@c++.ansi@ CCCC_FileExt@.CXX@c++.ansi@ CCCC_FileExt@.H@c++.ansi@ CCCC_FileExt@.H++@c++.ansi@ CCCC_FileExt@.HH@c++.ansi@ CCCC_FileExt@.HPP@c++.ansi@ CCCC_FileExt@.HXX@c++.ansi@ CCCC_FileExt@.J@java@ CCCC_FileExt@.JAV@java@ CCCC_FileExt@.JAVA@java@ CCCC_FileExt@.ada@ada.95@ CCCC_FileExt@.adb@ada.95@ CCCC_FileExt@.ads@ada.95@ CCCC_FileExt@.c@c.ansi@ CCCC_FileExt@.c++@c++.ansi@ CCCC_FileExt@.cc@c++.ansi@ CCCC_FileExt@.cpp@c++.ansi@ CCCC_FileExt@.cxx@c++.ansi@ CCCC_FileExt@.h@c++.ansi@ CCCC_FileExt@.h++@c++.ansi@ CCCC_FileExt@.hh@c++.ansi@ CCCC_FileExt@.hpp@c++.ansi@ CCCC_FileExt@.hxx@c++.ansi@ CCCC_FileExt@.j@java@ CCCC_FileExt@.jav@java@ CCCC_FileExt@.java@java@ CCCC_MetTmnt@8.3@999999.000000@999999.000000@0@8@3@General format for fixed precision 3 d.p.@ CCCC_MetTmnt@CBO@12.000000@30.000000@0@6@0@Coupling between objects@ CCCC_MetTmnt@COM@999999.000000@999999.000000@0@6@0@Comment lines@ CCCC_MetTmnt@COMper@999999.000000@999999.000000@0@6@3@Comment lines (averaged)@ CCCC_MetTmnt@DIT@3.000000@6.000000@0@6@0@Depth of Inheritance Tree@ CCCC_MetTmnt@FI@12.000000@20.000000@0@6@0@Fan in (overall)@ CCCC_MetTmnt@FIc@6.000000@12.000000@0@6@0@Fan in (concrete uses only)@ CCCC_MetTmnt@FIv@6.000000@12.000000@0@6@0@Fan in (visible uses only)@ CCCC_MetTmnt@FO@12.000000@20.000000@0@6@0@Fan out (overall)@ CCCC_MetTmnt@FOc@6.000000@12.000000@0@6@0@Fan out (concrete uses only)@ CCCC_MetTmnt@FOv@6.000000@12.000000@0@6@0@Fan out (visible uses only)@ CCCC_MetTmnt@IF4@100.000000@1000.000000@0@6@0@Henry-Kafura/Shepperd measure (overall)@ CCCC_MetTmnt@IF4c@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (concrete)@ CCCC_MetTmnt@IF4v@30.000000@100.000000@0@6@0@Henry-Kafura/Shepperd measure (visible)@ CCCC_MetTmnt@LOCf@30.000000@100.000000@0@6@0@Lines of code/function@ CCCC_MetTmnt@LOCm@500.000000@2000.000000@0@6@0@Lines of code/single module@ CCCC_MetTmnt@LOCp@999999.000000@999999.000000@0@6@0@Lines of code/project@ CCCC_MetTmnt@LOCper@500.000000@2000.000000@0@6@3@Lines of code/average module@ CCCC_MetTmnt@L_C@7.000000@30.000000@20@6@3@LOC/COM Lines of code/comment line@ CCCC_MetTmnt@MVGf@10.000000@30.000000@0@6@0@Cyclomatic complexity/function@ CCCC_MetTmnt@MVGm@200.000000@1000.000000@0@6@0@Cyclomatic complexity/single module@ CCCC_MetTmnt@MVGp@999999.000000@999999.000000@0@6@0@Cyclomatic complexity/project@ CCCC_MetTmnt@MVGper@200.000000@1000.000000@0@6@3@Cyclomatic complexity/average module@ CCCC_MetTmnt@M_C@5.000000@10.000000@5@6@3@MVG/COM McCabe/comment line@ CCCC_MetTmnt@NOC@4.000000@15.000000@0@6@0@Number of children@ CCCC_MetTmnt@WMC1@30.000000@100.000000@0@6@0@Weighting function=1 unit per method@ CCCC_MetTmnt@WMCv@10.000000@30.000000@0@6@0@Weighting function=1 unit per visible method@ CCCC_Dialect@c++.mfc@BEGIN_MESSAGE_MAP@start_skipping@ CCCC_Dialect@c++.mfc@END_MESSAGE_MAP@stop_skipping@ CCCC_Dialect@c++.stl@__STL_BEGIN_NAMESPACE@ignore@ CCCC_Dialect@c++.stl@__STL_END_NAMESPACE@ignore@ cccc-3.1.4/test/w32bcc.mak0000644000000000000000000000024107345451257013655 0ustar rootroot# Makefile for testing CCCC on Win32 VC platform RM=del RMDIR=rmdir MV=rename ECHO=echo DIFF=diff.bat PATHSEP=\\ CCCC=..\\cccc\\cccc.exe !include rules.mak cccc-3.1.4/test/w32vc.mak0000644000000000000000000000024007345451257013535 0ustar rootroot# Makefile for testing CCCC on Win32 VC platform RM=del RMDIR=rmdir MV=rename ECHO=echo DIFF=diff.bat PATHSEP=\\ CCCC=..\\cccc\\cccc.exe include rules.mak cccc-3.1.4/test/win32_nmake.mak0000644000000000000000000000024007272040214014670 0ustar rootroot# Makefile for testing CCCC on Win32 VC platform RM=del RMDIR=rmdir MV=rename ECHO=echo DIFF=diff.bat PATHSEP=\\ CCCC=..\\cccc\\cccc.exe include rules.mak cccc-3.1.4/vcaddin/0000755000000000000000000000000010357462460012527 5ustar rootrootcccc-3.1.4/vcaddin/res/0000755000000000000000000000000010357462460013320 5ustar rootrootcccc-3.1.4/vcaddin/res/CcccDevStudioAddIn.rc20000644000000000000000000000061507265351225017314 0ustar rootroot// // CCCCDEVSTUDIOADDIN.RC2 - resources Microsoft Visual C++ does not edit directly // #ifdef APSTUDIO_INVOKED #error this file is not editable by Microsoft Visual C++ #endif //APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // Add manually edited resources here... ///////////////////////////////////////////////////////////////////////////// cccc-3.1.4/vcaddin/res/TBarLrge.bmp0000644000000000000000000001456607265351225015476 0ustar rootrootBMvv( zp€€€€€€€€€ÀÀÀ€€€ÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»»»»»wwwwwwwww»»»»»wwwwwwwww»»»»»wwwwwwww»»»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»»»»»wwwwwwwww»»»»»wwwwwwwww»»»»»wwwwwwww»»»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»»www»»wwwwww»»»www»»www»»»www»»wwwww»»»wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»»www»»wwwwww»»»www»»www»»»www»»wwwww»»»wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»wwww»»wwwwww»»wwww»»wwww»»wwww»wwww»»www»wwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»wwww»»wwwwww»»wwww»»wwww»»wwww»wwww»»www»wwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwww»»wwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwww»»wwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwwww»»wwwwwwwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwww»»wwwwwwwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»»wwwwwwwwwww»»wwwwwwwwwwwwww»»wwwwwwwwwwwwwww»»wwwwwwwwwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»wwww»»wwwwwwww»»wwww»»wwwwwwww»»wwww»»wwwwwwwww»»wwww»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»wwww»»wwwwwwww»»wwww»»wwwwwwww»»wwww»»wwwwwwwww»»wwww»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»»www»»wwwwwwww»»»www»»wwwwwwww»»»www»»wwwwwwwww»»»www»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw»»»www»»wwwwwwww»»»www»»wwwwwwww»»»www»»wwwwwwwww»»»www»»wwwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»»»»»ww™wwwwwwww»»»»»ww™wwwwwwww»»»»»ww™wwwwwwwww»»»»»ww™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»»»»»ww™wwwwwwww»»»»»ww™wwwwwwww»»»»»ww™wwwwwwwww»»»»»ww™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwww™™™™wwwwwwwwwwww™™™™wwwwwwwwwwww™™™™wwwwwwwwwwwww™™™™wwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwww™™™™wwwwwwwwwwww™™™™wwwwwwwwwwww™™™™wwwwwwwwwwwww™™™™wwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwww™w™wwwwwwwwwwwww™w™wwwwwwwwwwwww™w™wwwwwwwwwwwwww™w™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwww™w™wwwwwwwwwwwww™w™wwwwwwwwwwwww™w™wwwwwwwwwwwwww™w™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwww™™wwwwwwwwwwwwww™™wwwwwwwwwwwwww™™wwwwwwwwwwwwwww™™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwww™™wwwwwwwwwwwwww™™wwwwwwwwwwwwww™™wwwwwwwwwwwwwww™™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwwww™wwwwwwwwwwwwwww™wwwwwwwwwwwwwww™wwwwwwwwwwwwwwww™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwwww™wwwwwwwwwwwwwww™wwwwwwwwwwwwwww™wwwwwwwwwwwwwwww™wwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿcccc-3.1.4/vcaddin/res/TBarMedm.bmp0000644000000000000000000000346607265351225015464 0ustar rootrootBM6v(ÒÀ€€€€€€€€€ÀÀÀ€€€ÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwwwwwwpwwwwwwwwwwwwwwpwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ w{»»wwww{»»pwww{»»ppww»»wwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ@­{»w{·ww{»w{°w{»w{°pw»·pwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww{·w{·ww{·w{°p{·w{pw»wp°pwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»wwwwww»wwwpp»wwwp{·wpwpwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»ww»wwwpw»wwwpp»wwwp{·wwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»ww»wwwwww»wwwpw»wwwwwww{·wwpwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww»wwwwww»wwwwwww»wwwwwww{·wwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿww»»wwwwpw»wwwwwww»wwwwwww{·wwwwwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿw™w{·w{·www{·w{·www{·w{·wwww»ww»wwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwww{»w{·www{»w{·www{»w{·wwww»·w»wwwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwww{»»w—www{»»w—www{»»w—wwww»»·ywwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ™™wwwww™™wwwwww™™wwwwww™™wwwwwwy™—wÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwww——wwwwww——wwwwww——wwwwwwyywwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwwwwwy—wwwwwwy—wwwwwwy—wwwwwww™wwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwww—wwwwwww—wwwwwww—wwwwwwwywwÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿwwwcccc-3.1.4/vcaddin/CcccDevStudioAddIn.cpp0000644000000000000000000001102707265351164016620 0ustar rootroot// CcccDevStudioAddIn.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include // Turn off warnings due to long names arising out of STL use #pragma warning ( disable : 4786 4503 ) #include "CcccDevStudioAddIn.h" #include "DSAddIn.h" #include "Commands.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CComModule _Module; BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_DSAddIn, CDSAddIn) END_OBJECT_MAP() ///////////////////////////////////////////////////////////////////////////// // CCcccDevStudioAddInApp class CCcccDevStudioAddInApp : public CWinApp { public: CCcccDevStudioAddInApp(); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCcccDevStudioAddInApp) public: virtual BOOL InitInstance(); virtual int ExitInstance(); //}}AFX_VIRTUAL //{{AFX_MSG(CCcccDevStudioAddInApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// // CCcccDevStudioAddInApp BEGIN_MESSAGE_MAP(CCcccDevStudioAddInApp, CWinApp) //{{AFX_MSG_MAP(CCcccDevStudioAddInApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // The one and only CCcccDevStudioAddInApp object CCcccDevStudioAddInApp theApp; ///////////////////////////////////////////////////////////////////////////// // CCcccDevStudioAddInApp construction CCcccDevStudioAddInApp::CCcccDevStudioAddInApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // CCcccDevStudioAddInApp initialization BOOL CCcccDevStudioAddInApp::InitInstance() { _Module.Init(ObjectMap, m_hInstance); return CWinApp::InitInstance(); } int CCcccDevStudioAddInApp::ExitInstance() { _Module.Term(); return CWinApp::ExitInstance(); } ///////////////////////////////////////////////////////////////////////////// // Special entry points required for inproc servers STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); return _Module.GetClassObject(rclsid, riid, ppv); } STDAPI DllCanUnloadNow(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE; } // by exporting DllRegisterServer, you can use regsvr32.exe STDAPI DllRegisterServer(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); HRESULT hRes = S_OK; // Registers object, typelib and all interfaces in typelib hRes = _Module.RegisterServer(TRUE); if (FAILED(hRes)) return hRes; // Register description of this add-in object in its own // "/Description" subkey. // TODO: If you add more add-ins to this module, you need // to register all of their descriptions, each description // in each add-in object's registry CLSID entry: // HKEY_CLASSES_ROOT\Clsid\{add-in CLSID}\Description="add-in description" _ATL_OBJMAP_ENTRY* pEntry = _Module.m_pObjMap; CRegKey key; LONG lRes = key.Open(HKEY_CLASSES_ROOT, _T("CLSID")); if (lRes == ERROR_SUCCESS) { USES_CONVERSION; LPOLESTR lpOleStr; StringFromCLSID(*pEntry->pclsid, &lpOleStr); LPTSTR lpsz = OLE2T(lpOleStr); lRes = key.Open(key, lpsz); if (lRes == ERROR_SUCCESS) { CString strDescription; strDescription.LoadString(IDS_CCCCDEVSTUDIOADDIN_DESCRIPTION); key.SetKeyValue(_T("Description"), strDescription); } CoTaskMemFree(lpOleStr); } if (lRes != ERROR_SUCCESS) hRes = HRESULT_FROM_WIN32(lRes); return hRes; } ///////////////////////////////////////////////////////////////////////////// // DllUnregisterServer - Removes entries from the system registry STDAPI DllUnregisterServer(void) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); HRESULT hRes = S_OK; _Module.UnregisterServer(); return hRes; } ///////////////////////////////////////////////////////////////////////////// // Debugging support // GetLastErrorDescription is used in the implementation of the VERIFY_OK // macro, defined in stdafx.h. #ifdef _DEBUG void GetLastErrorDescription(CComBSTR& bstr) { CComPtr pErrorInfo; if (GetErrorInfo(0, &pErrorInfo) == S_OK) pErrorInfo->GetDescription(&bstr); } #endif //_DEBUG cccc-3.1.4/vcaddin/CcccDevStudioAddIn.def0000644000000000000000000000050107265351164016567 0ustar rootroot; CcccDevStudioAddIn.def : Declares the module parameters for the DLL. LIBRARY "CCCCDEVSTUDIOADDIN" DESCRIPTION 'CCCCDEVSTUDIOADDIN Windows Dynamic Link Library' EXPORTS ; Explicit exports can go here DllCanUnloadNow PRIVATE DllGetClassObject PRIVATE DllRegisterServer PRIVATE DllUnregisterServer PRIVATE cccc-3.1.4/vcaddin/CcccDevStudioAddIn.dsp0000644000000000000000000001222607267567717016645 0ustar rootroot# Microsoft Developer Studio Project File - Name="CcccDevStudioAddIn" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=CcccDevStudioAddIn - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "CcccDevStudioAddIn.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "CcccDevStudioAddIn.mak" CFG="CcccDevStudioAddIn - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "CcccDevStudioAddIn - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "CcccDevStudioAddIn - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" # PROP BASE Use_MFC 2 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 2 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "release" # PROP Intermediate_Dir "release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 # ADD BASE RSC /l 0xc09 /d "NDEBUG" /d "_AFXDLL" # ADD RSC /l 0xc09 /d "NDEBUG" /d "_AFXDLL" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /dll /machine:I386 # ADD LINK32 mapi32.lib mpr.lib /nologo /subsystem:windows /dll /machine:I386 !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" # PROP BASE Use_MFC 2 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 2 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "debug" # PROP Intermediate_Dir "debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /FR /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 # ADD BASE RSC /l 0xc09 /d "_DEBUG" /d "_AFXDLL" # ADD RSC /l 0xc09 /d "_DEBUG" /d "_AFXDLL" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 mapi32.lib mpr.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "CcccDevStudioAddIn - Win32 Release" # Name "CcccDevStudioAddIn - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=.\CcccDevStudioAddIn.cpp # End Source File # Begin Source File SOURCE=.\CcccDevStudioAddIn.def # End Source File # Begin Source File SOURCE=.\CcccDevStudioAddIn.odl # ADD MTL /h "CcccDevStudioAddInTypes.h" # End Source File # Begin Source File SOURCE=.\CcccDevStudioAddIn.rc # End Source File # Begin Source File SOURCE=.\CommandForm.cpp # End Source File # Begin Source File SOURCE=.\Commands.cpp # End Source File # Begin Source File SOURCE=.\DevStudioFileStore.cpp # End Source File # Begin Source File SOURCE=.\DSAddIn.cpp # End Source File # Begin Source File SOURCE=.\StdAfx.cpp # ADD CPP /Yc"stdafx.h" # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE=.\CcccDevStudioAddIn.h # End Source File # Begin Source File SOURCE=.\CommandForm.h # End Source File # Begin Source File SOURCE=.\Commands.h # End Source File # Begin Source File SOURCE=.\DevStudioFileStore.h # End Source File # Begin Source File SOURCE=.\DSAddIn.h # End Source File # Begin Source File SOURCE=.\Resource.h # End Source File # Begin Source File SOURCE=.\StdAfx.h # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" # Begin Source File SOURCE=.\res\bitmap1.bmp # End Source File # Begin Source File SOURCE=.\res\bitmap2.bmp # End Source File # Begin Source File SOURCE=.\res\CcccDevStudioAddIn.rc2 # PROP Exclude_From_Scan -1 # PROP BASE Exclude_From_Build 1 # PROP Exclude_From_Build 1 # End Source File # Begin Source File SOURCE=.\res\TBarLrge.bmp # End Source File # Begin Source File SOURCE=.\res\TBarMedm.bmp # End Source File # End Group # Begin Source File SOURCE=.\ReadMe.txt # End Source File # End Target # End Project cccc-3.1.4/vcaddin/CcccDevStudioAddIn.h0000644000000000000000000000136507265351167016274 0ustar rootroot// CcccDevStudioAddIn.h : main header file for the CCCCDEVSTUDIOADDIN DLL // #if !defined(AFX_CCCCDEVSTUDIOADDIN_H__2AB447B3_A834_11D3_AFED_444553540000__INCLUDED_) #define AFX_CCCCDEVSTUDIOADDIN_H__2AB447B3_A834_11D3_AFED_444553540000__INCLUDED_ #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #include #include #include #include #include //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_CCCCDEVSTUDIOADDIN_H__2AB447B3_A834_11D3_AFED_444553540000__INCLUDED) cccc-3.1.4/vcaddin/CcccDevStudioAddIn.mak0000644000000000000000000002476007716073617016623 0ustar rootroot# Microsoft Developer Studio Generated NMAKE File, Based on CcccDevStudioAddIn.dsp !IF "$(CFG)" == "" CFG=CcccDevStudioAddIn - Win32 Debug !MESSAGE No configuration specified. Defaulting to CcccDevStudioAddIn - Win32 Debug. !ENDIF !IF "$(CFG)" != "CcccDevStudioAddIn - Win32 Release" && "$(CFG)" != "CcccDevStudioAddIn - Win32 Debug" !MESSAGE Invalid configuration "$(CFG)" specified. !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "CcccDevStudioAddIn.mak" CFG="CcccDevStudioAddIn - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "CcccDevStudioAddIn - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "CcccDevStudioAddIn - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE !ERROR An invalid configuration is specified. !ENDIF !IF "$(OS)" == "Windows_NT" NULL= !ELSE NULL=nul !ENDIF !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" OUTDIR=.\release INTDIR=.\release # Begin Custom Macros OutDir=.\release # End Custom Macros ALL : "$(OUTDIR)\CcccDevStudioAddIn.dll" "$(OUTDIR)\CcccDevStudioAddIn.tlb" CLEAN : -@erase "$(INTDIR)\CcccDevStudioAddIn.obj" -@erase "$(INTDIR)\CcccDevStudioAddIn.pch" -@erase "$(INTDIR)\CcccDevStudioAddIn.res" -@erase "$(INTDIR)\CcccDevStudioAddIn.tlb" -@erase "$(INTDIR)\CommandForm.obj" -@erase "$(INTDIR)\Commands.obj" -@erase "$(INTDIR)\DevStudioFileStore.obj" -@erase "$(INTDIR)\DSAddIn.obj" -@erase "$(INTDIR)\StdAfx.obj" -@erase "$(INTDIR)\vc60.idb" -@erase "$(OUTDIR)\CcccDevStudioAddIn.dll" -@erase "$(OUTDIR)\CcccDevStudioAddIn.exp" -@erase "$(OUTDIR)\CcccDevStudioAddIn.lib" -@erase ".\CcccDevStudioAddInTypes.h" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP=cl.exe CPP_PROJ=/nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /Fp"$(INTDIR)\CcccDevStudioAddIn.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c .c{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .c{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << MTL=midl.exe MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 RSC=rc.exe RSC_PROJ=/l 0xc09 /fo"$(INTDIR)\CcccDevStudioAddIn.res" /d "NDEBUG" /d "_AFXDLL" BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\CcccDevStudioAddIn.bsc" BSC32_SBRS= \ LINK32=link.exe LINK32_FLAGS=mapi32.lib mpr.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"$(OUTDIR)\CcccDevStudioAddIn.pdb" /machine:I386 /def:".\CcccDevStudioAddIn.def" /out:"$(OUTDIR)\CcccDevStudioAddIn.dll" /implib:"$(OUTDIR)\CcccDevStudioAddIn.lib" DEF_FILE= \ ".\CcccDevStudioAddIn.def" LINK32_OBJS= \ "$(INTDIR)\CcccDevStudioAddIn.obj" \ "$(INTDIR)\CommandForm.obj" \ "$(INTDIR)\Commands.obj" \ "$(INTDIR)\DevStudioFileStore.obj" \ "$(INTDIR)\DSAddIn.obj" \ "$(INTDIR)\StdAfx.obj" \ "$(INTDIR)\CcccDevStudioAddIn.res" "$(OUTDIR)\CcccDevStudioAddIn.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) $(LINK32) @<< $(LINK32_FLAGS) $(LINK32_OBJS) << !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" OUTDIR=.\debug INTDIR=.\debug # Begin Custom Macros OutDir=.\debug # End Custom Macros ALL : "$(OUTDIR)\CcccDevStudioAddIn.dll" "$(OUTDIR)\CcccDevStudioAddIn.tlb" ".\CcccDevStudioAddInTypes.h" "$(OUTDIR)\CcccDevStudioAddIn.bsc" CLEAN : -@erase "$(INTDIR)\CcccDevStudioAddIn.obj" -@erase "$(INTDIR)\CcccDevStudioAddIn.pch" -@erase "$(INTDIR)\CcccDevStudioAddIn.res" -@erase "$(INTDIR)\CcccDevStudioAddIn.sbr" -@erase "$(INTDIR)\CcccDevStudioAddIn.tlb" -@erase "$(INTDIR)\CommandForm.obj" -@erase "$(INTDIR)\CommandForm.sbr" -@erase "$(INTDIR)\Commands.obj" -@erase "$(INTDIR)\Commands.sbr" -@erase "$(INTDIR)\DevStudioFileStore.obj" -@erase "$(INTDIR)\DevStudioFileStore.sbr" -@erase "$(INTDIR)\DSAddIn.obj" -@erase "$(INTDIR)\DSAddIn.sbr" -@erase "$(INTDIR)\StdAfx.obj" -@erase "$(INTDIR)\StdAfx.sbr" -@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.pdb" -@erase "$(OUTDIR)\CcccDevStudioAddIn.bsc" -@erase "$(OUTDIR)\CcccDevStudioAddIn.dll" -@erase "$(OUTDIR)\CcccDevStudioAddIn.exp" -@erase "$(OUTDIR)\CcccDevStudioAddIn.ilk" -@erase "$(OUTDIR)\CcccDevStudioAddIn.lib" -@erase "$(OUTDIR)\CcccDevStudioAddIn.pdb" -@erase ".\CcccDevStudioAddInTypes.h" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP=cl.exe CPP_PROJ=/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\CcccDevStudioAddIn.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c .c{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << .c{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cpp{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << .cxx{$(INTDIR)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << MTL=midl.exe MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 RSC=rc.exe RSC_PROJ=/l 0xc09 /fo"$(INTDIR)\CcccDevStudioAddIn.res" /d "_DEBUG" /d "_AFXDLL" BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\CcccDevStudioAddIn.bsc" BSC32_SBRS= \ "$(INTDIR)\CcccDevStudioAddIn.sbr" \ "$(INTDIR)\CommandForm.sbr" \ "$(INTDIR)\Commands.sbr" \ "$(INTDIR)\DevStudioFileStore.sbr" \ "$(INTDIR)\DSAddIn.sbr" \ "$(INTDIR)\StdAfx.sbr" "$(OUTDIR)\CcccDevStudioAddIn.bsc" : "$(OUTDIR)" $(BSC32_SBRS) $(BSC32) @<< $(BSC32_FLAGS) $(BSC32_SBRS) << LINK32=link.exe LINK32_FLAGS=mapi32.lib mpr.lib /nologo /subsystem:windows /dll /incremental:yes /pdb:"$(OUTDIR)\CcccDevStudioAddIn.pdb" /debug /machine:I386 /def:".\CcccDevStudioAddIn.def" /out:"$(OUTDIR)\CcccDevStudioAddIn.dll" /implib:"$(OUTDIR)\CcccDevStudioAddIn.lib" /pdbtype:sept DEF_FILE= \ ".\CcccDevStudioAddIn.def" LINK32_OBJS= \ "$(INTDIR)\CcccDevStudioAddIn.obj" \ "$(INTDIR)\CommandForm.obj" \ "$(INTDIR)\Commands.obj" \ "$(INTDIR)\DevStudioFileStore.obj" \ "$(INTDIR)\DSAddIn.obj" \ "$(INTDIR)\StdAfx.obj" \ "$(INTDIR)\CcccDevStudioAddIn.res" "$(OUTDIR)\CcccDevStudioAddIn.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) $(LINK32) @<< $(LINK32_FLAGS) $(LINK32_OBJS) << !ENDIF !IF "$(NO_EXTERNAL_DEPS)" != "1" !IF EXISTS("CcccDevStudioAddIn.dep") !INCLUDE "CcccDevStudioAddIn.dep" !ELSE !MESSAGE Warning: cannot find "CcccDevStudioAddIn.dep" !ENDIF !ENDIF !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" || "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" SOURCE=.\CcccDevStudioAddIn.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\CcccDevStudioAddIn.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" ".\CcccDevStudioAddInTypes.h" !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\CcccDevStudioAddIn.obj" "$(INTDIR)\CcccDevStudioAddIn.sbr" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ENDIF SOURCE=.\CcccDevStudioAddIn.odl !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" MTL_SWITCHES=/nologo /D "NDEBUG" /tlb "$(OUTDIR)\CcccDevStudioAddIn.tlb" /h "CcccDevStudioAddInTypes.h" /mktyplib203 /o "NUL" /win32 "$(OUTDIR)\CcccDevStudioAddIn.tlb" ".\CcccDevStudioAddInTypes.h" : $(SOURCE) "$(OUTDIR)" $(MTL) @<< $(MTL_SWITCHES) $(SOURCE) << !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" MTL_SWITCHES=/nologo /D "_DEBUG" /tlb "$(OUTDIR)\CcccDevStudioAddIn.tlb" /h "CcccDevStudioAddInTypes.h" /mktyplib203 /o "NUL" /win32 "$(OUTDIR)\CcccDevStudioAddIn.tlb" ".\CcccDevStudioAddInTypes.h" : $(SOURCE) "$(OUTDIR)" $(MTL) @<< $(MTL_SWITCHES) $(SOURCE) << !ENDIF SOURCE=.\CcccDevStudioAddIn.rc !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\CcccDevStudioAddIn.res" : $(SOURCE) "$(INTDIR)" $(RSC) /l 0xc09 /fo"$(INTDIR)\CcccDevStudioAddIn.res" /i "release" /d "NDEBUG" /d "_AFXDLL" $(SOURCE) !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\CcccDevStudioAddIn.res" : $(SOURCE) "$(INTDIR)" $(RSC) /l 0xc09 /fo"$(INTDIR)\CcccDevStudioAddIn.res" /i "debug" /d "_DEBUG" /d "_AFXDLL" $(SOURCE) !ENDIF SOURCE=.\CommandForm.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\CommandForm.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\CommandForm.obj" "$(INTDIR)\CommandForm.sbr" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ENDIF SOURCE=.\Commands.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\Commands.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" ".\CcccDevStudioAddInTypes.h" !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\Commands.obj" "$(INTDIR)\Commands.sbr" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ENDIF SOURCE=.\DevStudioFileStore.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\DevStudioFileStore.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\DevStudioFileStore.obj" "$(INTDIR)\DevStudioFileStore.sbr" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ENDIF SOURCE=.\DSAddIn.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" "$(INTDIR)\DSAddIn.obj" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" ".\CcccDevStudioAddInTypes.h" !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" "$(INTDIR)\DSAddIn.obj" "$(INTDIR)\DSAddIn.sbr" : $(SOURCE) "$(INTDIR)" "$(INTDIR)\CcccDevStudioAddIn.pch" !ENDIF SOURCE=.\StdAfx.cpp !IF "$(CFG)" == "CcccDevStudioAddIn - Win32 Release" CPP_SWITCHES=/nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /Fp"$(INTDIR)\CcccDevStudioAddIn.pch" /Yc"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c "$(INTDIR)\StdAfx.obj" "$(INTDIR)\CcccDevStudioAddIn.pch" : $(SOURCE) "$(INTDIR)" $(CPP) @<< $(CPP_SWITCHES) $(SOURCE) << !ELSEIF "$(CFG)" == "CcccDevStudioAddIn - Win32 Debug" CPP_SWITCHES=/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_USRDLL" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\CcccDevStudioAddIn.pch" /Yc"stdafx.h" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c "$(INTDIR)\StdAfx.obj" "$(INTDIR)\StdAfx.sbr" "$(INTDIR)\CcccDevStudioAddIn.pch" : $(SOURCE) "$(INTDIR)" $(CPP) @<< $(CPP_SWITCHES) $(SOURCE) << !ENDIF !ENDIF cccc-3.1.4/vcaddin/CcccDevStudioAddIn.odl0000644000000000000000000000357007265351167016623 0ustar rootroot// CcccDevStudioAddIn.odl : type library source for CcccDevStudioAddIn.dll // This file will be processed by the Make Type Library (mktyplib) tool to // produce the type library (CcccDevStudioAddIn.tlb). [ uuid(2AB447AF-A834-11D3-AFED-444553540000), version(1.0), helpstring ("CCCCDEVSTUDIOADDIN Developer Studio Add-in") ] library CcccDevStudioAddIn { importlib("stdole32.tlb"); // Dual interface for CCommands // // All commands that your add-in adds to DevStudio // must appear in this interface. You may use the // ClassView to add methods to this interface, which // will cause stub implementations of those methods to // appear in your CCommands class. [ uuid(2AB447AB-A834-11D3-AFED-444553540000), oleautomation, dual ] interface ICommands : IDispatch { // methods [id(1)] HRESULT CcccDevStudioAddInCommandMethod(); [id(2), helpstring("method configureCCCCDevStudioAddIn")] HRESULT configureCCCCDevStudioAddIn(); [id(3), helpstring("method runCCCCOnActiveFile")] HRESULT runCCCCOnActiveFile(); [id(4), helpstring("method runCCCCOnProjectFiles")] HRESULT runCCCCOnProjectFiles(); [id(5), helpstring("method runCCCCOnWorkspaceFiles")] HRESULT runCCCCOnWorkspaceFiles(); [id(6), helpstring("method configureAddIn")] HRESULT configureAddIn(); [id(7), helpstring("method UserCommand1")] HRESULT userCommand1(); [id(8), helpstring("method UserCommand2")] HRESULT userCommand2(); [id(9), helpstring("method UserCommand3")] HRESULT userCommand3(); [id(10), helpstring("method UserCommand4")] HRESULT userCommand4(); [id(11), helpstring("method UserCommand5")] HRESULT userCommand5(); [id(12), helpstring("method UserCommand6")] HRESULT userCommand6(); }; // Class information for CCommands [ uuid(2AB447AC-A834-11D3-AFED-444553540000) ] coclass Commands { [default] interface ICommands; }; //{{AFX_APPEND_ODL}} //}}AFX_APPEND_ODL}} }; cccc-3.1.4/vcaddin/CcccDevStudioAddIn.rc0000644000000000000000000001324007265351172016440 0ustar rootroot//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904B0" BEGIN VALUE "CompanyName", "\0" VALUE "FileDescription", "CCCCDEVSTUDIOADDIN DLL\0" VALUE "FileVersion", "1, 0, 0, 1\0" VALUE "InternalName", "CCCCDEVSTUDIOADDIN\0" VALUE "LegalCopyright", "Copyright (C) 1996\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "CCCCDEVSTUDIOADDIN.DLL\0" VALUE "ProductName", "CCCCDEVSTUDIOADDIN Dynamic Link Library\0" VALUE "ProductVersion", "1, 0, 0, 1\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #endif // !_MAC #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // English (Australia) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENA) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS #pragma code_page(1252) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "#define _AFX_NO_SPLITTER_RESOURCES\r\n" "#define _AFX_NO_OLE_RESOURCES\r\n" "#define _AFX_NO_TRACKER_RESOURCES\r\n" "#define _AFX_NO_PROPERTY_RESOURCES\r\n" "\r\n" "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" "#ifdef _WIN32\r\n" "LANGUAGE 9, 1\r\n" "#pragma code_page(1252)\r\n" "#endif\r\n" "#include ""res\\CcccDevStudioAddIn.rc2"" // non-Microsoft Visual C++ edited resources\r\n" "#include ""afxres.rc"" // Standard components\r\n" "#endif\r\n" "1 TYPELIB ""CcccDevStudioAddIn.tlb""\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Bitmap // IDR_TOOLBAR_MEDIUM BITMAP MOVEABLE PURE "res\\TBarMedm.bmp" IDR_TOOLBAR_LARGE BITMAP DISCARDABLE "res\\TBarLrge.bmp" ///////////////////////////////////////////////////////////////////////////// // // Dialog // IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 258, 159 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Dialog" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",IDOK,37,131,50,14 PUSHBUTTON "Cancel",IDCANCEL,167,131,50,14 EDITTEXT IDC_EDIT1,70,17,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT2,70,30,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT3,70,44,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT4,70,57,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT5,70,70,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT6,70,82,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT7,70,95,181,12,ES_AUTOHSCROLL EDITTEXT IDC_EDIT8,70,108,181,12,ES_AUTOHSCROLL LTEXT "MSVC CCCC Add-In Commands",IDC_STATIC,76,4,109,8 PUSHBUTTON "Defaults",IDC_BUTTON1,102,131,50,14 LTEXT "CCCC program",IDC_STATIC,7,20,57,8 LTEXT "User commands",IDC_STATIC,7,47,60,8 LTEXT "Browser program",IDC_STATIC,7,33,60,8 END ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN IDD_DIALOG1, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 251 TOPMARGIN, 4 BOTTOMMARGIN, 152 END END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // String Table // STRINGTABLE DISCARDABLE BEGIN IDS_CCCCDEVSTUDIOADDIN_LONGNAME "CcccDevStudioAddIn" IDS_CCCCDEVSTUDIOADDIN_DESCRIPTION "Integrates the CCCC metric analysis tool into the Developer Studio IDE." END #endif // English (Australia) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // #define _AFX_NO_SPLITTER_RESOURCES #define _AFX_NO_OLE_RESOURCES #define _AFX_NO_TRACKER_RESOURCES #define _AFX_NO_PROPERTY_RESOURCES #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE 9, 1 #pragma code_page(1252) #endif #include "res\CcccDevStudioAddIn.rc2" // non-Microsoft Visual C++ edited resources #include "afxres.rc" // Standard components #endif 1 TYPELIB "CcccDevStudioAddIn.tlb" ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED cccc-3.1.4/vcaddin/CommandForm.cpp0000644000000000000000000002067507265351175015453 0ustar rootroot// CommandForm.cpp : implementation file // #include "stdafx.h" // Turn off warnings due to long names arising out of STL use #pragma warning ( disable : 4786 4503 ) #include "CcccDevStudioAddIn.h" #include "CommandForm.h" #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif namespace { // This namespace encapsulates a function to search for // a particular file in a list of directories. // Parameter fileName is initialized with the unqualified name // of the file which is sought, while path contains a list of // strings for the directories where the file might be. typedef std::list PathList; bool findFileOnPath(std::string& fileName, const PathList& path) { bool retval=false; PathList::const_iterator plIter=path.begin(); while( (retval==false) && (plIter!=path.end()) ) { std::string testName=*plIter+fileName; std::ifstream testStr(testName.c_str()); if(testStr.good()) { retval=true; fileName="\""+testName+"\""; } plIter++; } return retval; } // end of findFileOnPath() } // end of anonymous namespace // The standard for registry paths appears to be Software// // hence the fact that I am putting my name in your registry. // It's not just vanity, honest. HKEY registryTopLevelKey=HKEY_CURRENT_USER; const char* registryKeyPath="Software\\TimLittlefair\\CcccDevStudioAddIn"; const char* registryValueName="STRINGS"; const int BUF_SIZE=10240; ///////////////////////////////////////////////////////////////////////////// // CCommandForm dialog CCommandForm::CCommandForm(CWnd* pParent /*=NULL*/) : CDialog(CCommandForm::IDD, pParent) { //{{AFX_DATA_INIT(CCommandForm) //}}AFX_DATA_INIT loadConfiguration(); } CCommandForm::~CCommandForm() { saveConfiguration(); } void CCommandForm::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCommandForm) //}}AFX_DATA_MAP DDX_Text(pDX, IDC_EDIT1, m_Cmd[0]); DDX_Text(pDX, IDC_EDIT2, m_Cmd[1]); DDX_Text(pDX, IDC_EDIT3, m_Cmd[2]); DDX_Text(pDX, IDC_EDIT4, m_Cmd[3]); DDX_Text(pDX, IDC_EDIT5, m_Cmd[4]); DDX_Text(pDX, IDC_EDIT6, m_Cmd[5]); DDX_Text(pDX, IDC_EDIT7, m_Cmd[6]); DDX_Text(pDX, IDC_EDIT8, m_Cmd[7]); // save the modified information in the registry saveConfiguration(); } BEGIN_MESSAGE_MAP(CCommandForm, CDialog) //{{AFX_MSG_MAP(CCommandForm) ON_BN_CLICKED(IDC_BUTTON1, OnDefaults) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCommandForm message handlers void CCommandForm::setDefaults() { // This function is virtual so that it could // be overridden for a specific application // For the moment I am hard-coding the strings required // for my CCCC AddIn app here, but it would be better to // inherit and override. // The next string is used in the message displayed at the end of // this function. std::string missingFiles; // The command to run CCCC. std::string ccccName="cccc.exe"; PathList ccccSearchPath; ccccSearchPath.push_back("C:\\Program Files\\CCCC\\"); if( findFileOnPath(ccccName,ccccSearchPath) ) { m_Cmd[0]=ccccName.c_str(); } else { m_Cmd[0]="echo No location configured for CCCC.EXE"; missingFiles="the program CCCC.EXE"; } // We also need to know the location of a browser. // The default is to search a couple of likely locations for // a copy of Internet Explorer. This is very much the lowest common // denominator because I know it is more likely to be present than // not. The CCCC report should be equally easy to read with a version // of Netscape/Mozilla, Opera, or any other graphical browser (lynx won't // work too well, I'm afraid). // I would welcome advice on other locations IE might be in: the two below // reflect my Win95 OSR2 box at home and WinNT 4.0 at work, so I assume that // Win98, Win98SE and Win2000 may need still different locations. // If you find one of these, please mail me on tim_littlefair@hotmail.com. std::string browserName="iexplore.exe"; PathList browserSearchPath; browserSearchPath.push_back("C:\\Program Files\\Plus!\\Microsoft Internet\\"); browserSearchPath.push_back("C:\\Program Files\\Internet Explorer\\"); if( findFileOnPath(browserName,browserSearchPath) ) { m_Cmd[1]=browserName.c_str() ; } else { m_Cmd[1]="echo No location configured for HTML browser"; if(missingFiles.size()>0) { missingFiles+=" and "; } missingFiles+="a program to browse HTML reports"; } // Finally, report back on the process std::string message; if(missingFiles.size()==0) { message="The add-in has configured itself to use"; message+=m_Cmd[0]; message+=" to analyze files and "; message+=m_Cmd[1]; message+=" to browse the resulting HTML reports. "; message+="These locations can be changed at any time using the "; message+="configuration toolbar button."; } else { message="The add-in's self-configuration script has been " "unable too find "; message+=missingFiles; message+=". You will need to use the configuration toolbar " "button to specify a location for the missing program(s) " "before using the add-in to analyze files."; } AfxMessageBox(message.c_str()); // save the configuration data in the registry. saveConfiguration(); } CString CCommandForm::cmdText(int index) { CString retval; if(index>=0 && index<8) { retval=m_Cmd[index]; } return retval; } void CCommandForm::OnDefaults() { // TODO: Add your control notification handler code here setDefaults(); EndDialog(IDCANCEL); } void CCommandForm::loadConfiguration() { // The VC doco says that the RegCreateKey API is only provided // for legacy compatibility, but it seems to be less fussy // than other alternatives. HKEY configKey; DWORD type; unsigned char stringBuffer[BUF_SIZE]; DWORD sbufLen=BUF_SIZE; LONG keyStatus=RegCreateKey( registryTopLevelKey,registryKeyPath,&configKey); if(keyStatus!=ERROR_SUCCESS) { // failed to create or open the key // fall back on the defaults setDefaults(); } else { LONG queryStatus=RegQueryValueEx( configKey,registryValueName,0, &type,stringBuffer,&sbufLen); if(queryStatus==ERROR_SUCCESS && type==REG_MULTI_SZ) { // Success - suck in the values int i=0; // The Win32 API uses unsigned chars which makes it // unsuitable for passing to strlen etc. // Hence we keep two differently typed pointers which // we move over the same memory locations. unsigned char *uptr=stringBuffer; char *ptr=reinterpret_cast(uptr); while(i<8 && uptr<(stringBuffer+sbufLen-2)) { // copy the current null terminated string to a // member of the local array m_Cmd[i]=ptr; // advance ptr to point to the character after the // terminating zero byte ptr+=strlen(ptr)+1; uptr+=strlen(ptr)+1; i++; } } else { // Whereas not finding the key is a normal situation for first // running the program, finding the key but then not finding the // value is an unexpected situation, so we report it. AfxMessageBox( "Registry value query failed, " "default configuration will be used. " ); setDefaults(); } RegCloseKey(configKey); } } void CCommandForm::saveConfiguration() { HKEY configKey; unsigned char stringBuffer[BUF_SIZE]; DWORD sbufLen=BUF_SIZE; LONG keyStatus=RegCreateKey( registryTopLevelKey,registryKeyPath,&configKey); if(keyStatus!=ERROR_SUCCESS) { // failed to create or open the key // fall back on the defaults AfxMessageBox("Failed to open registry key"); setDefaults(); } else { // pump out the values int i=0; memset(stringBuffer,0,BUF_SIZE); // The Win32 API uses unsigned chars which makes it // unsuitable for passing to strlen etc. // Hence we keep two differently typed pointers which // we move over the same memory locations. unsigned char *uptr=stringBuffer; char *ptr=reinterpret_cast(uptr); while(i<8 && (uptr+strlen(ptr)+2)<(stringBuffer+sbufLen) ) { // copy the current string into the buffer, starting at ptr strcpy(ptr,m_Cmd[i]); // advance ptr to point to the character after the // terminating zero byte ptr+=strlen(ptr)+1; uptr+=strlen(ptr)+1; i++; } LONG setStatus=RegSetValueEx( configKey,registryValueName,0, REG_MULTI_SZ,stringBuffer,sbufLen); if(setStatus==ERROR_SUCCESS) { // success - nothing more to do } else { AfxMessageBox("Failed to set registry value"); } RegCloseKey(configKey); } } cccc-3.1.4/vcaddin/CommandForm.h0000644000000000000000000000252007265351175015105 0ustar rootroot#if !defined(AFX_COMMANDFORM_H__406BC922_AE87_11D3_AFED_444553540000__INCLUDED_) #define AFX_COMMANDFORM_H__406BC922_AE87_11D3_AFED_444553540000__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 // CommandForm.h : header file // ///////////////////////////////////////////////////////////////////////////// // CCommandForm dialog class CCommandForm : public CDialog { // Construction public: CCommandForm(CWnd* pParent = NULL); // standard constructor virtual ~CCommandForm(); virtual void setDefaults(); void loadConfiguration(); void saveConfiguration(); // function to allow access to the strings CString cmdText(int index); // Dialog Data //{{AFX_DATA(CCommandForm) enum { IDD = IDD_DIALOG1 }; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCommandForm) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CCommandForm) afx_msg void OnDefaults(); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: CString m_Cmd[8]; }; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_COMMANDFORM_H__406BC922_AE87_11D3_AFED_444553540000__INCLUDED_) cccc-3.1.4/vcaddin/Commands.cpp0000644000000000000000000001735407265351200014777 0ustar rootroot// Commands.cpp : implementation file // #include "stdafx.h" // Turn off warnings due to long names arising out of STL use #pragma warning ( disable : 4786 4503 ) #include "CcccDevStudioAddIn.h" #include "Commands.h" #include "CommandForm.h" #include #include #include #include #include #include "DevStudioFileStore.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif namespace { // The CCommandForm class defines a dialog // which basicly stores 8 editable strings // which can be used as configuration data. // The first four are used below, we wrap them // with appropriate names. CCommandForm cmdForm; std::string ccccCommand() { return cmdForm.cmdText(0).GetBuffer(0); } std::string browserCommand() { return cmdForm.cmdText(1).GetBuffer(0); } // the user commands are stored after the // strings reserved for use in the CCCC commands std::string userCommand(int whichOne) { // the user commands are indexed from one, so // we find the one we want by adding the index // to the index of the last space in the command // configuration form reserved for use by the add-in return cmdForm.cmdText(1+whichOne); } } ///////////////////////////////////////////////////////////////////////////// // CCommands CCommands::CCommands() { m_pApplication = NULL; } CCommands::~CCommands() { ASSERT (m_pApplication != NULL); m_pApplication->Release(); } void CCommands::SetApplicationObject(IApplication* pApplication) { // This function assumes pApplication has already been AddRef'd // for us, which CDSAddIn did in its QueryInterface call // just before it called us. m_pApplication = pApplication; } ///////////////////////////////////////////////////////////////////////////// // CCommands methods STDMETHODIMP CCommands::CcccDevStudioAddInCommandMethod() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: Replace this with the actual code to execute this command // Use m_pApplication to access the Developer Studio Application object, // and VERIFY_OK to see error strings in DEBUG builds of your add-in // (see stdafx.h) VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); AfxMessageBox(_T("CcccDevStudioAddIn Command invoked."), MB_OK | MB_ICONINFORMATION); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_OK; } STDMETHODIMP CCommands::configureCCCCDevStudioAddIn() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here cmdForm.DoModal(); return S_OK; } STDMETHODIMP CCommands::runCCCCOnActiveFile() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here CComPtr pDoc; VERIFY_OK(m_pApplication->get_ActiveDocument(&pDoc)); CComQIPtr p_Document(pDoc); CComBSTR bszStr; VERIFY_OK(p_Document->get_FullName(&bszStr)); CString fileName = bszStr; FilenameList files; files.insert(static_cast(fileName)); runCCCC(files); return S_OK; } STDMETHODIMP CCommands::runCCCCOnProjectFiles() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here FilenameList files; DevStudioFileStore dsfs(m_pApplication,"",""); // get the name of the active project from the workspace CComPtr p_ActiveProject; VERIFY_OK(m_pApplication->get_ActiveProject(&p_ActiveProject)); CComQIPtr p_Project(p_ActiveProject); CComBSTR bszStr; VERIFY_OK(p_Project->get_FullName(&bszStr)); CString projectName = bszStr; dsfs.listProjectFiles(static_cast(projectName),files); runCCCC(files); return S_OK; } STDMETHODIMP CCommands::runCCCCOnWorkspaceFiles() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here FilenameList workspaceFiles; DevStudioFileStore dsfs(m_pApplication,"",""); dsfs.listWorkspaceFiles(workspaceFiles); runCCCC(workspaceFiles); return S_OK; } STDMETHODIMP CCommands::configureAddIn() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here runProcess("c:\\COMMAND /c dir"); return S_OK; } void CCommands::runProcess(const std::string& commandLine) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). const_cast(commandLine.c_str()), // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent’s environment block. NULL, // Use parent’s starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) ) { AfxMessageBox("CreateProcess failed."); } else { // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); } // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); /* char lineBuffer[1024]; FILE *procOutput; std::string outFile=tmpnam(NULL); std::string fullCommand=commandLine+">"+outFile; int cmdStatus=system(fullCommand.c_str()); if(cmdStatus==0) { procOutput = fopen( outFile.c_str(), "rt"); if(procOutput!=NULL) { while( !feof( procOutput ) ) { if( fgets( lineBuffer, 1023, procOutput ) != NULL ) { VERIFY_OK(m_pApplication->PrintToOutputWindow(CComBSTR(lineBuffer))); } } } else { std::string msg; msg.append("Failed to open "); msg.append(outFile); VERIFY_OK(m_pApplication->PrintToOutputWindow(CComBSTR(msg.c_str()))); } } // else { CComBSTR bstrError; CComPtr pErrorInfo; if (GetErrorInfo(0, &pErrorInfo) == S_OK) { pErrorInfo->GetDescription(&bstrError); } VERIFY_OK(m_pApplication->PrintToOutputWindow(CComBSTR(fullCommand.c_str()))); std::string msg; msg.append("Command result: "); msg.append(strerror(errno)); VERIFY_OK(m_pApplication->PrintToOutputWindow(CComBSTR(msg.c_str()))); VERIFY_OK(m_pApplication->PrintToOutputWindow(bstrError)); } // get rid of the temporary file unlink(outFile.c_str()); */ } void CCommands::runCCCC(const FilenameList& fileList) { // The Win95 command.com can only accept a command line of up // to about 128 characters, so we use the option on CCCC to load the filenames from // a file DevStudioFileStore dsfs(m_pApplication,"",""); std::string ccccBaseDir=dsfs.suggestedWorkingDirectory(); ccccBaseDir.append("\\.cccc"); std::string ccccCommandLine=ccccCommand(); ccccCommandLine.append(" --outdir="); ccccCommandLine.append(ccccBaseDir); FilenameList::const_iterator flIter; for(flIter=fileList.begin(); flIter!=fileList.end(); ++flIter) { ccccCommandLine.append(" "); ccccCommandLine.append(*flIter); } runProcess(ccccCommandLine); std::string browseCommandLine; browseCommandLine=browserCommand(); browseCommandLine.append(" "); browseCommandLine.append(ccccBaseDir); browseCommandLine.append("\\cccc.html"); runProcess(browseCommandLine); } STDMETHODIMP CCommands::userCommand1() { runProcess(userCommand(1)); return S_OK; } STDMETHODIMP CCommands::userCommand2() { runProcess(userCommand(2)); return S_OK; } STDMETHODIMP CCommands::userCommand3() { runProcess(userCommand(3)); return S_OK; } STDMETHODIMP CCommands::userCommand4() { runProcess(userCommand(4)); return S_OK; } STDMETHODIMP CCommands::userCommand5() { runProcess(userCommand(5)); return S_OK; } STDMETHODIMP CCommands::userCommand6() { runProcess(userCommand(6)); return S_OK; } cccc-3.1.4/vcaddin/Commands.h0000644000000000000000000000347607265351200014444 0ustar rootroot// Commands.h : header file // #if !defined(AFX_COMMANDS_H__2AB447BF_A834_11D3_AFED_444553540000__INCLUDED_) #define AFX_COMMANDS_H__2AB447BF_A834_11D3_AFED_444553540000__INCLUDED_ #include "CcccDevStudioAddInTypes.h" #include "DevStudioFileStore.h" class CCommands : public CComDualImpl, public CComObjectRoot, public CComCoClass { protected: IApplication* m_pApplication; public: CCommands(); ~CCommands(); void SetApplicationObject(IApplication* m_pApplication); BEGIN_COM_MAP(CCommands) COM_INTERFACE_ENTRY(IDispatch) COM_INTERFACE_ENTRY(ICommands) END_COM_MAP() DECLARE_NOT_AGGREGATABLE(CCommands) public: STDMETHOD(configureAddIn)(); STDMETHOD(runCCCCOnWorkspaceFiles)(); STDMETHOD(runCCCCOnProjectFiles)(); STDMETHOD(runCCCCOnActiveFile)(); STDMETHOD(configureCCCCDevStudioAddIn)(); STDMETHOD(userCommand1)(); STDMETHOD(userCommand2)(); STDMETHOD(userCommand3)(); STDMETHOD(userCommand4)(); STDMETHOD(userCommand5)(); STDMETHOD(userCommand6)(); // ICommands methods STDMETHOD(CcccDevStudioAddInCommandMethod)(THIS); private: // member variable for the full path to the CCCC binary std::string m_CCCCName; // member variable for the full path to the web browser std::string m_BrowserName; // A utility function to run a process, copying the process's console // output to the Macro tab in the output pane. void runProcess(const std::string& commandLine); // A utility function to run CCCC on a list of files void runCCCC(const FilenameList& fileList); }; typedef CComObject CCommandsObj; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_COMMANDS_H__2AB447BF_A834_11D3_AFED_444553540000__INCLUDED) cccc-3.1.4/vcaddin/DSAddIn.cpp0000644000000000000000000000763307265351200014443 0ustar rootroot// AddInMod.cpp : implementation file // #include "stdafx.h" // Turn off warnings due to long names arising out of STL use #pragma warning ( disable : 4786 4503 ) #include "CcccDevStudioAddIn.h" #include "DSAddIn.h" #include "Commands.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // This is called when the user first loads the add-in, and on start-up // of each subsequent Developer Studio session STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime, long dwCookie, VARIANT_BOOL* OnConnection) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Store info passed to us IApplication* pApplication = NULL; if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication)) || pApplication == NULL) { *OnConnection = VARIANT_FALSE; return S_OK; } m_dwCookie = dwCookie; // Create command dispatch, send info back to DevStudio CCommandsObj::CreateInstance(&m_pCommands); m_pCommands->AddRef(); // The QueryInterface above AddRef'd the Application object. It will // be Release'd in CCommand's destructor. m_pCommands->SetApplicationObject(pApplication); // (see stdafx.h for the definition of VERIFY_OK) VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(), (LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie)); // Inform DevStudio of the commands we implement // TODO: Replace the AddCommand call below with a series of calls, // one for each command your add-in will add. // The command name should not be localized to other languages. The // tooltip, command description, and other strings related to this // command are stored in the string table (IDS_CMD_STRING) and should // be localized. addCommand(pApplication, "runCCCCOnActiveFile","run CCCC on the active file", 0,bFirstTime); addCommand(pApplication, "runCCCCOnProjectFiles","run CCCC on all files in the active project", 1,bFirstTime); addCommand(pApplication, "runCCCCOnWorkspaceFiles","run CCCC on all files in the active workspace", 2,bFirstTime); addCommand(pApplication, "configureCCCCDevStudioAddIn","configure the add-in", 3,bFirstTime); int i; for (i=0; i<6; i++) { char userCommandName[1024], userCommandTip[1024]; sprintf(userCommandName,"UserCommand%d",i+1); sprintf(userCommandTip,"User defined command #%d",i+1); addCommand(pApplication, userCommandName,userCommandTip,i+4,bFirstTime); } *OnConnection = VARIANT_TRUE; return S_OK; } // This is called on shut-down, and also when the user unloads the add-in STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); m_pCommands->Release(); m_pCommands = NULL; // TODO: Perform any cleanup work here return S_OK; } void CDSAddIn::addCommand(IApplication* pApp, LPCSTR methodName, LPCSTR methodTip, long imageIndex, VARIANT_BOOL bFirstTime) { VARIANT_BOOL bRet; // We can simplify on the MS boilerplate code // for this activity by deciding that the command name // and the method name will always be the same. CComBSTR bszMethodName(methodName); CComBSTR bszCmdName(methodName); // We still have to build up the command string CString strMethodName(methodName); CString strCmdString; strCmdString= strMethodName + "\n" + strMethodName + "\n" + methodTip + "\n" + methodTip ; CComBSTR bszCmdString(strCmdString); VERIFY_OK(pApp->AddCommand(bszCmdString, bszMethodName, imageIndex, m_dwCookie, &bRet)); if (bRet == VARIANT_FALSE) { AfxMessageBox("Failed to load command"); } else { // Add toolbar buttons only if this is the first time the add-in // is being loaded. Toolbar buttons are automatically remembered // by Developer Studio from session to session, so we should only // add the toolbar buttons once. if (bFirstTime == VARIANT_TRUE) { VERIFY_OK(pApp-> AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); } } } cccc-3.1.4/vcaddin/DSAddIn.h0000644000000000000000000000264107265351203014105 0ustar rootroot// DSAddIn.h : header file // #if !defined(AFX_DSADDIN_H__2AB447BD_A834_11D3_AFED_444553540000__INCLUDED_) #define AFX_DSADDIN_H__2AB447BD_A834_11D3_AFED_444553540000__INCLUDED_ #include "commands.h" // {2AB447AA-A834-11D3-AFED-444553540000} DEFINE_GUID(CLSID_DSAddIn, 0x2ab447aa, 0xa834, 0x11d3, 0xaf, 0xed, 0x44, 0x45, 0x53, 0x54, 0, 0); ///////////////////////////////////////////////////////////////////////////// // CDSAddIn class CDSAddIn : public IDSAddIn, public CComObjectRoot, public CComCoClass { public: DECLARE_REGISTRY(CDSAddIn, "CcccDevStudioAddIn.DSAddIn.1", "CCCCDEVSTUDIOADDIN Developer Studio Add-in", IDS_CCCCDEVSTUDIOADDIN_LONGNAME, THREADFLAGS_BOTH) CDSAddIn() {} BEGIN_COM_MAP(CDSAddIn) COM_INTERFACE_ENTRY(IDSAddIn) END_COM_MAP() DECLARE_NOT_AGGREGATABLE(CDSAddIn) // IDSAddIns public: STDMETHOD(OnConnection)(THIS_ IApplication* pApp, VARIANT_BOOL bFirstTime, long dwCookie, VARIANT_BOOL* OnConnection); STDMETHOD(OnDisconnection)(THIS_ VARIANT_BOOL bLastTime); protected: CCommandsObj* m_pCommands; DWORD m_dwCookie; private: void addCommand(IApplication* pApp, LPCSTR methodName, LPCSTR methodTip, long imageIndex, VARIANT_BOOL bFirstTime); }; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_DSADDIN_H__2AB447BD_A834_11D3_AFED_444553540000__INCLUDED) cccc-3.1.4/vcaddin/DevStudioFileStore.cpp0000644000000000000000000002077507265351207016771 0ustar rootroot// DevStudioFileStore.cpp: implementation of the DevStudioFileStore class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" // Turn off warnings due to long names arising out of STL use #pragma warning ( disable : 4786 4503 ) #include "CcccDevStudioAddIn.h" #include "DevStudioFileStore.h" // Use of the COM interface to the Visual Studio workspace is // localised to this file. #include #include #include #include #include #include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif // This file contains logic shamelessly copied from Joshua C. Jensen's // Workspace Utilities package. ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// DevStudioFileStore::DevStudioFileStore(IApplication *pApp, const std::string& wsDir, const std::string& wsName) : m_pApplication(pApp) , m_WorkspaceDirectory(wsDir) , m_WorkspaceName(wsName) { CComBSTR bszWSPath, bszWSName, bszWSFullName; VERIFY_OK(m_pApplication->get_Path(&bszWSPath)); VERIFY_OK(m_pApplication->get_Name(&bszWSName)); VERIFY_OK(m_pApplication->get_FullName(&bszWSFullName)); VERIFY_OK(m_pApplication->PrintToOutputWindow(bszWSPath)); VERIFY_OK(m_pApplication->PrintToOutputWindow(bszWSName)); VERIFY_OK(m_pApplication->PrintToOutputWindow(bszWSFullName)); // First, get a pointer to the dispatch for the Projects collection CComPtr pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr pProjects(pDispProjects); // Get the number of projects in the collection long workspaceProjectCount; VERIFY_OK(pProjects->get_Count(&workspaceProjectCount)); // get information on the projects for (long i = 1; i < workspaceProjectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr pProject(pGenProject); CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; ProjectFileStore::value_type pfsPair; std::string pfsName=projectName.GetBuffer(0); FilenameList pfsList; collectFilenames(pfsName,"SOURCE=",pfsList); m_ProjectFileStore.insert(std::make_pair(pfsName,pfsList)); } // end for [1..workspaceProjectCount] // dumpProjectFileList(); } DevStudioFileStore::~DevStudioFileStore() { } void DevStudioFileStore::listWorkspaceFiles(FilenameList& fileList) { ProjectFileStore::const_iterator pfsIter; for(pfsIter=m_ProjectFileStore.begin(); pfsIter!=m_ProjectFileStore.end(); ++pfsIter) { FilenameList::const_iterator flIter; for(flIter=pfsIter->second.begin(); flIter!=pfsIter->second.end(); ++flIter) { fileList.insert(*flIter); } } } void DevStudioFileStore::listProjectFiles(std::string projectName, FilenameList& fileList) { ProjectFileStore::const_iterator pfsIter; pfsIter=m_ProjectFileStore.find(projectName); std::string fileNames; if(pfsIter!=m_ProjectFileStore.end()) { FilenameList::const_iterator flIter; for(flIter=pfsIter->second.begin(); flIter!=pfsIter->second.end(); ++flIter) { fileList.insert(*flIter); fileNames+=*flIter+" "; } dump(fileNames); } else { std::string msg = "Project "; msg.append(projectName); msg.append(" not found"); AfxMessageBox(msg.c_str()); } } std::string DevStudioFileStore::composeFilename(const std::string& baseDir, const std::string& relName) { std::string retval; // baseDir can either be a directory specification ending in a '\' or '/' // or a file specification. // Either way // Now resolve relative paths. // We want to arrive at a canonical name for the file, that is a // name which gives the drive letter and full path, with no use of // ".." . We are provided with the name of the referring file // and a filename (possibly) relative to that location. // Our algorithm is to compose a non-canonical name by examining // the potentially relative name and prepending the directory path // of the base location unless the relative part is seen to be // absolute. std::string nonCanonicalName; // the classes of strings which are absolute in their // own right are // 1) those which start with / or \ indicating the root directory // on the current drive; and // 2) those which start with X: or X: indicating the root directory // on the specified drive if( (relName[0]=='\\') || (relName[0] == '/') || (relName[1]==':') ) { nonCanonicalName=relName; } else { std::string::size_type endOfPath=baseDir.find_last_of("\\/"); if(endOfPath!=std::string::npos) { nonCanonicalName=baseDir.substr(0,endOfPath+1)+relName; } else { // we needed a path separator and didn't find one, // so we are basically stuffed. std::string msg; msg.append("Couldn't compose name from "); msg.append(baseDir); msg.append(" and "); msg.append(relName); AfxMessageBox(msg.c_str()); } } // Hopefully, nonCanonicalName now contains _one_ path to the // file. We use the following logic to convert this to the // preferred name. if(nonCanonicalName.size()>0) { // The logic below has in the past contained experimentation // with various ways of accessing a canonical name for the // file. // There are still two different APIs covered, anyone who knows // of a reason why one is better than another or why anything else // would be better (remember I want to support Win95/98/NT4/2000 // in a single set of source), please mail me. CFileStatus fileStatus; CFile::GetStatus(nonCanonicalName.c_str(), fileStatus); char getFullPathNameBuf[1024],*shortNamePtr; unsigned long len=1024; memset(getFullPathNameBuf,0,len); int gcode=GetFullPathName(const_cast(nonCanonicalName.c_str()), len,getFullPathNameBuf,&shortNamePtr); char msgbuf[1024]; sprintf(msgbuf,"fs=%s, " "GetFull returned %d name 3=%s short=%s", fileStatus.m_szFullName,gcode,getFullPathNameBuf,shortNamePtr ); // AfxMessageBox(msgbuf); dump(msgbuf); retval = fileStatus.m_szFullName; } return retval; } void DevStudioFileStore::collectFilenames(const std::string& dsFile, const std::string& pfx, FilenameList& fileList) { std::ifstream prjStr(dsFile.c_str()); const int pfxWidth=pfx.size(); while(prjStr.good()) { char linebuf[1024]; prjStr.getline(linebuf,1023); if(!prjStr.good()) { // the stream has gone bad (hopefully due to simple exhaustion) // no action here and the loop should terminate } else if(strncmp(linebuf,pfx.c_str(),pfxWidth)==0) { std::string relname=linebuf+pfxWidth; std::string absName=composeFilename(dsFile,relname); fileList.insert(absName); } } } void DevStudioFileStore::dumpProjectFileList() { ProjectFileStore::const_iterator pfsIter; for(pfsIter=m_ProjectFileStore.begin(); pfsIter!=m_ProjectFileStore.end(); ++pfsIter) { dump(pfsIter->first); dump(": "); FilenameList::const_iterator flIter; for(flIter=pfsIter->second.begin(); flIter!=pfsIter->second.end(); ++flIter) { dump(flIter->c_str()); } dump(""); } } void DevStudioFileStore::dump(const std::string& str) { VERIFY_OK(m_pApplication->PrintToOutputWindow(CComBSTR(str.c_str()))); } std::string DevStudioFileStore::suggestedWorkingDirectory() { // It would be nice to be able to make the working directory take on a constant // relationship to the .dsw file of the workspace, but there is no programmatic // way of accessing this item. // If we just use the current working directory of the // project, we seem to start off in the .dsw file directory, // until a file is opened, at which point the current working // directory reflects the directory in which the file open // dialog most recently displayed. This is not very satisfactory, // so for the moment we just try to use a constant directory, // defined either by the environment variable CCCCTEMP, with fallbacks // to TEMP and to the hardcoded directory c:\ (the main virtue of the latter // being that we are reasonably confident it will exist). std::string retval; char * envdir = getenv("CCCCTEMP"); if(envdir!=0) { retval=envdir; } else { envdir=getenv("TEMP"); if(envdir!=0) { retval=envdir; } else { retval="c:\\"; } } return retval; } cccc-3.1.4/vcaddin/DevStudioFileStore.h0000644000000000000000000000520707265351207016427 0ustar rootroot// DevStudioFileStore.h: interface for the DevStudioFileStore class. // // This file defines a class DevStudioFileStore which exists to encapsulate // the operations required to parse the .dsp and .dsw files used by // MS Developer studio and get the names of the files in any or all of the // projects in the workspace. #if !defined(AFX_DEVSTUDIOFILESTORE_H__76B7B6C2_AA85_11D3_AFED_444553540000__INCLUDED_) #define AFX_DEVSTUDIOFILESTORE_H__76B7B6C2_AA85_11D3_AFED_444553540000__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include #include #include // The answers to queries on the class below will be // a collection of names. // For the moment, I can't see why we would not want to have // an automatically sorted list with duplicates eliminated. typedef std::set FilenameList; class DevStudioFileStore { public: DevStudioFileStore(IApplication *pApp, const std::string& wsDir, const std::string& wsName); virtual ~DevStudioFileStore(); void listWorkspaceFiles(FilenameList& fileList); void listProjectFiles(std::string projectName, FilenameList& fileList); // A diagnostic function to list the files in each project void dumpProjectFileList(); // a function to propose a working directory for the run. // If the IApplication object allowed access to the // path to the .dsw file, this would be an excellent // choice, but as it is there is no way of getting this, // so we propose either the directory containing the active // project (if one exists), or the directory containing // the active document (if one exists), or the current directory. std::string suggestedWorkingDirectory(); private: IApplication* m_pApplication; std::string m_WorkspaceName; std::string m_WorkspaceDirectory; typedef std::map ProjectFileStore; ProjectFileStore m_ProjectFileStore; // A utility function to accept a base directory and a relative file name, // and translate to the canonical name of the file they specify. std::string composeFilename(const std::string& baseDir, const std::string& relname); // A utility function to open a .dsp or .dsw file, search for lines with a // given prefix, and translate the remainder of those lines to filenames // using the location of the opened file as the base directory. void collectFilenames(const std::string& dsFile, const std::string& pfx, FilenameList& fileList); // A utility function to copy a std::string (or by implicit conversion // a const char*) to the Macro output tab. void dump(const std::string& str); }; #endif // !defined(AFX_DEVSTUDIOFILESTORE_H__76B7B6C2_AA85_11D3_AFED_444553540000__INCLUDED_) cccc-3.1.4/vcaddin/FileList.cpp0000644000000000000000000000765007265351212014752 0ustar rootroot#include "stdafx.h" #include "FileList.h" FileList::FileList() : m_fileList(100) { } FileList::~FileList() { } File& FileList::Add(const File& file) { POSITION pos = m_fileList.AddTail((File&)file); return m_fileList.GetAt(pos); } void FileList::RemoveAll() { m_fileList.RemoveAll(); m_fileArray.RemoveAll(); } void FileList::BuildArray() { // Build the file array. m_fileArray.RemoveAll(); m_fileArray.SetSize(m_fileList.GetCount()); int arrayPos = 0; POSITION listPos = m_fileList.GetHeadPosition(); while (listPos != NULL) { Info info; info.m_pos = listPos; info.m_file = &m_fileList.GetNext(listPos); m_fileArray[arrayPos++] = info; } } static int __cdecl CompareArray(const void* elem1, const void* elem2) { FileList::Info* info1 = (FileList::Info*)elem1; FileList::Info* info2 = (FileList::Info*)elem2; File* file1 = info1->m_file; File* file2 = info2->m_file; int ret = file1->GetShortName().Compare(file2->GetShortName()); if (ret == 0) { // If the names match, compare against the file extensions. ret = file1->GetExt().Compare(file2->GetExt()); if (ret == 0) { // If the extensions match, compare against the path. ret = file1->GetPath().CompareNoCase(file2->GetPath()); if (ret == 0) { file1->SetDuplicate(true); file2->SetDuplicate(true); } } } return ret; } void FileList::Sort() { // Build the file array. BuildArray(); // Sort the file array. qsort(m_fileArray.GetData(), m_fileArray.GetSize(), sizeof(Info), CompareArray); // Remove duplicates. for (int curPos = 0; curPos < m_fileArray.GetSize(); curPos++) { File& file = *m_fileArray[curPos].m_file; // Check for duplicates. if (!file.m_duplicate) continue; // Found a duplicate... see how many more match. for (int endPos = curPos + 1; endPos < m_fileArray.GetSize(); endPos++) { File& fileCmp = *m_fileArray[endPos].m_file; int ret = file.GetShortName().Compare(fileCmp.GetShortName()); if (ret) break; // If the names match, compare against the file extensions. ret = file.GetExt().Compare(fileCmp.GetExt()); if (ret) break; // If the extensions match, compare against the path. ret = file.GetPath().CompareNoCase(fileCmp.GetPath()); if (ret) break; } // [endPos] is now the last one that matched. if (endPos - curPos < 2) { // Huh? continue; } // Remove them. for (int i = curPos + 1; i < endPos; i++) { m_fileList.RemoveAt(m_fileArray[i].m_pos); } m_fileArray.RemoveAt(curPos + 1, endPos - curPos - 1); } } // Find exact file index. int FileList::FindExact(File& file) const { // Scan the file list. for (int i = 0; i < GetCount(); i++) { File& fileCmp = (*this)[i]; // Compare the extension. if (!file.GetExt().IsEmpty() && file.GetExt() != fileCmp.GetExt()) continue; // Compare the short name. if (file.GetShortName() != fileCmp.GetShortName()) continue; // Compare the path. if (file.GetPath().CompareNoCase(fileCmp.GetPath()) == 0) { return i; } } return -1; } // Find next file index. int FileList::FindNext(int startPos, File& file) const { // Scan the file list. for (int i = startPos + 1; i < GetCount(); i++) { File& fileCmp = (*this)[i]; // Compare the short name. if (file.GetShortName() == fileCmp.GetShortName()) return i; } for (i = 0; i < startPos; i++) { File& fileCmp = (*this)[i]; // Compare the short name. if (file.GetShortName() == fileCmp.GetShortName()) return i; } return -1; } // Find next file index. int FileList::FindPrevious(int startPos, File& file) const { // Scan the file list. for (int i = startPos - 1; i >= 0; i--) { File& fileCmp = (*this)[i]; // Compare the short name. if (file.GetShortName() == fileCmp.GetShortName()) return i; } for (i = GetCount() - 1; i > startPos; i--) { File& fileCmp = (*this)[i]; // Compare the short name. if (file.GetShortName() == fileCmp.GetShortName()) return i; } return -1; } cccc-3.1.4/vcaddin/FileList.h0000644000000000000000000000436407265351212014416 0ustar rootroot#ifndef FILELIST_H #define FILELIST_H #include /// class File { friend class FileList; public: File(); static bool Create(File& file, const CString& rootPath, CString filename, bool resolve = true); void* GetParent(void) const; const CString& GetShortName(void) const; const CString& GetTitle(void) const; const CString& GetExt(void) const; const CString& GetPath(void) const; void SetParent(void* parent); void SetShortName(const CString& shortName); void SetTitle(const CString& title); void SetExt(const CString& ext); void SetPath(const CString& path); void SetDuplicate(bool duplicate); protected: void* m_parent; CString m_shortName; CString m_title; CString m_ext; CString m_path; bool m_duplicate; }; //File class FileList { public: FileList(); ~FileList(); // Attributes int GetCount(void) const; // Operations File& Add(const File& file); void RemoveAll(void); void Sort(void); File& operator[](int index) const; int FindExact(File& file) const; int FindNext(int startPos, File& file) const; int FindPrevious(int startPos, File& file) const; struct Info { POSITION m_pos; File* m_file; }; protected: void BuildArray(void); CList m_fileList; CArray m_fileArray; }; inline File::File() : m_duplicate(false) { } inline void* File::GetParent(void) const { return m_parent; } inline const CString& File::GetShortName(void) const { return m_shortName; } inline const CString& File::GetTitle(void) const { return m_title; } inline const CString& File::GetExt(void) const { return m_ext; } inline const CString& File::GetPath(void) const { return m_path; } inline void File::SetParent(void* parent) { m_parent = parent; } inline void File::SetShortName(const CString& shortName) { m_shortName = shortName; } inline void File::SetTitle(const CString& title) { m_title = title; } inline void File::SetExt(const CString& ext) { m_ext = ext; } inline void File::SetPath(const CString& path) { m_path = path; } inline void File::SetDuplicate(bool duplicate) { m_duplicate = duplicate; } inline int FileList::GetCount(void) const { return m_fileList.GetCount(); } inline File& FileList::operator[](int index) const { return *m_fileArray[index].m_file; } #endif FILELIST_Hcccc-3.1.4/vcaddin/ReadMe.txt0000644000000000000000000000725407265351212014431 0ustar rootroot======================================================================== DEVELOPER STUDIO ADD-IN : CcccDevStudioAddIn ======================================================================== The Add-in Wizard has created this CcccDevStudioAddIn DLL for you. This DLL not only demonstrates the basics of creating a Developer Studio add-in, but it is also a starting point for writing your own add-in. An add-in mainly does two things. (1) It adds commands to Developer Studio, which can then be tied to keystrokes or toolbar buttons by the user or programmatically by the add-in. (2) It responds to events fired by Developer Studio. In both cases, the add-in code has access to the full Developer Studio Automation Object Model, and may manipulate those objects to affect the behavior of Developer Studio. This file contains a summary of what you will find in each of the files that make up your CcccDevStudioAddIn DLL. CcccDevStudioAddIn.h This is the main header file for the DLL. It declares the CCcccDevStudioAddInApp class. CcccDevStudioAddIn.cpp This is the main DLL source file. It contains the class CCcccDevStudioAddInApp. It also contains the OLE entry points required of inproc servers. CcccDevStudioAddIn.odl This file contains the Object Description Language source code for the type library of your DLL. CcccDevStudioAddIn.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the sample toolbar bitmap that is stored in the RES subdirectory. This file can be directly edited in Microsoft Developer Studio. res\CcccDevStudioAddIn.rc2 This file contains resources that are not edited by Microsoft Developer Studio. You should place all resources not editable by the resource editor in this file. CcccDevStudioAddIn.def This file contains information about the DLL that must be provided to run with Microsoft Windows. It defines parameters such as the name and description of the DLL. It also exports functions from the DLL. CcccDevStudioAddIn.clw This file contains information used by ClassWizard to edit existing classes or add new classes. ClassWizard also uses this file to store information needed to create and edit message maps and dialog data maps and to create prototype member functions. ///////////////////////////////////////////////////////////////////////////// Add-in-specific files: DSAddIn.cpp, DSAddIn.h These files contain the CDSAddIn class, which implements the IDSAddIn interface. This interface contains handlers for connecting and disconnecting the add-in. Commands.cpp, Commands.h These files contain the CCommands class, which implements your command dispatch interface. This interface contains one method for each command you add to Developer Studio. It already implements a sample command (CcccDevStudioAddInCommand) which displays a message box when it is invoked. You will probably want to rename and modify this command, as well as add your own commands. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named CcccDevStudioAddIn.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Developer Studio reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. ///////////////////////////////////////////////////////////////////////////// cccc-3.1.4/vcaddin/StdAfx.cpp0000644000000000000000000000035107265351212014417 0ustar rootroot// stdafx.cpp : source file that includes just the standard includes // CcccDevStudioAddIn.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" #include "atlimpl.cpp" cccc-3.1.4/vcaddin/StdAfx.h0000644000000000000000000000447007265351215014075 0ustar rootroot// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__2AB447B6_A834_11D3_AFED_444553540000__INCLUDED_) #define AFX_STDAFX_H__2AB447B6_A834_11D3_AFED_444553540000__INCLUDED_ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #include // MFC core and standard components #include #include //You may derive a class from CComModule and use it if you want to override //something, but do not change the name of _Module extern CComModule _Module; #include // Developer Studio Object Model #include #include #include #include #include #include #include #include #include ///////////////////////////////////////////////////////////////////////////// // Debugging support // Use VERIFY_OK around all calls to the Developer Studio objects which // you expect to return S_OK. // In DEBUG builds of your add-in, VERIFY_OK displays an ASSERT dialog box // if the expression returns an HRESULT other than S_OK. If the HRESULT // is a success code, the ASSERT box will display that HRESULT. If it // is a failure code, the ASSERT box will display that HRESULT plus the // error description string provided by the object which raised the error. // In RETAIL builds of your add-in, VERIFY_OK just evaluates the expression // and ignores the returned HRESULT. #ifdef _DEBUG void GetLastErrorDescription(CComBSTR& bstr); // Defined in CcccDevStudioAddIn.cpp #define VERIFY_OK(f) \ { \ HRESULT hr = (f); \ if (hr != S_OK) \ { \ if (FAILED(hr)) \ { \ CComBSTR bstr; \ GetLastErrorDescription(bstr); \ _RPTF2(_CRT_ASSERT, "Object call returned %lx\n\n%S", hr, (BSTR) bstr); \ } \ else \ _RPTF1(_CRT_ASSERT, "Object call returned %lx", hr); \ } \ } #else //_DEBUG #define VERIFY_OK(f) (f); #endif //_DEBUG //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__2AB447B6_A834_11D3_AFED_444553540000__INCLUDED) cccc-3.1.4/vcaddin/WorkspaceInfo.cpp0000644000000000000000000003241207265351220016002 0ustar rootroot#include "stdafx.h" //#include #include "CcccDevStudioAddIn.h" #include "DSAddIn.h" #include "Commands.h" #include "afx.h" #include "WorkspaceInfo.h" IApplication* WorkspaceInfo::m_pApplication; CString WorkspaceInfo::m_workspaceLocation; CString WorkspaceInfo::m_extraFilename; CString WorkspaceInfo::m_excludeFilename; WorkspaceInfo::ProjectList WorkspaceInfo::m_projects; FileList WorkspaceInfo::m_fileList; // Resolves the filename when it contains environment variables and relative paths. void ResolveFilename(const CString& rootDir, CString& filename) { /* // Initially resolve all environment variables. int position = -1; while (1) { // Search for $ symbols, denoting an environment variable. position = filename.Find('$', position + 1); if (position == -1) break; // Okay, there is an environment variable in there... resolve it. if (filename[position + 1] == '(') { int lastpos = filename.Find(')'); CString env = filename.Mid(position + 2, lastpos - (position + 2)); // See if we can resolve it. If not, then exit. char buffer[_MAX_PATH]; if (GetEnvironmentVariable(env, buffer, _MAX_PATH) == 0) continue; // Okay, rebuild the string. filename = filename.Left(position) + buffer + filename.Right(filename.GetLength() - lastpos - 1); } } // Now resolve relative paths. CFileStatus fileStatus; if (filename[0] == '.') filename = rootDir + filename; CFile::GetStatus(filename, fileStatus); filename = fileStatus.m_szFullName; */ } // bool File::Create(File& file, const CString& rootPath, CString filename, bool resolve) { // Resolve the filename. if (resolve) ResolveFilename(rootPath, filename); // Find the path. int pathEndPosition = filename.ReverseFind('\\'); if (pathEndPosition == -1) return false; file.SetPath(filename.Left(pathEndPosition + 1)); // Find the extension. int extPosition = filename.ReverseFind('.'); if (extPosition != -1) { file.m_ext = filename.Mid(extPosition + 1); file.m_ext.MakeLower(); } else extPosition = filename.GetLength(); // Find the file title. file.m_title = filename.Mid(pathEndPosition + 1, extPosition - (pathEndPosition + 1)); // Build the shortened name (no symbols). char shortName[200]; int sLen = 0; for (int i = 0; i < file.m_title.GetLength(); i++) if (isalnum(file.m_title[i])) shortName[sLen++] = tolower(file.m_title[i]); shortName[sLen] = 0; file.m_shortName = shortName; // Set the parent. file.m_parent = NULL; return true; } // This is a cheap way to get the workspace location, but it is the only way // which consistently worked. DevStudio, failing once again, provides no function to // return the location of the workspace. void WorkspaceInfo::SetWorkspaceLocation(void) { // Call the OS for the current directory. LPTSTR str = m_workspaceLocation.GetBuffer(_MAX_PATH); ::GetCurrentDirectory(_MAX_PATH, str); m_workspaceLocation.ReleaseBuffer(); // Make sure it ends in a closing backslash. if (m_workspaceLocation[m_workspaceLocation.GetLength() - 1] != '\\') { m_workspaceLocation += "\\"; } m_extraFilename = m_workspaceLocation + "ExtraFiles.WU"; m_excludeFilename = m_workspaceLocation + "ExcludeFiles.WU"; } // See if the .dsp or .dsw file changed on disk. bool WorkspaceInfo::CheckProjectIntegrity(CString projectName) { // Resolve the filename. ResolveFilename(GetWorkspaceLocation(), projectName); // Scan the projects list to find the project named [projectName]. POSITION pos = m_projects.GetHeadPosition(); Project* prj = NULL; while (pos != NULL) { prj = &m_projects.GetNext(pos); if (prj->m_name.CompareNoCase(projectName) == 0) break; prj = NULL; } // If it doesn't exist, exit. if (!prj) { // AfxMessageBox("Refresh: Project names differ."); return false; } // Check the date and time stamp. CFileStatus fileStatus; if (CFile::GetStatus(prj->m_name, fileStatus) == FALSE) return false; if (prj->m_timeStamp != fileStatus.m_mtime) { // AfxMessageBox("Refresh: Date/time stamp differs."); return false; } return true; } // CheckIntegrity() returns false if the internally stored projects // don't match the Visual Studio projects. bool WorkspaceInfo::CheckIntegrity(void) { // If there are no projects to compare against, then fail the integrity check. if (m_projects.GetCount() == 0) { // AfxMessageBox("Refresh: No projects."); return false; } // Is there an add-on file? int numAddOnProjects = 0; CStdioFile file; if (file.Open(GetExtraFilename(), CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Check the integrity. if (!CheckProjectIntegrity(line)) return false; // Increment the number of add-on projects. numAddOnProjects++; } // Close the file. file.Close(); } // Now run all projects with workspace parents (which means they were added // indirectly through a .dsw file). POSITION pos = m_projects.GetHeadPosition(); while (pos != NULL) { // Get the project. Project& prj = m_projects.GetNext(pos); // Does it have a parent? if (prj.m_parent) { // Yes, so it is a project added indirectly from a .dsw file. if (!CheckProjectIntegrity(prj.GetName())) return false; // Add it to the number of add-on projects. numAddOnProjects++; } } // First, get a pointer to the dispatch for the Projects collection CComPtr pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr pProjects(pDispProjects); // Get the number of projects in the collection long workspaceProjectCount; VERIFY_OK(pProjects->get_Count(&workspaceProjectCount)); // If the number of projects reported by Visual Studio is not the same // number as our local project list, then refresh everything. if (workspaceProjectCount + numAddOnProjects != m_projects.GetCount()) { // AfxMessageBox("Refresh: Project counts differ."); return false; } // Check for non-matching project names. for (long i = 1; i < workspaceProjectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr pProject(pGenProject); CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; // Check the project integrity. if (!CheckProjectIntegrity(projectName)) return false; } // end for [1..workspaceProjectCount] return true; } // Clean the projects and filenames lists. void WorkspaceInfo::RemoveAll(void) { // Clean the projects list. m_projects.RemoveAll(); // Clean the filenames list. m_fileList.RemoveAll(); } // Since Visual Studio provides no COM method of returning the names of // files in a project, we have to cheat, and read them from the .DSP // files on disk. This has at least one primary disadvantage. If a // change is made to the project in the Developer Studio, the project // MUST be saved before we can process the change here. void WorkspaceInfo::ReadDSPFile(Project& prj) { // Open the .dsp file. CStdioFile file; if (file.Open(prj.GetName(), CFile::modeRead) == FALSE) { // Huh? return; } // Build the root path to resolve filenames from. CString rootPath = prj.m_name.Left(prj.m_name.ReverseFind('\\') + 1); // Begin reading the file. CString line; while (1) { // Read in a line from the file. if (!file.ReadString(line)) break; // Check for SOURCE= lines. (Do strncmp() for speed) if (line.GetLength() <= 7 || strncmp(line, "SOURCE=", 7) != 0) continue; /////////////////////////////////////////////////////////////////////// // Start the pointer just after the SOURCE=, but strip the beginning // and end quotes if they exist. int startPos; if (line[7] == '"') startPos = 8; else startPos = 7; int endPos; if (line[line.GetLength() - 1] == '"') endPos = line.GetLength() - 1; else endPos = line.GetLength(); // Create and resolve the filename. CString filename = line.Mid(startPos, endPos - startPos); // Create the file structure. File file; if (File::Create(file, rootPath, filename) == false) continue; // Set the parent. file.SetParent(&prj); // Insert it. m_fileList.Add(file); } //while(1) // Close the .dsp file. file.Close(); } // Read in a .dsw file. void WorkspaceInfo::ReadDSWFile(Project& prj) { // Open the .dsw file. CStdioFile file; if (file.Open(prj.m_name, CFile::modeRead) == FALSE) { // Huh? return; } // Build the root path to resolve filenames from. CString rootPath = prj.m_name.Left(prj.m_name.ReverseFind('\\') + 1); // Begin reading the file. CString line; while (1) { // Read in a line from the file. if (!file.ReadString(line)) break; // Look for something that looks like this. // Project: "!EagleLib"=".\Prj\!EagleLib.dsp" - Package Owner=<4> // Project: "Gfx"=.\Prj\Gfx.dsp - Package Owner=<4> if (line.GetLength() <= 8 || strncmp(line, "Project:", 8) != 0) continue; // Search for the =. int endPos; // Will be one past the last letter. int startPos = line.Find('='); if (startPos == -1) continue; startPos++; // Move to the beginning of the name. /* // See if the name is quoted. if (line[startPos] == '"') { // Move past the quote. startPos++; // Find the closing quote. endPos = line.Find('"', startPos); if (endPos == -1) continue; } else //if (line[namePos] == '"') { // Find a space, since that should denote the end of the filename. endPos = line.Find(' ', startPos); } */ // Got the name isolated. Add it. CString projectPath = line.Mid(startPos, endPos - startPos); ResolveFilename(rootPath, projectPath); Project* newlyAddedProject = AddHelper(projectPath); if (newlyAddedProject) newlyAddedProject->m_parent = &prj; } //while(1) // Close the .dsp file. file.Close(); } // Add a new project or workspace to the list of projects. void WorkspaceInfo::Add(CString projectName) { AddHelper(projectName); } // Internal helper function. WorkspaceInfo::Project* WorkspaceInfo::AddHelper(CString projectName) { // Resolve the filename. ResolveFilename(GetWorkspaceLocation(), projectName); // Make sure there is an extension. int dotPosition = projectName.ReverseFind('.'); if (dotPosition == -1) { // What?! return NULL; } // Make sure the file exists. CFileStatus fileStatus; if (CFile::GetStatus(projectName, fileStatus) == FALSE) return NULL; // Create the project structure. Project prjToAdd; prjToAdd.m_name = projectName; prjToAdd.m_active = true; prjToAdd.m_timeStamp = fileStatus.m_mtime; prjToAdd.m_parent = NULL; // This is a little slow, but it can be moved later. CStdioFile file; if (file.Open(GetExcludeFilename(), CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Resolve the exclude filename. ResolveFilename(GetWorkspaceLocation(), line); // If it matches, then the project is inactive. if (prjToAdd.m_name.CompareNoCase(line) == 0) { prjToAdd.m_active = false; break; } } // Close the file. file.Close(); } // Add it to the end of the projects list. POSITION pos = m_projects.AddTail(prjToAdd); Project& prj = WorkspaceInfo::m_projects.GetAt(pos); // If the project is inactive, leave. if (!prj.IsActive()) { return &prj; } // Determine which type of file this is: CString ext = prj.m_name.Mid(dotPosition + 1); ext.MakeLower(); if (ext == "dsw") { // This is a workspace file. ReadDSWFile(prj); } else if (ext == "dsp") { // Assume it is a project file. ReadDSPFile(prj); } else { // Fail } return &prj; } // Refresh the projects list. bool WorkspaceInfo::Refresh(void) { // If the internal project integrity is good, then no refresh is needed. if (CheckIntegrity()) return true; // Delete everything. RemoveAll(); // First, get a pointer to the dispatch for the Projects collection CComPtr pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr pProjects(pDispProjects); // Get the number of projects in the collection long projectCount; VERIFY_OK(pProjects->get_Count(&projectCount)); // Iterate all the projects. for (long i = 1; i < projectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr pProject(pGenProject); // Get the project name. CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; Add(projectName); } // Rename a misnamed add-on file. CString oldFilename = m_workspaceLocation + "ExtraFiles.PFO"; CString wuFilename = GetExtraFilename(); rename(oldFilename, wuFilename); // Is there an add-on file? CStdioFile file; if (file.Open(wuFilename, CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Check the integrity. Add(line); } // Close the file. file.Close(); } // Build the file array. m_fileList.Sort(); // Rebuilt stuff. return false; } cccc-3.1.4/vcaddin/WorkspaceInfo.h0000644000000000000000000000477007265351223015460 0ustar rootroot#ifndef WORKSPACEINFO_H #define WORKSPACEINFO_H #include "resource.h" // main symbols #include #include #include #include #include #include "FileList.h" /// class WorkspaceInfo { public: /// class Project { friend class WorkspaceInfo; public: const CString& GetName(void) const; bool IsActive(void) const; const CTime& GetTimeStamp(void) const; void SetActive(bool active); protected: CString m_name; // The name of the project or workspace. bool m_active; // Is the project active? CTime m_timeStamp; // The time stamp of the project. Project* m_parent; // Parent project. }; //Project typedef CList ProjectList; public: // Attributes static ProjectList& GetProjectList(void); // Not const on purpose. static FileList& GetFileList(void); // Not const on purpose. static const CString& GetWorkspaceLocation(void); static const CString& GetExtraFilename(void); static const CString& GetExcludeFilename(void); // Operations static void SetWorkspaceLocation(void); // Do once on Workspace Open. static bool CheckIntegrity(void); static bool Refresh(void); static void Add(CString projectName); static void RemoveAll(void); static IApplication *m_pApplication; protected: static bool CheckProjectIntegrity(CString projectName); static void ReadDSPFile(Project& prj); static void ReadDSWFile(Project& prj); static Project* AddHelper(CString projectName); static CString m_workspaceLocation; static CString m_extraFilename; static CString m_excludeFilename; static ProjectList m_projects; static FileList m_fileList; }; //WorkspaceInfo inline const CString& WorkspaceInfo::Project::GetName(void) const { return m_name; } inline bool WorkspaceInfo::Project::IsActive(void) const { return m_active; } inline const CTime& WorkspaceInfo::Project::GetTimeStamp(void) const { return m_timeStamp; } inline void WorkspaceInfo::Project::SetActive(bool active) { m_active = active; } inline WorkspaceInfo::ProjectList& WorkspaceInfo::GetProjectList(void) { return m_projects; } inline FileList& WorkspaceInfo::GetFileList(void) { return m_fileList; } inline const CString& WorkspaceInfo::GetWorkspaceLocation(void) { return m_workspaceLocation; } inline const CString& WorkspaceInfo::GetExtraFilename(void) { return m_extraFilename; } inline const CString& WorkspaceInfo::GetExcludeFilename(void) { return m_excludeFilename; } #endif WORKSPACEINFO_H cccc-3.1.4/vcaddin/resource.h0000644000000000000000000000206107265351223014524 0ustar rootroot//{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by CcccDevStudioAddIn.rc // #define IDS_CCCCDEVSTUDIOADDIN_LONGNAME 1 #define IDS_CCCCDEVSTUDIOADDIN_DESCRIPTION 2 #define IDS_CMD_STRING 3 #define IDR_TOOLBAR_MEDIUM 128 #define IDR_TOOLBAR_LARGE 129 #define IDD_DIALOG1 132 #define IDC_EDIT1 1000 #define IDC_EDIT2 1001 #define IDC_EDIT3 1002 #define IDC_EDIT4 1003 #define IDC_EDIT5 1004 #define IDC_EDIT6 1005 #define IDC_EDIT7 1006 #define IDC_EDIT8 1007 #define IDC_BUTTON1 1008 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 133 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1010 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif cccc-3.1.4/w32installer/0000755000000000000000000000000010357462460013450 5ustar rootrootcccc-3.1.4/w32installer/cccc.iss.nover0000644000000000000000000000755710357334136016227 0ustar rootroot; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! [Setup] AppName=C and C++ Code Counter AppVerName=CCCC CCCC_VERSION for Win32 AppPublisher=Tim Littlefair AppPublisherURL=http: AppSupportURL=mailto:cccc-users@lists.sourceforge.net AppUpdatesURL=http: DefaultDirName={pf}\CCCC DefaultGroupName=C and C++ Code Counter OutputBaseFilename=CCCC_SETUP Uninstallable=yes ; uncomment the following line if you want your installation to run on NT 3.51 too. ; MinVersion=4,3.51 [Tasks] Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; MinVersion: 4,4 Name: "quicklaunchicon"; Description: "Create a &Quick Launch icon"; GroupDescription: "Additional icons:"; MinVersion: 4,4; Flags: unchecked [Files] Source: "..\w32installer\ccccwrap.bat"; DestDir: "{app}" Source: "..\w32installer\ccccwrap_build.bat"; DestDir: "{app}" Source: "..\w32installer\make_cccc_env.bat"; DestDir: "{app}" Source: "..\cccc\cccc.exe"; DestDir: "{app}" Source: "..\cccc\CCCC User Guide.html"; DestDir: "{app}" ; Source code Source: "..\pccts\*.h"; DestDir: "{app}\src\pccts"; Flags: "recursesubdirs" Source: "..\pccts\*.c"; DestDir: "{app}\src\pccts"; Flags: "recursesubdirs" Source: "..\pccts\*.cpp"; DestDir: "{app}\src\pccts"; Flags: "recursesubdirs" Source: "..\pccts\*.g"; DestDir: "{app}\src\pccts"; Flags: "recursesubdirs" Source: "..\cccc\*.g"; DestDir: "{app}\src\cccc" Source: "..\cccc\*.h"; DestDir: "{app}\src\cccc" Source: "..\cccc\*.cc"; DestDir: "{app}\src\cccc" Source: "..\cccc\*.mak"; DestDir: "{app}\src\cccc" Source: "..\cccc\*.html"; DestDir: "{app}\src\cccc" Source: "..\cccc\COPYING"; DestDir: "{app}\src\cccc" Source: "..\test\*.mak"; DestDir: "{app}\src\test" Source: "..\test\*.cc"; DestDir: "{app}\src\test" Source: "..\test\*.java"; DestDir: "{app}\src\test" Source: "..\test\*.opt"; DestDir: "{app}\src\test" Source: "..\test\*.htmlref"; DestDir: "{app}\src\test" Source: "..\test\*.xmlref"; DestDir: "{app}\src\test" Source: "..\test\*.dbref"; DestDir: "{app}\src\test" Source: "..\test\*.mak"; DestDir: "{app}\src\test" Source: "..\w32installer\*.bat"; DestDir: "{app}\src\w32installer" Source: "..\w32installer\*.nover"; DestDir: "{app}\src\w32installer" Source: "..\*.txt"; DestDir: "{app}\src" ; Sadly, the DevStudio add-in can't be built under the free compiler ;Source: "..\vcaddin\release\CcccDevStudioAddIn.dll"; DestDir: "{app}" Source: "..\readme.txt"; DestDir: "{app}" Source: "..\changes.txt"; DestDir: "{app}" Source: "..\cccc\COPYING"; DestDir: "{app}" Source: "..\build_w32vc.bat"; DestDir: "{app}\src" Source: "..\build_w32vct2003.bat"; DestDir: "{app}\src" Source: "..\ccccdist.dsw"; DestDir: "{app}\src" [Icons] Name: "{group}\CCCC Command Line"; Filename: "{app}\ccccwrap.bat"; IconIndex: 2; WorkingDir: "{app}" Name: "{group}\CCCC User Guide"; Filename: "{app}\CCCC User Guide.html" Name: "{group}\readme.txt"; Filename: "{app}\readme.txt" Name: "{group}\changes.txt"; Filename: "{app}\changes.txt" Name: "{group}\COPYING"; Filename: "{app}\COPYING" Name: "{group}\Build from source code\Build using MS Visual C++ Toolkit 2003"; Filename: "{app}\ccccwrap_build.bat"; IconIndex: 2; WorkingDir: "{app}"; Flags: dontcloseonexit Name: "{userdesktop}\CCCC"; Filename: "{app}\ccccwrap.bat"; MinVersion: 4,4; Tasks: desktopicon ; WorkingDir: "{app}" Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\CCCC"; Filename: "{app}\ccccwrap.bat"; IconIndex: 2; MinVersion: 4,4; Tasks: quicklaunchicon ; WorkingDir: "{app}" [Run] Filename: "{app}\make_cccc_env.bat"; Parameters: """{app}"" ""C:\"""; StatusMsg: "Creating environment script"; Flags: shellexec Filename: "{app}\ccccwrap.bat"; Description: "Launch CCCC Command Line"; Flags: shellexec postinstall skipifsilent Filename: "{app}\ccccwrap_build.bat"; Description: "Launch CCCC Build Environment"; Flags: shellexec postinstall skipifsilent cccc-3.1.4/w32installer/ccccwrap.bat0000755000000000000000000000250307716073737015742 0ustar rootroot@rem ccccwrap.bat @rem Wrapper script to provide a command line environment with CCCC in the path. @echo off rem Give the command prompt a distinctive colour scheme so that rem the user can tell it from other command prompt windows. color 2e set CCCC_ENV=cccc_env.bat set CCCC_EXE=cccc.exe if not exist %CCCC_ENV% goto noEnv call %CCCC_ENV% if not exist %CCCC_PATH_DIR%\%CCCC_EXE% goto noExe if not exist %CCCC_WORK_DIR% goto noWorkDir path %CCCC_PATH_DIR%;%path% cd %CCCC_WORK_DIR% rem Request the usage message. %CCCC_PATH_DIR%\cccc.exe --help rem Start the shell %COMSPEC% goto end :noEnv echo The file %CCCC_ENV% was not found. echo This file is required to define the command line environment for CCCC. echo Please uninstall and reinstall CCCC to get a working command line environment. pause goto end :noExe echo The executable %CCCC_EXE% was not found in %CCCC_PATH_DIR%. echo Please uninstall and reinstall CCCC to get a working command line environment. pause goto end :noWorkDir echo The shell variable CCCC_WORK_DIR is defined as %CCCC_WORK_DIR% but this echo directory does not exist. echo This variable is required to define the initial work directory echo for a session using the CCCC command line environment. echo Please uninstall and reinstall CCCC to get a working command line environment. pause goto end :end cccc-3.1.4/w32installer/ccccwrap_build.bat0000644000000000000000000000142310357334136017102 0ustar rootroot@rem ccccwrap.bat @rem Wrapper script to provide a command line environment @rem for building CCCC using the Microsoft Visual C++ Toolkit 2003. @echo off rem Give the command prompt a distinctive colour scheme so that rem the user can tell it from other command prompt windows. color 2f set CCCC_SRC_DIR=src set MSVCT2003_DIR="c:\Program Files\Microsoft Visual C++ Toolkit 2003" if not exist %CCCC_SRC_DIR% ( echo "Source code directory not present" pause exit ) if not exist %MSVCT2003_DIR% ( echo Microsoft Visual C++ Toolkit 2003 not present echo Please install or adapt build files to use a different compiler. pause ) else ( echo Start the build using the script 'build_w32vct2003.bat' ) cd %CCCC_SRC_DIR% rem Start the shell %COMSPEC% goto end :end cccc-3.1.4/w32installer/make_cccc_env.bat0000755000000000000000000000112207715623155016703 0ustar rootroot@rem make_cccc_env.bat @rem This script runs at CCCC install time to generate a @rem batch file to set up environment variables for the @rem command line interface for CCCC. @echo off set SCRIPT=cccc_env.bat echo @rem cccc_env.bat> %SCRIPT% echo @rem CCCC_PATH_DIR defines the installation directory where the>> %SCRIPT% echo @rem cccc executable is found.>> %SCRIPT% echo set CCCC_PATH_DIR=%1>> %SCRIPT% echo @rem >> %SCRIPT% echo @rem CCCC_WORK_DIR defines the initial working directory for the>> %SCRIPT% echo @rem command line session>> %SCRIPT% echo set CCCC_WORK_DIR=%2>> %SCRIPT%