comp.lang.ada
 help / color / mirror / Atom feed
From: emery@goldfinger.mitre.org (David Emery)
Subject: Ada formatter for MS-Word
Date: 2 Dec 94 14:55:07
Date: 1994-12-02T14:55:07+00:00	[thread overview]
Message-ID: <EMERY.94Dec2145507@goldfinger.mitre.org> (raw)
In-Reply-To: l107353@cliffy.lfwc.lockheed.com's message of 2 Dec 1994 14:03:18 GMT

Here are two files for C and Lex.  Run the second through Lex, and
then compile with the first.  Pipe Ada code into the result, and out
comes marked-up Ada in RTF format.  Then you can run this through your
favorite RTF translator (we use MS-Word), and print away...  Reserved
words are in lower-case, bold font.  Comments are in italics.  The
default font is Courier.  It's important to use a fixed-width font.
If you want to modify this, see hilite() and OTHERCMT.  

VERY IMPORTANT:  To get the newsreader to accept this, the header
string was 'broken' into multiple lines.  This should be a single
string, with no line feeds.  Make this change BEFORE compiling!

No warranty, express or implied...

				dave

p.s. The derivation history on this:  The 'root' is Herm Fisher's
Ada Lex/Yacc grammar.  Next came a tool Steve Rosen and I developed at
Siemens to do Scribe mark-up, which I subsequently adapted for RTF.  
------------------------------------------------------------------------
main()
{
char *header = "{\\rtf1\\mac\\deff2 {\\fonttbl{\\f0\\fswiss
Chicago;}{\\f3\\fswiss Geneva;}{\\f4\\fmodern Monaco;}{\\f16\\fnil
Palatino;}{\\f20\\froman Times;}{\\f21\\fswiss
Helvetica;}{\\f22\\fmodern Courier;}{\\f23\\ftech Symbol;}{\\f33\\fnil
Avant Garde;}{\\f200\\fnil MitreLogo;}\\015{\\f201\\fnil
MitreSymbol;}}{\\colortbl\\red0\\green0\\blue0;\\red0\\green0\\blue255;\\red0\\green255\\blue255;\\red0\\green255\\blue0;\\red255\\green0\\blue255;\\red255\\green0\\blue0;\\red255\\green255\\blue0;\\red255\\green255\\blue255;}{\\stylesheet{\\s224\\tx360
\\b\\v\\f20\\fs20 \\015\\sbasedon0\\snext0
PostScript;}{\\s225\\li5760\\ri720\\tldot\\tx8280\\tqr\\tx8640 \\f20
\\sbasedon0\\snext0 toc 9;}{\\s226\\tx540\\tqr\\tx9000 \\f20
\\sbasedon228\\snext0 toc 8;}{\\s227\\sa240\\tx540\\tqr\\tx9000 \\f20
\\sbasedon229\\snext0 toc 7;}{\\s228\\sl260\\tx540\\tqr\\tx9000
\\015\\f20 \\sbasedon0\\snext0 toc
6;}{\\s229\\sa240\\tx540\\tqr\\tx9000 \\f20 \\sbasedon0\\snext0 toc
5;}{\\s230\\li1800\\tx2520\\tqr\\tx8820\\tqr\\tx9000 \\f20
\\sbasedon231\\snext0 toc
4;}{\\s231\\li1080\\sl260\\tx1800\\tqr\\tx8820\\tqr\\tx9000 \\f20
\\sbasedon232\\snext0 toc
3;}{\\015\\s232\\li360\\sl260\\tx1080\\tqr\\tx8820\\tqr\\tx9000 \\f20
\\sbasedon233\\snext0 toc
2;}{\\s233\\sa240\\sl260\\tqr\\tx8820\\tqr\\tx9000 \\f20
\\sbasedon0\\snext0 toc 1;}{\\s234\\li2160\\tx360 \\f20
\\sbasedon0\\snext0 index 7;}{\\s235\\li1800\\tx360 \\f20
\\sbasedon0\\snext0 index 6;}{\\015\\s236\\li1440\\tx360 \\f20
\\sbasedon0\\snext0 index 5;}{\\s237\\li1080\\tx360 \\f20
\\sbasedon0\\snext0 index 4;}{\\s238\\li720\\tx360 \\f20
\\sbasedon0\\snext0 index 3;}{\\s239\\li360\\tx360 \\f20
\\sbasedon0\\snext0 index 2;}{\\s240\\tx360 \\f20 \\sbasedon0\\snext0
index 1;}{\\015\\s241\\tx360 \\f20 \\sbasedon0\\snext0 line
number;}{\\s242\\tx360 \\f20 \\sbasedon0\\snext0 page
number;}{\\s243\\qc\\tx360 \\f20 \\sbasedon0\\snext243
footer;}{\\s244\\tqc\\tx4320\\tqr\\tx8640 \\f20 \\sbasedon0\\snext0
header;}{\\s245\\tx360 \\f20\\fs18\\up6 \\sbasedon0\\snext0
\\015footnote reference;}{\\s246\\fi-360\\li360\\sa240\\sl260\\tx360
\\f20 \\sbasedon0\\snext246 footnote text;}{\\s247\\li720\\tx360
\\i\\f20\\fs20 \\sbasedon0\\snext0 heading 9;}{\\s248\\qc\\tx360 \\f20
\\sbasedon0\\snext0 heading 8,Two Line Table
Caption;}{\\s249\\qc\\sa480\\tx360 \\015\\f20 \\sbasedon0\\snext0
heading 7,Table Caption;}{\\s250\\qc\\sl260\\tx360 \\f20
\\sbasedon251\\snext0 heading 6,Two Line Figure
Caption;}{\\s251\\qc\\sb480\\sl260\\tx360 \\f20 \\sbasedon0\\snext0
heading 5,Figure Caption;}{\\s252\\li360\\sa240\\keepn\\tx360 \\b\\f20
\\015\\sbasedon0\\snext0 heading 4,Level 3
Heading;}{\\s253\\sa240\\keepn\\tx360 \\b\\f20 \\sbasedon0\\snext0
heading 3,Level 2 Heading;}{\\s254\\sa240\\keepn\\tx360 \\b\\caps\\f20
\\sbasedon0\\snext0 heading 2,Level 1
Heading;}{\\s255\\qc\\sa480\\keepn\\tx360 \\b\\caps\\f20
\\015\\sbasedon0\\snext0 heading 1,Section Title;}{\\tx360 \\f20
\\sbasedon222\\snext0 Normal,Font: Times 12 Point,Flush
left;}{\\s1\\sa240\\keepn\\tx360 \\b\\caps\\f20 \\sbasedon0\\snext0
Appendix Level 1 Heading;}{\\s2\\sa240\\keepn\\tx360 \\b\\f20
\\sbasedon0\\snext0 \\015Appendix Level 2
Heading;}{\\s3\\li360\\sa240\\keepn\\tx360 \\b\\f20
\\sbasedon0\\snext0 Appendix Level 3 Heading;}{\\s4\\tx360 \\f20
\\sbasedon0\\snext4 Distribution List ;}{\\s5\\sa240\\keepn\\tx360
\\b\\caps\\f20 \\sbasedon0\\snext0 Executive Summary Level 1
Heading;}{\\015\\s6\\sa240\\keepn\\tx360 \\b\\f20 \\sbasedon0\\snext0
Executive Summary Level 2 Heading;}{\\s7\\li360\\sa240\\keepn\\tx360
\\b\\f20 \\sbasedon0\\snext0 Executive Summary Level 3
Heading;}{\\s8\\sa240\\sl260\\tx360\\tqr\\tx9000 \\b\\caps\\f20
\\sbasedon0\\snext0 \\015Figure/Table/TOC
Headings;}{\\s9\\qc\\ri29\\sa480\\sl260\\tx360 \\b\\caps\\f20
\\sbasedon0\\snext0 Front Matter
Headings;}{\\s10\\fi-1080\\li1080\\tx360 \\f20 \\sbasedon0\\snext10
Glossary ;}{\\s11\\fi-360\\li360\\tx360 \\f20 \\sbasedon0\\snext11
Glossary (Long Terms);}{\\015\\s12\\fi-540\\li900\\tx360 \\f20
\\sbasedon0\\snext12 List - First Level;}{\\s13\\fi-540\\li1440\\tx360
\\f20 \\sbasedon0\\snext13 List - Second Level;}{\\s14\\tx360 \\f20
\\sbasedon0\\snext14 Name/Date Reference
;}{\\s15\\fi-360\\li360\\tx360 \\f20 \\sbasedon0\\snext15
\\015Numbered Reference ;}{\\s16\\li360 \\f20 \\sbasedon0\\snext16
Quotation;}{\\s17\\qc\\ri29\\sa240\\sl260\\keepn\\tx360 \\b\\caps\\f20
\\sbasedon0\\snext0 Section Number
Heading;}}\\margl1620\\margr1620\\margt2160\\margb2160\\ftnbj \\sectd
\\015\\pgnrestart\\linemod0\\linex0\\footery1080\\cols1\\endnhere
\\pard\\plain \\tx360 \\f20 ";

        printf("%s", header);
	yylex();
	printf("}");
}
yywrap()
{
  return (1);
}
------------------------------------------------------------------------
/*  modified from:  */
/*------------------------------------------------------------------------*/
/* Lexical input for LEX for LALR(1) Grammar for ANSI Ada                 */
/*                                                                        */
/*              Herman Fischer                                            */
/*            Litton Data Systems                                         */
/*              March 26, 1984                                            */
/*                                                                        */
/*------------------------------------------------------------------------*/
	int	my_start   = 0; /* indicates that it's startup time       */
	int	ignore_next_subprog = 0;  /* when in a generic parameter  */
					  /* declaration, indicates that  */
					  /* the next subprogram is a     */
					  /* formal parameter, and not    */
					  /* the actual generic thing.    */
	int	funct_defn = 0;  /* indicates that this return is part    */
				 /* of a function declaration, and should */
				 /* not be capitalized			  */ 
	char	class[20];
	int	do_index = 1;	/* 1 if indexing wanted, 0 otherwise	  */
#include "stdio.h"
#include "ctype.h"
%}

%e      3500  /* tree nodes array size    */
%p      9500  /* positions                */
%a      10000  /* transitions array size   */
%k      500   /* packed character classes */
%o      10000  /* output array size        */
%n	2000   /* states ?!		  */

%START IDENT Z COMMENT OTHERCMT PRAGMA KEEPNAME GENERICSPEC

%%
 	{BEGIN Z;}
<Z,IDENT>(ABORT|abort)|(ABS|abs)|(ACCEPT|accept)|(ACCESS|access)	|
<Z,IDENT>(ALL|all)|(AND|and)|(ARRAY|array)|(AT|at)			|
<Z,IDENT>(BEGIN|begin)|(BODY|body)|(CASE|case)|(CONSTANT|constant)	|
<Z,IDENT>(DECLARE|declare)|(DELAY|delay)|(DELTA|delta)|(DIGITS|digits)	|
<Z,IDENT>(DO|do)|(ELSE|else)|(ELSIF|elsif)|(END|end)|(ENTRY|entry)	|
<Z,IDENT>(EXCEPTION|exception)|(FOR|for)				|
<Z,IDENT>(IF|if)|(IN|in)|(IS|is)|(LIMITED|limited)|(LOOP|loop)		|
<Z,IDENT>(MOD|mod)|(NEW|new)|(NOT|not)|(NULL|null)|(OF|of)|(OR|or)	|
<Z,IDENT>(OTHERS|others)|(OUT|out)|(PRIVATE|private)			|
<Z,IDENT>(RANGE|range)|(RECORD|record)|(REM|rem)			|
<Z,IDENT>(RENAMES|renames)|(REVERSE|reverse)				|
<Z,IDENT>(SELECT|select)|(SEPARATE|separate)				|
<Z,IDENT>(TERMINATE|terminate)|(THEN|then)|(USE|use)			|
<Z,IDENT>(WHEN|when)|(WHILE|while)|(XOR|xor)				{
			MAKELOWER(yytext); hilite(yytext); BEGIN Z;	}

<Z,IDENT>(WITH|with)							{
			MAKELOWER(yytext); hilite(yytext);
			BEGIN Z;					}


<Z,IDENT>(GOTO|goto)|(EXIT|exit)|(RAISE|raise)				{
			MAKELOWER(yytext); hilite(yytext); BEGIN Z;	}

<Z,IDENT>(RETURN|return)						{
			MAKELOWER(yytext); hilite(yytext); BEGIN Z;	}

<Z,IDENT>("=>")|("..")|("**")|(":=")|("/=")|(">=")|("<=")|("<<")	|
<Z,IDENT>(">>")|("<>")|("&")|("(")|("*")|("+")|(",")|("-")|(".")	|
<Z,IDENT>("/")|(":")|(";")|("<")|("=")|(">")|("|")			{
						ECHO; BEGIN Z;		}

<Z,IDENT>")"     		{ECHO; BEGIN IDENT;}

<Z,IDENT>(PRAGMA|pragma)	{
				MAKELOWER(yytext);
				hilite(yytext);
				BEGIN PRAGMA;
				}


<PRAGMA>.			{
				unput(yytext[0]);
				BEGIN Z;
				}

<Z,IDENT>TYPE|type		|
<Z,IDENT>SUBTYPE|subtype	|
<Z,IDENT>TASK|task		|
<Z,IDENT>(PROCEDURE|procedure)	|
<Z,IDENT>(PACKAGE|package) 	{
				MAKELOWER(yytext);
				hilite(yytext); 
				BEGIN Z;}


<Z,IDENT>(FUNCTION|function)	{
				MAKELOWER(yytext);
				hilite(yytext); 
				BEGIN Z;}


<KEEPNAME>[a-zA-Z][a-z_A-Z0-9]*       {ECHO;BEGIN Z;}


<Z,IDENT>(GENERIC|generic)	{
				MAKELOWER(yytext); hilite(yytext); 
				BEGIN GENERICSPEC;}

<GENERICSPEC>(WITH|with)						{
				MAKELOWER(yytext); hilite(yytext);
				}

<GENERICSPEC>(PROCEDURE|procedure)|(FUNCTION|function)			{
				MAKELOWER(yytext); hilite(yytext);
									}

<GENERICSPEC>(PACKAGE|package)						{
				MAKELOWER(yytext); hilite(yytext);
				BEGIN Z;}


<GENERICSPEC>(ACCESS|access)|(ARRAY|array)|(CONSTANT|constant)		|
<GENERICSPEC>(DELTA|delta)|(DIGITS|digits)|(IN|in)|(IS|is)		|
<GENERICSPEC>(LIMITED|limited)|(OF|of)|(OTHERS|others)|(OUT|out)	|
<GENERICSPEC>(PRIVATE|private)|(RANGE|range)|(RETURN|return)		|
<GENERICSPEC>(SUBTYPE|subtype)|(TYPE|type)				{
				MAKELOWER(yytext); hilite(yytext);	}

<GENERICSPEC>[a-zA-Z][a-z_A-Z0-9]*	{ECHO;}

<GENERICSPEC>.				{ECHO;}


<IDENT>\'  {ECHO; BEGIN Z;}   /* type mark only */

<Z,IDENT>[a-zA-Z][a-z_A-Z0-9]*       {ECHO; BEGIN IDENT; }

<Z,IDENT>[0-9][0-9_]*([.][0-9_]+)?([Ee][-+]?[0-9_]+)?  {
						         ECHO; BEGIN Z; }

<Z,IDENT>[0-9][0-9_]*#[0-9a-fA-F_]+([.][0-9a-fA-F_]+)?#([Ee][-+]?[0-9_]+)? {
			      ECHO; BEGIN Z; }

<Z,IDENT>\"([^\"]*(\"\")*)*\" {ECHO; BEGIN Z; }

<Z>\'([^\']|\'\')\'    {ECHO; BEGIN Z; }

<Z,IDENT,PRAGMA,KEEPNAME,GENERICSPEC>[" "|"\t"]		{ECHO;}    /* ignore spaces and tabs */

<Z,IDENT>.       {ECHO; printf("?? lexical error [%s] ??\n(@\\)", yytext);}

<Z,IDENT,PRAGMA,KEEPNAME,GENERICSPEC>"--"([" "|"\t"]*)	{ECHO; BEGIN COMMENT;}

<Z,IDENT,PRAGMA,KEEPNAME,GENERICSPEC>[\n]	{printf("\\par \015"); BEGIN Z;}

<COMMENT,OTHERCMT>"-"+	{ECHO;}
<COMMENT,OTHERCMT>[\n]	{printf("\\par \015"); BEGIN Z;}


<COMMENT>.	{
		 unput(yytext[0]); 
		 BEGIN OTHERCMT;
		}

<OTHERCMT>.*	{
		 printf("{\\i %s}", yytext);
		 BEGIN Z;
		}

%%
hilite(it)	
	char 	*it;
{printf("{\\b %s}", it);}

MAKEUPPER(s)
	char	*s;
{
	for (; *s != NULL; ++s)
		*s = (islower(*s) ? toupper(*s) : *s);
}
MAKELOWER(s)
	char	*s;
{
	for (; *s != NULL; ++s)
		*s = (isupper(*s) ? tolower(*s) : *s);
}

--
--The preceeding opinions do not necessarily reflect the opinions of
--The MITRE Corporation or its sponsors. 
-- "A good plan violently executed -NOW- is better than a perfect plan
--  next week"                                      George Patton
-- "Any damn fool can write a plan.  It's the execution that gets you
--  all screwed up"                              James Hollingsworth
-------------------------------------------------------------------------



      parent reply	other threads:[~1994-12-02 14:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-01 19:47 Ada PostScript Pretty printer? Tony Leavitt
1994-12-02  0:09 ` David Weller
1994-12-02 10:05   ` Rolf Ebert
1994-12-03  4:27     ` David Weller
     [not found] ` <3bn9f6$8hl@cliffy.lfwc.lockheed.com>
1994-12-02 14:55   ` David Emery [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox