Commit 7e952f88 authored by david_v's avatar david_v
Browse files

2003-06-12 Valentin David <valentin@lrde.epita.fr>

	* README: New file.
	* AUTHORS: New file.
	* INSTALL: New file.

	* configure.ac: many deleted directories, and maintener mail added

	* lib/sdf-cons,
	* src/pack-boxed2pp-table,
	* src/pack-boxed2sdf: Deleted directories (unused).

	* test/inst.sh: Deleted file.
	* test/defs.in:
	XTC problem resolved. No make install any more for test ;)

	* src/pack-boxedsdf/pack-boxedsdf.str,
	* src/parser/parse-boxedsdf.str,
	* src/pp/pp-boxedsdf.str,
	* src/boxed2sdf/boxed2sdf.str,
	* src/boxed2pp-table/boxed2pp-table.str: Comments added.
parent 4f7f8060
Valentin David <valentin@lrde.epita.fr>
2003-06-12 Valentin David <valentin@lrde.epita.fr>
* README: New file.
* AUTHORS: New file.
* INSTALL: New file.
* configure.ac: many deleted directories, and maintener mail added
* lib/sdf-cons,
* src/pack-boxed2pp-table,
* src/pack-boxed2sdf: Deleted directories (unused).
* test/inst.sh: Deleted file.
* test/defs.in:
XTC problem resolved. No make install any more for test ;)
* src/pack-boxedsdf/pack-boxedsdf.str,
* src/parser/parse-boxedsdf.str,
* src/pp/pp-boxedsdf.str,
* src/boxed2sdf/boxed2sdf.str,
* src/boxed2pp-table/boxed2pp-table.str: Comments added.
2003-06-11 Valentin David <valentin.david@lrde.epita.fr>
* src/pack-boxedsdf/pack-boxedsdf:
......
Requirements
------------
StrategoXT 0.9 or above (http://www.stratego-language.org/)
Grammar Base 1.0 or above (http://homepages.cwi.nl/~mdejonge/downloads/)
Installation
------------
$ ./configure --with-xt=<PATH>
$ make
$ make install
......@@ -2,5 +2,5 @@ include config/Makefile.xt
SUBDIRS = . config lib src test
BOOTCLEAN_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = ChangeLog
EXTRA_DIST = ChangeLog README INSTALL AUTHORS
XTC_IMPORT = $(STRATEGOXT)/share/StrategoXT/XTC
BoxedSdf
--------
This package is to make easier the writting of Pretty-Print tables for Generic
Pretty-Printer.
Author : Valentin David <valentin@lrde.epita.fr>
Requirements
------------
StrategoXT 0.9 or above (http://www.stratego-language.org/)
Grammar Base 1.0 or above (http://homepages.cwi.nl/~mdejonge/downloads/)
Installation
------------
$ ./configure --with-xt=<PATH>
$ make
$ make install
Working with BoxedSdf grammar
-----------------------------
A common using is:
$ pack-boxedsdf -i MyGrammar.ppsdf | \
asfix-yield -o MyGrammar.ppdef
$ parse-boxedsdf -i MyGrammar.ppdef | \
boxed2sdf | \
pp -a -l sdf -v 2.1 -o MyGrammar.def
$ parse-boxedsdf -i MyGrammar.ppdef | \
boxed2pp-table | \
pp-pp-table -o MyGrammar.pp
Note: if you have to use sdf-cons on your grammar, do it before the boxed2*
filters
Using old grammars
------------------
If you want to use an aldready written grammar, you can merge PP information
into the Sdf grammar. Let's suppose have MyOldGrammar.def and MyOldGrammar.pp
$ parse-sdf -i MyOldGrammar.def | \
boxedsdf-merge -p MyOldGrammar.pp | \
pp-boxedsdf -o MyOldGrammar.ppdef
If you want to get modular files, you can use the unpack-sdf of the StrategoXT
package.
AC_PREREQ(2.57)
AC_INIT(sdf-box, 0.1)
AC_INIT(sdf-box, 0.1, valentin@lrde.epita.fr)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_FILES(config/Makefile)
......@@ -15,15 +15,12 @@ AC_PROG_INSTALL
AC_CONFIG_FILES([Makefile
lib/Makefile
lib/sdf-2.1/Makefile
lib/sdf-cons/Makefile
lib/ppgen/Makefile
src/Makefile
src/syn/Makefile
src/boxed2sdf/Makefile
src/boxed2pp-table/Makefile
src/pack-boxedsdf/Makefile
src/pack-boxed2sdf/Makefile
src/pack-boxed2pp-table/Makefile
src/pp/Makefile
src/boxedsdf-merge/Makefile
src/parser/Makefile
......
include $(top_srcdir)/config/Makefile.xt
SUBDIRS = sdf-2.1 sdf-cons ppgen
SUBDIRS = sdf-2.1 ppgen
BOOTCLEAN_SUBDIRS = $(SUBDIRS)
\literate[sdf-2-pp-lib]
%
% This file is from the Generic Pretty Printer from the StrategoXT package
%
% GT -- Grammar Tools
% Copyright (C) 2000 Merijn de Jonge <mdejonge@cwi.nl>
% Eelco Visser <visser@acm.org>
......@@ -19,7 +23,7 @@
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
% 02111-1307, USA.
% $Id: sdf-2-pp-lib.str 1.1 Mon, 19 May 2003 14:59:25 +0200 david_v $
% $Id: sdf-2-pp-lib.str 1.2 Thu, 12 Jun 2003 16:56:34 +0200 david_v $
% Author: Merijn de Jonge (mdjonge@cwi.nl)
......
#
# This Makefile extract the Sdf grammar from the grammar base
#
include $(top_srcdir)/config/Makefile.xt
SDFS = Alias-Sdf-Syntax.sdf \
......
include $(top_srcdir)/config/Makefile.xt
EXTRA_DIST = sdf-cons.str
// SDF Tools
// Copyright (C) 2001 Merijn de Jonge <mdejonge@cwi.nl>
// Eelco Visser <visser@acm.org>
// Joost Visser <jvisser@cwi.nl>
//
// 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, 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., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
\literate[sdf-cons]
% Author: Joost Visser (Joost.Visser@cwi.nl)
% Changes by: Merijn de Jonge, Eelco Visser, and Hedzer Westra.
% Refactorings by: Eelco Visser (19/4/2001)
% - injections not named
% Refactorings by: Eelco Visser (18/5/2001)
% - injections named by default
% - option --injections added to turn off
Add cons(...) attributes to Sdf productions.
\begin{code}
module sdf-cons
imports lib Sdf-Syntax Sdf-NormLit-Syntax prodcons.r termid
signature
constructors
Modular: Option
Injections: Option
strategies
sdf-cons =
io-idwrap(InOutId("\"sdf-2.1\"", !"\"sdf-2.1\""),
sdf-cons,
Option("--modular",!Modular,
!"--modular unique names per module")
+ Option("--injections",!Injections,
!"--injections do not generate constructors for injections"))
short-description(p) = ![<p>(), " -- usage:"]
long-description(p) = !["This program adds constructor names to productions of an SDF grammar." ]
sdf-cons =
(store-options,id)
; (id, alltd(lexical-syntax(id) <+ context-free-priorities(id) <+ lexical-priorities(id) <+ priorities(id) <+ (is-prod; prodcons)))
; try((option-defined(Modular), uniquify-modular))
; try((not(option-defined(Modular)), uniquify))
(*
sorts Grammar Production
constructors
lexical-syntax : List(Production) -> Grammar
prod : Symbols * Symbol * Attributes -> Production
prod-fun : Literal * Symbols * Symbol * Attributes -> Production
cons : ATerm -> Attribute
*)
strategies
uniquify-modular = Definition(map(uniquify-module))
uniquify = uniquify-module
// uniquifying using tables to implement a bucket sort
strategies
uniquify-module =
where(uniquify-prods)
; alltd(replace-prod)
uniquify-prods =
collect(prod(id,id,id))
; where(<table-create>"prods")
; map(try(add-prod))
; <table-getlist> "prods"
; map(uniquify-constr)
add-prod =
where(?p
; get-constr => c
; <table-push>("prods", c, p)
)
replace-prod =
?prod(srts, res, _)
; prod(id, id, at-cons(<table-get>("prods", prod(srts,res,no-attrs))))
uniquify-constr =
(id, reverse; [id | \ps -> <thread-map(prime-prod); Fst> (ps, 1) \ ])
rules
prime-prod :
Pair(p@prod(ss,res,as), n) ->
Pair(prod(ss,res,<at-cons(!c)>as), <add> (n, 1))
where <prime-constr> (<get-constr> p, n) => c
; <table-put>("prods", prod(ss,res,no-attrs), c)
prime-constr :
(c, n) -> <conc-strings; quote> (<de-quote> c, <int-to-string> n)
strategies
is-prod
= prod(id,id,id)
<+ prod-fun(id,id,id,id)
\end{code}
......@@ -4,8 +4,6 @@ SUBDIRS = syn \
boxed2sdf \
boxed2pp-table \
pack-boxedsdf \
pack-boxed2sdf \
pack-boxed2pp-table \
pp \
parser \
boxedsdf-merge
......
include $(top_srcdir)/config/Makefile.xt
-include boxed2pp-table.c.dep
bin_PROGRAMS = boxed2pp-table
SCFLAGS = --main $*
STRINCLUDES = -I $(top_builddir)/src/syn \
-I $(top_srcdir)/lib/sdf-cons \
-I $(ASFIX_TOOLS)/share/asfix-tools \
-I $(top_srcdir)/lib/ppgen
BOOTCLEANFILES = boxed2pp-table.c
CLEANFILES = boxed2pp-table.o boxed2pp-table \
*.tmp *.dep *.atree *.mtree *.txt *.af *.abox
EXTRA_DIST = boxed2pp-table.str
/**
* This module transforms a BoxedSdf AST into a PP-Table one.
*
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module boxed2pp-table
imports BoxedSdf2 prodcons sdf-cons sdf-2-pp-lib
imports BoxedSdf2 prodcons sdf-2-pp-lib
strategies
at-pp(s) = oncetd(BoxedAttr(pplist(s)))
/**
* PP-Entry equality.
*/
ppeq = ?(PP-Entry(Path1(cons), _), PP-Entry(Path1(cons), _))
ppeq = ?(PP-Entry(Path(cons, _), _), PP-Entry(Path(cons, _), _))
rules
/**
* Replace generated PP-Entries by written ones (attributes).
*/
ReplaceOnePP : (x, []) -> x
ReplaceOnePP : (x, [y|ys]) -> y
......@@ -37,11 +48,17 @@ rules
; !(l, my-pplist)
; ReplacePP => pplist
/**
* Convert PP attributes to PP-Entries
*/
ToPPEntry : (cons, Pathed(None, b))
-> PP-Entry(Path1(cons),b)
ToPPEntry : (cons, Pathed(Some(Path2(s)), b))
-> PP-Entry(Path(cons, s), b)
/**
* Explore and transform the AST.
*/
extexp : Exports(context-free-syntax(l)) -> l'
where <map(ToPP <+ ![])> l
; concat
......@@ -73,10 +90,14 @@ rules
strategies
putprod = where(ToPP)
/**
* Keep list element which match s.
*/
keep(s) = rec x([] <+ [s|x] <+ (\ [_|xs] -> xs \; x))
/**
* Main Strategy.
*/
boxed2pp-table = iowrap(\ _#([x]) -> x \
; (extdef + extmod)
; \ x -> PP-Table(x) \)
include $(top_srcdir)/config/Makefile.xt
-include boxed2sdf.c.dep
bin_PROGRAMS = boxed2sdf
SCFLAGS = --main $*
STRINCLUDES = -I $(top_builddir)/src/syn
BOOTCLEANFILES = boxed2sdf.c
CLEANFILES = boxed2sdf.o boxed2sdf \
*.tmp *.dep *.atree *.mtree *.txt *.af *.abox
EXTRA_DIST = boxed2sdf.str
\ No newline at end of file
EXTRA_DIST = boxed2sdf.str
/**
* This module clean all the pp entries in a BoxedSdf input so as to have a
* pure Sdf AST as output.
*
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module boxed2sdf
imports lib BoxedSdf2
strategies
/**
* Take an attribute list as input and return this list without the
* pp attributes
*/
skip-boxedattr = rec x([] <+ (?[BoxedAttr(_)|ys]; !ys; x) <+ [id|x])
/**
* Main strategy. Skip all the pp attributes in the AST.
*/
boxed2sdf = iowrap(
topdown(
try(attrs(skip-boxedattr)
......
include $(top_srcdir)/config/Makefile.xt
-include boxedsdf-merge.c.dep
bin_PROGRAMS = boxedsdf-merge
SCFLAGS = --main $*
......@@ -7,6 +8,7 @@ STRINCLUDES = -I $(top_builddir)/src/syn \
-I $(ASFIX_TOOLS)/share/asfix-tools \
-I $(top_srcdir)/lib/ppgen
BOOTCLEANFILES = boxedsdf-merge.c
CLEANFILES = boxedsdf-merge.o boxedsdf-merge \
*.tmp *.dep *.atree *.mtree *.txt *.af *.abox
EXTRA_DIST = boxedsdf-merge.str
/**
* Sdf and PP-table merger
*
* This module takes a Sdf grammar and a PP-table and merge it so as to get
* the corresponding BoxedSdf grammar.
*
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module sdf-boxed-merge
imports lib BoxedSdf2 xtc-lib stratego-xt-xtc-tools sdf-2-pp-lib
signature
......@@ -6,6 +14,12 @@ signature
rules
/**
* :: String -> Term
*
* If the infile has a pp extension. It parse it as PP-table into an
* AST.
*/
readtxtpp : infile -> tree
where <has-extension(!"pp")> infile
; xtc-temp-files(<xtc-transform(!"sglr",
......@@ -13,18 +27,30 @@ rules
; xtc-implode-asfix
; read-from => tree)
/**
* :: String -> Term
*
* The infile has a pp.af extension. The files is already an AST.
*/
readtxtpp : infile -> tree
where <has-extension(!"pp.af")> infile
; ReadFromFile => tree
strategies
/**
* -p/--pptable option
* to specify the pp table
*/
pptable-option =
ArgOption("-p" + "--pptable"
, where(<set-config> ("-p",<id>)); !Pptable(<id>)
, !"-p f|--pptable f Read pptable input from f"
)
/**
* iowrap with the new option.
*/
my-iowrap(s) =
iowrap(
(
......@@ -33,7 +59,10 @@ strategies
<+ !"bad -p option, try --help."; debug; giving-up)
; (id, s)
, pptable-option)
/**
* Main strategy
*/
boxedsdf-merge = my-iowrap(
?(i, p)
; !i
......@@ -44,8 +73,14 @@ strategies
at-cons(s) = oncetd(cons(s))
/**
* Success if input term is in e
*/
isin(e) = ?x; e; not(map(not(?x))); !x
/**
* Has a production as input. Then put all the useful PP attributes.
*/
tagprod(l) =
?p
; prod(id,id,at-cons(un-double-quote; ?cons))
......@@ -71,6 +106,9 @@ strategies
<+ prod(id,id, !attrs(BoxedAttr(pplist(pps)))))
))
/**
* Add PP attributes to all productions
*/
tag(l) = alltd(
lexical-syntax(id)
<+ context-free-priorities(id)
......
include $(top_srcdir)/config/Makefile.xt
bin_PROGRAMS = pack-boxed2pp-table
SCFLAGS = --main $*
STRINCLUDES = -I $(top_builddir)/src/syn -I $(XTC)/share/xtc
CLEANFILES = pack-boxed2pp-table.o pack-boxed2pp-table \
*.tmp *.dep *.atree *.mtree *.txt *.af *.abox
EXTRA_DIST = pack-boxed2pp-table.str
\ No newline at end of file
module pack-boxed2pp-table
imports xtc-lib stratego-xt-xtc-tools
strategies
pack-boxed2pp-table =
xtc-io-wrap(
xtc-transform(!"pack-boxedsdf",<get-configs(not("-i"); not("-o"))> ());
xtc-implode-asfix;
xtc-transform(!"sdf-cons");
xtc-transform(!"boxed2pp-table");
xtc-transform(!"pp-pp-table")
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment