Implemented parser
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
source = parse.cpp parserstate.cpp
|
||||
objects = parserstate.o
|
||||
source = parse.cpp parserstate.cpp parser.cpp templates.cpp
|
||||
objects = parserstate.o parser.o templates.o
|
||||
executables = parse
|
||||
|
||||
CPP = g++
|
||||
@@ -11,6 +11,9 @@ all: $(executables)
|
||||
parse: parse.o $(objects)
|
||||
$(CPP) $(CPPFLAGS) -o $@ $+ $(LIBS)
|
||||
|
||||
templates.o: templates.cpp
|
||||
$(CPP) $(CPPFLAGS) -frepo -c -o $@ $<
|
||||
|
||||
%.o: %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
#include <vector>
|
||||
|
||||
#include "parser.hpp"
|
||||
|
||||
int main( void )
|
||||
{
|
||||
Parser::Parser parser;
|
||||
|
||||
std::vector<Parser::Action> a, b, c;
|
||||
|
||||
a = parser.input( 'x' );
|
||||
b = parser.input( 'y' );
|
||||
c = parser.input( 'z' );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#include "parser.hpp"
|
||||
|
||||
std::vector<Parser::Action> Parser::Parser::input( wchar_t ch )
|
||||
{
|
||||
std::vector<Action> ret;
|
||||
|
||||
Transition tx = state->input( ch );
|
||||
|
||||
if ( tx.next_state != NULL ) {
|
||||
ret.push_back( state->exit() );
|
||||
}
|
||||
|
||||
ret.push_back( tx.action );
|
||||
|
||||
if ( tx.next_state != NULL ) {
|
||||
ret.push_back( tx.next_state->enter() );
|
||||
state = tx.next_state;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
+5
-2
@@ -2,6 +2,7 @@
|
||||
#define PARSE_HPP
|
||||
|
||||
#include <wchar.h>
|
||||
#include <vector>
|
||||
|
||||
#include "parsertransition.hpp"
|
||||
#include "parseraction.hpp"
|
||||
@@ -15,11 +16,13 @@ namespace Parser {
|
||||
State *state;
|
||||
|
||||
public:
|
||||
Parser() : family(), state( NULL ) {}
|
||||
Parser() : family(), state( &family.s_Ground ) {}
|
||||
|
||||
Parser( const Parser & );
|
||||
bool operator=( const Parser & );
|
||||
void input( wchar_t c ); /* should return list of actions */
|
||||
~Parser() {}
|
||||
|
||||
std::vector<Action> input( wchar_t c );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -13,14 +13,13 @@ namespace Parser {
|
||||
StateFamily *family;
|
||||
|
||||
private:
|
||||
virtual Action enter( void ) { return Ignore(); };
|
||||
virtual Action exit( void ) { return Ignore(); };
|
||||
|
||||
Transition input( wchar_t ch );
|
||||
Transition anywhere_rule( wchar_t ch );
|
||||
|
||||
public:
|
||||
void setfamily( StateFamily *s_family ) { family = s_family; }
|
||||
Transition input( wchar_t ch );
|
||||
virtual Action enter( void ) { return Ignore(); };
|
||||
virtual Action exit( void ) { return Ignore(); };
|
||||
|
||||
State() : family( NULL ) {};
|
||||
virtual ~State() {};
|
||||
|
||||
Reference in New Issue
Block a user