-/* $Id: cql.y,v 1.2 2004-03-10 16:34:29 adam Exp $
+/* $Id: cql.y,v 1.7 2004-10-15 00:19:00 adam Exp $
Copyright (C) 2002-2004
Index Data Aps
bison parser for CQL grammar.
*/
%{
+/**
+ * \file cql.c
+ * \brief Implements CQL parser.
+ *
+ * This is a YACC parser, but since it must be reentrant, Bison is required.
+ * The original source file is cql.y.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/cql.h>
-
+
+ /** Node in the LALR parse tree. */
typedef struct {
+ /** Inhereted attribute: relation */
struct cql_node *rel;
+ /** Synthesized attribute: CQL node */
struct cql_node *cql;
+ /** string buffer with token */
char *buf;
+ /** length of token */
size_t len;
+ /** size of buffer (len <= size) */
size_t size;
} token;
|
searchTerm {
struct cql_node *st = cql_node_dup ($0.rel);
- st->u.st.term = strdup($1.buf);
+ st->u.st.term = xstrdup($1.buf);
$$.cql = st;
}
|
| '>' searchTerm '=' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
- $$.cql = cql_node_prefix($6.cql, $2.buf, $4.buf);
+ $$.cql = cql_apply_prefix($6.cql, $2.buf, $4.buf);
}
| '>' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
- $$.cql = cql_node_prefix($4.cql, 0, $2.buf);
+ $$.cql = cql_apply_prefix($4.cql, 0, $2.buf);
}
;
return 0;
}
-/*
- * bison lexer for CQL.
+/**
+ * putb is a utility that puts one character to the string
+ * in current lexical token. This routine deallocates as
+ * necessary using NMEM.
*/
static void putb(YYSTYPE *lval, CQL_parser cp, int c)
{
if (lval->len+1 >= lval->size)
{
- char *nb = nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
+ char *nb = (char *)
+ nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
memcpy (nb, lval->buf, lval->len);
lval->buf = nb;
}
}
+/**
+ * yylex returns next token for Bison to be read. In this
+ * case one of the CQL terminals are returned.
+ */
int yylex(YYSTYPE *lval, void *vp)
{
CQL_parser cp = (CQL_parser) vp;
lval->rel = 0;
lval->len = 0;
lval->size = 10;
- lval->buf = nmem_malloc(cp->nmem, lval->size);
+ lval->buf = (char *) nmem_malloc(cp->nmem, lval->size);
lval->buf[0] = '\0';
do
{
}
if (c == '"')
{
- while ((c = cp->getbyte(cp->client_data)) != EOF && c != '"')
+ while ((c = cp->getbyte(cp->client_data)) != 0 && c != '"')
{
if (c == '\\')
c = cp->getbyte(cp->client_data);
CQL_parser cql_parser_create(void)
{
- CQL_parser cp = (CQL_parser) malloc (sizeof(*cp));
+ CQL_parser cp = (CQL_parser) xmalloc (sizeof(*cp));
cp->top = 0;
cp->getbyte = 0;
{
cql_node_destroy(cp->top);
nmem_destroy(cp->nmem);
- free (cp);
+ xfree (cp);
}
struct cql_node *cql_parser_result(CQL_parser cp)