From 2ce73ca1d5b47d314f9cba2742540dbc840ff3a7 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Mon, 10 Jan 2011 00:24:25 -0500 Subject: [PATCH] Action names --- parse.cpp | 3 ++ parseraction.hpp | 66 ++++++++++++++++++++++++++++++++++---------- parserstate.cpp | 9 ++++-- parserstate.hpp | 2 +- parsertransition.hpp | 10 +++++-- 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/parse.cpp b/parse.cpp index 9470395..d130abe 100644 --- a/parse.cpp +++ b/parse.cpp @@ -1,4 +1,5 @@ #include +#include #include "parser.hpp" @@ -12,5 +13,7 @@ int main( void ) b = parser.input( 'y' ); c = parser.input( 'z' ); + std::cout << a[0].name; + return 0; } diff --git a/parseraction.hpp b/parseraction.hpp index 244d294..c327ecd 100644 --- a/parseraction.hpp +++ b/parseraction.hpp @@ -1,27 +1,63 @@ #ifndef PARSERACTION_HPP #define PARSERACTION_HPP +#include + namespace Parser { class Action { public: - virtual ~Action() {} + bool char_present; + wchar_t ch; + + std::string name; + + Action() : char_present( false ), ch( -1 ), name( "" ) {} + virtual ~Action() {}; }; - class Ignore : public Action {}; - class Print : public Action {}; - class Execute : public Action {}; - class Clear : public Action {}; - class Collect : public Action {}; - class Param : public Action {}; - class Esc_Dispatch : public Action {}; - class CSI_Dispatch : public Action {}; - class Hook : public Action {}; - class Put : public Action {}; - class Unhook : public Action {}; - class OSC_Start : public Action {}; - class OSC_Put : public Action {}; - class OSC_End : public Action {}; + class Ignore : public Action { + public: Ignore() { name = "Ignore"; } + }; + class Print : public Action { + public: Print() { name = "Print"; } + }; + class Execute : public Action { + public: Execute() { name = "Execute"; } + }; + class Clear : public Action { + public: Clear() { name = "Clear"; } + }; + class Collect : public Action { + public: Collect() { name = "Collect"; } + }; + class Param : public Action { + public: Param() { name = "Param"; } + }; + class Esc_Dispatch : public Action { + public: Esc_Dispatch() { name = "Esc_Dispatch"; } + }; + class CSI_Dispatch : public Action { + public: CSI_Dispatch() { name = "CSI_Dispatch"; } + }; + class Hook : public Action { + public: Hook() { name = "Hook"; } + }; + class Put : public Action { + public: Put() { name = "Put"; } + }; + class Unhook : public Action { + public: Unhook() { name = "Unhook"; } + }; + class OSC_Start : public Action { + public: OSC_Start() { name = "OSC_Start"; } + }; + class OSC_Put : public Action { + public: OSC_Put() { name = "OSC_Put"; } + }; + class OSC_End : public Action { + public: OSC_End() { name = "OSC_End"; } + }; } #endif diff --git a/parserstate.cpp b/parserstate.cpp index f8953df..f613537 100644 --- a/parserstate.cpp +++ b/parserstate.cpp @@ -34,11 +34,16 @@ Transition State::input( wchar_t ch ) return any; } + Transition ret; + if ( ch >= 0xA0 ) { - return this->input_state_rule( 0x41 ); + ret = this->input_state_rule( 0x41 ); + } else { + ret = this->input_state_rule( ch ); } - return this->input_state_rule( ch ); + ret.action.ch = ch; + return ret; } static bool C0_prime( wchar_t ch ) diff --git a/parserstate.hpp b/parserstate.hpp index 6991648..3475062 100644 --- a/parserstate.hpp +++ b/parserstate.hpp @@ -25,7 +25,7 @@ namespace Parser { virtual ~State() {}; State( const State & ); - bool operator=( const State & ); + State & operator=( const State & ); }; class Ground : public State { diff --git a/parsertransition.hpp b/parsertransition.hpp index 272afb3..e62bcf7 100644 --- a/parsertransition.hpp +++ b/parsertransition.hpp @@ -17,10 +17,16 @@ namespace Parser { Transition( const Transition &x ) : action( x.action ), next_state( x.next_state ) {} - bool operator=( const Transition & ); + Transition & operator=( const Transition &t ) + { + action = t.action; + next_state = t.next_state; + + return *this; + } virtual ~Transition() {} - Transition( Action s_action, State *s_next_state ) + Transition( Action s_action=Ignore(), State *s_next_state=NULL ) : action( s_action ), next_state( s_next_state ) {} };