lexer working with pcre, not building any objects for handling tokens yet
This commit is contained in:
parent
25888fe55a
commit
96010ea9ae
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ tags
|
|||||||
tmpl.*
|
tmpl.*
|
||||||
tests/*/itest.cc
|
tests/*/itest.cc
|
||||||
tests/*/itest.h
|
tests/*/itest.h
|
||||||
|
tests/*/test
|
||||||
|
@ -6,7 +6,7 @@ LDFLAGS := -lpcre
|
|||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
$(TARGET):
|
$(TARGET): $(shell which imbecile)
|
||||||
imbecile $(I_SOURCE).I
|
imbecile $(I_SOURCE).I
|
||||||
$(CXX) -o $@ *.cc $(LDFLAGS)
|
$(CXX) -o $@ *.cc $(LDFLAGS)
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
|
||||||
[tokens]
|
[tokens]
|
||||||
|
|
||||||
ASSIGN :=
|
AND and
|
||||||
DASSIGN :==
|
OR or
|
||||||
IDENTIFIER [a-zA-Z_][a-zA-Z_0-9]*
|
NOT not
|
||||||
|
LPAREN \(
|
||||||
|
RPAREN \)
|
||||||
|
WS \s+
|
||||||
|
EQUALS =
|
||||||
|
IDENTIFIER [a-zA-Z_][a-zA-Z_0-9]*
|
||||||
|
|
||||||
[rules]
|
[rules]
|
||||||
|
|
||||||
|
16
tests/build/main.cc
Normal file
16
tests/build/main.cc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "itest.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
Parser p;
|
||||||
|
stringstream t(string(
|
||||||
|
"hi there (one and two and three and four) or (two = nine)"
|
||||||
|
));
|
||||||
|
p.parse(t);
|
||||||
|
}
|
@ -88,7 +88,7 @@ bool I_CLASSNAME::parse(istream & i)
|
|||||||
while (buff_pos < buff_size)
|
while (buff_pos < buff_size)
|
||||||
{
|
{
|
||||||
int longest_match_length = 0;
|
int longest_match_length = 0;
|
||||||
int longest_match_index;
|
int longest_match_index = -1;
|
||||||
int longest_match_ovector[ovector_size];
|
int longest_match_ovector[ovector_size];
|
||||||
for (int i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
|
for (int i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
|
||||||
{
|
{
|
||||||
@ -108,6 +108,16 @@ bool I_CLASSNAME::parse(istream & i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (longest_match_index >= 0)
|
||||||
|
{
|
||||||
|
cout << "Matched a " << tokens[longest_match_index].name << endl;
|
||||||
|
buff_pos += longest_match_length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* no pattern matched the input at the current position */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user