Removing "named let", and traces of other "let" constructs.
[shapes.git] / source / shapesparser.yy
blobed91f458729c8f9936fa8e8097c1df4535ab29bc
1 /* This file is part of Shapes.
2  *
3  * Shapes is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * any later version.
7  *
8  * Shapes is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with Shapes.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Copyright 2008 Henrik Tidefelt
17  */
19 /* File: shapesparser.y
20  * --------------
21  * Yacc input file to generate the parser for the Shapes language
22  */
26 /* Just like lex, the text within this first region delimited by %{ and %}
27  * is assumed to be C/C++ code and will be copied verbatim to the y.tab.c
28  * file ahead of the definitions of the yyparse() function. Add other header
29  * file inclusions or C++ variable declarations/prototypes that are needed
30  * by your code here.
31  */
32 #include "shapestypes.h"
33 #include "ast.h"
34 #include "astflow.h"
35 #include "astexprs.h"
36 #include "astfun.h"
37 #include "astvalues.h"
38 #include "astvar.h"
39 #include "astidentifier.h"
40 #include "astclass.h"
41 #include "shapesexceptions.h"
42 #include "consts.h"
43 #include "charptrless.h"
44 #include "autoonoff.h"
45 #include "shapescore.h"
46 #include "texlabelmanager.h"
48 using namespace Shapes;
49 #include "yyltype.h"
50 extern YYLTYPE shapeslloc;
52 #ifdef yylex
53         /* This is ugly.
54          * Warning! Warning! Warning!
55          * We'll soon use that yylex was defined as
56          *       #define yylex shapeslex
57          * in order to reset it after we're done with the inclusion.
58          */
59 #undef yylex
60 #include "globals.h"
61 #include "shapesscanner.h"
62 int shapeslex( )
64         return Ast::theShapesScanner.yylex( );
66 #define yylex shapeslex
67 #endif
69 #include "refcount.h"
71 #include <list>
72 #include <map>
73 #include <sstream>
75 using namespace std;
78 int shapeslex( );
81 void shapeserror( RefCountPtr< const char > msg )
83         throw Exceptions::ParserError( shapeslloc, msg );
86 void shapeserror( char * msg )
88         shapeserror( strrefdup( msg ) );
95  * The section before the first %% is the Definitions section of the yacc
96  * input file. Here is where you declare tokens and types, add precedence
97  * and associativity options, and so on.
98  */
101  * yylval 
102  * ------
103  * Here we define the type of the yylval global variable that is used by
104  * the scanner to store attibute information about the token just scanned
105  * and thus communicate that information to the parser. You will need to
106  * add new fields to this union as you add different attributes to your
107  * non-terminal symbols.
108  */
110 %union {
111         Ast::Expression * expr;
112         Ast::Node * node;
113         Ast::MethodIdExpr * methodId;
114         std::list< Ast::Node * > * nodeList;
115         std::list< Ast::Expression * > * exprList;
116         std::list< RefCountPtr< const char > > * strList;
117         std::map< const char *, Ast::Expression *, charPtrLess > * namedExprMap;
118         Kernel::Formals * formals;
119         std::list< Kernel::Formals * > * formalsList;
120         Ast::ArgListExprs * argList;
121         Ast::SplitDefineVariables * splitFormals;
122         int intVal;
123         double floatVal;
124         bool boolVal;
125         char * str;
126         int tokenID;
127         std::list< const Ast::CallExpr * > * callExprList;
128         std::list< Ast::ClassSection * > * classSectionList;
129         Ast::ClassSection * classSection;
130         Ast::MemberSection * memberSection;
131         Ast::MemberDeclaration * memberDeclaration;
132         Ast::StateReference * stateReference;
133         Ast::MemberMode memberMode;
134         Ast::ClassMode classMode;
135         Ast::FunctionMode functionMode;
139 /* Tokens
140  * ------
141  * Here we tell yacc about all the token types that we are using.
142  * Yacc will assign unique numbers to these and export the #define
143  * in the generated y.tab.h header file.
144  */
146 %token <tokenID> T_EOF T_minusminus T_plusplus T_ddot T_dddot T_assign T_eqeq T_eqneq T_atat T_projection T_angle T_ampersandMore
147 %token <tokenID> T_cycle T_and T_or T_xor T_not T_mapsto T_emptybrackets T_dddotbrackets T_bangbrackets T_bangdddotbrackets T_compose T_surrounding T_lesseq T_greatereq T_llthan T_ggthan T_declaretype T_bangbang
148 %token <tokenID> T_tex T_dynamic T_continuation T_continue T_esc_continuation T_esc_continue
149 %token <tokenID> T_class T_members T_prepare T_abstract T_overrides T_gr__
150 %token <tokenID> T_split T_splitLeft T_splitRight T_unionLeft T_unionRight
151  // %token <tokenID>    T_letdst T_plusassign T_minusassign T_starassign T_slashassign
153 %token <intVal> T_int
154 %token <floatVal> T_float T_length
155 %token <expr> T_speciallength
156 %token <boolVal> T_bool
157 %token <str> T_string T_identifier T_dynamic_identifier T_state_identifier T_dynamic_state_identifier T_typename
159 /* Non-terminal types
160  * ------------------
161  * In order for yacc to assign/access the correct field of $$, $1, we
162  * must to declare which field is appropriate for the non-terminal.
163  * As an example, this first type declaration establishes that the DeclList
164  * non-terminal uses the field named "declList" in the yylval union. This
165  * means that when we are setting $$ for a reduction for DeclList ore reading
166  * $n which corresponds to a DeclList nonterminal we are accessing the field
167  * of the union named "declList" which is of type List<Decl*>.
168  * pp2: You'll need to add many of these of your own.
169  */
171 %type <expr> Program Expr ExprExceptConstStrings DynamicBinding CallExpr CurryCallExpr MutateExpr Function OperatorFunction Class ConstantExceptStrings Coords PolarHandle
172 %type <expr> CodeBracket SuperCall SuperMemberReference
173 %type <exprList> InsertionSequence
174 %type <node> GroupElem
175 %type <nodeList> Group OneOrMoreGroupElems
176 %type <strList> OrderedFormals OneOrMoreOrderedFormals
177 %type <formals> Formals OneOrMoreFormalsItems
178  //                                     %type <formalsList> NamedFormalsWithOrder OneOrMoreNamedFormalsWithOrder
179 %type <argList> ArgList OneOrMoreArgListItems
180 %type <methodId> MethodIdentifier
181 %type <callExprList> ListOfParentsWithInitargs;
182 %type <classSectionList> ClassSections OneOrMoreClassSections
183 %type <classSection> ClassSection
184 %type <memberSection> MemberDeclarations OneOrMoreMemberDeclarations
185 %type <memberSection> MethodDeclarations OneOrMoreMethodDeclarations
186 %type <memberDeclaration> MemberDeclaration MethodDeclaration
187 %type <memberMode> MemberAccessList MemberAccessSpecifier
188 %type <classMode> ClassModeList ClassModeSpecifier OneOrMoreClassModeSpecifiers
189 %type <functionMode> FunctionModeList OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
190 %type <expr> Split
191 %type <stateReference> StateReference
192 %type <splitFormals> SplitFormals OneOrMoreSplitFormals
194 %nonassoc T_assign ':'
195 %left ']' T_splitRight
196 %left T_llthan
197 %nonassoc T_bangbang
198 %right '|'
199 %right T_mapsto T_emptybrackets T_bangbrackets
200 %left T_dddotbrackets T_bangdddotbrackets
201 %left T_ampersandMore
202 %left '&'
203 %nonassoc T_dynamiccolon
204 %left T_or T_xor
205 %left T_and
206 %left T_not
207 %nonassoc T_eqeq T_eqneq
208 %left T_plusplus T_minusminus
209 %left '<' '>'
210 %nonassoc T_lesseq T_greatereq
211 %left '+' '-'
212 %nonassoc T_angle
213 %left '*' '/' T_projection
214 %left '~'
215 %left T_compose
216 %left '[' '.' T_splitLeft
217 %left '#'
218 %left T_split
219 %left T_atat T_surrounding
221 %nonassoc ')'
222 %left ','
224 %start Program
226 %name-prefix="shapes"
230  * All productions and actions should be placed between the start and stop
231  * %% markers which delimit the Rules section.
232  */
234 Program
235 : Group T_EOF
237         $$ = new Ast::CodeBracket( @1, $1 );
238         Ast::theProgram = $$;
239         YYACCEPT;
241 | Group error
243         shapeserror( "Expecting end of file." );
248 Coords
249 : '(' Expr ',' Expr ')'
251         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
252         args->orderedExprs_->push_back( $2 );
253         args->orderedExprs_->push_back( $4 );
254         $$ = new Ast::CallExpr( @$,
255                                                                                                         Ast::THE_FUNCTION_coords2D,
256                                                                                                         args );
258 | '(' Expr ',' Expr '^' Expr ')'
260         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
261         args->orderedExprs_->push_back( $2 );
262         args->orderedExprs_->push_back( $4 );
263         args->orderedExprs_->push_back( $6 );
264         $$ = new Ast::CallExpr( @$,
265                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
266                                                                                                         args );
268 | '(' Expr ',' Expr '^' ')'
270         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
271         args->orderedExprs_->push_back( $2 );
272         args->orderedExprs_->push_back( $4 );
273         $$ = new Ast::CallExpr( @$,
274                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
275                                                                                                         args );
277 | '(' Expr ',' Expr ',' Expr ')'
279         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
280         args->orderedExprs_->push_back( $2 );
281         args->orderedExprs_->push_back( $4 );
282         args->orderedExprs_->push_back( $6 );
283         $$ = new Ast::CallExpr( @$,
284                                                                                                         Ast::THE_FUNCTION_coords3D,
285                                                                                                         args );
290 PolarHandle
291 : '(' Expr '^' Expr ')'
293         $$ = new Ast::PolarHandle2DExpr( @$, $2, $4 );
295 | '(' Expr '^' ')'
297         $$ = new Ast::PolarHandle2DExprFree_a( @$, $2 );
299 | '(' '^' Expr ')'
301         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
302         args->orderedExprs_->push_back( $3 );
303         $$ = new Ast::CallExpr( @$,
304                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_r,
305                                                                                                         args );
307 | '(' '^' ')'
309         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
310         $$ = new Ast::CallExpr( @$,
311                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_ra,
312                                                                                                         args );
316 StateReference
317 : T_state_identifier
319         $$ = new Ast::LexiographicState( @1, $1, new Kernel::Environment::LexicalKey * ( 0 ) );
321 | T_dynamic_state_identifier
323         $$ = new Ast::DynamicState( @1, $1 );
327 ArgList
330         $$ = new Ast::ArgListExprs( true );
332 | OneOrMoreArgListItems
335 OneOrMoreArgListItems
336 : Expr
338         $$ = new Ast::ArgListExprs( true );
339         $$->orderedExprs_->push_back( $1 );
341 | StateReference
343         $$ = new Ast::ArgListExprs( true );
344         $$->orderedStates_->push_back( $1 );
346 | T_identifier ':' Expr
348         $$ = new Ast::ArgListExprs( true );
349         (*$$->namedExprs_)[ $1 ] = $3;
351 | T_state_identifier ':' StateReference
353         $$ = new Ast::ArgListExprs( true );
354         (*$$->namedStates_)[ $1 ] = $3;
356 | OneOrMoreArgListItems Expr
358         $$ = $1;
359         if( ! $$->namedExprs_->empty( ) )
360                 {
361                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed expressions may not appear among named expressions." ) ) );
362                 }
363         $$->orderedExprs_->push_back( $2 );
365 | OneOrMoreArgListItems StateReference
367         $$ = $1;
368         if( ! $$->namedStates_->empty( ) )
369                 {
370                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed states may not appear among named states." ) ) );
371                 }
372         $$->orderedStates_->push_back( $2 );
374 | OneOrMoreArgListItems T_identifier ':' Expr
376         $$ = $1;
377         if( $$->namedExprs_->find( $2 ) != $$->namedExprs_->end( ) )
378                 {
379                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
380                 }
381         (*$$->namedExprs_)[ $2 ] = $4;
383 | OneOrMoreArgListItems T_state_identifier ':' StateReference
385         $$ = $1;
386         if( $$->namedStates_->find( $2 ) != $$->namedStates_->end( ) )
387                 {
388                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
389                 }
390         (*$$->namedStates_)[ $2 ] = $4;
395 CallExpr
396 : '[' Expr ArgList ']'
398         $$ = new Ast::CallExpr( @$, $2, $3 );
400 | Expr T_emptybrackets Expr
402         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
403         args->orderedExprs_->push_back( $3 );
404         $$ = new Ast::CallExpr( @$,
405                                                                                                         $1,
406                                                                                                         args );
408 | Expr T_emptybrackets Split
410         $$ = new Ast::CallSplitExpr( @$,
411                                                                                                                          $1,
412                                                                                                                          $3 );
414 | Expr T_dddotbrackets Expr
416         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
417         args->orderedExprs_->push_back( $3 );
418         $$ = new Ast::CallExpr( @$,
419                                                                                                         $1,
420                                                                                                         args,
421                                                                                                         true ); /* true means Curry */
423 | Expr T_dddotbrackets T_identifier ':' Expr %prec T_dynamiccolon
425         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
426         (*args->namedExprs_)[ $3 ] = $5;
427         $$ = new Ast::CallExpr( @$,
428                                                                                                         $1,
429                                                                                                         args,
430                                                                                                         true ); /* true means Curry */
432 | Expr T_dddotbrackets Split
434         $$ = new Ast::CallSplitExpr( @$,
435                                                                                                                          $1,
436                                                                                                                          $3,
437                                                                                                                          true );        /* true means Curry */
439 | '[' '!' Expr ArgList ']'
441         $$ = new Ast::CallExpr( @$, $3, $4, false, true );      /* false for no curry, true for procedural */
443 | Expr T_bangbrackets Expr
445         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
446         args->orderedExprs_->push_back( $3 );
447         $$ = new Ast::CallExpr( @$,
448                                                                                                         $1,
449                                                                                                         args,
450                                                                                                         false,  /* false means no curry */
451                                                                                                         true ); /* true means procedural */
453 | Expr T_bangbrackets Split
455         $$ = new Ast::CallSplitExpr( @$,
456                                                                                                                          $1,
457                                                                                                                          $3,
458                                                                                                                          false, /* false means no curry */
459                                                                                                                          true ); /* true means procedural */
461 | Expr T_bangdddotbrackets Expr
463         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
464         args->orderedExprs_->push_back( $3 );
465         $$ = new Ast::CallExpr( @$,
466                                                                                                         $1,
467                                                                                                         args,
468                                                                                                         true,   /* true means Curry */
469                                                                                                         true ); /* true means procedural */
471 | Expr T_bangdddotbrackets Split
473         $$ = new Ast::CallSplitExpr( @$,
474                                                                                                                          $1,
475                                                                                                                          $3,
476                                                                                                                          true, /* false means no curry */
477                                                                                                                          true ); /* true means procedural */
482 CurryCallExpr
483 : '[' Expr ArgList T_dddot ']'
485         $$ = new Ast::CallExpr( @$, $2, $3, true ); /* true means Curry */
489 MutateExpr
490 : StateReference '.' '[' T_identifier ArgList ']'
492         Ast::CallExpr * res =
493                 new Ast::CallExpr( @$,
494                                                                                          new Ast::MutatorReference( @4, $1, $4 ),
495                                                                                          $5 );
496         res->setMutatorSelf( $1 );
497         $$ = res;
501 Formals
504         $$ = new Kernel::Formals( );
505         $$->setLoc( @$ );
507 | T_split T_identifier
509         $$ = new Kernel::Formals( );
510         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
511         /* Note that we do not push a default expression (not even a null pointer) for the sink.
512          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
513          * The default value for the sink is taken care of in a non-standard way anyway.
514          */
515         $$->setLoc( @$ );
516         $$->sink_ = $2;
518 | OneOrMoreFormalsItems
520         $$ = $1;
521         $$->setLoc( @$ );
523 | OneOrMoreFormalsItems T_split T_identifier
525         $$ = $1;
526         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $3, $$->defaultExprs_.size( ) ) );
527         /* Note that we do not push a default expression (not even a null pointer) for the sink.
528          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
529          * The default value for the sink is taken care of in a non-standard way anyway.
530          */
531         $$->setLoc( @$ );
532         $$->sink_ = $3;
536 OneOrMoreFormalsItems
537 : T_identifier
539         $$ = new Kernel::Formals( );
540         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
541         $$->defaultExprs_.push_back( 0 );
543 | T_identifier ':' Expr
545         $$ = new Kernel::Formals( );
546         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
547         $$->defaultExprs_.push_back( $3 );
549 | T_state_identifier
551         $$ = new Kernel::Formals( );
552         $$->stateOrder_->insert( std::pair< const char *, size_t >( $1, $$->stateOrder_->size( ) ) );
554 | OneOrMoreFormalsItems T_identifier
556         $$ = $1;
557         if( $$->seenDefault_ )
558                 {
559                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
560                 }
561         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
562                 {
563                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
564                 }
565         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
566         $$->defaultExprs_.push_back( 0 );
568 | OneOrMoreFormalsItems T_identifier ':' Expr
570         $$ = $1;
571         $$->seenDefault_ = true;
572         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
573                 {
574                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
575                 }
576         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
577         $$->defaultExprs_.push_back( $4 );
579 | OneOrMoreFormalsItems T_state_identifier
581         $$ = $1;
582         if( $$->stateOrder_->find( $2 ) != $$->stateOrder_->end( ) )
583                 {
584                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
585                 }
586         $$->stateOrder_->insert( std::pair< const char *, size_t >( $2, $$->stateOrder_->size( ) ) );
591 SplitFormals
594         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "The list of split assignment variables must not be empty." ) ) );
595         $$ = new Ast::SplitDefineVariables( );
597 | T_split T_identifier
599         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "Just a sink in a split assignment formals list makes no sense." ) ) );
600         $$ = new Ast::SplitDefineVariables( );
602 | OneOrMoreSplitFormals
604         $$ = $1;
606 | OneOrMoreSplitFormals T_split T_identifier
608         $$ = $1;
609         Ast::StructSplitSink * expr = new Ast::StructSplitSink( );
610         size_t ** pos = new size_t * ( 0 );
611         $$->sinkDefine_ = new Ast::DefineVariable( @3, $3, expr, pos );
612         $$->sinkExpr_ = expr;
616 OneOrMoreSplitFormals
617 : T_identifier
619         $$ = new Ast::SplitDefineVariables( );
620         typedef typeof $$->exprs_ ListType;
621         size_t ** pos = new size_t * ( 0 );
622         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), 0 );
623         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
624                                                                                                                                                                                          ref ) );
626 | T_identifier ':' Expr
628         $$ = new Ast::SplitDefineVariables( );
629         typedef typeof $$->exprs_ ListType;
630         size_t ** pos = new size_t * ( 0 );
631         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), $3 );
632         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
633                                                                                                                                                                                          ref ) );
635 | T_identifier ':' '.' T_identifier
637         $$ = new Ast::SplitDefineVariables( );
638         typedef typeof $$->exprs_ ListType;
639         size_t ** pos = new size_t * ( 0 );
640         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, 0 );
641         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
642                                                                                                                                                                                          ref ) );
644 | T_identifier ':' '.' T_identifier ':' Expr
646         $$ = new Ast::SplitDefineVariables( );
647         typedef typeof $$->exprs_ ListType;
648         size_t ** pos = new size_t * ( 0 );
649         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, $6 );
650         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
651                                                                                                                                                                                          ref ) );
653 | T_identifier ':' '.' '\"'
655         $$ = new Ast::SplitDefineVariables( );
656         typedef typeof $$->exprs_ ListType;
657         size_t ** pos = new size_t * ( 0 );
658         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), 0 );
659         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
660                                                                                                                                                                                          ref ) );
662 | T_identifier ':' '.' '\"' ':' Expr
664         $$ = new Ast::SplitDefineVariables( );
665         typedef typeof $$->exprs_ ListType;
666         size_t ** pos = new size_t * ( 0 );
667         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), $6 );
668         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
669                                                                                                                                                                                          ref ) );
671 | OneOrMoreSplitFormals T_identifier
673         $$ = $1;
674         if( $$->seenNamed_ )
675                 {
676                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
677                 }
678         if( $$->seenDefault_ )
679                 {
680                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "All order-based formals without default values must be placed before those with default values." ) ) );
681                 }
682         typedef typeof $$->exprs_ ListType;
683         size_t ** pos = new size_t * ( 0 );
684         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), 0 );
685         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
686                                                                                                                                                                                          ref ) );
688 | OneOrMoreSplitFormals T_identifier ':' Expr
690         $$ = $1;
691         if( $$->seenNamed_ )
692                 {
693                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
694                 }
695         $$->seenDefault_ = true;
696         typedef typeof $$->exprs_ ListType;
697         size_t ** pos = new size_t * ( 0 );
698         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), $4 );
699         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
700                                                                                                                                                                                          ref ) );
702 | OneOrMoreSplitFormals T_identifier ':' '.' T_identifier
704         $$ = $1;
705         $$->seenNamed_ = true;
706         typedef typeof $$->exprs_ ListType;
707         size_t ** pos = new size_t * ( 0 );
708         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, 0 );
709         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
710                                                                                                                                                                                          ref ) );
712 | OneOrMoreSplitFormals T_identifier ':' '.' T_identifier ':' Expr
714         $$ = $1;
715         $$->seenNamed_ = true;
716         typedef typeof $$->exprs_ ListType;
717         size_t ** pos = new size_t * ( 0 );
718         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, $7 );
719         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
720                                                                                                                                                                                          ref ) );
722 | OneOrMoreSplitFormals T_identifier ':' '.' '\"'
724         $$ = $1;
725         $$->seenNamed_ = true;
726         typedef typeof $$->exprs_ ListType;
727         size_t ** pos = new size_t * ( 0 );
728         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), 0 );
729         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
730                                                                                                                                                                                          ref ) );
732 | OneOrMoreSplitFormals T_identifier ':' '.' '\"' ':' Expr
734         $$ = $1;
735         $$->seenNamed_ = true;
736         typedef typeof $$->exprs_ ListType;
737         size_t ** pos = new size_t * ( 0 );
738         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), $7 );
739         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
740                                                                                                                                                                                          ref ) );
745 Function
746 : '\\' Formals T_mapsto FunctionModeList Expr
748         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
749         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $2, $5, $4 );
750         res->push_exprs( args );
751         $$ = new Ast::CallExpr( @$,
752                                                                                                         RefCountPtr< const Lang::Function >( res ),
753                                                                                                         args );
755 | '(' OperatorFunction ')'
757         $$ = $2;
761 OrderedFormals
764         $$ = new list< RefCountPtr< const char > >( );
766 | OneOrMoreOrderedFormals
769 OneOrMoreOrderedFormals
770 : T_identifier
772         $$ = new list< RefCountPtr< const char > >( );
773         $$->push_back( strrefdup( $1 ) );
775 | OneOrMoreOrderedFormals T_identifier
777         $$ = $1;
778         $$->push_back( strrefdup( $2 ) );
782 OperatorFunction
783 : T_minusminus
785         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUSMINUS ) );
787 | T_plusplus
789         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUSPLUS ) );
791 | '&'
793         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND ) );
795 | '+'
797         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUS ) );
799 | '-'
801         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUS ) );
803 | '*'
805         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_STAR ) );
807 | '/'
809         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_SLASH ) );
811 | T_projection
813         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PROJECTION ) );
815 | T_angle
817         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_ANGLE ) );
819 | T_ampersandMore
821         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND_MORE ) );
823 | '~'
825         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NEG ) );
827 | T_compose
829         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_COMPOSE ) );
831 | '<'
833         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
835 | '>'
837         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
839 | T_eqeq
841         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQEQ ) );
843 | T_eqneq
845         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQNEQ ) );
847 | T_lesseq
849         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
851 | T_greatereq
853         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
855 | T_not
857         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NOT ) );
859 | T_and
861         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_AND ) );
863 | T_or
865         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_OR ) );
867 | T_xor
869         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_XOR ) );
873 Expr
874 : ExprExceptConstStrings
875 | T_string
877         $$ = new Ast::Constant( @1, new Lang::String( $1, false ) );
881 ExprExceptConstStrings
882 : ConstantExceptStrings
883 | Coords
884 | PolarHandle
885 | '(' T_tex ExprExceptConstStrings ')'
887         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
888         args->orderedExprs_->push_back( $3 );
889         $$ = new Ast::CallExpr( @$,
890                                                                                                         Ast::THE_FUNCTION_TeX,
891                                                                                                         args );
893 | '(' T_tex T_string ')'
895         Kernel::theTeXLabelManager.announce( string( $3 ), @3 );
896         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
897         args->orderedExprs_->push_back( new Ast::Constant( @3, new Lang::String( $3, false ) ) );
898         $$ = new Ast::CallExpr( @$,
899                                                                                                         Ast::THE_FUNCTION_TeX,
900                                                                                                         args );
902 | T_bangbang Expr
904         $$ = $2;
905         $$->immediate_ = true;
907 | CallExpr
908 | CurryCallExpr
909 | SuperCall
910 | SuperMemberReference
911 | T_speciallength
912 | '(' Expr ')'
914         $$ = $2;
916 | '(' '-' Expr ')'
918         $$ = new Ast::NegExpr( @$, @2, $3 );
920 | '(' '+' Expr ')'
922         $$ = new Ast::RelativeExpr( @$, @2, $3 );
924 | '(' ')'
926         $$ = new Ast::EmptyExpression( @$ );
928 | '(' Expr T_llthan InsertionSequence ')'
930         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
932         size_t ** pos = new size_t * ( 0 );
933         Ast::StateReference * dst = new Ast::LexiographicState( @2, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), new Kernel::Environment::LexicalKey * ( 0 ) );
935         bracket->push_back( new Ast::IntroduceState( @3,
936                                                                                                                                                                                          strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ),
937                                                                                                                                                                                          $2,
938                                                                                                                                                                                          pos ) );
939         for( std::list< Ast::Expression * >::const_iterator i = $4->begin( ); i != $4->end( ); ++i )
940                 {
941                         bracket->push_back( new Ast::Insertion( dst, *i ) );
942                 }
943         bracket->push_back( new Ast::Freeze( @3, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), pos ) );
944         $$ = new Ast::CodeBracket( @$, bracket );
946 | T_surrounding Expr
948         $$ = new Ast::EvalOutsideExpr( @$, $2 );
950 | CodeBracket
951 | Function
952 | Class
953 | T_identifier
955         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
956         $$ = new Ast::LexiographicVariable( @$, $1, key );
958 | T_atat Expr
960         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
961         Ast::EvalSymbolFunction * res = new Ast::EvalSymbolFunction( @$, $2 );
962         res->push_exprs( args );
963         $$ = new Ast::CallExpr( @$,
964                                                                                                         RefCountPtr< const Lang::Function >( res ),
965                                                                                                         args );
967 | T_dynamic_identifier
969         $$ = new Ast::DynamicVariable( @$, $1 );
971 | '(' StateReference ')'
973         $$ = new Ast::Peek( @$, $2 );
975 | MutateExpr
976 | Expr '.' T_identifier
978         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
979         Ast::MemberReferenceFunction * res = new Ast::MemberReferenceFunction( @$, $1, $3 );
980         res->push_exprs( args );
981         $$ = new Ast::CallExpr( @$,
982                                                                                                         RefCountPtr< const Lang::Function >( res ),
983                                                                                                         args );
985 | Expr '.' MethodIdentifier
987         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
988         Ast::PublicMethodReferenceFunction * res = new Ast::PublicMethodReferenceFunction( @$, $1, $3 );
989         res->push_exprs( args );
990         $$ = new Ast::CallExpr( @$,
991                                                                                                         RefCountPtr< const Lang::Function >( res ),
992                                                                                                         args );
994 | DynamicBinding
995 | '(' T_esc_continuation T_identifier Expr ')'
997         $$ = new Ast::LetDynamicECExpr( @$, @3, $3, $4 );
999 | '(' T_esc_continue T_identifier Expr ')'
1001         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1002         Ast::ContinueDynamicECFunction * res = new Ast::ContinueDynamicECFunction( @3, $3, $4 );
1003         res->push_exprs( args );
1004         $$ = new Ast::CallExpr( @$,
1005                                                                                                         RefCountPtr< const Lang::Function >( res ),
1006                                                                                                         args );
1007         /* This used to be immediate, but right now that seems utterly wrong!
1008          * Imagine choosing between two continuations; then both continuations would require invokation before being "passed" to the <if> function.
1009          * On the other hand, I can admit that it seems a bit uncanny to let the <if> function return the continuation invokations as thunks, not
1010          * knowing when they will be forced...  But I don't think there's a choice here anyway; this expression can't be immediate.
1011          */
1013 | Expr '|' Expr
1015         $$ = new Ast::WithDynamicExpr( @$, $1, $3 );
1017 | T_unionLeft ArgList T_unionRight
1019         $$ = new Ast::UnionExpr( @$, $2 );
1021 | Expr T_minusminus T_cycle
1023         $$ = new Ast::CycleExpr( @3, $1 );
1025 | Expr T_minusminus Expr
1027         $$ = new Ast::MinusMinusExpr( @2, $1, $3 );
1029 | Expr T_plusplus Expr
1031         $$ = new Ast::PlusPlusExpr( @2, $1, $3 );
1033 | Expr '&' Expr
1035         $$ = new Ast::AmpersandExpr( @2, $1, $3 );
1037 | Expr '+' Expr
1039         $$ = new Ast::PlusExpr( @2, $1, $3 );
1041 | Expr '-' Expr
1043         $$ = new Ast::MinusExpr( @2, $1, $3 );
1045 | Expr T_angle Expr
1047         $$ = new Ast::AngleExpr( @2, $1, $3 );
1049 | Expr T_ampersandMore Expr
1051         $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1053 | Expr '*' Expr
1055         $$ = new Ast::StarExpr( @2, $1, $3 );
1057 | Expr T_projection Expr
1059         $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1061 | Expr '/' Expr
1063         $$ = new Ast::SlashExpr( @2, $1, $3 );
1065 | '~' Expr
1067         $$ = new Ast::NegExpr( @1, $2 );
1069 | Expr T_compose Expr
1071         $$ = new Ast::ComposeExpr( @2, $1, $3 );
1073 | Expr '<' Expr
1075         $$ = new Ast::LessExpr( @2, $1, $3 );
1077 | Expr '>' Expr
1079         $$ = new Ast::GreaterExpr( @2, $1, $3 );
1081 | Expr T_eqeq Expr
1083         $$ = new Ast::EqualExpr( @2, $1, $3 );
1085 | Expr T_eqneq Expr
1087         $$ = new Ast::NotEqualExpr( @2, $1, $3 );
1089 | Expr T_lesseq Expr
1091         $$ = new Ast::LessEqualExpr( @2, $1, $3 );
1093 | Expr T_greatereq Expr
1095         $$ = new Ast::GreaterEqualExpr( @2, $1, $3 );
1097 | T_not Expr
1099         $$ = new Ast::NotExpr( @1, $2 );
1101 | Expr T_and Expr
1103         //      $$ = new Ast::AndExpr( @2, $1, $3 );
1105         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1106         args->orderedExprs_->push_back( $1 );
1107         args->orderedExprs_->push_back( $3 );
1108         $$ = new Ast::CallExpr( @$,
1109                                                                                                         Lang::THE_FUNCTION_AND,
1110                                                                                                         args );
1112 | Expr T_or Expr
1114         //      $$ = new Ast::OrExpr( @2, $1, $3 );
1116         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1117         args->orderedExprs_->push_back( $1 );
1118         args->orderedExprs_->push_back( $3 );
1119         $$ = new Ast::CallExpr( @$,
1120                                                                                                         Lang::THE_FUNCTION_OR,
1121                                                                                                         args );
1123 | Expr T_xor Expr
1125         $$ = new Ast::XorExpr( @2, $1, $3 );
1127 | T_typename
1129         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1130         $$ = new Ast::LexiographicType( @$, $1, key );
1135 DynamicBinding
1136 : T_dynamic_identifier ':' Expr %prec T_dynamiccolon
1138         $$ = new Ast::DynamicBindingExpression( @$, $1, $3, new Kernel::Environment::LexicalKey * ( 0 ) );
1140 | T_dynamic_identifier ':' T_dynamic Expr %prec T_dynamiccolon
1142         $$ = new Ast::DynamicBindingExpression( @$, $1,
1143                                                                                                                                                                         new Ast::DynamicExpression( @4, $4 ),
1144                                                                                                                                                                         new Kernel::Environment::LexicalKey * ( 0 ) );
1146 | T_dynamic_state_identifier ':' StateReference %prec T_dynamiccolon
1148         $$ = new Ast::DynamicStateBindingExpression( @$, @1, $1, $3 );
1153 ConstantExceptStrings
1154 : T_int
1156         $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1158 | T_float
1160         $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1162 | T_length
1164         $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1166 | T_bool
1168         $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1170 | '\'' T_identifier
1172         $$ = new Ast::Constant( @1, new Lang::Symbol( $2 ) );
1176 CodeBracket
1177 : '{' Group '}'
1179         $$ = new Ast::CodeBracket( @$, $2 );
1183 GroupElem
1184 : Expr
1186         $$ = $1;        // Explicit upcast avoids bison warning.
1188 | T_identifier ':' Expr
1190         size_t ** pos = new size_t * ( 0 );
1191         $$ = new Ast::DefineVariable( @1, $1, $3, pos );
1193 | T_state_identifier ':' Expr
1195         size_t ** pos = new size_t * ( 0 );
1196         $$ = new Ast::IntroduceState( @1, $1, $3, pos );
1198 | T_state_identifier ';'
1200         size_t ** pos = new size_t * ( 0 );
1201         $$ = new Ast::Freeze( @1, $1, pos );
1203 | T_identifier ':' T_state_identifier ';'
1205         size_t ** posVar = new size_t * ( 0 );
1206         size_t ** posState = new size_t * ( 0 );
1207         $$ = new Ast::DefineVariable( @1, $1, new Ast::Freeze( @3, $3, posState ), posVar );
1209 | T_dynamic T_dynamic_identifier Expr Expr
1211         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3, $4 );
1213 | T_dynamic T_dynamic_identifier Expr T_dynamic Expr
1215         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3,
1216                                                                                                                                                  new Ast::DynamicExpression( @5, $5 ) );
1218 | T_dynamic T_dynamic_state_identifier StateReference
1220         $$ = new Ast::DynamicStateDecl( @$, @2, $2, $3, new size_t * ( 0 ) );
1222 | Expr '.' T_identifier T_llthan InsertionSequence
1224         shapeserror( "MemberInsertionSequence not implemented" );
1225         //      $$ = new Ast::MemberInsertionSequence( @$, $1, $3, $5 );
1227 | '(' '#' Expr ')' '.' T_identifier T_llthan InsertionSequence
1229         shapeserror( "ProtectedMemberInsertionSequence not implemented" );
1230         //      $$ = new Ast::ProtectedMemberInsertionSequence( @$, @2, $3, $6, $8 );
1234 InsertionSequence
1235 : Expr
1237         $$ = new std::list< Ast::Expression * >( );
1238         $$->push_back( $1 );
1240 | InsertionSequence T_llthan Expr
1242         $$ = $1;
1243         $$->push_back( $3 );
1247 OneOrMoreGroupElems
1248 : GroupElem
1250         $$ = new list< Ast::Node * >( );
1251         $$->push_back( $1 );
1253 | OneOrMoreGroupElems GroupElem
1255         $$ = $1;
1256         $$->push_back( $2 );
1258 | StateReference T_llthan InsertionSequence
1260         $$ = new list< Ast::Node * >( );
1261         for( std::list< Ast::Expression * >::const_iterator i = $3->begin( ); i != $3->end( ); ++i )
1262                 {
1263                         $$->push_back( new Ast::Insertion( $1, *i ) );
1264                 }
1266 | OneOrMoreGroupElems StateReference T_llthan InsertionSequence
1268         $$ = $1;
1269         for( std::list< Ast::Expression * >::const_iterator i = $4->begin( ); i != $4->end( ); ++i )
1270                 {
1271                         $$->push_back( new Ast::Insertion( $2, *i ) );
1272                 }
1274 | T_splitLeft SplitFormals T_splitRight ':' Expr
1276         $$ = new list< Ast::Node * >( );
1277         size_t ** pos = new size_t * ( 0 );
1279         $5->immediate_ = true;
1280         $$->push_back( new Ast::DefineVariable( @5, $2->newSplitVarId( ), $5, pos ) );
1282         size_t orderedCount = 0;
1284         typedef typeof $2->exprs_ ListType;
1285         for( ListType::iterator i = $2->exprs_.begin( ); i != $2->exprs_.end( ); ++i )
1286                 {
1287                         i->second->setStruct( @5, pos );
1288                         $$->push_back( i->first );
1289                         if( i->second->isOrdered( ) )
1290                                 {
1291                                         ++orderedCount;
1292                                 }
1293                 }
1295         if( $2->sinkDefine_ != 0 )
1296                 {
1297                         $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1298                         $$->push_back( $2->sinkDefine_ );
1299                 }
1300         else
1301                 {
1302                         $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
1303                 }
1305 | T_splitLeft SplitFormals T_splitRight Expr
1307         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1308         $$ = new list< Ast::Node * >( );
1309         $$->push_back( new Ast::ErrorExpression( @$ ) );
1311 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight ':' Expr
1313         $$ = $1;
1314         size_t ** pos = new size_t * ( 0 );
1316         $6->immediate_ = true;
1317         $$->push_back( new Ast::DefineVariable( @6, $3->newSplitVarId( ), $6, pos ) );
1319         size_t orderedCount = 0;
1321         typedef typeof $3->exprs_ ListType;
1322         for( ListType::iterator i = $3->exprs_.begin( ); i != $3->exprs_.end( ); ++i )
1323                 {
1324                         i->second->setStruct( @6, pos );
1325                         $$->push_back( i->first );
1326                         if( i->second->isOrdered( ) )
1327                                 {
1328                                         ++orderedCount;
1329                                 }
1330                 }
1332         if( $3->sinkDefine_ != 0 )
1333                 {
1334                         $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1335                         $$->push_back( $3->sinkDefine_ );
1336                 }
1337         else
1338                 {
1339                         $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1340                 }
1342 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1344         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1345         $$ = $1;
1346         $$->push_back( new Ast::ErrorExpression( @$ ) );
1350 Group
1353         $$ = new list< Ast::Node * >( );
1355 | OneOrMoreGroupElems
1359 SuperMemberReference
1360 : '(' '#' Expr ')' '.' T_identifier
1362         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1363         Ast::ProtectedMemberReferenceFunction * res = new Ast::ProtectedMemberReferenceFunction( @$, @2, $3, @6, $6 );
1364         res->push_exprs( args );
1365         $$ = new Ast::CallExpr( @$,
1366                                                                                                         RefCountPtr< const Lang::Function >( res ),
1367                                                                                                         args );
1372 MethodIdentifier
1373 : T_identifier '#' T_identifier
1375         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1376         $$ = new Ast::MethodIdExpr( @$, new Ast::LexiographicVariable( @1, $1, key ), $3 );
1381 SuperCall
1382 : '[' '(' '#' Expr ')' '.' MethodIdentifier ArgList ']'
1384         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1385         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, $4, $7 );
1386         res->push_exprs( args );
1387         $$ = new Ast::CallExpr( @$,
1388                                                                                                         new Ast::CallExpr( @3,
1389                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1390                                                                                                                                                                                  args ),
1391                                                                                                         $8 );
1393 | '[' '(' '#' ')' '.' MethodIdentifier ArgList ']'
1395         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1396         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, 0, $6 );
1397         res->push_exprs( args );
1398         $$ = new Ast::CallExpr( @$,
1399                                                                                                         new Ast::CallExpr( @3,
1400                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1401                                                                                                                                                                                  args ),
1402                                                                                                         $7 );
1407 Class
1408 : '[' T_class '(' Expr Formals ')' T_identifier '(' ListOfParentsWithInitargs ')'
1409         ClassModeList
1410         ClassSections
1411         ']'
1413         DeleteOnExit< char > isaDeleter( $7 );
1414         if( strcmp( $7, "isa" ) != 0 )
1415                 {
1416                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1417                 }
1418         if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1419                 {
1420                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
1421                 }
1423         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1424         Ast::ClassFunction * res = new Ast::ClassFunction( @$, $4, $5, $9, $11, $12 );
1425         res->push_exprs( args );
1426         $$ = new Ast::CallExpr( @$,
1427                                                                                                         RefCountPtr< const Lang::Function >( res ),
1428                                                                                                         args );
1432 ListOfParentsWithInitargs
1433 : '(' Expr ArgList ')'
1435         $$ = new std::list< const Ast::CallExpr * >;
1436         $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1438 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1440         $$ = $1;
1441         $$->push_back( new Ast::CallExpr( Ast::SourceLocation( @2, @5 ), $3, $4 ) );
1445 ClassModeList
1448         $$ = 0;
1450 | OneOrMoreClassModeSpecifiers
1453 OneOrMoreClassModeSpecifiers
1454 : ClassModeSpecifier
1455 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1457         $$ = $1 | $2;
1461 ClassModeSpecifier
1462 : T_identifier
1464         DeleteOnExit< char > strDeleter( $1 );
1465         $$ = 0;
1466         if( strcmp( $1, "abstract" ) == 0 )
1467                 {
1468                         $$ = Ast::CLASS_MODE_ABSTRACT;
1469                 }
1470         else if( strcmp( $1, "final" ) == 0 )
1471                 {
1472                         $$ = Ast::CLASS_MODE_FINAL;
1473                 }
1474         else
1475                 {
1476                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1477                 }
1481 ClassSections
1484         $$ = new std::list< Ast::ClassSection * >;
1486 | OneOrMoreClassSections
1489 OneOrMoreClassSections
1490 : ClassSection
1492         $$ = new std::list< Ast::ClassSection * >;
1493         $$->push_back( $1 );
1495 | OneOrMoreClassSections ClassSection
1497         $$ = $1;
1498         $$->push_back( $2 );
1502 ClassSection
1503 : '(' T_members MemberDeclarations ')'
1505         $$ = $3;
1507 | '(' T_prepare Group ')'
1509         $$ = new Ast::PrepareSection( @$, $3 );
1511 | '(' T_identifier MethodDeclarations ')'
1513         DeleteOnExit< char > accessSpecDeleter( $2 );
1514         unsigned int accessSpec = 0;
1515         if( strcmp( $2, "__methods__" ) == 0    )
1516                 {
1517                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1518                 }
1519         else if( strcmp( $2, "__abstract__" ) == 0      )
1520                 {
1521                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1522                 }
1523         else if( strcmp( $2, "__final__" ) == 0 )
1524                 {
1525                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1526                 }
1527         else if( strcmp( $2, "__protected__" ) == 0 )
1528                 {
1529                         accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1530                 }
1531         else if( strcmp( $2, "__private__" ) == 0 )
1532                 {
1533                         /* OK, no change */
1534                 }
1535         else
1536                 {
1537                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1538                 }
1539         $3->addModeBits( accessSpec );
1540         $$ = $3;
1542 | '(' T_abstract OrderedFormals ')'
1544         $$ = new Ast::AbstractSection( @$, $3 );
1546 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1548         $$ = new Ast::OverridesSection( $3, $5 );
1552 MemberDeclarations
1555         $$ = new Ast::MemberSection;
1557 | OneOrMoreMemberDeclarations
1560 OneOrMoreMemberDeclarations
1561 : MemberDeclaration
1563         $$ = new Ast::MemberSection;
1564         $$->push_back( $1 );
1566 | OneOrMoreMemberDeclarations MemberDeclaration
1568         $$ = $1;
1569         $$->push_back( $2 );
1573 MemberDeclaration
1574 : '(' T_identifier Expr ')'
1576         $$ = new Ast::MemberDeclaration( @$, $2, $3, 0 );
1578 | '(' T_identifier Expr MemberAccessList ')'
1580         $$ = new Ast::MemberDeclaration( @$, $2, $3, $4 );
1584 MemberAccessList
1585 : MemberAccessSpecifier
1586 | MemberAccessList MemberAccessSpecifier
1588         $$ = $1 | $2;
1592 MemberAccessSpecifier
1593 : '.'
1595         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1597 | T_llthan
1599         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1601 | '(' '#' '.' ')'
1603         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1605 | '(' '#' T_llthan ')'
1607         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1609 | '^'
1611         $$ = Ast::MEMBER_TRANSFORMING;
1615 MethodDeclarations
1618         $$ = new Ast::MemberSection;
1620 | OneOrMoreMethodDeclarations
1623 OneOrMoreMethodDeclarations
1624 : MethodDeclaration
1626         $$ = new Ast::MemberSection;
1627         $$->push_back( $1 );
1629 | OneOrMoreMethodDeclarations MethodDeclaration
1631         $$ = $1;
1632         $$->push_back( $2 );
1636 MethodDeclaration
1637 : '(' T_identifier Expr ')'
1639         $$ = new Ast::MemberDeclaration( @$, $2, $3, Ast::MEMBER_CONST | Ast::MEMBER_METHOD );
1641 | '(' '[' T_identifier Formals ']' FunctionModeList GroupElem ')'
1643         Ast::Expression * body = dynamic_cast< Ast::Expression * >( $7 );
1644         if( body == 0 )
1645                 {
1646                         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1647                         bracket->push_back( $7 );
1648                         body = new Ast::CodeBracket( @7, bracket );
1649                 }
1650         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1651         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $4, body, $6 );
1652         res->push_exprs( args );
1653         $$ = new Ast::MemberDeclaration( @$, $3, new Ast::CallExpr( @$,
1654                                                                                                                                                                                                                                                         RefCountPtr< const Lang::Function >( res ),
1655                                                                                                                                                                                                                                                         args ),
1656                                                                                                                                          Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1660 FunctionModeList
1663         $$ = 0;
1665 | OneOrMoreFunctionModeSpecifiers
1668 OneOrMoreFunctionModeSpecifiers
1669 : FunctionModeSpecifier
1670 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1672         $$ = $1 | $2;
1676 FunctionModeSpecifier
1677 : '^'
1679         $$ = Ast::FUNCTION_TRANSFORMING;
1681 | '!'
1683         $$ = Ast::FUNCTION_PROCEDURAL;
1687 Split
1688 : T_split Expr
1690         $$ = $2;
1696 /* The closing %% above marks the end of the Rules section and the beginning
1697  * of the User Subroutines section. All text from here to the end of the
1698  * file is copied verbatim to the end of the generated y.tab.c file.
1699  * This section is where you put definitions of helper functions.
1700  */