Nearly CC
An educational compiler skeleton
ast.h
Go to the documentation of this file.
1 // Copyright (c) 2021-2023, David H. Hovemeyer <david.hovemeyer@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 // OTHER DEALINGS IN THE SOFTWARE.
20 
21 #ifndef AST_H
22 #define AST_H
23 
24 #include "grammar_symbols.h"
25 #include "treeprint.h"
26 class Node;
27 
30 
32 enum ASTNodeTag {
33  AST_UNIT = 10000,
34  AST_VARIABLE_DECLARATION,
35  AST_STRUCT_TYPE,
36  AST_UNION_TYPE,
37  AST_BASIC_TYPE,
38  AST_DECLARATOR_LIST,
39  AST_NAMED_DECLARATOR,
40  AST_POINTER_DECLARATOR,
41  AST_ARRAY_DECLARATOR,
42  AST_FUNCTION_DEFINITION,
43  AST_FUNCTION_DECLARATION,
44  AST_FUNCTION_PARAMETER_LIST,
45  AST_FUNCTION_PARAMETER,
46  AST_STATEMENT_LIST,
47  AST_EMPTY_STATEMENT,
48  AST_EXPRESSION_STATEMENT,
49  AST_RETURN_STATEMENT,
50  AST_RETURN_EXPRESSION_STATEMENT,
51  AST_WHILE_STATEMENT,
52  AST_DO_WHILE_STATEMENT,
53  AST_FOR_STATEMENT,
54  AST_IF_STATEMENT,
55  AST_IF_ELSE_STATEMENT,
56  AST_STRUCT_TYPE_DEFINITION,
57  AST_UNION_TYPE_DEFINITION,
58  AST_FIELD_DEFINITION_LIST,
59  AST_BINARY_EXPRESSION,
60  AST_UNARY_EXPRESSION,
61  AST_POSTFIX_EXPRESSION, // like AST_UNARY_EXPRESSION, but for postfix operators
62  AST_CONDITIONAL_EXPRESSION,
63  AST_CAST_EXPRESSION,
64  AST_FUNCTION_CALL_EXPRESSION,
65  AST_FIELD_REF_EXPRESSION,
66  AST_INDIRECT_FIELD_REF_EXPRESSION,
67  AST_ARRAY_ELEMENT_REF_EXPRESSION,
68  AST_ARGUMENT_EXPRESSION_LIST,
69  AST_VARIABLE_REF,
70  AST_LITERAL_VALUE,
71  AST_IMPLICIT_CONVERSION, // semantic analysis can add these to mark locations of implicit type conversions
72 };
73 
75 class ASTTreePrint : public ParseTreePrint {
76 public:
77  ASTTreePrint();
78  virtual ~ASTTreePrint();
79 
80  virtual std::string node_tag_to_string(int tag) const;
81 };
82 
83 
84 #endif // AST_H
ASTNodeTag
Enumeration type providing tag values for AST nodes.
Definition: ast.h:32
Support for printing a text representation of an AST.
Definition: ast.h:75
virtual std::string node_tag_to_string(int tag) const
Override to convert a parse node's tag to a string.
Definition: ast.cpp:11
Definition: node.h:35
Print a parse tree.
Definition: grammar_symbols.h:146
This header defines the GrammarSymbol enumeration, which defines members for each symbol (terminal an...