Adjust to updated function signature in libpng.
[shapes.git] / source / shapesparser.yy
blobcb7799378a3c24e56be7478cde5558e7b52b754f
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, 2010 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         uint32_t uintVal;
123         double floatVal;
124         bool boolVal;
125         char * char_p;
126         int tokenID;
127         Lang::String * Lang_String;
128         std::list< const Ast::CallExpr * > * callExprList;
129         std::list< Ast::ClassSection * > * classSectionList;
130         Ast::ClassSection * classSection;
131         Ast::MemberSection * memberSection;
132         Ast::MemberDeclaration * memberDeclaration;
133         Ast::StateReference * stateReference;
134         Ast::MemberMode memberMode;
135         Ast::ClassMode classMode;
136         Ast::FunctionMode functionMode;
137         void * nothing;
141 /* Tokens
142  * ------
143  * Here we tell yacc about all the token types that we are using.
144  * Yacc will assign unique numbers to these and export the #define
145  * in the generated y.tab.h header file.
146  */
148 %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
149 %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
150 %token <tokenID> T_indexof T_depthof T_variableName T_dynamic T_continuation T_continue T_esc_continuation T_esc_continue T_esc_backtrace T_last
151 %token <tokenID> T_class T_members T_prepare T_abstract T_overrides T_gr__
152 %token <tokenID> T_split T_splitLeft T_splitRight T_unionLeft T_unionRight T_absLeft T_absRight
153 %token <tokenID> T_srcLoc
154 %token <tokenID> T_interactiveMark
156 %token <intVal> T_int
157 %token <uintVal> T_char
158 %token <floatVal> T_float T_length
159 %token <expr> T_speciallength
160 %token <boolVal> T_bool
161 %token <char_p> T_identifier_except_tex T_identifier_tex T_dynamic_identifier T_state_identifier T_dynamic_state_identifier T_symbol T_typename
162 %token <Lang_String> T_string
164 /* Non-terminal types
165  * ------------------
166  * In order for yacc to assign/access the correct field of $$, $1, we
167  * must to declare which field is appropriate for the non-terminal.
168  * As an example, this first type declaration establishes that the DeclList
169  * non-terminal uses the field named "declList" in the yylval union. This
170  * means that when we are setting $$ for a reduction for DeclList ore reading
171  * $n which corresponds to a DeclList nonterminal we are accessing the field
172  * of the union named "declList" which is of type List<Decl*>.
173  * pp2: You'll need to add many of these of your own.
174  */
176 %type <expr> Program Expr ExprExceptConstStrings ConstantExceptStrings
177 %type <expr> DynamicBinding CallExpr CurryCallExpr MutateExpr MutatorCallbackExpr Function OperatorFunction Class Coords PolarHandle
178 %type <expr> CodeBracket SuperCall SuperMemberReference
179 %type <exprList> InsertionSequence
180 %type <node> GroupElem
181 %type <nodeList> Group OneOrMoreGroupElems
182 %type <strList> OrderedFormals OneOrMoreOrderedFormals
183 %type <formals> Formals OneOrMoreFormalsItems
184  //                                     %type <formalsList> NamedFormalsWithOrder OneOrMoreNamedFormalsWithOrder
185 %type <argList> ArgList OneOrMoreArgListItems
186 %type <methodId> MethodIdentifier
187 %type <callExprList> ListOfParentsWithInitargs;
188 %type <classSectionList> ClassSections OneOrMoreClassSections
189 %type <classSection> ClassSection
190 %type <memberSection> MemberDeclarations OneOrMoreMemberDeclarations
191 %type <memberSection> MethodDeclarations OneOrMoreMethodDeclarations
192 %type <memberDeclaration> MemberDeclaration MethodDeclaration
193 %type <memberMode> MemberAccessList MemberAccessSpecifier
194 %type <classMode> ClassModeList ClassModeSpecifier OneOrMoreClassModeSpecifiers
195 %type <functionMode> FunctionModeList OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
196 %type <expr> Split
197 %type <stateReference> StateReference
198 %type <splitFormals> SplitFormals OneOrMoreSplitFormals
199 %type <char_p> Identifier
201 %nonassoc T_assign ':'
203 %left T_llthan
204 %nonassoc '!'
206 %nonassoc T_mapsto
207 %right '|'
208 %left T_emptybrackets T_dddotbrackets T_ggthan
210 %left T_ampersandMore
211 %left '&'
212 %nonassoc T_dynamiccolon
214 %left T_or
215 %nonassoc T_xor
216 %left T_and
217 %left T_not
218 %nonassoc T_eqeq T_eqneq T_lesseq T_greatereq
220 %left T_plusplus T_minusminus
221 %left '<' '>'
223 %left '+' '-'
224 %nonassoc T_angle
225 %left '*' '/' T_projection
226 %left '~'
228 %left T_compose
230 %left '.'
231 %left '#'
232 %left T_split
233 %left T_atat T_surrounding
235 %left ','
237 %start Program
239 %name-prefix="shapes"
243  * All productions and actions should be placed between the start and stop
244  * %% markers which delimit the Rules section.
245  */
247 Program
248 : Group T_preludesep Group T_EOF
250         /* Note that the source location of the prelude is discarded. */
251         $1->push_back( new Ast::CodeBracket( @3, $3 ) );
252         $$ = new Ast::CodeBracket( @3, $1 );
253         Ast::theProgram = $$;
254         YYACCEPT;
256 | T_interactiveMark Group T_EOF
258         Ast::theInteractiveInput = $2;
259         YYACCEPT;
261 | Group error
263         shapeserror( "Expecting end of file." );
268 Coords
269 : '(' Expr ',' Expr ')'
271         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
272         args->orderedExprs_->push_back( $2 );
273         args->orderedExprs_->push_back( $4 );
274         $$ = new Ast::CallExpr( @$,
275                                                                                                         Ast::THE_FUNCTION_coords2D,
276                                                                                                         args );
278 | '(' Expr ',' Expr '^' Expr ')'
280         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
281         args->orderedExprs_->push_back( $2 );
282         args->orderedExprs_->push_back( $4 );
283         args->orderedExprs_->push_back( $6 );
284         $$ = new Ast::CallExpr( @$,
285                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
286                                                                                                         args );
288 | '(' Expr ',' Expr '^' ')'
290         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
291         args->orderedExprs_->push_back( $2 );
292         args->orderedExprs_->push_back( $4 );
293         $$ = new Ast::CallExpr( @$,
294                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
295                                                                                                         args );
297 | '(' Expr ',' Expr ',' Expr ')'
299         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
300         args->orderedExprs_->push_back( $2 );
301         args->orderedExprs_->push_back( $4 );
302         args->orderedExprs_->push_back( $6 );
303         $$ = new Ast::CallExpr( @$,
304                                                                                                         Ast::THE_FUNCTION_coords3D,
305                                                                                                         args );
310 PolarHandle
311 : '(' Expr '^' Expr ')'
313         $$ = new Ast::PolarHandle2DExpr( @$, $2, $4 );
315 | '(' Expr '^' ')'
317         $$ = new Ast::PolarHandle2DExprFree_a( @$, $2 );
319 | '(' '^' Expr ')'
321         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
322         args->orderedExprs_->push_back( $3 );
323         $$ = new Ast::CallExpr( @$,
324                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_r,
325                                                                                                         args );
327 | '(' '^' ')'
329         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
330         $$ = new Ast::CallExpr( @$,
331                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_ra,
332                                                                                                         args );
336 StateReference
337 : T_state_identifier
339         $$ = new Ast::LexiographicState( @1, $1, new Kernel::Environment::LexicalKey * ( 0 ) );
341 | T_dynamic_state_identifier
343         $$ = new Ast::DynamicState( @1, $1 );
347 ArgList
350         $$ = new Ast::ArgListExprs( true );
352 | OneOrMoreArgListItems
355 OneOrMoreArgListItems
356 : Expr
358         $$ = new Ast::ArgListExprs( true );
359         $$->orderedExprs_->push_back( $1 );
361 | StateReference
363         $$ = new Ast::ArgListExprs( true );
364         $$->orderedStates_->push_back( $1 );
366 | Identifier ':' Expr
368         $$ = new Ast::ArgListExprs( true );
369         (*$$->namedExprs_)[ $1 ] = $3;
371 | T_state_identifier ':' StateReference
373         $$ = new Ast::ArgListExprs( true );
374         (*$$->namedStates_)[ $1 ] = $3;
376 | OneOrMoreArgListItems Expr
378         $$ = $1;
379         if( ! $$->namedExprs_->empty( ) )
380                 {
381                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed expressions may not appear among named expressions." ) ) );
382                 }
383         $$->orderedExprs_->push_back( $2 );
385 | OneOrMoreArgListItems StateReference
387         $$ = $1;
388         if( ! $$->namedStates_->empty( ) )
389                 {
390                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed states may not appear among named states." ) ) );
391                 }
392         $$->orderedStates_->push_back( $2 );
394 | OneOrMoreArgListItems Identifier ':' Expr
396         $$ = $1;
397         if( $$->namedExprs_->find( $2 ) != $$->namedExprs_->end( ) )
398                 {
399                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
400                 }
401         (*$$->namedExprs_)[ $2 ] = $4;
403 | OneOrMoreArgListItems T_state_identifier ':' StateReference
405         $$ = $1;
406         if( $$->namedStates_->find( $2 ) != $$->namedStates_->end( ) )
407                 {
408                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
409                 }
410         (*$$->namedStates_)[ $2 ] = $4;
415 CallExpr
416 : '[' Expr ArgList ']'
418         $$ = new Ast::CallExpr( @$, $2, $3 );
420 | Expr T_emptybrackets Expr
422         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
423         args->orderedExprs_->push_back( $3 );
424         $$ = new Ast::CallExpr( @$,
425                                                                                                         $1,
426                                                                                                         args );
428 | Expr T_ggthan Expr
430         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
431         args->orderedExprs_->push_back( $1 );
432         $$ = new Ast::CallExpr( @$,
433                                                                                                         $3,
434                                                                                                         args );
436 | Expr T_emptybrackets Split
438         $$ = new Ast::CallSplitExpr( @$,
439                                                                                                                          $1,
440                                                                                                                          $3 );
442 | Expr T_dddotbrackets Expr
444         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
445         args->orderedExprs_->push_back( $3 );
446         $$ = new Ast::CallExpr( @$,
447                                                                                                         $1,
448                                                                                                         args,
449                                                                                                         true ); /* true means Curry */
451 | Expr T_dddotbrackets Identifier ':' Expr %prec T_dynamiccolon
453         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
454         (*args->namedExprs_)[ $3 ] = $5;
455         $$ = new Ast::CallExpr( @$,
456                                                                                                         $1,
457                                                                                                         args,
458                                                                                                         true ); /* true means Curry */
460 | Expr T_dddotbrackets Split
462         $$ = new Ast::CallSplitExpr( @$,
463                                                                                                                          $1,
464                                                                                                                          $3,
465                                                                                                                          true );        /* true means Curry */
470 CurryCallExpr
471 : '[' Expr ArgList T_dddot ']'
473         $$ = new Ast::CallExpr( @$, $2, $3, true ); /* true means Curry */
475 | '(' MutatorCallbackExpr ')'
477   $$ = $2;
481 MutatorCallbackExpr
482 : '.' '[' Identifier ArgList ']'
484         Kernel::Formals * stateFormal = new Kernel::Formals( );
485         stateFormal->stateOrder_->insert( std::pair< const char *, size_t >( Kernel::MUTATOR_CURRY_VAR_ID, stateFormal->stateOrder_->size( ) ) );
486         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
487         Ast::StateReference * stateref = new Ast::LexiographicState( @2, strdup( Kernel::MUTATOR_CURRY_VAR_ID ), new Kernel::Environment::LexicalKey * ( 0 ) );
488         Ast::CallExpr * body =
489                 new Ast::CallExpr( @$,
490                                                                                          new Ast::MutatorReference( @1, stateref, $3 ),
491                                                                                          $4 );
492         body->setMutatorSelf( stateref );
493         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, stateFormal, body, 0 );
494         res->push_exprs( args );
495         $$ = new Ast::CallExpr( @$,
496                                                                                                         RefCountPtr< const Lang::Function >( res ),
497                                                                                                         args );
501 MutateExpr
502 : StateReference '.' '[' Identifier ArgList ']'
504         Ast::CallExpr * res =
505                 new Ast::CallExpr( @$,
506                                                                                          new Ast::MutatorReference( @4, $1, $4 ),
507                                                                                          $5 );
508         res->setMutatorSelf( $1 );
509         $$ = res;
513 Formals
516         $$ = new Kernel::Formals( );
517         $$->setLoc( @$ );
519 | T_split Identifier
521         $$ = new Kernel::Formals( );
522         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
523         /* Note that we do not push a default expression (not even a null pointer) for the sink.
524          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
525          * The default value for the sink is taken care of in a non-standard way anyway.
526          */
527         $$->setLoc( @$ );
528         $$->sink_ = $2;
530 | OneOrMoreFormalsItems
532         $$ = $1;
533         $$->setLoc( @$ );
535 | OneOrMoreFormalsItems T_split Identifier
537         $$ = $1;
538         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $3, $$->defaultExprs_.size( ) ) );
539         /* Note that we do not push a default expression (not even a null pointer) for the sink.
540          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
541          * The default value for the sink is taken care of in a non-standard way anyway.
542          */
543         $$->setLoc( @$ );
544         $$->sink_ = $3;
548 OneOrMoreFormalsItems
549 : Identifier
551         $$ = new Kernel::Formals( );
552         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
553         $$->defaultExprs_.push_back( 0 );
555 | Identifier ':' Expr
557         $$ = new Kernel::Formals( );
558         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $1, $$->defaultExprs_.size( ) ) );
559         $$->defaultExprs_.push_back( $3 );
561 | T_state_identifier
563         $$ = new Kernel::Formals( );
564         $$->stateOrder_->insert( std::pair< const char *, size_t >( $1, $$->stateOrder_->size( ) ) );
566 | OneOrMoreFormalsItems Identifier
568         $$ = $1;
569         if( $$->seenDefault_ )
570                 {
571                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
572                 }
573         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
574                 {
575                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
576                 }
577         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
578         $$->defaultExprs_.push_back( 0 );
580 | OneOrMoreFormalsItems Identifier ':' Expr
582         $$ = $1;
583         $$->seenDefault_ = true;
584         if( $$->argumentOrder_->find( $2 ) != $$->argumentOrder_->end( ) )
585                 {
586                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
587                 }
588         $$->argumentOrder_->insert( std::pair< const char *, size_t >( $2, $$->defaultExprs_.size( ) ) );
589         $$->defaultExprs_.push_back( $4 );
591 | OneOrMoreFormalsItems T_state_identifier
593         $$ = $1;
594         if( $$->stateOrder_->find( $2 ) != $$->stateOrder_->end( ) )
595                 {
596                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, $2 ) );
597                 }
598         $$->stateOrder_->insert( std::pair< const char *, size_t >( $2, $$->stateOrder_->size( ) ) );
603 SplitFormals
606         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "The list of split assignment variables must not be empty." ) ) );
607         $$ = new Ast::SplitDefineVariables( );
609 | T_split Identifier
611         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "Just a sink in a split assignment formals list makes no sense." ) ) );
612         $$ = new Ast::SplitDefineVariables( );
614 | OneOrMoreSplitFormals
616         $$ = $1;
618 | OneOrMoreSplitFormals T_split Identifier
620         $$ = $1;
621         Ast::StructSplitSink * expr = new Ast::StructSplitSink( );
622         size_t ** pos = new size_t * ( 0 );
623         $$->sinkDefine_ = new Ast::DefineVariable( @3, $3, expr, pos );
624         $$->sinkExpr_ = expr;
628 OneOrMoreSplitFormals
629 : Identifier
631         $$ = new Ast::SplitDefineVariables( );
632         typedef typeof $$->exprs_ ListType;
633         size_t ** pos = new size_t * ( 0 );
634         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), 0 );
635         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
636                                                                                                                                                                                          ref ) );
638 | Identifier ':' Expr
640         $$ = new Ast::SplitDefineVariables( );
641         typedef typeof $$->exprs_ ListType;
642         size_t ** pos = new size_t * ( 0 );
643         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), $3 );
644         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
645                                                                                                                                                                                          ref ) );
647 | Identifier ':' '.' Identifier
649         $$ = new Ast::SplitDefineVariables( );
650         typedef typeof $$->exprs_ ListType;
651         size_t ** pos = new size_t * ( 0 );
652         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, 0 );
653         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
654                                                                                                                                                                                          ref ) );
656 | Identifier ':' '.' Identifier ':' Expr
658         $$ = new Ast::SplitDefineVariables( );
659         typedef typeof $$->exprs_ ListType;
660         size_t ** pos = new size_t * ( 0 );
661         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, $4, $6 );
662         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
663                                                                                                                                                                                          ref ) );
665 | Identifier ':' '.' '\"'
667         $$ = new Ast::SplitDefineVariables( );
668         typedef typeof $$->exprs_ ListType;
669         size_t ** pos = new size_t * ( 0 );
670         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), 0 );
671         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
672                                                                                                                                                                                          ref ) );
674 | Identifier ':' '.' '\"' ':' Expr
676         $$ = new Ast::SplitDefineVariables( );
677         typedef typeof $$->exprs_ ListType;
678         size_t ** pos = new size_t * ( 0 );
679         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( $1 ), $6 );
680         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, $1, ref, pos ),
681                                                                                                                                                                                          ref ) );
683 | OneOrMoreSplitFormals Identifier
685         $$ = $1;
686         if( $$->seenNamed_ )
687                 {
688                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
689                 }
690         if( $$->seenDefault_ )
691                 {
692                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "All order-based formals without default values must be placed before those with default values." ) ) );
693                 }
694         typedef typeof $$->exprs_ ListType;
695         size_t ** pos = new size_t * ( 0 );
696         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), 0 );
697         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
698                                                                                                                                                                                          ref ) );
700 | OneOrMoreSplitFormals Identifier ':' Expr
702         $$ = $1;
703         if( $$->seenNamed_ )
704                 {
705                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
706                 }
707         $$->seenDefault_ = true;
708         typedef typeof $$->exprs_ ListType;
709         size_t ** pos = new size_t * ( 0 );
710         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), $4 );
711         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
712                                                                                                                                                                                          ref ) );
714 | OneOrMoreSplitFormals Identifier ':' '.' Identifier
716         $$ = $1;
717         $$->seenNamed_ = true;
718         typedef typeof $$->exprs_ ListType;
719         size_t ** pos = new size_t * ( 0 );
720         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, 0 );
721         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
722                                                                                                                                                                                          ref ) );
724 | OneOrMoreSplitFormals Identifier ':' '.' Identifier ':' Expr
726         $$ = $1;
727         $$->seenNamed_ = true;
728         typedef typeof $$->exprs_ ListType;
729         size_t ** pos = new size_t * ( 0 );
730         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, $5, $7 );
731         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
732                                                                                                                                                                                          ref ) );
734 | OneOrMoreSplitFormals Identifier ':' '.' '\"'
736         $$ = $1;
737         $$->seenNamed_ = true;
738         typedef typeof $$->exprs_ ListType;
739         size_t ** pos = new size_t * ( 0 );
740         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), 0 );
741         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
742                                                                                                                                                                                          ref ) );
744 | OneOrMoreSplitFormals Identifier ':' '.' '\"' ':' Expr
746         $$ = $1;
747         $$->seenNamed_ = true;
748         typedef typeof $$->exprs_ ListType;
749         size_t ** pos = new size_t * ( 0 );
750         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( $2 ), $7 );
751         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, $2, ref, pos ),
752                                                                                                                                                                                          ref ) );
757 Function
758 : '\\' Formals T_mapsto FunctionModeList Expr
760         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
761         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $2, $5, $4 );
762         res->push_exprs( args );
763         $$ = new Ast::CallExpr( @$,
764                                                                                                         RefCountPtr< const Lang::Function >( res ),
765                                                                                                         args );
767 | '(' OperatorFunction ')'
769         $$ = $2;
773 OrderedFormals
776         $$ = new list< RefCountPtr< const char > >( );
778 | OneOrMoreOrderedFormals
781 OneOrMoreOrderedFormals
782 : Identifier
784         $$ = new list< RefCountPtr< const char > >( );
785         $$->push_back( strrefdup( $1 ) );
787 | OneOrMoreOrderedFormals Identifier
789         $$ = $1;
790         $$->push_back( strrefdup( $2 ) );
794 OperatorFunction
795 : T_minusminus
797         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUSMINUS ) );
799 | T_plusplus
801         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUSPLUS ) );
803 | '&'
805         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND ) );
807 | '+'
809         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUS ) );
811 | '-'
813         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUS ) );
815 | '*'
817         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_STAR ) );
819 | '/'
821         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_SLASH ) );
823 | T_projection
825         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PROJECTION ) );
827 | T_angle
829         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_ANGLE ) );
831 | T_ampersandMore
833         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND_MORE ) );
835 | '~'
837         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NEG ) );
839 | T_compose
841         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_COMPOSE ) );
843 | '<'
845         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
847 | '>'
849         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
851 | T_eqeq
853         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQEQ ) );
855 | T_eqneq
857         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQNEQ ) );
859 | T_lesseq
861         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
863 | T_greatereq
865         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
867 | T_not
869         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NOT ) );
871 | T_and
873         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_AND ) );
875 | T_or
877         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_OR ) );
879 | T_xor
881         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_XOR ) );
885 Expr
886 : ExprExceptConstStrings
887 | T_string
889         $$ = new Ast::Constant( @1, $1 );
893 ExprExceptConstStrings
894 : ConstantExceptStrings
895 | Coords
896 | PolarHandle
897 | '(' T_identifier_tex ExprExceptConstStrings ')'
899         Interaction::warn_or_push( new Exceptions::ParserError( @2, strrefdup( "The special form TeX is deprecated.  \"TeX\" is now an ordinary variable, and shall be called like a function, [TeX <expr>]." ), true ),
900                                                                                                                  & Ast::theAnalysisErrorsList );
901         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
902         args->orderedExprs_->push_back( $3 );
903         $$ = new Ast::CallExpr( @$,
904                                                                                                         Ast::THE_FUNCTION_TeX,
905                                                                                                         args );
907 | '(' T_identifier_tex T_string ')'
909         Interaction::warn_or_push( new Exceptions::ParserError( @2, strrefdup( "The special form TeX is deprecated.  \"TeX\" is now an ordinary variable, and shall be called like a function, [TeX <expr>]." ), true ),
910                                                                                                                  & Ast::theAnalysisErrorsList );
911         Kernel::theTeXLabelManager.announce( std::string( $3->val_.getPtr( ) ), @3 );
912         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
913         args->orderedExprs_->push_back( new Ast::Constant( @3, $3 ) );
914         $$ = new Ast::CallExpr( @$,
915                                                                                                         Ast::THE_FUNCTION_TeX,
916                                                                                                         args );
918 | '!' Expr
920         $$ = $2;
921         $$->immediate_ = true;
923 | CallExpr
924 | CurryCallExpr
925 | SuperCall
926 | SuperMemberReference
927 | T_speciallength
928 | '(' Expr ')'
930         $$ = $2;
932 | '(' '-' Expr ')'
934         $$ = new Ast::NegExpr( @$, @2, $3 );
936 | '(' '+' Expr ')'
938         $$ = new Ast::RelativeExpr( @$, @2, $3 );
940 | '(' ')'
942         $$ = new Ast::EmptyExpression( @$ );
944 | '(' Expr T_llthan InsertionSequence ')'
946         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
948         size_t ** pos = new size_t * ( 0 );
949         Ast::StateReference * dst = new Ast::LexiographicState( @2, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), new Kernel::Environment::LexicalKey * ( 0 ) );
951         bracket->push_back( new Ast::IntroduceState( @3,
952                                                                                                                                                                                          strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ),
953                                                                                                                                                                                          $2,
954                                                                                                                                                                                          pos ) );
955         for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
956                 {
957                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
958                         if( mutExpr != 0 )
959                                 {
960                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
961                                         args->orderedStates_->push_back( dst );
962                                         Ast::CallExpr * call =
963                                                 new Ast::CallExpr( mutExpr->loc( ),
964                                                                                                                          mutExpr->getExpr( ),
965                                                                                                                          args );
966                                         delete *i;
967                                         *i = 0;
968                                         bracket->push_back( call );
969                                 }
970                         else
971                                 {
972                                         bracket->push_back( new Ast::Insertion( dst, *i ) );
973                                 }
974                 }
975         bracket->push_back( new Ast::Freeze( @3, strdup( Kernel::SEQUENTIAL_EXPR_VAR_ID ), pos ) );
976         $$ = new Ast::CodeBracket( @$, bracket );
978 | T_surrounding Expr
980         $$ = new Ast::EvalOutsideExpr( @$, $2 );
982 | CodeBracket
983 | Function
984 | Class
985 | Identifier
987         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
988         $$ = new Ast::LexiographicVariable( @$, $1, key );
990 | T_atat Expr
992         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
993         Ast::EvalSymbolFunction * res = new Ast::EvalSymbolFunction( @$, $2 );
994         res->push_exprs( args );
995         $$ = new Ast::CallExpr( @$,
996                                                                                                         RefCountPtr< const Lang::Function >( res ),
997                                                                                                         args );
999 | T_dynamic_identifier
1001         $$ = new Ast::DynamicVariable( @$, $1 );
1003 | '(' StateReference ')'
1005         $$ = new Ast::Peek( @$, $2 );
1007 | MutateExpr
1008 | Expr '.' Identifier
1010         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1011         Ast::MemberReferenceFunction * res = new Ast::MemberReferenceFunction( @$, $1, $3 );
1012         res->push_exprs( args );
1013         $$ = new Ast::CallExpr( @$,
1014                                                                                                         RefCountPtr< const Lang::Function >( res ),
1015                                                                                                         args );
1017 | DynamicBinding
1018 | '(' T_esc_continuation Identifier Expr ')'
1020         $$ = new Ast::LetDynamicECExpr( @$, @3, $3, $4 );
1022 | '(' T_esc_continue Identifier Expr ')'
1024         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1025         Ast::ContinueDynamicECFunction * res = new Ast::ContinueDynamicECFunction( @3, $3, $4 );
1026         res->push_exprs( args );
1027         $$ = new Ast::CallExpr( @$,
1028                                                                                                         RefCountPtr< const Lang::Function >( res ),
1029                                                                                                         args );
1030         /* This used to be immediate, but right now that seems utterly wrong!
1031          * Imagine choosing between two continuations; then both continuations would require invokation before being "passed" to the <if> function.
1032          * 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
1033          * knowing when they will be forced...  But I don't think there's a choice here anyway; this expression can't be immediate.
1034          */
1036 | '(' T_esc_backtrace Identifier ')'
1038         $$ = new Ast::GetECBacktraceExpr( @3, $3 );
1040 | '(' T_indexof Identifier ')'
1042         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::INDEX );
1044 | '(' T_depthof Identifier ')'
1046         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::DEPTH );
1048 | T_variableName
1050         $$ = new Ast::LexicalVariableNameExpr( @1 );
1052 | T_absLeft Expr T_absRight
1054         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1055         args->orderedExprs_->push_back( $2 );
1056         $$ = new Ast::CallExpr( @$,
1057                                                                                                         Lang::THE_FUNCTION_ABS,
1058                                                                                                         args );
1060 | Expr '|' Expr
1062         $$ = new Ast::WithDynamicExpr( @$, $1, $3 );
1064 | T_unionLeft ArgList T_unionRight
1066         $$ = new Ast::UnionExpr( @$, $2 );
1068 | Expr T_minusminus T_cycle
1070         $$ = new Ast::CycleExpr( @3, $1 );
1072 | Expr T_minusminus Expr
1074         $$ = new Ast::MinusMinusExpr( @2, $1, $3 );
1076 | Expr T_plusplus Expr
1078         $$ = new Ast::PlusPlusExpr( @2, $1, $3 );
1080 | Expr '&' Expr
1082         $$ = new Ast::AmpersandExpr( @2, $1, $3 );
1084 | Expr '+' Expr
1086         $$ = new Ast::PlusExpr( @2, $1, $3 );
1088 | Expr '-' Expr
1090         $$ = new Ast::MinusExpr( @2, $1, $3 );
1092 | Expr T_angle Expr
1094         $$ = new Ast::AngleExpr( @2, $1, $3 );
1096 | Expr T_ampersandMore Expr
1098         $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1100 | Expr '*' Expr
1102         $$ = new Ast::StarExpr( @2, $1, $3 );
1104 | Expr T_projection Expr
1106         $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1108 | Expr '/' Expr
1110         $$ = new Ast::SlashExpr( @2, $1, $3 );
1112 | '~' Expr
1114         $$ = new Ast::NegExpr( @1, $2 );
1116 | Expr T_compose Expr
1118         $$ = new Ast::ComposeExpr( @2, $1, $3 );
1120 | Expr '<' Expr
1122         $$ = new Ast::LessExpr( @2, $1, $3 );
1124 | Expr '>' Expr
1126         $$ = new Ast::GreaterExpr( @2, $1, $3 );
1128 | Expr T_eqeq Expr
1130         $$ = new Ast::EqualExpr( @2, $1, $3 );
1132 | Expr T_eqneq Expr
1134         $$ = new Ast::NotEqualExpr( @2, $1, $3 );
1136 | Expr T_lesseq Expr
1138         $$ = new Ast::LessEqualExpr( @2, $1, $3 );
1140 | Expr T_greatereq Expr
1142         $$ = new Ast::GreaterEqualExpr( @2, $1, $3 );
1144 | T_not Expr
1146         $$ = new Ast::NotExpr( @1, $2 );
1148 | Expr T_and Expr
1150         //      $$ = new Ast::AndExpr( @2, $1, $3 );
1152         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1153         args->orderedExprs_->push_back( $1 );
1154         args->orderedExprs_->push_back( $3 );
1155         $$ = new Ast::CallExpr( @$,
1156                                                                                                         Lang::THE_FUNCTION_AND,
1157                                                                                                         args );
1159 | Expr T_or Expr
1161         //      $$ = new Ast::OrExpr( @2, $1, $3 );
1163         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1164         args->orderedExprs_->push_back( $1 );
1165         args->orderedExprs_->push_back( $3 );
1166         $$ = new Ast::CallExpr( @$,
1167                                                                                                         Lang::THE_FUNCTION_OR,
1168                                                                                                         args );
1170 | Expr T_xor Expr
1172         $$ = new Ast::XorExpr( @2, $1, $3 );
1174 | T_typename
1176         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1177         $$ = new Ast::LexiographicType( @$, $1, key );
1179 | T_last
1181         $$ = new Ast::SpanLastExpr( @$ );
1186 DynamicBinding
1187 : T_dynamic_identifier ':' Expr %prec T_dynamiccolon
1189         $$ = new Ast::DynamicBindingExpression( @1, $1, $3, new Kernel::Environment::LexicalKey * ( 0 ) );
1191 | T_dynamic_identifier ':' T_dynamic Expr %prec T_dynamiccolon
1193         $$ = new Ast::DynamicBindingExpression( @1, $1,
1194                                                                                                                                                                         new Ast::DynamicExpression( @4, $4 ),
1195                                                                                                                                                                         new Kernel::Environment::LexicalKey * ( 0 ) );
1197 | T_dynamic_state_identifier ':' StateReference %prec T_dynamiccolon
1199         $$ = new Ast::DynamicStateBindingExpression( @1, @1, $1, $3 );
1204 ConstantExceptStrings
1205 : T_float
1207         $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1209 | T_length
1211         $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1213 | T_int
1215         $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1217 | T_bool
1219         $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1221 | T_symbol
1223         $$ = new Ast::Constant( @1, new Lang::Symbol( $1 ) );
1225 | T_char
1227         $$ = new Ast::Constant( @1, new Lang::Character( $1 ) );
1231 CodeBracket
1232 : '{' Group '}'
1234         $$ = new Ast::CodeBracket( @$, $2 );
1238 GroupElem
1239 : Expr
1241         $$ = $1;        // Explicit upcast avoids bison warning.
1243 | Identifier ':' Expr
1245         size_t ** pos = new size_t * ( 0 );
1246         $$ = new Ast::DefineVariable( @1, $1, $3, pos );
1248 | T_state_identifier ':' Expr
1250         size_t ** pos = new size_t * ( 0 );
1251         $$ = new Ast::IntroduceState( @1, $1, $3, pos );
1253 | T_state_identifier ';'
1255         size_t ** pos = new size_t * ( 0 );
1256         $$ = new Ast::Freeze( @1, $1, pos );
1258 | Identifier ':' T_state_identifier ';'
1260         size_t ** posVar = new size_t * ( 0 );
1261         size_t ** posState = new size_t * ( 0 );
1262         $$ = new Ast::DefineVariable( @1, $1, new Ast::Freeze( @3, $3, posState ), posVar );
1264 | T_dynamic T_dynamic_identifier Expr Expr
1266         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3, $4 );
1268 | T_dynamic T_dynamic_identifier Expr T_dynamic Expr
1270         $$ = new Ast::DynamicVariableDecl( @$, @2, $2, $3,
1271                                                                                                                                                  new Ast::DynamicExpression( @5, $5 ) );
1273 | T_dynamic T_dynamic_state_identifier StateReference
1275         $$ = new Ast::DynamicStateDecl( @$, @2, $2, $3, new size_t * ( 0 ) );
1277 | T_srcLoc
1279         $$ = new Ast::SourceLocationMark( @$ );
1283 InsertionSequence
1284 : Expr
1286         $$ = new std::list< Ast::Expression * >( );
1287         $$->push_back( $1 );
1289 | T_ggthan Expr
1291         $$ = new std::list< Ast::Expression * >( );
1292         $$->push_back( new Ast::InsertionMutatorCall( @$, $2 ) );
1294 | T_ggthan MutatorCallbackExpr
1296         $$ = new std::list< Ast::Expression * >( );
1297         $$->push_back( new Ast::InsertionMutatorCall( @$, $2 ) );
1299 | InsertionSequence T_llthan Expr
1301         $$ = $1;
1302         $$->push_back( $3 );
1304 | InsertionSequence T_llthan T_ggthan Expr
1306         $$ = $1;
1307         $$->push_back( new Ast::InsertionMutatorCall( Ast::SourceLocation( @3, @4 ), $4 ) );
1309 | InsertionSequence T_llthan T_ggthan MutatorCallbackExpr
1311         $$ = $1;
1312         $$->push_back( new Ast::InsertionMutatorCall( Ast::SourceLocation( @3, @4 ), $4 ) );
1316 OneOrMoreGroupElems
1317 : GroupElem
1319         $$ = new list< Ast::Node * >( );
1320         $$->push_back( $1 );
1322 | OneOrMoreGroupElems GroupElem
1324         $$ = $1;
1325         $$->push_back( $2 );
1327 | StateReference T_llthan InsertionSequence
1329         $$ = new list< Ast::Node * >( );
1330         for( std::list< Ast::Expression * >::iterator i = $3->begin( ); i != $3->end( ); ++i )
1331                 {
1332                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
1333                         if( mutExpr != 0 )
1334                                 {
1335                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1336                                         args->orderedStates_->push_back( $1 );
1337                                         Ast::CallExpr * call =
1338                                                 new Ast::CallExpr( mutExpr->loc( ),
1339                                                                                                                          mutExpr->getExpr( ),
1340                                                                                                                          args );
1341                                         delete *i;
1342                                         *i = 0;
1343                                         $$->push_back( call );
1344                                 }
1345                         else
1346                                 {
1347                                         $$->push_back( new Ast::Insertion( $1, *i ) );
1348                                 }
1349                 }
1351 | OneOrMoreGroupElems StateReference T_llthan InsertionSequence
1353         $$ = $1;
1354         for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
1355                 {
1356                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
1357                         if( mutExpr != 0 )
1358                                 {
1359                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1360                                         args->orderedStates_->push_back( $2 );
1361                                         Ast::CallExpr * call =
1362                                                 new Ast::CallExpr( mutExpr->loc( ),
1363                                                                                                                          mutExpr->getExpr( ),
1364                                                                                                                          args );
1365                                         delete *i;
1366                                         *i = 0;
1367                                         $$->push_back( call );
1368                                 }
1369                         else
1370                                 {
1371                                         $$->push_back( new Ast::Insertion( $2, *i ) );
1372                                 }
1373                 }
1375 | T_splitLeft SplitFormals T_splitRight ':' Expr
1377         $$ = new list< Ast::Node * >( );
1378         size_t ** pos = new size_t * ( 0 );
1380         $5->immediate_ = true;
1381         $$->push_back( new Ast::DefineVariable( @5, $2->newSplitVarId( ), $5, pos ) );
1383         size_t orderedCount = 0;
1385         typedef typeof $2->exprs_ ListType;
1386         for( ListType::iterator i = $2->exprs_.begin( ); i != $2->exprs_.end( ); ++i )
1387                 {
1388                         i->second->setStruct( @5, pos );
1389                         $$->push_back( i->first );
1390                         if( i->second->isOrdered( ) )
1391                                 {
1392                                         ++orderedCount;
1393                                 }
1394                 }
1396         if( $2->sinkDefine_ != 0 )
1397                 {
1398                         $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1399                         $$->push_back( $2->sinkDefine_ );
1400                 }
1401         else
1402                 {
1403                         $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
1404                 }
1406 | T_splitLeft SplitFormals T_splitRight Expr
1408         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1409         $$ = new list< Ast::Node * >( );
1410         $$->push_back( new Ast::ErrorExpression( @$ ) );
1412 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight ':' Expr
1414         $$ = $1;
1415         size_t ** pos = new size_t * ( 0 );
1417         $6->immediate_ = true;
1418         $$->push_back( new Ast::DefineVariable( @6, $3->newSplitVarId( ), $6, pos ) );
1420         size_t orderedCount = 0;
1422         typedef typeof $3->exprs_ ListType;
1423         for( ListType::iterator i = $3->exprs_.begin( ); i != $3->exprs_.end( ); ++i )
1424                 {
1425                         i->second->setStruct( @6, pos );
1426                         $$->push_back( i->first );
1427                         if( i->second->isOrdered( ) )
1428                                 {
1429                                         ++orderedCount;
1430                                 }
1431                 }
1433         if( $3->sinkDefine_ != 0 )
1434                 {
1435                         $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1436                         $$->push_back( $3->sinkDefine_ );
1437                 }
1438         else
1439                 {
1440                         $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1441                 }
1443 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1445         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1446         $$ = $1;
1447         $$->push_back( new Ast::ErrorExpression( @$ ) );
1451 Group
1454         $$ = new list< Ast::Node * >( );
1456 | OneOrMoreGroupElems
1460 SuperMemberReference
1461 : '(' '#' Expr ')' '.' Identifier
1463         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1464         Ast::ProtectedMemberReferenceFunction * res = new Ast::ProtectedMemberReferenceFunction( @$, @2, $3, @6, $6 );
1465         res->push_exprs( args );
1466         $$ = new Ast::CallExpr( @$,
1467                                                                                                         RefCountPtr< const Lang::Function >( res ),
1468                                                                                                         args );
1473 MethodIdentifier
1474 : Identifier '#' Identifier
1476         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1477         $$ = new Ast::MethodIdExpr( @$, new Ast::LexiographicVariable( @1, $1, key ), $3 );
1482 SuperCall
1483 : '[' '(' '#' Expr ')' '.' MethodIdentifier ArgList ']'
1485         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1486         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, $4, $7 );
1487         res->push_exprs( args );
1488         $$ = new Ast::CallExpr( @$,
1489                                                                                                         new Ast::CallExpr( @3,
1490                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1491                                                                                                                                                                                  args ),
1492                                                                                                         $8 );
1494 | '[' '(' '#' ')' '.' MethodIdentifier ArgList ']'
1496         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1497         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, 0, $6 );
1498         res->push_exprs( args );
1499         $$ = new Ast::CallExpr( @$,
1500                                                                                                         new Ast::CallExpr( @3,
1501                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1502                                                                                                                                                                                  args ),
1503                                                                                                         $7 );
1508 Class
1509 : '[' T_class '(' Expr Formals ')' Identifier '(' ListOfParentsWithInitargs ')'
1510         ClassModeList
1511         ClassSections
1512         ']'
1514         DeleteOnExit< char > isaDeleter( $7 );
1515         if( strcmp( $7, "isa" ) != 0 )
1516                 {
1517                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1518                 }
1519         if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1520                 {
1521                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
1522                 }
1524         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1525         Ast::ClassFunction * res = new Ast::ClassFunction( @$, $4, $5, $9, $11, $12 );
1526         res->push_exprs( args );
1527         $$ = new Ast::CallExpr( @$,
1528                                                                                                         RefCountPtr< const Lang::Function >( res ),
1529                                                                                                         args );
1533 ListOfParentsWithInitargs
1534 : '(' Expr ArgList ')'
1536         $$ = new std::list< const Ast::CallExpr * >;
1537         $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1539 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1541         $$ = $1;
1542         $$->push_back( new Ast::CallExpr( Ast::SourceLocation( @2, @5 ), $3, $4 ) );
1546 ClassModeList
1549         $$ = 0;
1551 | OneOrMoreClassModeSpecifiers
1554 OneOrMoreClassModeSpecifiers
1555 : ClassModeSpecifier
1556 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1558         $$ = $1 | $2;
1562 ClassModeSpecifier
1563 : Identifier
1565         DeleteOnExit< char > strDeleter( $1 );
1566         $$ = 0;
1567         if( strcmp( $1, "abstract" ) == 0 )
1568                 {
1569                         $$ = Ast::CLASS_MODE_ABSTRACT;
1570                 }
1571         else if( strcmp( $1, "final" ) == 0 )
1572                 {
1573                         $$ = Ast::CLASS_MODE_FINAL;
1574                 }
1575         else
1576                 {
1577                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1578                 }
1582 ClassSections
1585         $$ = new std::list< Ast::ClassSection * >;
1587 | OneOrMoreClassSections
1590 OneOrMoreClassSections
1591 : ClassSection
1593         $$ = new std::list< Ast::ClassSection * >;
1594         $$->push_back( $1 );
1596 | OneOrMoreClassSections ClassSection
1598         $$ = $1;
1599         $$->push_back( $2 );
1603 ClassSection
1604 : '(' T_members MemberDeclarations ')'
1606         $$ = $3;
1608 | '(' T_prepare Group ')'
1610         $$ = new Ast::PrepareSection( @$, $3 );
1612 | '(' Identifier MethodDeclarations ')'
1614         DeleteOnExit< char > accessSpecDeleter( $2 );
1615         unsigned int accessSpec = 0;
1616         if( strcmp( $2, "__methods__" ) == 0    )
1617                 {
1618                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1619                 }
1620         else if( strcmp( $2, "__abstract__" ) == 0      )
1621                 {
1622                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1623                 }
1624         else if( strcmp( $2, "__final__" ) == 0 )
1625                 {
1626                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1627                 }
1628         else if( strcmp( $2, "__protected__" ) == 0 )
1629                 {
1630                         accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1631                 }
1632         else if( strcmp( $2, "__private__" ) == 0 )
1633                 {
1634                         /* OK, no change */
1635                 }
1636         else
1637                 {
1638                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1639                 }
1640         $3->addModeBits( accessSpec );
1641         $$ = $3;
1643 | '(' T_abstract OrderedFormals ')'
1645         $$ = new Ast::AbstractSection( @$, $3 );
1647 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1649         $$ = new Ast::OverridesSection( $3, $5 );
1653 MemberDeclarations
1656         $$ = new Ast::MemberSection;
1658 | OneOrMoreMemberDeclarations
1661 OneOrMoreMemberDeclarations
1662 : MemberDeclaration
1664         $$ = new Ast::MemberSection;
1665         $$->push_back( $1 );
1667 | OneOrMoreMemberDeclarations MemberDeclaration
1669         $$ = $1;
1670         $$->push_back( $2 );
1674 MemberDeclaration
1675 : '(' Identifier Expr ')'
1677         $$ = new Ast::MemberDeclaration( @$, $2, $3, 0 );
1679 | '(' Identifier Expr MemberAccessList ')'
1681         $$ = new Ast::MemberDeclaration( @$, $2, $3, $4 );
1685 MemberAccessList
1686 : MemberAccessSpecifier
1687 | MemberAccessList MemberAccessSpecifier
1689         $$ = $1 | $2;
1693 MemberAccessSpecifier
1694 : '.'
1696         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1698 | T_llthan
1700         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1702 | '(' '#' '.' ')'
1704         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1706 | '(' '#' T_llthan ')'
1708         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1710 | '^'
1712         $$ = Ast::MEMBER_TRANSFORMING;
1716 MethodDeclarations
1719         $$ = new Ast::MemberSection;
1721 | OneOrMoreMethodDeclarations
1724 OneOrMoreMethodDeclarations
1725 : MethodDeclaration
1727         $$ = new Ast::MemberSection;
1728         $$->push_back( $1 );
1730 | OneOrMoreMethodDeclarations MethodDeclaration
1732         $$ = $1;
1733         $$->push_back( $2 );
1737 MethodDeclaration
1738 : '(' Identifier Expr ')'
1740         $$ = new Ast::MemberDeclaration( @$, $2, $3, Ast::MEMBER_CONST | Ast::MEMBER_METHOD );
1742 | '(' '[' Identifier Formals ']' FunctionModeList GroupElem ')'
1744         Ast::Expression * body = dynamic_cast< Ast::Expression * >( $7 );
1745         if( body == 0 )
1746                 {
1747                         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1748                         bracket->push_back( $7 );
1749                         body = new Ast::CodeBracket( @7, bracket );
1750                 }
1751         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1752         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $4, body, $6 );
1753         res->push_exprs( args );
1754         $$ = new Ast::MemberDeclaration( @$, $3, new Ast::CallExpr( @$,
1755                                                                                                                                                                                                                                                         RefCountPtr< const Lang::Function >( res ),
1756                                                                                                                                                                                                                                                         args ),
1757                                                                                                                                          Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1761 FunctionModeList
1764         $$ = 0;
1766 | OneOrMoreFunctionModeSpecifiers
1769 OneOrMoreFunctionModeSpecifiers
1770 : FunctionModeSpecifier
1771 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1773         $$ = $1 | $2;
1777 FunctionModeSpecifier
1778 : '^'
1780         $$ = Ast::FUNCTION_TRANSFORMING;
1784 Split
1785 : T_split Expr
1787         $$ = $2;
1791 Identifier
1792 : T_identifier_tex
1793 | T_identifier_except_tex
1798 /* The closing %% above marks the end of the Rules section and the beginning
1799  * of the User Subroutines section. All text from here to the end of the
1800  * file is copied verbatim to the end of the generated y.tab.c file.
1801  * This section is where you put definitions of helper functions.
1802  */