/* A Bison parser, made from instrument.y
   by GNU bison 1.35.  */

#define YYBISON 1  /* Identify Bison output.  */

# define	TOK_RESTRICTED	257
# define	TOK_GENERAL	258
# define	TOK_ABSOLUTE	259
# define	TOK_AT	260
# define	TOK_COMPONENT	261
# define	TOK_DECLARE	262
# define	TOK_DEFINE	263
# define	TOK_DEFINITION	264
# define	TOK_END	265
# define	TOK_FINALLY	266
# define	TOK_EXTERN	267
# define	TOK_INITIALIZE	268
# define	TOK_INSTRUMENT	269
# define	TOK_MCDISPLAY	270
# define	TOK_OUTPUT	271
# define	TOK_PARAMETERS	272
# define	TOK_POLARISATION	273
# define	TOK_RELATIVE	274
# define	TOK_ROTATED	275
# define	TOK_PREVIOUS	276
# define	TOK_SETTING	277
# define	TOK_STATE	278
# define	TOK_TRACE	279
# define	TOK_SHARE	280
# define	TOK_EXTEND	281
# define	TOK_GROUP	282
# define	TOK_SAVE	283
# define	TOK_NEXUS	284
# define	TOK_DICTFILE	285
# define	TOK_HDF	286
# define	TOK_ID	287
# define	TOK_STRING	288
# define	TOK_NUMBER	289
# define	TOK_CTOK	290
# define	TOK_CODE_START	291
# define	TOK_CODE_END	292
# define	TOK_CODE_LINE	293
# define	TOK_INVALID	294

#line 24 "instrument.y"

#include <math.h>
#include <string.h>
#include <stdio.h>

#include "mcstas.h"

#define YYERROR_VERBOSE 1
#define YYDEBUG 1


#line 44 "instrument.y"
#ifndef YYSTYPE
typedef union {
  char *number;
  char *string;
  struct code_block *ccode; /* User-supplied C code block */
  CExp exp;     /* Expression datatype (for arguments) */
  int linenum;      /* Starting line number for code block */
  Coords_exp coords;    /* Coordinates for location or rotation */
  List formals;     /* List of formal parameters */
  List iformals;    /* List of formal instrument parameters */
  List comp_iformals;   /* List of formal comp. input parameters */
  struct instr_formal *iformal; /* Single formal instrument parameter */
  struct comp_iformal *cformal; /* Single formal component input parameter */
  Symtab actuals;   /* Values for formal parameters */
  char **polform;   /* Polarisation state formal parameter */
  struct {List def, set, out, state;
    char **polarisation;} parms;  /* Parameter lists */
  struct instr_def *instrument; /* Instrument definition */
  struct comp_inst *instance; /* Component instance */
  struct comp_place place;  /* Component place */
  struct comp_orientation ori;  /* Component orientation */
  struct NXDinfo *nxdinfo;  /* Info for NeXus dictionary interface */
  struct group_inst *groupinst;
} yystype;
# define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
#endif
#ifndef YYDEBUG
# define YYDEBUG 0
#endif



#define	YYFINAL		203
#define	YYFLAG		-32768
#define	YYNTBASE	50

/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
#define YYTRANSLATE(x) ((unsigned)(x) <= 294 ? yytranslate[x] : 105)

/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
static const char yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
      41,    43,    44,     2,    42,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,    45,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,    46,     2,    47,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,    48,     2,    49,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     3,     4,     5,
       6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
      16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
      26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40
};

#if YYDEBUG
static const short yyprhs[] =
{
       0,     0,     4,     7,     8,    11,    24,    30,    31,    35,
      36,    40,    41,    45,    49,    50,    60,    64,    65,    67,
      69,    73,    76,    80,    82,    86,    91,    97,    98,   111,
     115,   116,   118,   120,   124,   127,   131,   133,   137,   142,
     148,   149,   152,   153,   156,   157,   160,   161,   166,   167,
     171,   172,   176,   179,   180,   183,   184,   187,   188,   191,
     194,   195,   198,   208,   212,   213,   215,   217,   221,   225,
     226,   228,   232,   238,   242,   243,   247,   249,   252,   258,
     261,   262,   265,   267,   269,   277,   278,   281,   282,   285,
     286,   290,   292,   295,   297,   299,   301,   303,   305,   307,
     311,   314,   318,   321,   325,   328,   330,   333,   335,   337,
     341,   342
};
static const short yyrhs[] =
{
       4,    51,    63,     0,     3,    52,     0,     0,    51,    52,
       0,     9,     7,    33,    53,    71,    69,    70,    75,    76,
      77,    78,    11,     0,    54,    55,    56,    57,    58,     0,
       0,    10,    18,    59,     0,     0,    23,    18,    59,     0,
       0,    17,    18,    82,     0,    24,    18,    82,     0,     0,
      19,    18,    41,    33,    42,    33,    42,    33,    43,     0,
      41,    60,    43,     0,     0,    61,     0,    62,     0,    61,
      42,    62,     0,    33,    33,     0,    33,    44,    33,     0,
      33,     0,    33,    45,    96,     0,    33,    33,    45,    96,
       0,    33,    44,    33,    45,    96,     0,     0,     9,    15,
      33,    65,    64,    69,    70,    72,    79,    76,    77,    11,
       0,    41,    66,    43,     0,     0,    67,     0,    68,     0,
      67,    42,    68,     0,    33,    33,     0,    33,    44,    33,
       0,    33,     0,    33,    45,    96,     0,    33,    33,    45,
      96,     0,    33,    44,    33,    45,    96,     0,     0,     8,
     103,     0,     0,    14,   103,     0,     0,    26,   103,     0,
       0,    72,    30,    73,    74,     0,     0,    73,    31,    34,
       0,     0,    74,    32,    35,     0,    25,   103,     0,     0,
      29,   103,     0,     0,    12,   103,     0,     0,    16,   103,
       0,    25,    80,     0,     0,    80,    81,     0,     7,    33,
      45,    33,    85,    88,    89,    91,    95,     0,    41,    83,
      43,     0,     0,    84,     0,    33,     0,    84,    42,    33,
       0,    41,    86,    43,     0,     0,    87,     0,    33,    45,
      96,     0,    87,    42,    33,    45,    96,     0,     6,    94,
      90,     0,     0,    21,    94,    90,     0,     5,     0,    20,
      22,     0,    20,    22,    41,    35,    43,     0,    20,    93,
       0,     0,    28,    92,     0,    33,     0,    33,     0,    41,
      96,    42,    96,    42,    96,    43,     0,     0,    27,   103,
       0,     0,    97,    99,     0,     0,    13,    98,    33,     0,
     100,     0,    99,   100,     0,    33,     0,    35,     0,    34,
       0,    36,     0,    45,     0,    44,     0,    41,   101,    43,
       0,    41,    43,     0,    46,   101,    47,     0,    46,    47,
       0,    48,   101,    49,     0,    48,    49,     0,   102,     0,
     101,   102,     0,   100,     0,    42,     0,    37,   104,    38,
       0,     0,   104,    39,     0
};

#endif

#if YYDEBUG
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const short yyrline[] =
{
       0,   132,   133,   136,   137,   140,   169,   180,   184,   190,
     194,   200,   204,   210,   216,   220,   231,   237,   241,   247,
     252,   259,   277,   291,   300,   310,   330,   348,   348,   371,
     377,   381,   387,   392,   399,   417,   431,   440,   450,   470,
     487,   491,   497,   501,   508,   512,   519,   527,   545,   549,
     554,   558,   564,   570,   574,   580,   584,   590,   594,   600,
     602,   609,   637,   670,   677,   681,   687,   692,   699,   705,
     709,   715,   721,   729,   736,   741,   750,   754,   763,   777,
     784,   788,   794,   814,   831,   840,   844,   852,   852,   858,
     858,   869,   873,   883,   905,   910,   915,   920,   924,   928,
     937,   945,   954,   962,   971,   982,   986,   994,   998,  1004,
    1013,  1018
};
#endif


#if (YYDEBUG) || defined YYERROR_VERBOSE

/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
static const char *const yytname[] =
{
  "$", "error", "$undefined.", "TOK_RESTRICTED", "TOK_GENERAL", 
  "\"ABSOLUTE\"", "\"AT\"", "\"COMPONENT\"", "\"DECLARE\"", "\"DEFINE\"", 
  "\"DEFINITION\"", "\"END\"", "\"FINALLY\"", "\"EXTERN\"", 
  "\"INITIALIZE\"", "\"INSTRUMENT\"", "\"MCDISPLAY\"", "\"OUTPUT\"", 
  "\"PARAMETERS\"", "\"POLARISATION\"", "\"RELATIVE\"", "\"ROTATED\"", 
  "\"PREVIOUS\"", "\"SETTING\"", "\"STATE\"", "\"TRACE\"", "\"SHARE\"", 
  "\"EXTEND\"", "\"GROUP\"", "\"SAVE\"", "\"NEXUS\"", "\"DICTFILE\"", 
  "\"HDF\"", "TOK_ID", "TOK_STRING", "TOK_NUMBER", "TOK_CTOK", 
  "TOK_CODE_START", "TOK_CODE_END", "TOK_CODE_LINE", "TOK_INVALID", "'('", 
  "','", "')'", "'*'", "'='", "'['", "']'", "'{'", "'}'", "main", 
  "compdefs", "compdef", "parameters", "def_par", "set_par", "out_par", 
  "state_par", "polarisation_par", "comp_iformallist", "comp_iformals", 
  "comp_iformals1", "comp_iformal", "instrument", "@1", "instrpar_list", 
  "instr_formals", "instr_formals1", "instr_formal", "declare", 
  "initialize", "share", "nexus", "dictfile", "hdfversion", "trace", 
  "save", "finally", "mcdisplay", "instr_trace", "complist", "component", 
  "formallist", "formals", "formals1", "actuallist", "actuals", 
  "actuals1", "place", "orientation", "reference", "groupref", "groupdef", 
  "compref", "coords", "extend", "exp", "@2", "@3", "topexp", "topatexp", 
  "genexp", "genatexp", "codeblock", "code", 0
};
#endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const short yyr1[] =
{
       0,    50,    50,    51,    51,    52,    53,    54,    54,    55,
      55,    56,    56,    57,    58,    58,    59,    60,    60,    61,
      61,    62,    62,    62,    62,    62,    62,    64,    63,    65,
      66,    66,    67,    67,    68,    68,    68,    68,    68,    68,
      69,    69,    70,    70,    71,    71,    72,    72,    73,    73,
      74,    74,    75,    76,    76,    77,    77,    78,    78,    79,
      80,    80,    81,    82,    83,    83,    84,    84,    85,    86,
      86,    87,    87,    88,    89,    89,    90,    90,    90,    90,
      91,    91,    92,    93,    94,    95,    95,    97,    96,    98,
      96,    99,    99,   100,   100,   100,   100,   100,   100,   100,
     100,   100,   100,   100,   100,   101,   101,   102,   102,   103,
     104,   104
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const short yyr2[] =
{
       0,     3,     2,     0,     2,    12,     5,     0,     3,     0,
       3,     0,     3,     3,     0,     9,     3,     0,     1,     1,
       3,     2,     3,     1,     3,     4,     5,     0,    12,     3,
       0,     1,     1,     3,     2,     3,     1,     3,     4,     5,
       0,     2,     0,     2,     0,     2,     0,     4,     0,     3,
       0,     3,     2,     0,     2,     0,     2,     0,     2,     2,
       0,     2,     9,     3,     0,     1,     1,     3,     3,     0,
       1,     3,     5,     3,     0,     3,     1,     2,     5,     2,
       0,     2,     1,     1,     7,     0,     2,     0,     2,     0,
       3,     1,     2,     1,     1,     1,     1,     1,     1,     3,
       2,     3,     2,     3,     2,     1,     2,     1,     1,     3,
       0,     2
};

/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
   doesn't specify something else to do.  Zero means the default is an
   error. */
static const short yydefact[] =
{
       0,     0,     3,     0,     2,     0,     0,     0,     4,     1,
       7,     0,     0,    44,     9,     0,     0,     0,    40,     0,
      11,    30,    27,    17,     8,   110,    45,     0,    42,     0,
       0,     0,    36,     0,    31,    32,    40,    23,     0,    18,
      19,     0,    41,     0,     0,    10,     0,     0,    14,    34,
       0,    87,    29,     0,    42,    21,     0,    87,    16,     0,
     109,   111,    43,     0,    53,    64,    12,     0,     0,     6,
      87,    35,    89,    37,     0,    33,    46,    87,    22,    24,
      20,    52,     0,    55,    66,     0,    65,    13,     0,    38,
      87,     0,    93,    95,    94,    96,     0,    98,    97,     0,
       0,    88,    91,     0,    25,    87,    54,     0,    57,    63,
       0,     0,    39,    90,   108,   100,   107,     0,   105,   102,
       0,   104,     0,    92,    60,    48,    53,    26,    56,     0,
       0,    67,     0,    99,   106,   101,   103,    59,    50,    55,
      58,     5,     0,     0,    61,     0,    47,     0,     0,     0,
      49,     0,    28,     0,     0,    51,     0,     0,    15,    69,
       0,     0,     0,    70,     0,    74,    87,    68,     0,    87,
       0,     0,    80,    71,     0,     0,    76,     0,    73,     0,
       0,    85,    87,    87,    77,    83,    79,    75,    82,    81,
       0,    62,    72,     0,     0,    86,    87,     0,     0,    78,
      84,     0,     0,     0
};

static const short yydefgoto[] =
{
     201,     5,     4,    13,    14,    20,    31,    48,    69,    24,
      38,    39,    40,     9,    36,    22,    33,    34,    35,    28,
      44,    18,   103,   138,   146,    64,    83,   108,   130,   126,
     137,   144,    66,    85,    86,   160,   162,   163,   165,   172,
     178,   181,   189,   186,   170,   191,    73,    74,    91,   101,
     116,   117,   118,    26,    41
};

static const short yypact[] =
{
       0,    16,-32768,    30,-32768,    35,    21,    -2,-32768,-32768,
      47,    27,    46,    43,    48,    29,    31,    41,    69,    61,
      70,    56,-32768,    57,-32768,-32768,-32768,    41,    77,    31,
      78,    73,   -21,    55,    66,-32768,    69,    23,    68,    74,
  -32768,   -11,-32768,    41,    90,-32768,    58,    99,   100,    79,
      85,   112,-32768,    56,    77,    89,   108,   112,-32768,    57,
  -32768,-32768,-32768,    41,   113,   110,-32768,    58,   128,-32768,
     112,   107,-32768,-32768,   -26,-32768,-32768,   112,   109,-32768,
  -32768,-32768,    41,   141,-32768,   114,   116,-32768,   115,-32768,
     112,   122,-32768,-32768,-32768,-32768,    40,-32768,-32768,    59,
      -3,   -26,-32768,    10,-32768,   112,-32768,    41,   143,-32768,
     127,   129,-32768,-32768,-32768,-32768,-32768,    87,-32768,-32768,
     103,-32768,    17,-32768,-32768,-32768,   113,-32768,-32768,    41,
     150,-32768,   123,-32768,-32768,-32768,-32768,   157,   135,   141,
  -32768,-32768,   134,   136,-32768,   137,   138,   161,   126,   130,
  -32768,   139,-32768,   140,   144,-32768,   133,   142,-32768,   145,
     173,   146,   147,   151,   148,   159,   112,-32768,   149,   112,
       6,   148,   153,-32768,   152,   154,-32768,   -16,-32768,     6,
     155,   158,   112,   112,   160,-32768,-32768,-32768,-32768,-32768,
      41,-32768,-32768,   156,   164,-32768,   112,   162,   163,-32768,
  -32768,   184,   186,-32768
};

static const short yypgoto[] =
{
  -32768,-32768,   182,-32768,-32768,-32768,-32768,-32768,-32768,   165,
  -32768,-32768,   166,-32768,-32768,-32768,-32768,-32768,   167,   168,
     169,-32768,-32768,-32768,-32768,-32768,    76,    53,-32768,-32768,
  -32768,-32768,   170,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
      24,-32768,-32768,-32768,    36,-32768,   -56,-32768,-32768,-32768,
     -72,   -52,    -8,   -27,-32768
};


#define	YYLAST		237


static const short yytable[] =
{
      42,    79,   102,     1,     2,     6,   184,    92,    93,    94,
      95,   176,    49,    11,    89,    96,    62,   185,    97,    98,
      99,   104,   100,    50,    51,     3,   177,    60,    61,   123,
      92,    93,    94,    95,   112,   124,    81,     6,    96,   114,
     125,    97,    98,    99,     7,   100,   121,   120,   122,   127,
      92,    93,    94,    95,    10,   106,    55,    12,    96,   114,
      15,    97,    98,    99,    16,   100,   136,    56,    57,    17,
      21,    19,    23,    92,    93,    94,    95,    27,    25,    29,
     128,    96,   114,   115,    97,    98,    99,    30,   100,    32,
      37,    43,    92,    93,    94,    95,    46,    47,    52,    65,
      96,   114,   140,    97,    98,    99,   119,   100,    53,   134,
     173,    58,   134,   175,   134,    63,    59,    67,    71,    68,
      92,    93,    94,    95,    70,    72,   192,   193,    96,   114,
     133,    97,    98,    99,    77,   100,    92,    93,    94,    95,
     198,    78,    82,    84,    96,   114,    88,    97,    98,    99,
     135,   100,    90,   107,   105,   113,   111,   109,   110,   129,
     131,   141,   132,   195,   143,   142,   145,   148,   153,   149,
     151,   150,   152,   156,   155,   154,   158,   157,   161,   164,
     171,   180,   174,   159,   202,   190,   203,     8,   188,   169,
     167,   166,   147,   168,    45,     0,   183,   182,   196,   197,
       0,   194,   139,   187,    54,   199,   200,   179,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      75,     0,     0,    76,     0,    80,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,    87
};

static const short yycheck[] =
{
      27,    57,    74,     3,     4,     7,    22,    33,    34,    35,
      36,     5,    33,    15,    70,    41,    43,    33,    44,    45,
      46,    77,    48,    44,    45,     9,    20,    38,    39,   101,
      33,    34,    35,    36,    90,    25,    63,     7,    41,    42,
      30,    44,    45,    46,     9,    48,    49,    99,   100,   105,
      33,    34,    35,    36,    33,    82,    33,    10,    41,    42,
      33,    44,    45,    46,    18,    48,    49,    44,    45,    26,
      41,    23,    41,    33,    34,    35,    36,     8,    37,    18,
     107,    41,    42,    43,    44,    45,    46,    17,    48,    33,
      33,    14,    33,    34,    35,    36,    18,    24,    43,    41,
      41,    42,   129,    44,    45,    46,    47,    48,    42,   117,
     166,    43,   120,   169,   122,    25,    42,    18,    33,    19,
      33,    34,    35,    36,    45,    13,   182,   183,    41,    42,
      43,    44,    45,    46,    45,    48,    33,    34,    35,    36,
     196,    33,    29,    33,    41,    42,    18,    44,    45,    46,
      47,    48,    45,    12,    45,    33,    41,    43,    42,    16,
      33,    11,    33,   190,     7,    42,    31,    33,    42,    33,
      32,    34,    11,    33,    35,    45,    43,    33,    33,     6,
      21,    28,    33,    41,     0,    27,     0,     5,    33,    41,
      43,    45,   139,    42,    29,    -1,    42,    45,    42,    35,
      -1,    41,   126,   179,    36,    43,    43,   171,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
      53,    -1,    -1,    54,    -1,    59,    -1,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    67
};
#define YYPURE 1

/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
#line 3 "/usr/local/share/bison/bison.simple"

/* Skeleton output parser for bison,

   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

/* As a special exception, when this file is copied by Bison into a
   Bison output file, you may use that output file without restriction.
   This special exception was added by the Free Software Foundation
   in version 1.24 of Bison.  */

/* This is the parser code that is written into each bison parser when
   the %semantic_parser declaration is not specified in the grammar.
   It was written by Richard Stallman by simplifying the hairy parser
   used when %semantic_parser is specified.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

#if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# if YYSTACK_USE_ALLOCA
#  define YYSTACK_ALLOC alloca
# else
#  ifndef YYSTACK_USE_ALLOCA
#   if defined (alloca) || defined (_ALLOCA_H)
#    define YYSTACK_ALLOC alloca
#   else
#    ifdef __GNUC__
#     define YYSTACK_ALLOC __builtin_alloca
#    endif
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's `empty if-body' warning. */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# else
#  if defined (__STDC__) || defined (__cplusplus)
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   define YYSIZE_T size_t
#  endif
#  define YYSTACK_ALLOC malloc
#  define YYSTACK_FREE free
# endif
#endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */


#if (! defined (yyoverflow) \
     && (! defined (__cplusplus) \
	 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  short yyss;
  YYSTYPE yyvs;
# if YYLSP_NEEDED
  YYLTYPE yyls;
# endif
};

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# if YYLSP_NEEDED
#  define YYSTACK_BYTES(N) \
     ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))	\
      + 2 * YYSTACK_GAP_MAX)
# else
#  define YYSTACK_BYTES(N) \
     ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
      + YYSTACK_GAP_MAX)
# endif

/* Copy COUNT objects from FROM to TO.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if 1 < __GNUC__
#   define YYCOPY(To, From, Count) \
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
#  else
#   define YYCOPY(To, From, Count)		\
      do					\
	{					\
	  register YYSIZE_T yyi;		\
	  for (yyi = 0; yyi < (Count); yyi++)	\
	    (To)[yyi] = (From)[yyi];		\
	}					\
      while (0)
#  endif
# endif

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack)					\
    do									\
      {									\
	YYSIZE_T yynewbytes;						\
	YYCOPY (&yyptr->Stack, Stack, yysize);				\
	Stack = &yyptr->Stack;						\
	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;	\
	yyptr += yynewbytes / sizeof (*yyptr);				\
      }									\
    while (0)

#endif


#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
# define YYSIZE_T __SIZE_TYPE__
#endif
#if ! defined (YYSIZE_T) && defined (size_t)
# define YYSIZE_T size_t
#endif
#if ! defined (YYSIZE_T)
# if defined (__STDC__) || defined (__cplusplus)
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# endif
#endif
#if ! defined (YYSIZE_T)
# define YYSIZE_T unsigned int
#endif

#define yyerrok		(yyerrstatus = 0)
#define yyclearin	(yychar = YYEMPTY)
#define YYEMPTY		-2
#define YYEOF		0
#define YYACCEPT	goto yyacceptlab
#define YYABORT 	goto yyabortlab
#define YYERROR		goto yyerrlab1
/* Like YYERROR except do call yyerror.  This remains here temporarily
   to ease the transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */
#define YYFAIL		goto yyerrlab
#define YYRECOVERING()  (!!yyerrstatus)
#define YYBACKUP(Token, Value)					\
do								\
  if (yychar == YYEMPTY && yylen == 1)				\
    {								\
      yychar = (Token);						\
      yylval = (Value);						\
      yychar1 = YYTRANSLATE (yychar);				\
      YYPOPSTACK;						\
      goto yybackup;						\
    }								\
  else								\
    { 								\
      yyerror ("syntax error: cannot back up");			\
      YYERROR;							\
    }								\
while (0)

#define YYTERROR	1
#define YYERRCODE	256


/* YYLLOC_DEFAULT -- Compute the default location (before the actions
   are run).

   When YYLLOC_DEFAULT is run, CURRENT is set the location of the
   first token.  By default, to implement support for ranges, extend
   its range to the last symbol.  */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N)       	\
   Current.last_line   = Rhs[N].last_line;	\
   Current.last_column = Rhs[N].last_column;
#endif


/* YYLEX -- calling `yylex' with the right arguments.  */

#if YYPURE
# if YYLSP_NEEDED
#  ifdef YYLEX_PARAM
#   define YYLEX		yylex (&yylval, &yylloc, YYLEX_PARAM)
#  else
#   define YYLEX		yylex (&yylval, &yylloc)
#  endif
# else /* !YYLSP_NEEDED */
#  ifdef YYLEX_PARAM
#   define YYLEX		yylex (&yylval, YYLEX_PARAM)
#  else
#   define YYLEX		yylex (&yylval)
#  endif
# endif /* !YYLSP_NEEDED */
#else /* !YYPURE */
# define YYLEX			yylex ()
#endif /* !YYPURE */


/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)			\
do {						\
  if (yydebug)					\
    YYFPRINTF Args;				\
} while (0)
/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
#endif /* !YYDEBUG */

/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef	YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#if YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif

#ifdef YYERROR_VERBOSE

# ifndef yystrlen
#  if defined (__GLIBC__) && defined (_STRING_H)
#   define yystrlen strlen
#  else
/* Return the length of YYSTR.  */
static YYSIZE_T
#   if defined (__STDC__) || defined (__cplusplus)
yystrlen (const char *yystr)
#   else
yystrlen (yystr)
     const char *yystr;
#   endif
{
  register const char *yys = yystr;

  while (*yys++ != '\0')
    continue;

  return yys - yystr - 1;
}
#  endif
# endif

# ifndef yystpcpy
#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
#   define yystpcpy stpcpy
#  else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
   YYDEST.  */
static char *
#   if defined (__STDC__) || defined (__cplusplus)
yystpcpy (char *yydest, const char *yysrc)
#   else
yystpcpy (yydest, yysrc)
     char *yydest;
     const char *yysrc;
#   endif
{
  register char *yyd = yydest;
  register const char *yys = yysrc;

  while ((*yyd++ = *yys++) != '\0')
    continue;

  return yyd - 1;
}
#  endif
# endif
#endif

#line 315 "/usr/local/share/bison/bison.simple"


/* The user can define YYPARSE_PARAM as the name of an argument to be passed
   into yyparse.  The argument should have type void *.
   It should actually point to an object.
   Grammar actions can access the variable by casting it
   to the proper pointer type.  */

#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
#  define YYPARSE_PARAM_DECL
# else
#  define YYPARSE_PARAM_ARG YYPARSE_PARAM
#  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
# endif
#else /* !YYPARSE_PARAM */
# define YYPARSE_PARAM_ARG
# define YYPARSE_PARAM_DECL
#endif /* !YYPARSE_PARAM */

/* Prevent warning if -Wstrict-prototypes.  */
#ifdef __GNUC__
# ifdef YYPARSE_PARAM
int yyparse (void *);
# else
int yyparse (void);
# endif
#endif

/* YY_DECL_VARIABLES -- depending whether we use a pure parser,
   variables are global, or local to YYPARSE.  */

#define YY_DECL_NON_LSP_VARIABLES			\
/* The lookahead symbol.  */				\
int yychar;						\
							\
/* The semantic value of the lookahead symbol. */	\
YYSTYPE yylval;						\
							\
/* Number of parse errors so far.  */			\
int yynerrs;

#if YYLSP_NEEDED
# define YY_DECL_VARIABLES			\
YY_DECL_NON_LSP_VARIABLES			\
						\
/* Location data for the lookahead symbol.  */	\
YYLTYPE yylloc;
#else
# define YY_DECL_VARIABLES			\
YY_DECL_NON_LSP_VARIABLES
#endif


/* If nonreentrant, generate the variables here. */

#if !YYPURE
YY_DECL_VARIABLES
#endif  /* !YYPURE */

int
yyparse (YYPARSE_PARAM_ARG)
     YYPARSE_PARAM_DECL
{
  /* If reentrant, generate the variables here. */
#if YYPURE
  YY_DECL_VARIABLES
#endif  /* !YYPURE */

  register int yystate;
  register int yyn;
  int yyresult;
  /* Number of tokens to shift before error messages enabled.  */
  int yyerrstatus;
  /* Lookahead token as an internal (translated) token number.  */
  int yychar1 = 0;

  /* Three stacks and their tools:
     `yyss': related to states,
     `yyvs': related to semantic values,
     `yyls': related to locations.

     Refer to the stacks thru separate pointers, to allow yyoverflow
     to reallocate them elsewhere.  */

  /* The state stack. */
  short	yyssa[YYINITDEPTH];
  short *yyss = yyssa;
  register short *yyssp;

  /* The semantic value stack.  */
  YYSTYPE yyvsa[YYINITDEPTH];
  YYSTYPE *yyvs = yyvsa;
  register YYSTYPE *yyvsp;

#if YYLSP_NEEDED
  /* The location stack.  */
  YYLTYPE yylsa[YYINITDEPTH];
  YYLTYPE *yyls = yylsa;
  YYLTYPE *yylsp;
#endif

#if YYLSP_NEEDED
# define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
#else
# define YYPOPSTACK   (yyvsp--, yyssp--)
#endif

  YYSIZE_T yystacksize = YYINITDEPTH;


  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;
#if YYLSP_NEEDED
  YYLTYPE yyloc;
#endif

  /* When reducing, the number of symbols on the RHS of the reduced
     rule. */
  int yylen;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;		/* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss;
  yyvsp = yyvs;
#if YYLSP_NEEDED
  yylsp = yyls;
#endif
  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed. so pushing a state here evens the stacks.
     */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyssp >= yyss + yystacksize - 1)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
	/* Give user a chance to reallocate the stack. Use copies of
	   these so that the &'s don't force the real ones into
	   memory.  */
	YYSTYPE *yyvs1 = yyvs;
	short *yyss1 = yyss;

	/* Each stack pointer address is followed by the size of the
	   data in use in that stack, in bytes.  */
# if YYLSP_NEEDED
	YYLTYPE *yyls1 = yyls;
	/* This used to be a conditional around just the two extra args,
	   but that might be undefined if yyoverflow is a macro.  */
	yyoverflow ("parser stack overflow",
		    &yyss1, yysize * sizeof (*yyssp),
		    &yyvs1, yysize * sizeof (*yyvsp),
		    &yyls1, yysize * sizeof (*yylsp),
		    &yystacksize);
	yyls = yyls1;
# else
	yyoverflow ("parser stack overflow",
		    &yyss1, yysize * sizeof (*yyssp),
		    &yyvs1, yysize * sizeof (*yyvsp),
		    &yystacksize);
# endif
	yyss = yyss1;
	yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyoverflowlab;
# else
      /* Extend the stack our own way.  */
      if (yystacksize >= YYMAXDEPTH)
	goto yyoverflowlab;
      yystacksize *= 2;
      if (yystacksize > YYMAXDEPTH)
	yystacksize = YYMAXDEPTH;

      {
	short *yyss1 = yyss;
	union yyalloc *yyptr =
	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
	if (! yyptr)
	  goto yyoverflowlab;
	YYSTACK_RELOCATE (yyss);
	YYSTACK_RELOCATE (yyvs);
# if YYLSP_NEEDED
	YYSTACK_RELOCATE (yyls);
# endif
# undef YYSTACK_RELOCATE
	if (yyss1 != yyssa)
	  YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
#if YYLSP_NEEDED
      yylsp = yyls + yysize - 1;
#endif

      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
		  (unsigned long int) yystacksize));

      if (yyssp >= yyss + yystacksize - 1)
	YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  goto yybackup;


/*-----------.
| yybackup.  |
`-----------*/
yybackup:

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* yyresume: */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* yychar is either YYEMPTY or YYEOF
     or a valid token in external form.  */

  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = YYLEX;
    }

  /* Convert token to internal form (in yychar1) for indexing tables with */

  if (yychar <= 0)		/* This means end of input. */
    {
      yychar1 = 0;
      yychar = YYEOF;		/* Don't call YYLEX any more */

      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yychar1 = YYTRANSLATE (yychar);

#if YYDEBUG
     /* We have to keep this `#if YYDEBUG', since we use variables
	which are defined only if `YYDEBUG' is set.  */
      if (yydebug)
	{
	  YYFPRINTF (stderr, "Next token is %d (%s",
		     yychar, yytname[yychar1]);
	  /* Give the individual parser a way to print the precise
	     meaning of a token, for further debugging info.  */
# ifdef YYPRINT
	  YYPRINT (stderr, yychar, yylval);
# endif
	  YYFPRINTF (stderr, ")\n");
	}
#endif
    }

  yyn += yychar1;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
    goto yydefault;

  yyn = yytable[yyn];

  /* yyn is what to do for this token type in this state.
     Negative => reduce, -yyn is rule number.
     Positive => shift, yyn is new state.
       New state is final state => don't bother to shift,
       just return success.
     0, or most negative number => error.  */

  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrlab;

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Shift the lookahead token.  */
  YYDPRINTF ((stderr, "Shifting token %d (%s), ",
	      yychar, yytname[yychar1]));

  /* Discard the token being shifted unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  *++yyvsp = yylval;
#if YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  yystate = yyn;
  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     `$$ = $1'.

     Otherwise, the following line sets YYVAL to the semantic value of
     the lookahead token.  This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];

#if YYLSP_NEEDED
  /* Similarly for the default location.  Let the user run additional
     commands if for instance locations are ranges.  */
  yyloc = yylsp[1-yylen];
  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
#endif

#if YYDEBUG
  /* We have to keep this `#if YYDEBUG', since we use variables which
     are defined only if `YYDEBUG' is set.  */
  if (yydebug)
    {
      int yyi;

      YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
		 yyn, yyrline[yyn]);

      /* Print the symbols being reduced, and their result.  */
      for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
	YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
      YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
    }
#endif

  switch (yyn) {

case 5:
#line 141 "instrument.y"
{
        struct comp_def *c;
        palloc(c);
        c->name = yyvsp[-9].string;
        /* ADD: E. Farhi, Aug 14th, 2002 */
        c->source = str_quote(instr_current_filename);
        c->def_par = yyvsp[-8].parms.def;
        c->set_par = yyvsp[-8].parms.set;
        c->out_par = yyvsp[-8].parms.out;
        c->state_par = yyvsp[-8].parms.state;
        c->polarisation_par = yyvsp[-8].parms.polarisation;
        c->share_code = yyvsp[-7].ccode;  /* ADD: E. Farhi Sep 20th, 2001 */
        c->decl_code = yyvsp[-6].ccode;  /* MOD: E. Farhi Sep 20th, 2001, shifted param numbs */
        c->init_code = yyvsp[-5].ccode;
        c->trace_code = yyvsp[-4].ccode;
        c->save_code = yyvsp[-3].ccode;  /* ADD: E. Farhi Aug 25th, 2002+shifted indexes */
        c->finally_code = yyvsp[-2].ccode;
        c->mcdisplay_code = yyvsp[-1].ccode;
        c->comp_inst_number = 0; /* ADD: E. Farhi Sep 20th, 2001 */

        /* Check definition and setting params for uniqueness */
        check_comp_formals(c->def_par, c->set_par, c->name);
        /* Put component definition in table. */
        symtab_add(read_components, c->name, c);
        if (verbose) fprintf(stderr, "Embedding component %s from file %s\n", c->name, c->source);
      ;
    break;}
case 6:
#line 170 "instrument.y"
{
        yyval.parms.def = yyvsp[-4].formals;
        yyval.parms.set = yyvsp[-3].formals;
        yyval.parms.out = yyvsp[-2].formals;
        yyval.parms.state = yyvsp[-1].formals;
        yyval.parms.polarisation = yyvsp[0].polform;
      ;
    break;}
case 7:
#line 181 "instrument.y"
{
        yyval.formals = list_create();
      ;
    break;}
case 8:
#line 185 "instrument.y"
{
        yyval.formals = yyvsp[0].comp_iformals;
      ;
    break;}
case 9:
#line 191 "instrument.y"
{
        yyval.formals = list_create();
      ;
    break;}
case 10:
#line 195 "instrument.y"
{
        yyval.formals = yyvsp[0].comp_iformals;
      ;
    break;}
case 11:
#line 201 "instrument.y"
{
        yyval.formals = list_create();
      ;
    break;}
case 12:
#line 205 "instrument.y"
{
        yyval.formals = yyvsp[0].formals;
      ;
    break;}
case 13:
#line 211 "instrument.y"
{
        yyval.formals = yyvsp[0].formals;
      ;
    break;}
case 14:
#line 217 "instrument.y"
{
        yyval.polform = NULL;
      ;
    break;}
case 15:
#line 221 "instrument.y"
{
        char **polform;
        nalloc(polform, 3);
        polform[0] = yyvsp[-5].string;
        polform[1] = yyvsp[-3].string;
        polform[2] = yyvsp[-1].string;
        yyval.polform = polform;
      ;
    break;}
case 16:
#line 232 "instrument.y"
{
        yyval.comp_iformals = yyvsp[-1].comp_iformals;
      ;
    break;}
case 17:
#line 238 "instrument.y"
{
        yyval.comp_iformals = list_create();
      ;
    break;}
case 18:
#line 242 "instrument.y"
{
        yyval.comp_iformals = yyvsp[0].comp_iformals;
      ;
    break;}
case 19:
#line 248 "instrument.y"
{
        yyval.comp_iformals = list_create();
        list_add(yyval.comp_iformals, yyvsp[0].cformal);
      ;
    break;}
case 20:
#line 253 "instrument.y"
{
        list_add(yyvsp[-2].comp_iformals, yyvsp[0].cformal);
        yyval.comp_iformals = yyvsp[-2].comp_iformals;
      ;
    break;}
case 21:
#line 260 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-1].string, "double")) {
          formal->type = instr_type_double;
        } else if(!strcmp(yyvsp[-1].string, "int")) {
          formal->type = instr_type_int;
        } else if(!strcmp(yyvsp[-1].string, "string")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s for component "
          "parameter %s at line %s:%d.\n", yyvsp[-1].string, yyvsp[0].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[0].string;
        yyval.cformal = formal;
      ;
    break;}
case 22:
#line 278 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-2].string, "char")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s* for component "
          "parameter %s at line $s:%d.\n", yyvsp[-2].string, yyvsp[0].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[0].string;
        yyval.cformal = formal;
      ;
    break;}
case 23:
#line 292 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        formal->id = str_dup(yyvsp[0].string);
        formal->isoptional = 0; /* No default value */
        formal->type = instr_type_double;
        yyval.cformal = formal;
      ;
    break;}
case 24:
#line 301 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        formal->type = instr_type_double;
        yyval.cformal = formal;
      ;
    break;}
case 25:
#line 311 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-3].string, "double")) {
          formal->type = instr_type_double;
        } else if(!strcmp(yyvsp[-3].string, "int")) {
          formal->type = instr_type_int;
        } else if(!strcmp(yyvsp[-3].string, "string")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s for component "
          "parameter %s at line %s:%d.\n", yyvsp[-3].string, yyvsp[-2].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        yyval.cformal = formal;
      ;
    break;}
case 26:
#line 331 "instrument.y"
{
        struct comp_iformal *formal;
        palloc(formal);
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        if(!strcmp(yyvsp[-4].string, "char")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s* for component "
          "parameter %s at line %s:%d.\n", yyvsp[-4].string, yyvsp[-2].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        yyval.cformal = formal;
      ;
    break;}
case 27:
#line 349 "instrument.y"
{ instrument_definition->formals = yyvsp[0].iformals; instrument_definition->name = yyvsp[-1].string; ;
    break;}
case 28:
#line 351 "instrument.y"
{
        instrument_definition->decls = yyvsp[-6].ccode;
        instrument_definition->inits = yyvsp[-5].ccode;
        instrument_definition->nxdinfo = yyvsp[-4].nxdinfo;
        instrument_definition->saves  = yyvsp[-2].ccode;
        instrument_definition->finals = yyvsp[-1].ccode;
        instrument_definition->compmap = comp_instances;
        instrument_definition->groupmap = group_instances;  /* ADD: E. Farhi Sep 25th, 2001 */
        instrument_definition->complist = comp_instances_list;
        instrument_definition->grouplist = group_instances_list;  /* ADD: E. Farhi Sep 25th, 2001 */

        /* Check instrument parameters for uniqueness */
        check_instrument_formals(instrument_definition->formals,
               instrument_definition->name);
        if (verbose) fprintf(stderr, "Creating instrument %s\n", instrument_definition->name);
      ;
    break;}
case 29:
#line 372 "instrument.y"
{
        yyval.iformals = yyvsp[-1].iformals;
      ;
    break;}
case 30:
#line 378 "instrument.y"
{
        yyval.iformals = list_create();
      ;
    break;}
case 31:
#line 382 "instrument.y"
{
        yyval.iformals = yyvsp[0].iformals;
      ;
    break;}
case 32:
#line 388 "instrument.y"
{
        yyval.iformals = list_create();
        list_add(yyval.iformals, yyvsp[0].iformal);
      ;
    break;}
case 33:
#line 393 "instrument.y"
{
        list_add(yyvsp[-2].iformals, yyvsp[0].iformal);
        yyval.iformals = yyvsp[-2].iformals;
      ;
    break;}
case 34:
#line 400 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-1].string, "double")) {
          formal->type = instr_type_double;
        } else if(!strcmp(yyvsp[-1].string, "int")) {
          formal->type = instr_type_int;
        } else if(!strcmp(yyvsp[-1].string, "string")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s for instrument "
          "parameter %s at line %s:%d.\n", yyvsp[-1].string, yyvsp[0].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[0].string;
        yyval.iformal = formal;
      ;
    break;}
case 35:
#line 418 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-2].string, "char")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type $s* for instrument "
          "parameter %s at line %s:%d.\n", yyvsp[-2].string, yyvsp[0].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[0].string;
        yyval.iformal = formal;
      ;
    break;}
case 36:
#line 432 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        formal->type = instr_type_double;
        formal->id = yyvsp[0].string;
        formal->isoptional = 0; /* No default value */
        yyval.iformal = formal;
      ;
    break;}
case 37:
#line 441 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        formal->type = instr_type_double;
        yyval.iformal = formal;
      ;
    break;}
case 38:
#line 451 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        if(!strcmp(yyvsp[-3].string, "double")) {
          formal->type = instr_type_double;
        } else if(!strcmp(yyvsp[-3].string, "int")) {
          formal->type = instr_type_int;
        } else if(!strcmp(yyvsp[-3].string, "string")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s for instrument "
          "parameter %s at line %s:%d.\n", yyvsp[-3].string, yyvsp[-2].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        yyval.iformal = formal;
      ;
    break;}
case 39:
#line 471 "instrument.y"
{
        struct instr_formal *formal;
        palloc(formal);
        formal->id = yyvsp[-2].string;
        formal->isoptional = 1; /* Default value available */
        formal->default_value = yyvsp[0].exp;
        if(!strcmp(yyvsp[-4].string, "char")) {
          formal->type = instr_type_string;
        } else {
          print_error("Illegal type %s* for instrument "
          "parameter %s at line %s:%d.\n", yyvsp[-4].string, yyvsp[-2].string, instr_current_filename, instr_current_line);
          formal->type = instr_type_double;
        }
        yyval.iformal = formal;
      ;
    break;}
case 40:
#line 488 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 41:
#line 492 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 42:
#line 498 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 43:
#line 502 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 44:
#line 509 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 45:
#line 513 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 46:
#line 520 "instrument.y"
{
        struct NXDinfo *nxdinfo;
        palloc(nxdinfo);
        nxdinfo->nxdfile = NULL;
        nxdinfo->any = 0;
        yyval.nxdinfo = nxdinfo;
      ;
    break;}
case 47:
#line 528 "instrument.y"
{ /* ADD: E.Farhi Aug 6th 2002: use default NeXus dictionary file */
        struct NXDinfo *nxdinfo = yyvsp[-3].nxdinfo;
        if(nxdinfo->nxdfile)
        {
          print_error("Multiple NeXus DICTFILE declarations found (%s).\n"
          "At most one NeXus DICTFILE declarations may "
          "be used in an instrument", nxdinfo->nxdfile);
        }
        else
        {
          nxdinfo->nxdfile     = yyvsp[-1].string;
          nxdinfo->hdfversion = atof(yyvsp[0].number);
        }
        nxdinfo->any = 1; /* Now need NeXus support in runtime */
        yyval.nxdinfo = nxdinfo;
      ;
    break;}
case 48:
#line 546 "instrument.y"
{
        yyval.string = str_cat(instrument_definition->name, ".dic", NULL);
      ;
    break;}
case 49:
#line 550 "instrument.y"
{
        yyval.string = yyvsp[0].string;
      ;
    break;}
case 50:
#line 555 "instrument.y"
{
        yyval.number = "4";
      ;
    break;}
case 51:
#line 559 "instrument.y"
{
        yyval.number = yyvsp[0].number;
      ;
    break;}
case 52:
#line 565 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 53:
#line 571 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 54:
#line 575 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 55:
#line 581 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 56:
#line 585 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 57:
#line 591 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 58:
#line 595 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 60:
#line 603 "instrument.y"
{
        comp_instances      = symtab_create();
        comp_instances_list = list_create();
        group_instances     = symtab_create();
        group_instances_list= list_create();
      ;
    break;}
case 61:
#line 610 "instrument.y"
{
        /* Check that the component instance name has not
                       been used before. */
        if(symtab_lookup(comp_instances, yyvsp[0].instance->name))
        {
          print_error("Multiple use of component instance name "
          "'%s' at line %s:%d.\n", yyvsp[0].instance->name, instr_current_filename, instr_current_line);
          /* Since this is an error condition, we do not
             worry about freeing the memory allocated for
       the component instance. */
        }
        else
        {
          symtab_add(comp_instances, yyvsp[0].instance->name, yyvsp[0].instance);
          list_add(comp_instances_list, yyvsp[0].instance);
          if(yyvsp[0].instance->def)
          {
            /* Check if the component handles polarisation. */
            if(yyvsp[0].instance->def->polarisation_par)
            {
              instrument_definition->polarised = 1;
            }
          }
        }
      ;
    break;}
case 62:
#line 638 "instrument.y"
{
        struct comp_def *def;
        struct comp_inst *comp;

        def = read_component(yyvsp[-5].string);
        if (def != NULL) def->comp_inst_number--;
        palloc(comp); /* Allocate new instance. */
        comp->name = yyvsp[-7].string;
        comp->type = yyvsp[-5].string;
        comp->def = def;
        palloc(comp->pos);
        comp->group = yyvsp[-1].groupinst;           /* ADD: E. Farhi Sep 24th, 2001 component is part of an exclusive group */
        comp->extend = yyvsp[0].ccode;  /* ADD: E. Farhi Sep 20th, 2001 EXTEND block*/
        comp->index = 0;       /* ADD: E. Farhi Sep 20th, 2001 index of comp instance */
        comp->pos->place = yyvsp[-3].place.place;
        comp->pos->place_rel = yyvsp[-3].place.place_rel;
        comp->pos->orientation = yyvsp[-2].ori.orientation;
        comp->pos->orientation_rel =
          yyvsp[-2].ori.isdefault ? yyvsp[-3].place.place_rel : yyvsp[-2].ori.orientation_rel;
        if(def != NULL)
        {
          /* Check actual parameters against definition and
                         setting parameters. */
          comp_formals_actuals(comp, yyvsp[-4].actuals);
        }
        str_free(yyvsp[-5].string);
        debugn((DEBUG_HIGH, "Component: %s.\n", yyvsp[-7].string));
        previous_comp = comp; /* this comp will be 'previous' for the next */
        yyval.instance = comp;
      ;
    break;}
case 63:
#line 671 "instrument.y"
{
        yyval.formals = yyvsp[-1].formals;
      ;
    break;}
case 64:
#line 678 "instrument.y"
{
        yyval.formals = list_create();
      ;
    break;}
case 65:
#line 682 "instrument.y"
{
        yyval.formals = yyvsp[0].formals;
      ;
    break;}
case 66:
#line 688 "instrument.y"
{
        yyval.formals = list_create();
        list_add(yyval.formals, yyvsp[0].string);
      ;
    break;}
case 67:
#line 693 "instrument.y"
{
        list_add(yyvsp[-2].formals, yyvsp[0].string);
        yyval.formals = yyvsp[-2].formals;
      ;
    break;}
case 68:
#line 700 "instrument.y"
{
        yyval.actuals = yyvsp[-1].actuals;
      ;
    break;}
case 69:
#line 706 "instrument.y"
{
        yyval.actuals = symtab_create();
      ;
    break;}
case 70:
#line 710 "instrument.y"
{
        yyval.actuals = yyvsp[0].actuals;
      ;
    break;}
case 71:
#line 716 "instrument.y"
{
        yyval.actuals = symtab_create();
        symtab_add(yyval.actuals, yyvsp[-2].string, yyvsp[0].exp);
        str_free(yyvsp[-2].string);
      ;
    break;}
case 72:
#line 722 "instrument.y"
{
        symtab_add(yyvsp[-4].actuals, yyvsp[-2].string, yyvsp[0].exp);
        str_free(yyvsp[-2].string);
        yyval.actuals = yyvsp[-4].actuals;
      ;
    break;}
case 73:
#line 730 "instrument.y"
{
        yyval.place.place = yyvsp[-1].coords;
        yyval.place.place_rel = yyvsp[0].instance;
      ;
    break;}
case 74:
#line 737 "instrument.y"
{
        yyval.ori.orientation = coords_exp_origo(); /* Default to (0,0,0). */
        yyval.ori.isdefault = 1; /* No ROTATED modifier was present */
      ;
    break;}
case 75:
#line 742 "instrument.y"
{
        yyval.ori.orientation = yyvsp[-1].coords;
        yyval.ori.orientation_rel = yyvsp[0].instance;
        yyval.ori.isdefault = 0;
      ;
    break;}
case 76:
#line 751 "instrument.y"
{
        yyval.instance = NULL;
      ;
    break;}
case 77:
#line 755 "instrument.y"
{
        if (previous_comp) {
          yyval.instance = previous_comp;
        } else {
          print_warn(NULL, "Found invalid PREVIOUS reference at line %s:%d. Using ABSOLUTE.\n", instr_current_filename, instr_current_line);
          yyval.instance = NULL;
        }
      ;
    break;}
case 78:
#line 764 "instrument.y"
{
        /* get the $4 previous item in comp_instances */
        struct Symtab_entry *entry;
        int index;
        index = atoi(yyvsp[-1].number);
        entry = symtab_previous(comp_instances, index);
        if (!index) { /* invalid index reference */
          print_warn(NULL, "Found invalid PREVIOUS(%i) reference at line %s:%d. Using ABSOLUTE.\n", index, instr_current_filename, instr_current_line);
          yyval.instance = NULL;
        } else {
          yyval.instance = entry->val;
        }
      ;
    break;}
case 79:
#line 778 "instrument.y"
{
        yyval.instance = yyvsp[0].instance;
      ;
    break;}
case 80:
#line 785 "instrument.y"
{
        yyval.groupinst = NULL;
      ;
    break;}
case 81:
#line 789 "instrument.y"
{
        yyval.groupinst = yyvsp[0].groupinst;
      ;
    break;}
case 82:
#line 795 "instrument.y"
{
        struct group_inst *group;
        struct Symtab_entry *ent;

        ent = symtab_lookup(group_instances, yyvsp[0].string);
        if(ent == NULL)
        {
          palloc(group);    /* create new group instance */
          group->name = yyvsp[0].string;
          group->index= 0;
          symtab_add(group_instances, yyvsp[0].string, group);
          list_add(group_instances_list, group);
        }
        else
          group = ent->val;
        yyval.groupinst = group;
      ;
    break;}
case 83:
#line 815 "instrument.y"
{
        struct comp_inst *comp;
        struct Symtab_entry *ent;

        ent = symtab_lookup(comp_instances, yyvsp[0].string);
        comp = NULL;
        if(ent == NULL)
          print_error("Reference to undefined component %s at line %s:%d.\n",
          yyvsp[0].string, instr_current_filename, instr_current_line);
        else
          comp = ent->val;
        str_free(yyvsp[0].string);
        yyval.instance = comp;
      ;
    break;}
case 84:
#line 832 "instrument.y"
{
        yyval.coords.x = yyvsp[-5].exp;
        yyval.coords.y = yyvsp[-3].exp;
        yyval.coords.z = yyvsp[-1].exp;
      ;
    break;}
case 85:
#line 841 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 86:
#line 845 "instrument.y"
{
        yyval.ccode = yyvsp[0].ccode;
      ;
    break;}
case 87:
#line 852 "instrument.y"
{ yyval.linenum = instr_current_line; ;
    break;}
case 88:
#line 853 "instrument.y"
{
        CExp e = yyvsp[0].exp;
        exp_setlineno(e, yyvsp[-1].linenum );
        yyval.exp = e;
      ;
    break;}
case 89:
#line 858 "instrument.y"
{ yyval.linenum = instr_current_line; ;
    break;}
case 90:
#line 859 "instrument.y"
{
        CExp e;
        /* Note: "EXTERN" is now obsolete and redundant. */
        e = exp_extern_id(yyvsp[0].string);
        exp_setlineno(e, yyvsp[-1].linenum );
        str_free(yyvsp[0].string);
        yyval.exp = e;
      ;
    break;}
case 91:
#line 870 "instrument.y"
{
        yyval.exp = yyvsp[0].exp;
      ;
    break;}
case 92:
#line 874 "instrument.y"
{
        yyval.exp = exp_compound(2, yyvsp[-1].exp, yyvsp[0].exp);
        exp_free(yyvsp[0].exp);
        exp_free(yyvsp[-1].exp);
      ;
    break;}
case 93:
#line 884 "instrument.y"
{
        List_handle liter;
        struct instr_formal *formal;
        /* Check if this is an instrument parameter or not. */
        /* ToDo: This will be inefficient if the number of
                       instrument parameters is really huge. */
        liter = list_iterate(instrument_definition->formals);
        while(formal = list_next(liter))
        {
          if(!strcmp(yyvsp[0].string, formal->id))
          {
            /* It was an instrument parameter */
            yyval.exp = exp_id(yyvsp[0].string);
            goto found;
          }
        }
        /* It was an external id. */
        yyval.exp = exp_extern_id(yyvsp[0].string);
      found:
        str_free(yyvsp[0].string);
      ;
    break;}
case 94:
#line 906 "instrument.y"
{
        yyval.exp = exp_number(yyvsp[0].number);
        str_free(yyvsp[0].number);
      ;
    break;}
case 95:
#line 911 "instrument.y"
{
        yyval.exp = exp_string(yyvsp[0].string);
        str_free(yyvsp[0].string);
      ;
    break;}
case 96:
#line 916 "instrument.y"
{
        yyval.exp = exp_ctoken(yyvsp[0].string);
        str_free(yyvsp[0].string);
      ;
    break;}
case 97:
#line 921 "instrument.y"
{
        yyval.exp = exp_ctoken("=");
      ;
    break;}
case 98:
#line 925 "instrument.y"
{
        yyval.exp = exp_ctoken("*");
      ;
    break;}
case 99:
#line 929 "instrument.y"
{
        CExp p1 = exp_ctoken("(");
        CExp p2 = exp_ctoken(")");
        yyval.exp = exp_compound(3, p1, yyvsp[-1].exp, p2);
        exp_free(p2);
        exp_free(p1);
        exp_free(yyvsp[-1].exp);
      ;
    break;}
case 100:
#line 938 "instrument.y"
{
        CExp p1 = exp_ctoken("(");
        CExp p2 = exp_ctoken(")");
        yyval.exp = exp_compound(2, p1, p2);
        exp_free(p2);
        exp_free(p1);
      ;
    break;}
case 101:
#line 946 "instrument.y"
{
        CExp p1 = exp_ctoken("[");
        CExp p2 = exp_ctoken("]");
        yyval.exp = exp_compound(3, p1, yyvsp[-1].exp, p2);
        exp_free(p2);
        exp_free(p1);
        exp_free(yyvsp[-1].exp);
      ;
    break;}
case 102:
#line 955 "instrument.y"
{
        CExp p1 = exp_ctoken("[");
        CExp p2 = exp_ctoken("]");
        yyval.exp = exp_compound(2, p1, p2);
        exp_free(p2);
        exp_free(p1);
      ;
    break;}
case 103:
#line 963 "instrument.y"
{
        CExp p1 = exp_ctoken("{");
        CExp p2 = exp_ctoken("}");
        yyval.exp = exp_compound(3, p1, yyvsp[-1].exp, p2);
        exp_free(p2);
        exp_free(p1);
        exp_free(yyvsp[-1].exp);
      ;
    break;}
case 104:
#line 972 "instrument.y"
{
        CExp p1 = exp_ctoken("{");
        CExp p2 = exp_ctoken("}");
        yyval.exp = exp_compound(2, p1, p2);
        exp_free(p2);
        exp_free(p1);
      ;
    break;}
case 105:
#line 983 "instrument.y"
{
        yyval.exp = yyvsp[0].exp;
      ;
    break;}
case 106:
#line 987 "instrument.y"
{
        yyval.exp = exp_compound(2, yyvsp[-1].exp, yyvsp[0].exp);
        exp_free(yyvsp[0].exp);
        exp_free(yyvsp[-1].exp);
      ;
    break;}
case 107:
#line 995 "instrument.y"
{
        yyval.exp = yyvsp[0].exp;
      ;
    break;}
case 108:
#line 999 "instrument.y"
{
        yyval.exp = exp_ctoken(",");
      ;
    break;}
case 109:
#line 1005 "instrument.y"
{
        yyvsp[-1].ccode->filename = instr_current_filename;
        yyvsp[-1].ccode->quoted_filename = str_quote(instr_current_filename);
        yyvsp[-1].ccode->linenum = yyvsp[-2].linenum;
        yyval.ccode = yyvsp[-1].ccode;
      ;
    break;}
case 110:
#line 1014 "instrument.y"
{
        yyval.ccode = codeblock_new();
      ;
    break;}
case 111:
#line 1019 "instrument.y"
{
        list_add(yyvsp[-1].ccode->lines, yyvsp[0].string);
        yyval.ccode = yyvsp[-1].ccode;
      ;
    break;}
}

#line 705 "/usr/local/share/bison/bison.simple"


  yyvsp -= yylen;
  yyssp -= yylen;
#if YYLSP_NEEDED
  yylsp -= yylen;
#endif

#if YYDEBUG
  if (yydebug)
    {
      short *yyssp1 = yyss - 1;
      YYFPRINTF (stderr, "state stack now");
      while (yyssp1 != yyssp)
	YYFPRINTF (stderr, " %d", *++yyssp1);
      YYFPRINTF (stderr, "\n");
    }
#endif

  *++yyvsp = yyval;
#if YYLSP_NEEDED
  *++yylsp = yyloc;
#endif

  /* Now `shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTBASE];

  goto yynewstate;


/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;

#ifdef YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (yyn > YYFLAG && yyn < YYLAST)
	{
	  YYSIZE_T yysize = 0;
	  char *yymsg;
	  int yyx, yycount;

	  yycount = 0;
	  /* Start YYX at -YYN if negative to avoid negative indexes in
	     YYCHECK.  */
	  for (yyx = yyn < 0 ? -yyn : 0;
	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
	    if (yycheck[yyx + yyn] == yyx)
	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
	  yysize += yystrlen ("parse error, unexpected ") + 1;
	  yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
	  yymsg = (char *) YYSTACK_ALLOC (yysize);
	  if (yymsg != 0)
	    {
	      char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
	      yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);

	      if (yycount < 5)
		{
		  yycount = 0;
		  for (yyx = yyn < 0 ? -yyn : 0;
		       yyx < (int) (sizeof (yytname) / sizeof (char *));
		       yyx++)
		    if (yycheck[yyx + yyn] == yyx)
		      {
			const char *yyq = ! yycount ? ", expecting " : " or ";
			yyp = yystpcpy (yyp, yyq);
			yyp = yystpcpy (yyp, yytname[yyx]);
			yycount++;
		      }
		}
	      yyerror (yymsg);
	      YYSTACK_FREE (yymsg);
	    }
	  else
	    yyerror ("parse error; also virtual memory exhausted");
	}
      else
#endif /* defined (YYERROR_VERBOSE) */
	yyerror ("parse error");
    }
  goto yyerrlab1;


/*--------------------------------------------------.
| yyerrlab1 -- error raised explicitly by an action |
`--------------------------------------------------*/
yyerrlab1:
  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
	 error, discard it.  */

      /* return failure if at end of input */
      if (yychar == YYEOF)
	YYABORT;
      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
		  yychar, yytname[yychar1]));
      yychar = YYEMPTY;
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */

  yyerrstatus = 3;		/* Each real token shifted decrements this */

  goto yyerrhandle;


/*-------------------------------------------------------------------.
| yyerrdefault -- current state does not do anything special for the |
| error token.                                                       |
`-------------------------------------------------------------------*/
yyerrdefault:
#if 0
  /* This is wrong; only states that explicitly want error tokens
     should shift them.  */

  /* If its default is to accept any token, ok.  Otherwise pop it.  */
  yyn = yydefact[yystate];
  if (yyn)
    goto yydefault;
#endif


/*---------------------------------------------------------------.
| yyerrpop -- pop the current state because it cannot handle the |
| error token                                                    |
`---------------------------------------------------------------*/
yyerrpop:
  if (yyssp == yyss)
    YYABORT;
  yyvsp--;
  yystate = *--yyssp;
#if YYLSP_NEEDED
  yylsp--;
#endif

#if YYDEBUG
  if (yydebug)
    {
      short *yyssp1 = yyss - 1;
      YYFPRINTF (stderr, "Error: state stack now");
      while (yyssp1 != yyssp)
	YYFPRINTF (stderr, " %d", *++yyssp1);
      YYFPRINTF (stderr, "\n");
    }
#endif

/*--------------.
| yyerrhandle.  |
`--------------*/
yyerrhandle:
  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yyerrdefault;

  yyn += YYTERROR;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
    goto yyerrdefault;

  yyn = yytable[yyn];
  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrpop;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrpop;

  if (yyn == YYFINAL)
    YYACCEPT;

  YYDPRINTF ((stderr, "Shifting error token, "));

  *++yyvsp = yylval;
#if YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

/*---------------------------------------------.
| yyoverflowab -- parser overflow comes here.  |
`---------------------------------------------*/
yyoverflowlab:
  yyerror ("parser stack overflow");
  yyresult = 2;
  /* Fall through.  */

yyreturn:
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
  return yyresult;
}
#line 1025 "instrument.y"


static Pool parser_pool = NULL; /* Pool of parser allocations. */

static int mc_yyparse(void)
{
  int ret;
  Pool oldpool;

  oldpool = parser_pool;
  parser_pool = pool_create();
  ret = yyparse();
  pool_free(parser_pool);
  parser_pool = oldpool;
  return ret;
}

/* Name of the file currently being parsed. */
char *instr_current_filename = NULL;
/* Number of the line currently being parsed. */
int instr_current_line = 0;

/* Result from parsing instrument definition. */
struct instr_def *instrument_definition;

/* Map from names to component instances. */
Symtab comp_instances;

/* Will store component instance for PREVIOUS reference */
struct comp_inst *previous_comp=NULL;

/* ADD: E. Farhi Sep 24th, 2001 Map from names to component group instances. */
Symtab group_instances;

/* Map from names to embedded libraries */
Symtab lib_instances;

/* List of components, in the order they where declared in the instrument
   definition. */
List comp_instances_list;

/* List of component groups, in the order they where declared in the instrument
   definition. */
List group_instances_list;

/* Filename for outputting generated simulation program ('-' means stdin). */
static char *output_filename;

/* Verbose parsing/code generation */
char verbose;

/* Map of already-read components. */
Symtab read_components = NULL;

/* Print a summary of the command usage and exit with error. */
static void
print_usage(void)
{
  fprintf(stderr, "Usage:\n"
    "  mcstas [-o file] [-I dir1 ...] [-t] [-p] [-v] "
    "[--no-main] [--no-runtime] [--verbose] file\n");
  fprintf(stderr, "      -o FILE --output-file=FILE Place C output in file FILE.\n");
  fprintf(stderr, "      -I DIR  --search-dir=DIR   Append DIR to the component search list. \n");
  fprintf(stderr, "      -t      --trace            Enable 'trace' mode for instrument display.\n");
  fprintf(stderr, "      -v      --version          Prints McStas version.\n");
  fprintf(stderr, "      --no-main                  Do not create main(), for external embedding.\n");
  fprintf(stderr, "      --no-runtime               Do not embed run-time libraries.\n");
  fprintf(stderr, "      --verbose                  Display compilation process steps.\n");
  fprintf(stderr, "  The file will be processed and translated into a C code program.\n");
  fprintf(stderr, "  The default component search list is usually defined by the 'MCSTAS'\n");
  fprintf(stderr, "  environment variable. Use 'mcrun' to both run mcstas and the C compiler.\n");
  fprintf(stderr, "  If run-time libraries are not embedded, you will have to pre-compile\n");
  fprintf(stderr, "  them (.c -> .o) before assembling the program.\n");
  fprintf(stderr, "SEE ALSO: mcrun, mcplot, mcdisplay, mcresplot, mcstas2vitess, mcgui\n");
  fprintf(stderr, "DOC:      Please visit http://neutron.risoe.dk/mcstas/\n");
  exit(1);
}

/* Print McStas version and copyright. */
static void
print_version(void)
{ /* MOD: E. Farhi Sep 20th, 2001 version number */
  printf("McStas version " MCSTAS_VERSION "\n"
    "Copyright (C) Risoe National Laboratory, 1997-2004\n"
    "Additions (C) Institut Laue Langevin, 2003-2004\n"
    "All rights reserved\n");
  exit(0);
}

/* Construct default filename for simulation output from instrument file
   name. Strip any leading directory path and trailing .instr, and add .c to
   the end. */
static char *
make_output_filename(char *name)
{
  char *p;
  int l;

  /* Find basename */
  p = strrchr(name, '/');
  if(p == NULL)
    p = name;     /* No initial path. */
  else
    p++;      /* Point past last '/' character. */

  /* Check for trailing .instr suffix. */
  l = strlen(p);
  if(l > 6 && !strcmp(&p[l - 6], ".instr"))
  {
    char *tmp = str_dup(p);
    tmp[l - 6] = '\0';
    p = str_cat(tmp, ".c", NULL);
    str_free(tmp);
  }
  else
    p = str_cat(p, ".c", NULL);
  return p;
}


static void
set_output_filename(char *name)
{
  output_filename = str_dup(name);
}

/* Parse command line options. */
static void
parse_command_line(int argc, char *argv[])
{
  int i;

  output_filename = NULL;
  verbose = 0;
  instr_current_filename = NULL;
  instrument_definition->use_default_main = 1;
  instrument_definition->include_runtime = 1;
  instrument_definition->enable_trace = 0;
  instrument_definition->portable = 0;
  instrument_definition->polarised = 0;
  for(i = 1; i < argc; i++)
  {
    if(!strcmp("-o", argv[i]) && (i + 1) < argc)
      set_output_filename(argv[++i]);
    else if(!strncmp("-o", argv[i], 2))
      set_output_filename(&argv[i][2]);
    else if(!strcmp("--output-file", argv[i]) && (i + 1) < argc)
      set_output_filename(argv[++i]);
    else if(!strncmp("--output-file=", argv[i], 14))
      set_output_filename(&argv[i][14]);
    else if(!strcmp("-I", argv[i]) && (i + 1) < argc)
      add_search_dir(argv[++i]);
    else if(!strncmp("-I", argv[i], 2))
      add_search_dir(&argv[i][2]);
    else if(!strcmp("--search-dir", argv[i]) && (i + 1) < argc)
      add_search_dir(argv[++i]);
    else if(!strncmp("--search-dir=", argv[i], 13))
      add_search_dir(&argv[i][13]);
    else if(!strcmp("-t", argv[i]))
      instrument_definition->enable_trace = 1;
    else if(!strcmp("--trace", argv[i]))
      instrument_definition->enable_trace = 1;
    else if(!strcmp("-p", argv[i]))
      instrument_definition->portable = 1;
    else if(!strcmp("--portable", argv[i]))
      instrument_definition->portable = 1;
    else if(!strcmp("-v", argv[i]))
      print_version();
    else if(!strcmp("--version", argv[i]))
      print_version();
    else if(!strcmp("--verbose", argv[i]))
      verbose = 1;
    else if(!strcmp("--no-main", argv[i]))
      instrument_definition->use_default_main = 0;
    else if(!strcmp("--no-runtime", argv[i]))
      instrument_definition->include_runtime = 0;
    else if(argv[i][0] != '-')
    {
      if(instr_current_filename != NULL)
        print_usage();    /* Multiple instruments given. */
      instr_current_filename = str_dup(argv[i]);
    }
    else
      print_usage();
  }

  /* Instrument filename must be given. */
  if(instr_current_filename == NULL)
    print_usage();
  /* If no '-o' option was given for INSTR.instr, default to INSTR.c  */
  if(output_filename == NULL)
    output_filename = make_output_filename(instr_current_filename);
}


int
main(int argc, char *argv[])
{
  FILE *file;
  int err;

#ifdef MAC
  argc = ccommand(&argv);
#endif

  yydebug = 0;      /* If 1, then bison gives verbose parser debug info. */

  palloc(instrument_definition); /* Allocate instrument def. structure. */
  parse_command_line(argc, argv);
  if(!strcmp(instr_current_filename, "-"))
  {
    instrument_definition->source = str_dup("<stdin>");
    file = fdopen(0, "r");  /* Lone '-' designates stdin. */
  }
  else
  {
    instrument_definition->source = str_dup(instr_current_filename);
    file = fopen(instr_current_filename, "r");
  }
  if(file == NULL)
    fatal_error("Instrument definition file `%s' not found\n",
    instr_current_filename);
  instrument_definition->quoted_source =
    str_quote(instrument_definition->source);
  instr_current_line = 1;
  lex_new_file(file);
  read_components = symtab_create(); /* Create table of components. */
  lib_instances   = symtab_create(); /* Create table of libraries. */
  err = mc_yyparse();
  fclose(file);
  if(err != 0 || error_encountered != 0)
  {
    print_error("Errors encountered during parse.\n");
    exit(1);
  }
  else
  {

    cogen(output_filename, instrument_definition);
    if (verbose) fprintf(stderr, "Generating code     %s\n", output_filename);
    exit(0);
  }
}


int
yyerror(char *s)
{
  print_error("%s at line %d.\n", s, instr_current_line);
  return 0;
}


/*******************************************************************************
* Check that all formal parameters of a component definition are unique.
*******************************************************************************/
void
check_comp_formals(List deflist, List setlist, char *compname)
{
  Symtab formals;
  struct comp_iformal *formal;
  struct Symtab_entry *entry;
  List_handle liter;

  /* We check the uniqueness by adding all the formals to a symbol table with
     a dummy pointer value. Any formal parameter that already appears in the
     symbol table is an error. */
  formals = symtab_create();
  liter = list_iterate(deflist);
  while(formal = list_next(liter))
  {
    entry = symtab_lookup(formals, formal->id);
    if(entry != NULL)
      print_error("Definition parameter name %s is used multiple times "
      "in component %s\n", formal->id, compname);
    else
      symtab_add(formals, formal->id, NULL);
  }
  list_iterate_end(liter);
  liter = list_iterate(setlist);
  while(formal = list_next(liter))
  {
    entry = symtab_lookup(formals, formal->id);
    if(entry != NULL)
      print_error("Setting parameter name %s is used multiple times "
      "in component %s\n", formal->id, compname);
    else
      symtab_add(formals, formal->id, NULL);
  }
  list_iterate_end(liter);
  symtab_free(formals, NULL);
}


/*******************************************************************************
* Check that all formal parameters of an instrument definition are unique.
*******************************************************************************/
void
check_instrument_formals(List formallist, char *instrname)
{
  Symtab formals;
  struct instr_formal *formal;
  struct Symtab_entry *entry;
  List_handle liter;

  /* We check the uniqueness by adding all the formals to a symbol table with
     a dummy pointer value. Any formal parameter that already appears in the
     symbol table is an error. */
  formals = symtab_create();
  liter = list_iterate(formallist);
  while(formal = list_next(liter))
  {
    entry = symtab_lookup(formals, formal->id);
    if(entry != NULL)
      print_error("Instrument parameter name %s is used multiple times "
      "in instrument %s\n", formal->id, instrname);
    else
      symtab_add(formals, formal->id, NULL);
  }
  list_iterate_end(liter);
  symtab_free(formals, NULL);
}

/*******************************************************************************
* Check the actual parameters to a component against the formal parameters.
*******************************************************************************/
void
comp_formals_actuals(struct comp_inst *comp, Symtab actuals)
{
  List_handle liter;
  struct comp_iformal *formal;
  struct Symtab_entry *entry;
  Symtab defpar, setpar;
  Symtab_handle siter;

  /* We need to check
     1. That all actual parameters correspond to formal parameters.
     2. That all formal parameters are assigned actual parameters. */

  /* First check the formal parameters one by one. */
  defpar = symtab_create();
  setpar = symtab_create();
  liter = list_iterate(comp->def->def_par);
  while(formal = list_next(liter))
  {
    entry = symtab_lookup(actuals, formal->id);
    if(entry == NULL)
    {
      if(formal->isoptional)
      {
        /* Use default value for unassigned optional parameter */
        symtab_add(defpar, formal->id, formal->default_value);
      } else {
        print_error("Unassigned definition parameter %s for component %s.\n",
              formal->id, comp->name);
        symtab_add(defpar, formal->id, exp_number("0.0"));
      }
    } else {
      symtab_add(defpar, formal->id, entry->val);
      /* Ensure that the actual DEFINITION parameters are all values
         (identifiers, constant numbers, and constant strings). This is
         necessary to avoid duplication of computations or side effects in the
         expressions for the actual parameters, since DEFINITION parameters
         are assigned using #define's. */
      if(!exp_isvalue(entry->val))
      {
	print_warn(NULL, "Using DEFINITION parameter of component %s (potential syntax error)\n"
		"  %s=%s\n",
		comp->name, formal->id, exp_tostring(entry->val));
      }
    }
  }
  list_iterate_end(liter);
  liter = list_iterate(comp->def->set_par);
  while(formal = list_next(liter))
  {
    entry = symtab_lookup(actuals, formal->id);
    if(entry == NULL)
    {
      if(formal->isoptional)
      {
        /* Use default value for unassigned optional parameter */
        symtab_add(setpar, formal->id, formal->default_value);
      } else {
        print_error("Unassigned setting parameter %s for component %s.\n",
              formal->id, comp->name);
        symtab_add(setpar, formal->id, exp_number("0.0"));
      }
    } else {
      symtab_add(setpar, formal->id, entry->val);
    }
  }
  list_iterate_end(liter);

  /* Now check the actual parameters one by one. */
  siter = symtab_iterate(actuals);
  while(entry = symtab_next(siter))
  {
    if(symtab_lookup(defpar, entry->name) == NULL &&
       symtab_lookup(setpar, entry->name) == NULL)
    {
      print_error("Unmatched actual parameter %s for component %s.\n",
      entry->name, comp->name);
    }
  }
  comp->defpar = defpar;
  comp->setpar = setpar;
}


/*******************************************************************************
* This is the main entry point for reading a component. When a component
* definition is needed, this function is called with the name of the
* component. A map of previously read components is maintained. If a
* component definition (struct comp)def) is found, it is returned. Otherwise
* an attempt is made to read the component definition from a file with the
* same name as the component with added file extension ".com".
* If for some reasons the component cannot be read, NULL is returned; else a
* pointer to a struct comp_def is returned. Since components definitions can
* be used multiple times, the returned structure is shared and should not be
* modified.
*******************************************************************************/
struct comp_def *
read_component(char *name)
{
  struct Symtab_entry *entry;

  /* Look for an existing definition for the component. */
  entry = symtab_lookup(read_components, name);
  if(entry != NULL)
  {
    return entry->val;    /* Return it if found. */
  }
  else
  {
    FILE *file;
    int err;

    /* Attempt to read definition from file components/<name>.com. */
    file = open_component_search(name);
    if(file == NULL)
    {
      print_error(
        "Cannot find file containing definition of component `%s'.\n", name);
      return NULL;
    }
    push_autoload(file);
    /* Note: the str_dup copy of the file name is stored in codeblocks, and
       must not be freed. */
    instr_current_filename = component_pathname;
    instr_current_line = 1;
    err = mc_yyparse();   /* Read definition from file. */
    if(err != 0)
      fatal_error("Errors encountered during autoload of component %s.\n",
        name);
    fclose(file);
    /* Now check if the file contained the required component definition. */
    entry = symtab_lookup(read_components, name);
    if(entry != NULL)
    {
      return entry->val;
    }
    else
    {
      print_error("Definition of component %s not found.\n", name);
      return NULL;
    }
  }
}


syntax highlighted by Code2HTML, v. 0.9.1