2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-08-31 18:04:51 +00:00
|
|
|
#ifndef ForthParser_DEFINED
|
|
|
|
#define ForthParser_DEFINED
|
|
|
|
|
|
|
|
#include "SkTDict.h"
|
2009-09-02 02:07:32 +00:00
|
|
|
//#include "SkString.h"
|
2009-08-31 18:04:51 +00:00
|
|
|
|
|
|
|
class ForthWord;
|
|
|
|
class FCode;
|
|
|
|
|
|
|
|
class ForthParser {
|
|
|
|
public:
|
|
|
|
ForthParser();
|
|
|
|
~ForthParser();
|
|
|
|
|
|
|
|
const char* parse(const char text[], FCode*);
|
|
|
|
|
|
|
|
void addWord(const char name[], ForthWord* word) {
|
|
|
|
this->add(name, strlen(name), word);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const char name[], size_t len, ForthWord* word) {
|
2009-09-02 02:07:32 +00:00
|
|
|
// SkString str(name, len);
|
|
|
|
// SkDebugf("add %s %p\n", str.c_str(), word);
|
2011-05-31 15:35:54 +00:00
|
|
|
SkDEBUGCODE(bool isNewWord = )fDict.set(name, len, word);
|
|
|
|
SkASSERT(isNewWord);
|
2009-08-31 18:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ForthWord* find(const char name[], size_t len) const {
|
|
|
|
ForthWord* word;
|
|
|
|
return fDict.find(name, len, &word) ? word : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void addStdWords();
|
|
|
|
|
|
|
|
SkTDict<ForthWord*> fDict;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|