Implemented parser

This commit is contained in:
Keith Winstein
2011-01-09 04:39:51 -05:00
parent 2f70137df0
commit d8ac8c15c2
5 changed files with 42 additions and 8 deletions
+5 -2
View File
@@ -1,5 +1,5 @@
source = parse.cpp parserstate.cpp source = parse.cpp parserstate.cpp parser.cpp templates.cpp
objects = parserstate.o objects = parserstate.o parser.o templates.o
executables = parse executables = parse
CPP = g++ CPP = g++
@@ -11,6 +11,9 @@ all: $(executables)
parse: parse.o $(objects) parse: parse.o $(objects)
$(CPP) $(CPPFLAGS) -o $@ $+ $(LIBS) $(CPP) $(CPPFLAGS) -o $@ $+ $(LIBS)
templates.o: templates.cpp
$(CPP) $(CPPFLAGS) -frepo -c -o $@ $<
%.o: %.cpp %.o: %.cpp
$(CPP) $(CPPFLAGS) -c -o $@ $< $(CPP) $(CPPFLAGS) -c -o $@ $<
+8
View File
@@ -1,8 +1,16 @@
#include <vector>
#include "parser.hpp" #include "parser.hpp"
int main( void ) int main( void )
{ {
Parser::Parser parser; Parser::Parser parser;
std::vector<Parser::Action> a, b, c;
a = parser.input( 'x' );
b = parser.input( 'y' );
c = parser.input( 'z' );
return 0; return 0;
} }
+21
View File
@@ -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
View File
@@ -2,6 +2,7 @@
#define PARSE_HPP #define PARSE_HPP
#include <wchar.h> #include <wchar.h>
#include <vector>
#include "parsertransition.hpp" #include "parsertransition.hpp"
#include "parseraction.hpp" #include "parseraction.hpp"
@@ -15,11 +16,13 @@ namespace Parser {
State *state; State *state;
public: public:
Parser() : family(), state( NULL ) {} Parser() : family(), state( &family.s_Ground ) {}
Parser( const Parser & ); Parser( const Parser & );
bool operator=( const Parser & ); bool operator=( const Parser & );
void input( wchar_t c ); /* should return list of actions */
~Parser() {} ~Parser() {}
std::vector<Action> input( wchar_t c );
}; };
} }
+3 -4
View File
@@ -13,14 +13,13 @@ namespace Parser {
StateFamily *family; StateFamily *family;
private: private:
virtual Action enter( void ) { return Ignore(); };
virtual Action exit( void ) { return Ignore(); };
Transition input( wchar_t ch );
Transition anywhere_rule( wchar_t ch ); Transition anywhere_rule( wchar_t ch );
public: public:
void setfamily( StateFamily *s_family ) { family = s_family; } 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 ) {}; State() : family( NULL ) {};
virtual ~State() {}; virtual ~State() {};