Bugfix: Source location of a symbol was missing the identifier part of it.
[shapes.git] / source / shapesparser.yy
blobc1327e1f29150c8de16c75047c2fc071a9915bb4
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_variableName 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_variableName
1011         $$ = new Ast::LexicalVariableNameExpr( @1 );
1013 | T_absLeft Expr T_absRight
1015         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1016         args->orderedExprs_->push_back( $2 );
1017         $$ = new Ast::CallExpr( @$,
1018                                                                                                         Lang::THE_FUNCTION_ABS,
1019                                                                                                         args );
1021 | Expr '|' Expr
1023         $$ = new Ast::WithDynamicExpr( @$, $1, $3 );
1025 | T_unionLeft ArgList T_unionRight
1027         $$ = new Ast::UnionExpr( @$, $2 );
1029 | Expr T_minusminus T_cycle
1031         $$ = new Ast::CycleExpr( @3, $1 );
1033 | Expr T_minusminus Expr
1035         $$ = new Ast::MinusMinusExpr( @2, $1, $3 );
1037 | Expr T_plusplus Expr
1039         $$ = new Ast::PlusPlusExpr( @2, $1, $3 );
1041 | Expr '&' Expr
1043         $$ = new Ast::AmpersandExpr( @2, $1, $3 );
1045 | Expr '+' Expr
1047         $$ = new Ast::PlusExpr( @2, $1, $3 );
1049 | Expr '-' Expr
1051         $$ = new Ast::MinusExpr( @2, $1, $3 );
1053 | Expr T_angle Expr
1055         $$ = new Ast::AngleExpr( @2, $1, $3 );
1057 | Expr T_ampersandMore Expr
1059         $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1061 | Expr '*' Expr
1063         $$ = new Ast::StarExpr( @2, $1, $3 );
1065 | Expr T_projection Expr
1067         $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1069 | Expr '/' Expr
1071         $$ = new Ast::SlashExpr( @2, $1, $3 );
1073 | '~' Expr
1075         $$ = new Ast::NegExpr( @1, $2 );
1077 | Expr T_compose Expr
1079         $$ = new Ast::ComposeExpr( @2, $1, $3 );
1081 | Expr '<' Expr
1083         $$ = new Ast::LessExpr( @2, $1, $3 );
1085 | Expr '>' Expr
1087         $$ = new Ast::GreaterExpr( @2, $1, $3 );
1089 | Expr T_eqeq Expr
1091         $$ = new Ast::EqualExpr( @2, $1, $3 );
1093 | Expr T_eqneq Expr
1095         $$ = new Ast::NotEqualExpr( @2, $1, $3 );
1097 | Expr T_lesseq Expr
1099         $$ = new Ast::LessEqualExpr( @2, $1, $3 );
1101 | Expr T_greatereq Expr
1103         $$ = new Ast::GreaterEqualExpr( @2, $1, $3 );
1105 | T_not Expr
1107         $$ = new Ast::NotExpr( @1, $2 );
1109 | Expr T_and Expr
1111         //      $$ = new Ast::AndExpr( @2, $1, $3 );
1113         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1114         args->orderedExprs_->push_back( $1 );
1115         args->orderedExprs_->push_back( $3 );
1116         $$ = new Ast::CallExpr( @$,
1117                                                                                                         Lang::THE_FUNCTION_AND,
1118                                                                                                         args );
1120 | Expr T_or Expr
1122         //      $$ = new Ast::OrExpr( @2, $1, $3 );
1124         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1125         args->orderedExprs_->push_back( $1 );
1126         args->orderedExprs_->push_back( $3 );
1127         $$ = new Ast::CallExpr( @$,
1128                                                                                                         Lang::THE_FUNCTION_OR,
1129                                                                                                         args );
1131 | Expr T_xor Expr
1133         $$ = new Ast::XorExpr( @2, $1, $3 );
1135 | T_typename
1137         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1138         $$ = new Ast::LexiographicType( @$, $1, key );
1143 DynamicBinding
1144 : T_dynamic_identifier ':' Expr %prec T_dynamiccolon
1146         $$ = new Ast::DynamicBindingExpression( @1, $1, $3, new Kernel::Environment::LexicalKey * ( 0 ) );
1148 | T_dynamic_identifier ':' T_dynamic Expr %prec T_dynamiccolon
1150         $$ = new Ast::DynamicBindingExpression( @1, $1,
1151                                                                                                                                                                         new Ast::DynamicExpression( @4, $4 ),
1152                                                                                                                                                                         new Kernel::Environment::LexicalKey * ( 0 ) );
1154 | T_dynamic_state_identifier ':' StateReference %prec T_dynamiccolon
1156         $$ = new Ast::DynamicStateBindingExpression( @1, @1, $1, $3 );
1161 ConstantExceptStrings
1162 : T_int
1164         $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1166 | T_float
1168         $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1170 | T_length
1172         $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1174 | T_bool
1176         $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1178 | '\'' T_identifier
1180         $$ = new Ast::Constant( @$, new Lang::Symbol( $2 ) );
1184 CodeBracket
1185 : '{' Group '}'
1187         $$ = new Ast::CodeBracket( @$, $2 );
1191 GroupElem
1192 : Expr
1194         $$ = $1;        // Explicit upcast avoids bison warning.
1196 | T_identifier ':' Expr
1198         size_t ** pos = new size_t * ( 0 );
1199         $$ = new Ast::DefineVariable( @1, $1, $3, pos );
1201 | T_state_identifier ':' Expr
1203         size_t ** pos = new size_t * ( 0 );
1204         $$ = new Ast::IntroduceState( @1, $1, $3, pos );
1206 | T_state_identifier ';'
1208         size_t ** pos = new size_t * ( 0 );
1209         $$ = new Ast::Freeze( @1, $1, pos );
1211 | T_identifier ':' T_state_identifier ';'
1213         size_t ** posVar = new size_t * ( 0 );
1214         size_t ** posState = new size_t * ( 0 );
1215         $$ = new Ast::DefineVariable( @1, $1, new Ast::Freeze( @3, $3, posState ), posVar );
1217 | T_dynamic T_dynamic_identifier Expr Expr
1219         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3, $4 );
1221 | T_dynamic T_dynamic_identifier Expr T_dynamic Expr
1223         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3,
1224                                                                                                                                                  new Ast::DynamicExpression( @5, $5 ) );
1226 | T_dynamic T_dynamic_state_identifier StateReference
1228         $$ = new Ast::DynamicStateDecl( @$, @2, $2, $3, new size_t * ( 0 ) );
1230 | Expr '.' T_identifier T_llthan InsertionSequence
1232         shapeserror( "MemberInsertionSequence not implemented" );
1233         //      $$ = new Ast::MemberInsertionSequence( @$, $1, $3, $5 );
1235 | '(' '#' Expr ')' '.' T_identifier T_llthan InsertionSequence
1237         shapeserror( "ProtectedMemberInsertionSequence not implemented" );
1238         //      $$ = new Ast::ProtectedMemberInsertionSequence( @$, @2, $3, $6, $8 );
1240 | T_srcLoc
1242         $$ = new Ast::SourceLocationMark( @$ );
1246 InsertionSequence
1247 : Expr
1249         $$ = new std::list< Ast::Expression * >( );
1250         $$->push_back( $1 );
1252 | InsertionSequence T_llthan Expr
1254         $$ = $1;
1255         $$->push_back( $3 );
1259 OneOrMoreGroupElems
1260 : GroupElem
1262         $$ = new list< Ast::Node * >( );
1263         $$->push_back( $1 );
1265 | OneOrMoreGroupElems GroupElem
1267         $$ = $1;
1268         $$->push_back( $2 );
1270 | StateReference T_llthan InsertionSequence
1272         $$ = new list< Ast::Node * >( );
1273         for( std::list< Ast::Expression * >::const_iterator i = $3->begin( ); i != $3->end( ); ++i )
1274                 {
1275                         $$->push_back( new Ast::Insertion( $1, *i ) );
1276                 }
1278 | OneOrMoreGroupElems StateReference T_llthan InsertionSequence
1280         $$ = $1;
1281         for( std::list< Ast::Expression * >::const_iterator i = $4->begin( ); i != $4->end( ); ++i )
1282                 {
1283                         $$->push_back( new Ast::Insertion( $2, *i ) );
1284                 }
1286 | T_splitLeft SplitFormals T_splitRight ':' Expr
1288         $$ = new list< Ast::Node * >( );
1289         size_t ** pos = new size_t * ( 0 );
1291         $5->immediate_ = true;
1292         $$->push_back( new Ast::DefineVariable( @5, $2->newSplitVarId( ), $5, pos ) );
1294         size_t orderedCount = 0;
1296         typedef typeof $2->exprs_ ListType;
1297         for( ListType::iterator i = $2->exprs_.begin( ); i != $2->exprs_.end( ); ++i )
1298                 {
1299                         i->second->setStruct( @5, pos );
1300                         $$->push_back( i->first );
1301                         if( i->second->isOrdered( ) )
1302                                 {
1303                                         ++orderedCount;
1304                                 }
1305                 }
1307         if( $2->sinkDefine_ != 0 )
1308                 {
1309                         $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1310                         $$->push_back( $2->sinkDefine_ );
1311                 }
1312         else
1313                 {
1314                         $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
1315                 }
1317 | T_splitLeft SplitFormals T_splitRight Expr
1319         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1320         $$ = new list< Ast::Node * >( );
1321         $$->push_back( new Ast::ErrorExpression( @$ ) );
1323 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight ':' Expr
1325         $$ = $1;
1326         size_t ** pos = new size_t * ( 0 );
1328         $6->immediate_ = true;
1329         $$->push_back( new Ast::DefineVariable( @6, $3->newSplitVarId( ), $6, pos ) );
1331         size_t orderedCount = 0;
1333         typedef typeof $3->exprs_ ListType;
1334         for( ListType::iterator i = $3->exprs_.begin( ); i != $3->exprs_.end( ); ++i )
1335                 {
1336                         i->second->setStruct( @6, pos );
1337                         $$->push_back( i->first );
1338                         if( i->second->isOrdered( ) )
1339                                 {
1340                                         ++orderedCount;
1341                                 }
1342                 }
1344         if( $3->sinkDefine_ != 0 )
1345                 {
1346                         $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1347                         $$->push_back( $3->sinkDefine_ );
1348                 }
1349         else
1350                 {
1351                         $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1352                 }
1354 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1356         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1357         $$ = $1;
1358         $$->push_back( new Ast::ErrorExpression( @$ ) );
1362 Group
1365         $$ = new list< Ast::Node * >( );
1367 | OneOrMoreGroupElems
1371 SuperMemberReference
1372 : '(' '#' Expr ')' '.' T_identifier
1374         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1375         Ast::ProtectedMemberReferenceFunction * res = new Ast::ProtectedMemberReferenceFunction( @$, @2, $3, @6, $6 );
1376         res->push_exprs( args );
1377         $$ = new Ast::CallExpr( @$,
1378                                                                                                         RefCountPtr< const Lang::Function >( res ),
1379                                                                                                         args );
1384 MethodIdentifier
1385 : T_identifier '#' T_identifier
1387         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1388         $$ = new Ast::MethodIdExpr( @$, new Ast::LexiographicVariable( @1, $1, key ), $3 );
1393 SuperCall
1394 : '[' '(' '#' Expr ')' '.' MethodIdentifier ArgList ']'
1396         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1397         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, $4, $7 );
1398         res->push_exprs( args );
1399         $$ = new Ast::CallExpr( @$,
1400                                                                                                         new Ast::CallExpr( @3,
1401                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1402                                                                                                                                                                                  args ),
1403                                                                                                         $8 );
1405 | '[' '(' '#' ')' '.' MethodIdentifier ArgList ']'
1407         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1408         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, 0, $6 );
1409         res->push_exprs( args );
1410         $$ = new Ast::CallExpr( @$,
1411                                                                                                         new Ast::CallExpr( @3,
1412                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1413                                                                                                                                                                                  args ),
1414                                                                                                         $7 );
1419 Class
1420 : '[' T_class '(' Expr Formals ')' T_identifier '(' ListOfParentsWithInitargs ')'
1421         ClassModeList
1422         ClassSections
1423         ']'
1425         DeleteOnExit< char > isaDeleter( $7 );
1426         if( strcmp( $7, "isa" ) != 0 )
1427                 {
1428                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1429                 }
1430         if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1431                 {
1432                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
1433                 }
1435         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1436         Ast::ClassFunction * res = new Ast::ClassFunction( @$, $4, $5, $9, $11, $12 );
1437         res->push_exprs( args );
1438         $$ = new Ast::CallExpr( @$,
1439                                                                                                         RefCountPtr< const Lang::Function >( res ),
1440                                                                                                         args );
1444 ListOfParentsWithInitargs
1445 : '(' Expr ArgList ')'
1447         $$ = new std::list< const Ast::CallExpr * >;
1448         $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1450 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1452         $$ = $1;
1453         $$->push_back( new Ast::CallExpr( Ast::SourceLocation( @2, @5 ), $3, $4 ) );
1457 ClassModeList
1460         $$ = 0;
1462 | OneOrMoreClassModeSpecifiers
1465 OneOrMoreClassModeSpecifiers
1466 : ClassModeSpecifier
1467 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1469         $$ = $1 | $2;
1473 ClassModeSpecifier
1474 : T_identifier
1476         DeleteOnExit< char > strDeleter( $1 );
1477         $$ = 0;
1478         if( strcmp( $1, "abstract" ) == 0 )
1479                 {
1480                         $$ = Ast::CLASS_MODE_ABSTRACT;
1481                 }
1482         else if( strcmp( $1, "final" ) == 0 )
1483                 {
1484                         $$ = Ast::CLASS_MODE_FINAL;
1485                 }
1486         else
1487                 {
1488                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1489                 }
1493 ClassSections
1496         $$ = new std::list< Ast::ClassSection * >;
1498 | OneOrMoreClassSections
1501 OneOrMoreClassSections
1502 : ClassSection
1504         $$ = new std::list< Ast::ClassSection * >;
1505         $$->push_back( $1 );
1507 | OneOrMoreClassSections ClassSection
1509         $$ = $1;
1510         $$->push_back( $2 );
1514 ClassSection
1515 : '(' T_members MemberDeclarations ')'
1517         $$ = $3;
1519 | '(' T_prepare Group ')'
1521         $$ = new Ast::PrepareSection( @$, $3 );
1523 | '(' T_identifier MethodDeclarations ')'
1525         DeleteOnExit< char > accessSpecDeleter( $2 );
1526         unsigned int accessSpec = 0;
1527         if( strcmp( $2, "__methods__" ) == 0    )
1528                 {
1529                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1530                 }
1531         else if( strcmp( $2, "__abstract__" ) == 0      )
1532                 {
1533                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1534                 }
1535         else if( strcmp( $2, "__final__" ) == 0 )
1536                 {
1537                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1538                 }
1539         else if( strcmp( $2, "__protected__" ) == 0 )
1540                 {
1541                         accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1542                 }
1543         else if( strcmp( $2, "__private__" ) == 0 )
1544                 {
1545                         /* OK, no change */
1546                 }
1547         else
1548                 {
1549                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1550                 }
1551         $3->addModeBits( accessSpec );
1552         $$ = $3;
1554 | '(' T_abstract OrderedFormals ')'
1556         $$ = new Ast::AbstractSection( @$, $3 );
1558 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1560         $$ = new Ast::OverridesSection( $3, $5 );
1564 MemberDeclarations
1567         $$ = new Ast::MemberSection;
1569 | OneOrMoreMemberDeclarations
1572 OneOrMoreMemberDeclarations
1573 : MemberDeclaration
1575         $$ = new Ast::MemberSection;
1576         $$->push_back( $1 );
1578 | OneOrMoreMemberDeclarations MemberDeclaration
1580         $$ = $1;
1581         $$->push_back( $2 );
1585 MemberDeclaration
1586 : '(' T_identifier Expr ')'
1588         $$ = new Ast::MemberDeclaration( @$, $2, $3, 0 );
1590 | '(' T_identifier Expr MemberAccessList ')'
1592         $$ = new Ast::MemberDeclaration( @$, $2, $3, $4 );
1596 MemberAccessList
1597 : MemberAccessSpecifier
1598 | MemberAccessList MemberAccessSpecifier
1600         $$ = $1 | $2;
1604 MemberAccessSpecifier
1605 : '.'
1607         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1609 | T_llthan
1611         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1613 | '(' '#' '.' ')'
1615         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1617 | '(' '#' T_llthan ')'
1619         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1621 | '^'
1623         $$ = Ast::MEMBER_TRANSFORMING;
1627 MethodDeclarations
1630         $$ = new Ast::MemberSection;
1632 | OneOrMoreMethodDeclarations
1635 OneOrMoreMethodDeclarations
1636 : MethodDeclaration
1638         $$ = new Ast::MemberSection;
1639         $$->push_back( $1 );
1641 | OneOrMoreMethodDeclarations MethodDeclaration
1643         $$ = $1;
1644         $$->push_back( $2 );
1648 MethodDeclaration
1649 : '(' T_identifier Expr ')'
1651         $$ = new Ast::MemberDeclaration( @$, $2, $3, Ast::MEMBER_CONST | Ast::MEMBER_METHOD );
1653 | '(' '[' T_identifier Formals ']' FunctionModeList GroupElem ')'
1655         Ast::Expression * body = dynamic_cast< Ast::Expression * >( $7 );
1656         if( body == 0 )
1657                 {
1658                         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1659                         bracket->push_back( $7 );
1660                         body = new Ast::CodeBracket( @7, bracket );
1661                 }
1662         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1663         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $4, body, $6 );
1664         res->push_exprs( args );
1665         $$ = new Ast::MemberDeclaration( @$, $3, new Ast::CallExpr( @$,
1666                                                                                                                                                                                                                                                         RefCountPtr< const Lang::Function >( res ),
1667                                                                                                                                                                                                                                                         args ),
1668                                                                                                                                          Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1672 FunctionModeList
1675         $$ = 0;
1677 | OneOrMoreFunctionModeSpecifiers
1680 OneOrMoreFunctionModeSpecifiers
1681 : FunctionModeSpecifier
1682 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1684         $$ = $1 | $2;
1688 FunctionModeSpecifier
1689 : '^'
1691         $$ = Ast::FUNCTION_TRANSFORMING;
1695 Split
1696 : T_split Expr
1698         $$ = $2;
1704 /* The closing %% above marks the end of the Rules section and the beginning
1705  * of the User Subroutines section. All text from here to the end of the
1706  * file is copied verbatim to the end of the generated y.tab.c file.
1707  * This section is where you put definitions of helper functions.
1708  */