11 changed files with 2502 additions and 568 deletions
-
5ChangeLog
-
4src/frontend/Makefile.am
-
61src/frontend/evaluate.c
-
1874src/frontend/parse-bison.c
-
96src/frontend/parse-bison.h
-
169src/frontend/parse-bison.y
-
836src/frontend/parse.c
-
1src/include/fteparse.h
-
2src/include/ngspice.h
-
15src/misc/string.c
-
3src/misc/stringutil.h
1874
src/frontend/parse-bison.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,96 @@ |
|||
/* A Bison parser, made by GNU Bison 2.3. */ |
|||
|
|||
/* Skeleton interface for Bison's Yacc-like parsers in C |
|||
|
|||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
|||
Free Software Foundation, Inc. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2, or (at your option) |
|||
any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|||
Boston, MA 02110-1301, USA. */ |
|||
|
|||
/* As a special exception, you may create a larger work that contains |
|||
part or all of the Bison parser skeleton and distribute that work |
|||
under terms of your choice, so long as that work isn't itself a |
|||
parser generator using the skeleton or a modified version thereof |
|||
as a parser skeleton. Alternatively, if you modify or redistribute |
|||
the parser skeleton itself, you may (at your option) remove this |
|||
special exception, which will cause the skeleton and the resulting |
|||
Bison output files to be licensed under the GNU General Public |
|||
License without this special exception. |
|||
|
|||
This special exception was added by the Free Software Foundation in |
|||
version 2.2 of Bison. */ |
|||
|
|||
/* Tokens. */ |
|||
#ifndef YYTOKENTYPE |
|||
# define YYTOKENTYPE |
|||
/* Put the tokens into the symbol table, so that GDB and other debuggers |
|||
know about them. */ |
|||
enum yytokentype { |
|||
TOK_NUM = 258, |
|||
TOK_STR = 259, |
|||
TOK_LE = 260, |
|||
TOK_GE = 261, |
|||
TOK_NE = 262, |
|||
TOK_LRANGE = 263, |
|||
TOK_RRANGE = 264, |
|||
NEG = 265 |
|||
}; |
|||
#endif |
|||
/* Tokens. */ |
|||
#define TOK_NUM 258 |
|||
#define TOK_STR 259 |
|||
#define TOK_LE 260 |
|||
#define TOK_GE 261 |
|||
#define TOK_NE 262 |
|||
#define TOK_LRANGE 263 |
|||
#define TOK_RRANGE 264 |
|||
#define NEG 265 |
|||
|
|||
|
|||
|
|||
|
|||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
|||
typedef union YYSTYPE |
|||
#line 51 "parse-bison.y" |
|||
{ |
|||
double num; |
|||
const char *str; |
|||
struct pnode *pnode; |
|||
} |
|||
/* Line 1529 of yacc.c. */ |
|||
#line 75 "parse-bison.h" |
|||
YYSTYPE; |
|||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ |
|||
# define YYSTYPE_IS_DECLARED 1 |
|||
# define YYSTYPE_IS_TRIVIAL 1 |
|||
#endif |
|||
|
|||
|
|||
|
|||
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED |
|||
typedef struct YYLTYPE |
|||
{ |
|||
int first_line; |
|||
int first_column; |
|||
int last_line; |
|||
int last_column; |
|||
} YYLTYPE; |
|||
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ |
|||
# define YYLTYPE_IS_DECLARED 1 |
|||
# define YYLTYPE_IS_TRIVIAL 1 |
|||
#endif |
|||
|
|||
|
|||
@ -0,0 +1,169 @@ |
|||
%{ |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
|
|||
struct PPltype { |
|||
const char *start, *stop; |
|||
}; |
|||
|
|||
# define YYLTYPE struct PPltype |
|||
|
|||
# define YYLLOC_DEFAULT(Current, Rhs, N) \ |
|||
do \ |
|||
if (N) { \ |
|||
(Current).start = YYRHSLOC(Rhs, 1).start; \ |
|||
(Current).stop = YYRHSLOC(Rhs, N).stop; \ |
|||
} else { \ |
|||
(Current).start = (Current).stop = YYRHSLOC(Rhs, 0).stop; \ |
|||
} \ |
|||
while (0) |
|||
|
|||
#include "parse-bison.h" |
|||
|
|||
extern int PPlex (YYSTYPE *lvalp, struct PPltype *llocp, char **line); |
|||
extern int PPparse (char **line, struct pnode **retval); |
|||
extern int PPdebug; |
|||
|
|||
static void PPerror (YYLTYPE *locp, char **line, struct pnode **retval, char const *); |
|||
|
|||
#if defined (_MSC_VER) |
|||
# define __func__ __FUNCTION__ /* __func__ is C99, but MSC can't */ |
|||
#endif |
|||
|
|||
#define U(x) (void)x |
|||
%} |
|||
|
|||
%name-prefix="PP" |
|||
%output="parse-bison.c" |
|||
|
|||
%defines |
|||
%locations |
|||
%debug |
|||
|
|||
%pure-parser |
|||
|
|||
%parse-param {char **line} |
|||
%lex-param {char **line} |
|||
|
|||
%parse-param {struct pnode **retval} |
|||
|
|||
%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 |
|||
|
|||
%token <num> TOK_NUM |
|||
%token <str> TOK_STR |
|||
%token TOK_LE TOK_GE TOK_NE TOK_LRANGE TOK_RRANGE |
|||
|
|||
%type <pnode> exp exp_list one_exp |
|||
|
|||
/* Operator Precedence */ |
|||
|
|||
%right '?' ':' |
|||
%left '|' |
|||
%left '&' |
|||
%left '=' TOK_NE TOK_LE '<' TOK_GE '>' |
|||
%left '~' |
|||
%right ',' |
|||
%left '-' '+' |
|||
%left '*' '/' '%' |
|||
%right '^' /* exponentiation */ |
|||
%left NEG /* negation--unary minus */ |
|||
%left '[' ']' |
|||
%left TOK_LRANGE TOK_RRANGE |
|||
|
|||
%% |
|||
|
|||
/* |
|||
*/ |
|||
|
|||
|
|||
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 { $$ = mknnode($1); } |
|||
| TOK_STR { $$ = mksnode($1); } |
|||
|
|||
| exp ',' exp { $$ = mkbnode(COMMA, $1, $3); } |
|||
| exp '+' exp { $$ = mkbnode(PLUS, $1, $3); } |
|||
| exp '-' exp { $$ = mkbnode(MINUS, $1, $3); } |
|||
| exp '*' exp { $$ = mkbnode(TIMES, $1, $3); } |
|||
| exp '%' exp { $$ = mkbnode(MOD, $1, $3); } |
|||
| exp '/' exp { $$ = mkbnode(DIVIDE, $1, $3); } |
|||
| exp '^' exp { $$ = mkbnode(POWER, $1, $3); } |
|||
|
|||
| '(' exp ')' { $$ = $2; } |
|||
|
|||
| '-' exp %prec NEG { $$ = mkunode(UMINUS, $2); } |
|||
| '~' exp { $$ = mkunode(NOT, $2); } |
|||
|
|||
| TOK_STR '(' exp ')' { $$ = mkfnode($1, $3); } |
|||
|
|||
| exp '=' exp { $$ = mkbnode(EQ, $1, $3); } |
|||
| exp TOK_NE exp { $$ = mkbnode(NE, $1, $3); } |
|||
| exp '>' exp { $$ = mkbnode(GT, $1, $3); } |
|||
| exp '<' exp { $$ = mkbnode(LT, $1, $3); } |
|||
| exp TOK_GE exp { $$ = mkbnode(GE, $1, $3); } |
|||
| exp TOK_LE exp { $$ = mkbnode(LE, $1, $3); } |
|||
|
|||
| exp '&' exp { $$ = mkbnode(AND, $1, $3); } |
|||
| exp '|' exp { $$ = mkbnode(OR, $1, $3); } |
|||
|
|||
| exp '[' exp ']' { $$ = mkbnode(INDX, $1, $3); } |
|||
| exp TOK_LRANGE exp TOK_RRANGE { $$ = mkbnode(RANGE, $1, $3); } |
|||
| exp '?' exp ':' exp { $$ = mkbnode(TERNARY,$1, |
|||
mkbnode(COMMA,$3,$5)); } |
|||
; |
|||
|
|||
%% |
|||
|
|||
|
|||
/* Called by yyparse on error. */ |
|||
static void |
|||
PPerror (YYLTYPE *locp, char **line, struct pnode **retval, char const *s) |
|||
{ |
|||
U(line); U(retval); |
|||
fprintf (stderr, "%s: %s\n", __func__, s); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue