New expression to obtain the depth or index of a lexical variable.
[shapes.git] / source / shapesparser.yy
blobf6a40427fa24f911ef28584499835e10cae55dab
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 "astclass.h"
40 #include "shapesexceptions.h"
41 #include "consts.h"
42 #include "charptrless.h"
43 #include "autoonoff.h"
44 #include "shapescore.h"
45 #include "texlabelmanager.h"
47 using namespace Shapes;
48 #include "yyltype.h"
49 extern YYLTYPE shapeslloc;
51 #ifdef yylex
52         /* This is ugly.
53          * Warning! Warning! Warning!
54          * We'll soon use that yylex was defined as
55          *       #define yylex shapeslex
56          * in order to reset it after we're done with the inclusion.
57          */
58 #undef yylex
59 #include "globals.h"
60 #include "shapesscanner.h"
61 int shapeslex( )
63         return Ast::theShapesScanner.yylex( );
65 #define yylex shapeslex
66 #endif
68 #include "refcount.h"
70 #include <list>
71 #include <map>
72 #include <sstream>
74 using namespace std;
77 int shapeslex( );
80 void shapeserror( RefCountPtr< const char > msg )
82         throw Exceptions::ParserError( shapeslloc, msg );
85 void shapeserror( const char * msg )
87         shapeserror( strrefdup( msg ) );
94  * The section before the first %% is the Definitions section of the yacc
95  * input file. Here is where you declare tokens and types, add precedence
96  * and associativity options, and so on.
97  */
100  * yylval
101  * ------
102  * Here we define the type of the yylval global variable that is used by
103  * the scanner to store attibute information about the token just scanned
104  * and thus communicate that information to the parser. You will need to
105  * add new fields to this union as you add different attributes to your
106  * non-terminal symbols.
107  */
109 %union {
110         Ast::Expression * expr;
111         Ast::Node * node;
112         Ast::MethodIdExpr * methodId;
113         std::list< Ast::Node * > * nodeList;
114         std::list< Ast::Expression * > * exprList;
115         std::list< RefCountPtr< const char > > * strList;
116         std::map< const char *, Ast::Expression *, charPtrLess > * namedExprMap;
117         Kernel::Formals * formals;
118         std::list< Kernel::Formals * > * formalsList;
119         Ast::ArgListExprs * argList;
120         Ast::SplitDefineVariables * splitFormals;
121         int intVal;
122         double floatVal;
123         bool boolVal;
124         char * char_p;
125         int tokenID;
126         Lang::String * Lang_String;
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;
136         void * nothing;
140 /* Tokens
141  * ------
142  * Here we tell yacc about all the token types that we are using.
143  * Yacc will assign unique numbers to these and export the #define
144  * in the generated y.tab.h header file.
145  */
147 %token <tokenID> T_EOF T_preludesep T_minusminus T_plusplus T_ddot T_dddot T_assign T_eqeq T_eqneq T_atat T_projection T_angle T_ampersandMore
148 %token <tokenID> T_cycle T_and T_or T_xor T_not T_mapsto T_emptybrackets T_dddotbrackets T_compose T_surrounding T_lesseq T_greatereq T_llthan T_ggthan T_declaretype
149 %token <tokenID> T_tex T_indexof T_depthof T_dynamic T_continuation T_continue T_esc_continuation T_esc_continue T_esc_backtrace
150 %token <tokenID> T_class T_members T_prepare T_abstract T_overrides T_gr__
151 %token <tokenID> T_split T_splitLeft T_splitRight T_unionLeft T_unionRight T_absLeft T_absRight
152 %token <tokenID> T_srcLoc
153 %token <tokenID> T_interactiveMark
155 %token <intVal> T_int
156 %token <floatVal> T_float T_length
157 %token <expr> T_speciallength
158 %token <boolVal> T_bool
159 %token <char_p> T_identifier T_dynamic_identifier T_state_identifier T_dynamic_state_identifier T_typename
160 %token <Lang_String> T_string
162 /* Non-terminal types
163  * ------------------
164  * In order for yacc to assign/access the correct field of $$, $1, we
165  * must to declare which field is appropriate for the non-terminal.
166  * As an example, this first type declaration establishes that the DeclList
167  * non-terminal uses the field named "declList" in the yylval union. This
168  * means that when we are setting $$ for a reduction for DeclList ore reading
169  * $n which corresponds to a DeclList nonterminal we are accessing the field
170  * of the union named "declList" which is of type List<Decl*>.
171  * pp2: You'll need to add many of these of your own.
172  */
174 %type <expr> Program Expr ExprExceptConstStrings DynamicBinding CallExpr CurryCallExpr MutateExpr Function OperatorFunction Class ConstantExceptStrings Coords PolarHandle
175 %type <expr> CodeBracket SuperCall SuperMemberReference
176 %type <exprList> InsertionSequence
177 %type <node> GroupElem
178 %type <nodeList> Group OneOrMoreGroupElems
179 %type <strList> OrderedFormals OneOrMoreOrderedFormals
180 %type <formals> Formals OneOrMoreFormalsItems
181  //                                     %type <formalsList> NamedFormalsWithOrder OneOrMoreNamedFormalsWithOrder
182 %type <argList> ArgList OneOrMoreArgListItems
183 %type <methodId> MethodIdentifier
184 %type <callExprList> ListOfParentsWithInitargs;
185 %type <classSectionList> ClassSections OneOrMoreClassSections
186 %type <classSection> ClassSection
187 %type <memberSection> MemberDeclarations OneOrMoreMemberDeclarations
188 %type <memberSection> MethodDeclarations OneOrMoreMethodDeclarations
189 %type <memberDeclaration> MemberDeclaration MethodDeclaration
190 %type <memberMode> MemberAccessList MemberAccessSpecifier
191 %type <classMode> ClassModeList ClassModeSpecifier OneOrMoreClassModeSpecifiers
192 %type <functionMode> FunctionModeList OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
193 %type <expr> Split
194 %type <stateReference> StateReference
195 %type <splitFormals> SplitFormals OneOrMoreSplitFormals
197 %nonassoc T_assign ':'
199 %left T_llthan
200 %nonassoc '!'
202 %nonassoc T_mapsto
203 %right '|'
204 %left T_emptybrackets T_dddotbrackets T_ggthan
206 %left T_ampersandMore
207 %left '&'
208 %nonassoc T_dynamiccolon
210 %left T_or
211 %nonassoc T_xor
212 %left T_and
213 %left T_not
214 %nonassoc T_eqeq T_eqneq T_lesseq T_greatereq
216 %left T_plusplus T_minusminus
217 %left '<' '>'
219 %left '+' '-'
220 %nonassoc T_angle
221 %left '*' '/' T_projection
222 %left '~'
224 %left T_compose
226 %left '.'
227 %left '#'
228 %left T_split
229 %left T_atat T_surrounding
231 %left ','
233 %start Program
235 %name-prefix="shapes"
239  * All productions and actions should be placed between the start and stop
240  * %% markers which delimit the Rules section.
241  */
243 Program
244 : Group T_preludesep Group T_EOF
246         /* Note that the source location of the prelude is discarded. */
247         $1->push_back( new Ast::CodeBracket( @3, $3 ) );
248         $$ = new Ast::CodeBracket( @3, $1 );
249         Ast::theProgram = $$;
250         YYACCEPT;
252 | T_interactiveMark Group T_EOF
254         Ast::theInteractiveInput = $2;
255         YYACCEPT;
257 | Group error
259         shapeserror( "Expecting end of file." );
264 Coords
265 : '(' Expr ',' Expr ')'
267         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
268         args->orderedExprs_->push_back( $2 );
269         args->orderedExprs_->push_back( $4 );
270         $$ = new Ast::CallExpr( @$,
271                                                                                                         Ast::THE_FUNCTION_coords2D,
272                                                                                                         args );
274 | '(' Expr ',' Expr '^' Expr ')'
276         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
277         args->orderedExprs_->push_back( $2 );
278         args->orderedExprs_->push_back( $4 );
279         args->orderedExprs_->push_back( $6 );
280         $$ = new Ast::CallExpr( @$,
281                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
282                                                                                                         args );
284 | '(' Expr ',' Expr '^' ')'
286         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
287         args->orderedExprs_->push_back( $2 );
288         args->orderedExprs_->push_back( $4 );
289         $$ = new Ast::CallExpr( @$,
290                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
291                                                                                                         args );
293 | '(' Expr ',' Expr ',' Expr ')'
295         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
296         args->orderedExprs_->push_back( $2 );
297         args->orderedExprs_->push_back( $4 );
298         args->orderedExprs_->push_back( $6 );
299         $$ = new Ast::CallExpr( @$,
300                                                                                                         Ast::THE_FUNCTION_coords3D,
301                                                                                                         args );
306 PolarHandle
307 : '(' Expr '^' Expr ')'
309         $$ = new Ast::PolarHandle2DExpr( @$, $2, $4 );
311 | '(' Expr '^' ')'
313         $$ = new Ast::PolarHandle2DExprFree_a( @$, $2 );
315 | '(' '^' Expr ')'
317         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
318         args->orderedExprs_->push_back( $3 );
319         $$ = new Ast::CallExpr( @$,
320                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_r,
321                                                                                                         args );
323 | '(' '^' ')'
325         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
326         $$ = new Ast::CallExpr( @$,
327                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_ra,
328                                                                                                         args );
332 StateReference
333 : T_state_identifier
335         $$ = new Ast::LexiographicState( @1, $1, new Kernel::Environment::LexicalKey * ( 0 ) );
337 | T_dynamic_state_identifier
339         $$ = new Ast::DynamicState( @1, $1 );
343 ArgList
346         $$ = new Ast::ArgListExprs( true );
348 | OneOrMoreArgListItems
351 OneOrMoreArgListItems
352 : Expr
354         $$ = new Ast::ArgListExprs( true );
355         $$->orderedExprs_->push_back( $1 );
357 | StateReference
359         $$ = new Ast::ArgListExprs( true );
360         $$->orderedStates_->push_back( $1 );
362 | T_identifier ':' Expr
364         $$ = new Ast::ArgListExprs( true );
365         (*$$->namedExprs_)[ $1 ] = $3;
367 | T_state_identifier ':' StateReference
369         $$ = new Ast::ArgListExprs( true );
370         (*$$->namedStates_)[ $1 ] = $3;
372 | OneOrMoreArgListItems Expr
374         $$ = $1;
375         if( ! $$->namedExprs_->empty( ) )
376                 {
377                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed expressions may not appear among named expressions." ) ) );
378                 }
379         $$->orderedExprs_->push_back( $2 );
381 | OneOrMoreArgListItems StateReference
383         $$ = $1;
384         if( ! $$->namedStates_->empty( ) )
385                 {
386                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed states may not appear among named states." ) ) );
387                 }
388         $$->orderedStates_->push_back( $2 );
390 | OneOrMoreArgListItems T_identifier ':' Expr
392         $$ = $1;
393         if( $$->namedExprs_->find( $2 ) != $$->namedExprs_->end( ) )
394                 {
395                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
396                 }
397         (*$$->namedExprs_)[ $2 ] = $4;
399 | OneOrMoreArgListItems T_state_identifier ':' StateReference
401         $$ = $1;
402         if( $$->namedStates_->find( $2 ) != $$->namedStates_->end( ) )
403                 {
404                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
405                 }
406         (*$$->namedStates_)[ $2 ] = $4;
411 CallExpr
412 : '[' Expr ArgList ']'
414         $$ = new Ast::CallExpr( @$, $2, $3 );
416 | Expr T_emptybrackets Expr
418         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
419         args->orderedExprs_->push_back( $3 );
420         $$ = new Ast::CallExpr( @$,
421                                                                                                         $1,
422                                                                                                         args );
424 | Expr T_ggthan Expr
426         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
427         args->orderedExprs_->push_back( $1 );
428         $$ = new Ast::CallExpr( @$,
429                                                                                                         $3,
430                                                                                                         args );
432 | Expr T_emptybrackets Split
434         $$ = new Ast::CallSplitExpr( @$,
435                                                                                                                          $1,
436                                                                                                                          $3 );
438 | Expr T_dddotbrackets Expr
440         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
441         args->orderedExprs_->push_back( $3 );
442         $$ = new Ast::CallExpr( @$,
443                                                                                                         $1,
444                                                                                                         args,
445                                                                                                         true ); /* true means Curry */
447 | Expr T_dddotbrackets T_identifier ':' Expr %prec T_dynamiccolon
449         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
450         (*args->namedExprs_)[ $3 ] = $5;
451         $$ = new Ast::CallExpr( @$,
452                                                                                                         $1,
453                                                                                                         args,
454                                                                                                         true ); /* true means Curry */
456 | Expr T_dddotbrackets Split
458         $$ = new Ast::CallSplitExpr( @$,
459                                                                                                                          $1,
460                                                                                                                          $3,
461                                                                                                                          true );        /* true means Curry */
466 CurryCallExpr
467 : '[' Expr ArgList T_dddot ']'
469         $$ = new Ast::CallExpr( @$, $2, $3, true ); /* true means Curry */
473 MutateExpr
474 : StateReference '.' '[' T_identifier ArgList ']'
476         Ast::CallExpr * res =
477                 new Ast::CallExpr( @$,
478                                                                                          new Ast::MutatorReference( @4, $1, $4 ),
479                                                                                          $5 );
480         res->setMutatorSelf( $1 );
481         $$ = res;
485 Formals
488         $$ = new Kernel::Formals( );
489         $$->setLoc( @$ );
491 | T_split T_identifier
493         $$ = new Kernel::Formals( );
494         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
495         /* Note that we do not push a default expression (not even a null pointer) for the sink.
496          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
497          * The default value for the sink is taken care of in a non-standard way anyway.
498          */
499         $$->setLoc( @$ );
500         $$->sink_ = $2;
502 | OneOrMoreFormalsItems
504         $$ = $1;
505         $$->setLoc( @$ );
507 | OneOrMoreFormalsItems T_split T_identifier
509         $$ = $1;
510         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $3, $$->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_ = $3;
520 OneOrMoreFormalsItems
521 : T_identifier
523         $$ = new Kernel::Formals( );
524         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
525         $$->defaultExprs_.push_back( 0 );
527 | T_identifier ':' Expr
529         $$ = new Kernel::Formals( );
530         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
531         $$->defaultExprs_.push_back( $3 );
533 | T_state_identifier
535         $$ = new Kernel::Formals( );
536         $$->stateOrder_->insert( std::pair< const char *, size_t >( $1, $$->stateOrder_->size( ) ) );
538 | OneOrMoreFormalsItems T_identifier
540         $$ = $1;
541         if( $$->seenDefault_ )
542                 {
543                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
544                 }
545         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
546                 {
547                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
548                 }
549         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
550         $$->defaultExprs_.push_back( 0 );
552 | OneOrMoreFormalsItems T_identifier ':' Expr
554         $$ = $1;
555         $$->seenDefault_ = true;
556         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
557                 {
558                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
559                 }
560         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
561         $$->defaultExprs_.push_back( $4 );
563 | OneOrMoreFormalsItems T_state_identifier
565         $$ = $1;
566         if( $$->stateOrder_->find( $2 ) != $$->stateOrder_->end( ) )
567                 {
568                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
569                 }
570         $$->stateOrder_->insert( std::pair< const char *, size_t >( $2, $$->stateOrder_->size( ) ) );
575 SplitFormals
578         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "The list of split assignment variables must not be empty." ) ) );
579         $$ = new Ast::SplitDefineVariables( );
581 | T_split T_identifier
583         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "Just a sink in a split assignment formals list makes no sense." ) ) );
584         $$ = new Ast::SplitDefineVariables( );
586 | OneOrMoreSplitFormals
588         $$ = $1;
590 | OneOrMoreSplitFormals T_split T_identifier
592         $$ = $1;
593         Ast::StructSplitSink * expr = new Ast::StructSplitSink( );
594         size_t ** pos = new size_t * ( 0 );
595         $$->sinkDefine_ = new Ast::DefineVariable( @3, $3, expr, pos );
596         $$->sinkExpr_ = expr;
600 OneOrMoreSplitFormals
601 : T_identifier
603         $$ = new Ast::SplitDefineVariables( );
604         typedef typeof $$->exprs_ ListType;
605         size_t ** pos = new size_t * ( 0 );
606         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), 0 );
607         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
608                                                                                                                                                                                          ref ) );
610 | T_identifier ':' Expr
612         $$ = new Ast::SplitDefineVariables( );
613         typedef typeof $$->exprs_ ListType;
614         size_t ** pos = new size_t * ( 0 );
615         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), $3 );
616         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
617                                                                                                                                                                                          ref ) );
619 | T_identifier ':' '.' T_identifier
621         $$ = new Ast::SplitDefineVariables( );
622         typedef typeof $$->exprs_ ListType;
623         size_t ** pos = new size_t * ( 0 );
624         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, 0 );
625         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
626                                                                                                                                                                                          ref ) );
628 | T_identifier ':' '.' T_identifier ':' Expr
630         $$ = new Ast::SplitDefineVariables( );
631         typedef typeof $$->exprs_ ListType;
632         size_t ** pos = new size_t * ( 0 );
633         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, $6 );
634         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
635                                                                                                                                                                                          ref ) );
637 | T_identifier ':' '.' '\"'
639         $$ = new Ast::SplitDefineVariables( );
640         typedef typeof $$->exprs_ ListType;
641         size_t ** pos = new size_t * ( 0 );
642         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), 0 );
643         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
644                                                                                                                                                                                          ref ) );
646 | T_identifier ':' '.' '\"' ':' Expr
648         $$ = new Ast::SplitDefineVariables( );
649         typedef typeof $$->exprs_ ListType;
650         size_t ** pos = new size_t * ( 0 );
651         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), $6 );
652         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
653                                                                                                                                                                                          ref ) );
655 | OneOrMoreSplitFormals T_identifier
657         $$ = $1;
658         if( $$->seenNamed_ )
659                 {
660                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
661                 }
662         if( $$->seenDefault_ )
663                 {
664                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "All order-based formals without default values must be placed before those with default values." ) ) );
665                 }
666         typedef typeof $$->exprs_ ListType;
667         size_t ** pos = new size_t * ( 0 );
668         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), 0 );
669         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
670                                                                                                                                                                                          ref ) );
672 | OneOrMoreSplitFormals T_identifier ':' Expr
674         $$ = $1;
675         if( $$->seenNamed_ )
676                 {
677                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
678                 }
679         $$->seenDefault_ = true;
680         typedef typeof $$->exprs_ ListType;
681         size_t ** pos = new size_t * ( 0 );
682         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), $4 );
683         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
684                                                                                                                                                                                          ref ) );
686 | OneOrMoreSplitFormals T_identifier ':' '.' T_identifier
688         $$ = $1;
689         $$->seenNamed_ = true;
690         typedef typeof $$->exprs_ ListType;
691         size_t ** pos = new size_t * ( 0 );
692         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, 0 );
693         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
694                                                                                                                                                                                          ref ) );
696 | OneOrMoreSplitFormals T_identifier ':' '.' T_identifier ':' Expr
698         $$ = $1;
699         $$->seenNamed_ = true;
700         typedef typeof $$->exprs_ ListType;
701         size_t ** pos = new size_t * ( 0 );
702         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, $7 );
703         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
704                                                                                                                                                                                          ref ) );
706 | OneOrMoreSplitFormals T_identifier ':' '.' '\"'
708         $$ = $1;
709         $$->seenNamed_ = true;
710         typedef typeof $$->exprs_ ListType;
711         size_t ** pos = new size_t * ( 0 );
712         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), 0 );
713         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
714                                                                                                                                                                                          ref ) );
716 | OneOrMoreSplitFormals T_identifier ':' '.' '\"' ':' Expr
718         $$ = $1;
719         $$->seenNamed_ = true;
720         typedef typeof $$->exprs_ ListType;
721         size_t ** pos = new size_t * ( 0 );
722         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), $7 );
723         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
724                                                                                                                                                                                          ref ) );
729 Function
730 : '\\' Formals T_mapsto FunctionModeList Expr
732         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
733         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $2, $5, $4 );
734         res->push_exprs( args );
735         $$ = new Ast::CallExpr( @$,
736                                                                                                         RefCountPtr< const Lang::Function >( res ),
737                                                                                                         args );
739 | '(' OperatorFunction ')'
741         $$ = $2;
745 OrderedFormals
748         $$ = new list< RefCountPtr< const char > >( );
750 | OneOrMoreOrderedFormals
753 OneOrMoreOrderedFormals
754 : T_identifier
756         $$ = new list< RefCountPtr< const char > >( );
757         $$->push_back( strrefdup( $1 ) );
759 | OneOrMoreOrderedFormals T_identifier
761         $$ = $1;
762         $$->push_back( strrefdup( $2 ) );
766 OperatorFunction
767 : T_minusminus
769         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUSMINUS ) );
771 | T_plusplus
773         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUSPLUS ) );
775 | '&'
777         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND ) );
779 | '+'
781         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUS ) );
783 | '-'
785         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUS ) );
787 | '*'
789         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_STAR ) );
791 | '/'
793         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_SLASH ) );
795 | T_projection
797         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PROJECTION ) );
799 | T_angle
801         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_ANGLE ) );
803 | T_ampersandMore
805         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND_MORE ) );
807 | '~'
809         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NEG ) );
811 | T_compose
813         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_COMPOSE ) );
815 | '<'
817         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
819 | '>'
821         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
823 | T_eqeq
825         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQEQ ) );
827 | T_eqneq
829         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQNEQ ) );
831 | T_lesseq
833         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
835 | T_greatereq
837         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
839 | T_not
841         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NOT ) );
843 | T_and
845         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_AND ) );
847 | T_or
849         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_OR ) );
851 | T_xor
853         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_XOR ) );
857 Expr
858 : ExprExceptConstStrings
859 | T_string
861         $$ = new Ast::Constant( @1, $1 );
865 ExprExceptConstStrings
866 : ConstantExceptStrings
867 | Coords
868 | PolarHandle
869 | '(' T_tex ExprExceptConstStrings ')'
871         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
872         args->orderedExprs_->push_back( $3 );
873         $$ = new Ast::CallExpr( @$,
874                                                                                                         Ast::THE_FUNCTION_TeX,
875                                                                                                         args );
877 | '(' T_tex T_string ')'
879         Kernel::theTeXLabelManager.announce( std::string( $3->val_.getPtr( ) ), @3 );
880         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
881         args->orderedExprs_->push_back( new Ast::Constant( @3, $3 ) );
882         $$ = new Ast::CallExpr( @$,
883                                                                                                         Ast::THE_FUNCTION_TeX,
884                                                                                                         args );
886 | '!' Expr
888         $$ = $2;
889         $$->immediate_ = true;
891 | CallExpr
892 | CurryCallExpr
893 | SuperCall
894 | SuperMemberReference
895 | T_speciallength
896 | '(' Expr ')'
898         $$ = $2;
900 | '(' '-' Expr ')'
902         $$ = new Ast::NegExpr( @$, @2, $3 );
904 | '(' '+' Expr ')'
906         $$ = new Ast::RelativeExpr( @$, @2, $3 );
908 | '(' ')'
910         $$ = new Ast::EmptyExpression( @$ );
912 | '(' Expr T_llthan InsertionSequence ')'
914         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
916         size_t ** pos = new size_t * ( 0 );
917         Ast::StateReference * dst = new Ast::LexiographicState( @2, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), new Kernel::Environment::LexicalKey * ( 0 ) );
919         bracket->push_back( new Ast::IntroduceState( @3,
920                                                                                                                                                                                          strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ),
921                                                                                                                                                                                          $2,
922                                                                                                                                                                                          pos ) );
923         for( std::list< Ast::Expression * >::const_iterator i = $4->begin( ); i != $4->end( ); ++i )
924                 {
925                         bracket->push_back( new Ast::Insertion( dst, *i ) );
926                 }
927         bracket->push_back( new Ast::Freeze( @3, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), pos ) );
928         $$ = new Ast::CodeBracket( @$, bracket );
930 | T_surrounding Expr
932         $$ = new Ast::EvalOutsideExpr( @$, $2 );
934 | CodeBracket
935 | Function
936 | Class
937 | T_identifier
939         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
940         $$ = new Ast::LexiographicVariable( @$, $1, key );
942 | T_atat Expr
944         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
945         Ast::EvalSymbolFunction * res = new Ast::EvalSymbolFunction( @$, $2 );
946         res->push_exprs( args );
947         $$ = new Ast::CallExpr( @$,
948                                                                                                         RefCountPtr< const Lang::Function >( res ),
949                                                                                                         args );
951 | T_dynamic_identifier
953         $$ = new Ast::DynamicVariable( @$, $1 );
955 | '(' StateReference ')'
957         $$ = new Ast::Peek( @$, $2 );
959 | MutateExpr
960 | Expr '.' T_identifier
962         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
963         Ast::MemberReferenceFunction * res = new Ast::MemberReferenceFunction( @$, $1, $3 );
964         res->push_exprs( args );
965         $$ = new Ast::CallExpr( @$,
966                                                                                                         RefCountPtr< const Lang::Function >( res ),
967                                                                                                         args );
969 | Expr '.' MethodIdentifier
971         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
972         Ast::PublicMethodReferenceFunction * res = new Ast::PublicMethodReferenceFunction( @$, $1, $3 );
973         res->push_exprs( args );
974         $$ = new Ast::CallExpr( @$,
975                                                                                                         RefCountPtr< const Lang::Function >( res ),
976                                                                                                         args );
978 | DynamicBinding
979 | '(' T_esc_continuation T_identifier Expr ')'
981         $$ = new Ast::LetDynamicECExpr( @$, @3, $3, $4 );
983 | '(' T_esc_continue T_identifier Expr ')'
985         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
986         Ast::ContinueDynamicECFunction * res = new Ast::ContinueDynamicECFunction( @3, $3, $4 );
987         res->push_exprs( args );
988         $$ = new Ast::CallExpr( @$,
989                                                                                                         RefCountPtr< const Lang::Function >( res ),
990                                                                                                         args );
991         /* This used to be immediate, but right now that seems utterly wrong!
992          * Imagine choosing between two continuations; then both continuations would require invokation before being "passed" to the <if> function.
993          * 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
994          * knowing when they will be forced...  But I don't think there's a choice here anyway; this expression can't be immediate.
995          */
997 | '(' T_esc_backtrace T_identifier ')'
999         $$ = new Ast::GetECBacktraceExpr( @3, $3 );
1001 | '(' T_indexof T_identifier ')'
1003         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::INDEX );
1005 | '(' T_depthof T_identifier ')'
1007         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::DEPTH );
1009 | T_absLeft Expr T_absRight
1011         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1012         args->orderedExprs_->push_back( $2 );
1013         $$ = new Ast::CallExpr( @$,
1014                                                                                                         Lang::THE_FUNCTION_ABS,
1015                                                                                                         args );
1017 | Expr '|' Expr
1019         $$ = new Ast::WithDynamicExpr( @$, $1, $3 );
1021 | T_unionLeft ArgList T_unionRight
1023         $$ = new Ast::UnionExpr( @$, $2 );
1025 | Expr T_minusminus T_cycle
1027         $$ = new Ast::CycleExpr( @3, $1 );
1029 | Expr T_minusminus Expr
1031         $$ = new Ast::MinusMinusExpr( @2, $1, $3 );
1033 | Expr T_plusplus Expr
1035         $$ = new Ast::PlusPlusExpr( @2, $1, $3 );
1037 | Expr '&' Expr
1039         $$ = new Ast::AmpersandExpr( @2, $1, $3 );
1041 | Expr '+' Expr
1043         $$ = new Ast::PlusExpr( @2, $1, $3 );
1045 | Expr '-' Expr
1047         $$ = new Ast::MinusExpr( @2, $1, $3 );
1049 | Expr T_angle Expr
1051         $$ = new Ast::AngleExpr( @2, $1, $3 );
1053 | Expr T_ampersandMore Expr
1055         $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1057 | Expr '*' Expr
1059         $$ = new Ast::StarExpr( @2, $1, $3 );
1061 | Expr T_projection Expr
1063         $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1065 | Expr '/' Expr
1067         $$ = new Ast::SlashExpr( @2, $1, $3 );
1069 | '~' Expr
1071         $$ = new Ast::NegExpr( @1, $2 );
1073 | Expr T_compose Expr
1075         $$ = new Ast::ComposeExpr( @2, $1, $3 );
1077 | Expr '<' Expr
1079         $$ = new Ast::LessExpr( @2, $1, $3 );
1081 | Expr '>' Expr
1083         $$ = new Ast::GreaterExpr( @2, $1, $3 );
1085 | Expr T_eqeq Expr
1087         $$ = new Ast::EqualExpr( @2, $1, $3 );
1089 | Expr T_eqneq Expr
1091         $$ = new Ast::NotEqualExpr( @2, $1, $3 );
1093 | Expr T_lesseq Expr
1095         $$ = new Ast::LessEqualExpr( @2, $1, $3 );
1097 | Expr T_greatereq Expr
1099         $$ = new Ast::GreaterEqualExpr( @2, $1, $3 );
1101 | T_not Expr
1103         $$ = new Ast::NotExpr( @1, $2 );
1105 | Expr T_and Expr
1107         //      $$ = new Ast::AndExpr( @2, $1, $3 );
1109         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1110         args->orderedExprs_->push_back( $1 );
1111         args->orderedExprs_->push_back( $3 );
1112         $$ = new Ast::CallExpr( @$,
1113                                                                                                         Lang::THE_FUNCTION_AND,
1114                                                                                                         args );
1116 | Expr T_or Expr
1118         //      $$ = new Ast::OrExpr( @2, $1, $3 );
1120         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1121         args->orderedExprs_->push_back( $1 );
1122         args->orderedExprs_->push_back( $3 );
1123         $$ = new Ast::CallExpr( @$,
1124                                                                                                         Lang::THE_FUNCTION_OR,
1125                                                                                                         args );
1127 | Expr T_xor Expr
1129         $$ = new Ast::XorExpr( @2, $1, $3 );
1131 | T_typename
1133         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1134         $$ = new Ast::LexiographicType( @$, $1, key );
1139 DynamicBinding
1140 : T_dynamic_identifier ':' Expr %prec T_dynamiccolon
1142         $$ = new Ast::DynamicBindingExpression( @1, $1, $3, new Kernel::Environment::LexicalKey * ( 0 ) );
1144 | T_dynamic_identifier ':' T_dynamic Expr %prec T_dynamiccolon
1146         $$ = new Ast::DynamicBindingExpression( @1, $1,
1147                                                                                                                                                                         new Ast::DynamicExpression( @4, $4 ),
1148                                                                                                                                                                         new Kernel::Environment::LexicalKey * ( 0 ) );
1150 | T_dynamic_state_identifier ':' StateReference %prec T_dynamiccolon
1152         $$ = new Ast::DynamicStateBindingExpression( @1, @1, $1, $3 );
1157 ConstantExceptStrings
1158 : T_int
1160         $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1162 | T_float
1164         $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1166 | T_length
1168         $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1170 | T_bool
1172         $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1174 | '\'' T_identifier
1176         $$ = new Ast::Constant( @1, new Lang::Symbol( $2 ) );
1180 CodeBracket
1181 : '{' Group '}'
1183         $$ = new Ast::CodeBracket( @$, $2 );
1187 GroupElem
1188 : Expr
1190         $$ = $1;        // Explicit upcast avoids bison warning.
1192 | T_identifier ':' Expr
1194         size_t ** pos = new size_t * ( 0 );
1195         $$ = new Ast::DefineVariable( @1, $1, $3, pos );
1197 | T_state_identifier ':' Expr
1199         size_t ** pos = new size_t * ( 0 );
1200         $$ = new Ast::IntroduceState( @1, $1, $3, pos );
1202 | T_state_identifier ';'
1204         size_t ** pos = new size_t * ( 0 );
1205         $$ = new Ast::Freeze( @1, $1, pos );
1207 | T_identifier ':' T_state_identifier ';'
1209         size_t ** posVar = new size_t * ( 0 );
1210         size_t ** posState = new size_t * ( 0 );
1211         $$ = new Ast::DefineVariable( @1, $1, new Ast::Freeze( @3, $3, posState ), posVar );
1213 | T_dynamic T_dynamic_identifier Expr Expr
1215         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3, $4 );
1217 | T_dynamic T_dynamic_identifier Expr T_dynamic Expr
1219         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3,
1220                                                                                                                                                  new Ast::DynamicExpression( @5, $5 ) );
1222 | T_dynamic T_dynamic_state_identifier StateReference
1224         $$ = new Ast::DynamicStateDecl( @$, @2, $2, $3, new size_t * ( 0 ) );
1226 | Expr '.' T_identifier T_llthan InsertionSequence
1228         shapeserror( "MemberInsertionSequence not implemented" );
1229         //      $$ = new Ast::MemberInsertionSequence( @$, $1, $3, $5 );
1231 | '(' '#' Expr ')' '.' T_identifier T_llthan InsertionSequence
1233         shapeserror( "ProtectedMemberInsertionSequence not implemented" );
1234         //      $$ = new Ast::ProtectedMemberInsertionSequence( @$, @2, $3, $6, $8 );
1236 | T_srcLoc
1238         $$ = new Ast::SourceLocationMark( @$ );
1242 InsertionSequence
1243 : Expr
1245         $$ = new std::list< Ast::Expression * >( );
1246         $$->push_back( $1 );
1248 | InsertionSequence T_llthan Expr
1250         $$ = $1;
1251         $$->push_back( $3 );
1255 OneOrMoreGroupElems
1256 : GroupElem
1258         $$ = new list< Ast::Node * >( );
1259         $$->push_back( $1 );
1261 | OneOrMoreGroupElems GroupElem
1263         $$ = $1;
1264         $$->push_back( $2 );
1266 | StateReference T_llthan InsertionSequence
1268         $$ = new list< Ast::Node * >( );
1269         for( std::list< Ast::Expression * >::const_iterator i = $3->begin( ); i != $3->end( ); ++i )
1270                 {
1271                         $$->push_back( new Ast::Insertion( $1, *i ) );
1272                 }
1274 | OneOrMoreGroupElems StateReference T_llthan InsertionSequence
1276         $$ = $1;
1277         for( std::list< Ast::Expression * >::const_iterator i = $4->begin( ); i != $4->end( ); ++i )
1278                 {
1279                         $$->push_back( new Ast::Insertion( $2, *i ) );
1280                 }
1282 | T_splitLeft SplitFormals T_splitRight ':' Expr
1284         $$ = new list< Ast::Node * >( );
1285         size_t ** pos = new size_t * ( 0 );
1287         $5->immediate_ = true;
1288         $$->push_back( new Ast::DefineVariable( @5, $2->newSplitVarId( ), $5, pos ) );
1290         size_t orderedCount = 0;
1292         typedef typeof $2->exprs_ ListType;
1293         for( ListType::iterator i = $2->exprs_.begin( ); i != $2->exprs_.end( ); ++i )
1294                 {
1295                         i->second->setStruct( @5, pos );
1296                         $$->push_back( i->first );
1297                         if( i->second->isOrdered( ) )
1298                                 {
1299                                         ++orderedCount;
1300                                 }
1301                 }
1303         if( $2->sinkDefine_ != 0 )
1304                 {
1305                         $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1306                         $$->push_back( $2->sinkDefine_ );
1307                 }
1308         else
1309                 {
1310                         $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
1311                 }
1313 | T_splitLeft SplitFormals T_splitRight Expr
1315         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1316         $$ = new list< Ast::Node * >( );
1317         $$->push_back( new Ast::ErrorExpression( @$ ) );
1319 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight ':' Expr
1321         $$ = $1;
1322         size_t ** pos = new size_t * ( 0 );
1324         $6->immediate_ = true;
1325         $$->push_back( new Ast::DefineVariable( @6, $3->newSplitVarId( ), $6, pos ) );
1327         size_t orderedCount = 0;
1329         typedef typeof $3->exprs_ ListType;
1330         for( ListType::iterator i = $3->exprs_.begin( ); i != $3->exprs_.end( ); ++i )
1331                 {
1332                         i->second->setStruct( @6, pos );
1333                         $$->push_back( i->first );
1334                         if( i->second->isOrdered( ) )
1335                                 {
1336                                         ++orderedCount;
1337                                 }
1338                 }
1340         if( $3->sinkDefine_ != 0 )
1341                 {
1342                         $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1343                         $$->push_back( $3->sinkDefine_ );
1344                 }
1345         else
1346                 {
1347                         $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1348                 }
1350 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1352         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1353         $$ = $1;
1354         $$->push_back( new Ast::ErrorExpression( @$ ) );
1358 Group
1361         $$ = new list< Ast::Node * >( );
1363 | OneOrMoreGroupElems
1367 SuperMemberReference
1368 : '(' '#' Expr ')' '.' T_identifier
1370         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1371         Ast::ProtectedMemberReferenceFunction * res = new Ast::ProtectedMemberReferenceFunction( @$, @2, $3, @6, $6 );
1372         res->push_exprs( args );
1373         $$ = new Ast::CallExpr( @$,
1374                                                                                                         RefCountPtr< const Lang::Function >( res ),
1375                                                                                                         args );
1380 MethodIdentifier
1381 : T_identifier '#' T_identifier
1383         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1384         $$ = new Ast::MethodIdExpr( @$, new Ast::LexiographicVariable( @1, $1, key ), $3 );
1389 SuperCall
1390 : '[' '(' '#' Expr ')' '.' MethodIdentifier ArgList ']'
1392         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1393         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, $4, $7 );
1394         res->push_exprs( args );
1395         $$ = new Ast::CallExpr( @$,
1396                                                                                                         new Ast::CallExpr( @3,
1397                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1398                                                                                                                                                                                  args ),
1399                                                                                                         $8 );
1401 | '[' '(' '#' ')' '.' MethodIdentifier ArgList ']'
1403         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1404         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, 0, $6 );
1405         res->push_exprs( args );
1406         $$ = new Ast::CallExpr( @$,
1407                                                                                                         new Ast::CallExpr( @3,
1408                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1409                                                                                                                                                                                  args ),
1410                                                                                                         $7 );
1415 Class
1416 : '[' T_class '(' Expr Formals ')' T_identifier '(' ListOfParentsWithInitargs ')'
1417         ClassModeList
1418         ClassSections
1419         ']'
1421         DeleteOnExit< char > isaDeleter( $7 );
1422         if( strcmp( $7, "isa" ) != 0 )
1423                 {
1424                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1425                 }
1426         if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1427                 {
1428                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
1429                 }
1431         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1432         Ast::ClassFunction * res = new Ast::ClassFunction( @$, $4, $5, $9, $11, $12 );
1433         res->push_exprs( args );
1434         $$ = new Ast::CallExpr( @$,
1435                                                                                                         RefCountPtr< const Lang::Function >( res ),
1436                                                                                                         args );
1440 ListOfParentsWithInitargs
1441 : '(' Expr ArgList ')'
1443         $$ = new std::list< const Ast::CallExpr * >;
1444         $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1446 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1448         $$ = $1;
1449         $$->push_back( new Ast::CallExpr( Ast::SourceLocation( @2, @5 ), $3, $4 ) );
1453 ClassModeList
1456         $$ = 0;
1458 | OneOrMoreClassModeSpecifiers
1461 OneOrMoreClassModeSpecifiers
1462 : ClassModeSpecifier
1463 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1465         $$ = $1 | $2;
1469 ClassModeSpecifier
1470 : T_identifier
1472         DeleteOnExit< char > strDeleter( $1 );
1473         $$ = 0;
1474         if( strcmp( $1, "abstract" ) == 0 )
1475                 {
1476                         $$ = Ast::CLASS_MODE_ABSTRACT;
1477                 }
1478         else if( strcmp( $1, "final" ) == 0 )
1479                 {
1480                         $$ = Ast::CLASS_MODE_FINAL;
1481                 }
1482         else
1483                 {
1484                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1485                 }
1489 ClassSections
1492         $$ = new std::list< Ast::ClassSection * >;
1494 | OneOrMoreClassSections
1497 OneOrMoreClassSections
1498 : ClassSection
1500         $$ = new std::list< Ast::ClassSection * >;
1501         $$->push_back( $1 );
1503 | OneOrMoreClassSections ClassSection
1505         $$ = $1;
1506         $$->push_back( $2 );
1510 ClassSection
1511 : '(' T_members MemberDeclarations ')'
1513         $$ = $3;
1515 | '(' T_prepare Group ')'
1517         $$ = new Ast::PrepareSection( @$, $3 );
1519 | '(' T_identifier MethodDeclarations ')'
1521         DeleteOnExit< char > accessSpecDeleter( $2 );
1522         unsigned int accessSpec = 0;
1523         if( strcmp( $2, "__methods__" ) == 0    )
1524                 {
1525                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1526                 }
1527         else if( strcmp( $2, "__abstract__" ) == 0      )
1528                 {
1529                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1530                 }
1531         else if( strcmp( $2, "__final__" ) == 0 )
1532                 {
1533                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1534                 }
1535         else if( strcmp( $2, "__protected__" ) == 0 )
1536                 {
1537                         accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1538                 }
1539         else if( strcmp( $2, "__private__" ) == 0 )
1540                 {
1541                         /* OK, no change */
1542                 }
1543         else
1544                 {
1545                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1546                 }
1547         $3->addModeBits( accessSpec );
1548         $$ = $3;
1550 | '(' T_abstract OrderedFormals ')'
1552         $$ = new Ast::AbstractSection( @$, $3 );
1554 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1556         $$ = new Ast::OverridesSection( $3, $5 );
1560 MemberDeclarations
1563         $$ = new Ast::MemberSection;
1565 | OneOrMoreMemberDeclarations
1568 OneOrMoreMemberDeclarations
1569 : MemberDeclaration
1571         $$ = new Ast::MemberSection;
1572         $$->push_back( $1 );
1574 | OneOrMoreMemberDeclarations MemberDeclaration
1576         $$ = $1;
1577         $$->push_back( $2 );
1581 MemberDeclaration
1582 : '(' T_identifier Expr ')'
1584         $$ = new Ast::MemberDeclaration( @$, $2, $3, 0 );
1586 | '(' T_identifier Expr MemberAccessList ')'
1588         $$ = new Ast::MemberDeclaration( @$, $2, $3, $4 );
1592 MemberAccessList
1593 : MemberAccessSpecifier
1594 | MemberAccessList MemberAccessSpecifier
1596         $$ = $1 | $2;
1600 MemberAccessSpecifier
1601 : '.'
1603         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1605 | T_llthan
1607         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1609 | '(' '#' '.' ')'
1611         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1613 | '(' '#' T_llthan ')'
1615         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1617 | '^'
1619         $$ = Ast::MEMBER_TRANSFORMING;
1623 MethodDeclarations
1626         $$ = new Ast::MemberSection;
1628 | OneOrMoreMethodDeclarations
1631 OneOrMoreMethodDeclarations
1632 : MethodDeclaration
1634         $$ = new Ast::MemberSection;
1635         $$->push_back( $1 );
1637 | OneOrMoreMethodDeclarations MethodDeclaration
1639         $$ = $1;
1640         $$->push_back( $2 );
1644 MethodDeclaration
1645 : '(' T_identifier Expr ')'
1647         $$ = new Ast::MemberDeclaration( @$, $2, $3, Ast::MEMBER_CONST | Ast::MEMBER_METHOD );
1649 | '(' '[' T_identifier Formals ']' FunctionModeList GroupElem ')'
1651         Ast::Expression * body = dynamic_cast< Ast::Expression * >( $7 );
1652         if( body == 0 )
1653                 {
1654                         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1655                         bracket->push_back( $7 );
1656                         body = new Ast::CodeBracket( @7, bracket );
1657                 }
1658         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1659         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $4, body, $6 );
1660         res->push_exprs( args );
1661         $$ = new Ast::MemberDeclaration( @$, $3, new Ast::CallExpr( @$,
1662                                                                                                                                                                                                                                                         RefCountPtr< const Lang::Function >( res ),
1663                                                                                                                                                                                                                                                         args ),
1664                                                                                                                                          Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1668 FunctionModeList
1671         $$ = 0;
1673 | OneOrMoreFunctionModeSpecifiers
1676 OneOrMoreFunctionModeSpecifiers
1677 : FunctionModeSpecifier
1678 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1680         $$ = $1 | $2;
1684 FunctionModeSpecifier
1685 : '^'
1687         $$ = Ast::FUNCTION_TRANSFORMING;
1691 Split
1692 : T_split Expr
1694         $$ = $2;
1700 /* The closing %% above marks the end of the Rules section and the beginning
1701  * of the User Subroutines section. All text from here to the end of the
1702  * file is copied verbatim to the end of the generated y.tab.c file.
1703  * This section is where you put definitions of helper functions.
1704  */