SexprParser.y

Go to the documentation of this file.
00001 %{
00002   /*
00003    * Copyright (C) 2008, The EROS Group, LLC.
00004    * All rights reserved.
00005    *
00006    * Redistribution and use in source and binary forms, with or
00007    * without modification, are permitted provided that the following
00008    * conditions are met:
00009    *
00010    *   - Redistributions of source code must contain the above 
00011    *     copyright notice, this list of conditions, and the following
00012    *     disclaimer. 
00013    *
00014    *   - Redistributions in binary form must reproduce the above
00015    *     copyright notice, this list of conditions, and the following
00016    *     disclaimer in the documentation and/or other materials 
00017    *     provided with the distribution.
00018    *
00019    *   - Neither the names of the copyright holders nor the names of any
00020    *     of any contributors may be used to endorse or promote products
00021    *     derived from this software without specific prior written
00022    *     permission. 
00023    *
00024    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00027    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035    */
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 (SexprLexer *)lexer
00070 #undef yyerror
00071 #define yyerror(lexer, s) lexer->ReportParseError(s)
00072 
00073 #include "SexprLexer.hxx"
00074 
00075 #define SHOWPARSE(s) \
00076   do { \
00077     if (Options::showParse) \
00078       lexer->errStream << (s) << std::endl;                \
00079   } while (false);
00080 #define SHOWPARSE1(s,x) \
00081   do { \
00082     if (Options::showParse) \
00083       lexer->errStream << (s) << " " << (x) << std::endl;        \
00084   } while (false);
00085 
00086 
00087 inline int sexpr_lex(YYSTYPE *lvalp, SexprLexer *lexer)
00088 {
00089   return lexer->lex(lvalp);
00090 }
00091 
00092 // If the passed exprSeq has a documentation string at the front,
00093 // remove it. Note that if the exprSeq has length 1 then the string is
00094 // the expression value and not a documentation comment.
00095 static shared_ptr<AST> 
00096 stripDocString(shared_ptr<AST> exprSeq)
00097 {
00098   if (exprSeq->children.size() > 1 &&
00099       exprSeq->child(0)->astType == at_stringLiteral)
00100     exprSeq->disown(0);
00101 
00102   return exprSeq;
00103 }
00104 
00105 %}
00106 
00107 %pure-parser
00108 %parse-param {SexprLexer *lexer}
00109 
00110 %token <tok> tk_ReservedWord        /* reserved words */
00111 
00112 /* Categorical terminals: */
00113 %token <tok> tk_Ident
00114 %token <tok> tk_TypeVar
00115 %token <tok> tk_EffectVar
00116 %token <tok> tk_Int
00117 %token <tok> tk_Float
00118 %token <tok> tk_Char
00119 %token <tok> tk_String
00120 
00121 /* Primary types and associated hand-recognized literals: */
00122 %token <tok> '(' ')' ','        /* unit */
00123 %token <tok> '[' ']'
00124 %token <tok> '.'
00125 %token <tok> tk_AS
00126 %token <tok> tk_BOOL
00127 %token <tok> tk_TRUE   /* #t */
00128 %token <tok> tk_FALSE  /* #f */
00129 %token <tok> tk_CHAR
00130 %token <tok> tk_STRING
00131 %token <tok> tk_FLOAT
00132 %token <tok> tk_DOUBLE
00133 %token <tok> tk_DUP
00134 %token <tok> tk_QUAD
00135 %token <tok> tk_INT8
00136 %token <tok> tk_INT16
00137 %token <tok> tk_INT32
00138 %token <tok> tk_INT64
00139 %token <tok> tk_UINT8
00140 %token <tok> tk_UINT16
00141 %token <tok> tk_UINT32
00142 %token <tok> tk_UINT64
00143 %token <tok> tk_WORD
00144 
00145 %token <tok> tk_SIZEOF
00146 %token <tok> tk_BITSIZEOF
00147 
00148 %token <tok> tk_BITFIELD
00149 %token <tok> tk_FILL
00150 %token <tok> tk_RESERVED
00151 %token <tok> tk_WHERE
00152   
00153 %token <tok> tk_BITC_VERSION
00154 
00155 %token <tok> tk_PURE
00156 %token <tok> tk_IMPURE
00157 %token <tok> tk_CONST
00158 
00159 %token <tok> tk_THE
00160 %token <tok> tk_IF
00161 %token <tok> tk_WHEN
00162 %token <tok> tk_AND
00163 %token <tok> tk_OR
00164 %token <tok> tk_COND
00165 %token <tok> tk_SWITCH
00166 %token <tok> tk_CASE
00167 %token <tok> tk_OTHERWISE
00168 
00169 %token <tok> tk_BLOCK tk_RETURN_FROM
00170 %token <tok> tk_RETURN tk_CONTINUE
00171 
00172 %token <tok> tk_PAIR
00173 %token <tok> tk_VECTOR
00174 %token <tok> tk_ARRAY
00175  //%token <tok> tk_MAKE_VECTOR
00176 %token <tok> tk_MAKE_VECTORL
00177 %token <tok> tk_NTH
00178 
00179 %token <tok> tk_DEFSTRUCT
00180 %token <tok> tk_DEFOBJECT
00181 %token <tok> tk_DEFUNION
00182 %token <tok> tk_DEFREPR
00183 %token <tok> tk_DEFTHM
00184 %token <tok> tk_DEFINE
00185 %token <tok> tk_DECLARE
00186 %token <tok> tk_PROCLAIM
00187 %token <tok> tk_EXTERNAL
00188 %token <tok> tk_TAG
00189 %token <tok> tk_DEFEXCEPTION
00190 
00191 %token <tok> tk_MUTABLE
00192 %token <tok> tk_SET
00193 %token <tok> tk_DEREF
00194 %token <tok> tk_REF
00195 %token <tok> tk_INNER_REF
00196 %token <tok> tk_VAL
00197 %token <tok> tk_OPAQUE
00198 %token <tok> tk_CLOSED
00199 %token <tok> tk_MEMBER
00200 %token <tok> tk_LAMBDA
00201 %token <tok> tk_LET
00202 %token <tok> tk_LETREC
00203 %token <tok> tk_FN
00204 %token <tok> tk_FNARROW
00205 %token <tok> tk_BEGIN
00206 %token <tok> tk_DO
00207 %token <tok> tk_APPLY
00208 %token <tok> tk_BY_REF
00209 %token <tok> tk_ARRAY_REF
00210 
00211 %token <tok> tk_EXCEPTION
00212 %token <tok> tk_TRY
00213 %token <tok> tk_CATCH
00214 %token <tok> tk_THROW
00215 
00216 %token <tok> tk_METHOD
00217 %token <tok> tk_DEFTYPECLASS
00218 %token <tok> tk_DEFINSTANCE
00219 %token <tok> tk_FORALL
00220 
00221 %token <tok> tk_INTERFACE
00222 %token <tok> tk_MODULE
00223 // token tk_USESEL historic significance only 
00224 // %token <tok> tk_USESEL
00225 %token <tok> tk_IMPORT
00226 %token <tok> tk_PROVIDE
00227 
00228 %token <tok> tk_TYFN
00229 //%token <tok> tk_SUPER
00230 %token <tok> tk_SUSPEND
00231 %type <tok>  ifident
00232 
00233 //%token <tok> tk_EXPORT
00234    
00235 %type <ast> module implicit_module module_seq
00236 %type <ast> interface
00237 %type <ast> defpattern
00238 %type <ast> mod_definitions mod_definition
00239 %type <ast> if_definitions if_definition
00240 %type <ast> common_definition
00241 %type <ast> value_declaration
00242 %type <ast> ptype_name val openclosed
00243 %type <ast> type_definition typeapp
00244 %type <ast> type_decl externals alias
00245 %type <ast> importList provideList
00246 %type <ast> type_cpair eform_cpair
00247 %type <ast> value_definition tc_definition ti_definition
00248 %type <ast> import_definition provide_definition
00249 %type <ast> tc_decls tc_decl ow
00250 %type <ast> declares declare decls decl
00251 %type <ast> constructors constructor 
00252 %type <ast> repr_constructors repr_constructor 
00253 %type <ast> repr_reprs repr_repr 
00254 %type <ast> bindingpattern lambdapatterns lambdapattern
00255 %type <ast> expr_seq 
00256 %type <ast> qual_type
00257 %type <ast> expr the_expr eform method_decls method_decl
00258 %type <ast> method_bindings method_binding
00259 %type <ast> constraints constraint_seq constraint 
00260 %type <ast> types type bitfieldtype bool_type 
00261 %type <ast> field_type type_pl_byref types_pl_byref
00262 %type <ast> int_type uint_type any_int_type float_type
00263 %type <ast> tvlist
00264 %type <ast> fields field 
00265 %type <ast> fields_and_methods methods_only methdecl
00266 %type <ast> literal typevar //mod_ident
00267 %type <ast> ident defident useident switch_matches switch_match
00268 %type <ast> exident
00269 %type <ast> docstring optdocstring
00270 %type <ast> condcases condcase fntype method_type
00271 %type <ast> fneffect
00272  //%type <ast> reprbody reprbodyitems reprbodyitem reprtags reprcase reprcaseleg
00273 //%type <ast> typecase_leg typecase_legs 
00274 %type <ast> sw_legs sw_leg otherwise
00275 //%type <ast> catchclauses catchclause
00276 %type <ast> letbindings letbinding
00277 %type <ast> dobindings ne_dobindings dobinding dotest
00278 %type <ast> intLit floatLit charlit strLit boolLit  
00279 %type <ast> let_eform
00280 %type <ast> type_val_definition
00281 %type <ast> constrained_definition
00282 %%
00283 
00284 // Parser built for version 0.9
00285 // Section Numbers indicated within []
00286 
00287 // COMPILATION UNITS [2.5]
00288 // This definition od start mus be changed as it ignores
00289 // junk after the body.
00290 
00291 start: version uoc_body {
00292   SHOWPARSE("start -> version uoc_body");
00293   return 0;
00294 };
00295 
00296 start: uoc_body {
00297   SHOWPARSE("start -> uoc_body");
00298   return 0;
00299 };
00300 
00301 uoc_body: interface {
00302   SHOWPARSE("uocbody -> interface");
00303 }
00304 
00305 uoc_body: implicit_module {
00306   SHOWPARSE("uocbody -> implicit_module");
00307 }
00308 
00309 uoc_body: module_seq {
00310   SHOWPARSE("uocbody -> module_seq");
00311 }
00312 
00313 // VERSION [2.5]
00314 
00315 // We cannot do optversion, because that would require two token look-ahead.
00316 version: '(' tk_BITC_VERSION strLit ')' {
00317   SHOWPARSE("version -> ( BITC-VERSION strLit )");
00318   if (!CheckVersionCompatibility($3->s)) {
00319     std::string s = ": Warning: BitC version conflict " + $3->s + " vs " + Version();
00320     lexer->ReportParseWarning($3->loc, s);
00321   }
00322 }; 
00323 
00324 // It would be really nice to support this, but the tokenizer will
00325 // report the literal as a floating point value. We could, I suppose,
00326 // crack that back into its constituent parts, but I don't have the
00327 // energy to implement that today.
00328 // version: '(' tk_BITC_VERSION intLit '.' intLit ')' {
00329 //   SHOWPARSE("version -> ( BITC-VERSION intLit '.' intLit )");
00330 //   if (!CheckVersionCompatibility($3->litValue.i, $5->litValue.i)) {
00331 //     std::string s = ": Warning: BitC version conflict " + $3->s + " vs " + Version();
00332 //     lexer->ReportParseWarning($3->loc, s);
00333 //   }
00334 // }; 
00335 
00336 // Documentation comments. These are added only in productions where
00337 // they do NOT appear before expr_seq. If a string literal appears as
00338 // the first form of a multiform expr_seq, it won't hurt anything. If
00339 // it is the *only* form, then it is the value in any case, and that
00340 // is fine. We can figure out which case is which in the documentation
00341 // extractor.
00342 docstring: tk_String {
00343   SHOWPARSE("docstring -> STRING");
00344   $$ = AST::make(at_docString, $1.loc, AST::makeStringLit($1));
00345 };
00346 optdocstring: docstring {
00347   SHOWPARSE("optdocstring -> docstring");
00348   $$ = $1;
00349 };
00350 optdocstring: {
00351   SHOWPARSE("optdocstring -> ");
00352   $$ = AST::make(at_docString);
00353 };
00354 
00355 // INTERFACES [8.1]
00356 interface: '(' tk_INTERFACE ifident {
00357     if ($3.str.find("bitc.") == 0)
00358       lexer->isRuntimeUoc = true;
00359   }
00360   optdocstring if_definitions ')' {
00361   SHOWPARSE("interface -> INTERFACE ifident optdocstring if_definitions");  
00362   shared_ptr<AST> ifIdent = AST::make(at_ident, $3);
00363   $$ = AST::make(at_interface, $2.loc, ifIdent);
00364   $$->addChildrenFrom($6);
00365 
00366   if (lexer->isCommandLineInput) {
00367     const char *s =
00368       ": Warning: interface units of compilation should no longer\n"
00369       "    be given on the command line.\n";
00370     lexer->ReportParseWarning($$->loc, s);
00371   }
00372 
00373   std::string uocName = ifIdent->s;
00374   shared_ptr<UocInfo> uoc = 
00375     UocInfo::make(uocName, lexer->here.origin, $$);
00376 
00377   if (uocName == "bitc.prelude")
00378     uoc->flags |= UOC_IS_PRELUDE;
00379 
00380   shared_ptr<UocInfo> existingUoc = UocInfo::findInterface(uocName);
00381 
00382   if (existingUoc) {
00383     std::string s = "Error: This interface has already been loaded from "
00384       + existingUoc->uocAst->loc.asString();
00385     lexer->ReportParseError($$->loc, s);
00386 
00387   }
00388   else  {
00389     /* Put the UoC onto the interface list so that we do not recurse on
00390        import. */
00391     UocInfo::ifList[uocName] = uoc;
00392   }
00393     
00394   // Regardless, compile the new interface to check for further
00395   // warnings and/or errors:
00396   uoc->Compile();
00397 };
00398 
00399 ifident: {
00400     lexer->setIfIdentMode(true);
00401   } ident {
00402   lexer->setIfIdentMode(false);
00403   $$ = LToken($2->loc, $2->s);
00404 };
00405 ifident: ifident '.' {
00406     lexer->setIfIdentMode(true);
00407   } tk_Ident {
00408   lexer->setIfIdentMode(false);
00409   $$ = LToken($1.loc, $1.str + "." + $4.str);
00410 };
00411 
00412 // MODULES [2.5]
00413 implicit_module: mod_definitions  {
00414  SHOWPARSE("implicit_module -> mod_definitions");
00415  $$ = $1;
00416  $$->astType = at_module;
00417  $$->printVariant = pf_IMPLIED;
00418 
00419  // Construct, compile, and admit the parsed UoC:
00420  string uocName = 
00421    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00422 
00423  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00424  lexer->nModules++;
00425 
00426  uoc->Compile();
00427  UocInfo::srcList[uocName] = uoc;
00428 };
00429 
00430 module: '(' tk_MODULE optdocstring mod_definitions ')' {
00431  SHOWPARSE("module -> ( tk_MODULE optdocstring mod_definitions )");
00432  $$ = $4;
00433  $$->astType = at_module;
00434 
00435  string uocName = 
00436    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00437 
00438  // Construct, compile, and admit the parsed UoC:
00439  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00440  lexer->nModules++;
00441  uoc->Compile();
00442  UocInfo::srcList[uocName] = uoc;
00443 };
00444 
00445 module: '(' tk_MODULE ifident optdocstring mod_definitions ')' {
00446  SHOWPARSE("module -> ( tk_MODULE ifident optdocstring mod_definitions )");
00447  $$ = $5;
00448  $$->astType = at_module;
00449 
00450  // Construct, compile, and admit the parsed UoC.
00451  // Note that we do not even consider the user-provided module name
00452  // for purposes of internal naming, because it is not significant.
00453  string uocName = 
00454    UocInfo::UocNameFromSrcName(lexer->here.origin, lexer->nModules);
00455 
00456  shared_ptr<UocInfo> uoc = UocInfo::make(uocName, lexer->here.origin, $$);
00457  lexer->nModules++;
00458  uoc->Compile();
00459  UocInfo::srcList[uocName] = uoc;
00460 };
00461 
00462 module_seq: module {
00463  SHOWPARSE("module_seq -> module");
00464 }
00465 
00466 module_seq: module_seq module {
00467  SHOWPARSE("module_seq -> module_seq module");
00468 }
00469 
00470 // INTERFACE TOP LEVEL DEFINITIONS
00471 if_definitions: if_definition {
00472   SHOWPARSE("if_definitions -> if_definition");
00473   $$ = AST::make(at_Null, $1->loc, $1);
00474 };
00475 
00476 if_definitions: if_definitions if_definition {
00477   SHOWPARSE("if_definitions -> if_definitions if_definition");
00478   $$ = $1;
00479   $$->addChild($2);   
00480 };
00481 
00482 if_definition: common_definition {
00483   SHOWPARSE("if_definition -> common_definition");
00484   $$ = $1;
00485 };
00486 
00487 // TOP LEVEL DEFINITIONS [2.5.1]
00488 constrained_definition: '(' tk_FORALL constraints type_val_definition ')' {
00489   // HACK ALERT!!! For reasons of ancient history, there is no
00490   // at_forall AST. Instead, all of the type_val_definition ASTs have
00491   // their constraints tacked on at the end. This is rather badly
00492   // glitched and we need to fix it, but the immediate goal was to
00493   // move the (forall ...) syntax to the outside without doing major
00494   // surgery on the compiler internals.
00495 
00496   uint32_t nChildren = $4->children.size();
00497 
00498   shared_ptr<AST> tvConstraints= $4->child(nChildren-1);
00499   tvConstraints->addChildrenFrom($3);
00500   $$ = $4;
00501 };
00502 
00503 mod_definitions: mod_definition {
00504   SHOWPARSE("mod_definitions -> mod_definition");
00505   $$ = AST::make(at_Null, $1->loc, $1);
00506 };
00507 
00508 mod_definitions: mod_definitions mod_definition {
00509   SHOWPARSE("mod_definitions -> mod_definitions mod_definition");
00510   $$ = $1;
00511   $$->addChild($2);   
00512 };
00513 
00514 mod_definition: provide_definition {
00515   SHOWPARSE("mod_definition -> provide_definition");
00516   $$ = $1;
00517 };
00518 mod_definition: common_definition {
00519   SHOWPARSE("mod_definition -> common_definition");
00520   $$ = $1;
00521 };
00522 
00523 common_definition: import_definition {
00524   SHOWPARSE("common_definition -> import_definition");
00525   $$ = $1;
00526 };
00527 
00528 common_definition: type_val_definition {
00529   SHOWPARSE("common_definition -> type_val_definition");
00530   $$ = $1;
00531 };
00532 
00533 common_definition: constrained_definition {
00534   SHOWPARSE("common_definition -> constrained_definition");
00535   $$ = $1;
00536 };
00537 
00538 type_val_definition: type_definition {
00539   SHOWPARSE("type_val_definition -> type_definition");
00540   $$ = $1;
00541 };
00542 
00543 type_val_definition: type_decl {
00544   SHOWPARSE("type_val_definition -> type_decl");
00545   $$ = $1;
00546 };
00547 
00548 type_val_definition: value_definition {
00549   SHOWPARSE("type_val_definition -> value_definition");
00550   $$ = $1;
00551 };
00552 
00553 type_val_definition: value_declaration {
00554   SHOWPARSE("type_val_definition -> value_declaration");
00555   $$ = $1;
00556 };
00557 
00558 type_val_definition: tc_definition {
00559   SHOWPARSE("type_val_definition -> tc_definition");
00560   $$ = $1;
00561 };
00562 
00563 type_val_definition: ti_definition {
00564   SHOWPARSE("type_val_definition -> ti_definition");
00565   $$ = $1;
00566 };
00567 
00568 // DECLARE [8.4.2]
00569 //common_definition: declare {
00570 //  SHOWPARSE("common_definition -> declare");
00571 //  $$ = $1;
00572 //};
00573 
00574 //Typeclass constraint declarations
00575 
00576 constraints: '(' constraint_seq ')' {
00577  SHOWPARSE("constraints -> ( constraint_seq )");  
00578  $$ = $2; 
00579 };
00580 
00581 constraint_seq: constraint_seq constraint {
00582  SHOWPARSE("constraint_seq -> constraint_seq constraint");  
00583  $$ = $1;
00584  $$->addChild($2);
00585 };
00586  
00587 constraint_seq: constraint {
00588  SHOWPARSE("constraint_seq -> constraint");  
00589  $$ = AST::make(at_constraints, $1->loc, $1);
00590 };
00591 
00592 constraint: typeapp {
00593  SHOWPARSE("constraint -> typeapp");  
00594  $1->astType = at_tcapp;
00595  $$ = $1;
00596 };
00597 
00598 constraint: useident {
00599  SHOWPARSE("constraint -> useident");  
00600  $$ = AST::make(at_tcapp, $1->loc, $1); 
00601 };
00602 
00603 
00604 // FIX: This should probably get its own AST type.
00605 ptype_name: defident {
00606   SHOWPARSE("ptype_name -> defident");
00607   shared_ptr<AST> tvlist = AST::make(at_tvlist, $1->loc);
00608   shared_ptr<AST> constraints = AST::make(at_constraints, $1->loc);
00609   $$ = AST::make(at_Null, $1->loc, $1, tvlist, constraints);  
00610 };
00611 
00612 ptype_name: '(' defident tvlist ')' {
00613   SHOWPARSE("ptype_name -> '(' defident tvlist ')'");
00614   shared_ptr<AST> constraints = AST::make(at_constraints, $2->loc);
00615   $$ = AST::make(at_Null, $2->loc, $2, $3, constraints);
00616 };
00617 
00618 //ptype_name: '(' tk_FORALL constraints defident ')' {
00619 //  SHOWPARSE("ptype_name -> '(' FORALL constraints '(' defident tvlist ')' ')' ");
00620 //  shared_ptr<AST> tvlist = AST::make(at_tvlist, $4->loc);
00621 //  $$ = AST::make(at_Null, $2.loc, $4, tvlist, $3);
00622 //};
00623 //
00624 //ptype_name: '(' tk_FORALL constraints '(' defident tvlist ')' ')' {
00625 //  SHOWPARSE("ptype_name -> '(' FORALL constraints '(' defident tvlist ')' ')' ");
00626 //  $$ = AST::make(at_Null, $2.loc, $5, $6, $3);
00627 //};
00628 
00629 // STRUCTURE TYPES [3.6.1]           
00630 type_definition: '(' tk_DEFSTRUCT ptype_name val optdocstring declares fields_and_methods ')'  {
00631   SHOWPARSE("type_definition -> ( DEFSTRUCT ptype_name val "
00632             "optdocstring declares fields )");
00633   $$ = AST::make(at_defstruct, $2.loc, $3->child(0), $3->child(1), $4,
00634                $6, $7);
00635   $$->child(0)->defForm = $$;
00636   $$->addChild($3->child(2));
00637 };
00638 
00639 
00640 // UNION TYPES [3.6.2]                
00641 type_definition: '(' tk_DEFUNION ptype_name val optdocstring declares constructors  ')'  {
00642   SHOWPARSE("type_definition -> ( DEFUNION ptype_name val "
00643             "optdocstring declares constructors");
00644   $$ = AST::make(at_defunion, $2.loc, $3->child(0), $3->child(1), $4,
00645                $6, $7);
00646   $$->child(0)->defForm = $$;
00647   $$->addChild($3->child(2));  
00648 };
00649 
00650 /* // REPR TYPES */
00651 /* type_definition: '(' tk_DEFREPR defident val optdocstring declares reprbody  ')'  { */
00652 /*   SHOWPARSE("type_definition -> ( DEFUNION ptype_name val " */
00653 /*             "optdocstring declares reprbody"); */
00654 /*   $$ = AST::make(at_defrepr, $2.loc, $3->child(0), $3->child(1), $4, */
00655 /*                $6, $7); */
00656 /*   $$->addChild($3->child(2));   */
00657 /* }; */
00658 /* reprbody: '(' reprbodyitems ')' { */
00659 /*   SHOWPARSE("reprbody -> reprbodyitems"); */
00660 /*   $$ = $2; */
00661 /* }; */
00662 
00663 /* reprbodyitems: reprbodyitem { */
00664 /*   SHOWPARSE("reprbodyitems -> reprbodyitem"); */
00665 /*   $$ = AST::make(at_reprbody, $1->loc, $1); */
00666 /* }; */
00667 
00668 /* reprbodyitems: reprbodyitems reprbodyitem { */
00669 /*   SHOWPARSE("reprbodyitems -> reprbodyitems reprbodyitem"); */
00670 /*   $$ = $1; */
00671 /*   $$->addChild($2); */
00672 /* }; */
00673 
00674 /* reprbodyitem: field { */
00675 /*   SHOWPARSE("reprbodyitem -> field"); */
00676 /*   $$ = $1; */
00677 /* }; */
00678 
00679 /* reprbodyitem: '(' tk_TAG reprtags ')' { */
00680 /*   SHOWPARSE("reprbodyitem -> '(' TAG reprtags ')' "); */
00681 /*   $$ = $3; */
00682 /*   $$->loc = $2.loc; */
00683 /* }; */
00684 
00685 /* reprbodyitem: '(' tk_THE field_type '(' tk_TAG reprtags ')' ')' { */
00686 /*   SHOWPARSE("reprbodyitem -> '(' TAG reprtags ')' "); */
00687 /*   $$ = $6; */
00688 /*   $$->loc = $5.loc; */
00689 /* }; */
00690 
00691 /* reprbodyitem: '(' tk_CASE reprcase ')' { */
00692 /*   SHOWPARSE("reprbodyitem -> '(' CASE reprcases ')' "); */
00693 /*   $$ = $3; */
00694 /*   $$->loc = $2.loc; */
00695 /* }; */
00696 
00697 /* reprcase: reprcaseleg { */
00698 /*   SHOWPARSE("reprcase -> reprcaseleg"); */
00699 /*   $$ = AST::make(at_reprcase, $1->loc, $1); */
00700 /* }; */
00701 
00702 /* reprcase: reprcase reprcaseleg { */
00703 /*   SHOWPARSE("reprcase -> reprcase reprcaseleg"); */
00704 /*   $$ = $1; */
00705 /*   $$->addChild($2); */
00706 /* }; */
00707 
00708 /* reprcaseleg: '(' reprtags reprbody ')' { */
00709 /*   SHOWPARSE("reprcaseleg -> reprtags reprbody"); */
00710 /*   $$ = AST::make(at_reprcaselegR, $1.loc, $3); */
00711 /*   $$->addChildrenFrom($2); */
00712 /* }; */
00713 
00714 /* reprtags: ident { */
00715 /*   SHOWPARSE("reprtags -> ident"); */
00716 /*   $$ = AST::make(at_reprtag, $1->loc, $1); /\* dummy AST type *\/ */
00717 /* }; */
00718 
00719 /* reprtags: reprtags ident { */
00720 /*   SHOWPARSE("reprtags -> reprtags ident"); */
00721 /*   $$ = $1; */
00722 /*   $$->addChild($2); */
00723 /* }; */
00724 
00725 // REPR TYPES
00726 type_definition: '(' tk_DEFREPR defident val optdocstring declares repr_constructors  ')'  {
00727   SHOWPARSE("type_definition -> ( DEFREPR defident val "
00728             "optdocstring declares repr_constructors");
00729   $$ = AST::make(at_defrepr, $2.loc, $3, $4, $6, $7);
00730   $$->child(0)->defForm = $$;
00731 };
00732 
00733 // Type Declarations
00734 // External declarations
00735 externals: /* nothing */ {
00736   SHOWPARSE("externals -> ");
00737   $$ = AST::make(at_Null);
00738   $$->flags = NO_FLAGS;
00739 };
00740 
00741 externals: tk_EXTERNAL {
00742   SHOWPARSE("externals -> EXTERNAL");
00743   $$ = AST::make(at_Null, $1.loc);
00744   $$->flags = DEF_IS_EXTERNAL;
00745 };
00746 
00747 externals: tk_EXTERNAL exident {
00748   SHOWPARSE("externals -> EXTERNAL exident");
00749   $$ = AST::make(at_Null, $1.loc);
00750   $$->flags = DEF_IS_EXTERNAL;  
00751   $$->externalName = $2->s;
00752 };
00753 
00754 
00755 // OBJECT TYPES [3.6.1]           
00756 type_definition: '(' tk_DEFOBJECT ptype_name optdocstring declares methods_only ')'  {
00757   SHOWPARSE("type_definition -> ( DEFSTRUCT ptype_name val "
00758             "optdocstring declares fields )");
00759 
00760   // For the moment, all objects are value types:
00761   shared_ptr<AST> valCat = AST::make(at_valCat, LToken($2.loc, "val"));
00762 
00763   $$ = AST::make(at_defobject, $2.loc, $3->child(0), $3->child(1), 
00764                  valCat,
00765                  $5, $6);
00766   $$->child(0)->defForm = $$;
00767   $$->addChild($3->child(2));
00768 };
00769 
00770 
00771 // STRUCTURE DECLARATIONS
00772 type_decl: '(' tk_DEFSTRUCT ptype_name val externals ')' {
00773   SHOWPARSE("type_decl -> ( DEFSTRUCT ptype_name val externals )");
00774   $$ = AST::make(at_declstruct, $2.loc, $3->child(0), $3->child(1), $4,
00775                $3->child(2));
00776   $$->child(0)->defForm = $$;
00777   $$->flags |= $5->flags;
00778   $$->getID()->flags |= $5->flags;
00779   $$->getID()->externalName = $5->externalName;
00780 };
00781 
00782 // UNION DECLARATIONS
00783 type_decl: '(' tk_DEFUNION ptype_name val externals ')' {
00784   SHOWPARSE("type_decl -> ( DEFUNION ptype_name val )");
00785   $$ = AST::make(at_declunion, $2.loc, $3->child(0), $3->child(1), $4,
00786                $3->child(2));
00787   $$->child(0)->defForm = $$;
00788   $$->flags |= $5->flags;
00789   $$->getID()->flags |= $5->flags;
00790   $$->getID()->externalName = $5->externalName;
00791 };
00792 
00793 // REPR DECLARATIONS
00794 type_decl: '(' tk_DEFREPR defident val externals ')' {
00795   SHOWPARSE("type_decl -> ( DEFREPR defident val externals )");
00796   $$ = AST::make(at_declrepr, $2.loc, $3, $4);
00797   $$->child(0)->defForm = $$;
00798   $$->flags |= $5->flags;
00799   $$->getID()->flags |= $5->flags;
00800   $$->getID()->externalName = $5->externalName;
00801 };
00802 
00803 // CATEGORIES
00804 
00805 val: { 
00806   SHOWPARSE("val -> <empty>");
00807   $$ = AST::make(at_refCat);
00808   $$->printVariant = pf_IMPLIED;
00809 };
00810 
00811 val: ':' tk_VAL {
00812   SHOWPARSE("val -> ':' VAL");
00813   $$ = AST::make(at_valCat, $2);
00814 };
00815 val: ':' tk_OPAQUE {
00816   SHOWPARSE("val -> ':' OPAQUE");
00817   $$ = AST::make(at_opaqueCat, $2);
00818 };
00819 val: ':' tk_REF {
00820   /* Same as :ref, since that is the default. */
00821   SHOWPARSE("val -> ':' REF");
00822   $$ = AST::make(at_refCat, $2);
00823 };
00824  
00825 openclosed: { 
00826   SHOWPARSE("closed -> <empty>");
00827   $$ = AST::make(at_Null);
00828   $$->printVariant = pf_IMPLIED;
00829 };
00830 
00831 openclosed: ':' tk_CLOSED {
00832   SHOWPARSE("closed -> ':' CLOSED");
00833   $$ = AST::make(at_closed, $2);
00834 };
00835 
00836 // EXCEPTION DEFINITION [3.10]
00837 type_definition: '(' tk_DEFEXCEPTION ident optdocstring ')' {
00838   SHOWPARSE("type_definition -> ( defexception ident )");
00839   $3->flags |= ID_IS_GLOBAL;
00840   $$ = AST::make(at_defexception, $2.loc, $3);
00841   $$->child(0)->defForm = $$;
00842 };
00843 
00844 type_definition: '(' tk_DEFEXCEPTION ident optdocstring fields ')' {
00845   SHOWPARSE("type_definition -> ( defexception ident fields )");
00846   $3->flags |= ID_IS_GLOBAL;
00847   $$ = AST::make(at_defexception, $2.loc, $3);
00848   $$->child(0)->defForm = $$;
00849   $$->addChildrenFrom($5);
00850 };
00851 
00852 // TYPE CLASSES [4]
00853 // TYPE CLASS DEFINITION [4.1]
00854 
00855 tc_definition: '(' tk_DEFTYPECLASS ptype_name optdocstring tc_decls openclosed method_decls ')' {
00856   SHOWPARSE("tc_definition -> ( DEFTYPECLASS ptype_name optdocstring tc_decls openclosed method_decls)");
00857   $$ = AST::make(at_deftypeclass, $2.loc, $3->child(0), 
00858                  $3->child(1), $5, $6, $7);
00859   $$->addChild($3->child(2));
00860   $$->child(0)->defForm = $$;
00861 };
00862 
00863 //tc_definition: '(' tk_DEFTYPECLASS ptype_name optdocstring tc_decls method_decls ')' {
00864 //  SHOWPARSE("tc_definition -> ( DEFTYPECLASS ptype_name optdocstring tc_decls openclosed method_decls)");
00865 //  $$ = AST::make(at_deftypeclass, $2.loc, $3->child(0), 
00866 //                 $3->child(1), $5, $6, $3->child(2));  
00867 //  $$->child(0)->defForm = $$;
00868 //};
00869 
00870 tc_decls: {
00871   SHOWPARSE("tcdecls -> <empty>");
00872   $$ = AST::make(at_tcdecls);
00873 };
00874 
00875 tc_decls: tc_decls tc_decl {
00876   SHOWPARSE("tcdecls -> tcdelcs tcdecl");
00877   $$ = $1;
00878   $$->addChild($2);
00879 };
00880 
00881 tc_decl: '(' tk_TYFN '(' tvlist ')' typevar ')' {
00882   //                     ^^^^^^
00883   // I really mean tvlist here, arbitraty types
00884   // are not accepptable.
00885   SHOWPARSE("tc_decl -> ( TYFN ( tvlist ) typevar )");
00886   $4->astType = at_fnargVec;
00887   $$ = AST::make(at_tyfn, $2.loc, $4, $6);  
00888 };
00889 
00890 method_decls: /* Nothing */ {
00891   SHOWPARSE("method_decls -> ");
00892   LexLoc loc;
00893   $$ = AST::make(at_method_decls, loc);
00894 };
00895 
00896 method_decls: method_decls method_decl {
00897   SHOWPARSE("method_decls -> method_decls method_decl");
00898   $$ = $1;
00899   $$->addChild($2);
00900 };
00901 
00902 method_decl: ident ':' fntype {
00903   SHOWPARSE("method_decl -> ident : fntype");
00904   $1->flags |= ID_IS_GLOBAL;
00905   $1->identType = id_tcmethod;
00906   $$ = AST::make(at_method_decl, $1->loc, $1, $3);
00907 };
00908 
00909 // TYPE CLASS INSTANTIATIONS [4.2]
00910 // No docstring here because method_seq is really a potentially empty
00911 // expr_seq
00912 ti_definition: '(' tk_DEFINSTANCE constraint optdocstring ')' {
00913   SHOWPARSE("ti_definition -> ( DEFINSTANCE constraint [docstring])");
00914   $$ = AST::make(at_definstance, $2.loc, $3, 
00915                  AST::make(at_tcmethods, $5.loc),
00916                  AST::make(at_constraints, $3->loc));
00917 };
00918 ti_definition: '(' tk_DEFINSTANCE constraint optdocstring method_bindings ')' {
00919   SHOWPARSE("ti_definition -> ( DEFINSTANCE constraint [docstring] method_bindings)");
00920   $$ = AST::make(at_definstance, $2.loc, $3, $5, 
00921                  AST::make(at_constraints, $3->loc));
00922 };
00923 
00924 method_bindings: method_binding {
00925   SHOWPARSE("method_bindings -> method_binding");
00926   $$ = AST::make(at_tcmethods, $1->loc, $1);
00927 };
00928 
00929 method_bindings: method_bindings method_binding {
00930   SHOWPARSE("method_bindings -> method_bindings method_binding");
00931   $$ = $1;
00932   $$->addChild($2);
00933 };
00934 
00935 method_binding: '(' ident ident expr ')' {
00936   SHOWPARSE("method_binding -> ( ident = expr )");
00937   
00938   if ($3->s != "=") {
00939     cerr << $2->loc << ": Syntax error, expecting `='.\n";
00940     lexer->num_errors++;
00941   }
00942   
00943   $$ = AST::make(at_tcmethod_binding, $1.loc, $2, $4);
00944 };
00945 
00946 // DEFINE  [5.1]
00947 value_definition: '(' tk_DEFINE defpattern expr ')'  {
00948   SHOWPARSE("value_definition -> ( DEFINE  defpattern expr )");
00949   $$ = AST::make(at_define, $2.loc, $3, $4);
00950   $$->addChild(AST::make(at_constraints));
00951 };
00952 value_definition: '(' tk_DEFINE defpattern docstring expr ')'  {
00953   SHOWPARSE("value_definition -> ( DEFINE  defpattern docstring expr )");
00954   $$ = AST::make(at_define, $2.loc, $3, $5);
00955   $$->addChild(AST::make(at_constraints));
00956 };
00957 
00958 // Define convenience syntax case 1: no arguments
00959 // No docstring here because of expr_seq
00960 value_definition: '(' tk_DEFINE '(' defident ')' expr_seq ')'  {
00961   SHOWPARSE("value_definition -> ( DEFINE  ( defident ) [docstring] expr_seq )");
00962   $6 = stripDocString($6);
00963   shared_ptr<AST> iRetBlock = 
00964     AST::make(at_block, $2.loc, AST::make(at_ident, LToken("__return")), $6);
00965   shared_ptr<AST> iLambda =
00966     AST::make(at_lambda, $2.loc, AST::make(at_argVec, $5.loc), iRetBlock);
00967   iLambda->printVariant = pf_IMPLIED;
00968   shared_ptr<AST> iP = AST::make(at_identPattern, $4->loc, $4);
00969   $$ = AST::make(at_recdef, $2.loc, iP, iLambda);
00970   $$->addChild(AST::make(at_constraints));
00971 };
00972 
00973 // Define convenience syntax case 3: one or more arguments
00974 // No docstring here because of expr_seq
00975 value_definition: '(' tk_DEFINE '(' defident lambdapatterns ')' 
00976                   expr_seq ')'  {
00977   SHOWPARSE("value_definition -> ( DEFINE  ( defident lambdapatterns ) "
00978             "[docstring] expr_seq )");
00979   $7 = stripDocString($7);
00980   shared_ptr<AST> iRetBlock = 
00981     AST::make(at_block, $2.loc, AST::make(at_ident, LToken("__return")), $7);
00982   shared_ptr<AST> iLambda = AST::make(at_lambda, $2.loc, $5, iRetBlock);
00983   iLambda->printVariant = pf_IMPLIED;
00984   shared_ptr<AST> iP = AST::make(at_identPattern, $4->loc, $4);
00985   $$ = AST::make(at_recdef, $2.loc, iP, iLambda);
00986   $$->addChild(AST::make(at_constraints));
00987 };
00988 
00989 // PROCLAIM DEFINITION -- VALUES [6.2]
00990 value_declaration: '(' tk_PROCLAIM defident ':' qual_type optdocstring externals ')' {
00991   SHOWPARSE("if_definition -> ( PROCLAIM ident : qual_type optdocstring externals )");
00992   $$ = AST::make(at_proclaim, $2.loc, $3, $5);
00993   $$->flags |= $7->flags;
00994   $$->getID()->flags |= $7->flags;
00995   $$->getID()->externalName = $7->externalName;
00996   $$->addChild(AST::make(at_constraints));
00997 };
00998 
00999 // TODO: The second ident in import rule, and the ident in the provide rule 
01000 //  should be restricted to 
01001 // ({ALPHA} | [_\-]) (({ALPHA} | {DECDIGIT} | [_\-])*
01002 // IMPORT DEFINITIONS [8.2]
01003 
01004 //import_definition: '(' tk_IMPORT ident ifident ')' {
01005 //  SHOWPARSE("import_definition -> ( IMPORT ident ifident )");
01006 //  shared_ptr<AST> ifIdent = AST::make(at_ifident, $4);
01007 //  ifIdent->uoc = UocInfo::importInterface(lexer->errStream, $4.loc, $4.str);
01008 //  $$ = AST::make(at_import, $2.loc, $3, ifIdent); 
01009 //};
01010 
01011 import_definition: '(' tk_IMPORT ifident tk_AS ident ')' {
01012   SHOWPARSE("import_definition -> ( IMPORT ident ifident )");
01013   shared_ptr<AST> ifIdent = AST::make(at_ifident, $3);
01014   UocInfo::importInterface(lexer->errStream, $3.loc, $3.str);
01015   $$ = AST::make(at_importAs, $2.loc, ifIdent, $5); 
01016 };
01017 
01018 import_definition: '(' tk_IMPORT ifident ')' {
01019   SHOWPARSE("import_definition -> (IMPORT ifident)");
01020   shared_ptr<AST> ifIdent = AST::make(at_ifident, $3);
01021   UocInfo::importInterface(lexer->errStream, $3.loc, $3.str);
01022   $$ = AST::make(at_import, $2.loc, ifIdent);
01023 };
01024 
01025 import_definition: '(' tk_IMPORT ifident importList ')' {
01026   SHOWPARSE("import_definition -> (IMPORT ifident importList)");
01027   shared_ptr<AST> ifIdent = AST::make(at_ifident, $3);
01028   UocInfo::importInterface(lexer->errStream, $3.loc, $3.str);
01029   $$ = AST::make(at_import, $2.loc, ifIdent);
01030   $$->addChildrenFrom($4);
01031 };
01032 
01033 importList: alias {
01034   SHOWPARSE("importList -> alias");
01035   $$ = AST::make(at_Null, $1->loc, $1);
01036 };
01037 importList: importList alias {
01038   SHOWPARSE("importList -> importList alias");
01039   $$ = $1;
01040   $$->addChild($2);
01041 };
01042 
01043 alias: ident {
01044   SHOWPARSE("alias -> ident");
01045   // The two identifiers in this case are textually the same, but the
01046   // need to end up with distinct AST nodes, thus getDCopy().
01047   $$ = AST::make(at_ifsel, $1->loc, $1, $1->getDeepCopy());
01048 };
01049 alias: '(' ident tk_AS ident ')' {
01050   SHOWPARSE("alias -> ( ident AS ident )");
01051   
01052   $$ = AST::make(at_ifsel, $2->loc, $4, $2);
01053 };
01054 
01055 
01056 // PROVIDE DEFINITION [8.3]
01057 provide_definition: '(' tk_PROVIDE ifident provideList ')' {
01058   SHOWPARSE("provide_definition -> (PROVIDE ifident provideList)");
01059   shared_ptr<AST> ifIdent = AST::make(at_ifident, $3);
01060   UocInfo::importInterface(lexer->errStream, $3.loc, $3.str);
01061   $$ = AST::make(at_provide, $2.loc, ifIdent); 
01062   $$->addChildrenFrom($4);
01063 };
01064 
01065 provideList: ident {
01066   SHOWPARSE("provideList -> ident");
01067   $$ = AST::make(at_Null, $1->loc, $1);
01068 };
01069 
01070 provideList: provideList ident {
01071   SHOWPARSE("provideList -> provideList ident");
01072   $$ = $1;
01073   $$->addChild($2);
01074 };
01075 
01076 // definition: '(' tk_DEFTHM ident expr ')'  {
01077 //    SHOWPARSE("definition -> ( DEFTHM ident expr )");
01078 //    $$ = AST::make(at_defthm, $2.loc, $3, $4);
01079 // };
01080 
01081 declares: {
01082   SHOWPARSE("declares -> <empty>");
01083   $$ = AST::make(at_declares);
01084 };
01085 declares: declares declare {
01086   SHOWPARSE("declares -> declares declare");
01087   $$ = $1;
01088   $$->addChildrenFrom($2);
01089 };
01090 
01091 declare: '(' tk_DECLARE decls ')' {
01092   SHOWPARSE("declare -> ( DECLARE decls )");
01093   $$ = $3;
01094 };
01095 
01096 decls: decl {
01097   SHOWPARSE("decls -> decl");
01098   $$ = AST::make(at_declares, $1->loc, $1);
01099 };
01100 
01101 decls: decls decl {
01102   SHOWPARSE("decls -> decls decl");
01103   $$ = $1;
01104   $$->addChild($2);
01105 };
01106 
01107 decl: '(' ident field_type ')' {
01108   SHOWPARSE("decl -> ( ident field_type )");
01109   $$ = AST::make(at_declare, $2->loc, $2, $3);
01110 };
01111 //decl: '(' ident ')' {
01112 //  SHOWPARSE("decl -> ( ident )");
01113 //  $$ = AST::make(at_declare, $2->loc, $2);
01114 //};
01115 decl: ident {
01116   SHOWPARSE("decl -> ident");
01117   $$ = AST::make(at_declare, $1->loc, $1);
01118 };
01119 
01120 
01121 /* defunion Constructors */
01122 constructors: constructor {
01123   SHOWPARSE("constructors -> constructor");
01124   $$ = AST::make(at_constructors, $1->loc, $1);
01125 };
01126 constructors: constructors constructor {
01127   SHOWPARSE("constructors -> constructors constructor");
01128   $$ = $1;
01129   $$->addChild($2);
01130 };
01131 constructor: ident {                          /* simple constructor */ 
01132   SHOWPARSE("constructor -> defident");
01133   $1->flags |= (ID_IS_GLOBAL);
01134   $$ = AST::make(at_constructor, $1->loc, $1);
01135 };
01136 constructor: '(' ident fields ')' {  /* compound constructor */ 
01137   SHOWPARSE("constructor ->  ( ident fields )");
01138   $2->flags |= (ID_IS_GLOBAL);
01139   $$ = AST::make(at_constructor, $2->loc, $2);
01140   $$->addChildrenFrom($3);
01141 };
01142 
01143 /* defrepr Constructors */
01144 repr_constructors: repr_constructor {
01145   SHOWPARSE("repr_constructors -> repr_constructor");
01146   $$ = AST::make(at_reprctrs, $1->loc, $1);
01147 };
01148 repr_constructors: repr_constructors repr_constructor {
01149   SHOWPARSE("repr_constructors -> repr_constructors repr_constructor");
01150   $$ = $1;
01151   $$->addChild($2);
01152 };
01153 /* repr_constructor: ident repr_reprs {                          /\* simple constructor *\/  */
01154 /*   SHOWPARSE("repr_constructor -> defident"); */
01155 /*   $1->flags |= (ID_IS_GLOBAL); */
01156 /*   $$ = AST::make(at_reprctr, $1->loc, $1); */
01157 /* }; */
01158 repr_constructor: '(' ident fields '(' tk_WHERE repr_reprs ')' ')' {  /* compound constructor */ 
01159   SHOWPARSE("repr_constructor ->  ( ident fields ( WHERE repr_reprs ) )");
01160   $2->flags |= (ID_IS_GLOBAL);
01161   shared_ptr<AST> ctr = AST::make(at_constructor, $2->loc, $2);
01162   ctr->addChildrenFrom($3);
01163   $$ = AST::make(at_reprctr, $2->loc, ctr);
01164   $$->addChildrenFrom($6);
01165 };
01166 
01167 repr_reprs: repr_repr {
01168   SHOWPARSE("repr_reprs -> repr_repr");
01169   $$ = AST::make(at_Null, $1->loc, $1);
01170 };
01171 repr_reprs: repr_reprs repr_repr {
01172   SHOWPARSE("repr_reprs -> repr_reprs repr_repr");
01173   $$ = $1;
01174   $$->addChild($2);
01175 };
01176 repr_repr: '(' ident ident intLit')' {
01177   SHOWPARSE("repr_repr ->  ( = ident intLit )");
01178 
01179   if ($2->s != "==") {
01180     cerr << $2->loc << ": Syntax error, expecting `=='.\n";
01181     lexer->num_errors++;
01182   }
01183   
01184   $$ = AST::make(at_reprrepr, $2->loc, $3, $4);
01185 };
01186 
01187 
01188 /* defstruct / constructor / exception fields */
01189 fields: field  {
01190   SHOWPARSE("fields -> field");
01191   $$ = AST::make(at_fields, $1->loc, $1);
01192 };
01193 
01194 fields: fields field {
01195   SHOWPARSE("fields -> fields field ");
01196   $$ = $1;
01197   $$->addChild($2);
01198 };
01199 
01200 field: ident ':' field_type  {
01201   SHOWPARSE("field -> ident : field_type");
01202   $$ = AST::make(at_field, $1->loc, $1, $3);
01203 };
01204 
01205 field: '(' tk_THE field_type ident ')'  {
01206   SHOWPARSE("field -> '(' THE field_type ident ')'");
01207   $$ = AST::make(at_field, $1.loc, $4, $3);
01208 };
01209 
01210 field: '(' tk_FILL bitfieldtype ')'  {
01211   SHOWPARSE("field -> '(' FILL bitfieldtype ')'");
01212   $$ = AST::make(at_fill, $1.loc, $3);
01213 };
01214 
01215 // Some low level data structures have reserved bit positions that are
01216 // required to hold designated values.
01217 field: '(' tk_RESERVED bitfieldtype intLit ')'  {
01218   SHOWPARSE("field -> '(' RESERVED bitfieldtype intLit ')'");
01219   $$ = AST::make(at_fill, $1.loc, $3, $4);
01220 };
01221 
01222 methdecl: ident ':' method_type  {
01223   SHOWPARSE("methdecl -> ident : method_type");
01224   $$ = AST::make(at_methdecl, $1->loc, $1, $3);
01225 };
01226 
01227 methods_only: methdecl  {
01228   SHOWPARSE("methods_only -> methdecl");
01229   $$ = AST::make(at_fields, $1->loc, $1);
01230 };
01231 
01232 methods_only: methods_only methdecl  {
01233   SHOWPARSE("methods_only -> methods_only methdecl");
01234   $$ = $1;
01235   $$->addChild($2);
01236 };
01237 
01238 fields_and_methods: methdecl  {
01239   SHOWPARSE("fields_and_methods -> methdecl");
01240   $$ = AST::make(at_fields, $1->loc, $1);
01241 };
01242 
01243 fields_and_methods: field  {
01244   SHOWPARSE("fields_and_methods -> field");
01245   $$ = AST::make(at_fields, $1->loc, $1);
01246 };
01247 
01248 fields_and_methods: fields_and_methods methdecl {
01249   SHOWPARSE("fields_and_methods -> fields_and_methods methdecl ");
01250   $$ = $1;
01251   $$->addChild($2);
01252 };
01253 
01254 fields_and_methods: fields_and_methods field {
01255   SHOWPARSE("fields_and_methods -> fields_and_methods field ");
01256   $$ = $1;
01257   $$->addChild($2);
01258 };
01259 
01260 tvlist: typevar  {
01261   SHOWPARSE("tvlist -> typevar");
01262   $$ = AST::make(at_tvlist, $1->loc, $1);
01263 };
01264 tvlist: tvlist typevar {
01265   SHOWPARSE("tvlist -> tvlist typevar");
01266   $$ = $1;
01267   $1->addChild($2);
01268 };
01269 
01270 // TYPES [3]
01271 types: type  {
01272   SHOWPARSE("types -> type");
01273   $$ = AST::make(at_Null);
01274   $$->addChild($1);
01275 }; 
01276 types: types type {
01277   SHOWPARSE("types -> types type");
01278   $$ = $1;
01279   $1->addChild($2);
01280 };
01281 
01282 type: useident  {                         /* previously defined type */ 
01283   SHOWPARSE("type -> useident");
01284   $$ = $1;
01285 };
01286 
01287 // PRIMARY TYPES [3.2]             
01288 type: '(' ')' {
01289   SHOWPARSE("type -> ( )");
01290   $$ = AST::make(at_primaryType, $1.loc);
01291   $$->s = "unit";                /* for lookup! */
01292 };
01293 
01294 bool_type: tk_BOOL {
01295   SHOWPARSE("bool_type -> BOOL");
01296   $$ = AST::make(at_primaryType, $1);
01297 };
01298 
01299 type: bool_type {
01300   SHOWPARSE("type -> bool_type");
01301   $$ = $1;
01302 };
01303 
01304 type: tk_CHAR {
01305   SHOWPARSE("type -> CHAR");
01306   $$ = AST::make(at_primaryType, $1);
01307 };
01308 type: tk_STRING {
01309   SHOWPARSE("type -> STRING");
01310   $$ = AST::make(at_primaryType, $1);
01311 };
01312 
01313 int_type: tk_INT8 {
01314   SHOWPARSE("int_type -> INT8");
01315   $$ = AST::make(at_primaryType, $1);
01316 };
01317 int_type: tk_INT16 {
01318   SHOWPARSE("int_type -> INT16");
01319   $$ = AST::make(at_primaryType, $1);
01320 };
01321 int_type: tk_INT32 {
01322   SHOWPARSE("int_type -> INT32");
01323   $$ = AST::make(at_primaryType, $1);
01324 };
01325 int_type: tk_INT64 {
01326   SHOWPARSE("int_type -> INT64");
01327   $$ = AST::make(at_primaryType, $1);
01328 };
01329 uint_type: tk_UINT8 {
01330   SHOWPARSE("uint_type -> UINT8");
01331   $$ = AST::make(at_primaryType, $1);
01332 };
01333 uint_type: tk_UINT16 {
01334   SHOWPARSE("uint_type -> UINT16");
01335   $$ = AST::make(at_primaryType, $1);
01336 };
01337 uint_type: tk_UINT32 {
01338   SHOWPARSE("uint_type -> UINT32");
01339   $$ = AST::make(at_primaryType, $1);
01340 };
01341 uint_type: tk_UINT64 {
01342   SHOWPARSE("type -> UINT64");
01343   $$ = AST::make(at_primaryType, $1);
01344 };
01345 
01346 any_int_type: int_type {
01347   SHOWPARSE("any_int_type -> int_type");
01348   $$ = $1;
01349 };
01350 any_int_type: uint_type {
01351   SHOWPARSE("any_int_type -> uint_type");
01352   $$ = $1;
01353 };
01354 any_int_type: tk_WORD {
01355   SHOWPARSE("any_int_type -> WORD");
01356   $$ = AST::make(at_primaryType, $1);
01357 };
01358 
01359 float_type: tk_FLOAT {
01360   SHOWPARSE("float_type -> FLOAT");
01361   $$ = AST::make(at_primaryType, $1);
01362 };
01363 float_type: tk_DOUBLE {
01364   SHOWPARSE("float_type -> DOUBLE");
01365   $$ = AST::make(at_primaryType, $1);
01366 };
01367 float_type: tk_QUAD {
01368   SHOWPARSE("float_type -> QUAD");
01369   $$ = AST::make(at_primaryType, $1);
01370 };
01371 
01372 type: any_int_type {
01373   SHOWPARSE("type -> any_int_type");
01374   $$ = $1;
01375 };
01376 type: float_type {
01377   SHOWPARSE("type -> float_type");
01378   $$ = $1;
01379 };
01380 
01381 // EXCEPTION type
01382 type: tk_EXCEPTION {
01383   SHOWPARSE("type -> EXCEPTION");
01384   $$ = AST::make(at_exceptionType, $1.loc);
01385 };
01386 
01387 // TYPE VARIABLES [3.3]            
01388 type: typevar  {                 
01389   SHOWPARSE("type -> typevar");
01390   $$ = $1;
01391 };
01392 
01393 // REF TYPES [3.4.1]               
01394 type: '(' tk_REF type ')' {
01395   SHOWPARSE("type -> ( REF type )");
01396   $$ = AST::make(at_refType, $2.loc, $3);
01397 };
01398 
01399 // VAL TYPES [3.4.2]
01400 type: '(' tk_VAL type ')' {
01401   SHOWPARSE("type -> ( VAL type )");
01402   $$ = AST::make(at_valType, $2.loc, $3);
01403 };
01404 
01405 // FUNCTION TYPES [3.4.3]
01406 type: fntype {
01407   SHOWPARSE("type -> fntype");
01408   $$ = $1;
01409 }
01410 
01411 fneffect: {
01412   SHOWPARSE("fneffect -> <empty>");
01413   $$ = AST::make(at_ident, LToken("impure"));
01414 };
01415 
01416 fneffect: tk_PURE {
01417   SHOWPARSE("fneffect -> PURE");
01418   $$ = AST::make(at_ident, $1);
01419 };
01420 
01421 fneffect: tk_IMPURE {
01422   SHOWPARSE("fneffect -> IMPURE");
01423   $$ = AST::make(at_ident, $1);
01424 };
01425 
01426 fneffect: tk_EffectVar {
01427   SHOWPARSE("fneffect -> <EffectVar=" + $1.str + ">");
01428   $$ = AST::make(at_ident, $1);
01429 };
01430 
01431 // Reworked by shap on 10/9/2008 to use arrow syntax
01432 fntype: '(' fneffect tk_FN tk_FNARROW type ')' {
01433   SHOWPARSE("fntype -> ( fneffect FN -> type )");
01434   shared_ptr<AST> fnargVec = AST::make(at_fnargVec, $4.loc);
01435   $$ = AST::make(at_fn, $1.loc, fnargVec, $5);
01436 };
01437 //fntype: '(' fneffect tk_FN '(' ')' type ')' {
01438 //  SHOWPARSE("fntype -> ( fneffect FN () type )");
01439 //  shared_ptr<AST> fnargVec = AST::make(at_fnargVec, $4.loc);
01440 //  $$ = AST::make(at_fn, $1.loc, fnargVec, $6);
01441 //};
01442 
01443 // Reworked by shap on 10/9/2008 to use arrow syntax
01444 fntype: '(' fneffect tk_FN types_pl_byref tk_FNARROW type ')'  {
01445   SHOWPARSE("fntype -> ( fneffect FN types_pl_byref -> type )");
01446   $$ = AST::make(at_fn, $1.loc, $4, $6);
01447 };
01448 //fntype: '(' fneffect tk_FN '(' types_pl_byref ')' type ')'  {
01449 //  SHOWPARSE("fntype -> ( fneffect FN ( types_pl_byref ) type )");
01450 //  $$ = AST::make(at_fn, $1.loc, $5, $7);
01451 //};
01452 
01453 // METHOD TYPES [3.9]
01454 // Note: not complete; need methods taking no arguments.
01455 method_type: '(' fneffect tk_METHOD tk_FNARROW type ')' {
01456   SHOWPARSE("methodtype -> ( fneffect METHOD -> type )");
01457   shared_ptr<AST> fnargVec = AST::make(at_fnargVec, $4.loc);
01458   $$ = AST::make(at_methType, $1.loc, fnargVec, $5);
01459 };
01460 
01461 method_type: '(' fneffect tk_METHOD types_pl_byref tk_FNARROW type ')' {
01462   SHOWPARSE("methodtype -> ( fneffect METHOD types_pl_byref -> type )");
01463   $$ = AST::make(at_methType, $1.loc, $4, $6);
01464 };
01465 
01466 /* type: '(' tk_METHOD tvapp fntype')' { */
01467 /*   SHOWPARSE("METHOD tcapp fntype )"); */
01468 /*   shared_ptr<AST> tcreqs = AST::make(at_tcreqs, $3->loc, $3); */
01469 /*   $$ = AST::make(at_methodType, $2.loc, tcreqs, $4); */
01470 /* }; */
01471 
01472 /* type: '(' tk_METHOD '(' tk_AND tcreqs ')' fntype')' { */
01473 /*   SHOWPARSE("tcreq -> ( var tvlist )"); */
01474 /*   $$ = AST::make(at_methodType, $2.loc, $5, $7); */
01475 /* }; */
01476 
01477 type_cpair: type ',' type {
01478   SHOWPARSE("type_cpair -> type ',' type");
01479   $$ = AST::make(at_typeapp, $2.loc,
01480                AST::make(at_ident, LToken($2.loc, "pair")),
01481                $1, $3);
01482   $$->printVariant = pf_IMPLIED;
01483 };
01484 type_cpair: type ',' type_cpair {
01485   SHOWPARSE("type_cpair -> type ',' type_cpair");
01486   $$ = AST::make(at_typeapp, $2.loc,
01487                AST::make(at_ident, LToken($2.loc, "pair")),
01488                $1, $3);
01489   $$->printVariant = pf_IMPLIED;
01490 };
01491 
01492 type: '(' type_cpair ')' {
01493   SHOWPARSE("type -> type_cpair");
01494   $$ = $2;
01495 };
01496 
01497 // ARRAY TYPE [3.5.1]                 
01498 type: '(' tk_ARRAY type intLit ')'  {
01499   SHOWPARSE("type -> ( ARRAY type intLit )");
01500   $$ = AST::make(at_arrayType, $2.loc, $3, $4);
01501 };
01502 // VECTOR TYPE [3.5.2]               
01503 type: '(' tk_VECTOR type ')' {
01504   SHOWPARSE("type -> (VECTOR type )");
01505   $$ = AST::make(at_vectorType, $2.loc, $3);
01506 };
01507 
01508 // TYPE CONSTRUCTORS (typeapp)
01509 type: typeapp {
01510   SHOWPARSE("type -> typeapp");
01511   $$ = $1;
01512 };
01513 
01514 typeapp: '(' useident types ')' {
01515   SHOWPARSE("typeapp -> ( useident types )");
01516   $$ = AST::make(at_typeapp, $2->loc, $2);
01517   $$->addChildrenFrom($3);
01518 };
01519 
01520 // MUTABLE TYPE [3.7]              
01521 type: '(' tk_MUTABLE type ')' {
01522   SHOWPARSE("type -> ( MUTABLE type )");
01523   $$ = AST::make(at_mutableType, $2.loc, $3);
01524 };
01525 
01526 type: '(' tk_CONST type ')' {
01527   SHOWPARSE("type -> ( CONST type )");
01528   $$ = AST::make(at_constType, $2.loc, $3);
01529   };
01530 
01531 // BITFIELD TYPE
01532 bitfieldtype: '(' tk_BITFIELD any_int_type intLit ')' {
01533   SHOWPARSE("bitfieldtype -> ( BITFIELD any_int_type intLit )");
01534   $$ = AST::make(at_bitfield, $2.loc, $3, $4);
01535 };
01536 bitfieldtype: '(' tk_BITFIELD bool_type intLit ')' {
01537   SHOWPARSE("bitfieldtype -> ( BITFIELD bool_type intLit )");
01538   $$ = AST::make(at_bitfield, $2.loc, $3, $4);
01539 };
01540 
01541 // Any-type, including bitfield type
01542 field_type: bitfieldtype {
01543   SHOWPARSE("field_type -> bitfieldtype");
01544   $$ = $1;
01545 };
01546 
01547 field_type: type {
01548   SHOWPARSE("field_type -> type");
01549   $$ = $1;
01550 };
01551 
01552 // by-ref types are not a part of general `type' rule. 
01553 // They are gramatiocally restricted to apprae only on 
01554 // formal function arguments and function types. 
01555 type_pl_byref: type {
01556   SHOWPARSE("type_pl_byref -> type");
01557   $$ = $1;
01558 };
01559 
01560 type_pl_byref: '(' tk_BY_REF type ')' {
01561   SHOWPARSE("type_pl_byref -> ( BY-REF type )");
01562   $$ = AST::make(at_byRefType, $2.loc, $3);
01563 };
01564 
01565 type_pl_byref: '(' tk_ARRAY_REF type ')' {
01566   SHOWPARSE("type_pl_byref -> ( ARRAY-BY-REF type )");
01567   $$ = AST::make(at_arrayRefType, $2.loc, $3);
01568 };
01569 
01570 types_pl_byref: type_pl_byref {
01571   SHOWPARSE("types_pl_byref -> type_pl_byref");
01572   $$ = AST::make(at_fnargVec);
01573   $$->addChild($1);
01574 }; 
01575 types_pl_byref: types_pl_byref type_pl_byref {
01576   SHOWPARSE("types_pl_byref -> types_pl_byref type_pl_byref");
01577   $$ = $1;
01578   $1->addChild($2);
01579 };
01580 
01581 
01582 // Qualified types:
01583 
01584 qual_type: type {
01585   SHOWPARSE("qual_type -> type");
01586   $$ = $1;  
01587 };
01588 
01589 qual_type: '(' tk_FORALL constraints type ')' {
01590  SHOWPARSE("qual_type -> ( FORALL constraints type )");
01591  $$ = AST::make(at_qualType, $2.loc, $3, $4);
01592 };
01593 
01594 // BINDING PATTERNS [5.1]
01595 bindingpattern: ident {
01596   SHOWPARSE("bindingpattern -> ident");
01597   $$ = AST::make(at_identPattern, $1->loc, $1);
01598 };
01599 bindingpattern: ident ':' type {
01600   SHOWPARSE("bindingpattern -> ident : type");
01601   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01602 };
01603 bindingpattern: '(' tk_THE type ident ')' {
01604   SHOWPARSE("bindingpattern -> ident : type");
01605   $$ = AST::make(at_identPattern, $1.loc, $4, $3);
01606 };
01607 
01608 // There are no defpattern sequences, because there is no top-level
01609 // pattern application 
01610 // DEFPATTERN
01611 defpattern: defident {
01612   SHOWPARSE("defpattern -> defident");
01613   $$ = AST::make(at_identPattern, $1->loc, $1);
01614 };
01615 defpattern: defident ':' qual_type {
01616   SHOWPARSE("defpattern -> defident : qual_type");
01617   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01618 };
01619 defpattern: '(' tk_THE qual_type defident ')' {
01620   SHOWPARSE("defpattern -> (THE qual_type defident)");
01621   $$ = AST::make(at_identPattern, $1.loc, $4, $3);
01622 };
01623 
01624 
01625 /* Lambda Patterns -- with an additional by-ref annotation */
01626 lambdapatterns: lambdapattern {
01627   SHOWPARSE("lambdapatterns -> lambdapattern");
01628   $$ = AST::make(at_argVec, $1->loc);
01629   $$->addChild($1);
01630 };
01631 lambdapatterns: lambdapatterns lambdapattern {
01632   SHOWPARSE("lambdapatterns -> lambdapatterns lambdapattern");
01633   $$ = $1;
01634   $$->addChild($2);
01635 };
01636 
01637 lambdapattern: ident {
01638   SHOWPARSE("lambdapattern -> ident");
01639   $$ = AST::make(at_identPattern, $1->loc, $1);
01640 };
01641 
01642 lambdapattern: ident ':' type_pl_byref {
01643   SHOWPARSE("lambdapattern -> ident : type_pl_byref");
01644   $$ = AST::make(at_identPattern, $1->loc, $1, $3);
01645   if ($3->astType == at_byRefType)
01646     $1->flags |= ARG_BYREF;
01647 };
01648 
01649 lambdapattern: '(' tk_THE type ident ')' {
01650   SHOWPARSE("lambdapattern -> ( THE type ident ) ");
01651   $$ = AST::make(at_identPattern, $1.loc, $4, $3);  
01652 };
01653 
01654 lambdapattern: '(' tk_THE '(' tk_BY_REF type ')' ident ')' {
01655   SHOWPARSE("lambdapattern -> ( THE ( BY-REF type ) ident )");
01656   $$ = AST::make(at_identPattern, $1.loc, $7, $5);
01657   $5->flags |= ARG_BYREF;
01658 };
01659 
01660 lambdapattern: '(' tk_THE '(' tk_ARRAY_REF type ')' ident ')' {
01661   SHOWPARSE("lambdapattern -> ( THE ( ARRAY-REF type ) ident )");
01662   $$ = AST::make(at_identPattern, $1.loc, $7, $5);
01663 };
01664 
01665 // EXPRESSIONS [7]
01666 //
01667 // expr   -- an expression form with an optional type qualifier
01668 // eform  -- a naked expression form
01669 //
01670 // As a practical matter, every expression on the RHS of a production
01671 // should be an expr
01672 
01673 expr_seq: expr {
01674   SHOWPARSE("expr_seq -> expr");
01675   $$ = AST::make(at_begin, $1->loc, $1);
01676   $$->printVariant = pf_IMPLIED;
01677 };
01678 expr_seq: value_definition {
01679   SHOWPARSE("expr_seq -> value_definition");
01680   $$ = AST::make(at_begin, $1->loc, $1);
01681   $$->printVariant = pf_IMPLIED;
01682 };
01683 expr_seq: expr_seq expr {
01684   SHOWPARSE("expr_seq -> expr_seq expr");
01685   $$ = $1;
01686   $$->addChild($2);
01687 };
01688 expr_seq: expr_seq value_definition {
01689   SHOWPARSE("expr_seq -> expr_seq value_definition");
01690   $$ = $1;
01691   $$->addChild($2);
01692 };
01693 //expr_seq: value_definition expr_seq {
01694 //  // AST define = identPattern expr constraints;
01695 //  SHOWPARSE("expr_seq -> value_definition expr_seq");
01696 //  shared_ptr<AST> letBinding = AST::make(at_letbinding, $1->loc, 
01697 //                            $1->child(0), $1->child(1));
01698 //  $$ = AST::make(at_letrec, $1->loc, 
01699 //               AST::make(at_letbindings, $1->loc, letBinding),
01700 //               $2,
01701 //               $1->child(2));
01702 //};
01703 
01704 
01705 // TYPE QUALIFIED EXPRESSIONS  [7.3]
01706 expr: eform {
01707   SHOWPARSE("expr -> eform");
01708   $$ = $1;
01709 };
01710 expr: eform ':' type {
01711   SHOWPARSE("expr -> eform : type");
01712   $$ = AST::make(at_tqexpr, $1->loc, $1, $3);
01713 };
01714 expr: the_expr {
01715   SHOWPARSE("expr -> the_expr");
01716   $$ = $1;
01717 };
01718 
01719 the_expr: '(' tk_THE type eform ')' {
01720   SHOWPARSE("the_expr -> ( THE type eform )");
01721   // Note: argument order swapped for historical reasons.
01722   $$ = AST::make(at_tqexpr, $2.loc, $4, $3);
01723 };
01724 
01725 // SUSPENDED EXPRESSIONS
01726 expr: '(' tk_SUSPEND useident expr ')' {
01727   SHOWPARSE("expr -> ( SUSPEND useident expr )");
01728   $$ = AST::make(at_suspend, $2.loc, $3, $4);
01729 };
01730 
01731 // LITERALS  [7.1]
01732 eform: literal {
01733   SHOWPARSE("eform -> Literal");
01734   $$ = $1;
01735 };
01736 
01737 eform: '(' tk_SIZEOF type ')' {
01738   SHOWPARSE("eform -> (SIZEOF type)");
01739   $$ = AST::make(at_sizeof, $2.loc, $3);
01740 };
01741 
01742 eform: '(' tk_BITSIZEOF type ')' {
01743   SHOWPARSE("eform -> (BITSIZEOF type)");
01744   $$ = AST::make(at_bitsizeof, $2.loc, $3);
01745 };
01746 
01747 // UNIT EXPRESSIONS   [7.4.1]
01748 eform: '(' ')' {
01749   SHOWPARSE("eform -> ()");
01750   $$ = AST::make(at_unit, $1.loc);
01751 };
01752 
01753 // Expressions that involve locations:
01754 
01755 // IDENTIFIERS [7.2]
01756 /* This would actually have been 
01757 eform: useident {
01758   SHOWPARSE("eform -> useident");
01759   $$ = $1;
01760 };
01761 but for the ambiguity with record (field) selection. 
01762 So, the burden is now passed to further stages */
01763 
01764 eform: ident {
01765   SHOWPARSE("eform -> ident");
01766   $$ = $1;
01767 };
01768 
01769 // MEMBER [7.9]
01770 // In principle, we would like to accept expr.ident here, but that
01771 // creates a parse conflict with expr:type, because the sequence
01772 //
01773 //    expr : type . ident
01774 //
01775 // can turn into:
01776 //
01777 //    expr : Id . Id . ident
01778 //           ^^^^^^^
01779 //             type
01780 //
01781 // which creates a shift-reduce conflict. It's all fine as long as the
01782 // expr is fully bracketed, so there is no problem accepting:
01783 //
01784 //    (the type expr).ident
01785 //
01786 // We have adopted the solution of declaring that the ":" convenience
01787 // syntax cannot be used inside a member selection. This is not likely
01788 // to be burdensome. If the expr on the LHS is a locally computed
01789 // result, the type will be inferred through chaining from the
01790 // constructor expression. The only case where this is likely to be
01791 // annoying is for arguments of structure type, but we do not infer
01792 // structure types from field names in any case, so those will
01793 // probably require argument declarations in any case.
01794 eform: eform '.' ident {
01795   SHOWPARSE("eform -> eform . ident");
01796   $$ = AST::make(at_select, $1->loc, $1, $3);
01797 };
01798 
01799 eform: the_expr '.' ident {
01800   SHOWPARSE("eform -> the_expr . ident");
01801   $$ = AST::make(at_select, $1->loc, $1, $3);
01802 };
01803 
01804 eform: '(' tk_MEMBER expr ident ')' {
01805   SHOWPARSE("eform -> ( member expr ident )");
01806   $$ = AST::make(at_select, $2.loc, $3, $4);
01807 };
01808 
01809 // NTH-REF [7.11.2]          
01810 eform: expr '[' expr ']' {
01811   SHOWPARSE("eform -> expr [ expr ]");
01812   $$ = AST::make(at_nth, $1->loc, $1, $3);
01813 };
01814 
01815 eform: '(' tk_NTH expr expr ')' {
01816   SHOWPARSE("eform -> ( NTH expr expr )");
01817   $$ = AST::make(at_nth, $2.loc, $3, $4);
01818 };
01819 
01820 // DUP [7.17.1]
01821 eform: '(' tk_DUP expr ')' {
01822   SHOWPARSE("eform -> ( DUP expr )");
01823   $$ = AST::make(at_dup, $2.loc, $3);
01824 };
01825 
01826 // DEREF [7.17.2]                
01827 eform: expr '^' {
01828   SHOWPARSE("eform -> expr ^");
01829   $$ = AST::make(at_deref, $1->loc, $1); 
01830   $$->printVariant = pf_IMPLIED;
01831 };
01832 eform: '(' tk_DEREF expr ')' {
01833   SHOWPARSE("eform -> ( DEREF expr )");
01834   $$ = AST::make(at_deref, $2.loc, $3);
01835 };
01836 
01837 // INNER-REF
01838 // In the case of structures, the second "expression"
01839 // must be a label. This cannot be checked until 
01840 // type-checking phase.
01841 /* eform: '(' tk_INNER_REF expr expr ')' { */
01842 /*   SHOWPARSE("eform -> ( INNER_REF expr expr)"); */
01843 /*   $$ = AST::make(at_inner_ref, $2.loc, $3, $4); */
01844 /* }; */
01845 
01846 // End of locations
01847 
01848 // PAIR EXPRESSIONS
01849 eform_cpair: expr ',' expr {
01850   SHOWPARSE("eform_cpair -> expr ',' expr");
01851   $$ = AST::make(at_apply, $2.loc,
01852                AST::make(at_ident, LToken($2.loc, "pair")),
01853                $1, $3);
01854   $$->printVariant = pf_IMPLIED;
01855 };
01856 eform_cpair: expr ',' eform_cpair {
01857   SHOWPARSE("eform_cpair -> expr ',' eform_cpair");
01858   $$ = AST::make(at_apply, $2.loc,
01859                AST::make(at_ident, LToken($2.loc, "pair")),
01860                $1, $3);
01861   $$->printVariant = pf_IMPLIED;
01862 };
01863 eform: '(' eform_cpair ')' {
01864   SHOWPARSE("eform -> ( eform_cpair )");
01865   $$ = $2;
01866 };
01867 
01868 eform: '(' tk_MAKE_VECTORL expr expr ')' {
01869   SHOWPARSE("eform -> ( MAKE-VECTOR expr expr )");
01870   $$ = AST::make(at_makevectorL, $2.loc, $3, $4);
01871 };
01872 
01873 // VECTORS [7.4.3]
01874 eform: '(' tk_VECTOR expr_seq ')' {
01875   SHOWPARSE("eform -> (VECTOR expr_seq)");
01876   $$ = $3;
01877   $$->astType = at_vector;
01878   $$->loc = $2.loc;
01879 };
01880 
01881 // ARRAYS [7.4.3]
01882 eform: '(' tk_ARRAY expr_seq ')' {
01883   SHOWPARSE("eform -> (ARRAY expr_seq)");
01884   $$ = $3;
01885   $$->astType = at_array;
01886   $$->loc = $2.loc;
01887 };
01888 
01889 // BEGIN [7.5] 
01890 eform: '(' tk_BEGIN expr_seq ')' {
01891   SHOWPARSE("eform -> ( BEGIN expr_seq )");
01892   $$ = $3;
01893   $$->loc = $2.loc;
01894   $$->astType = at_begin;
01895 };
01896 
01897 // LABELS and LABELED EXIT [7.6]
01898 eform: '(' tk_BLOCK ident expr_seq ')' {
01899   SHOWPARSE("eform -> (BLOCK defident expr)");
01900   $$ = AST::make(at_block, $2.loc, $3, $4);
01901 }
01902 
01903 eform: '(' tk_RETURN_FROM ident expr ')' {
01904   SHOWPARSE("eform -> (RETURN-FROM ident expr)");
01905   $$ = AST::make(at_return_from, $2.loc, $3, $4);
01906 }
01907 
01908 // ARRAY-LENGTH, ARRAY-REF-LENGTH, VECTOR-LENGTH [7.11.1]
01909 /* eform: '(' tk_ARRAY_LENGTH expr ')' {
01910   SHOWPARSE("eform -> ( ARRAY-LENGTH expr )");
01911   $$ = AST::make(at_array_length, $2.loc, $3);
01912 };
01913 eform: '(' tk_ARRAY_REF_LENGTH expr ')' {
01914   SHOWPARSE("eform -> ( ARRAY-REF-LENGTH expr )");
01915   $$ = AST::make(at_array_ref_length, $2.loc, $3);
01916 };
01917 eform: '(' tk_VECTOR_LENGTH expr ')' {
01918   SHOWPARSE("eform -> ( VECTOR-LENGTH expr )");
01919   $$ = AST::make(at_vector_length, $2.loc, $3);
01920 }; */
01921 
01922 // LAMBDA [7.12]
01923 // handles unit argument
01924 //eform: '(' tk_LAMBDA lambdapattern expr_seq ')'  {
01925 //  SHOWPARSE("lambda -> ( LAMBDA lambdapattern expr_seq )");
01926 //  $4->astType = at_ibegin;
01927 //  $$ = AST::make(at_xlambda, $2.loc, $3, $4);
01928 //};
01929 // convenience syntax: multiple arguments
01930 eform: '(' tk_LAMBDA '(' ')' expr_seq ')'  {
01931   SHOWPARSE("lambda -> ( LAMBDA lambdapatterns expr_seq )");
01932   if ($5->children.size() == 1 && $5->child(0)->astType == at_begin)
01933     $5 = $5->child(0);
01934   shared_ptr<AST> argVec = AST::make(at_argVec, $3.loc);
01935   shared_ptr<AST> iRetBlock = 
01936     AST::make(at_block, $2.loc, AST::make(at_ident, LToken("__return")), $5);
01937   $$ = AST::make(at_lambda, $2.loc, argVec, iRetBlock);
01938 };
01939 
01940 eform: '(' tk_LAMBDA '(' lambdapatterns ')' expr_seq ')'  {
01941   SHOWPARSE("lambda -> ( LAMBDA lambdapatterns expr_seq )");
01942   if ($6->children.size() == 1 && $6->child(0)->astType == at_begin)
01943     $6 = $6->child(0);
01944   shared_ptr<AST> iRetBlock = 
01945     AST::make(at_block, $2.loc, AST::make(at_ident, LToken("__return")), $6);
01946   $$ = AST::make(at_lambda, $2.loc, $4, iRetBlock);
01947 };
01948 
01949 // RETURN [7.13]          
01950 eform: '(' tk_RETURN expr ')' {
01951   SHOWPARSE("eform -> (RETURN expr)");
01952   $$ = AST::make(at_return_from, $2.loc, 
01953                  AST::make(at_ident, LToken("__return")), $3);
01954 }
01955 
01956 // APPLICATION [7.14]          
01957 eform: '(' expr ')' { /* apply to zero args */ 
01958   SHOWPARSE("eform -> ( expr )");
01959   $$ = AST::make(at_apply, $2->loc, $2);
01960 };
01961 eform: '(' expr expr_seq ')' { /* apply to one or more args */ 
01962   SHOWPARSE("eform -> ( expr expr_seq )");
01963   $$ = AST::make(at_apply, $2->loc, $2);
01964   $$->addChildrenFrom($3);
01965 };
01966  
01967 // IF [7.15.1]
01968 eform: '(' tk_IF expr expr expr ')' {
01969   SHOWPARSE("eform -> (IF expr expr expr )");
01970   $$ = AST::make(at_if, $2.loc, $3, $4, $5);
01971 };
01972 
01973 // WHEN [7.15.2]
01974 eform: '(' tk_WHEN expr expr_seq ')' {
01975   SHOWPARSE("eform -> (WHEN expr_seq )");
01976   $$ = AST::make(at_when, $2.loc, $3, $4);
01977 };
01978 
01979 // NOT [7.15.3]
01980 // no longer a keyword and no longer syntactic
01981 
01982 // AND [7.15.4]                  
01983 eform: '(' tk_AND expr_seq ')'  {
01984   SHOWPARSE("eform -> ( AND expr_seq )");
01985   $$ = $3;
01986   $$->loc = $2.loc;
01987   $$->astType = at_and;
01988 };
01989 
01990 // OR [7.15.5]
01991 eform: '(' tk_OR expr_seq ')'  {
01992   SHOWPARSE("eform -> ( OR expr_seq )");
01993   $$ = $3;
01994   $$->loc = $2.loc;
01995   $$->astType = at_or;
01996 };
01997 
01998 // COND [7.15.6]           
01999 eform: '(' tk_COND condcases otherwise ')'  {
02000   SHOWPARSE("eform -> (COND  ( condcases otherwise ) ) ");
02001   $4->astType = at_condelse;
02002   $$ = AST::make(at_cond, $2.loc, $3, $4);
02003 };
02004 
02005 condcases: condcase {
02006   SHOWPARSE("condcases -> condcase");
02007   $$ = AST::make(at_cond_legs, $1->loc, $1);
02008 };
02009 
02010 condcases: condcases condcase {
02011   SHOWPARSE("condcases -> condcases condcase");
02012   $$ = $1;
02013   $$->addChild($2);
02014 };
02015 
02016 condcase: '(' expr expr_seq ')'  {
02017   SHOWPARSE("condcase -> ( expr expr_seq )");
02018   $$ = AST::make(at_cond_leg, $1.loc, $2, $3);
02019 };
02020 
02021 // SET! [7.16]                 
02022 eform: '(' tk_SET expr expr ')' {
02023   SHOWPARSE("eform -> ( SET! expr expr )");
02024   $$ = AST::make(at_setbang, $2.loc, $3, $4);
02025 };
02026 
02027 // SWITCH
02028 eform: '(' tk_SWITCH ident expr sw_legs ow ')' {
02029   SHOWPARSE("eform -> ( SWITCH ident expr sw_legs ow)");
02030   $$ = AST::make(at_uswitch, $2.loc, $3, $4, $5, $6);
02031   for (size_t c =0; c < $5->children.size(); c++) {
02032     shared_ptr<AST> sw_leg = $5->child(c);
02033     sw_leg->children.insert(sw_leg->children.begin(), 
02034                             $3->getDeepCopy());
02035   }
02036   if ($6->astType == at_otherwise) {
02037     shared_ptr<AST> ow = $6;
02038     ow->children.insert(ow->children.begin(), 
02039                         $3->getDeepCopy());
02040   }
02041 };
02042 
02043 sw_legs: sw_leg {
02044   SHOWPARSE("sw_legs -> sw_leg");
02045   $$ = AST::make(at_usw_legs, $1->loc, $1);
02046 };
02047 
02048 sw_legs: sw_legs sw_leg {
02049   SHOWPARSE("sw_legs -> sw_legs sw_leg");
02050   $$ = $1;
02051   $$->addChild($2);
02052 };
02053 
02054 sw_leg: '(' switch_match expr_seq ')'  {
02055   SHOWPARSE("sw_leg -> ( switch_match expr_seq )");
02056   $$ = AST::make(at_usw_leg, $1.loc, $3, $2);
02057 };
02058 
02059 sw_leg: '(' '(' switch_matches ')' expr_seq ')'  {
02060   SHOWPARSE("sw_leg -> ( ( switch_matches ) expr_seq )");
02061   $$ = AST::make(at_usw_leg, $1.loc, $5);
02062   $$->addChildrenFrom($3);
02063 };
02064 
02065 switch_matches: switch_match {
02066   SHOWPARSE("switch_matches -> switch_match");
02067   $$ = AST::make(at_Null, $1->loc, $1);
02068 };
02069 
02070 switch_matches: switch_matches switch_match {
02071   SHOWPARSE("switch_matches -> switch_matches switch_match");
02072   $$ = $1;
02073   $$->addChild($2);
02074 };
02075 
02076 /* Constructors may be expressed as:
02077    i) cons
02078    ii) list.cons
02079    iii) bitc.list.cons
02080 
02081    If we find the double-dotted version, we are sure that we have
02082    found the useident.ctr version, otherwise, this is ambiguous, and
02083    leave the burden on the resolver to find out */
02084 switch_match: ident {
02085   SHOWPARSE("switch_match -> ident");
02086   $$ = $1;
02087 };
02088 
02089 switch_match: ident '.' ident {
02090   SHOWPARSE("switch_match -> ident . ident");  
02091   $$ = AST::make(at_select, $1->loc, $1, $3);
02092 };
02093 
02094 switch_match: ident '.' ident '.' ident {
02095   SHOWPARSE("switch_match -> ident '.' ident '.' ident");
02096   shared_ptr<AST> usesel = AST::make(at_usesel, $1->loc, $1, $3);  
02097   usesel->s = $1->s + "." + $3->s;
02098   $$ = AST::make(at_select, $1->loc, usesel, $5);
02099 };
02100 
02101 ow: otherwise {
02102   SHOWPARSE("ow -> otherwise");
02103   $$ = $1;
02104 };
02105 
02106 ow: { //empty
02107   SHOWPARSE("ow -> Null");
02108   $$ = AST::make(at_Null);
02109 };
02110 
02111 otherwise: '(' tk_OTHERWISE expr_seq')' {
02112   SHOWPARSE("otherwise -> ( OTHERWISE expr_seq)");
02113   $$ = AST::make(at_otherwise, $2.loc, $3);
02114 };
02115 
02116 /* // TYPECASE  [11]            
02117 eform: '(' tk_TYPECASE '(' typecase_legs ')' ')'  {
02118   SHOWPARSE("eform -> ( typecase ( typecase_legs ) )");
02119   $$ = $4;
02120   $$->loc = $2.loc;
02121 };
02122 typecase_legs: typecase_leg {
02123   SHOWPARSE("typecase_legs -> typecase_leg");
02124   $$ = AST::make(at_typecase, $1->loc);
02125   $$->addChild($1);
02126 };
02127 typecase_legs: typecase_legs typecase_leg {
02128   SHOWPARSE("typecase_legs -> typecase_legs typecase_leg");
02129   $$ = $1;
02130   $$->addChild($2);
02131 };
02132 typecase_leg: '(' bindingpattern expr ')'  {
02133   SHOWPARSE("typecase_leg -> ( Bindingpattern expr )");
02134   $$ = AST::make(at_typecase_leg, $1.loc, $2, $3);
02135   }; */
02136 
02137 // TRY/CATCH [7.19.1]
02138 eform: '(' tk_TRY expr '(' tk_CATCH  ident sw_legs ow ')' ')'  {
02139   SHOWPARSE("eform -> ( TRY expr ( CATCH ident sw_legs ow) )");
02140   $$ = AST::make(at_try, $2.loc, $3, $6, $7, $8);
02141   for (size_t c =0; c < $7->children.size(); c++) {
02142     shared_ptr<AST> sw_leg = $7->child(c);
02143     sw_leg->children.insert(sw_leg->children.begin(), 
02144                             $6->getDeepCopy());
02145   }
02146   if ($8->astType == at_otherwise) {
02147     shared_ptr<AST> ow = $8;
02148     ow->children.insert(ow->children.begin(), 
02149                         $6->getDeepCopy());
02150   }
02151 };
02152 // shap: empty switch legs permitted, but only if otherwise clause is present.
02153 eform: '(' tk_TRY expr '(' tk_CATCH ident ow ')' ')'  {
02154   SHOWPARSE("eform -> ( TRY expr ( CATCH ident ow) )");
02155   $$ = AST::make(at_try, $2.loc, $3, $6, 
02156                  AST::make(at_usw_legs, $7->loc), $7);
02157 
02158   if ($7->astType == at_otherwise) {
02159     shared_ptr<AST> ow = $7;
02160     ow->children.insert(ow->children.begin(), 
02161                         $6->getDeepCopy());
02162   }
02163 };
02164 
02165 // THROW  [7.19.2]               
02166 eform: '(' tk_THROW expr ')' {
02167   SHOWPARSE("eform -> ( THROW expr )");
02168   $$ = AST::make(at_throw, $2.loc, $3);
02169 };
02170 
02171 // let / letrec forms
02172 
02173 eform: let_eform {
02174   SHOWPARSE("eform -> let_eform");
02175   $$ = $1;
02176 };
02177 
02178 // LET [5.3.1]                  
02179 let_eform: '(' tk_LET '(' letbindings ')' expr_seq ')' {
02180   SHOWPARSE("eform -> (LET (letbindings) expr_seq)");
02181   $6->astType = at_begin;
02182   $6->printVariant = pf_IMPLIED;
02183   $$ = AST::make(at_let, $2.loc, $4, $6);
02184   $$->addChild(AST::make(at_constraints));
02185 };
02186 letbindings: letbinding {
02187   SHOWPARSE("letbindings -> letbinding");
02188   $$ = AST::make(at_letbindings, $1->loc, $1);
02189 };
02190 letbindings: letbindings letbinding {
02191   SHOWPARSE("letbindings -> letbindings letbinding");
02192   $$ = $1;
02193   $$->addChild($2);
02194 };
02195 letbinding: '(' bindingpattern expr ')' {
02196   SHOWPARSE("letbinding -> ( bindingpattern expr )");
02197   $$ = AST::make(at_letbinding, $2->loc, $2, $3);
02198 };
02199 
02200 // LETREC [5.3.2]               
02201 let_eform: '(' tk_LETREC '(' letbindings ')' expr_seq ')' {
02202   SHOWPARSE("eform -> (LETREC (letbindings) expr_seq)");
02203   $6->astType = at_begin;
02204   $6->printVariant = pf_IMPLIED;
02205   shared_ptr<AST> lbs = $4;
02206   for (size_t c=0; c < lbs->children.size(); c++)
02207     lbs->child(c)->flags |= LB_REC_BIND;
02208   
02209   $$ = AST::make(at_letrec, $2.loc, $4, $6);
02210   $$->addChild(AST::make(at_constraints));
02211 };
02212 
02213 eform: '(' tk_DO '(' dobindings ')' dotest expr_seq ')' {
02214   SHOWPARSE("eform -> (DO (dobindings) dotest expr_seq)");
02215 
02216   // The body is executed for side effects. We need to know its result
02217   // type so that the CONTINUE block will be properly typed. Since we
02218   // are only running the body for side effects, force the result type
02219   // to be unit by appending a unit constructor at the end of the
02220   // expression sequence:
02221   $7->addChild(AST::make(at_unit, $7->loc));
02222 
02223   shared_ptr<AST> iContinueBlock = 
02224     AST::make(at_block, $2.loc, 
02225               AST::make(at_ident, LToken("__continue")), 
02226               $7);
02227   $$ = AST::make(at_do, $2.loc, $4, $6, iContinueBlock);
02228 };
02229 
02230 
02231 dobindings: {
02232   SHOWPARSE("dobindings -> <empty>");
02233   $$ = AST::make(at_dobindings);
02234 };
02235 dobindings: ne_dobindings {
02236   SHOWPARSE("dobindings -> ne_dobindings");
02237   $$ = $1;
02238 };
02239 ne_dobindings: dobinding {
02240   SHOWPARSE("ne_dobindings -> dobinding");
02241   $$ = AST::make(at_dobindings, $1->loc, $1);
02242 };
02243 ne_dobindings: ne_dobindings dobinding {
02244   SHOWPARSE("ne_dobindings -> ne_dobindings dobinding");
02245   $$ = $1;
02246   $$->addChild($2);
02247 };
02248 dobinding: '(' bindingpattern expr expr ')' {
02249   SHOWPARSE("dobinding -> ( bindingpattern expr )");
02250   $$ = AST::make(at_dobinding, $2->loc, $2, $3, $4);
02251 };
02252 dotest: '(' expr expr ')' {
02253   SHOWPARSE("dobinding -> ( expr expr )");
02254   $$ = AST::make(at_dotest, $2->loc, $2, $3);  
02255 };
02256 
02257 eform: '(' tk_CONTINUE ')' {
02258   SHOWPARSE("eform -> (CONTINUE)");
02259   $$ = AST::make(at_return_from, $2.loc, 
02260                  AST::make(at_ident, LToken("__continue")),
02261                  AST::make(at_unit, $2.loc));
02262 }
02263 
02264 /* Literals and Variables */
02265 // INTEGER LITERALS [2.4.1]
02266 literal: boolLit {
02267   SHOWPARSE("literal -> boolLit");
02268   $$ = $1;
02269 };
02270 literal: intLit {
02271   SHOWPARSE("literal -> intLit");
02272   $$ = $1;
02273 };
02274 // FLOATING POINT LITERALS [2.4.2]
02275 literal: floatLit {
02276   SHOWPARSE("literal -> floatLit");
02277   $$ = $1;
02278 };
02279 // CHARACTER LITERALS [2.4.3]
02280 literal: charlit {
02281   SHOWPARSE("literal -> Charlit");
02282   $$ = $1;
02283 };
02284 // STRING LITERALS [2.4.4]
02285 literal: strLit {
02286   SHOWPARSE("literal -> strLit");
02287   $$ = $1;
02288 };
02289 
02290 // External identifiers are not subject to reserved word restrictions...
02291 exident: tk_Ident {
02292   SHOWPARSE("exident -> <Ident " + $1.str + ">");
02293   $$ = AST::make(at_ident, $1);
02294 };
02295 
02296 exident: tk_ReservedWord {
02297   SHOWPARSE("exident -> <Reserved " + $1.str + ">");
02298   $$ = AST::make(at_ident, $1);
02299 };
02300 
02301 // IDENTIFIERS [2.2]
02302 ident: tk_Ident {
02303   SHOWPARSE("ident -> <Ident " + $1.str + ">");
02304   $$ = AST::make(at_ident, $1);
02305 };
02306 
02307 ident: tk_ReservedWord {
02308   SHOWPARSE("ident -> <RESERVED=" + $1.str + ">");
02309   cerr << $1.loc.asString() << ": The token \"" << $1.str 
02310        << "\" is reserved for future use.\n";
02311   lexer->num_errors++;
02312   $$ = AST::make(at_ident, $1);
02313 };
02314 
02315 useident: ident {
02316   SHOWPARSE("useident -> ident");
02317   $$ = $1;
02318 };
02319 
02320 useident: ident '.' ident { 
02321   SHOWPARSE("useident -> ident . ident");
02322   shared_ptr<AST> usesel = AST::make(at_usesel, $2.loc, $1, $3);  
02323   usesel->s = $1->s + "." + $3->s;
02324   $$ = usesel;
02325 };
02326 
02327 useident: ident '.' ident '.' ident { 
02328   SHOWPARSE("useident -> ident . ident . ident");
02329 
02330   shared_ptr<AST> lhs = AST::make(at_usesel, $2.loc, $1, $3);
02331   lhs->s = $1->s + "." + $3->s;
02332 
02333   shared_ptr<AST> usesel = AST::make(at_usesel, $4.loc, lhs, $5);  
02334   usesel->s = lhs->s + "." + $5->s;
02335   $$ = usesel;
02336 };
02337 
02338 //defident: ident {
02339 //  SHOWPARSE("defident -> ident");
02340 //  $1->flags |= (ID_IS_GLOBAL);
02341 //  $$ = $1;
02342 //};
02343 
02344 defident: useident {
02345   SHOWPARSE("defident -> useident");
02346   $1->flags |= (ID_IS_GLOBAL);
02347   $$ = $1;
02348 };
02349 
02350 // TYPE VARIABLES [3.3]
02351 typevar: tk_TypeVar {
02352   SHOWPARSE("typevar -> <TypeVar=" + $1.str + ">");
02353   $$ = AST::make(at_ident, $1);
02354   $$->identType = id_tvar;
02355 }; 
02356 
02357 // Literal Value Representations
02358 
02359 boolLit: tk_TRUE {
02360   SHOWPARSE("boolLit -> <Bool=" + $1.str +">");
02361   $$ = AST::makeBoolLit($1);
02362 };
02363 boolLit: tk_FALSE {
02364   SHOWPARSE("boolLit -> <Bool=" + $1.str +">");
02365   $$ = AST::makeBoolLit($1);
02366 };
02367 
02368 charlit: tk_Char {
02369   SHOWPARSE("charlit -> <Char=" + $1.str +">");
02370   $$ = AST::makeCharLit($1);
02371 };
02372 
02373 intLit: tk_Int {
02374   SHOWPARSE("intLit -> <Int=" + $1.str +">");
02375   $$ = AST::makeIntLit($1);
02376 };
02377 
02378 floatLit: tk_Float {
02379   SHOWPARSE("floatLit -> <Float=" + $1.str +">");
02380   $$ = AST::makeFloatLit($1);
02381 };
02382 
02383 strLit: tk_String {
02384   SHOWPARSE("strLit -> <String=" + $1.str +">");
02385   $$ = AST::makeStringLit($1);
02386 };
02387 
02388 %%
02389 

Generated on Fri Jul 30 07:59:15 2010 for BitC Compiler by  doxygen 1.4.7