You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
9 years ago
|
#ifndef PARSER_PARSER_H
|
||
|
#define PARSER_PARSER_H
|
||
9 years ago
|
#include <string>
|
||
|
#include <stack>
|
||
|
#include <stdio.h>
|
||
9 years ago
|
|
||
9 years ago
|
// State of lexical parser (filename and position in file)
|
||
9 years ago
|
struct lexical_state
|
||
9 years ago
|
{
|
||
9 years ago
|
std::string filename,curdir;
|
||
|
unsigned int inclevel;
|
||
9 years ago
|
unsigned int curline,curpos,curoffset;
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
// Container for "static" parameters of lexical parser
|
||
9 years ago
|
struct lexical_extra
|
||
|
{
|
||
|
struct lexical_state state;
|
||
|
unsigned int maxinclevel;
|
||
|
int retcode;
|
||
|
std::stack<FILE*> fds;
|
||
|
std::stack<struct lexical_state> states;
|
||
|
~lexical_extra()
|
||
|
{
|
||
|
while(fds.size()!=0) {fclose(fds.top()); fds.pop();} while(states.size()!=0) states.pop();
|
||
|
}
|
||
|
void ParsePath(const std::string& path)
|
||
|
{
|
||
|
// !!!NONPORTABLE!!!
|
||
|
if('/'==path[0]) state.curdir=path.substr(0,path.rfind('/')+1); // absolute path
|
||
|
else if(std::string::npos!=path.rfind('/')) state.curdir+=path.substr(0,path.rfind('/')+1); // relative path
|
||
|
state.filename=path.substr((path.rfind('/')!=std::string::npos)?(path.rfind('/')+1):0,std::string::npos);
|
||
|
}
|
||
|
};
|
||
|
|
||
9 years ago
|
// Bison location
|
||
|
struct grammatic_location
|
||
|
{
|
||
|
int first_line;
|
||
|
int first_column;
|
||
|
int last_line;
|
||
|
int last_column;
|
||
|
std::string filename;
|
||
|
};
|
||
|
|
||
|
#if !defined CONFLTYPE && !defined CONFLTYPE_IS_DECLARED
|
||
|
typedef struct grammatic_location CONFLTYPE;
|
||
|
#define CONFLTYPE_IS_DECLARED 1
|
||
|
#endif
|
||
|
|
||
9 years ago
|
#endif
|