📄 ast.cc
字号:
/* File: ast.cc * ------------ */#include "ast.h"#include "ast_type.h"#include "ast_decl.h"#include <string.h> // strdup#include <stdio.h> // printfNode::Node(yyltype loc) { location = new yyltype(loc); parent = NULL;}Node::Node() { location = NULL; parent = NULL;}/* The Print method is used to print the parse tree nodes. * If this node has a location (most nodes do, but some do not), it * will first print the line number to help you match the parse tree * back to the source text. It then indents the proper number of levels * and prints the "print name" of the node. It then will invoke the * virtual function PrintChildren which is expected to print the * internals of the node (itself & children) as appropriate. */void Node::Print(int indentLevel, const char *label) { const int numSpaces = 3; printf("\n"); if (GetLocation()) printf("%*d", numSpaces, GetLocation()->first_line); else printf("%*s", numSpaces, ""); printf("%*s%s%s: ", indentLevel*numSpaces, "", label? label : "", GetPrintNameForNode()); PrintChildren(indentLevel);} Identifier::Identifier(yyltype loc, const char *n) : Node(loc) { name = strdup(n);} void Identifier::PrintChildren(int indentLevel) { printf("%s", name);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -