10 changed files with 2183 additions and 238 deletions
-
5ChangeLog
-
1src/frontend/inpcom.c
-
9src/frontend/numparam/xpressn.c
-
12src/include/inpptree.h
-
3src/spicelib/parser/Makefile.am
-
1799src/spicelib/parser/inpptree-parser.c
-
81src/spicelib/parser/inpptree-parser.h
-
112src/spicelib/parser/inpptree-parser.y
-
364src/spicelib/parser/inpptree.c
-
35src/spicelib/parser/ptfuncs.c
1799
src/spicelib/parser/inpptree-parser.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,81 @@ |
|||
|
|||
/* A Bison parser, made by GNU Bison 2.4.1. */ |
|||
|
|||
/* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */ |
|||
|
|||
/* 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_LT = 261, |
|||
TOK_GE = 262, |
|||
TOK_GT = 263, |
|||
TOK_EQ = 264, |
|||
TOK_NE = 265, |
|||
TOK_OR = 266, |
|||
TOK_AND = 267, |
|||
NEG = 268 |
|||
}; |
|||
#endif |
|||
|
|||
|
|||
|
|||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
|||
typedef union YYSTYPE |
|||
{ |
|||
|
|||
/* Line 1740 of yacc.c */ |
|||
#line 29 "inpptree-parser.y" |
|||
|
|||
double num; |
|||
const char *str; |
|||
struct INPparseNode *pnode; |
|||
|
|||
|
|||
|
|||
/* Line 1740 of yacc.c */ |
|||
#line 73 "inpptree-parser.h" |
|||
} YYSTYPE; |
|||
# define YYSTYPE_IS_TRIVIAL 1 |
|||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ |
|||
# define YYSTYPE_IS_DECLARED 1 |
|||
#endif |
|||
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,112 @@ |
|||
%{ |
|||
|
|||
#include <stdio.h> |
|||
#include "inpptree-parser.h" |
|||
|
|||
extern int PTlex (YYSTYPE *lvalp, char **line); |
|||
extern int PTparse (char **line, struct INPparseNode **retval); |
|||
|
|||
static void PTerror (char **line, struct INPparseNode **retval, char const *); |
|||
|
|||
#if defined (_MSC_VER) |
|||
# define __func__ __FUNCTION__ /* __func__ is C99, but MSC can't */ |
|||
#endif |
|||
|
|||
%} |
|||
|
|||
%name-prefix="PT" |
|||
%output="inpptree-parser.c" |
|||
|
|||
%defines |
|||
|
|||
%pure-parser |
|||
|
|||
%parse-param {char **line} |
|||
%lex-param {char **line} |
|||
|
|||
%parse-param {struct INPparseNode **retval} |
|||
|
|||
%union { |
|||
double num; |
|||
const char *str; |
|||
struct INPparseNode *pnode; |
|||
} |
|||
|
|||
%token <num> TOK_NUM |
|||
%token <str> TOK_STR |
|||
%token TOK_LE TOK_LT TOK_GE TOK_GT TOK_EQ TOK_NE |
|||
|
|||
%type <pnode> exp nonempty_arglist |
|||
|
|||
// Operator Precedence |
|||
|
|||
%left ',' |
|||
%right '?' ':' |
|||
%left TOK_OR |
|||
%left TOK_AND |
|||
%left TOK_EQ TOK_NE |
|||
%left TOK_LE TOK_LT TOK_GE TOK_GT |
|||
%left '-' '+' |
|||
%left '*' '/' |
|||
%left '^' /* exponentiation */ |
|||
%left NEG '!' /* negation--unary minus, and boolean not */ |
|||
|
|||
%% |
|||
|
|||
expression: |
|||
exp { *retval = $1; } |
|||
; |
|||
|
|||
exp: |
|||
TOK_NUM { $$ = mknnode($1); } |
|||
| TOK_STR { $$ = mksnode($1); } |
|||
|
|||
| exp '+' exp { $$ = mkbnode("+", $1, $3); } |
|||
| exp '-' exp { $$ = mkbnode("-", $1, $3); } |
|||
| exp '*' exp { $$ = mkbnode("*", $1, $3); } |
|||
| exp '/' exp { $$ = mkbnode("/", $1, $3); } |
|||
| exp '^' exp { $$ = mkbnode("^", $1, $3); } |
|||
|
|||
| '(' exp ')' { $$ = $2; } |
|||
|
|||
| '-' exp %prec NEG { $$ = mkfnode("-",$2); } |
|||
|
|||
| TOK_STR '(' nonempty_arglist ')' { $$ = mkfnode($1, $3); } |
|||
|
|||
| exp '?' exp ':' exp { $$ = mkfnode("ternary_fcn", |
|||
mkbnode(",", |
|||
mkbnode(",", $1, $3), |
|||
$5)); } |
|||
|
|||
| exp TOK_EQ exp { $$ = mkfnode("eq0", mkbnode("-",$1,$3)); } |
|||
| exp TOK_NE exp { $$ = mkfnode("ne0", mkbnode("-",$1,$3)); } |
|||
| exp TOK_GT exp { $$ = mkfnode("gt0", mkbnode("-",$1,$3)); } |
|||
| exp TOK_LT exp { $$ = mkfnode("lt0", mkbnode("-",$1,$3)); } |
|||
| exp TOK_GE exp { $$ = mkfnode("ge0", mkbnode("-",$1,$3)); } |
|||
| exp TOK_LE exp { $$ = mkfnode("le0", mkbnode("-",$1,$3)); } |
|||
|
|||
| exp TOK_OR exp { $$ = mkfnode("ne0", |
|||
mkbnode("+", |
|||
mkfnode("ne0", $1), |
|||
mkfnode("ne0", $3))); } |
|||
| exp TOK_AND exp { $$ = mkfnode("eq0", |
|||
mkbnode("+", |
|||
mkfnode("eq0", $1), |
|||
mkfnode("eq0", $3))); } |
|||
| '!' exp { $$ = mkfnode("eq0", $2); } |
|||
|
|||
; |
|||
|
|||
nonempty_arglist: |
|||
exp |
|||
| nonempty_arglist ',' exp { $$ = mkbnode(",", $1, $3); } |
|||
|
|||
%% |
|||
|
|||
|
|||
/* Called by yyparse on error. */ |
|||
static void |
|||
PTerror (char **line, struct INPparseNode **retval, char const *s) |
|||
{ |
|||
fprintf (stderr, "%s: %s\n", __func__, s); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue