/* //paragraph [1] Title: [{\Large \bf] [}] //[ue] [\"{u}] [1] An Extension of the PD System: Compiling into HTML Ralf Hartmut G[ue]ting November 1995 1 Overview A version of the ~PDSystem~ has been constructed which transforms PD files into HTML instead of LaTeX source files. This document describes the changes relative to the previous PDSystem, as described in [G[ue]95a, G[ue]95b]. Basically only the parser component (~Parser.y~) had to be changed and only in a rather trivial way by letting the statements generating LaTeX code produce corresponding HTML code. The result is a new version of the parser called ~ParserHTML.y~. A second small change concerns the main program ~Maketex.c~ which produces an ---- \end{document} ---- tail for the output text. This was removed; the changed version is called ~MakeHTML.c~. A simple command procedure ~pd2html~ was introduced (analogous to the procedure ~pd2tex~) which produces a HTML file from a PD file. The remainder of this document contains the revised parser ~ParserHTML.y~, the main program ~MakeHTML.c~, the command procedure ~pd2html~, and the revised ~makefile~. */ /* ---- This file is part of the PD system Copyright (C) 1998 Ralf Hartmut Gueting, Fachbereich Informatik, FernUniversitaet Hagen 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. ---- //[\] [$\setminus $] 5 The Parser (HTML Version) (File ~PDParserHTML.y~) 5.1 Introduction This file contains a ~yacc~ specification of a parser which is transformed by the UNIX tool ~yacc~ into a program file ~y.tab.c~ which in turn is compiled to produce a parser. For an introduction to ~yacc~ specifications see [ASU86, Section 4.9]. Detailed information is given in [SUN88, Section 11]. In fact, the specification contains ``semantic rules'' (or ~actions~); hence, the generated program is a compiler (from PD files into HTML). The parsing technique used is bottom-up LR parsing. Let us briefly consider two example rules: ---- heading : heading1 | heading2 | heading3 | heading4 | heading5 ; heading1 : HEAD1 paragraph_rest {printf("
\n");}
chars {printf("\n");}
;
chars :
| chars text_char {print($2);}
| chars TILDE {print($2);}
| chars STAR {print($2);}
| chars DUS {print($2);}
| chars QUOTE {print($2);}
| chars '\"' {print($2);}
| chars '*' {print($2);}
| chars '~' {print($2);}
| chars '[' {print($2);}
| chars ']' {print($2);}
| chars follow_elem {print($2);}
| chars EPAR {print($2);}
| chars DEFLINE {print($2);}
| chars TTFORMAT {print($2);}
;
elements :
| elements definitions
| elements element {release_storage();}
| elements list /* storage cannot be released after
lists because of look-ahead */
;
/*
5.4 Definitions of Special Formats and Characters
*/
definitions : defs EPAR
;
defs : defline
| defs defline
;
defline : DEFLINE par_format
| DEFLINE char_format
| DEFLINE special_char_def
;
par_format : PARFORMAT space REF space ident space ':'
space bracketed2 space bracketed2
{
/* test only:
print($3);
printf("paragraph definition: %d ",
get_ref_index($3));
print($5);
print($9);
print($11);
*/
enter_def(get_ref_index($3), $5, $9, $11);}
;
char_format : CHARFORMAT space REF space ident space ':'
space bracketed2 space bracketed2
{
/*
printf("characters definition: %d ",
get_ref_index($3));
print($5);
print($9);
print($11);
*/
enter_def(get_ref_index($3), $5, $9, $11);}
;
special_char_def: bracketed2 space bracketed2
{enter_schar($1, $3);}
;
space :
| space ' '
| space FOLLOW1
| space FOLLOW2
| space DISPLAY
| space FIGURE
;
ident : LETTER {$$ = $1;}
| ident LETTER {$$ = concat($1, $2);}
| ident DIGIT {$$ = concat($1, $2);}
;
/*
5.5 Text Elements
5.5.1 Predefined Paragraph Types
*/
element : standard_paragraph
| heading
| verb
| display
| figure
| special_paragraph
;
standard_paragraph : paragraph_rest {print($1); printf("\n\n");} ; heading : heading1 | heading2 | heading3 | heading4 | heading5 ; heading1 : HEAD1 paragraph_rest {printf("
\n ");}
;
verb_end : vchars ENDVERBATIM {printf("\n");}
;
vchars : vchars VCHAR { print($2); }
| VCHAR { print($1); }
;
display : DISPLAY paragraph_rest {printf("\n"); printf(" "); print($2); printf("\n\n\n");} ; /* 5.5.2 Figures */ figure : FIGURE figure_text optional_caption bracketed2 annotations {printf("
\n\n");}
;
/*
Here a figure description of the form
---- Figure 1: Picture of something [filename]
----
is transformed into a text in HTML:
---- Picture of something
---- */ optional_caption: {$$ = atomc("");} | ':' figure_text {$$ = $2;} ; figure_text : {$$ = atomc("");} | figure_text ftext_char {$$ = concat($1, $2);} | figure_text TILDE {$$ = concat($1, atomc("~"));} | figure_text STAR {$$ = concat($1, atomc("*"));} | figure_text DUS {$$ = concat($1, atomc("__"));} | figure_text QUOTE {$$ = concat($1, atomc("\""));} | figure_text emphasized {$$ = concat($1, $2);} | figure_text typewriter {$$ = concat($1, $2);} | figure_text bold_face {$$ = concat($1, $2);} | figure_text special_char_format {$$ = concat($1, $2);} | figure_text follow_elem {$$ = concat($1, $2);} ; /* 5.5.4 Special Paragraph Formats */ special_paragraph: STARTREF paragraph_rest {int i; i = get_startref_index($1); if (i > 0) /* not an empty start ref */ pindex = lookup_def(i); /* otherwise use previous pindex value */ if (pindex >= 0) /* def was found */ {printf("%s ", definitions[pindex].open); print($2); printf("%s \n\n", definitions[pindex].close); } else print($2); /* make it a standard paragraph */ } ; /* 5.6 Lists */ list : itemized1 {printf("
"),
concat($2,
atomc("")));}
;
bold_face : '*' unbold_list '*' {$$ = concat(atomc(""),
concat($2,
atomc("")));}
;
unemph_list : {$$ = atomc("");}
| unemph_list unemph {$$ = concat($1, $2);}
;
unemph : text_char {$$ = $1;}
| TILDE {$$ = atomc("~");}
| STAR {$$ = atomc("*");}
| DUS {$$ = atomc("__");}
| QUOTE {$$ = atomc("\"");}
| follow_elem {$$ = $1;}
| '*' unboldemph_list '*' {$$ = concat(atomc(""),
concat($2,
atomc("")));}
| special_char_format {$$ = $1;}
| bracketed {$$ = $1;}
;
untt_list : {$$ = atomc("");}
| untt_list untt {$$ = concat($1, $2);}
;
untt : text_char {$$ = $1;}
| TILDE {$$ = atomc("~");}
| STAR {$$ = atomc("*");}
| DUS {$$ = atomc("__");}
| QUOTE {$$ = atomc("\"");}
| follow_elem {$$ = $1;}
| special_char_format {$$ = $1;}
| bracketed {$$ = $1;}
;
unbold_list : {$$ = atomc("");}
| unbold_list unbold {$$ = concat($1, $2);}
;
unbold : text_char {$$ = $1;}
| TILDE {$$ = atomc("~");}
| STAR {$$ = atomc("*");}
| DUS {$$ = atomc("__");}
| QUOTE {$$ = atomc("\"");}
| follow_elem {$$ = $1;}
| '~' unboldemph_list '~' {$$ = concat(atomc(""),
concat($2,
atomc("")));}
| special_char_format {$$ = $1;}
| bracketed {$$ = $1;}
;
unboldemph_list : {$$ = atomc("");}
| unboldemph_list unboldemph {$$ = concat($1, $2);}
;
unboldemph : text_char {$$ = $1;}
| TILDE {$$ = atomc("~");}
| STAR {$$ = atomc("*");}
| DUS {$$ = atomc("__");}
| QUOTE {$$ = atomc("\"");}
| follow_elem {$$ = $1;}
| special_char_format {$$ = $1;}
| bracketed {$$ = $1;}
;
plain_list : {$$ = atomc("");}
| plain_list plain {$$ = concat($1, $2);}
;
plain : text_char {$$ = $1;}
| TILDE {$$ = atomc("~");}
| STAR {$$ = atomc("*");}
| DUS {$$ = atomc("__");}
| QUOTE {$$ = atomc("\"");}
| bracketed {$$ = $1;}
;
/*
5.8 Special Character Formats
*/
special_char_format : '\"' plain_list '\"' REF
{int i;
i = get_ref_index($4);
cindex = lookup_def(i);
if (cindex >= 0) /* def was found */
{$$ = concat(
atomc(definitions[cindex].open),
concat($2,
atomc(definitions[cindex].close) ));
}
else /* ignore special format */
$$ = $2;
}
| '\"' plain_list '\"'
{if (cindex >= 0) /* def exists */
{$$ = concat(
atomc(definitions[cindex].open),
concat($2,
atomc(definitions[cindex].close) ));
}
else /* ignore special format */
$$ = $2;
}
;
/*
5.9 Text in Square Brackets: Checking for Special Characters
*/
bracketed : '[' btext ']'
{char bracketstring[BRACKETLENGTH];
int i;
int length;
copyout($2, bracketstring, BRACKETLENGTH);
length = strlen(bracketstring);
if (length <= CODELENGTH - 1)
{i = lookup_schar(bracketstring);
if (i >= 0) /* found */
$$ = atomc(schars[i].command);
else
$$ = concat($1,
concat($2, $3));
}
else
$$ = concat($1, concat($2, $3));
}
;
btext : {$$ = atomc("");}
| btext text_char {$$ = concat($1, $2);}
| btext TILDE {$$ = concat($1, atomc("~"));}
| btext STAR {$$ = concat($1, atomc("*"));}
| btext DUS {$$ = concat($1, atomc("__"));}
| btext QUOTE {$$ = concat($1, atomc("\""));}
| btext follow_elem {$$ = concat($1, $2);}
| btext '\"' {$$ = concat($1, $2);}
| btext '*' {$$ = concat($1, $2);}
| btext '~' {$$ = concat($1, $2);}
| btext '[' btext ']'
{char bracketstring[BRACKETLENGTH];
int i;
int length;
copyout($3, bracketstring, BRACKETLENGTH);
length = strlen(bracketstring);
if (length <= CODELENGTH - 1)
{i = lookup_schar(bracketstring);
if (i >= 0) /* found */
$$ = concat($1, atomc(schars[i].command));
else
{$$ = concat($1,
concat($2,
concat($3, $4)));}
}
else
{$$ = concat($1,
concat($2,
concat($3, $4)));}
}
;
/*
5.10 Uninterpreted Square Brackets (Used in Definitions)
*/
bracketed2 : '[' btext2 ']' {$$ = $2;}
;
btext2 : {$$ = atomc("");}
| btext2 text_char {$$ = concat($1, $2);}
| btext2 TILDE {$$ = concat($1, $2);}
| btext2 STAR {$$ = concat($1, $2);}
| btext2 DUS {$$ = concat($1, $2);}
| btext2 QUOTE {$$ = concat($1, $2);}
| btext2 follow_elem {$$ = concat($1, $2);}
| btext2 '\"' {$$ = concat($1, $2);}
| btext2 '*' {$$ = concat($1, $2);}
| btext2 '~' {$$ = concat($1, $2);}
| btext2 '[' btext2 ']' {$$ = concat($1,
concat($2,
concat($3, $4)));}
;
annotations :
;
%%
#include "PDLex.c"
/*
----
This file is part of the PD system
Copyright (C) 1998 Ralf Hartmut Gueting,
(C) 2006 Markus Spiekermann
Fachbereich Informatik, FernUniversitaet in Hagen
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.
----
3 Main Program: MakeHTML.c
Use the parser to transform from implicitly formatted text to HTML.
*/
#include "PDLib.h"
extern int yyparse();
int main() {
CheckDebugEnv();
int error=0;
error = yyparse();
return error;
}
/*
4 Command Procedure ~pd2html~
*/
# This file is part of the PD system
# Copyright (C) 1998 Ralf Hartmut Gueting, Fachbereich Informatik, FernUniversitaet Hagen
# 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.
#!/bin/bash
#
# pd2html - Converts a PD file to a HTML file
#
# May 2004, M. Spiekermann
pdFile="$1"
htmlFile="$1.html"
if { ! pdtabs < $pdFile | makehtml > /dev/null; }; then
printf "\n PD-Error: Could not create $htmlFile! \n\n"
exit 1
fi
pdtabs < $pdFile | makehtml > $htmlFile
/*
5 The Makefile
*/
# This file is part of the PD system
# Copyright (C) 1998 Ralf Hartmut Gueting, Fachbereich Informatik, FernUniversitaet Hagen
# 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.
# File: makefile
#
# 05/03 Markus Spiekermann. Makefile revised to make it Windows/Unix
# compatible. Automatic enumeration of pd files is now done by a
# lex generated scanner, this is a replacement for the perl solution.
#
# 10/03 Markus Spiekermann. Target install introduced.
#
# 05/04 Markus Spiekermann. Changes in documentation and script files.
# 12/06 Markus Spiekermann. More generic rules introduced.
# Uncomment next line to switch on debug mode
#OPTIONS = -g
# The first line is used when compiling with FLEX (2.5.4a) and BISON (1.35)
# The second line when compiling with LEX and YACC
LINKLIBS = -lfl
# The first line is used when compiling with FLEX and BISON
# The second line when compiling with LEX and YACC
LEX = flex
#LEX = lex
# The first line is used when compiling with FLEX and BISON
# The second line when compiling with LEX and YACC
YACC = bison --yacc
#YACC = yacc
# specify your C-compiler
ifeq ($(platform),android)
CC := $(HOME)/toolchain-standalone/bin/arm-linux-androideabi-gcc
else
CC := gcc
endif
DOCU_FILES = PD1 PDNestedText.h PDNestedText.c \
PD3 PDLex.l PDTokens.h PDLexTest.c PDParserDS.c PDParser.y \
PD6 pd.header PDMaketex.c \
PD7 pdtabs.c linebreaks.c \
PD8 pdview \
PD8.2 pdshow \
PD8.3 pd2tex \
PD8.4 pd2dvi \
PD8.5 pd2ps \
PD8.6 pd2pdf \
PD9 makefile \
PDRefs
DOCU_HTML_FILES = HTML1 PDParserHTML.y PDMakeHTML.c \
HTML4 pd2html \
HTML5 makefile \
PDRefsHTML
OBJECTS = PDNestedText.o \
PDLib.o
APPS = pdtabs \
linebreaks \
enumerate \
maketex \
linecheck \
tabcheck \
filterpd \
makehtml \
makeascii
DOCU = docu docuhtml
SCRIPTS = pd2ascii pd2html pd2tex pd2dvi pd2ps pd2pdf pdshow pdview checkpd pdpreview
TEMPORARYS = PDLex.c enumerate.c linecheck.c tabcheck.c y.tab.c
.PHONY: all
all: $(OBJECTS) $(APPS) $(DOCU)
@chmod ugo+x $(SCRIPTS)
maketex: PDMaketex.c PDParser.y PDLex.c PDParserDS.c $(OBJECTS)
$(YACC) PDParser.y -o PDParser.tab.c
$(CC) $(OPTIONS) -o $@ $< PDParser.tab.c $(OBJECTS) $(LINKLIBS)
makehtml: PDMakeHTML.c PDParserHTML.y PDLex.c PDParserDS.c $(OBJECTS)
$(YACC) PDParserHTML.y -o PDParserHTML.tab.c
$(CC) $(OPTIONS) -o $@ $< PDParserHTML.tab.c $(OBJECTS) $(LINKLIBS)
makeascii: PDMakeASCII.c PDParserASCII.y PDLex.c PDParserDS.c $(OBJECTS)
$(YACC) PDParserASCII.y -o PDParserASCII.tab.c
$(CC) $(OPTIONS) -o $@ $< PDParserASCII.tab.c $(OBJECTS) $(LINKLIBS)
pdtabs: pdtabs.c
$(CC) -o $@ $<
linebreaks: linebreaks.c
$(CC) -o $@ $<
# some dependencies
PDNestedText.o: PDNestedText.h
PDLib.o: PDLib.h
# some generic translation rules
%.c: %.l
$(LEX) -o$@ $<
%.o: %.c
$(CC) -c -g $<
%: %.c
$(CC) -o $@ $< $(LINKLIBS)
docu: $(DOCU_FILES)
cat $^ > $@
docuhtml: $(DOCU_HTML_FILES)
cat $^ > $@
.PHONY: dist
dist: pd.tar.gz
pd.tar.gz:
cvs export -r$(tag) pd
tar -czf pd.tgz pd/*
rm -r pd
INST_DIR = $(prefix)/pd
EPS_FILES = $(shell find ./Figures -name "*.eps")
.PHONY: install
install: $(OBJECTS) $(SCRIPTS)
install -d $(INST_DIR)
install -m744 -d $(INST_DIR)/Figures
install $(OBJECTS) $(INST_DIR)
install -m444 $(DOCU) $(INST_DIR)
install -m444 $(EPS_FILES) $(INST_DIR)/Figures
install $(SCRIPTS) $(INST_DIR)
install pd.header $(INST_DIR)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(APPS) $(DOCU) $(TEMPORARYS) *.exe *.tab.c
/*
//[ae] [\"{a}]
//[oe] [\"{o}]
//[ue] [\"{u}]
//[ss] [\ss]
\begin{thebibliography}{ABCD99}
\bibitem[ASU86]{ASU86}
Aho, A.V., R. Sethi, and J.D. Ullman, Compilers: Principles, Techniques, and Tools. Addison-Wesley, 1986.
\bibitem[G[ue]95a]{Gue95a} G[ue]ting, R.H., Integrating Programs and Documentation. FernUniversit[ae]t Hagen, Informatik-Report 182, May 1995.
\bibitem[G[ue]95b]{Gue95b} G[ue]ting, R.H., The PD System: Integrating Programs and Documentation. Praktische Informatik IV, FernUniversit[ae]t Hagen, Software-Report 2, May 1995.
\bibitem[HTML95]{} A Beginner's Guide to HTML. WWW Document. \\http://www.ncsa.uiuc.edu/General/Internet/WWW/HTMLPrimer.html
\bibitem[SUN88]{SUN88} Sun Microsystems, Programming Utilities and Libraries. User Manual. Sun Microsystems, 1988.
\end{thebibliography}
*/