From 29f2ff340d11bda28ec37113869644a1fd1b3522 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Thu, 3 May 2012 15:17:30 -0400 Subject: [PATCH] Updated AST to create a node directly from a token (for literals like numbers) --- source/parser/ast/ast.cpp | 7 +++++++ source/parser/ast/ast.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/source/parser/ast/ast.cpp b/source/parser/ast/ast.cpp index 4f3a993..9be1c15 100644 --- a/source/parser/ast/ast.cpp +++ b/source/parser/ast/ast.cpp @@ -12,6 +12,13 @@ AST::AST(ASTNodeType type) node_children = new list(); } +AST::AST(Token tok) +{ + node_type = tok.type(); + node_text = tok.text(); + node_children = new list(); +} + AST::AST(ASTNodeType type, const char* text) { node_type = type; diff --git a/source/parser/ast/ast.h b/source/parser/ast/ast.h index abce052..5e89442 100644 --- a/source/parser/ast/ast.h +++ b/source/parser/ast/ast.h @@ -4,6 +4,7 @@ #include #include #include +#include "token.h" typedef unsigned int ASTNodeType; @@ -15,6 +16,7 @@ class AST std::list* node_children; public: AST(ASTNodeType type); + AST(Token tok); AST(ASTNodeType type, const char* text); AST(ASTNodeType type, std::string text); AST(ASTNodeType type, int child_count, ...); -- 2.52.0