]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Updated AST to create a node directly from a token (for literals like numbers)
authorMike D. Lowis <mike@mdlowis.com>
Thu, 3 May 2012 19:17:30 +0000 (15:17 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Thu, 3 May 2012 19:17:30 +0000 (15:17 -0400)
source/parser/ast/ast.cpp
source/parser/ast/ast.h

index 4f3a9938b44a3bbdb1a4f0898f96bf72a692a519..9be1c15b1d0af19d6df371b7bc1706be2247ff2d 100644 (file)
@@ -12,6 +12,13 @@ AST::AST(ASTNodeType type)
     node_children = new list<AST*>();
 }
 
+AST::AST(Token tok)
+{
+    node_type = tok.type();
+    node_text = tok.text();
+    node_children = new list<AST*>();
+}
+
 AST::AST(ASTNodeType type, const char* text)
 {
     node_type = type;
index abce052aaa3a334f251e29b49f2643f8783b2237..5e894428e29c652732cd23d99738e5712377a442 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <list>
 #include <string>
+#include "token.h"
 
 typedef unsigned int ASTNodeType;
 
@@ -15,6 +16,7 @@ class AST
         std::list<AST*>* 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, ...);