]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/ParseTreeWalker.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / tree / ParseTreeWalker.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include "antlr4-common.h"
9
10 namespace antlr4 {
11 namespace tree {
12
13   class ANTLR4CPP_PUBLIC ParseTreeWalker {
14   public:
15     static ParseTreeWalker &DEFAULT;
16
17     virtual ~ParseTreeWalker();
18     
19     /**
20     * <summary>
21     * Performs a walk on the given parse tree starting at the root and going down recursively
22         * with depth-first search. On each node, <seealso cref="ParseTreeWalker#enterRule"/> is called before
23     * recursively walking down into child nodes, then
24     * <seealso cref="ParseTreeWalker#exitRule"/> is called after the recursive call to wind up.
25         * </summary>
26     * <param name='listener'> The listener used by the walker to process grammar rules </param>
27         * <param name='t'> The parse tree to be walked on </param>
28     */
29     virtual void walk(ParseTreeListener *listener, ParseTree *t) const;
30
31   protected:
32     
33     /**
34     * <summary>
35     * Enters a grammar rule by first triggering the generic event <seealso cref="ParseTreeListener#enterEveryRule"/>
36         * then by triggering the event specific to the given parse tree node
37         * </summary>
38     * <param name='listener'> The listener responding to the trigger events </param>
39         * <param name='r'> The grammar rule containing the rule context </param>
40     */
41     virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const;
42     
43     /**
44     * <summary>
45     * Exits a grammar rule by first triggering the event specific to the given parse tree node
46         * then by triggering the generic event <seealso cref="ParseTreeListener#exitEveryRule"/>
47         * </summary>
48     * <param name='listener'> The listener responding to the trigger events </param>
49         * <param name='r'> The grammar rule containing the rule context </param>
50     */
51     virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const;
52   };
53
54 } // namespace tree
55 } // namespace antlr4