]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Refactored dllexer
authorMike D. Lowis <mike@mdlowis.com>
Sun, 26 Feb 2012 20:09:42 +0000 (15:09 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Sun, 26 Feb 2012 20:09:42 +0000 (15:09 -0500)
source/dllexer/dllexer.cpp
source/dllexer/dllexer.h
source/dlparser/macro/macro.c [deleted file]
source/dlparser/macro/param.c [deleted file]

index 83c9b3acd51b1c8ff5de3d73b3d984194eadfffa..28d10d6b625f7469aa412b89cebed010ec359e37 100644 (file)
@@ -61,8 +61,7 @@ bool DLLexer::isStringChar(void)
 Token DLLexer::next(void)
 {
     Token ret;
-    Token* temp = NULL;
-    while ( (!input->eof()) && (temp == NULL) )
+    while ( (!input->eof()) && (ret.type() != EOF) )
     {
         if (isWhiteSpace())
         {
@@ -74,40 +73,34 @@ Token DLLexer::next(void)
         }
         else if (isLetter())
         {
-            temp = Id();
+            Id(ret);
         }
         else if( isOperator() )
         {
-            temp = MultiCharOp();
+            MultiCharOp(ret);
         }
         else if (isDigit())
         {
-            temp = Number();
+            Number(ret);
         }
         else if(current == '\'')
         {
-            temp = Char();
+            Char(ret);
         }
         else if(current == '"')
         {
-            temp = String();
+            String(ret);
         }
         else if(current == '$')
         {
-            temp = Symbol();
+            Symbol(ret);
         }
         else
         {
-            temp = SingleCharOp();
+            SingleCharOp(ret);
         }
     }
 
-    if(temp !=  NULL)
-    {
-        ret = *(temp);
-        delete temp;
-    }
-
     return ret;
 }
 
@@ -132,7 +125,7 @@ void DLLexer::COMMENT(void)
 
 }
 
-Token* DLLexer::Id(void)
+void DLLexer::Id(Token& tok)
 {
     ostringstream oss;
     do
@@ -141,10 +134,10 @@ Token* DLLexer::Id(void)
         consume();
     }
     while(isLetter() || isDigit() || current == '_');
-    return _new Token(ID, oss.str(), line, column);
+    tok = Token(ID, oss.str(), line, column);
 }
 
-Token* DLLexer::Number(void)
+void DLLexer::Number(Token& tok)
 {
     ostringstream oss;
     do
@@ -156,13 +149,13 @@ Token* DLLexer::Number(void)
 
     if(current == '.')
     {
-        return Decimal(oss);
+        Decimal(tok, oss);
     }
 
-    return _new Token(NUM, oss.str(), line, column);
+    tok = Token(NUM, oss.str(), line, column);
 }
 
-Token* DLLexer::Decimal(ostringstream& oss)
+void DLLexer::Decimal(Token& tok, std::ostringstream& oss)
 {
     oss << current;
     consume();
@@ -181,10 +174,10 @@ Token* DLLexer::Decimal(ostringstream& oss)
     }
     while ( isDigit() );
 
-    return _new Token(NUM, oss.str(), line, column);
+    tok = Token(NUM, oss.str(), line, column);
 }
 
-Token* DLLexer::Char(void)
+void DLLexer::Char(Token& tok)
 {
     ostringstream oss;
 
@@ -202,10 +195,10 @@ Token* DLLexer::Char(void)
     }
     match('\'');
 
-    return _new Token( CHAR, oss.str(), line, column );
+    tok = Token( CHAR, oss.str(), line, column );
 }
 
-Token* DLLexer::String(void)
+void DLLexer::String(Token& tok)
 {
     ostringstream oss;
     match('"');
@@ -215,10 +208,10 @@ Token* DLLexer::String(void)
         consume();
     }
     match('"');
-    return _new Token( STRING, oss.str(), line, column );
+    tok = Token( STRING, oss.str(), line, column );
 }
 
-Token* DLLexer::Symbol(void)
+void DLLexer::Symbol(Token& tok)
 {
     ostringstream oss;
     match('$');
@@ -228,25 +221,24 @@ Token* DLLexer::Symbol(void)
         consume();
     }
     while(isLetter() || isDigit() || current == '_');
-    return _new Token( SYMBOL, oss.str(), line, column );
+    tok = Token( SYMBOL, oss.str(), line, column );
 }
 
-Token* DLLexer::SingleCharOp(void)
+void DLLexer::SingleCharOp(Token& tok)
 {
     for(int i = 0; i < NUM_SINGLE_CHAR_MATCHES; i++)
     {
         if(current == Single_Character_Matches[i].match)
         {
             consume();
-            return _new Token( Single_Character_Matches[i].type, line, column );
+            tok = Token( Single_Character_Matches[i].type, line, column );
         }
     }
     throw Exception(line,column);
 }
 
-Token* DLLexer::MultiCharOp(void)
+void DLLexer::MultiCharOp(Token& tok)
 {
-    Token* tok = NULL;
     // save the current token so we can refer back to it
     char last = current;
     // remove the current token from the buffer so we cna see the next
@@ -257,11 +249,11 @@ Token* DLLexer::MultiCharOp(void)
         if(current == '=')
         {
             consume();
-            tok = _new Token(EQ, line, column);
+            tok = Token(EQ, line, column);
         }
         else
         {
-            tok = _new Token(ASSIGN, line, column);
+            tok = Token(ASSIGN, line, column);
         }
     }
     else if(last == '!')
@@ -269,11 +261,11 @@ Token* DLLexer::MultiCharOp(void)
         if(current == '=')
         {
             consume();
-            tok = _new Token(NE, line, column);
+            tok = Token(NE, line, column);
         }
         else
         {
-            tok = _new Token(NOT, line, column);
+            tok = Token(NOT, line, column);
         }
     }
     else if(last == '<')
@@ -281,11 +273,11 @@ Token* DLLexer::MultiCharOp(void)
         if(current == '=')
         {
             consume();
-            tok = _new Token(LTE, line, column);
+            tok = Token(LTE, line, column);
         }
         else
         {
-            tok = _new Token(LT, line, column);
+            tok = Token(LT, line, column);
         }
     }
     else if(last == '>')
@@ -293,11 +285,11 @@ Token* DLLexer::MultiCharOp(void)
         if(current == '=')
         {
             consume();
-            tok = _new Token(GTE, line, column);
+            tok = Token(GTE, line, column);
         }
         else
         {
-            tok = _new Token(GT, line, column);
+            tok = Token(GT, line, column);
         }
     }
     else if(last == '|')
@@ -305,21 +297,20 @@ Token* DLLexer::MultiCharOp(void)
         if(current == '|')
         {
             consume();
-            tok = _new Token(OR, line, column);
+            tok = Token(OR, line, column);
         }
         else
         {
-            tok = _new Token(PIPE, line, column);
+            tok = Token(PIPE, line, column);
         }
     }
     else if((last == '&') && (current == '&'))
     {
         consume();
-        tok = _new Token(AND, line, column);
+        tok = Token(AND, line, column);
     }
     else
     {
         throw Exception(line,column);
     }
-    return tok;
 }
index e93e7ad40a31741261b57b535b0cadd7858f5f4b..0c3a057c9a451fc29cea47a7f2d72544c519e826 100644 (file)
@@ -68,14 +68,14 @@ class DLLexer : public ILexer {
         void COMMENT(void);
 
         Token next(void);
-        Token* Id(void);
-        Token* Number(void);
-        Token* Decimal(std::ostringstream& oss);
-        Token* Char(void);
-        Token* String(void);
-        Token* Symbol(void);
-        Token* SingleCharOp(void);
-        Token* MultiCharOp(void);
+        void Id(Token& tok);
+        void Number(Token& tok);
+        void Decimal(Token& tok, std::ostringstream& oss);
+        void Char(Token& tok);
+        void String(Token& tok);
+        void Symbol(Token& tok);
+        void SingleCharOp(Token& tok);
+        void MultiCharOp(Token& tok);
 };
 
 
diff --git a/source/dlparser/macro/macro.c b/source/dlparser/macro/macro.c
deleted file mode 100644 (file)
index a01f804..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "macro.h"
-#include "macroapplication.h"
-#include "cork.h"
-
-using namespace std;
-
-Macro::Macro(AST* macro_def)
-{
-    list<AST*>::iterator it = macro_def->children()->begin();
-
-    // Set Name
-    macro_name = (*it++)->text();
-
-    // Set Body
-    setUpParamList( *it++ );
-
-    // Set Params
-    macro_body = (*it++)->clone();
-
-}
-
-Macro::~Macro()
-{
-
-    std::list<Param*>::iterator iter;
-    for (iter = macro_params.begin(); iter != macro_params.end(); ++iter) {
-        delete *iter;
-    }
-    delete macro_body;
-}
-
-const std::string& Macro::name(void)
-{
-    return macro_name;
-}
-
-const std::list<Param*>& Macro::params(void)
-{
-    return macro_params;
-}
-
-AST* Macro::apply(void)
-{
-    MacroApplication application(macro_body->clone(), macro_params);
-    application.visit();
-    return application.getAST()->clone();
-}
-
-void Macro::setUpParamList( AST* param_tree )
-{
-    list<AST*>::iterator it = param_tree->children()->begin();
-    for(; it != param_tree->children()->end(); it++)
-    {
-        macro_params.push_back( _new Param( *it ) );
-    }
-}
-
diff --git a/source/dlparser/macro/param.c b/source/dlparser/macro/param.c
deleted file mode 100644 (file)
index 367c118..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "param.h"
-
-Param::Param(AST* param_def)
-{
-    int children = param_def->children()->size();
-    if( children == 0 )
-    {
-        param_name = param_def->text();
-    }
-    else if( children == 2)
-    {
-        param_name = param_def->children()->front()->text();
-        setType( param_def->children()->front()->text() );
-    }
-    else
-    {
-        // Throw
-    }
-}
-
-Param::~Param()
-{
-    if( param_value != NULL )
-    {
-        delete param_value;
-    }
-}
-
-std::string Param::name(void)
-{
-    return param_name;
-}
-
-ParamType_T Param::type(void)
-{
-    return param_type;
-}
-
-AST* Param::value(void)
-{
-    return param_value;
-}
-
-void Param::setValue(AST* val)
-{
-    param_value = val;
-}
-
-void Param::setType( const std::string& type_string )
-{
-    if ( type_string.compare("Block") == 0 )
-    {
-        param_type = BlockTyp;
-    }
-    else
-    {
-        param_type = ExpTyp;
-    }
-}
-