From ccc3a506dd842503eab21518fb06bab7774b68a6 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 1 Jun 2009 15:26:46 +0000 Subject: [PATCH] A couple touchups to the parser to get the root node to include filename --- langkit/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/langkit/main.cpp b/langkit/main.cpp index fb34846..7802e85 100644 --- a/langkit/main.cpp +++ b/langkit/main.cpp @@ -10,7 +10,7 @@ #include "langkit_lexer.hpp" #include "langkit_parser.hpp" -class TokenType { public: enum Type { Whitespace, Identifier, Number, Operator, Parens_Open, Parens_Close, +class TokenType { public: enum Type { File, Whitespace, Identifier, Number, Operator, Parens_Open, Parens_Close, Square_Open, Square_Close, Curly_Open, Curly_Close, Comma, Quoted_String, Single_Quoted_String, Carriage_Return, Semicolon, Function_Def, Scoped_Block, Statement, Equation, Return, Add, Comment}; }; @@ -48,7 +48,7 @@ std::string load_file(const char *filename) { return ret_val; } -void parse(std::vector &tokens) { +void parse(std::vector &tokens, const char *filename) { /* Rule lhs; @@ -107,7 +107,7 @@ void parse(std::vector &tokens) { */ Token_Iterator iter = tokens.begin(), end = tokens.end(); - TokenPtr parent(new Token("Root", 0, "test")); + TokenPtr parent(new Token("Root", TokenType::File, filename)); std::pair results = rule(iter, end, parent); @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) { while (input != "quit") { std::vector tokens = lexer.lex(input, "INPUT"); debug_print(tokens); - parse(tokens); + parse(tokens, "INPUT"); std::cout << "Expression> "; std::getline(std::cin, input); @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) { } else { std::vector tokens = lexer.lex(load_file(argv[1]), argv[1]); - parse(tokens); + parse(tokens, argv[1]); //debug_print(tokens); } }