Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/*
* (compile (concat "bison -ydo parse-bison.c " (file-relative-name buffer-
file-name)))
*/
#include "ngspice/ngspice.h"
#include "ngspice/fteparse.h"
#include <stdio.h>
#include <stdlib.h>
#include "parse.h"
#include "parse-bison.h"
#include "parse-bison-y.h"
static void PPerror (YYLTYPE *locp, char **line, struct pnode **retval, char
const *);
%}
%name-prefix "PP"
%defines
%locations
%debug
%pure-parser
%union {
double num;
const char *str;
struct pnode *pnode;
}
/*
* This gramar has two expected shift/reduce conflicts
* exp1 '-' exp2 can
* o yield an exp, interpreting '-' as a binary operator
* o yield a list of two expressions
* exp1 and
* unary '-' exp2
* the first interpretation is favoured. (bison defaults to 'shift')
* TOK_STR '(' exp1 ')' can
* o yield an exp, per function application
* o yield a list of two expressions
* TOK_STR and
* '(' exp1 ')' which will be reduced to exp1
* the first interpretation is favoured. (bison defaults to 'shift')
*
* to verify:
* execute bison --report=state
*
* the %expect 2
* manifests my expectation, and will issue a `warning' when not met
*/
%expect 2
/* Operator Precedence */
%%
/*
*/
expression:
{ *retval = NULL; }
| exp_list { *retval = $1; }
;
exp_list:
one_exp
| one_exp exp_list { $1->pn_next = $2; $2->pn_use ++; $$ = $1; }
;
one_exp:
exp {
$1->pn_name = copy_substring(@1.start, @1.stop);
$$ = $1;
}
;
exp:
TOK_NUM { $$ = PP_mknnode($1); }
| TOK_STR { $$ = PP_mksnode($1); txfree($1); }
%%