00001 %{
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00093
00094
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
00111
00112
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
00122 %token <tok> '(' ')' ','
00123 %token <tok> '[' ']'
00124 %token <tok> '.'
00125 %token <tok> tk_AS
00126 %token <tok> tk_BOOL
00127 %token <tok> tk_TRUE
00128 %token <tok> tk_FALSE
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
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
00224
00225 %token <tok> tk_IMPORT
00226 %token <tok> tk_PROVIDE
00227
00228 %token <tok> tk_TYFN
00229
00230 %token <tok> tk_SUSPEND
00231 %type <tok> ifident
00232
00233
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
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
00273
00274 %type <ast> sw_legs sw_leg otherwise
00275
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
00285
00286
00287
00288
00289
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
00314
00315
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
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
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
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
00390
00391 UocInfo::ifList[uocName] = uoc;
00392 }
00393
00394
00395
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
00413 implicit_module: mod_definitions {
00414 SHOWPARSE("implicit_module -> mod_definitions");
00415 $$ = $1;
00416 $$->astType = at_module;
00417 $$->printVariant = pf_IMPLIED;
00418
00419
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
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
00451
00452
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
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
00488 constrained_definition: '(' tk_FORALL constraints type_val_definition ')' {
00489
00490
00491
00492
00493
00494
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
00569
00570
00571
00572
00573
00574
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
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
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
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
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
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
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
00734
00735 externals: {
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
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
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
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
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
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
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
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
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
00853
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
00864
00865
00866
00867
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
00884
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: {
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
00910
00911
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
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
00959
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
00974
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
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
01000
01001
01002
01003
01004
01005
01006
01007
01008
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
01046
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
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
01077
01078
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
01112
01113
01114
01115 decl: ident {
01116 SHOWPARSE("decl -> ident");
01117 $$ = AST::make(at_declare, $1->loc, $1);
01118 };
01119
01120
01121
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 {
01132 SHOWPARSE("constructor -> defident");
01133 $1->flags |= (ID_IS_GLOBAL);
01134 $$ = AST::make(at_constructor, $1->loc, $1);
01135 };
01136 constructor: '(' ident fields ')' {
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
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
01154
01155
01156
01157
01158 repr_constructor: '(' ident fields '(' tk_WHERE repr_reprs ')' ')' {
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
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
01216
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
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 {
01283 SHOWPARSE("type -> useident");
01284 $$ = $1;
01285 };
01286
01287
01288 type: '(' ')' {
01289 SHOWPARSE("type -> ( )");
01290 $$ = AST::make(at_primaryType, $1.loc);
01291 $$->s = "unit";
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
01382 type: tk_EXCEPTION {
01383 SHOWPARSE("type -> EXCEPTION");
01384 $$ = AST::make(at_exceptionType, $1.loc);
01385 };
01386
01387
01388 type: typevar {
01389 SHOWPARSE("type -> typevar");
01390 $$ = $1;
01391 };
01392
01393
01394 type: '(' tk_REF type ')' {
01395 SHOWPARSE("type -> ( REF type )");
01396 $$ = AST::make(at_refType, $2.loc, $3);
01397 };
01398
01399
01400 type: '(' tk_VAL type ')' {
01401 SHOWPARSE("type -> ( VAL type )");
01402 $$ = AST::make(at_valType, $2.loc, $3);
01403 };
01404
01405
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
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
01438
01439
01440
01441
01442
01443
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
01449
01450
01451
01452
01453
01454
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
01467
01468
01469
01470
01471
01472
01473
01474
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
01498 type: '(' tk_ARRAY type intLit ')' {
01499 SHOWPARSE("type -> ( ARRAY type intLit )");
01500 $$ = AST::make(at_arrayType, $2.loc, $3, $4);
01501 };
01502
01503 type: '(' tk_VECTOR type ')' {
01504 SHOWPARSE("type -> (VECTOR type )");
01505 $$ = AST::make(at_vectorType, $2.loc, $3);
01506 };
01507
01508
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
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
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
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
01553
01554
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
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
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
01609
01610
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
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
01666
01667
01668
01669
01670
01671
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
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
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
01722 $$ = AST::make(at_tqexpr, $2.loc, $4, $3);
01723 };
01724
01725
01726 expr: '(' tk_SUSPEND useident expr ')' {
01727 SHOWPARSE("expr -> ( SUSPEND useident expr )");
01728 $$ = AST::make(at_suspend, $2.loc, $3, $4);
01729 };
01730
01731
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
01748 eform: '(' ')' {
01749 SHOWPARSE("eform -> ()");
01750 $$ = AST::make(at_unit, $1.loc);
01751 };
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764 eform: ident {
01765 SHOWPARSE("eform -> ident");
01766 $$ = $1;
01767 };
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
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
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
01821 eform: '(' tk_DUP expr ')' {
01822 SHOWPARSE("eform -> ( DUP expr )");
01823 $$ = AST::make(at_dup, $2.loc, $3);
01824 };
01825
01826
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
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
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
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
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
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
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
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
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
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
01957 eform: '(' expr ')' {
01958 SHOWPARSE("eform -> ( expr )");
01959 $$ = AST::make(at_apply, $2->loc, $2);
01960 };
01961 eform: '(' expr expr_seq ')' {
01962 SHOWPARSE("eform -> ( expr expr_seq )");
01963 $$ = AST::make(at_apply, $2->loc, $2);
01964 $$->addChildrenFrom($3);
01965 };
01966
01967
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
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
01980
01981
01982
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
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
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
02022 eform: '(' tk_SET expr expr ')' {
02023 SHOWPARSE("eform -> ( SET! expr expr )");
02024 $$ = AST::make(at_setbang, $2.loc, $3, $4);
02025 };
02026
02027
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
02077
02078
02079
02080
02081
02082
02083
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: {
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
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
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
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
02166 eform: '(' tk_THROW expr ')' {
02167 SHOWPARSE("eform -> ( THROW expr )");
02168 $$ = AST::make(at_throw, $2.loc, $3);
02169 };
02170
02171
02172
02173 eform: let_eform {
02174 SHOWPARSE("eform -> let_eform");
02175 $$ = $1;
02176 };
02177
02178
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
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
02217
02218
02219
02220
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
02265
02266 literal: boolLit {
02267 SHOWPARSE("literal -> boolLit");
02268 $$ = $1;
02269 };
02270 literal: intLit {
02271 SHOWPARSE("literal -> intLit");
02272 $$ = $1;
02273 };
02274
02275 literal: floatLit {
02276 SHOWPARSE("literal -> floatLit");
02277 $$ = $1;
02278 };
02279
02280 literal: charlit {
02281 SHOWPARSE("literal -> Charlit");
02282 $$ = $1;
02283 };
02284
02285 literal: strLit {
02286 SHOWPARSE("literal -> strLit");
02287 $$ = $1;
02288 };
02289
02290
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
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
02339
02340
02341
02342
02343
02344 defident: useident {
02345 SHOWPARSE("defident -> useident");
02346 $1->flags |= (ID_IS_GLOBAL);
02347 $$ = $1;
02348 };
02349
02350
02351 typevar: tk_TypeVar {
02352 SHOWPARSE("typevar -> <TypeVar=" + $1.str + ">");
02353 $$ = AST::make(at_ident, $1);
02354 $$->identType = id_tvar;
02355 };
02356
02357
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