1226031Sstas/* 2226031Sstas * Copyright (c) 2008 Kungliga Tekniska H��gskolan 3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4226031Sstas * All rights reserved. 5226031Sstas * 6226031Sstas * Redistribution and use in source and binary forms, with or without 7226031Sstas * modification, are permitted provided that the following conditions 8226031Sstas * are met: 9226031Sstas * 10226031Sstas * 1. Redistributions of source code must retain the above copyright 11226031Sstas * notice, this list of conditions and the following disclaimer. 12226031Sstas * 13226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 14226031Sstas * notice, this list of conditions and the following disclaimer in the 15226031Sstas * documentation and/or other materials provided with the distribution. 16226031Sstas * 17226031Sstas * 3. Neither the name of the Institute nor the names of its contributors 18226031Sstas * may be used to endorse or promote products derived from this software 19226031Sstas * without specific prior written permission. 20226031Sstas * 21226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31226031Sstas * SUCH DAMAGE. 32226031Sstas */ 33226031Sstas 34226031Sstas%{ 35226031Sstas#ifdef HAVE_CONFIG_H 36226031Sstas#include <config.h> 37226031Sstas#endif 38226031Sstas#include <stdio.h> 39226031Sstas#include <stdlib.h> 40226031Sstas#include <hx_locl.h> 41226031Sstas 42226031Sstas 43226031Sstas%} 44226031Sstas 45226031Sstas%union { 46226031Sstas char *string; 47226031Sstas struct hx_expr *expr; 48226031Sstas} 49226031Sstas 50226031Sstas%token kw_TRUE 51226031Sstas%token kw_FALSE 52226031Sstas%token kw_AND 53226031Sstas%token kw_OR 54226031Sstas%token kw_IN 55226031Sstas%token kw_TAILMATCH 56226031Sstas 57226031Sstas%type <expr> expr 58226031Sstas%type <expr> comp 59226031Sstas%type <expr> word words 60226031Sstas%type <expr> number 61226031Sstas%type <expr> string 62226031Sstas%type <expr> function 63226031Sstas%type <expr> variable variables 64226031Sstas 65226031Sstas%token <string> NUMBER 66226031Sstas%token <string> STRING 67226031Sstas%token <string> IDENTIFIER 68226031Sstas 69226031Sstas%start start 70226031Sstas 71226031Sstas%% 72226031Sstas 73226031Sstasstart: expr { _hx509_expr_input.expr = $1; } 74226031Sstas 75226031Sstasexpr : kw_TRUE { $$ = _hx509_make_expr(op_TRUE, NULL, NULL); } 76226031Sstas | kw_FALSE { $$ = _hx509_make_expr(op_FALSE, NULL, NULL); } 77226031Sstas | '!' expr { $$ = _hx509_make_expr(op_NOT, $2, NULL); } 78226031Sstas | expr kw_AND expr { $$ = _hx509_make_expr(op_AND, $1, $3); } 79226031Sstas | expr kw_OR expr { $$ = _hx509_make_expr(op_OR, $1, $3); } 80226031Sstas | '(' expr ')' { $$ = $2; } 81226031Sstas | comp { $$ = _hx509_make_expr(op_COMP, $1, NULL); } 82226031Sstas ; 83226031Sstas 84226031Sstaswords : word { $$ = _hx509_make_expr(expr_WORDS, $1, NULL); } 85226031Sstas | word ',' words { $$ = _hx509_make_expr(expr_WORDS, $1, $3); } 86226031Sstas ; 87226031Sstas 88226031Sstascomp : word '=' '=' word { $$ = _hx509_make_expr(comp_EQ, $1, $4); } 89226031Sstas | word '!' '=' word { $$ = _hx509_make_expr(comp_NE, $1, $4); } 90226031Sstas | word kw_TAILMATCH word { $$ = _hx509_make_expr(comp_TAILEQ, $1, $3); } 91226031Sstas | word kw_IN '(' words ')' { $$ = _hx509_make_expr(comp_IN, $1, $4); } 92226031Sstas | word kw_IN variable { $$ = _hx509_make_expr(comp_IN, $1, $3); } 93226031Sstas ; 94226031Sstas 95226031Sstasword : number { $$ = $1; } 96226031Sstas | string { $$ = $1; } 97226031Sstas | function { $$ = $1; } 98226031Sstas | variable { $$ = $1; } 99226031Sstas ; 100226031Sstas 101226031Sstasnumber : NUMBER { $$ = _hx509_make_expr(expr_NUMBER, $1, NULL); }; 102226031Sstasstring : STRING { $$ = _hx509_make_expr(expr_STRING, $1, NULL); }; 103226031Sstas 104226031Sstasfunction: IDENTIFIER '(' words ')' { 105226031Sstas $$ = _hx509_make_expr(expr_FUNCTION, $1, $3); } 106226031Sstas ; 107226031Sstasvariable: '%' '{' variables '}' { $$ = $3; } 108226031Sstas ; 109226031Sstas 110226031Sstasvariables: IDENTIFIER '.' variables { 111226031Sstas $$ = _hx509_make_expr(expr_VAR, $1, $3); } 112226031Sstas | IDENTIFIER { 113226031Sstas $$ = _hx509_make_expr(expr_VAR, $1, NULL); } 114226031Sstas ; 115