mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 01:06:54 +08:00
Adding my oop parser test to svn. Looks promising so far, but still very young
This commit is contained in:
parent
32edcf170d
commit
f4efd62e65
11
chaioop/CMakeLists.txt
Normal file
11
chaioop/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
|
||||||
|
project(chaioop)
|
||||||
|
|
||||||
|
SET (CMAKE_BUILD_TYPE gdb)
|
||||||
|
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
|
||||||
|
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
|
||||||
|
|
||||||
|
include_directories(../langkit ../dispatchkit)
|
||||||
|
|
||||||
|
add_executable(chaioop_test main.cpp)
|
||||||
74
chaioop/main.cpp
Normal file
74
chaioop/main.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace langkit {
|
||||||
|
class Token {
|
||||||
|
std::string text;
|
||||||
|
|
||||||
|
std::vector<Token> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Parser {
|
||||||
|
std::string::iterator input_pos, input_end;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool Int() {
|
||||||
|
bool retval = false;
|
||||||
|
if ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
|
||||||
|
retval = true;
|
||||||
|
while ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
|
||||||
|
++input_pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Id() {
|
||||||
|
bool retval = false;
|
||||||
|
if ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || ((*input_pos >= 'a') && (*input_pos <= 'z')))) {
|
||||||
|
retval = true;
|
||||||
|
while ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || ((*input_pos >= 'a') && (*input_pos <= 'z')))) {
|
||||||
|
++input_pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Char(char c) {
|
||||||
|
bool retval = false;
|
||||||
|
if ((input_pos != input_end) && (*input_pos == c)) {
|
||||||
|
++input_pos;
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Arg_List() {
|
||||||
|
bool retval = Id() || Int();
|
||||||
|
while (retval && Char(',')) {
|
||||||
|
retval = Id() || Int();
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parse(std::string input) {
|
||||||
|
input_pos = input.begin();
|
||||||
|
input_end = input.end();
|
||||||
|
|
||||||
|
return Id() && Char('(') && Arg_List() && Char(')');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
langkit::Parser parser;
|
||||||
|
|
||||||
|
std::cout << "Hello, world" << std::endl;
|
||||||
|
|
||||||
|
std::cout << parser.parse("e(x,10)") << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user