Commit 7b3235e3 authored by Simon Morlat's avatar Simon Morlat

initial commit

parents
This diff is collapsed.
SUBDIRS=src
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([myantlr], [0.0.1], [simon.morlat@linphone.org])
AC_CONFIG_SRCDIR([src/myantlr.hh])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
AC_PROG_LIBTOOL
# Checks for programs.
AC_PROG_CXX
CXXFLAGS="$CXXFLAGS -std=c++11"
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_CONFIG_FILES(
Makefile
src/Makefile
)
AC_OUTPUT
lib_LTLIBRARIES=libmyantlr.la
libmyantlr_la_SOURCES=myantlr.cc myantlr.hh
#include "myantlr.hh"
#include <algorithm>
namespace myantlr{
Recognizer::Recognizer(){
mMatchCount=0;
}
void Recognizer::reset(){
_reset();
mMatchCount=0;
}
ssize_t Recognizer::feed(const string &input, ssize_t pos){
mMatchCount=_feed(input, pos);
return mMatchCount;
}
CharRecognizer::CharRecognizer(char to_recognize) : mToRecognize(to_recognize){
}
void CharRecognizer::_reset(){
}
ssize_t CharRecognizer::_feed(const string &input, ssize_t pos){
return input[pos]==mToRecognize ? 1 : 0;
}
Selector::Selector(){
}
void Selector::addRecognizer(const shared_ptr<Recognizer> &r){
mElements.push_back(r);
}
void Selector::_reset(){
for_each(mElements.begin(),mElements.end(),bind(&Recognizer::reset,placeholders::_1));
}
ssize_t Selector::_feed(const string &input, ssize_t pos){
ssize_t matched=0;
for (auto it=mElements.begin(); it!=mElements.end(); ++it){
matched=(*it)->feed(input, pos);
if (matched>0) break;
}
return matched;
}
}
\ No newline at end of file
#include <list>
#include <memory>
using namespace ::std;
namespace myantlr{
class Recognizer{
public:
void reset();
ssize_t feed(const string &input, ssize_t pos);
protected:
Recognizer();
virtual void _reset()=0;
virtual ssize_t _feed(const string &input, ssize_t pos)=0;
ssize_t mMatchCount;
};
class CharRecognizer : public Recognizer{
public:
CharRecognizer(char to_recognize);
private:
virtual void _reset();
virtual ssize_t _feed(const string &input, ssize_t pos);
const char mToRecognize;
};
class Selector : public Recognizer{
public:
Selector();
void addRecognizer(const shared_ptr<Recognizer> &element);
private:
virtual void _reset();
virtual ssize_t _feed(const string &input, ssize_t pos);
list<shared_ptr<Recognizer>> mElements;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment