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
#ifndef PARSER_PARSER_H |
|
#define PARSER_PARSER_H |
|
#include <stack> |
|
#include <string> |
|
#include <stdio.h> |
|
|
|
// State of lexical parser (filename and position in file) |
|
struct lexical_state |
|
{ |
|
std::string filename,curdir; |
|
unsigned int inclevel; |
|
unsigned int curline,curpos,curoffset; |
|
}; |
|
|
|
// Container for "static" parameters of lexical parser |
|
struct lexical_extra |
|
{ |
|
std::string includedirs,moduledirs; |
|
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); |
|
} |
|
}; |
|
|
|
// 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 |
|
|
|
#endif
|
|
|