Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
%code requires {
#include "keywordset.h"
struct parser_context {
char *input;
struct keywordset *tags;
int pos;
int result;
};
struct empty {};
// #define YYLTYPE struct empty
}
%code {
#define YYMAXDEPTH 200
// #define YYLLOC_DEFAULT(Cur, Rhs, N) { ; }
int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, struct parser_context *ctx);
void yyerror (YYLTYPE *llocp, struct parser_context *ctx, char const *s);
}
/* Bison declarations */
%define api.pure full
%define api.value.type {int}
%param {struct parser_context *ctx}
%locations
%token TAG
%nterm bool
%left '|'
%left '&'
%right '!'
%%
/* Bison Grammar rules and actions */
expr: bool { ctx->result = $1; }
bool: TAG;
bool: bool '&' bool { $$ = $1 && $3; };
bool: bool '|' bool { $$ = $1 || $3; };
bool: '!' bool { $$ = ! $2; };
bool: '(' bool ')' { $$ = $2; };
%%
/* Bison Epilogue */
#include <ctype.h>
#include <string.h>
#include "xmalloc.h"
int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, struct parser_context *ctx) {
(void)llocp;
int c = ctx->input[ctx->pos];
while (c == ' ' || c == '\t')
c = ctx->input[++ctx->pos];
if (!c)
return 0;
/* identifier => read the name. */
if (isalpha (c))
{
size_t name_len = 1;
while(isalnum(ctx->input[ctx->pos+name_len]) || ctx->input[ctx->pos+name_len] == '_')
name_len++;
char *name=xstrndup(&ctx->input[ctx->pos], name_len);
ctx->pos += name_len;
if (keywordset_ismember(ctx->tags, name))
*lvalp = 1;
else
*lvalp = 0;
free(name);
return TAG;
}
/* Any other character is a token by itself. */
ctx->pos++;
return c;
}
#include <stdio.h>
void yyerror (YYLTYPE *locp, struct parser_context *ctx, char const *s) {
(void)locp;
(void)ctx;
(void)s;
}