TransitionParser.y

Go to the documentation of this file.
00001 %{
00002   /*
00003    * Copyright (C) 2010, Jonathan S. Shapiro
00004    * Portions Copyright (C) 2008, The EROS Group, LLC.
00005    * All rights reserved.
00006    *
00007    * Redistribution and use in source and binary forms, with or
00008    * without modification, are permitted provided that the following
00009    * conditions are met:
00010    *
00011    *   - Redistributions of source code must contain the above
00012    *     copyright notice, this list of conditions, and the following
00013    *     disclaimer.
00014    *
00015    *   - Redistributions in binary form must reproduce the above
00016    *     copyright notice, this list of conditions, and the following
00017    *     disclaimer in the documentation and/or other materials
00018    *     provided with the distribution.
00019    *
00020    *   - Neither the names of the copyright holders nor the names of any
00021    *     of any contributors may be used to endorse or promote products
00022    *     derived from this software without specific prior written
00023    *     permission.
00024    *
00025    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036    */
00037 
00044 
00045 #include <sys/fcntl.h>
00046 #include <sys/stat.h>
00047 #include <getopt.h>
00048 #include <string.h>
00049 #include <stdlib.h>
00050 #include <stdio.h>
00051 #include <unistd.h>
00052 #include <assert.h>
00053 #include <dirent.h>
00054 #include <iostream>
00055 
00056 #include <string>
00057 
00058 #include "Version.hxx"
00059 #include "AST.hxx"
00060 #include "ParseType.hxx"
00061 #include "UocInfo.hxx"
00062 #include "Options.hxx"
00063 
00064 using namespace boost;
00065 using namespace sherpa;
00066 using namespace std;
00067 
00068 #define YYSTYPE ParseType
00069 #define YYLEX_PARAM (TransitionLexer *)lexer
00070 
00071 // We disable yyerror entirely, because it emits whenever "error" is
00072 // shifted, and we're going to take over error handling for ourselves
00073 // (entirely). Unfortunately we cannot use YYRECOVERING() to make
00074 // error printing decisions, because that's already set by the time
00075 // the error action is being run (which is where we print our
00076 // message). We therefore use a scheme by which yyerror signals to us
00077 // that the next error message should be printed.
00078 #undef yyerror
00079 #define yyerror(lexer, s) lexer->showNextError = true
00080 
00081 #include "TransitionLexer.hxx"
00082 
00083 #define SHOWPARSE(s)                           \
00084   do {                                         \
00085     if (Options::showParse)                    \
00086       lexer->errStream << (s) << std::endl;    \
00087   } while (false);
00088 
00089 #define SHOWPARSE1(s,x)                                    \
00090   do {                                                     \
00091     if (Options::showParse)                                \
00092       lexer->errStream << (s) << " " << (x) << std::endl;  \
00093   } while (false);
00094 
00095 static void PrintSyntaxError(TransitionLexer *lexer, const char *s);
00096 #define syntaxError(s) PrintSyntaxError(lexer, (s))
00097 
00098 inline int
00099 transition_lex(YYSTYPE *lvalp, TransitionLexer *lexer)
00100 {
00101   extern int yydebug;
00102 
00103   // yydebug = 1;
00104   return lexer->lex(lvalp);
00105 }
00106 
00107 // If the passed exprSeq has a documentation string at the front,
00108 // remove it. Note that if the exprSeq has length 1 then the string is
00109 // the expression value and not a documentation comment.
00110 static shared_ptr<AST>
00111 stripDocString(shared_ptr<AST> exprSeq)
00112 {
00113   if (exprSeq->children.size() > 1 &&
00114       exprSeq->child(0)->astType == at_stringLiteral)
00115     exprSeq->disown(0);
00116 
00117   return exprSeq;
00118 }
00119 
00120 static unsigned VersionMajor(const std::string s)
00121 {
00122   std::string::size_type dotPos = s.find('.');
00123   return strtoul(s.substr(0, dotPos).c_str(), 0, 10);
00124 }
00125 
00126 static unsigned VersionMinor(const std::string s)
00127 {
00128   std::string::size_type dotPos = s.find('.');
00129   return strtoul(s.substr(dotPos+1, s.size()).c_str(), 0, 10);
00130 }
00131 
00132 %}
00133 
00134 // We currently have 3 shift/reduce ambiguities of the form
00135 //   x -> a
00136 //   x -> a ( {args} )
00137 //
00138 // that are resolved by explicit prioritization.
00139 // 
00140 // The first is type = identifier vs type = type application
00141 // The second is parameterized type names (with or without type vars)
00142 // The third is constraint = identifier vs constraint = type app
00143 //
00144 // We have one that is the classic dangling if/then/else problem. This
00145 // one probably *should* be resolved by explicit prioritization.
00146 //
00147 // We have ten associated with opt_docstring in the s-expression
00148 // grammar that will be going away when the s-expression syntax is
00149 // dropped.
00150 //
00151 // We will undoubtedly see another when we introduce procedure
00152 // application syntax.
00153 //
00154 // There are a large number of others, mainly due to optional
00155 // semicolons.
00156 //
00157 // In C, we would resolve this by introducing associativity for '(',
00158 // but I'm not convinced that we can do that safely until we are fully
00159 // done with the s-expression syntax.
00160 %pure-parser
00161 %token-table
00162 %parse-param {TransitionLexer *lexer}
00163 
00164  /* Place-holder "low priority" terminal for use in %prec */
00165 %nonassoc <tok> prec_PreferShift
00166 
00167 %nonassoc <tok> tk_ReservedWord        /* reserved words */
00168 
00169 /* Categorical terminals: */
00170 %nonassoc <tok> tk_BlkIdent
00171 %nonassoc <tok> tk_NotApply
00172 
00173 %token <tok> tk_TypeVar
00174 %token <tok> tk_EffectVar
00175  /* Nat and NegativeInt are distinguished to ensure that only naturals
00176     are legal in types. The lexer returns tk_Nat for positive integer
00177     literals and tk_NegativeInt for negative integer literals. In the
00178     expression grammar these are re-merged immediately in the IntLit
00179     production. 
00180 
00181     Actually, this distinction reflects a bug in the grammar in the
00182     handling of unary negation. The lexer should really be returning
00183     tk_Nat at all times, and negation should be getting handled at
00184     the grammar level. */
00185 %token <tok> tk_NegativeInt     /* S-expression only */
00186 %token <tok> tk_Nat         /* in block: *postive* integer */
00187 %token <tok> tk_Float       /* in block: *postive* float */
00188 %token <tok> tk_Char
00189 %token <tok> tk_String
00190 %token <tok> tk_VersionNumber
00191 
00192 %nonassoc <tok> '('
00193 %nonassoc <tok> ':'
00194 %nonassoc <tok> ')'                /* procedure call, unit */
00195 %right    <tok> ','                /* pair */
00196 %nonassoc <tok> '{' '}' ';'
00197 %nonassoc <tok> '[' ']'            /* array, vector */
00198 %left     <tok> '.'
00199 %nonassoc <tok> tk_ASSIGN
00200 
00201 /* Primary types and associated hand-recognized literals: */
00202 %token <tok> tk_AS
00203 %token <tok> tk_BOOL
00204 %token <tok> tk_TRUE   /* #t */
00205 %token <tok> tk_FALSE  /* #f */
00206 %token <tok> tk_CHAR
00207 %token <tok> tk_STRING
00208 %token <tok> tk_FLOAT
00209 %token <tok> tk_DOUBLE
00210 %token <tok> tk_DUP
00211 %token <tok> tk_QUAD
00212 %token <tok> tk_INT8
00213 %token <tok> tk_INT16
00214 %token <tok> tk_INT32
00215 %token <tok> tk_INT64
00216 %token <tok> tk_UINT8
00217 %token <tok> tk_UINT16
00218 %token <tok> tk_UINT32
00219 %token <tok> tk_UINT64
00220 %token <tok> tk_WORD
00221 
00222 %token <tok> tk_MIXFIX          /* for testing */
00223 
00224 %token <tok> tk_SIZEOF
00225 %token <tok> tk_BITSIZEOF
00226 
00227 %token <tok> tk_BITFIELD
00228 %token <tok> tk_FILL
00229 %token <tok> tk_RESERVED
00230 %token <tok> tk_WHERE
00231 %token <tok> tk_IS
00232 
00233 %token <tok> tk_BITC
00234 %token <tok> tk_VERSION
00235 
00236 %token <tok> tk_PURE
00237 %token <tok> tk_IMPURE
00238 %token <tok> tk_CONST
00239 
00240 /* The following are on separate lines so that tk_ELSE has slightly
00241    higher precedence than tk_THEN. This lets us use %prec to
00242    explicitly resolve the S/R ambiguity for dangling else. */
00243 %token <tok> tk_IF
00244 %nonassoc <tok> tk_THEN
00245 %nonassoc <tok> tk_ELSE
00246 
00247 // %token <tok> tk_THE
00248 
00249 %token <tok> tk_WHEN tk_UNLESS
00250 %token <tok> tk_COND
00251 %token <tok> tk_SWITCH
00252 %token <tok> tk_TYPECASE
00253 %left <tok> tk_CASE
00254 %nonassoc <tok> tk_OTHERWISE
00255 
00256 // MIXFIX: No more infix operators now that we have mixfix. AND an OR
00257 // are handled as special cases in the mixfix engine.
00258 
00259 %left <tok> tk_AND tk_OR
00260 %left <tok> tk_EQUALS
00261 // %left <tok> tk_NOTEQUALS
00262 
00263 %left <tok> '='
00264 
00265 %token <tok> tk_LABEL
00266 %token <tok> tk_RETURN tk_FROM tk_CONTINUE
00267 
00268 // MIXFIX:These are regrettably going to get tricky to handle...
00269 %token <tok> tk_PAIR
00270 %token <tok> tk_VECTOR
00271 %token <tok> tk_ARRAY
00272 %token <tok> tk_MAKE_VECTOR
00273 
00274 // Block syntax:
00275 %token <tok> tk_STRUCT
00276 %token <tok> tk_OBJECT
00277 %token <tok> tk_UNION
00278 %token <tok> tk_REPR
00279 %token <tok> tk_EXCEPTION
00280 %token <tok> tk_TRAIT
00281 %token <tok> tk_INSTANCE
00282 %token <tok> tk_DEF
00283 
00284 // S-expr syntax:
00285 %token <tok> tk_DEFTHM
00286 %token <tok> tk_DECLARE
00287 // %token <tok> tk_PROCLAIM
00288 %token <tok> tk_EXTERNAL
00289 %token <tok> tk_TAG
00290 
00291 %token <tok> tk_MUTABLE
00292 %token <tok> tk_DEREF
00293 %token <tok> tk_INNER_REF
00294 %token <tok> tk_UNBOXED
00295 %token <tok> tk_BOXED
00296 %left <tok> tk_PTR
00297 %token <tok> tk_OPAQUE
00298 %token <tok> tk_CLOSED
00299 %token <tok> tk_MEMBER
00300 %token <tok> tk_LAMBDA
00301 %token <tok> tk_LET
00302 %token <tok> tk_LETREC
00303 %token <tok> tk_IN
00304 %token <tok> tk_FN
00305 %token <tok> tk_FNARROW
00306 %token <tok> tk_BEGIN
00307 %token <tok> tk_LOOP
00308 %token <tok> tk_DO
00309 %token <tok> tk_UNTIL
00310 %token <tok> tk_APPLY
00311 %token <tok> tk_BY_REF
00312 %token <tok> tk_ARRAY_REF
00313 
00314 %token <tok> tk_TRY
00315 %token <tok> tk_CATCH
00316 %token <tok> tk_HANDLE
00317 %token <tok> tk_THROW
00318 
00319 %token <tok> tk_METHOD
00320 %token <tok> tk_FORALL
00321 
00322 %token <tok> tk_INTERFACE
00323 %token <tok> tk_MODULE
00324 // token tk_USESEL historic significance only
00325 // %token <tok> tk_USESEL
00326 %token <tok> tk_IMPORT
00327 %token <tok> tk_PROVIDE
00328 
00329 //%token <tok> tk_SUPER
00330 %token <tok> tk_SUSPEND
00331 %type <tok>  blk_ifident
00332 
00333 //%token <tok> tk_EXPORT
00334  
00335 %type <ast> trn_module trn_implicit_module trn_module_seq
00336 %type <ast> trn_interface
00337 %type <ast> blk_defpattern
00338 %type <ast> blk_mod_definition
00339 %type <ast> trn_mod_definitions trn_mod_definition
00340 %type <ast> trn_if_definitions trn_if_definition
00341 %type <ast> blk_common_definition
00342 %type <ast> blk_value_declaration
00343 %type <ast> blk_val blk_optval
00344 %type <ast> blk_openclosed
00345 %type <ast> blk_ptype_name
00346 %type <ast> blk_typeapp
00347 %type <ast> blk_type_definition blk_type_decl
00348 %type <ast> blk_externals
00349 %type <ast> blk_importList blk_provideList
00350 %type <ast> blk_alias
00351 %type <ast> blk_type_cpair
00352 %type <ast> blk_value_definition blk_fndef_tail
00353 %type <ast> blk_tc_definition blk_ti_definition
00354 %type <ast> blk_import_definition blk_provide_definition
00355 %type <ast> blk_tc_decls // blk_tc_decl
00356 %type <ast> blk_opt_declares blk_declares blk_declare blk_decl
00357 %type <ast> blk_constructors blk_constructor
00358 %type <ast> blk_repr_constructors blk_repr_constructor
00359 %type <ast> blk_repr_reprs blk_repr_repr
00360 %type <ast> blk_bindingpattern blk_lambdapatterns blk_lambdapattern
00361 %type <ast> blk_actual_params blk_nonempty_params
00362 %type <ast> blk_iblock
00363 %type <ast> blk_expr_seq
00364 // Primary exprs are the truly primitive things.
00365 // Closed exprs are things like LET, DO, WHILE that are bracketed on
00366 // all sides.
00367 %type <ast> blk_expr_primary
00368 %type <ast> blk_expr_apply
00369 
00370 %type <ast> blk_expr
00371 
00372 %type <ast> blk_expr_mixfix blk_mixfix_elem
00373 %type <ast> blk_mixfix_arglist
00374 
00375 %type <ast> blk_expr_if_then_else blk_expr_when blk_expr_unless
00376 %type <ast> blk_expr_switch
00377 %type <ast> blk_expr_try
00378 %type <ast> blk_expr_let blk_expr_letrec
00379 %type <ast> blk_expr_loop
00380 %type <ast> blk_expr_return blk_expr_from_return
00381 %type <ast> blk_expr_throw
00382 %type <ast> blk_expr_lambda
00383 %type <ast> blk_expr_continue
00384 
00385 // %type <ast> sxp_method_decls sxp_method_decl
00386 %type <ast> blk_method_decls blk_method_decl
00387 // %type <ast> sxp_method_bindings sxp_method_binding
00388 %type <ast> blk_method_bindings blk_method_binding
00389 %type <ast> blk_constraints blk_constraint_seq blk_constraint
00390 
00391 // in order of precedence, *lowest* first:
00392 %type <ast> blk_type
00393 %type <ast> blk_postfix_type
00394 %type <ast> blk_prefix_type
00395 %type <ast> primary_type
00396 %type <ast> blk_primary_type
00397 
00398 %type <ast> blk_type_args blk_bitfieldtype
00399 %type <ast> blk_field_type blk_type_pl_byref blk_type_args_pl_byref
00400 %type <ast> int_type uint_type any_int_type float_type bool_type
00401 %type <ast> blk_tvlist
00402 %type <ast> blk_fields blk_field
00403 %type <ast> blk_fields_and_methods blk_methods_only blk_methdecl
00404 %type <ast> trn_literal typevar //mod_ident
00405 %type <ast> blk_expr_switch_matches blk_expr_switch_match
00406 %type <ast> blk_exident
00407 %type <ast> blk_fntype blk_method_type
00408 %type <ast> trn_fneffect
00409 %type <ast> blk_sw_legs blk_sw_leg
00410 %type <ast> blk_otherwise blk_opt_otherwise
00411 %type <ast> blk_letbindings blk_letbinding
00412 %type <ast> blk_loopbindings blk_nonempty_loopbindings blk_expr_loopbinding
00413 %type <ast> blk_type_val_definition
00414 %type <ast> blk_ident blk_defident blk_useident
00415 %type <ast> intLit natLit floatLit charLit strLit boolLit
00416 
00417 %type <tok> ILCB  IRCB   // one inserted by layout
00418 %type <tok> OptRCB
00419 %type <tok> IsILCB  // Used in types
00420 
00421 %%
00422 
00423 // Parser built for version 10.0
00424 // Section Numbers indicated within []
00425 
00426 // COMPILATION UNITS [2.5]
00427 // This definition of start must be changed as it ignores
00428 // junk after the body.
00429 
00430 start: ILCB blk_version ';' trn_uoc_body IRCB {
00431   SHOWPARSE("start -> ILCB blk_version SC trn_uoc_body IRCB");
00432   return 0;
00433 };
00434 
00435 start: error {
00436   syntaxError("input");
00437   return -1;
00438 }
00439 
00440 trn_uoc_body: trn_interface {
00441   SHOWPARSE("trn_uoc_body -> trn_interface");
00442 }
00443 
00444 trn_uoc_body: trn_implicit_module {
00445   SHOWPARSE("trn_uoc_body -> trn_implicit_module");
00446 }
00447 
00448 trn_uoc_body: trn_module_seq {
00449   SHOWPARSE("trn_uoc_body -> trn_module_seq");
00450 }
00451 
00452 // VERSION [2.5]
00453 blk_version: tk_BITC {
00454     lexer->currentLang |= TransitionLexer::lf_version; 
00455 } tk_VERSION {
00456     lexer->currentLang |= TransitionLexer::lf_version; 
00457 } tk_VersionNumber {
00458   SHOWPARSE("blk_version -> BITC VERSION VersionNumber");
00459   shared_ptr<AST> version = AST::makeStringLit($5);
00460 
00461   if ((VersionMajor(version->s) == 0) && (VersionMinor(version->s) < 11)) {
00462     std::string s = ": Error: block syntax is supported in versions 0.11 and above.";
00463     lexer->ReportParseError(version->loc, s);
00464   }
00465 };
00466 
00467 // INTERFACES [8.1]
00468 trn_interface: tk_INTERFACE blk_ifident {
00469     if ($2.str.find("bitc.") == 0)
00470       lexer->isRuntimeUoc = true;
00471   }
00472   IsILCB {
00473     lexer->layoutStack->precedingToken = tk_INTERFACE;
00474   } trn_if_definitions IRCB {
00475   SHOWPARSE("trn_interface -> INTERFACE blk_ifident IS { trn_if_definitions }");
00476   shared_ptr<AST> ifIdent = AST::make(at_ident, $2);
00477   $$ = AST::make(at_interface, $1.loc, ifIdent);
00478   $$->addChildrenFrom($6);
00479 
00480   if (lexer->isCommandLineInput) {
00481     const char *s =
00482       ": Warning: interface units of compilation should no longer\n"
00483       "    be given on the command line.\n";
00484     lexer->ReportParseWarning($$->loc, s);
00485   }
00486 
00487   std::string uocName = ifIdent->s;
00488   shared_ptr<UocInfo> uoc =
00489     UocInfo::make(uocName, lexer->here.origin, $$);
00490 
00491   if (uocName == "bitc.prelude")
00492     uoc->flags |= UOC_IS_PRELUDE;
00493 
00494   shared_ptr<UocInfo> existingUoc = UocInfo::findInterface(uocName);
00495 
00496   if (existingUoc) {
00497     std::string s = "Error: This sxp_interface has already been loaded from "
00498       + existingUoc->uocAst->loc.asString();
00499     lexer->ReportParseError($$->loc, s);
00500 
00501   }
00502   else  {
00503     /* Put the UoC onto the sxp_interface list so that we do not recurse on
00504        import. */
00505     UocInfo::ifList[uocName] = uoc;
00506   }
00507   
00508   // Regardless, compile the new sxp_interface to check for further
00509   // warnings and/or errors:
00510   uoc->Compile();
00511 };
00512 
00513 // When IfIdentMode is set we are matching fully legal interface
00514 // identifiers in both syntax families.
00515 blk_ifident: {
00516     lexer->setIfIdentMode(true);
00517   } blk_ident {
00518   lexer->setIfIdentMode(false);
00519   $$ = LToken(tk_BlkIdent, $2->loc, $2->endLoc(), $2->s);
00520 };
00521 blk_ifident: blk_ifident '.' {
00522     lexer->setIfIdentMode(true);
00523   } tk_BlkIdent {
00524   lexer->setIfIdentMode(false);
00525   $$ = LToken(tk_BlkIdent, $1.loc, $4.endLoc, $1.str + "." + $4.str);
00526 };
00527 
00528 // MODULES [2.5]
00529 trn_module_seq: trn_module {
00530  SHOWPARSE("trn_module_seq -> trn_module");
00531 }
00532 
00533 trn_module_seq: trn_module_seq SC trn_module {
00534  SHOWPARSE("trn_module_seq -> trn_module_seq SC trn_module");
00535 }
00536 
00537 trn_implicit_module: trn_mod_definitions  {
00538  SHOWPARSE("trn_implicit_module -> trn_mod_definitions");
00539  $$ = $1;
00540  $$->astType = at_module;
00541  $$->printVariant = pf_IMPLIED;
00542 
00543  // Construct, compile, and admit the parsed UoC:
00544  string uocName =
00545    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00546 
00547  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00548  lexer->nModules++;
00549 
00550  uoc->Compile();
00551  UocInfo::srcList[uocName] = uoc;
00552 };
00553 
00554 trn_module: tk_MODULE IsILCB {
00555     lexer->layoutStack->precedingToken = tk_INTERFACE;
00556   } trn_mod_definitions IRCB {
00557  SHOWPARSE("trn_module -> tk_MODULE IS { trn_mod_definitions }");
00558  $$ = $4;
00559  $$->astType = at_module;
00560 
00561  string uocName =
00562    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00563 
00564  // Construct, compile, and admit the parsed UoC:
00565  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00566  lexer->nModules++;
00567  uoc->Compile();
00568  UocInfo::srcList[uocName] = uoc;
00569 };
00570 
00571 trn_module: tk_MODULE blk_ifident IsILCB {
00572     lexer->layoutStack->precedingToken = tk_INTERFACE;
00573   } trn_mod_definitions IRCB {
00574  SHOWPARSE("trn_module -> tk_MODULE blk_ifident trn_optdocstring IS { trn_mod_definitions }");
00575  $$ = $5;
00576  $$->astType = at_module;
00577 
00578  // Construct, compile, and admit the parsed UoC.
00579  // Note that we do not even consider the user-provided sxp_module name
00580  // for purposes of internal naming, because it is not significant.
00581  string uocName =
00582    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00583 
00584  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00585  lexer->nModules++;
00586  uoc->Compile();
00587  UocInfo::srcList[uocName] = uoc;
00588 };
00589 
00590 // INTERFACE TOP LEVEL DEFINITIONS
00591 trn_if_definitions: trn_if_definition {
00592   SHOWPARSE("trn_if_definitions -> trn_if_definition");
00593   $$ = AST::make(at_Null, $1->loc, $1);
00594 };
00595 
00596 trn_if_definitions: trn_if_definitions SC trn_if_definition {
00597   SHOWPARSE("trn_if_definitions -> trn_if_definitions SC trn_if_definition");
00598   $$ = $1;
00599   $$->addChild($3); 
00600 };
00601 
00602 trn_if_definition: blk_common_definition {
00603   SHOWPARSE("trn_if_definition -> blk_common_definition");
00604   $$ = $1;
00605 };
00606 
00607 // TOP LEVEL DEFINITIONS [2.5.1]
00608 // Note that the block syntax has no direct analog to this, since we
00609 // moved the constraints back inside the defining form.
00610 trn_mod_definitions: trn_mod_definition {
00611   SHOWPARSE("trn_mod_definitions -> trn_mod_definition");
00612   $$ = AST::make(at_Null, $1->loc, $1);
00613 };
00614 
00615 trn_mod_definitions: trn_mod_definitions SC trn_mod_definition {
00616   SHOWPARSE("trn_mod_definitions -> trn_mod_definitions SC trn_mod_definition");
00617   $$ = $1;
00618   $$->addChild($3); 
00619 };
00620 
00621 trn_mod_definition: blk_mod_definition {
00622   SHOWPARSE("trn_mod_definition -> blk_mod_defintion");
00623   $$ = $1;
00624 };
00625 
00626 blk_mod_definition: blk_provide_definition {
00627   SHOWPARSE("blk_mod_definition -> blk_provide_definition");
00628   $$ = $1;
00629 };
00630 
00631 blk_mod_definition: blk_common_definition {
00632   SHOWPARSE("blk_mod_definition -> blk_common_definition");
00633   $$ = $1;
00634 };
00635 
00636 blk_common_definition: blk_import_definition {
00637   SHOWPARSE("blk_common_definition -> blk_import_definition");
00638   $$ = $1;
00639 }
00640 
00641 blk_common_definition: blk_type_val_definition {
00642   SHOWPARSE("blk_common_definition -> blk_type_val_definition");
00643   $$ = $1;
00644 };
00645 
00646 // No corresponding production in the block syntax, since constraints
00647 // moved back inside their respective forms.
00648 //
00649 //blk_common_definition: blk_constrained_definition {
00650 //  SHOWPARSE("blk_common_definition -> blk_constrained_definition");
00651 //  $$ = $1;
00652 //}
00653 
00654 blk_type_val_definition: blk_type_decl {
00655   SHOWPARSE("blk_type_val_definition -> blk_type_decl");
00656   $$ = $1;
00657 };
00658 
00659 blk_type_val_definition: blk_type_definition {
00660   SHOWPARSE("blk_type_val_definition -> blk_type_definition");
00661   $$ = $1;
00662 };
00663 
00664 blk_type_val_definition: blk_value_definition {
00665   SHOWPARSE("blk_type_val_definition -> blk_value_definition");
00666   $$ = $1;
00667 };
00668 
00669 blk_type_val_definition: blk_value_declaration {
00670   SHOWPARSE("blk_type_val_definition -> blk_value_declaration");
00671   $$ = $1;
00672 };
00673 
00674 blk_type_val_definition: blk_tc_definition {
00675   SHOWPARSE("blk_type_val_definition -> blk_tc_definition");
00676   $$ = $1;
00677 };
00678 
00679 blk_type_val_definition: blk_ti_definition {
00680   SHOWPARSE("blk_type_val_definition -> blk_ti_definition");
00681   $$ = $1;
00682 };
00683 
00684 // DECLARE [8.4.2]
00685 //common_definition: sxp_declare {
00686 //  SHOWPARSE("sxp_common_definition -> sxp_declare");
00687 //  $$ = $1;
00688 //};
00689 
00690 //Typeclass sxp_constraint declarations
00691 
00692 blk_constraints: {
00693   $$ = AST::make(at_constraints);
00694 }
00695 
00696 blk_constraints: tk_WHERE blk_constraint_seq SC {
00697   SHOWPARSE("blk_constraints -> FORALL blk_constraint_seq SC");
00698   $$ = $2;
00699 }
00700 
00701 blk_constraint_seq: blk_constraint_seq ',' blk_constraint {
00702  SHOWPARSE("blk_constraint_seq -> blk_constraint_seq , blk_constraint");
00703  $$ = $1;
00704  $$->addChild($3);
00705 };
00706 
00707 blk_constraint_seq: blk_constraint {
00708  SHOWPARSE("blk_constraint_seq -> blk_constraint");
00709  $$ = AST::make(at_constraints, $1->loc, $1);
00710 };
00711 
00712 blk_constraint: blk_typeapp {
00713   $1->astType = at_tcapp;
00714   $$ = $1;
00715 }
00716 
00717 blk_constraint: blk_useident %prec prec_PreferShift {
00718  SHOWPARSE("blk_constraint -> blk_useident");
00719  $$ = AST::make(at_tcapp, $1->loc, $1);
00720 };
00721 
00722 // Issue: parameterized type names in the block syntax have a
00723 // shift/reduce ambiguity at:
00724 //
00725 //  blk_defident .
00726 //  blk_defident . '(' blk_tvlist ')' blk_constraints
00727 
00728 blk_ptype_name: blk_defident %prec prec_PreferShift {
00729   SHOWPARSE("blk_ptype_name -> blk_defident");
00730   shared_ptr<AST> tvlist = AST::make(at_tvlist, $1->loc);
00731 
00732   // In the block syntax, we have a reliable syntactic position for
00733   // constraints later, so we don't build one here as we needed to do
00734   // in the S-expression syntax.
00735 
00736   // shared_ptr<AST> constraints = AST::make(at_constraints, $1->loc);
00737 
00738   $$ = AST::make(at_Null, $1->loc, $1, tvlist);
00739 };
00740 
00741 blk_ptype_name: blk_defident '(' blk_tvlist ')' %prec '(' {
00742   SHOWPARSE("blk_ptype_name -> blk_defident ( blk_tvlist )");
00743   // In the block syntax, we have a reliable syntactic position for
00744   // constraints later, so we don't build one here as we needed to do
00745   // in the S-expression syntax.
00746 
00747   // shared_ptr<AST> constraints = AST::make(at_constraints, $1->loc);
00748 
00749   $$ = AST::make(at_Null, $1->loc, $1, $3);
00750 };
00751 
00752 // STRUCTURE TYPES [3.6.1]         
00753 blk_type_definition: blk_constraints blk_val tk_STRUCT blk_ptype_name blk_opt_declares IsILCB blk_fields_and_methods IRCB {
00754   SHOWPARSE("blk_type_definition -> blk_constraints blk_val STRUCT blk_ptype_name "
00755             "blk_declares { blk_fields }");
00756   $$ = AST::make(at_defstruct, $3.loc, $4->child(0), $4->child(1), $2,
00757                  $5, $7, $1);
00758   $$->child(0)->defForm = $$;
00759 };
00760 
00761 // UNION TYPES [3.6.2]              
00762 blk_type_definition: blk_constraints blk_val tk_UNION blk_ptype_name blk_opt_declares IsILCB blk_constructors IRCB {
00763   SHOWPARSE("blk_type_definition -> blk_constraints blk_val UNION blk_ptype_name "
00764             "trn_optdocstring blk_opt_declares { blk_constructors }");
00765   $$ = AST::make(at_defunion, $3.loc,
00766                  $4->child(0),   /* ident */
00767                  $4->child(1),   /* tvlist */
00768                  $2,             /* category */
00769                  $5,             /* declares */
00770                  $7,             /* constructors */
00771                  $1);            /* constraints */
00772   $$->child(0)->defForm = $$;
00773 }
00774 
00775 // REPR TYPES
00776 blk_type_definition: blk_constraints blk_val tk_REPR blk_defident blk_opt_declares IsILCB blk_repr_constructors IRCB {
00777   SHOWPARSE("blk_type_definition -> blk_constraints blk_val REPR blk_defident "
00778             "blk_opt_declares { blk_repr_constructors }");
00779   if ($1->children.size() != 0) {
00780     std::string s = ": Error: Repr declarations cannot be quantified.";
00781     lexer->ReportParseError($1->loc, s);
00782   }
00783   $$ = AST::make(at_defrepr, $3.loc, $4,
00784                  AST::make(at_tvlist), /* empty tvlist */
00785                  $2, $5, $7,
00786                  $1); /* empty constraints */
00787   $$->child(0)->defForm = $$;
00788 }
00789 
00790 blk_repr_constructors: blk_repr_constructor {
00791   SHOWPARSE("blk_repr_constructors -> blk_repr_constructor");
00792   $$ = AST::make(at_reprctrs, $1->loc, $1);
00793 }
00794 
00795 blk_repr_constructors: blk_repr_constructors SC blk_repr_constructor {
00796   SHOWPARSE("blk_repr_constructors -> blk_repr_constructors SC blk_repr_constructor");
00797   $$ = $1;
00798   $$->addChild($3);
00799 }
00800 
00801 blk_repr_constructor: blk_ident IsILCB blk_fields OptRCB tk_WHERE blk_repr_reprs {
00802   SHOWPARSE("blk_repr_constructor ->  blk_ident { sxp_fields } WHERE blk_repr_reprs");
00803   $1->flags |= (ID_IS_GLOBAL);
00804   shared_ptr<AST> ctr = AST::make(at_constructor, $1->loc, $1);
00805   ctr->addChildrenFrom($3);
00806   $$ = AST::make(at_reprctr, $1->loc, ctr);
00807   $$->addChildrenFrom($6);
00808 }
00809 
00810 blk_repr_reprs: blk_repr_repr {
00811   SHOWPARSE("blk_repr_reprs -> blk_repr_repr");
00812   $$ = AST::make(at_Null, $1->loc, $1);
00813 };
00814 blk_repr_reprs: blk_repr_reprs ',' blk_repr_repr {
00815   SHOWPARSE("blk_repr_reprs -> blk_repr_reprs ',' blk_repr_repr");
00816   $$ = $1;
00817   $$->addChild($3);
00818 };
00819 
00820 blk_repr_repr: blk_ident tk_EQUALS intLit {
00821   SHOWPARSE("blk_repr_repr ->  sxp_ident == intLit");
00822 
00823   $$ = AST::make(at_reprrepr, $2.loc, $1, $3);
00824 };
00825 
00826 // Type Declarations
00827 // External declarations
00828 blk_externals: {
00829   SHOWPARSE("blk_externals -> ");
00830   yyerrok;
00831   lexer->showNextError = false;
00832 
00833   $$ = AST::make(at_Null);
00834   $$->flags = NO_FLAGS;
00835 };
00836 
00837 blk_externals: tk_EXTERNAL {
00838   SHOWPARSE("blk_externals -> EXTERNAL");
00839   $$ = AST::make(at_Null, $1.loc);
00840   $$->flags = DEF_IS_EXTERNAL;
00841 };
00842 
00843 blk_externals: tk_EXTERNAL blk_exident {
00844   SHOWPARSE("blk_externals -> EXTERNAL blk_exident");
00845   $$ = AST::make(at_Null, $1.loc);
00846   $$->flags = DEF_IS_EXTERNAL;
00847   $$->externalName = $2->s;
00848 };
00849 
00850 // OBJECT TYPES [3.6.1]         
00851 blk_type_definition: blk_constraints tk_OBJECT blk_ptype_name blk_opt_declares IsILCB blk_methods_only IRCB  {
00852   SHOWPARSE("blk_type_definition -> blk_constraints OBJECT blk_ptype_name "
00853             "blk_opt_declares blk_methods_only )");
00854 
00855   // For the moment, all objects are value types:
00856   shared_ptr<AST> valCat = 
00857     AST::make(at_unboxedCat, LToken(tk_UNBOXED, "unboxed"));
00858 
00859   $$ = AST::make(at_defobject, $2.loc, $3->child(0), $3->child(1),
00860                  valCat,
00861                  $4, $6, $1);
00862   $$->child(0)->defForm = $$;
00863 };
00864 
00865 // STRUCTURE DECLARATIONS
00866 blk_type_decl: blk_constraints blk_val tk_STRUCT blk_ptype_name blk_externals {
00867   SHOWPARSE("blk_type_decl -> blk_constraints blk_val STRUCT blk_ptype_name blk_externals '");
00868   $$ = AST::make(at_declstruct, $3.loc, 
00869                  $4->child(0),  /* ident */
00870                  $4->child(1),  /* tvlist */
00871                  $2,            /* category */
00872                  AST::make(at_declares), /* empty declares */
00873                  AST::make(at_fields), /* empty fields */
00874                  $1);                  /* constraints */
00875   $$->child(0)->defForm = $$;
00876   $$->flags |= $5->flags;
00877   $$->getID()->flags |= $5->flags;
00878   $$->getID()->externalName = $5->externalName;
00879 };
00880 
00881 // UNION DECLARATIONS
00882 blk_type_decl: blk_constraints blk_val tk_UNION blk_ptype_name blk_externals {
00883   SHOWPARSE("blk_type_decl -> blk_constraints blk_val UNION blk_ptype_name blk_externals");
00884   $$ = AST::make(at_declunion, $3.loc, 
00885                  $4->child(0),  /* ident */
00886                  $4->child(1),  /* tvlist */
00887                  $2,            /* category */
00888                  AST::make(at_declares), /* empty declares */
00889                  AST::make(at_constructors), /* empty constructors */
00890                  $1);                        /* constraints */
00891   $$->child(0)->defForm = $$;
00892   $$->flags |= $5->flags;
00893   $$->getID()->flags |= $5->flags;
00894   $$->getID()->externalName = $5->externalName;
00895 };
00896 
00897 // REPR DECLARATIONS
00898 blk_type_decl: blk_constraints blk_val tk_REPR blk_defident blk_externals {
00899   SHOWPARSE("blk_type_decl -> blk_val REPR blk_defident blk_externals )");
00900   if ($1->children.size() != 0) {
00901     std::string s = ": Error: Repr declarations cannot be quantified.";
00902     lexer->ReportParseError($1->loc, s);
00903   }
00904 
00905   $$ = AST::make(at_declrepr, $3.loc, $4, 
00906                  AST::make(at_tvlist), /* empty tvlist */
00907                  $2,                   /* category */
00908                  AST::make(at_declares), /* empty declares */
00909                  AST::make(at_reprctrs), /* empty constructors */
00910                  $1); /* empty constraints */
00911   $$->child(0)->defForm = $$;
00912   $$->flags |= $5->flags;
00913   $$->getID()->flags |= $5->flags;
00914   $$->getID()->externalName = $5->externalName;
00915 };
00916 
00917 // CATEGORIES
00918 
00919 blk_optval: {
00920   SHOWPARSE("blk_optval ->");
00921   $$ = AST::make(at_boxedCat);
00922   $$->printVariant = pf_IMPLIED;
00923 }
00924 blk_optval: blk_val {
00925   SHOWPARSE("blk_optval -> blk_val");
00926   $$ = $1;
00927 }
00928 
00929 blk_val: tk_BOXED {
00930   SHOWPARSE("blk_val -> BOXED");
00931   $$ = AST::make(at_boxedCat);
00932 }
00933 
00934 blk_val: tk_UNBOXED {
00935   SHOWPARSE("blk_val -> UNBOXED");
00936   $$ = AST::make(at_unboxedCat, $1);
00937 };
00938 
00939 blk_val: tk_OPAQUE {
00940   SHOWPARSE("blk_val -> tk_OPAQUE");
00941   $$ = AST::make(at_opaqueCat, $1);
00942 };
00943 
00944 blk_openclosed: {
00945   SHOWPARSE("blk_closed -> <empty>");
00946   $$ = AST::make(at_oc_open);
00947   $$->printVariant = pf_IMPLIED;
00948 };
00949 
00950 blk_openclosed: tk_CLOSED {
00951   SHOWPARSE("blk_closed -> CLOSED");
00952   $$ = AST::make(at_oc_closed, $1);
00953 };
00954 
00955 // EXCEPTION DEFINITION [3.10]
00956 blk_type_definition: blk_constraints blk_optval tk_EXCEPTION blk_ident {
00957   SHOWPARSE("blk_type_definition -> blk_constraints optval EXCEPTION blk_ident");
00958   if ($1->children.size() != 0) {
00959     std::string s = ": Error: Exception declarations cannot be quantified.";
00960     lexer->ReportParseError($1->loc, s);
00961   }
00962   $4->flags |= ID_IS_GLOBAL;
00963   $$ = AST::make(at_defexception, $3.loc, 
00964                  $4,            /* ident */
00965                  AST::make(at_tvlist), /* empty tvlist */
00966                  $2,                   /* category */
00967                  AST::make(at_declares), /* empty declares */
00968                  AST::make(at_fields), /* empty fields */
00969                  $1); /* empty constraints */
00970   $$->child(0)->defForm = $$;
00971 };
00972 
00973 blk_type_definition: blk_constraints blk_optval tk_EXCEPTION blk_ident IsILCB blk_fields IRCB {
00974   SHOWPARSE("blk_type_definition -> blk_constraints exception blk_ident IS { blk_fields }");
00975   if ($1->children.size() != 0) {
00976     std::string s = ": Error: Exception declarations cannot be quantified.";
00977     lexer->ReportParseError($1->loc, s);
00978   }
00979   $4->flags |= ID_IS_GLOBAL;
00980   $$ = AST::make(at_defexception, $3.loc, 
00981                  $4,
00982                  AST::make(at_tvlist), /* empty tvlist */
00983                  $2,                   /* category */
00984                  AST::make(at_declares), /* empty declares */
00985                  $6,                     /* fields */
00986                  $1); /* empty constraints */
00987   $$->child(0)->defForm = $$;
00988 };
00989 
00990 // TYPE CLASSES [4]
00991 // TYPE CLASS DEFINITION [4.1]
00992 
00993 blk_tc_definition: blk_constraints blk_openclosed tk_TRAIT blk_ptype_name blk_tc_decls IsILCB blk_method_decls IRCB {
00994   SHOWPARSE("blk_tc_definition -> blk_constraints blk_openclosed TRAIT blk_ptype_name "
00995             "blk_tc_decls blk_method_decls)");
00996   $$ = AST::make(at_deftypeclass, $3.loc, $4->child(0),
00997                  $4->child(1), $5, $2, $7, $1);
00998   $$->child(0)->defForm = $$;
00999 };
01000 
01001 blk_tc_decls: {
01002   SHOWPARSE("blk_tc_decls -> <empty>");
01003   $$ = AST::make(at_tcdecls);
01004 };
01005 
01006 // This used to support TYFN. I've left in the empty node
01007 // as a placeholder against the possible need for other
01008 // declarations later.
01009 //blk_tc_decls: blk_tc_decls blk_tc_decl {
01010 //  SHOWPARSE("blk_tcdecls -> blk_tcdelcs sxp_tcdecl");
01011 //  $$ = $1;
01012 //  $$->addChild($2);
01013 //};
01014 //
01015 //blk_tc_decl: tk_TYFN '(' blk_tvlist ')' tk_FNARROW typevar {
01016 //  //                     ^^^^^^
01017 //  // I really mean sxp_tvlist here, arbitrary types
01018 //  // are not acceptable.
01019 //  SHOWPARSE("blk_tc_decl -> TYFN ( blk_tvlist ) -> typevar");
01020 //  $3->astType = at_fnargVec;
01021 //  $$ = AST::make(at_tyfn, $2.loc, $3, $6);
01022 //};
01023 
01024 blk_method_decls: /* Nothing */ {
01025   SHOWPARSE("blk_method_decls -> ");
01026   LexLoc loc;
01027   $$ = AST::make(at_method_decls, loc);
01028 };
01029 
01030 blk_method_decls: blk_method_decls SC blk_method_decl {
01031   SHOWPARSE("blk_method_decls -> blk_method_decls SC blk_method_decl");
01032   $$ = $1;
01033   $$->addChild($3);
01034 };
01035 
01036 blk_method_decl: blk_ident ':' blk_fntype {
01037   SHOWPARSE("blk_method_decl -> blk_ident : blk_fntype");
01038   $1->flags |= ID_IS_GLOBAL;
01039   $1->identType = id_tcmethod;
01040   $$ = AST::make(at_method_decl, $1->loc, $1, $3);
01041 };
01042 
01043 // TYPE CLASS INSTANTIATIONS [4.2]
01044 blk_ti_definition: blk_constraints tk_INSTANCE blk_constraint {
01045   SHOWPARSE("blk_ti_definition -> blk_constraints INSTANCE blk_constraint)");
01046   $$ = AST::make(at_definstance, $2.loc, $3,
01047                  AST::make(at_tcmethods, $2.loc), $1);
01048 };
01049 blk_ti_definition: blk_constraints tk_INSTANCE blk_constraint IsILCB blk_method_bindings IRCB {
01050   SHOWPARSE("blk_ti_definition -> blk_constraints INSTANCE blk_constraint IS { blk_method_bindings }");
01051   $$ = AST::make(at_definstance, $2.loc, $3, $5, $1);
01052 };
01053 
01054 blk_method_bindings: blk_method_binding {
01055   SHOWPARSE("blk_method_bindings -> blk_method_binding");
01056   $$ = AST::make(at_tcmethods, $1->loc, $1);
01057 };
01058 blk_method_bindings: blk_method_bindings SC blk_method_binding {
01059   SHOWPARSE("blk_method_bindings -> blk_method_bindings SC blk_method_binding");
01060   $$ = $1;
01061   $$->addChild($3);
01062 };
01063 
01064 blk_method_binding: blk_ident '=' blk_expr {
01065   SHOWPARSE("blk_method_binding -> blk_ident = blk_expr");
01066 
01067   $$ = AST::make(at_tcmethod_binding, $1->loc, $1, $3);
01068 };
01069 
01070 // DEFINE  [5.1]
01071 //blk_value_definition: tk_DEF blk_defpattern blk_constraints '=' blk_expr {
01072 //  SHOWPARSE("blk_value_definition -> DEF  blk_defpattern blk_constraints = blk_expr");
01073 //  $$ = AST::make(at_define, $1.loc, $2, $5, $3);
01074 //};
01075 
01076 blk_value_definition: blk_constraints tk_DEF blk_defpattern '=' blk_expr {
01077   SHOWPARSE("blk_value_definition -> blk_constraints DEF blk_defpattern = blk_expr");
01078   $$ = AST::make(at_define, $2.loc, $3, $5, $1);
01079 };
01080 blk_value_definition: blk_constraints tk_DEF blk_defident '(' ')' blk_fndef_tail {
01081   SHOWPARSE("blk_value_definition -> blk_constraints DEF blk_defident () blk_expr");
01082   shared_ptr<AST> iRetBlock =
01083     AST::make(at_labeledBlock, $2.loc, 
01084               AST::make(at_ident, LToken(tk_BlkIdent, "__return")), $6);
01085   shared_ptr<AST> iLambda =
01086     AST::make(at_lambda, $2.loc, AST::make(at_argVec, $4.loc), iRetBlock);
01087   iLambda->printVariant = pf_IMPLIED;
01088   shared_ptr<AST> iP = AST::make(at_identPattern, $3->loc, $3);
01089   $$ = AST::make(at_recdef, $2.loc, iP, iLambda, $1);
01090 }
01091 
01092 blk_value_definition: blk_constraints tk_DEF blk_defident '(' blk_lambdapatterns ')' blk_fndef_tail {
01093   SHOWPARSE("blk_value_definition -> blk_constraints DEF blk_defident () blk_expr");
01094   // $5 = stripDocString($5);
01095   shared_ptr<AST> iRetBlock =
01096     AST::make(at_labeledBlock, $2.loc, 
01097               AST::make(at_ident, LToken(tk_BlkIdent, "__return")), $7);
01098   shared_ptr<AST> iLambda = AST::make(at_lambda, $2.loc, $5, iRetBlock);
01099   iLambda->printVariant = pf_IMPLIED;
01100   shared_ptr<AST> iP = AST::make(at_identPattern, $3->loc, $3);
01101   $$ = AST::make(at_recdef, $2.loc, iP, iLambda, $1);
01102 }
01103 
01104 blk_fndef_tail: '=' blk_expr {
01105   SHOWPARSE("blk_fndef_tail -> '=' blk_expr");
01106   $$ = $2;
01107 }
01108 blk_fndef_tail: tk_IN blk_iblock {
01109   SHOWPARSE("blk_fndef_tail -> IN blk_iblock");
01110   $$ = $2;
01111 }
01112 blk_fndef_tail: '{' blk_expr_seq '}' {
01113   SHOWPARSE("blk_fndef_tail -> '{' blk_expr_seq '}'");
01114   $$ = $2;
01115 }
01116 
01117 // PROCLAIM DEFINITION -- VALUES [6.2]
01118 blk_value_declaration: blk_constraints tk_DEF blk_defpattern blk_externals {
01119   SHOWPARSE("blk_value_declaration -> blk_constraints DEF blk_defpattern blk_externals");
01120 
01121   // I had to use blk_defpattern above to eliminate a reduce/reduce
01122   // conflict, but in a declaration we require the type to be present
01123   if ($3->children.size() == 1)
01124     lexer->ReportParseError($3->loc, "Declaration forms require a type");
01125 
01126   shared_ptr<AST> declIdent = $3->child(0);
01127   shared_ptr<AST> declType = $3->child(1);
01128 
01129   $$ = AST::make(at_proclaim, $2.loc, declIdent, declType, $1);
01130   $$->flags |= $4->flags;
01131   $$->getID()->flags |= $4->flags;
01132   $$->getID()->externalName = $4->externalName;
01133 };
01134 
01135 // TODO: The second ident in import rule, and the ident in the provide rule
01136 //  should be restricted to
01137 // ({ALPHA} | [_\-]) (({ALPHA} | {DECDIGIT} | [_\-])*
01138 // IMPORT DEFINITIONS [8.2]
01139 
01140 //import_definition: '(' tk_IMPORT sxp_ident sxp_ifident ')' {
01141 //  SHOWPARSE("sxp_import_definition -> ( IMPORT sxp_ident sxp_ifident )");
01142 //  shared_ptr<AST> ifIdent = AST::make(at_ifident, $4);
01143 //  ifIdent->uoc = UocInfo::importInterface(lexer->errStream, $4.loc, $4.str);
01144 //  $$ = AST::make(at_import, $2.loc, $3, ifIdent);
01145 //};
01146 
01147 blk_import_definition: tk_IMPORT blk_ifident tk_AS blk_ident {
01148   SHOWPARSE("blk_import_definition -> IMPORT blk_ifident AS blk_ident;");
01149   shared_ptr<AST> ifIdent = AST::make(at_ifident, $2);
01150   if (!UocInfo::importInterface(lexer->errStream, $2.loc, $2.str)) {
01151     std::string err = "Unable to import " + $2.str;
01152     lexer->ReportParseError($1.loc, err);
01153   }
01154 
01155   $$ = AST::make(at_importAs, $1.loc, ifIdent, $4);
01156 }
01157 
01158 blk_import_definition: tk_IMPORT blk_ifident {
01159   SHOWPARSE("blk_import_definition -> IMPORT blk_ifident;");
01160   shared_ptr<AST> ifIdent = AST::make(at_ifident, $2);
01161   if (!UocInfo::importInterface(lexer->errStream, $2.loc, $2.str)) {
01162     std::string err = "Unable to import " + $2.str;
01163     lexer->ReportParseError($1.loc, err);
01164   }
01165   $$ = AST::make(at_import, $1.loc, ifIdent);
01166 };
01167 
01168 blk_import_definition: tk_IMPORT blk_ifident blk_importList {
01169   SHOWPARSE("blk_import_definition -> IMPORT blk_ifident blk_importList;");
01170   shared_ptr<AST> ifIdent = AST::make(at_ifident, $2);
01171   if (!UocInfo::importInterface(lexer->errStream, $2.loc, $2.str)) {
01172     std::string err = "Unable to import " + $2.str;
01173     lexer->ReportParseError($1.loc, err);
01174   }
01175   $$ = AST::make(at_import, $1.loc, ifIdent);
01176   $$->addChildrenFrom($3);
01177 };
01178 
01179 blk_importList: blk_alias {
01180   SHOWPARSE("blk_importList -> blk_alias");
01181   $$ = AST::make(at_Null, $1->loc, $1);
01182 };
01183 blk_importList: blk_importList ',' blk_alias {
01184   SHOWPARSE("blk_importList -> blk_importList blk_alias");
01185   $$ = $1;
01186   $$->addChild($3);
01187 };
01188 
01189 blk_alias: blk_ident {
01190   SHOWPARSE("blk_alias -> blk_ident");
01191   // The two identifiers in this case are textually the same, but the
01192   // need to end up with distinct AST nodes, thus getDCopy().
01193   $$ = AST::make(at_ifsel, $1->loc, $1, $1->getDeepCopy());
01194 };
01195 blk_alias: blk_ident '=' blk_ident {
01196   SHOWPARSE("blk_alias -> blk_ident '=' blk_ident");
01197 
01198   $$ = AST::make(at_ifsel, $1->loc, $1, $3);
01199 };
01200 
01201 // PROVIDE DEFINITION [8.3]
01202 blk_provide_definition: tk_PROVIDE blk_ifident blk_provideList {
01203   SHOWPARSE("blk_provide_definition -> PROVIDE blk_ifident blk_provideList;");
01204   shared_ptr<AST> ifIdent = AST::make(at_ifident, $2);
01205   UocInfo::importInterface(lexer->errStream, $2.loc, $2.str);
01206   $$ = AST::make(at_provide, $1.loc, ifIdent);
01207   $$->addChildrenFrom($3);
01208 };
01209 
01210 blk_provideList: blk_ident {
01211   SHOWPARSE("blk_provideList -> blk_ident");
01212   $$ = AST::make(at_Null, $1->loc, $1);
01213 };
01214 
01215 blk_provideList: blk_provideList ',' blk_ident {
01216   SHOWPARSE("blk_provideList -> blk_provideList , blk_ident");
01217   $$ = $1;
01218   $$->addChild($3);
01219 };
01220 
01221 blk_opt_declares: {
01222   SHOWPARSE("blk_opt_declares -> <empty>");
01223   yyerrok;
01224   lexer->showNextError = false;
01225   $$ = AST::make(at_declares);
01226 };
01227 blk_opt_declares: blk_declares {
01228   SHOWPARSE("blk_opt_declares -> blk_declares");
01229   $$ = $1;
01230 };
01231 
01232 blk_declares: blk_declare {
01233   SHOWPARSE("blk_declares -> blk_declare");
01234   $$ = AST::make(at_declares, $1->loc, $1);
01235 };
01236 
01237 blk_declares: blk_declares SC blk_declare {
01238   SHOWPARSE("blk_declares -> blk_declares blk_declare");
01239   $$ = $1;
01240   $$->addChildrenFrom($3);
01241 };
01242 
01243 blk_declare: tk_DECLARE blk_decl {
01244   SHOWPARSE("blk_declare -> DECLARE blk_decl");
01245   $$ = $2;
01246 };
01247 
01248 // For tag type declaration.
01249 blk_decl: blk_ident tk_AS blk_field_type {
01250   SHOWPARSE("blk_decl -> blk_ident AS blk_field_type");
01251   $$ = AST::make(at_declare, $1->loc, $1, $3);
01252 };
01253 
01254 //decl: '(' sxp_ident ')' {
01255 //  SHOWPARSE("sxp_decl -> ( sxp_ident )");
01256 //  $$ = AST::make(at_declare, $2->loc, $2);
01257 //};
01258 blk_decl: blk_ident {
01259   SHOWPARSE("blk_decl -> blk_ident");
01260   $$ = AST::make(at_declare, $1->loc, $1);
01261 };
01262 
01263 
01264 /* defunion Constructors */
01265 blk_constructors: blk_constructor {
01266   SHOWPARSE("blk_constructors -> blk_constructor");
01267   $$ = AST::make(at_constructors, $1->loc, $1);
01268 };
01269 blk_constructors: blk_constructors SC blk_constructor {
01270   SHOWPARSE("blk_constructors -> blk_constructors SC blk_constructor");
01271   $$ = $1;
01272   $$->addChild($3);
01273 };
01274 
01275 blk_constructor: blk_ident { /* simple constructor */
01276   SHOWPARSE("blk_constructor -> blk_ident");
01277   $1->flags |= (ID_IS_GLOBAL);
01278   $$ = AST::make(at_constructor, $1->loc, $1);
01279 };
01280 // This is possible without conflict, but we aren't doing it yet:
01281 //blk_constructor: blk_ident ':' blk_field_type { /* common field */
01282 //  SHOWPARSE("blk_constructor -> blk_ident");
01283 //  $$ = AST::make(at_field, $1->loc, $1, $3);
01284 //};
01285 blk_constructor: blk_ident IsILCB blk_fields IRCB { /* compound constructor */
01286   SHOWPARSE("blk_constructor ->  blk_ident { blk_fields }");
01287   $1->flags |= (ID_IS_GLOBAL);
01288   $$ = AST::make(at_constructor, $1->loc, $1);
01289   $$->addChildrenFrom($3);
01290 };
01291 
01292 /* defstruct / sxp_constructor / exception sxp_fields */
01293 blk_fields: blk_field  {
01294   SHOWPARSE("blk_fields -> blk_field");
01295   $$ = AST::make(at_fields, $1->loc, $1);
01296 };
01297 
01298 blk_fields: blk_fields SC blk_field {
01299   SHOWPARSE("sxp_fields -> sxp_fields SC sxp_field ");
01300   $$ = $1;
01301   $$->addChild($3);
01302 };
01303 
01304 blk_field: blk_ident ':' blk_field_type {
01305   SHOWPARSE("blk_field -> blk_ident : blk_field_type");
01306   $$ = AST::make(at_field, $1->loc, $1, $3);
01307 };
01308 // FIX: Not clear why this is just bitfieldtype. Why can't it be any
01309 // field type at all? I think it can.
01310 blk_field: tk_FILL ':' blk_bitfieldtype {
01311   SHOWPARSE("blk_field -> FILL : blk_bitfieldtype");
01312   $$ = AST::make(at_fill, $1.loc, $3);
01313 };
01314 
01315 // Some low level data structures have reserved bit positions that are
01316 // required to hold designated values.
01317 blk_field: tk_RESERVED ':' blk_bitfieldtype '=' natLit  {
01318   SHOWPARSE("blk_field -> RESERVED ':' blk_bitfieldtype = natLit");
01319   $$ = AST::make(at_fill, $1.loc, $3, $5);
01320 };
01321 
01322 blk_methods_only: blk_methdecl  {
01323   SHOWPARSE("blk_methods_only -> blk_methdecl");
01324   $$ = AST::make(at_fields, $1->loc, $1);
01325 };
01326 
01327 blk_methods_only: blk_methods_only SC blk_methdecl  {
01328   SHOWPARSE("blk_methods_only -> blk_methods_only SC blk_methdecl");
01329   $$ = $1;
01330   $$->addChild($3);
01331 };
01332 
01333 blk_methdecl: blk_ident ':' blk_method_type {
01334   SHOWPARSE("blk_methdecl -> blk_ident : blk_method_type");
01335   $$ = AST::make(at_methdecl, $1->loc, $1, $3);
01336 };
01337 
01338 blk_fields_and_methods: blk_methdecl  {
01339   SHOWPARSE("blk_fields_and_methods -> blk_methdecl");
01340   $$ = AST::make(at_fields, $1->loc, $1);
01341 };
01342 
01343 blk_fields_and_methods: blk_field  {
01344   SHOWPARSE("blk_fields_and_methods -> blk_field");
01345   $$ = AST::make(at_fields, $1->loc, $1);
01346 };
01347 
01348 blk_fields_and_methods: blk_fields_and_methods SC blk_methdecl {
01349   SHOWPARSE("blk_fields_and_methods -> blk_fields_and_methods SC blk_methdecl ");
01350   $$ = $1;
01351   $$->addChild($3);
01352 };
01353 
01354 blk_fields_and_methods: blk_fields_and_methods SC blk_field {
01355   SHOWPARSE("blk_fields_and_methods -> blk_fields_and_methods SC blk_field ");
01356   $$ = $1;
01357   $$->addChild($3);
01358 };
01359 
01360 // Block tvlist is currently the same as sxp_tvlist, and these may
01361 // merge, but we might still need to change this to comma-separated,
01362 // so keep them separate for now.
01363 blk_tvlist: typevar  {
01364   SHOWPARSE("blk_tvlist -> typevar");
01365   $$ = AST::make(at_tvlist, $1->loc, $1);
01366 };
01367 blk_tvlist: blk_tvlist ',' typevar {
01368   SHOWPARSE("blk_tvlist -> blk_tvlist , typevar");
01369   $$ = $1;
01370   $1->addChild($3);
01371 };
01372 
01373 // TYPES [3]
01374 //  Unfortunately, the grammar for block types requires precedence
01375 //  rules, so it can't follow the order of appearance in the
01376 //  specification. Specifically, we have to deal with precedence rules
01377 //  and associativity for type application and vectors, so the overall
01378 //  shape of the block type grammar is:
01379 //
01380 //  blk_primary_type -> {identifiers, keywords}
01381 //
01382 //  blk_prefix_type -> blk_primary_type
01383 //  blk_prefix_type -> REF blk_prefix_type
01384 //  blk_prefix_type -> MUTABLE blk_prefix_type
01385 //
01386 //  blk_postfix_type -> blk_prefix_type
01387 //  blk_postfix_type -> blk_postfix_type '[' ']'
01388 //  blk_postfix_type -> blk_postfix_type '[' intLit ']'
01389 //  blk_postfix_type -> blk_postfix_type '(' type args ')'
01390 //
01391 //  blk_type -> blk_postfix_type
01392 //
01393 // Since the block type grammar and the s-expr type grammar share
01394 // their primary type production, I moved sxp_useident inside
01395 // primary_type. This is in contrast with the ANSI C grammar, where '.'
01396 // (field select) is handled in the postfix_expression production, but
01397 // the context for resolving '.' is never actually ambiguous, so it
01398 // doesn't matter here.
01399 
01400 blk_prefix_type: blk_primary_type {
01401   SHOWPARSE("blk_prefix_type -> blk_primary_type");
01402   $$ = $1;
01403 }
01404 
01405 blk_prefix_type: tk_MUTABLE blk_prefix_type {
01406   SHOWPARSE("blk_prefix_type -> MUTABLE blk_prefix_type");
01407   $$ = AST::make(at_mutableType, $1.loc, $2);
01408 }
01409 blk_prefix_type: tk_CONST blk_prefix_type {
01410   SHOWPARSE("blk_prefix_type -> CONST blk_prefix_type");
01411   $$ = AST::make(at_constType, $1.loc, $2);
01412 }
01413 
01414 blk_postfix_type: blk_prefix_type {
01415   SHOWPARSE("blk_postfix_type -> blk_prefix_type");
01416   $$ = $1;
01417 }
01418 
01419 blk_type: blk_postfix_type %prec prec_PreferShift {
01420   SHOWPARSE("blk_type -> blk_postfix_type");
01421   $$ = $1;
01422 }
01423 
01424 blk_primary_type: primary_type {
01425   SHOWPARSE("blk_primary_type -> primary_type");
01426   $$ = $1;
01427 }
01428 blk_primary_type: '(' blk_type ')' {
01429   SHOWPARSE("blk_primary_type -> '(' blk_type ')'");
01430   $$ = $2;
01431   // Preserve precedence when pretty printing:
01432   $2->printVariant |= pf_PARENWRAP;
01433 }
01434 blk_primary_type: '(' blk_type_cpair ')' {
01435   SHOWPARSE("blk_primary_type -> (blk_type_cpair)");
01436   $$ = $2;
01437 };
01438 
01439 // Temporary expedient: for each of the postfix types, introduce an
01440 // application-style alternate syntax for use in pretty-printing:
01441 blk_primary_type: tk_BOXED '(' blk_type ')' {
01442   SHOWPARSE("blk_primary_type -> tk_BOXED ( blk_type )");
01443   $$ = AST::make(at_boxedType, $1.loc, $3);
01444 
01445 }
01446 blk_primary_type: tk_UNBOXED '(' blk_type ')' {
01447   SHOWPARSE("blk_type -> UNBOXED ( blk_type )");
01448   $$ = AST::make(at_unboxedType, $1.loc, $3);
01449 };
01450 blk_primary_type: tk_ARRAY '(' blk_type ',' natLit ')' {
01451   SHOWPARSE("blk_primary_type -> tk_ARRAY ( blk_type, natLit )");
01452   $$ = AST::make(at_arrayType, $1.loc, $3, $5);
01453 
01454 }
01455 blk_primary_type: tk_VECTOR '(' blk_type ')' {
01456   SHOWPARSE("blk_primary_type -> tk_VECTOR ( blk_type )");
01457   $$ = AST::make(at_vectorType, $1.loc, $3);
01458 
01459 }
01460 
01461 blk_primary_type: blk_useident %prec prec_PreferShift {   /* previously defined type */
01462   SHOWPARSE("blk_primary_type -> blk_useident");
01463   $$ = $1;
01464 };
01465 
01466 primary_type: '(' ')' {
01467   SHOWPARSE("primary_type -> ( )");
01468   $$ = AST::make(at_primaryType, $1.loc);
01469   $$->s = "unit";                /* for lookup! */
01470 };
01471 
01472 // primary_type: tk_Nat {
01473 //   SHOWPARSE("primary_type -> Nat");
01474 //   // Temporary, for testing:
01475 //   $$ = AST::make(at_primaryType, $1.loc);
01476 //   $$->s = "unit";                /* for lookup! */
01477 // }
01478 
01479 bool_type: tk_BOOL {
01480   SHOWPARSE("bool_type -> BOOL");
01481   $$ = AST::make(at_primaryType, $1);
01482 };
01483 
01484 primary_type: bool_type {
01485   SHOWPARSE("primary_type -> bool_type");
01486   $$ = $1;
01487 };
01488 
01489 primary_type: tk_CHAR {
01490   SHOWPARSE("primary_type -> CHAR");
01491   $$ = AST::make(at_primaryType, $1);
01492 };
01493 primary_type: tk_STRING {
01494   SHOWPARSE("primary_type -> STRING");
01495   $$ = AST::make(at_primaryType, $1);
01496 };
01497 
01498 int_type: tk_INT8 {
01499   SHOWPARSE("int_type -> INT8");
01500   $$ = AST::make(at_primaryType, $1);
01501 };
01502 int_type: tk_INT16 {
01503   SHOWPARSE("int_type -> INT16");
01504   $$ = AST::make(at_primaryType, $1);
01505 };
01506 int_type: tk_INT32 {
01507   SHOWPARSE("int_type -> INT32");
01508   $$ = AST::make(at_primaryType, $1);
01509 };
01510 int_type: tk_INT64 {
01511   SHOWPARSE("int_type -> INT64");
01512   $$ = AST::make(at_primaryType, $1);
01513 };
01514 uint_type: tk_UINT8 {
01515   SHOWPARSE("uint_type -> UINT8");
01516   $$ = AST::make(at_primaryType, $1);
01517 };
01518 uint_type: tk_UINT16 {
01519   SHOWPARSE("uint_type -> UINT16");
01520   $$ = AST::make(at_primaryType, $1);
01521 };
01522 uint_type: tk_UINT32 {
01523   SHOWPARSE("uint_type -> UINT32");
01524   $$ = AST::make(at_primaryType, $1);
01525 };
01526 uint_type: tk_UINT64 {
01527   SHOWPARSE("uint_type -> UINT64");
01528   $$ = AST::make(at_primaryType, $1);
01529 };
01530 
01531 any_int_type: int_type {
01532   SHOWPARSE("any_int_type -> int_type");
01533   $$ = $1;
01534 };
01535 any_int_type: uint_type {
01536   SHOWPARSE("any_int_type -> uint_type");
01537   $$ = $1;
01538 };
01539 any_int_type: tk_WORD {
01540   SHOWPARSE("any_int_type -> WORD");
01541   $$ = AST::make(at_primaryType, $1);
01542 };
01543 
01544 float_type: tk_FLOAT {
01545   SHOWPARSE("float_type -> FLOAT");
01546   $$ = AST::make(at_primaryType, $1);
01547 };
01548 float_type: tk_DOUBLE {
01549   SHOWPARSE("float_type -> DOUBLE");
01550   $$ = AST::make(at_primaryType, $1);
01551 };
01552 float_type: tk_QUAD {
01553   SHOWPARSE("float_type -> QUAD");
01554   $$ = AST::make(at_primaryType, $1);
01555 };
01556 
01557 primary_type: any_int_type {
01558   SHOWPARSE("primary_type -> any_int_type");
01559   $$ = $1;
01560 };
01561 primary_type: float_type {
01562   SHOWPARSE("primary_type -> float_type");
01563   $$ = $1;
01564 };
01565 
01566 // EXCEPTION sxp_type
01567 primary_type: tk_EXCEPTION {
01568   SHOWPARSE("primary_type -> EXCEPTION");
01569   $$ = AST::make(at_exceptionType, $1.loc);
01570 };
01571 
01572 // TYPE VARIABLES [3.3]          
01573 primary_type: typevar  {                 
01574   SHOWPARSE("primary_type -> typevar");
01575   $$ = $1;
01576 };
01577 
01578 // REF TYPES [3.4.1]             
01579 blk_postfix_type: blk_postfix_type tk_PTR %prec tk_PTR {
01580   SHOWPARSE("blk_postfix_type -> blk_postfix_type PTR");
01581   $$ = AST::make(at_boxedType, $2.loc, $1);
01582 };
01583 
01584 // FUNCTION TYPES [3.4.3]
01585 blk_type: blk_fntype {
01586   SHOWPARSE("blk_type -> blk_fntype");
01587   $$ = $1;
01588 }
01589 
01590 trn_fneffect: {
01591   SHOWPARSE("trn_fneffect -> <empty>");
01592   $$ = AST::make(at_ident, LToken(tk_IMPURE, "impure"));
01593 };
01594 
01595 trn_fneffect: tk_PURE {
01596   SHOWPARSE("trn_fneffect -> PURE");
01597   $$ = AST::make(at_ident, $1);
01598 };
01599 
01600 trn_fneffect: tk_IMPURE {
01601   SHOWPARSE("trn_fneffect -> IMPURE");
01602   $$ = AST::make(at_ident, $1);
01603 };
01604 
01605 trn_fneffect: tk_EffectVar {
01606   SHOWPARSE("trn_fneffect -> <EffectVar=" + $1.str + ">");
01607   $$ = AST::make(at_ident, $1);
01608 };
01609 
01610 blk_type_args: blk_type  {
01611   SHOWPARSE("blk_type_args -> blk_type");
01612   $$ = AST::make(at_Null);
01613   $$->addChild($1);
01614 };
01615 blk_type_args: blk_type_args ',' blk_type {
01616   SHOWPARSE("blk_type_args -> blk_type_args, blk_type");
01617   $$ = $1;
01618   $1->addChild($3);
01619 };
01620 
01621 // Really blk_type, but broken out for the sake of trait declarations
01622 blk_fntype: trn_fneffect tk_FN '(' ')' tk_FNARROW blk_type {
01623   SHOWPARSE("blk_fntype -> trn_fneffect FN () -> blk_type )");
01624   shared_ptr<AST> fnargVec = AST::make(at_fnargVec, $5.loc);
01625   $$ = AST::make(at_fn, $1->loc, fnargVec, $6);
01626 };
01627 
01628 blk_fntype: trn_fneffect tk_FN '(' blk_type_args_pl_byref ')' tk_FNARROW blk_type {
01629   SHOWPARSE("blk_fntype -> trn_fneffect FN ( blk_type_args_pl_byref ) -> blk_type )");
01630   $$ = AST::make(at_fn, $1->loc, $4, $7);
01631 };
01632 
01633 // METHOD TYPES [3.9]
01634 blk_method_type: trn_fneffect tk_METHOD '(' ')' tk_FNARROW blk_type {
01635   SHOWPARSE("blk_method_type -> trn_fneffect METHOD () -> blk_type )");
01636   shared_ptr<AST> fnargVec = AST::make(at_fnargVec, $5.loc);
01637   $$ = AST::make(at_methType, $1->loc, fnargVec, $6);
01638 };
01639 
01640 blk_method_type: trn_fneffect tk_METHOD '(' blk_type_args_pl_byref ')' tk_FNARROW blk_type {
01641   SHOWPARSE("blk_method_type -> trn_fneffect METHOD ( blk_type_args_pl_byref ) -> blk_type )");
01642   $$ = AST::make(at_fn, $1->loc, $4, $7);
01643 };
01644 
01645 blk_type_cpair: blk_type ',' blk_type {
01646   SHOWPARSE("blk_type_cpair -> blk_type ',' blk_type");
01647   $$ = AST::make(at_typeapp, $2.loc,
01648                  AST::make(at_ident, LToken(tk_PAIR, $2.loc, $2.endLoc, "pair")),
01649                  $1, $3);
01650   $$->printVariant = pf_IMPLIED;
01651 };
01652 blk_type_cpair: blk_type ',' blk_type_cpair {
01653   SHOWPARSE("blk_type_cpair -> blk_type ',' blk_type_cpair");
01654   $$ = AST::make(at_typeapp, $2.loc,
01655                  AST::make(at_ident, LToken(tk_PAIR, $2.loc, $2.endLoc, "pair")),
01656                  $1, $3);
01657   $$->printVariant = pf_IMPLIED;
01658 };
01659 
01660 // ARRAY TYPE [3.5.1]               
01661 blk_postfix_type: blk_postfix_type '[' natLit ']' %prec '[' {
01662   SHOWPARSE("blk_postfix_type -> blk_postfix_type '[' natLit ']'");
01663   $$ = AST::make(at_arrayType, $1->loc, $1, $3);
01664 };
01665 // VECTOR TYPE [3.5.2]             
01666 blk_postfix_type: blk_postfix_type '[' ']' %prec '[' {
01667   SHOWPARSE("blk_postfix_type -> blk_postfix_type '[' ']'");
01668   $$ = AST::make(at_vectorType, $1->loc, $1);
01669 };
01670 
01671 // TYPE CONSTRUCTORS (typeapp)
01672 //blk_type:  blk_useident '(' blk_type_args ')' {
01673 //  SHOWPARSE("blk_typeapp -> blk_useident (blk_type_args)");
01674 //  $$ = AST::make(at_typeapp, $1->loc, $1);
01675 //  $$->addChildrenFrom($3);
01676 //};
01677 blk_primary_type: blk_typeapp {
01678   SHOWPARSE("blk_primary_type -> blk_typeapp");
01679   $$ = $1;
01680 };
01681 
01682 blk_typeapp: blk_useident '(' blk_type_args ')' %prec '(' {
01683   SHOWPARSE("blk_typeapp -> blk_useident (blk_type_args)");
01684   $$ = AST::make(at_typeapp, $1->loc, $1);
01685   $$->addChildrenFrom($3);
01686 };
01687 
01688 // BITFIELD TYPE
01689 blk_bitfieldtype: any_int_type '(' natLit ')' {
01690   SHOWPARSE("blk_bitfieldtype -> any_int_type ( natLit )");
01691   $$ = AST::make(at_bitfieldType, $1->loc, $1, $3);
01692 };
01693 blk_bitfieldtype: bool_type '(' natLit ')' {
01694   SHOWPARSE("blk_bitfieldtype -> bool_type ( natLit )");
01695   $$ = AST::make(at_bitfieldType, $1->loc, $1, $3);
01696 };
01697 
01698 // Any non-by-ref type, including bitfield type
01699 blk_field_type: blk_bitfieldtype {
01700   SHOWPARSE("blk_field_type -> blk_bitfieldtype");
01701   $$ = $1;
01702 };
01703 
01704 blk_field_type: blk_type {
01705   SHOWPARSE("blk_field_type -> blk_type");
01706   $$ = $1;
01707 };
01708 
01709 // by-ref sxp_type_args are not a part of general `type' rule.
01710 // They are gramatiocally restricted to apprae only on
01711 // formal function arguments and function types.
01712 blk_type_pl_byref: blk_type {
01713   SHOWPARSE("blk_type_pl_byref -> blk_type");
01714   $$ = $1;
01715 };
01716 
01717 blk_type_pl_byref: tk_BY_REF blk_type {
01718   SHOWPARSE("blk_type_pl_byref -> BY-REF blk_type");
01719   $$ = AST::make(at_byRefType, $1.loc, $2);
01720 };
01721 
01722 blk_type_pl_byref: tk_ARRAY_REF blk_type {
01723   SHOWPARSE("blk_type_pl_byref -> ARRAY-REF blk_type");
01724   $$ = AST::make(at_arrayRefType, $1.loc, $2);
01725 };
01726 
01727 blk_type_args_pl_byref: blk_type_pl_byref {
01728   SHOWPARSE("blk_type_args_pl_byref -> blk_type_pl_byref");
01729   $$ = AST::make(at_fnargVec);
01730   $$->addChild($1);
01731 };
01732 blk_type_args_pl_byref: blk_type_args_pl_byref ',' blk_type_pl_byref {
01733   SHOWPARSE("blk_type_args_pl_byref -> blk_type_args_pl_byref blk_type_pl_byref");
01734   $$ = $1;
01735   $1->addChild($3);
01736 };
01737 
01738 // BINDING PATTERNS [5.1]
01739 blk_bindingpattern: blk_ident {
01740   SHOWPARSE("blk_bindingpattern -> blk_ident");
01741   $$ = AST::make(at_identPattern, $1->loc, $1);
01742 };
01743 
01744 blk_bindingpattern: blk_ident ':' blk_type {
01745   SHOWPARSE("blk_bindingpattern -> blk_ident : blk_type");
01746   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01747 };
01748 
01749 // There are no sxp_defpattern sequences, because there is no top-level
01750 // pattern application
01751 // DEFPATTERN
01752 blk_defpattern: blk_defident %prec prec_PreferShift {
01753   SHOWPARSE("blk_defpattern -> blk_defident");
01754   $$ = AST::make(at_identPattern, $1->loc, $1);
01755 };
01756 blk_defpattern: blk_defident ':' blk_type %prec ':' {
01757   SHOWPARSE("blk_defpattern -> blk_defident : blk_qual_type");
01758   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01759 };
01760 
01761 /* Lambda Patterns -- with an additional by-ref annotation */
01762 blk_lambdapatterns: blk_lambdapattern {
01763   SHOWPARSE("blk_lambdapatterns -> blk_lambdapattern");
01764   $$ = AST::make(at_argVec, $1->loc);
01765   $$->addChild($1);
01766 };
01767 blk_lambdapatterns: blk_lambdapatterns ',' blk_lambdapattern {
01768   SHOWPARSE("blk_lambdapatterns -> blk_lambdapatterns , blk_lambdapattern");
01769   $$ = $1;
01770   $$->addChild($3);
01771 };
01772 
01773 blk_lambdapattern: blk_ident {
01774   SHOWPARSE("blk_lambdapattern -> blk_ident");
01775   $$ = AST::make(at_identPattern, $1->loc, $1);
01776 };
01777 
01778 blk_lambdapattern: blk_ident ':' blk_type_pl_byref {
01779   SHOWPARSE("blk_lambdapattern -> blk_ident : blk_type_pl_byref");
01780   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01781   if ($3->astType == at_byRefType)
01782     $1->flags |= ARG_BYREF;
01783 };
01784 
01785 // EXPRESSIONS [7]
01786 //
01787 // sxp_expr   -- an expression form with an optional sxp_type qualifier
01788 // sxp_unqual_expr  -- a naked expression form
01789 //
01790 // As a practical matter, every expression on the RHS of a production
01791 // should be an sxp_expr.
01792 //
01793 // In the block syntax we have prefix, postfix, and infix expressions
01794 // to worry about. The precedence grammar is:
01795 //
01796 //   primary_expr -> { identifiers, literals }
01797 //
01798 //   postfix_expr -> primary_expr
01799 //   postfix_expr -> postfix_expr '(' {arg list} ')'
01800 //   postfix_expr -> SIZEOF '(' expr ')'
01801 //   postfix_expr -> postfix_expr '[' expr ']'
01802 //
01803 //   prefix_expr -> postfix_expr
01804 //   prefix_expr -> REF prefix_expr
01805 //   prefix_expr -> unary_op prefix_expr
01806 //
01807 //   BEGIN INFIX_EXPR
01808 //
01809 //   mul_expr -> prefix_expr
01810 //   mul_expr -> mul_expr '*' prefix_expr
01811 //   mul_expr -> mul_expr '/' prefix_expr
01812 //   mul_expr -> mul_expr '%' prefix_expr
01813 //
01814 //   add_expr -> mul_expr
01815 //   add_expr -> add_expr '+' mul_expr
01816 //   add_expr -> add_expr '-' mul_expr
01817 //
01818 //   shift_expr -> add_expr
01819 //   shift_expr -> shift_expr << add_expr
01820 //   shift_expr -> shift_expr >> add_expr
01821 //
01822 //   relational_expr -> shift_expr
01823 //   relational_expr -> rel_expr < shift_expr
01824 //   relational_expr -> rel_expr > shift_expr
01825 //   relational_expr -> rel_expr <= shift_expr
01826 //   relational_expr -> rel_expr >= shift_expr
01827 //
01828 //   equal_expr -> relational_expr
01829 //   equal_expr -> equal_expr == relational_expr
01830 //   equal_expr -> equal_expr != relational_expr
01831 //
01832 //   bitand_expr -> equal_expr
01833 //   bitand_expr -> bitand_expr & equal_expr
01834 //
01835 //   bitxor_expr -> bitand_expr
01836 //   bitxor_expr -> bitxor_expr ^ bitand_expr
01837 //
01838 //   bitor_expr -> bitxor_expr
01839 //   bitor_expr -> bitor_expr | bitxor_expr
01840 //
01841 //   and_expr -> bitor_expr
01842 //   and_expr -> and_expr && bitor_expr
01843 //
01844 //   or_expr -> and_expr
01845 //   or_expr -> or_expr && and_expr
01846 //
01847 //   END INFIX_EXPR
01848 //
01849 //   if_expr -> or_expr
01850 //   if_expr -> IF expr THEN or_expr ELSE or_expr
01851 //
01852 //   assign_expr -> if_expr
01853 //   assign_expr -> or_expr '=' assign_expr
01854 //
01855 // As a practical matter, I have collapsed all of the infix operator
01856 // cases using the BISON operator precedence specification capabilities.
01857 //
01858 // note that things like SIZEOF can pretty much go anywhere. We put
01859 // them in postfix_expr mainly to put things of like appearance in a
01860 // common production.
01861 
01862 // MIXFIX: This needs a replacement...
01863 blk_expr_primary: blk_iblock {
01864   SHOWPARSE("blk_expr_primary -> blk_iblock");
01865   $$ = $1;
01866 }
01867 
01868 // blk_expr_primary: '(' blk_expr ')' {
01869 //  SHOWPARSE("blk_expr_primary -> ( blk_expr )");
01870 //   $$ = $2;
01871 //   // Be careful to preserve precedence when pretty printing:
01872 //   $$->printVariant |= pf_PARENWRAP;
01873 // }
01874 
01875 blk_expr_apply: blk_expr_primary {
01876   SHOWPARSE("blk_expr_apply -> blk_expr_primary");
01877   $$ = $1;
01878 }
01879 blk_expr_apply: tk_SIZEOF '(' blk_type ')' {
01880   SHOWPARSE("blk_expr_apply -> SIZEOF (blk_type)");
01881   $$ = AST::make(at_sizeof, $1.loc, $3);
01882 };
01883 blk_expr_apply: tk_BITSIZEOF '(' blk_type ')' {
01884   SHOWPARSE("blk_expr_apply -> BITSIZEOF (blk_type)");
01885   $$ = AST::make(at_bitsizeof, $1.loc, $3);
01886 };
01887 // FIX: This should be a built-in procedure
01888 blk_expr_apply: tk_DUP '(' blk_expr ')' {
01889   SHOWPARSE("blk_expr_apply -> DUP ( blk_expr )");
01890   $$ = AST::make(at_dup, $1.loc, $3);
01891 };
01892 blk_expr_apply: tk_DEREF '(' blk_expr ')' {
01893   SHOWPARSE("blk_expr_apply -> DEREF ( blk_expr )");
01894   $$ = AST::make(at_deref, $1.loc, $3);
01895 };
01896 blk_expr_apply: tk_MAKE_VECTOR '(' blk_expr ',' blk_expr ')' {
01897   SHOWPARSE("blk_expr_apply -> MAKE-VECTOR ( blk_expr , blk_expr )");
01898   $$ = AST::make(at_MakeVector, $1.loc, $3, $5);
01899 };
01900 blk_expr_apply: tk_VECTOR '(' blk_actual_params ')' {
01901   SHOWPARSE("blk_expr_apply -> VECTOR (blk_actual_params)");
01902   $$ = $3;
01903   $$->astType = at_vector;
01904   $$->loc = $1.loc;
01905 };
01906 blk_expr_apply: tk_ARRAY '(' blk_nonempty_params ')' {
01907   // Zero-length vector is illegal
01908   SHOWPARSE("blk_expr_apply -> (ARRAY blk_nonempty_params)");
01909   $$ = $3;
01910   $$->astType = at_array;
01911   $$->loc = $1.loc;
01912 };
01913 
01914 blk_expr_mixfix: blk_mixfix_elem %prec prec_PreferShift {
01915   SHOWPARSE("blk_expr_mixfix -> blk_mixfix_elem");
01916   $$ = $1;
01917 }
01918 
01919 blk_expr_mixfix: blk_expr_mixfix blk_mixfix_elem {
01920   SHOWPARSE("blk_expr_mixfix -> blk_expr_mixfix blk_mixfix_elem");
01921   $1->addChildrenFrom($2);
01922   $$ = $1;
01923 }
01924 
01925 // blk_mixfix_elem: blk_expr_mixfix '.' blk_ident {
01926 //   SHOWPARSE("blk_expr_mixfix -> blk_expr_mixfix . blk_ident");
01927 //   $$ = $1;
01928 //   $$->addChild(at_ident, $1));
01929 //   $$->addChild($3);
01930 // }
01931 
01932 blk_mixfix_elem: blk_expr_apply {
01933   SHOWPARSE("blk_mixfix_elem -> blk_expr_apply");
01934   $$ = AST::make(at_mixfix, $1->loc, $1);
01935 }
01936 
01937 // This entry is rather strange because it allows mixfix expressions
01938 // like "1 , , 2". Unfortunately, trying to impose any sort of
01939 // syntactic sanity here by doing something like mixfix_expr ','
01940 // mixfix_expr causes gobs of shift/reduce errors. So I'm leaving it
01941 // this way, and we'll field the unsyntactic cases in the mixfix
01942 // parser by virtue of the fact that neither ",_" nor "_," will be
01943 // defined. Then we'll check in the post-rewrite pass that these don't
01944 // appear outside of their legal bracketing contexts, which are
01945 // "(a,..,b)" and "[a,..,b]"
01946 
01947 // blk_mixfix_elem: ',' {
01948 //   SHOWPARSE("blk_mixfix_elem -> <Ident " + $1.str + ">");
01949 //   $$ = AST::make(at_mixfix, $1.loc, AST::make(at_ident, $1));
01950 // };
01951 
01952 // Note that the "_._" rule is the only rule admitting '.', and will
01953 // force an expr match on the left, which is what we want.
01954 blk_mixfix_elem: '.' blk_ident {
01955   SHOWPARSE("blk_mixfix_elem -> '.' <Ident " + $1.str + "> blk_ident");
01956   $$ = AST::make(at_mixfix, $1.loc, AST::make(at_ident, $1), $2);
01957 };
01958 
01959 blk_mixfix_arglist: blk_expr {
01960   SHOWPARSE("blk_mixfix_arglist -> blk_expr");
01961   $$ = AST::make(at_mixfix, $1->loc, $1);
01962 }
01963 
01964 blk_mixfix_arglist: blk_mixfix_arglist ',' blk_expr {
01965   SHOWPARSE("blk_mixfix_arglist -> blk_mixfix_arglist , blk_expr");
01966   $$ = $1;
01967   $$->addChild(AST::make(at_ident, $2));
01968   $$->addChild(AST::make(at_mixfix, $3->loc, $3));
01969 }
01970 
01971 // Note that an arglist can be a singleton expression, so this
01972 // subsumes fully parenthesized expressions:
01973 blk_mixfix_elem: '(' blk_mixfix_arglist ')' {
01974   SHOWPARSE("blk_mixfix_elem -> ( blk_mixfix_arglist )");
01975   $$ = AST::make(at_mixfix, $1.loc, AST::make(at_ident, $1));
01976   $$->addChildrenFrom($2);
01977   $$->addChild(AST::make(at_ident, $3));
01978 }
01979 
01980 blk_mixfix_elem: '(' ')' {
01981   SHOWPARSE("blk_mixfix_elem -> ( )");
01982   $$ = AST::make(at_mixfix, $1.loc, AST::make(at_ident, $1));
01983   $$->addChild(AST::make(at_ident, $2));
01984 }
01985 
01986 blk_mixfix_elem: '[' blk_mixfix_arglist ']' {
01987   SHOWPARSE("blk_mixfix_elem -> [ blk_mixfix_arglist ]");
01988   $$ = AST::make(at_mixfix, $1.loc, AST::make(at_ident, $1));
01989   $$->addChildrenFrom($2);
01990   $$->addChild(AST::make(at_ident, $3));
01991 }
01992 
01993 // This is the only production defining blk_expr. It is causing
01994 // a (correctly resolved) S/R ambiguity that we should probably try to
01995 // clean up.
01996 blk_expr: blk_expr_mixfix %prec prec_PreferShift {
01997   SHOWPARSE("blk_expr -> blk_expr_mixfix");
01998   $$ = $1;
01999 }
02000 blk_expr: blk_expr_mixfix ':' blk_type {
02001   SHOWPARSE("blk_expr -> blk_expr_mixfix : blk_type");
02002   $$ = AST::make(at_typeAnnotation, $2.loc, $1, $3);
02003 }
02004 
02005 blk_iblock: ILCB IRCB {
02006   SHOWPARSE("blk_block -> { }");
02007   // Empty blocks are okay:
02008   $$ = AST::make(at_begin, $1.loc);
02009 }
02010 blk_iblock: ILCB blk_expr_seq IRCB {
02011   SHOWPARSE("blk_block -> { blk_expr_seq }");
02012 
02013   // Remove redundant blocks eagerly:
02014   if ($2->children.size() == 1 && $2->child(0)->astType == at_begin)
02015     $2 = $2->child(0);
02016   $$ = $2;
02017 }
02018 
02019 blk_expr_seq: blk_expr {
02020   SHOWPARSE("blk_expr_seq -> blk_expr");
02021   $$ = AST::make(at_begin, $1->loc, $1);
02022 };
02023 blk_expr_seq: blk_value_definition {
02024   SHOWPARSE("blk_expr_seq -> blk_value_definition");
02025   $$ = AST::make(at_begin, $1->loc, $1);
02026 };
02027 blk_expr_seq: blk_expr_seq ';' blk_expr {
02028   SHOWPARSE("blk_expr_seq -> blk_expr_seq ; blk_expr");
02029   $$ = $1;
02030   $$->addChild($3);
02031 };
02032 blk_expr_seq: blk_expr_seq ';' blk_value_definition {
02033   SHOWPARSE("blk_expr_seq -> blk_expr_seq ; blk_value_definition");
02034   $$ = $1;
02035   $$->addChild($3);
02036 };
02037 
02038 blk_actual_params: {
02039   SHOWPARSE("blk_actual_params -> ");
02040   $$ = AST::make(at_Null);
02041 };
02042 blk_actual_params: blk_nonempty_params {
02043   SHOWPARSE("blk_actual_params -> blk_nonempty_params");
02044   $$ = $1;
02045 };
02046 blk_nonempty_params: blk_expr {
02047   SHOWPARSE("blk_nonempty_params -> blk_expr");
02048   $$ = AST::make(at_Null, $1->loc, $1);
02049 };
02050 blk_nonempty_params: blk_nonempty_params ',' blk_expr {
02051   SHOWPARSE("blk_nonempty_params -> blk_nonempty_params , blk_expr");
02052   $$ = $1;
02053   $$->addChild($3);
02054 };
02055 
02056 // LITERALS  [7.1]
02057 blk_expr_primary: trn_literal {
02058   SHOWPARSE("blk_expr_primary -> Literal");
02059   $$ = $1;
02060 };
02061 
02062 // UNIT EXPRESSIONS   [7.4.1]
02063 // blk_expr_primary: '(' ')' {
02064 //   SHOWPARSE("blk_expr_primary -> ()");
02065 //   $$ = AST::make(at_unit, $1.loc);
02066 // };
02067 
02068 // Expressions that involve locations:
02069 
02070 // IDENTIFIERS [7.2]
02071 /* This would actually have been
02072 blk_expr_primary: blk_useident {
02073   SHOWPARSE("blk_expr_primary -> blk_useident");
02074   $$ = $1;
02075 };
02076 but for the ambiguity with record (field) selection.
02077 So, the burden is now passed to further stages */
02078 
02079 blk_expr_primary: blk_ident {
02080   SHOWPARSE("blk_expr_primary -> blk_ident");
02081   $$ = $1;
02082 };
02083 
02084 // MEMBER [7.9]
02085 // In principle, we would like to accept expr.ident here, but that
02086 // creates a parse conflict with expr:type, because the sequence
02087 //
02088 //    expr : type . ident
02089 //
02090 // can turn into:
02091 //
02092 //    expr : Id . Id . ident
02093 //           ^^^^^^^
02094 //             type
02095 //
02096 // which creates a shift-reduce conflict. It's all fine as long as the
02097 // sxp_expr is fully bracketed, so there is no problem accepting:
02098 //
02099 //    (the type expr).ident
02100 //
02101 // We have adopted the solution of declaring that the ":" convenience
02102 // syntax cannot be used inside a member selection. This is not likely
02103 // to be burdensome. If the sxp_expr on the LHS is a locally computed
02104 // result, the sxp_type will be inferred through chaining from the
02105 // sxp_constructor expression. The only case where this is likely to be
02106 // annoying is for arguments of structure type, but we do not infer
02107 // structure types from sxp_field names in any case, so those will
02108 // probably require argument declarations in any case.
02109 
02110 // INNER-REF
02111 // In the case of structures, the second "sxp_expression"
02112 // must be a label. This cannot be checked until
02113 // type-checking phase.
02114 /* eform: '(' tk_INNER_REF sxp_expr sxp_expr ')' { */
02115 /*   SHOWPARSE("sxp_unqual_expr -> ( INNER_REF sxp_expr sxp_expr)"); */
02116 /*   $$ = AST::make(at_inner_ref, $2.loc, $3, $4); */
02117 /* }; */
02118 
02119 // End of locations
02120 
02121 // PAIR EXPRESSIONS
02122 // FIX: Should we just do this with a tuple syntax, because this is
02123 //      *begging* for issues with procedure call. The only reason
02124 //      we are going to get away with it is because it must appear
02125 //      within parenthesis, and if we have seen
02126 //
02127 //        expr ( . expr
02128 //
02129 //      we already know at the time of shift that we are doing
02130 //      function application. GACK!
02131 //
02132 //      In any case, this is an issue that we should certainly revisit
02133 //      before introducing mixfix.
02134 
02135 // LABELS and LABELED EXIT [7.6]
02136 // Note that we do not want a generalized blk_ident in the first
02137 // position here, because that creates an ambiguity with primary
02138 // expressions. Note that we only want a local identifier here in any
02139 // case, and not an operator, so using tk_BlkIdent is fine here.
02140 
02141 blk_expr_primary: tk_LABEL tk_BlkIdent tk_IN blk_iblock {
02142   SHOWPARSE("blk_expr_primary -> LABEL ident in blk_iblock");
02143   $$ = AST::make(at_labeledBlock, $1.loc,
02144                  AST::make(at_ident, $2),
02145                  $4);
02146 }
02147 
02148 blk_expr: blk_expr_continue {
02149   SHOWPARSE("blk_expr -> blk_continue");
02150   $$ = $1;
02151 }
02152 blk_expr_continue: tk_CONTINUE {
02153   SHOWPARSE("blk_expr_continue -> CONTINUE");
02154   $$ = AST::make(at_return_from, $1.loc,
02155                  AST::make(at_ident, LToken(tk_BlkIdent, "__continue")),
02156                  AST::make(at_unit, $1.loc));
02157 }
02158 
02159 blk_expr: blk_expr_from_return {
02160   SHOWPARSE("blk_expr -> blk_expr_from_return");
02161   $$ = $1;
02162 }
02163 blk_expr_from_return: tk_FROM blk_ident tk_RETURN blk_expr {
02164   SHOWPARSE("blk_expr_from_return -> FROM blk_ident RETURN blk_expr");
02165   $$ = AST::make(at_return_from, $1.loc, $2, $4);
02166 }
02167 
02168 // ARRAY-LENGTH [7.11.1]
02169 // VECTOR-LENGTH [7.11.1]
02170 // Replaced by v.length, a.length, ar.length
02171 
02172 // convenience syntax: multiple arguments
02173 blk_expr: blk_expr_lambda {
02174   SHOWPARSE("blk_expr -> blk_expr_lambda");
02175   $$ = $1;
02176 }
02177 blk_expr_lambda: tk_LAMBDA '(' ')' blk_expr {
02178   SHOWPARSE("blk_expr_lambda -> LAMBDA () blk_expr");
02179   shared_ptr<AST> argVec = AST::make(at_argVec, $2.loc);
02180   shared_ptr<AST> iRetBlock =
02181     AST::make(at_labeledBlock, $1.loc, 
02182               AST::make(at_ident, LToken(tk_BlkIdent, "__return")), $4);
02183   $$ = AST::make(at_lambda, $1.loc, argVec, iRetBlock);
02184 };
02185 
02186 blk_expr_lambda: tk_LAMBDA '(' blk_lambdapatterns ')' blk_expr {
02187   SHOWPARSE("blk_expr_lambda -> LAMBDA (blk_lambdapatterns) blk_expr");
02188   shared_ptr<AST> iRetBlock =
02189     AST::make(at_labeledBlock, $1.loc, 
02190               AST::make(at_ident, LToken(tk_BlkIdent, "__return")), $5);
02191   $$ = AST::make(at_lambda, $1.loc, $3, iRetBlock);
02192 };
02193 
02194 // RETURN [7.13]         
02195 blk_expr: blk_expr_return {
02196   SHOWPARSE("blk_expr -> blk_expr_return");
02197   $$ = $1;
02198 }
02199 blk_expr_return: tk_RETURN blk_expr {
02200   SHOWPARSE("blk_expr_return -> RETURN blk_expr");
02201   $$ = AST::make(at_return_from, $1.loc,
02202                  AST::make(at_ident, LToken(tk_BlkIdent, "__return")), $2);
02203 }
02204 
02205 // IF [7.15.1]
02206 blk_expr: blk_expr_if_then_else {
02207   SHOWPARSE("blk_expr -> blk_expr_if_then_else");
02208   $$ = $1;
02209 }
02210 
02211 blk_expr_if_then_else: tk_IF blk_expr tk_THEN ILCB blk_expr_seq OptRCB tk_ELSE blk_iblock {
02212   SHOWPARSE("blk_expr_if_then_else -> IF blk_expr THEN blk_ieblock ELSE blk_iblock");
02213   $$ = AST::make(at_if, $1.loc, $2, $5, $8);
02214 };
02215 blk_expr: tk_IF blk_expr error {
02216   SHOWPARSE("blk_expr -> IF blk_expr error");
02217   LToken lastTok = lexer->getLastToken();
02218   lexer->ReportParseError($1.loc, 
02219                           "Expected 'then' following 'if', got " + lastTok.str
02220                           + " at " + lastTok.loc.asString());
02221   $$ = AST::make(at_unit, $1.loc);
02222 };
02223 blk_expr: tk_IF blk_expr tk_THEN ILCB blk_expr_seq OptRCB error {
02224   SHOWPARSE("blk_expr -> IF blk_expr error");
02225   LToken lastTok = lexer->getLastToken();
02226   lexer->ReportParseError($1.loc, 
02227                           "if/then/else missing else clause at "
02228                           + lastTok.loc.asString() +
02229                           ", assuming unit. Consider when or unless?");
02230 
02231   // Yacc shifted a token in the position of error. Since we are
02232   // recovering locally, push that token back onto the input and make
02233   // the parser re-process it.
02234   assert(yychar != YYEMPTY);
02235   yylval.tok.flags |= TF_REPROCESS;
02236   lexer->pushTokenBack(yylval.tok, true);
02237   yyclearin;
02238      
02239   lexer->showNextError = false;
02240 
02241   $$ = AST::make(at_if, $1.loc, $2, $5,
02242                  AST::make(at_unit, $1.loc));
02243 };
02244 
02245 // WHEN [7.15.2]
02246 blk_expr: blk_expr_when {
02247   SHOWPARSE("blk_expr -> blk_expr_when");
02248   $$ = $1;
02249 }
02250 blk_expr_when: tk_WHEN blk_expr tk_DO blk_expr {
02251   SHOWPARSE("blk_expr -> WHEN blk_expr DO blk_expr");
02252   $$ = AST::make(at_when, $1.loc, $2, $4);
02253 };
02254 blk_expr_when: tk_WHEN blk_expr tk_THEN blk_expr {
02255   // Transition:
02256   SHOWPARSE("blk_expr -> WHEN blk_expr THEN blk_expr");
02257   lexer->ReportParseError($3.loc, 
02258                           "when/then has been replaced by when/do.");
02259   $$ = AST::make(at_when, $1.loc, $2, $4);
02260 };
02261 blk_expr: blk_expr_unless {
02262   SHOWPARSE("blk_expr -> blk_expr_unless");
02263   $$ = $1;
02264 }
02265 blk_expr_unless: tk_UNLESS blk_expr tk_DO blk_expr {
02266   SHOWPARSE("blk_expr -> UNLESS blk_expr DO blk_expr");
02267   $$ = AST::make(at_unless, $1.loc, $2, $4);
02268 };
02269 
02270 // SET! [7.16]                
02271 blk_expr: blk_expr_mixfix tk_ASSIGN blk_expr %prec tk_ASSIGN {
02272   /* Strictly speaking, RHS could be a higher-level parse form,, but
02273    * none of those are l-values in any case. Need postfix_expr in
02274    * order to pick up things like 'a.b'. There is a location check
02275    * later in the compiler, but might as well reject what we can
02276    * early.
02277    */
02278   SHOWPARSE("blk_assignment -> blk_expr_mixfix := blk_expr");
02279   $$ = AST::make(at_setbang, $2.loc, $1, $3);
02280 };
02281 
02282 // SWITCH
02283 // blk_expr: tk_SWITCH blk_expr OptLCB blk_sw_legs blk_opt_otherwise OptRCB {
02284 //   SHOWPARSE("blk_expr -> SWITCH blk_expr IN blk_sw_legs blk_opt_otherwise");
02285 //   $$ = AST::make(at_uswitch, $1.loc, 
02286 //                  AST::make(at_ident, LToken(tk_BlkIdent, "__dummy")),
02287 //                  $2, $4, $5);
02288 // }
02289 // FIX: For the moment, cannot use blk_letbinding here, because that
02290 // admits a type qualifier on the bound identifier. I don't want to
02291 // deal with that complication in the type inference engine just at
02292 // the moment.
02293 blk_expr: blk_expr_switch {
02294   SHOWPARSE("blk_expr -> blk_expr_switch");
02295   $$ = $1;
02296 }
02297 blk_expr_switch: tk_SWITCH ILCB blk_ident '=' blk_expr OptRCB blk_sw_legs blk_opt_otherwise {
02298   SHOWPARSE("blk_expr_switch -> SWITCH { blk_letbinding } blk_sw_legs blk_opt_otherwise");
02299 
02300   $$ = AST::make(at_uswitch, $1.loc, $3, $5, $7, $8);
02301 
02302   // Inject the ident down into the case legs:
02303   for (size_t c =0; c < $7->children.size(); c++) {
02304     shared_ptr<AST> sw_leg = $7->child(c);
02305     sw_leg->children.insert(sw_leg->children.begin(),
02306                             $3->getDeepCopy());
02307   }
02308   if ($8->astType == at_otherwise) {
02309     shared_ptr<AST> ow = $8;
02310     ow->children.insert(ow->children.begin(),
02311                         $3->getDeepCopy());
02312   }
02313 }
02314 
02315 blk_sw_legs: blk_sw_legs blk_sw_leg {
02316   SHOWPARSE("blk_sw_legs -> blk_sw_legs blk_sw_leg");
02317   $$ = $1;
02318   $1->addChild($2);
02319 }
02320 blk_sw_legs: blk_sw_leg {
02321   SHOWPARSE("blk_sw_legs -> blk_sw_leg");
02322   $$ = AST::make(at_usw_legs, $1->loc, $1);
02323 }
02324 //blk_sw_leg: tk_CASE OptLCB blk_ident tk_AS blk_expr_switch_match OptRCB tk_IN blk_block {
02325 //  SHOWPARSE("blk_sw_leg -> CASE { blk_ident AS blk_type } blk_block");
02326 //  $$ = AST::make(at_usw_leg, $1.loc, $3, $8, $5);
02327 //}
02328 blk_sw_leg: tk_CASE blk_expr_switch_matches tk_IN blk_iblock {
02329   SHOWPARSE("blk_sw_leg -> CASE blk_expr_switch_matches IN blk_iblock");
02330   $$ = AST::make(at_usw_leg, $1.loc, $4);
02331   $$->addChildrenFrom($2);
02332 }
02333 
02334 blk_expr_switch_matches: blk_expr_switch_match {
02335   SHOWPARSE("blk_expr_switch_matches -> blk_expr_switch_match");
02336   $$ = AST::make(at_Null, $1->loc, $1);
02337 }
02338 
02339 blk_expr_switch_matches: blk_expr_switch_matches ',' blk_expr_switch_match {
02340   SHOWPARSE("blk_expr_switch_matches -> blk_expr_switch_matches ',' blk_expr_switch_match");
02341   $$ = $1;
02342   $$->addChild($3);
02343 }
02344 
02345 /* Constructors may be expressed as:
02346    i) cons
02347    ii) list.cons
02348    iii) bitc.list.cons
02349 
02350    If we find the double-dotted version, we are sure that we have
02351    found the sxp_useident.ctr version, otherwise, this is ambiguous, and
02352    leave the burden on the resolver to find out */
02353 blk_expr_switch_match: blk_ident {
02354   SHOWPARSE("blk_expr_switch_match -> blk_ident");
02355   $$ = $1;
02356 };
02357 
02358 blk_expr_switch_match: blk_ident '.' blk_ident {
02359   SHOWPARSE("blk_expr_switch_match -> blk_ident . blk_ident"); 
02360   $$ = AST::make(at_select, $1->loc, $1, $3);
02361 };
02362 
02363 blk_expr_switch_match: blk_ident '.' blk_ident '.' blk_ident {
02364   SHOWPARSE("blk_expr_switch_match -> blk_ident '.' blk_ident '.' blk_ident");
02365   shared_ptr<AST> usesel = AST::make(at_usesel, $1->loc, $1, $3); 
02366   usesel->s = $1->s + "." + $3->s;
02367   $$ = AST::make(at_select, $1->loc, usesel, $5);
02368 };
02369 
02370 // This is just like dangling ELSE...
02371 blk_opt_otherwise: blk_otherwise {
02372   SHOWPARSE("blk_opt_otherwise -> blk_otherwise");
02373   $$ = $1;
02374 };
02375 blk_opt_otherwise: %prec prec_PreferShift { //empty
02376   SHOWPARSE("blk_opt_otherwise -> ");
02377   $$ = AST::make(at_Null);
02378 };
02379 blk_otherwise: tk_OTHERWISE blk_iblock %prec tk_OTHERWISE {
02380   SHOWPARSE("blk_otherwise -> OTHERWISE blk_expr");
02381   $$ = AST::make(at_otherwise, $1.loc, $2);
02382 };
02383 
02384 // TRY/CATCH [7.19.1]
02385 blk_expr: blk_expr_try {
02386   SHOWPARSE("blk_expr -> blk_expr_try");
02387   $$ = $1;
02388 }
02389 blk_expr_try: tk_TRY blk_iblock tk_CATCH blk_ident blk_sw_legs blk_opt_otherwise {
02390   SHOWPARSE("blk_expr -> TRY blk_iblock CATCH blk_ident blk_sw_legs blk_opt_otherwise");
02391   $$ = AST::make(at_try, $1.loc, $2, 
02392                  AST::make(at_ident, LToken(tk_BlkIdent, "__dummy")),
02393                  $5, $6);
02394 
02395   for (size_t c =0; c < $5->children.size(); c++) {
02396     shared_ptr<AST> sw_leg = $5->child(c);
02397     sw_leg->children.insert(sw_leg->children.begin(),
02398                             $4->getDeepCopy());
02399   }
02400   if ($6->astType == at_otherwise) {
02401     shared_ptr<AST> ow = $6;
02402     ow->children.insert(ow->children.begin(),
02403                         $4->getDeepCopy());
02404   }
02405 }
02406 
02407 blk_expr_try: tk_TRY blk_iblock tk_CATCH blk_ident blk_otherwise {
02408   SHOWPARSE("blk_expr_try -> TRY blk_expr tk_CATCH blk_ident blk_otherwise");
02409   shared_ptr<AST> dummyID = 
02410     AST::make(at_ident, LToken(tk_BlkIdent, "__dummy"));
02411 
02412   $$ = AST::make(at_try, $1.loc, $2, dummyID,
02413                  AST::make(at_usw_legs, $5->loc), /* empty */
02414                  $5);
02415 
02416   shared_ptr<AST> ow = $5;
02417   ow->children.insert(ow->children.begin(), $4->getDeepCopy());
02418 }
02419 
02420 //HERE
02421 //blk_opt_catch_legs: {
02422 //  SHOWPARSE("blk_opt_catch_legs -> ");
02423 //  $$ = AST::make(at_catch_legs);
02424 //}
02425 //blk_opt_catch_legs: blk_catch_legs {
02426 //  SHOWPARSE("blk_opt_catch_legs -> blk_catch_legs");
02427 //  $$ = $1;
02428 //}
02429 
02430 //blk_expr: tk_TRY blk_letbinding tk_IN blk_expr blk_catch_legs {
02431 //  SHOWPARSE("blk_expr -> LET blk_letbinding IN expr");
02432 //
02433 //  shared_ptr<AST> bindings = AST::make(at_letbindings, $2->loc, $2);
02434 //  $$ = AST::make(at_kennedy_try, $1.loc, bindings, $4);
02435 //}
02436 
02437 // THROW  [7.19.2]              
02438 blk_expr: blk_expr_throw {
02439   SHOWPARSE("blk_expr -> blk_expr_throw");
02440   $$ = $1;
02441 }
02442 blk_expr_throw: tk_THROW blk_expr {
02443   SHOWPARSE("blk_expr_throw -> THROW blk_expr");
02444   $$ = AST::make(at_throw, $1.loc, $2);
02445 }
02446 
02447 // LET [5.3.1]                 
02448 blk_expr: blk_expr_let {
02449   SHOWPARSE("blk_expr -> blk_expr_let");
02450   $$ = $1;
02451 }
02452 blk_expr_let: tk_LET ILCB blk_letbindings OptRCB tk_IN blk_iblock {
02453   SHOWPARSE("blk_expr_let -> LET { blk_letbindings } IN blk_iblock");
02454 
02455   $$ = AST::make(at_let, $1.loc, $3, $6);
02456   $$->addChild(AST::make(at_constraints));
02457 }
02458 blk_letbinding: blk_bindingpattern '=' blk_expr {
02459   SHOWPARSE("blk_letbinding -> blk_bindingpattern '=' blk_expr");
02460   $$ = AST::make(at_letbinding, $1->loc, $1, $3);
02461 };
02462 // Following not used in LET, but may end up used in LETREC:
02463 blk_letbindings: blk_letbinding {
02464   SHOWPARSE("blk_letbindings -> blk_letbinding");
02465   $$ = AST::make(at_letbindings, $1->loc, $1);
02466 };
02467 blk_letbindings: blk_letbindings SC blk_letbinding {
02468   SHOWPARSE("blk_letbindings -> blk_letbindings SC blk_letbinding");
02469   $$ = $1;
02470   $$->addChild($3);
02471 };
02472 
02473 // LETREC [5.3.2]              
02474 blk_expr: blk_expr_letrec {
02475   SHOWPARSE("blk_expr -> blk_expr_letrec");
02476   $$ = $1;
02477 }
02478 blk_expr_letrec: tk_LETREC ILCB blk_letbindings OptRCB tk_IN blk_iblock {
02479   SHOWPARSE("blk_expr_letrec -> LETREC { blk_letbindings } IN blk_iblock");
02480 
02481   shared_ptr<AST> lbs = $3;
02482   for (size_t c=0; c < lbs->children.size(); c++)
02483     lbs->child(c)->flags |= LB_REC_BIND;
02484 
02485   $$ = AST::make(at_letrec, $1.loc, lbs, $6, AST::make(at_constraints));
02486 }
02487 
02488 // FIX: Need to reconcile this with until e do { ... }, where we need
02489 // the semicolon to be inserted at start of statement. The problem
02490 // here is that UNTIL can either be a leading keyword or an internal
02491 // keyword, but not both.
02492 blk_expr: blk_expr_loop {
02493   SHOWPARSE("blk_expr -> blk_expr_loop");
02494   $$ = $1;
02495 }
02496 blk_expr_loop: tk_LOOP ILCB blk_loopbindings OptRCB tk_UNTIL blk_expr tk_IN blk_iblock {
02497   SHOWPARSE("blk_expr -> LOOP blk_loopbindings UNTIL blk_expr IN blk_iblock");
02498 
02499   // The body is executed for side effects. We need to know its result
02500   // type so that the CONTINUE block will be properly typed. Since we
02501   // are only running the body for side effects, force the result type
02502   // to be unit by appending a unit constructor after the body:
02503 
02504   shared_ptr<AST> iTest =
02505     AST::make(at_looptest, $6->loc, $6, AST::make(at_unit, $6->loc));
02506 
02507   shared_ptr<AST> iBody =
02508     AST::make(at_begin, $8->loc, $8, AST::make(at_unit, $8->loc));
02509 
02510   shared_ptr<AST> iContinueBlock =
02511     AST::make(at_labeledBlock, $1.loc,
02512               AST::make(at_ident, LToken(tk_BlkIdent, "__continue")),
02513               iBody);
02514 
02515   $$ = AST::make(at_loop, $1.loc, $3, iTest, iContinueBlock);
02516 }
02517 
02518 blk_loopbindings: {
02519   SHOWPARSE("blk_loopbindings -> <empty>");
02520   $$ = AST::make(at_loopbindings);
02521 };
02522 blk_loopbindings: blk_nonempty_loopbindings {
02523   SHOWPARSE("blk_loopbindings -> blk_nonempty_loopbindings");
02524   $$ = $1;
02525 };
02526 blk_nonempty_loopbindings: blk_expr_loopbinding {
02527   SHOWPARSE("blk_nonempty_loopbindings -> blk_expr_loopbinding");
02528   $$ = AST::make(at_loopbindings, $1->loc, $1);
02529 };
02530 blk_nonempty_loopbindings: blk_nonempty_loopbindings SC blk_expr_loopbinding {
02531   SHOWPARSE("blk_nonempty_loopbindings -> blk_nonempty_loopbindings SC blk_expr_loopbinding");
02532   $$ = $1;
02533   $$->addChild($3);
02534 };
02535 // Fix: the fact that the first is expr and the second is iblock is an
02536 // artifact of layout due to an interaction with the THEN
02537 // keyword. This is quite irritating, and we should probably change
02538 // the keyword here.
02539 blk_expr_loopbinding: blk_bindingpattern '=' blk_expr tk_THEN blk_iblock {
02540   SHOWPARSE("blk_expr_loopbinding -> blk_bindingpattern = blk_expr THEN blk_iblock");
02541   $$ = AST::make(at_loopbinding, $1->loc, $1, $3, $5);
02542 };
02543 
02544 /* Literals and Variables */
02545 // BOOLEAN LITERALS [2.4.1]
02546 trn_literal: boolLit {
02547   SHOWPARSE("trn_literal -> boolLit");
02548   $$ = $1;
02549 };
02550 // (signed) INTEGER LITERALS [2.4.1]
02551 trn_literal: intLit {
02552   SHOWPARSE("trn_literal -> intLit");
02553   $$ = $1;
02554 };
02555 
02556 // FLOATING POINT LITERALS [2.4.2]
02557 trn_literal: floatLit {
02558   SHOWPARSE("trn_literal -> floatLit");
02559   $$ = $1;
02560 };
02561 // CHARACTER LITERALS [2.4.3]
02562 trn_literal: charLit {
02563   SHOWPARSE("trn_literal -> CharLit");
02564   $$ = $1;
02565 };
02566 // STRING LITERALS [2.4.4]
02567 trn_literal: strLit {
02568   SHOWPARSE("trn_literal -> strLit");
02569   $$ = $1;
02570 };
02571 
02572 // External identifiers are not subject to reserved word restrictions...
02573 blk_exident: tk_BlkIdent {
02574   SHOWPARSE("blk_exident -> <Ident " + $1.str + ">");
02575   $$ = AST::make(at_ident, $1);
02576 };
02577 
02578 blk_exident: tk_ReservedWord {
02579   SHOWPARSE("blk_exident -> <Reserved " + $1.str + ">");
02580   $$ = AST::make(at_ident, $1);
02581 };
02582 
02583 // IDENTIFIERS [2.2]
02584 blk_ident: tk_BlkIdent {
02585   SHOWPARSE("blk_ident -> <Ident " + $1.str + ">");
02586   $$ = AST::make(at_ident, $1);
02587 };
02588 blk_ident: tk_EQUALS {
02589   SHOWPARSE("blk_ident -> <Ident \"" + $1.str + "\">");
02590   $$ = AST::make(at_ident, $1);
02591 };
02592 // These two remain keywords until we are done with the S-expression syntax:
02593 blk_ident: tk_AND {
02594   SHOWPARSE("blk_ident -> <Ident " + $1.str + ">");
02595   $$ = AST::make(at_ident, $1);
02596 };
02597 blk_ident: tk_OR {
02598   SHOWPARSE("blk_ident -> <Ident " + $1.str + ">");
02599   $$ = AST::make(at_ident, $1);
02600 };
02601 blk_ident: tk_ReservedWord {
02602   SHOWPARSE("blk_ident -> <RESERVED=" + $1.str + ">");
02603   cerr << $1.loc.asString() << ": The token \"" << $1.str
02604        << "\" is reserved for future use.\n";
02605   lexer->num_errors++;
02606   $$ = AST::make(at_ident, $1);
02607 };
02608 
02609 blk_useident: blk_ident %prec prec_PreferShift {
02610   SHOWPARSE("blk_useident -> blk_ident");
02611   $$ = $1;
02612 };
02613 
02614 blk_useident: blk_useident '.' blk_ident %prec '.' {
02615   SHOWPARSE("blk_useident -> blk_useident . blk_ident");
02616   shared_ptr<AST> usesel = AST::make(at_usesel, $2.loc, $1, $3); 
02617   usesel->s = $1->s + "." + $3->s;
02618   $$ = usesel;
02619 };
02620 
02621 blk_defident: blk_useident {
02622   SHOWPARSE("blk_defident -> blk_useident");
02623   $1->flags |= (ID_IS_GLOBAL);
02624   $$ = $1;
02625 };
02626 
02627 // TYPE VARIABLES [3.3]
02628 typevar: tk_TypeVar {
02629   SHOWPARSE("typevar -> <TypeVar=" + $1.str + ">");
02630   $$ = AST::make(at_ident, $1);
02631   $$->identType = id_tvar;
02632 };
02633 
02634 // Literal Value Representations
02635 
02636 boolLit: tk_TRUE {
02637   SHOWPARSE("boolLit -> <Bool=" + $1.str +">");
02638   $$ = AST::makeBoolLit($1);
02639 };
02640 boolLit: tk_FALSE {
02641   SHOWPARSE("boolLit -> <Bool=" + $1.str +">");
02642   $$ = AST::makeBoolLit($1);
02643 };
02644 
02645 charLit: tk_Char {
02646   SHOWPARSE("charLit -> <Char=" + $1.str +">");
02647   $$ = AST::makeCharLit($1);
02648 };
02649 
02650 intLit: tk_NegativeInt {        /* S-expression only */
02651   SHOWPARSE("intLit -> <Int=" + $1.str +">");
02652   $$ = AST::makeIntLit($1);
02653 };
02654 
02655 intLit: tk_Nat {
02656   SHOWPARSE("intLit -> <Nat=" + $1.str +">");
02657   $$ = AST::makeIntLit($1);
02658 };
02659 
02660 natLit: tk_Nat {
02661   SHOWPARSE("natLit -> <Nat=" + $1.str +">");
02662   $$ = AST::makeIntLit($1);
02663 };
02664 
02665 floatLit: tk_Float {
02666   SHOWPARSE("floatLit -> <Float=" + $1.str +">");
02667   $$ = AST::makeFloatLit($1);
02668 };
02669 
02670 strLit: tk_String {
02671   SHOWPARSE("strLit -> <String=" + $1.str +">");
02672   $$ = AST::makeStringLit($1);
02673 };
02674 
02675 // These are for transitional documentation purposes:
02676 ILCB: '{' {
02677   $$ = $1;
02678 }
02679 IRCB: '}' {
02680   $$ = $1;
02681 }
02682 
02683 //IsErrLCB: '{' {
02684 //  $$ = $1;
02685 //}
02686 //IsErrLCB: tk_IS ErrLCB {
02687 //  $$ = $2;
02688 //}
02689 
02690 // OptLCB: {
02691 // }
02692 // OptLCB: ILCB {
02693 // }
02694 OptRCB: {
02695   assert(yychar != YYEMPTY);
02696 
02697   yylval.tok.flags |= TF_REPROCESS;
02698 
02699   LToken tok = LToken('}', yylval.tok.loc, yylval.tok.loc, "}");
02700   tok.prevTokType = yylval.tok.prevTokType;
02701   yylval.tok.prevTokType = '}';
02702   tok.flags |= (TF_INSERTED|TF_BY_PARSER);
02703 
02704   lexer->pushTokenBack(yylval.tok, true);
02705   lexer->pushTokenBack(tok, true);
02706   lexer->lex(&yylval);    /* re-read for side effects */
02707 
02708   // Force parser to re-fetch the lookahead token after we reduce,
02709   // since it may have changed because of the layout rules:
02710   if (yychar != YYEMPTY)
02711     yyclearin;
02712 
02713   $$ = tok;
02714 }
02715 OptRCB: IRCB {
02716   $$ = $1;
02717 }
02718 
02719 IsILCB: tk_IS ILCB {
02720   $$ = $2;
02721 }
02722 
02723 IsILCB: '{' {
02724   $$ = $1;
02725 }
02726 
02727 //ErrLCB: '{' {
02728 //  $$ = $1;
02729 //}
02730 //ErrLCB: error {
02731 //  yyerrok;
02732 //
02733 //  assert(yychar != YYEMPTY);
02734 //
02735 //  yylval.tok.flags |= TF_REPROCESS;
02736 //
02737 //  LToken tok = LToken('{', yylval.tok.loc, yylval.tok.loc, "{");
02738 //  tok.prevTokType = yylval.tok.prevTokType;
02739 //  yylval.tok.prevTokType = '{';
02740 //  tok.flags |= (TF_INSERTED|TF_BY_PARSER);
02741 //
02742 //  lexer->pushTokenBack(yylval.tok, true);
02743 //  lexer->pushTokenBack(tok, true);
02744 //  lexer->lex(&yylval);    /* re-read for side effects */
02745 //
02746 //  // Force parser to re-fetch the lookahead token after we reduce,
02747 //  // since it may have changed because of the layout rules:
02748 //  if (yychar != YYEMPTY)
02749 //    yyclearin;
02750 //
02751 //  lexer->showNextError = false;
02752 //  $$ = tok;
02753 //}
02754 
02755 SC: {
02756   SHOWPARSE("SC -> ");
02757 }
02758 SC: ';' {
02759   SHOWPARSE("SC -> ;");
02760 }
02761 %%
02762 static void
02763 PrintSyntaxError(TransitionLexer *lexer, const char *s)
02764 {
02765   std::stringstream ss;
02766   LToken tok = lexer->getLastToken();
02767 
02768   if (!lexer->showNextError)
02769     return;
02770 
02771   ss << "Syntax error in " << s << ": unexpected ";
02772 
02773   switch(tok.tokType) {
02774   case '{':
02775   case '}':
02776   case ';':
02777     {
02778       ss << '\'' << tok.str << '\'' << " (possibly inserted by layout)";
02779       break;
02780     }
02781   case ':':
02782     {
02783       ss << '\'' << tok.str << '\'';
02784       break;
02785     }
02786   case tk_TypeVar:
02787     ss << "type variable '" << tok.str;
02788     break;
02789 
02790   case EOF:
02791     ss << tok.str;
02792     break;
02793 
02794   default:
02795     ss << '"' << tok.str << '"';
02796     break;
02797   }
02798 
02799   lexer->ReportParseError(ss.str());
02800   lexer->showNextError = false;
02801 }
02802 
02805 const char *TransitionTokenName(int lexTokenNumber)
02806 {
02807   if (lexTokenNumber == -1)
02808     return "EOF";
02809 
02810   int bisonSymbolNumber = YYTRANSLATE(lexTokenNumber);
02811   const char * bisonTokenName = yytname[bisonSymbolNumber];
02812 
02813   return bisonTokenName;
02814 }

Generated on Fri Feb 10 07:59:20 2012 for BitC Compiler by  doxygen 1.4.7