-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseparser.h
93 lines (67 loc) · 2.01 KB
/
baseparser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#ifndef __BASEPARSER_H
#define __BASEPARSER_H
#include <stdio.h>
#include <assert.h>
#include <string>
#include <map>
#include <memory>
#include <vector>
#include <list>
#include "lexer.h"
#include "symboltable.h"
#define SMALL_BUFFER 512
//
class BaseParser
{
public:
bool yydebug = false;
FILE *yyout = stdout;
FILE *yyhout = stdout;
protected:
// the lexical analyzer
std::unique_ptr<LexicalAnalyzer> m_lexer;
// the value filled in by the lexical analyzer
YYSTYPE yylval;
// next token in the parse stream
int lookahead;
// total error count
unsigned m_errorCount;
// total warning count
unsigned m_warningCount;
// our symbol table
std::unique_ptr<SymbolTable> m_pSymbolTable;
std::string outputFileName;
public:
BaseParser(std::unique_ptr<SymbolTable> symbolTable);
virtual ~BaseParser();
unsigned getErrorCount() const { return m_errorCount; }
unsigned getWarningCount() const { return m_warningCount; }
void addWarningCount(int count) { m_warningCount += count; }
virtual int reportUnreferencedSymbols() const { return m_pSymbolTable->dumpUnreferencedSymbolsAtCurrentLevel(); }
virtual int parseFile(const char *filename);
virtual int parseData(char *textToParse, const char *fileName, void *pUserData);
virtual int yyparse();
virtual void yyerror(const char *fmt, ...);
virtual void yyerror(const Position &pos, const char *fmt, ...);
virtual void yywarning(const char *fmt, ...);
virtual void yywarning(const Position &pos, const char *fmt, ...);
virtual void yylog(const char *fmt, ...);
virtual void expected(int token);
virtual int match(int token);
virtual int match() { return match(lookahead); }
void setFileName(std::string &str)
{
outputFileName = str;
}
// these methods delegate their work to the symbol table object
SymbolEntry *installSymbol(char *lexeme, SymbolType st = stUndef)
{
return m_pSymbolTable->install(lexeme, st);
}
SymbolEntry *lookupSymbol(char *lexeme)
{
return m_pSymbolTable->lookup(lexeme);
}
};
#endif //__BASEPARSER_H