Home | History | Annotate | Download | only in forth
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #ifndef ForthParser_DEFINED
      9 #define ForthParser_DEFINED
     10 
     11 #include "SkTDict.h"
     12 //#include "SkString.h"
     13 
     14 class ForthWord;
     15 class FCode;
     16 
     17 class ForthParser {
     18 public:
     19     ForthParser();
     20     ~ForthParser();
     21 
     22     const char* parse(const char text[], FCode*);
     23 
     24     void addWord(const char name[], ForthWord* word) {
     25         this->add(name, strlen(name), word);
     26     }
     27 
     28     void add(const char name[], size_t len, ForthWord* word) {
     29     //    SkString str(name, len);
     30     //    SkDebugf("add %s %p\n", str.c_str(), word);
     31         SkDEBUGCODE(bool isNewWord = )fDict.set(name, len, word);
     32         SkASSERT(isNewWord);
     33     }
     34 
     35     ForthWord* find(const char name[], size_t len) const {
     36         ForthWord* word;
     37         return fDict.find(name, len, &word) ? word : NULL;
     38     }
     39 
     40 private:
     41     void addStdWords();
     42 
     43     SkTDict<ForthWord*> fDict;
     44 };
     45 
     46 #endif
     47