implode-asfix — maps an asfix parse tree to an abstract syntax tree
implode-asfix
[--lex]
[--layout]
[--lit]
[--alt]
[--appl]
[--nt]
[--inj]
[--list]
[--seq]
[--pt]
[--concrete]
[-i file
| --input file
]
[-o file
| --output file
]
[-b]
[-S | --silent]
[--verbose level
]
[--k level
| --keep level
]
[-h | -? | --help]
[--about]
[--version]
The implode-asfix utility maps an AsFix tree to an abstract syntax tree. The mapping performs several transformations, including:
remove layout
flatten lexical subtrees to strings
replace appl(prod(...),[...])
applications by
constructor applications, if the production is annotated
with a cons(...)
attribute.
The input tree is required to be in AsFix2 format. See the AsFix section for more information about the AsFix format.
Implode Options
--alt
Flatten alternatives.
--appl
Replace appl
applications by constructor applications.
--concrete
Skip concrete syntax parts of a Stratego program. Concrete
syntax starts a ToTerm
,
ToStrategy
or
ToBuild
and stops at
FromTerm
or
FromApp
.
--inj
Remove injections from the parse tree.
--layout
Remove layout nodes from the parse tree.
--lex
Flatten lexical substrings to strings.
--list
Flatten lists.
--lit
Remove literal nodes from the parse tree.
--nt
Replace appl
application by non-terminal applications.
--pt
Remove the outer pt
constructor from the
parse tree
--seq
Replace sequences by tuples
Common Input/Output Options
-i file
The input term given by the file name
.
file
In the absence of the -i
option, input
will be read from stdin
.
-o file
The output will be written to the file given by the file name
.
file
In the absence of the -o
option,
output will be written to stdout
.
-b
The output will be written in the binary (BAF) ATerm format.
ATerms in the BAF format require a lot less space than ones in the TAF format, but the Java ATerm library does not currently support baf ATerms. ATerms in the baf format is the preferred format of exchange between Stratego tools.
Common Debugging Options
--about
See --version
.
-h
, -?
, --help
Display usage information.
--keep int
Keep intermediate results produced by the internal stages in the
pretty-printing process. This is only useful for debugging. A high
value of int
indicates increased eagerness
for keeping intermediate results.
Default setting is 0, indicating that no intermediates will be kept.
-S
, --silent
Silent execution. Same as --verbose
.
0
--verbose int
Set verbosity level to numerical value int
. The
higher the number, the more information about pp-aterm's inner workings are
printed.
Alternatively, int
can be set to either of the
following verbosity levels, given in increasing order of verbosity:
emergency
, alert
, critical
,
error
, warning
, notice
,
info
, debug
, vomit
.
--version
Displays the tool name and version.
The implosion of parse trees by implode-asfix uses the
cons
annotation of SDF productions. For
instance, the following annotation are typical for a small
expression language.
module Exp exports context-free start-symbols Exp sorts Id IntConst Exp lexical syntax [\ \t\n] -> LAYOUT [a-zA-Z]+ -> Id [0-9]+ -> IntConst context-free syntax Id -> Exp {cons("Var")} IntConst -> Exp {cons("Int")} Exp "*" Exp -> Exp {left, cons("Mul")} Exp "/" Exp -> Exp {left, cons("Div")} Exp "%" Exp -> Exp {left, cons("Mod")} Exp "+" Exp -> Exp {left, cons("Plus")} Exp "-" Exp -> Exp {left, cons("Minus")} context-free priorities {left: Exp "*" Exp -> Exp Exp "/" Exp -> Exp Exp "%" Exp -> Exp } > {left: Exp "+" Exp -> Exp Exp "-" Exp -> Exp }
Invoking sglr followed by implode-asfix results in an abstract syntax tree.
$
echo "1 + 2 * 3" | sglr -2 -p Exp.def.tbl | implode-asfix
Plus(Int("1"),Mul(Int("2"),Int("3")))
Copyright (C) 2002-2005 Eelco Visser <visser@acm.org>
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.