further merging of pesco's and aegis' changes
This commit is contained in:
parent
1c7e9947a4
commit
3978266651
5 changed files with 71 additions and 83 deletions
23
README.md
23
README.md
|
|
@ -11,24 +11,25 @@ Features
|
|||
* Benchmarking for parsing backends -- determine empirically which backend will be most time-efficient for your grammar
|
||||
* Parsing backends:
|
||||
* Packrat parsing
|
||||
* LL(k) (not yet implemented)
|
||||
* LL(k)
|
||||
* GLR (not yet implemented)
|
||||
* LALR(8) (not yet implemented)
|
||||
* Regular expressions (not yet implemented)
|
||||
* Language bindings: (not yet implemented)
|
||||
* C++
|
||||
* Regular expressions
|
||||
* Language bindings:
|
||||
* C++ (not yet implemented)
|
||||
* Java
|
||||
* Python
|
||||
* Ruby
|
||||
* Perl
|
||||
* Go
|
||||
* PHP
|
||||
* .NET
|
||||
* Python (not yet implemented)
|
||||
* Ruby (not yet implemented)
|
||||
* Perl (not yet implemented)
|
||||
* Go (not yet implemented)
|
||||
* PHP (not yet implemented)
|
||||
* .NET (not yet implemented)
|
||||
|
||||
Installing
|
||||
==========
|
||||
### Prerequisites
|
||||
* make
|
||||
* a JDK
|
||||
|
||||
### Optional Dependencies
|
||||
* pkg-config (for `make test`)
|
||||
|
|
@ -37,6 +38,8 @@ Installing
|
|||
|
||||
To install, type `make`. To run the built-in test suite, type `make test`.
|
||||
|
||||
If jni.h and jni_md.h aren't already somewhere on your include path, prepend `C_INCLUDE_PATH=/path/to/jdk/include` to that.
|
||||
|
||||
There is not currently a `make install` target; to make Hammer available system-wide, copy `libhammer.a` to `/usr/lib/` (or `/usr/local/lib/`, or wherever ld will find it) and `hammer.h` to `/usr/include/`.
|
||||
|
||||
Usage
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ HAMMER_PARTS := \
|
|||
system_allocator.o \
|
||||
benchmark.o \
|
||||
cfgrammar.o \
|
||||
actions.o \
|
||||
compile.o \
|
||||
glue.o \
|
||||
$(PARSERS:%=parsers/%.o) \
|
||||
$(BACKENDS:%=backends/%.o)
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
// XXX to be consolidated with glue.c when merged upstream
|
||||
|
||||
#include <assert.h>
|
||||
#include "hammer.h"
|
||||
#include "internal.h"
|
||||
#include "parsers/parser_internal.h"
|
||||
|
||||
|
||||
const HParsedToken *h_act_first(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[0];
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_second(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[1];
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_last(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[p->ast->seq->used-1];
|
||||
}
|
||||
|
||||
static void act_flatten_(HCountedArray *seq, const HParsedToken *tok) {
|
||||
if(tok == NULL) {
|
||||
return;
|
||||
} else if(tok->token_type == TT_SEQUENCE) {
|
||||
size_t i;
|
||||
for(i=0; i<tok->seq->used; i++)
|
||||
act_flatten_(seq, tok->seq->elements[i]);
|
||||
} else {
|
||||
h_carray_append(seq, (HParsedToken *)tok);
|
||||
}
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_flatten(const HParseResult *p) {
|
||||
HCountedArray *seq = h_carray_new(p->arena);
|
||||
|
||||
act_flatten_(seq, p->ast);
|
||||
|
||||
HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
|
||||
res->token_type = TT_SEQUENCE;
|
||||
res->seq = seq;
|
||||
res->index = p->ast->index;
|
||||
res->bit_offset = p->ast->bit_offset;
|
||||
return res;
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_ignore(const HParseResult *p) {
|
||||
return NULL;
|
||||
}
|
||||
64
src/glue.c
64
src/glue.c
|
|
@ -1,12 +1,8 @@
|
|||
#include <assert.h>
|
||||
#include "glue.h"
|
||||
#include "../src/internal.h" // for h_carray_*
|
||||
|
||||
|
||||
// The action equivalent of h_ignore.
|
||||
const HParsedToken *h_act_ignore(const HParseResult *p)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#include "hammer.h"
|
||||
#include "internal.h" // for h_carray_*
|
||||
#include "parsers/parser_internal.h"
|
||||
|
||||
// Helper to build HAction's that pick one index out of a sequence.
|
||||
const HParsedToken *h_act_index(int i, const HParseResult *p)
|
||||
|
|
@ -27,9 +23,57 @@ const HParsedToken *h_act_index(int i, const HParseResult *p)
|
|||
return tok->seq->elements[i];
|
||||
}
|
||||
|
||||
// Action version of h_seq_flatten.
|
||||
const HParsedToken *h_act_first(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[0];
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_second(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[1];
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_last(const HParseResult *p) {
|
||||
assert(p->ast);
|
||||
assert(p->ast->token_type == TT_SEQUENCE);
|
||||
assert(p->ast->seq->used > 0);
|
||||
|
||||
return p->ast->seq->elements[p->ast->seq->used-1];
|
||||
}
|
||||
|
||||
static void act_flatten_(HCountedArray *seq, const HParsedToken *tok) {
|
||||
if(tok == NULL) {
|
||||
return;
|
||||
} else if(tok->token_type == TT_SEQUENCE) {
|
||||
size_t i;
|
||||
for(i=0; i<tok->seq->used; i++)
|
||||
act_flatten_(seq, tok->seq->elements[i]);
|
||||
} else {
|
||||
h_carray_append(seq, (HParsedToken *)tok);
|
||||
}
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_flatten(const HParseResult *p) {
|
||||
return h_seq_flatten(p->arena, p->ast);
|
||||
HCountedArray *seq = h_carray_new(p->arena);
|
||||
|
||||
act_flatten_(seq, p->ast);
|
||||
|
||||
HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
|
||||
res->token_type = TT_SEQUENCE;
|
||||
res->seq = seq;
|
||||
res->index = p->ast->index;
|
||||
res->bit_offset = p->ast->bit_offset;
|
||||
return res;
|
||||
}
|
||||
|
||||
const HParsedToken *h_act_ignore(const HParseResult *p) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Low-level helper for the h_make family.
|
||||
|
|
|
|||
|
|
@ -88,9 +88,12 @@
|
|||
// action such as h_act_index.
|
||||
//
|
||||
|
||||
const HParsedToken *h_act_ignore(const HParseResult *p);
|
||||
const HParsedToken *h_act_index(int i, const HParseResult *p);
|
||||
const HParsedToken *h_act_first(const HParseResult *p);
|
||||
const HParsedToken *h_act_second(const HParseResult *p);
|
||||
const HParsedToken *h_act_last(const HParseResult *p);
|
||||
const HParsedToken *h_act_flatten(const HParseResult *p);
|
||||
const HParsedToken *h_act_ignore(const HParseResult *p);
|
||||
|
||||
// Define 'myaction' as a specialization of 'paction' by supplying the leading
|
||||
// parameters.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue