1grammar::me::util(n)     Grammar operations and usage     grammar::me::util(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       grammar::me::util - AST utilities
9

SYNOPSIS

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

DESCRIPTION

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

BUGS, IDEAS, FEEDBACK

75       This document, and the package it describes, will  undoubtedly  contain
76       bugs and other problems.  Please report such in the category grammar_me
77       of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].   Please
78       also  report any ideas for enhancements you may have for either package
79       and/or documentation.
80
81       When proposing code changes, please provide unified diffs, i.e the out‐
82       put of diff -u.
83
84       Note  further  that  attachments  are  strongly  preferred over inlined
85       patches. Attachments can be made by going  to  the  Edit  form  of  the
86       ticket  immediately  after  its  creation, and then using the left-most
87       button in the secondary navigation bar.
88

KEYWORDS

90       abstract syntax tree, syntax tree, tree
91

CATEGORY

93       Grammars and finite automata
94
96       Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>
97
98
99
100
101tcllib                                0.1                 grammar::me::util(n)
Impressum