1grammar::me::util(n) Grammar operations and usage grammar::me::util(n)
2
3
4
5______________________________________________________________________________
6
8 grammar::me::util - AST utilities
9
11 package require Tcl 8.4
12
13 package require grammar::me::util ?0.1?
14
15 ::grammar::me::util::ast2tree ast tree ?root?
16
17 ::grammar::me::util::ast2etree ast mcmd tree ?root?
18
19 mcmd lc location
20
21 mcmd tok from ?to?
22
23 ::grammar::me::util::tree2ast tree ?root?
24
25_________________________________________________________________
26
28 This package provides a number of utility command for the conversion
29 between the various representations of abstract syntax trees as speci‐
30 fied in the document grammar::me_ast.
31
32 ::grammar::me::util::ast2tree ast tree ?root?
33 This command converts an ast from value to object representa‐
34 tion. All nodes in the ast will be converted into nodes of this
35 tree, with the root of the AST a child of the node root. If this
36 node is not explicitly specified the root of the tree is used.
37 Existing content of tree is not touched, i.e. neither removed
38 nor changed, with the exception of the specified root node,
39 which will gain a new child.
40
41 ::grammar::me::util::ast2etree ast mcmd tree ?root?
42 This command is like ::grammar::me::util::ast2tree, except that
43 the result is in the extended object representation of the input
44 AST. The source of the extended information is the command pre‐
45 fix mcmd. It has to understand two methods, lc, and tok, with
46 the semantics specified below.
47
48 mcmd lc location
49 Takes the location of a token given as offset in the
50 input stream and return a 2-element list containing the
51 associated line number and column index, in this order.
52
53 mcmd tok from ?to?
54 Takes one or two locations from and to as offset in the
55 input stream and returns a Tcl list containing the speci‐
56 fied part of the input stream. Both location are inclu‐
57 sive. If to is not specified it will default to the value
58 of from.
59
60 Each element of the returned list is a list containing
61 the token, its associated lexeme, the line number, and
62 column index, in this order.
63
64 Both the ensemble command ::grammar::me::tcl provided by the package
65 grammar::me::tcl and the objects command created by the package ::gram‐
66 mar::me::cpu fit the above specification.
67
68 ::grammar::me::util::tree2ast tree ?root?
69 This command converts an ast in (extended) object representation
70 into a value and returns it. If a root node is specified the
71 AST is generated from that node downward. Otherwise the root of
72 the tree object is used as the starting point.
73
75 abstract syntax tree, syntax tree, tree
76
78 Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>
79
80
81
82
83grammar_me 0.1 grammar::me::util(n)