Update procedures
[shapes.git] / source / shapesparser.yy
blob08bf58030f101874008b38d012d0884a2ef32083
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, 2014 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         Ast::Identifier * ident;
129         Ast::PlacedIdentifier * placedIdent;
130         std::list< const Ast::CallExpr * > * callExprList;
131         std::list< Ast::ClassSection * > * classSectionList;
132         Ast::ClassSection * classSection;
133         Ast::MemberSection * memberSection;
134         Ast::MemberDeclaration * memberDeclaration;
135         Ast::StateReference * stateReference;
136         Ast::MemberMode memberMode;
137         Ast::ClassMode classMode;
138         Ast::FunctionMode functionMode;
139         void * nothing;
143 /* Tokens
144  * ------
145  * Here we tell yacc about all the token types that we are using.
146  * Yacc will assign unique numbers to these and export the #define
147  * in the generated y.tab.h header file.
148  */
150 %token <tokenID> T_EOF T_preludesep T_minusminus T_plusplus T_dddot T_assign T_eqeq T_eqneq T_projection T_angle T_ampersandMore
151 %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
152 %token <tokenID> T_paren_less T_paren_greater T_paren_lesseq T_paren_greatereq
153 %token <tokenID> T_indexof T_depthof T_variableName T_absrefof T_dynamic T_continuation T_continue T_esc_continuation T_esc_continue T_esc_backtrace T_last
154 %token <tokenID> T_class T_members T_prepare T_abstract T_overrides T_gr__
155 %token <tokenID> T_split T_splitLeft T_splitRight T_unionLeft T_unionRight T_absLeft T_absRight
156 %token <tokenID> T_srcLoc T_freeze T_namespaceSpecial
157 %token <tokenID> T_interactiveMark
159 %token <intVal> T_int
160 %token <uintVal> T_char
161 %token <floatVal> T_float T_length
162 %token <expr> T_speciallength
163 %token <boolVal> T_bool
164 %token <char_p> T_symbol
165 %token <Lang_String> T_string
166 %token <placedIdent> T_atat
167 %token <ident> T_identifier_except_tex T_identifier_tex T_pathed_identifier T_dynamic_identifier T_state_identifier T_dynamic_state_identifier T_typename
168 %token <node> T_alias
170 /* Non-terminal types
171  * ------------------
172  * In order for yacc to assign/access the correct field of $$, $1, we
173  * must to declare which field is appropriate for the non-terminal.
174  * As an example, this first type declaration establishes that the DeclList
175  * non-terminal uses the field named "declList" in the yylval union. This
176  * means that when we are setting $$ for a reduction for DeclList ore reading
177  * $n which corresponds to a DeclList nonterminal we are accessing the field
178  * of the union named "declList" which is of type List<Decl*>.
179  * pp2: You'll need to add many of these of your own.
180  */
182 %type <expr> Program Expr ExprExceptConstStrings ConstantExceptStrings
183 %type <expr> DynamicBinding CallExpr CurryCallExpr MutateExpr MutatorCallbackExpr Function OperatorFunction ParenOperatorFunction Class Coords PolarHandle
184 %type <expr> CodeBracket SuperCall SuperMemberReference
185 %type <exprList> InsertionSequence
186 %type <node> GroupElem
187 %type <nodeList> Group OneOrMoreGroupElems
188 %type <strList> OrderedFormals OneOrMoreOrderedFormals
189 %type <formals> Formals OneOrMoreFormalsItems
190  //                                     %type <formalsList> NamedFormalsWithOrder OneOrMoreNamedFormalsWithOrder
191 %type <argList> ArgList OneOrMoreArgListItems
192 %type <methodId> MethodIdentifier
193 %type <callExprList> ListOfParentsWithInitargs;
194 %type <classSectionList> ClassSections OneOrMoreClassSections
195 %type <classSection> ClassSection
196 %type <memberSection> MemberDeclarations OneOrMoreMemberDeclarations
197 %type <memberSection> MethodDeclarations OneOrMoreMethodDeclarations
198 %type <memberDeclaration> MemberDeclaration MethodDeclaration
199 %type <memberMode> MemberAccessList MemberAccessSpecifier
200 %type <classMode> ClassModeList ClassModeSpecifier OneOrMoreClassModeSpecifiers
201 %type <functionMode> FunctionModeList OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
202 %type <expr> Split
203 %type <stateReference> StateReference
204 %type <splitFormals> SplitFormals OneOrMoreSplitFormals
205 %type <ident> Identifier
207 %nonassoc T_assign ':'
209 %left T_llthan
210 %nonassoc '!'
212 %nonassoc T_mapsto
213 %right '|'
214 %left T_emptybrackets T_dddotbrackets T_ggthan
216 %right ';'
217 %left T_ampersandMore
218 %left '&'
219 %nonassoc T_dynamiccolon
221 %left T_or
222 %nonassoc T_xor
223 %left T_and
224 %left T_not
225 %nonassoc T_eqeq T_eqneq T_lesseq T_greatereq
227 %left T_plusplus T_minusminus
228 %left '<' '>'
230 %left '+' '-'
231 %nonassoc T_angle
232 %left '*' '/' T_projection
233 %left '~'
235 %left T_compose
237 %left '.'
238 %left '#'
239 %left T_split
240 %left T_atat T_surrounding
242 %left ','
244 %start Program
246 %name-prefix "shapes"
250  * All productions and actions should be placed between the start and stop
251  * %% markers which delimit the Rules section.
252  */
254 Program
255 : Group T_preludesep Group T_EOF
257         /* Note that the source location of the prelude is discarded. */
258         $1->push_back( new Ast::CodeBracket( @3, $3 ) );
259         $$ = new Ast::CodeBracket( @3, $1 );
260         Ast::theProgram = $$;
261         YYACCEPT;
263 | T_interactiveMark Group T_EOF
265         Ast::theInteractiveInput = $2;
266         YYACCEPT;
268 | Group error
270         shapeserror( "Expecting end of file." );
275 Coords
276 : '(' Expr ',' Expr ')'
278         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
279         args->orderedExprs_->push_back( $2 );
280         args->orderedExprs_->push_back( $4 );
281         $$ = new Ast::CallExpr( @$,
282                                                                                                         Ast::THE_FUNCTION_coords2D,
283                                                                                                         args );
285 | '(' Expr ',' Expr '^' Expr ')'
287         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
288         args->orderedExprs_->push_back( $2 );
289         args->orderedExprs_->push_back( $4 );
290         args->orderedExprs_->push_back( $6 );
291         $$ = new Ast::CallExpr( @$,
292                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
293                                                                                                         args );
295 | '(' Expr ',' Expr '^' ')'
297         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
298         args->orderedExprs_->push_back( $2 );
299         args->orderedExprs_->push_back( $4 );
300         $$ = new Ast::CallExpr( @$,
301                                                                                                         Ast::THE_FUNCTION_cornercoords2D,
302                                                                                                         args );
304 | '(' Expr ',' Expr ',' Expr ')'
306         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
307         args->orderedExprs_->push_back( $2 );
308         args->orderedExprs_->push_back( $4 );
309         args->orderedExprs_->push_back( $6 );
310         $$ = new Ast::CallExpr( @$,
311                                                                                                         Ast::THE_FUNCTION_coords3D,
312                                                                                                         args );
317 PolarHandle
318 : '(' Expr '^' Expr ')'
320         $$ = new Ast::PolarHandle2DExpr( @$, $2, $4 );
322 | '(' Expr '^' ')'
324         $$ = new Ast::PolarHandle2DExprFree_a( @$, $2 );
326 | '(' '^' Expr ')'
328         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
329         args->orderedExprs_->push_back( $3 );
330         $$ = new Ast::CallExpr( @$,
331                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_r,
332                                                                                                         args );
334 | '(' '^' ')'
336         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
337         $$ = new Ast::CallExpr( @$,
338                                                                                                         Ast::THE_FUNCTION_polarHandle2DFree_ra,
339                                                                                                         args );
343 StateReference
344 : T_state_identifier
346         $$ = new Ast::LexiographicState( @1, $1, new Kernel::Environment::LexicalKey * ( 0 ) );
348 | T_dynamic_state_identifier
350         $$ = new Ast::DynamicState( @1, $1 );
354 ArgList
357         $$ = new Ast::ArgListExprs( true );
359 | OneOrMoreArgListItems
362 OneOrMoreArgListItems
363 : Expr
365         $$ = new Ast::ArgListExprs( true );
366         $$->orderedExprs_->push_back( $1 );
368 | StateReference
370         $$ = new Ast::ArgListExprs( true );
371         $$->orderedStates_->push_back( $1 );
373 | Identifier ':' Expr
375         $$ = new Ast::ArgListExprs( true );
376         const char * id = $1->strip( @1 );
377         (*$$->namedExprs_)[ id ] = $3;
379 | T_state_identifier ':' StateReference
381         $$ = new Ast::ArgListExprs( true );
382         const char * id( $1->strip( @1 ) );
383         (*$$->namedStates_)[ id ] = $3;
385 | OneOrMoreArgListItems Expr
387         $$ = $1;
388         if( ! $$->namedExprs_->empty( ) )
389                 {
390                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed expressions may not appear among named expressions." ) ) );
391                 }
392         $$->orderedExprs_->push_back( $2 );
394 | OneOrMoreArgListItems StateReference
396         $$ = $1;
397         if( ! $$->namedStates_->empty( ) )
398                 {
399                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed states may not appear among named states." ) ) );
400                 }
401         $$->orderedStates_->push_back( $2 );
403 | OneOrMoreArgListItems Identifier ':' Expr
405         $$ = $1;
406         const char * id = $2->strip( @2 );
407         if( $$->namedExprs_->find( id ) != $$->namedExprs_->end( ) )
408                 {
409                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id ) );
410                 }
411         (*$$->namedExprs_)[ id ] = $4;
413 | OneOrMoreArgListItems T_state_identifier ':' StateReference
415         $$ = $1;
416         const char * id( $2->strip( @2 ) );
417         if( $$->namedStates_->find( id ) != $$->namedStates_->end( ) )
418                 {
419                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id ) );
420                 }
421         (*$$->namedStates_)[ id ] = $4;
426 CallExpr
427 : '[' Expr ArgList ']'
429         $$ = new Ast::CallExpr( @$, $2, $3 );
431 | Expr T_emptybrackets Expr
433         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
434         args->orderedExprs_->push_back( $3 );
435         $$ = new Ast::CallExpr( @$,
436                                                                                                         $1,
437                                                                                                         args );
439 | Expr T_ggthan Expr
441         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
442         args->orderedExprs_->push_back( $1 );
443         $$ = new Ast::CallExpr( @$,
444                                                                                                         $3,
445                                                                                                         args );
447 | Expr T_emptybrackets Split
449         $$ = new Ast::CallSplitExpr( @$,
450                                                                                                                          $1,
451                                                                                                                          $3 );
453 | Expr T_dddotbrackets Expr
455         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
456         args->orderedExprs_->push_back( $3 );
457         $$ = new Ast::CallExpr( @$,
458                                                                                                         $1,
459                                                                                                         args,
460                                                                                                         true ); /* true means Curry */
462 | Expr T_dddotbrackets Identifier ':' Expr %prec T_dynamiccolon
464         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
465         const char * id = $3->strip( @3 );
466         (*args->namedExprs_)[ id ] = $5;
467         $$ = new Ast::CallExpr( @$,
468                                                                                                         $1,
469                                                                                                         args,
470                                                                                                         true ); /* true means Curry */
472 | Expr T_dddotbrackets Split
474         $$ = new Ast::CallSplitExpr( @$,
475                                                                                                                          $1,
476                                                                                                                          $3,
477                                                                                                                          true );        /* true means Curry */
482 CurryCallExpr
483 : '[' Expr ArgList T_dddot ']'
485         $$ = new Ast::CallExpr( @$, $2, $3, true ); /* true means Curry */
487 | '(' MutatorCallbackExpr ')'
489   $$ = $2;
493 MutatorCallbackExpr
494 : '.' '[' Identifier ArgList ']'
496         const char * id = $3->strip( @3 );
497         Kernel::Formals * stateFormal = new Kernel::Formals( );
498         stateFormal->appendStateFormal( Kernel::MUTATOR_CURRY_VAR_ID );
499         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
500         Ast::StateReference * stateref = new Ast::LexiographicState( @2, Kernel::MUTATOR_CURRY_VAR_ID.newAbsolute( ), new Kernel::Environment::LexicalKey * ( 0 ) );
501         Ast::CallExpr * body =
502                 new Ast::CallExpr( @$,
503                                                                                          new Ast::MutatorReference( @1, stateref, id ),
504                                                                                          $4 );
505         body->setMutatorSelf( stateref );
506         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, stateFormal, body, 0 );
507         res->push_exprs( args );
508         $$ = new Ast::CallExpr( @$,
509                                                                                                         RefCountPtr< const Lang::Function >( res ),
510                                                                                                         args );
514 MutateExpr
515 : StateReference '.' '[' Identifier ArgList ']'
517         const char * id = $4->strip( @4 );
518         Ast::CallExpr * res =
519                 new Ast::CallExpr( @$,
520                                                                                          new Ast::MutatorReference( @4, $1, id ),
521                                                                                          $5 );
522         res->setMutatorSelf( $1 );
523         $$ = res;
527 Formals
530         $$ = new Kernel::Formals( );
531         $$->setLoc( @$ );
533 | T_split Identifier
535         Ast::PlacedIdentifier * id = $2->place( @2 );
536         $$ = new Kernel::Formals( );
537         $$->appendArgumentFormal( *id );
538         /* Note that we do not push a default expression (not even a null pointer) for the sink.
539          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
540          * The default value for the sink is taken care of in a non-standard way anyway.
541          */
542         $$->setLoc( @$ );
543         $$->sink_ = id;
545 | OneOrMoreFormalsItems
547         $$ = $1;
548         $$->setLoc( @$ );
550 | OneOrMoreFormalsItems T_split Identifier
552         Ast::PlacedIdentifier * id = $3->place( @3 );
553         $$ = $1;
554         if( ! $$->appendArgumentFormal( *id ) )
555                 {
556                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @3, id->strip( ) ) );
557                 }
558         /* Note that we do not push a default expression (not even a null pointer) for the sink.
559          * This way, the length of defaultExprs_ allways gives the number of non-sink arguments.
560          * The default value for the sink is taken care of in a non-standard way anyway.
561          */
562         $$->setLoc( @$ );
563         $$->sink_ = id;
567 OneOrMoreFormalsItems
568 : Identifier
570         $$ = new Kernel::Formals( );
571         Ast::PlacedIdentifier * id = $1->place( @1 );
572         $$->appendArgumentFormal( *id );
573         delete id;
574         $$->defaultExprs_.push_back( NULL );
576 | Identifier ':' Expr
578         $$ = new Kernel::Formals( );
579         Ast::PlacedIdentifier * id = $1->place( @1 );
580         $$->appendArgumentFormal( *id );
581         delete id;
582         $$->defaultExprs_.push_back( $3 );
584 | T_state_identifier
586         $$ = new Kernel::Formals( );
587         Ast::PlacedIdentifier * id = $1->place( @1 );
588         $$->appendStateFormal( *id );
589         delete id;
591 | OneOrMoreFormalsItems Identifier
593         $$ = $1;
594         Ast::PlacedIdentifier * id = $2->place( @2 );
595         if( $$->seenDefault_ )
596                 {
597                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
598                 }
599         if( ! $$->appendArgumentFormal( *id ) )
600                 {
601                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
602                 }
603         delete id;
604         $$->defaultExprs_.push_back( NULL );
606 | OneOrMoreFormalsItems Identifier ':' Expr
608         $$ = $1;
609         Ast::PlacedIdentifier * id = $2->place( @2 );
610         $$->seenDefault_ = true;
611         if( ! $$->appendArgumentFormal( *id ) )
612                 {
613                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
614                 }
615         delete id;
616         $$->defaultExprs_.push_back( $4 );
618 | OneOrMoreFormalsItems T_state_identifier
620         $$ = $1;
621         Ast::PlacedIdentifier * id = $2->place( @2 );
622         if( ! $$->appendStateFormal( *id ) )
623                 {
624                         Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
625                 }
626         delete id;
631 SplitFormals
634         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "The list of split assignment variables must not be empty." ) ) );
635         $$ = new Ast::SplitDefineVariables( );
637 | T_split Identifier
639         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "Just a sink in a split assignment formals list makes no sense." ) ) );
640         $$ = new Ast::SplitDefineVariables( );
642 | OneOrMoreSplitFormals
644         $$ = $1;
646 | OneOrMoreSplitFormals T_split Identifier
648         $$ = $1;
649         Ast::PlacedIdentifier * id = $3->place( @3 );
650         Ast::StructSplitSink * expr = new Ast::StructSplitSink( );
651         size_t ** pos = new size_t * ( 0 );
652         $$->sinkDefine_ = new Ast::DefineVariable( @3, id, expr, pos );
653         $$->sinkExpr_ = expr;
657 OneOrMoreSplitFormals
658 : Identifier
660         $$ = new Ast::SplitDefineVariables( );
661         Ast::PlacedIdentifier * id = $1->place( @1 );
662         typedef typeof $$->exprs_ ListType;
663         size_t ** pos = new size_t * ( 0 );
664         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), 0 );
665         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id, ref, pos ),
666                                                                                                                                                                                          ref ) );
668 | Identifier ':' Expr
670         $$ = new Ast::SplitDefineVariables( );
671         Ast::PlacedIdentifier * id = $1->place( @1 );
672         typedef typeof $$->exprs_ ListType;
673         size_t ** pos = new size_t * ( 0 );
674         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @1, static_cast< size_t >( 0 ), $3 );
675         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id, ref, pos ),
676                                                                                                                                                                                          ref ) );
678 | Identifier ':' '.' Identifier
680         Ast::PlacedIdentifier * id1 = $1->place( @1 );
681         const char * id2 = $4->strip( @4 );
682         $$ = new Ast::SplitDefineVariables( );
683         typedef typeof $$->exprs_ ListType;
684         size_t ** pos = new size_t * ( 0 );
685         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, id2, 0 );
686         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id1, ref, pos ),
687                                                                                                                                                                                          ref ) );
689 | Identifier ':' '.' Identifier ':' Expr
691         Ast::PlacedIdentifier * id1 = $1->place( @1 );
692         const char * id2 = $4->strip( @4 );
693         $$ = new Ast::SplitDefineVariables( );
694         typedef typeof $$->exprs_ ListType;
695         size_t ** pos = new size_t * ( 0 );
696         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, id2, $6 );
697         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id1, ref, pos ),
698                                                                                                                                                                                          ref ) );
700 | Identifier ':' '.' '\"'
702         $$ = new Ast::SplitDefineVariables( );
703         Ast::PlacedIdentifier * id = $1->place( @1 );
704         typedef typeof $$->exprs_ ListType;
705         size_t ** pos = new size_t * ( 0 );
706         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( id->simpleId( ) ), 0 );
707         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id, ref, pos ),
708                                                                                                                                                                                          ref ) );
710 | Identifier ':' '.' '\"' ':' Expr
712         $$ = new Ast::SplitDefineVariables( );
713         Ast::PlacedIdentifier * id = $1->place( @1 );
714         typedef typeof $$->exprs_ ListType;
715         size_t ** pos = new size_t * ( 0 );
716         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @4, strdup( id->simpleId( ) ), $6 );
717         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @1, id, ref, pos ),
718                                                                                                                                                                                          ref ) );
720 | OneOrMoreSplitFormals Identifier
722         $$ = $1;
723         Ast::PlacedIdentifier * id = $2->place( @2 );
724         if( $$->seenNamed_ )
725                 {
726                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
727                 }
728         if( $$->seenDefault_ )
729                 {
730                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "All order-based formals without default values must be placed before those with default values." ) ) );
731                 }
732         typedef typeof $$->exprs_ ListType;
733         size_t ** pos = new size_t * ( 0 );
734         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), 0 );
735         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id, ref, pos ),
736                                                                                                                                                                                          ref ) );
738 | OneOrMoreSplitFormals Identifier ':' Expr
740         $$ = $1;
741         Ast::PlacedIdentifier * id = $2->place( @2 );
742         if( $$->seenNamed_ )
743                 {
744                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
745                 }
746         $$->seenDefault_ = true;
747         typedef typeof $$->exprs_ ListType;
748         size_t ** pos = new size_t * ( 0 );
749         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @2, $$->exprs_.size( ), $4 );
750         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id, ref, pos ),
751                                                                                                                                                                                          ref ) );
753 | OneOrMoreSplitFormals Identifier ':' '.' Identifier
755         $$ = $1;
756         Ast::PlacedIdentifier * id1 = $2->place( @2 );
757         const char * id2 = $5->strip( @5 );
758         $$->seenNamed_ = true;
759         typedef typeof $$->exprs_ ListType;
760         size_t ** pos = new size_t * ( 0 );
761         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, id2, 0 );
762         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id1, ref, pos ),
763                                                                                                                                                                                          ref ) );
765 | OneOrMoreSplitFormals Identifier ':' '.' Identifier ':' Expr
767         $$ = $1;
768         Ast::PlacedIdentifier * id1 = $2->place( @2 );
769         const char * id2 = $5->strip( @5 );
770         $$->seenNamed_ = true;
771         typedef typeof $$->exprs_ ListType;
772         size_t ** pos = new size_t * ( 0 );
773         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, id2, $7 );
774         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id1, ref, pos ),
775                                                                                                                                                                                          ref ) );
777 | OneOrMoreSplitFormals Identifier ':' '.' '\"'
779         $$ = $1;
780         Ast::PlacedIdentifier * id = $2->place( @2 );
781         $$->seenNamed_ = true;
782         typedef typeof $$->exprs_ ListType;
783         size_t ** pos = new size_t * ( 0 );
784         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( id->simpleId( ) ), 0 );
785         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id, ref, pos ),
786                                                                                                                                                                                          ref ) );
788 | OneOrMoreSplitFormals Identifier ':' '.' '\"' ':' Expr
790         $$ = $1;
791         Ast::PlacedIdentifier * id = $2->place( @2 );
792         $$->seenNamed_ = true;
793         typedef typeof $$->exprs_ ListType;
794         size_t ** pos = new size_t * ( 0 );
795         Ast::StructSplitReference * ref = new Ast::StructSplitReference( @5, strdup( id->simpleId( ) ), $7 );
796         $$->exprs_.push_back( ListType::value_type( new Ast::DefineVariable( @2, id, ref, pos ),
797                                                                                                                                                                                          ref ) );
802 Function
803 : '\\' Formals T_mapsto FunctionModeList Expr
805         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
806         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $2, $5, $4 );
807         res->push_exprs( args );
808         $$ = new Ast::CallExpr( @$,
809                                                                                                         RefCountPtr< const Lang::Function >( res ),
810                                                                                                         args );
812 | '(' OperatorFunction ')'
814         $$ = $2;
816 | ParenOperatorFunction
818         $$ = $1;
822 OrderedFormals
825         $$ = new list< RefCountPtr< const char > >( );
827 | OneOrMoreOrderedFormals
830 OneOrMoreOrderedFormals
831 : Identifier
833         $$ = new list< RefCountPtr< const char > >( );
834         RefCountPtr< const char > id = $1->refstrip( @1 );
835         $$->push_back( id );
837 | OneOrMoreOrderedFormals Identifier
839         $$ = $1;
840         RefCountPtr< const char > id = $2->refstrip( @2 );
841         $$->push_back( id );
845 OperatorFunction
846 : T_minusminus
848         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUSMINUS ) );
850 | T_plusplus
852         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUSPLUS ) );
854 | '&'
856         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND ) );
858 | ';'
860         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Ast::THE_FUNCTION_fcons ) );
862 | '+'
864         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUS ) );
866 | '-'
868         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUS ) );
870 | '*'
872         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_STAR ) );
874 | '/'
876         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_SLASH ) );
878 | T_projection
880         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PROJECTION ) );
882 | T_angle
884         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_ANGLE ) );
886 | T_ampersandMore
888         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND_MORE ) );
890 | '~'
892         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NEG ) );
894 | T_compose
896         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_COMPOSE ) );
898 | '<'
900         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
902 | '>'
904         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
906 | T_eqeq
908         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQEQ ) );
910 | T_eqneq
912         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQNEQ ) );
914 | T_lesseq
916         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
918 | T_greatereq
920         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
922 | T_not
924         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NOT ) );
926 | T_and
928         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_AND ) );
930 | T_or
932         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_OR ) );
934 | T_xor
936         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_XOR ) );
940 ParenOperatorFunction
941 : T_paren_less
943         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
945 | T_paren_greater
947         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
949 | T_paren_lesseq
951         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
953 | T_paren_greatereq
955         $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
959 Expr
960 : ExprExceptConstStrings
961 | T_string
963         $$ = new Ast::Constant( @1, $1 );
967 ExprExceptConstStrings
968 : ConstantExceptStrings
969 | Coords
970 | PolarHandle
971 | '(' T_identifier_tex ExprExceptConstStrings ')'
973         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 ),
974                                                                                                                  & Ast::theAnalysisErrorsList );
975         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
976         args->orderedExprs_->push_back( $3 );
977         $$ = new Ast::CallExpr( @$,
978                                                                                                         Ast::THE_FUNCTION_TeX,
979                                                                                                         args );
981 | '(' T_identifier_tex T_string ')'
983         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 ),
984                                                                                                                  & Ast::theAnalysisErrorsList );
985         Kernel::theTeXLabelManager.announce( std::string( $3->val_.getPtr( ) ), @3 );
986         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
987         args->orderedExprs_->push_back( new Ast::Constant( @3, $3 ) );
988         $$ = new Ast::CallExpr( @$,
989                                                                                                         Ast::THE_FUNCTION_TeX,
990                                                                                                         args );
992 | '!' Expr
994         $$ = new Ast::Force( @$, $2 );
996 | CallExpr
997 | CurryCallExpr
998 | SuperCall
999 | SuperMemberReference
1000 | T_speciallength
1001 | '(' Expr ')'
1003         $$ = $2;
1005 | '(' '-' Expr ')'
1007         $$ = new Ast::NegExpr( @$, @2, $3 );
1009 | '(' '+' Expr ')'
1011         $$ = new Ast::RelativeExpr( @$, @2, $3 );
1013 | '(' ')'
1015         $$ = new Ast::EmptyExpression( @$ );
1017 | '(' Expr T_llthan InsertionSequence ')'
1019         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1021         size_t ** pos = new size_t * ( 0 );
1022         /* Note that there is currently no node which is considered the owner of dst and will take care of its deallocation. */
1023   Ast::StateReference * dst = new Ast::LexiographicState( @2, Kernel::SEQUENTIAL_EXPR_VAR_ID.newAbsolute( ), new Kernel::Environment::LexicalKey * ( 0 ) );
1025         bracket->push_back( new Ast::IntroduceState( @3,
1026                                                                                                                                                                                          Kernel::SEQUENTIAL_EXPR_VAR_ID.clone( ),
1027                                                                                                                                                                                          $2,
1028                                                                                                                                                                                          pos ) );
1029         for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
1030                 {
1031                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
1032                         if( mutExpr != 0 )
1033                                 {
1034                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true, false );
1035                                         args->orderedStates_->push_back( dst );
1036                                         Ast::CallExpr * call =
1037                                                 new Ast::CallExpr( mutExpr->loc( ),
1038                                                                                                                          mutExpr->getExpr( ),
1039                                                                                                                          args );
1040                                         delete *i;
1041                                         *i = 0;
1042                                         bracket->push_back( call );
1043                                 }
1044                         else
1045                                 {
1046                                         bracket->push_back( new Ast::Insertion( dst, *i ) );
1047                                 }
1048                 }
1049         bracket->push_back( new Ast::Freeze( @3, Kernel::SEQUENTIAL_EXPR_VAR_ID.clone( ), pos ) );
1050         $$ = new Ast::CodeBracket( @$, bracket );
1052 | T_surrounding Expr
1054         $$ = new Ast::EvalOutsideExpr( @$, $2 );
1056 | CodeBracket
1057 | Function
1058 | Class
1059 | Identifier
1061         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1062         $$ = new Ast::LexiographicVariable( @$, $1, key );
1064 | T_atat Expr
1066         /* $1 contains a placed identifier just for communicating the namespace at the point of the
1067          * operator.
1068          */
1069         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1070         Ast::EvalSymbolFunction * res = new Ast::EvalSymbolFunction( @$, $2, $1->absolutePathRef( ) );
1071         res->push_exprs( args );
1072         $$ = new Ast::CallExpr( @$,
1073                                                                                                         RefCountPtr< const Lang::Function >( res ),
1074                                                                                                         args );
1075         delete $1;
1077 | T_dynamic_identifier
1079         $$ = new Ast::DynamicVariable( @$, $1 );
1081 | '(' StateReference ')'
1083         $$ = new Ast::Peek( @$, $2 );
1085 | MutateExpr
1086 | Expr '.' Identifier
1088         const char * id = $3->strip( @3 );
1089         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1090         Ast::MemberReferenceFunction * res = new Ast::MemberReferenceFunction( @$, $1, id );
1091         res->push_exprs( args );
1092         $$ = new Ast::CallExpr( @$,
1093                                                                                                         RefCountPtr< const Lang::Function >( res ),
1094                                                                                                         args );
1096 | DynamicBinding
1097 | '(' T_esc_continuation Identifier Expr ')'
1099         const char * id = $3->strip( @3 );
1100         $$ = new Ast::LetDynamicECExpr( @$, @3, id, $4 );
1102 | '(' T_esc_continue Identifier Expr ')'
1104         const char * id = $3->strip( @3 );
1105         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1106         Ast::ContinueDynamicECFunction * res = new Ast::ContinueDynamicECFunction( @3, id, $4 );
1107         res->push_exprs( args );
1108         $$ = new Ast::CallExpr( @$,
1109                                                                                                         RefCountPtr< const Lang::Function >( res ),
1110                                                                                                         args );
1111         /* This used to be immediate, but right now that seems utterly wrong!
1112          * Imagine choosing between two continuations; then both continuations would require invokation before being "passed" to the <if> function.
1113          * 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
1114          * knowing when they will be forced...  But I don't think there's a choice here anyway; this expression can't be immediate.
1115          */
1117 | '(' T_esc_backtrace Identifier ')'
1119         const char * id = $3->strip( @3 );
1120         $$ = new Ast::GetECBacktraceExpr( @3, id );
1122 | '(' T_indexof Identifier ')'
1124         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::INDEX );
1126 | '(' T_depthof Identifier ')'
1128         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::DEPTH );
1130 | T_variableName
1132         $$ = new Ast::LexicalVariableNameExpr( @1 );
1134 | '(' T_absrefof Identifier ')'
1136         $$ = new Ast::LexicalVariableLocationExpr( @3, $3, Ast::LexicalVariableLocationExpr::ABSID );
1138 | '(' T_absrefof T_atat ')'
1140         /* $3 contains a placed identifier just for communicating the namespace at the point of the
1141          * operator.
1142          */
1143         std::ostringstream oss;
1144         oss << Interaction::NAMESPACE_SEPARATOR ;
1145   for( Ast::NamespacePath::const_iterator i = $3->absolutePath( ).begin( ); i != $3->absolutePath( ).end( ); ++i ){
1146     oss << *i << Interaction::NAMESPACE_SEPARATOR ;
1147   }
1148         $$ = new Ast::Constant( @$, new Lang::String( strrefdup( oss ) ) );
1150 | T_absLeft Expr T_absRight
1152         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1153         args->orderedExprs_->push_back( $2 );
1154         $$ = new Ast::CallExpr( @$,
1155                                                                                                         Lang::THE_FUNCTION_ABS,
1156                                                                                                         args );
1158 | Expr '|' Expr
1160         $$ = new Ast::WithDynamicExpr( @$, $1, $3 );
1162 | T_unionLeft ArgList T_unionRight
1164         $$ = new Ast::UnionExpr( @$, $2 );
1166 | Expr T_minusminus T_cycle
1168         $$ = new Ast::CycleExpr( @3, $1 );
1170 | Expr T_minusminus Expr
1172         $$ = new Ast::MinusMinusExpr( @2, $1, $3 );
1174 | Expr T_plusplus Expr
1176         $$ = new Ast::PlusPlusExpr( @2, $1, $3 );
1178 | Expr '&' Expr
1180         $$ = new Ast::AmpersandExpr( @2, $1, $3 );
1182 | Expr ';' Expr
1184         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1185         args->orderedExprs_->push_back( $1 );
1186         args->orderedExprs_->push_back( $3 );
1187         $$ = new Ast::CallExpr( @$,
1188                                                                                                         Ast::THE_FUNCTION_fcons,
1189                                                                                                         args );
1191 | Expr '+' Expr
1193         $$ = new Ast::PlusExpr( @2, $1, $3 );
1195 | Expr '-' Expr
1197         $$ = new Ast::MinusExpr( @2, $1, $3 );
1199 | Expr T_angle Expr
1201         $$ = new Ast::AngleExpr( @2, $1, $3 );
1203 | Expr T_ampersandMore Expr
1205         $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1207 | Expr '*' Expr
1209         $$ = new Ast::StarExpr( @2, $1, $3 );
1211 | Expr T_projection Expr
1213         $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1215 | Expr '/' Expr
1217         $$ = new Ast::SlashExpr( @2, $1, $3 );
1219 | '~' Expr
1221         $$ = new Ast::NegExpr( @1, $2 );
1223 | Expr T_compose Expr
1225         $$ = new Ast::ComposeExpr( @2, $1, $3 );
1227 | Expr '<' Expr
1229         $$ = new Ast::LessExpr( @2, $1, $3 );
1231 | Expr '>' Expr
1233         $$ = new Ast::GreaterExpr( @2, $1, $3 );
1235 | Expr T_eqeq Expr
1237         $$ = new Ast::EqualExpr( @2, $1, $3 );
1239 | Expr T_eqneq Expr
1241         $$ = new Ast::NotEqualExpr( @2, $1, $3 );
1243 | Expr T_lesseq Expr
1245         $$ = new Ast::LessEqualExpr( @2, $1, $3 );
1247 | Expr T_greatereq Expr
1249         $$ = new Ast::GreaterEqualExpr( @2, $1, $3 );
1251 | T_not Expr
1253         $$ = new Ast::NotExpr( @1, $2 );
1255 | Expr T_and Expr
1257         //      $$ = new Ast::AndExpr( @2, $1, $3 );
1259         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1260         args->orderedExprs_->push_back( $1 );
1261         args->orderedExprs_->push_back( $3 );
1262         $$ = new Ast::CallExpr( @$,
1263                                                                                                         Lang::THE_FUNCTION_AND,
1264                                                                                                         args );
1266 | Expr T_or Expr
1268         //      $$ = new Ast::OrExpr( @2, $1, $3 );
1270         Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
1271         args->orderedExprs_->push_back( $1 );
1272         args->orderedExprs_->push_back( $3 );
1273         $$ = new Ast::CallExpr( @$,
1274                                                                                                         Lang::THE_FUNCTION_OR,
1275                                                                                                         args );
1277 | Expr T_xor Expr
1279         $$ = new Ast::XorExpr( @2, $1, $3 );
1281 | T_typename
1283         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1284         $$ = new Ast::LexiographicType( @$, $1, key );
1286 | T_last
1288         $$ = new Ast::SpanLastExpr( @$ );
1293 DynamicBinding
1294 : T_dynamic_identifier ':' Expr %prec T_dynamiccolon
1296         $$ = new Ast::DynamicBindingExpression( @1, $1, $3, new Kernel::Environment::LexicalKey * ( 0 ) );
1298 | T_dynamic_identifier ':' T_dynamic Expr %prec T_dynamiccolon
1300         $$ = new Ast::DynamicBindingExpression( @1, $1,
1301                                                                                                                                                                         new Ast::DynamicExpression( @4, $4 ),
1302                                                                                                                                                                         new Kernel::Environment::LexicalKey * ( 0 ) );
1304 | T_dynamic_state_identifier ':' StateReference %prec T_dynamiccolon
1306         $$ = new Ast::DynamicStateBindingExpression( @1, @1, $1, $3 );
1311 ConstantExceptStrings
1312 : T_float
1314         $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1316 | T_length
1318         $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1320 | T_int
1322         $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1324 | T_bool
1326         $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1328 | T_symbol
1330         $$ = new Ast::Constant( @1, new Lang::Symbol( $1 ) );
1332 | T_char
1334         $$ = new Ast::Constant( @1, new Lang::Character( $1 ) );
1338 CodeBracket
1339 : '{' Group '}'
1341         $$ = new Ast::CodeBracket( @$, $2 );
1345 GroupElem
1346 : Expr
1348         $$ = $1;        // Explicit upcast avoids bison warning.
1350 | Identifier ':' Expr
1352         Ast::PlacedIdentifier * id = $1->place( @1 );
1353         size_t ** pos = new size_t * ( 0 );
1354         $$ = new Ast::DefineVariable( @1, id, $3, pos );
1356 | Identifier ':' '-'
1358         Ast::PlacedIdentifier * id = $1->place( @1 );
1359         Ast::PrivateAliasVariable * expr = new Ast::PrivateAliasVariable( @3, *id, $1->searchContext( ).privateName( ) );
1360         size_t ** pos = new size_t * ( 0 );
1361         $$ = new Ast::DefineVariable( @1, id, expr, pos );
1363 | '\"' ':' Identifier
1365         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1366         Ast::LexiographicVariable * expr = new Ast::LexiographicVariable( @3, $3, key );
1367   Ast::PlacedIdentifier * id = new Ast::PlacedIdentifier( $3->searchContext( ).lexicalPath( ), $3->simpleId( ) );
1368         size_t ** pos = new size_t * ( 0 );
1369         $$ = new Ast::DefineVariable( @1, id, expr, pos );
1371 | T_state_identifier ':' Expr
1373         Ast::PlacedIdentifier * id = $1->place( @1 );
1374         size_t ** pos = new size_t * ( 0 );
1375         $$ = new Ast::IntroduceState( @1, id, $3, pos );
1377 | T_freeze T_state_identifier
1379         Ast::PlacedIdentifier * id = $2->place( @2 );
1380         size_t ** pos = new size_t * ( 0 );
1381         $$ = new Ast::Freeze( @2, id, pos );
1383 | Identifier ':' T_freeze T_state_identifier
1385         Ast::PlacedIdentifier * id1 = $1->place( @1 );
1386         Ast::PlacedIdentifier * id2 = $4->place( @4 );
1387         size_t ** posVar = new size_t * ( 0 );
1388         size_t ** posState = new size_t * ( 0 );
1389         $$ = new Ast::DefineVariable( @1, id1, new Ast::Freeze( @4, id2, posState ), posVar );
1391 | T_dynamic T_dynamic_identifier Expr Expr
1393         Ast::PlacedIdentifier * id( $2->place( @2 ) );
1394         $$ = new Ast::DynamicVariableDecl( @$, @2, id, $3, $4 );
1396 | T_dynamic T_dynamic_identifier Expr T_dynamic Expr
1398         Ast::PlacedIdentifier * id( $2->place( @2 ) );
1399         $$ = new Ast::DynamicVariableDecl( @$, @2, id, $3,
1400                                                                                                                                                  new Ast::DynamicExpression( @5, $5 ) );
1402 | T_dynamic T_dynamic_state_identifier StateReference
1404         Ast::PlacedIdentifier * id = $2->place( @2 );
1405         $$ = new Ast::DynamicStateDecl( @$, @2, id, $3, new size_t * ( 0 ) );
1407 | T_alias
1408 | T_srcLoc
1410         $$ = new Ast::SourceLocationMark( @$ );
1414 InsertionSequence
1415 : Expr
1417         $$ = new std::list< Ast::Expression * >( );
1418         $$->push_back( $1 );
1420 | T_ggthan Expr
1422         $$ = new std::list< Ast::Expression * >( );
1423         $$->push_back( new Ast::InsertionMutatorCall( @$, $2 ) );
1425 | T_ggthan MutatorCallbackExpr
1427         $$ = new std::list< Ast::Expression * >( );
1428         $$->push_back( new Ast::InsertionMutatorCall( @$, $2 ) );
1430 | InsertionSequence T_llthan Expr
1432         $$ = $1;
1433         $$->push_back( $3 );
1435 | InsertionSequence T_llthan T_ggthan Expr
1437         $$ = $1;
1438         Ast::SourceLocation loc( @3, @4 );
1439         $$->push_back( new Ast::InsertionMutatorCall( loc, $4 ) );
1441 | InsertionSequence T_llthan T_ggthan MutatorCallbackExpr
1443         $$ = $1;
1444         Ast::SourceLocation loc( @3, @4 );
1445         $$->push_back( new Ast::InsertionMutatorCall( loc, $4 ) );
1449 OneOrMoreGroupElems
1450 : GroupElem
1452         $$ = new list< Ast::Node * >( );
1453         $$->push_back( $1 );
1455 | OneOrMoreGroupElems GroupElem
1457         $$ = $1;
1458         $$->push_back( $2 );
1460 | StateReference T_llthan InsertionSequence
1462         /* Note that there is currently no node which is considered the owner of $1 and will take care of its deallocation. */
1463         $$ = new list< Ast::Node * >( );
1464         for( std::list< Ast::Expression * >::iterator i = $3->begin( ); i != $3->end( ); ++i )
1465                 {
1466                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
1467                         if( mutExpr != 0 )
1468                                 {
1469                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true, false );
1470                                         args->orderedStates_->push_back( $1 );
1471                                         Ast::CallExpr * call =
1472                                                 new Ast::CallExpr( mutExpr->loc( ),
1473                                                                                                                          mutExpr->getExpr( ),
1474                                                                                                                          args );
1475                                         delete *i;
1476                                         *i = 0;
1477                                         $$->push_back( call );
1478                                 }
1479                         else
1480                                 {
1481                                         $$->push_back( new Ast::Insertion( $1, *i ) );
1482                                 }
1483                 }
1485 | OneOrMoreGroupElems StateReference T_llthan InsertionSequence
1487         /* Note that there is currently no node which is considered the owner of $2 and will take care of its deallocation. */
1488         $$ = $1;
1489         for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
1490                 {
1491                         Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
1492                         if( mutExpr != 0 )
1493                                 {
1494                                         Ast::ArgListExprs * args = new Ast::ArgListExprs( true, false );
1495                                         args->orderedStates_->push_back( $2 );
1496                                         Ast::CallExpr * call =
1497                                                 new Ast::CallExpr( mutExpr->loc( ),
1498                                                                                                                          mutExpr->getExpr( ),
1499                                                                                                                          args );
1500                                         delete *i;
1501                                         *i = 0;
1502                                         $$->push_back( call );
1503                                 }
1504                         else
1505                                 {
1506                                         $$->push_back( new Ast::Insertion( $2, *i ) );
1507                                 }
1508                 }
1510 | T_splitLeft SplitFormals T_splitRight ':' Expr
1512         $$ = new list< Ast::Node * >( );
1513         size_t ** pos = new size_t * ( 0 );
1515         Ast::Force * rhs( new Ast::Force( @5, $5 ) );
1516         $$->push_back( new Ast::DefineVariable( @5, $2->newSplitVarId( ), rhs, pos ) );
1518         size_t orderedCount = 0;
1520         typedef typeof $2->exprs_ ListType;
1521         for( ListType::iterator i = $2->exprs_.begin( ); i != $2->exprs_.end( ); ++i )
1522                 {
1523                         i->second->setStruct( @5, pos );
1524                         $$->push_back( i->first );
1525                         if( i->second->isOrdered( ) )
1526                                 {
1527                                         ++orderedCount;
1528                                 }
1529                 }
1531         if( $2->sinkDefine_ != 0 )
1532                 {
1533                         $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1534                         $$->push_back( $2->sinkDefine_ );
1535                 }
1536         else
1537                 {
1538                         $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
1539                 }
1541 | T_splitLeft SplitFormals T_splitRight Expr
1543         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1544         $$ = new list< Ast::Node * >( );
1545         $$->push_back( new Ast::ErrorExpression( @$ ) );
1547 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight ':' Expr
1549         $$ = $1;
1550         size_t ** pos = new size_t * ( 0 );
1552         Ast::Force * rhs( new Ast::Force( @6, $6 ) );
1553         $$->push_back( new Ast::DefineVariable( @6, $3->newSplitVarId( ), rhs, pos ) );
1555         size_t orderedCount = 0;
1557         typedef typeof $3->exprs_ ListType;
1558         for( ListType::iterator i = $3->exprs_.begin( ); i != $3->exprs_.end( ); ++i )
1559                 {
1560                         i->second->setStruct( @6, pos );
1561                         $$->push_back( i->first );
1562                         if( i->second->isOrdered( ) )
1563                                 {
1564                                         ++orderedCount;
1565                                 }
1566                 }
1568         if( $3->sinkDefine_ != 0 )
1569                 {
1570                         $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1571                         $$->push_back( $3->sinkDefine_ );
1572                 }
1573         else
1574                 {
1575                         $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1576                 }
1578 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1580         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1581         $$ = $1;
1582         $$->push_back( new Ast::ErrorExpression( @$ ) );
1584 | T_namespaceSpecial
1586         $$ = new list< Ast::Node * >( );
1588 | OneOrMoreGroupElems T_namespaceSpecial
1590         $$ = $1;
1594 Group
1597         $$ = new list< Ast::Node * >( );
1599 | OneOrMoreGroupElems
1603 SuperMemberReference
1604 : '(' '#' Expr ')' '.' Identifier
1606         const char * id = $6->strip( @6 );
1607         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1608         Ast::ProtectedMemberReferenceFunction * res = new Ast::ProtectedMemberReferenceFunction( @$, @2, $3, @6, id );
1609         res->push_exprs( args );
1610         $$ = new Ast::CallExpr( @$,
1611                                                                                                         RefCountPtr< const Lang::Function >( res ),
1612                                                                                                         args );
1617 MethodIdentifier
1618 : Identifier '#' Identifier
1620         const char * id = $3->strip( @3 );
1621         Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1622         $$ = new Ast::MethodIdExpr( @$, new Ast::LexiographicVariable( @1, $1, key ), id );
1627 SuperCall
1628 : '[' '(' '#' Expr ')' '.' MethodIdentifier ArgList ']'
1630         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1631         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, $4, $7 );
1632         res->push_exprs( args );
1633         $$ = new Ast::CallExpr( @$,
1634                                                                                                         new Ast::CallExpr( @3,
1635                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1636                                                                                                                                                                                  args ),
1637                                                                                                         $8 );
1639 | '[' '(' '#' ')' '.' MethodIdentifier ArgList ']'
1641         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1642         Ast::ProtectedMethodReferenceFunction * res = new Ast::ProtectedMethodReferenceFunction( @$, @3, 0, $6 );
1643         res->push_exprs( args );
1644         $$ = new Ast::CallExpr( @$,
1645                                                                                                         new Ast::CallExpr( @3,
1646                                                                                                                                                                                  RefCountPtr< const Lang::Function >( res ),
1647                                                                                                                                                                                  args ),
1648                                                                                                         $7 );
1653 Class
1654 : '[' T_class '(' Expr Formals ')' Identifier '(' ListOfParentsWithInitargs ')'
1655         ClassModeList
1656         ClassSections
1657         ']'
1659         const char * id = $7->strip( @7 );
1660         DeleteOnExit< const char > isaDeleter( id );
1661         if( strcmp( id, "isa" ) != 0 )
1662                 {
1663                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1664                 }
1665         if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1666                 {
1667                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
1668                 }
1670         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1671         Ast::ClassFunction * res = new Ast::ClassFunction( @$, $4, $5, $9, $11, $12 );
1672         res->push_exprs( args );
1673         $$ = new Ast::CallExpr( @$,
1674                                                                                                         RefCountPtr< const Lang::Function >( res ),
1675                                                                                                         args );
1679 ListOfParentsWithInitargs
1680 : '(' Expr ArgList ')'
1682         $$ = new std::list< const Ast::CallExpr * >;
1683         $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1685 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1687         $$ = $1;
1688         Ast::SourceLocation loc( @2, @5 );
1689         $$->push_back( new Ast::CallExpr( loc, $3, $4 ) );
1693 ClassModeList
1696         $$ = 0;
1698 | OneOrMoreClassModeSpecifiers
1701 OneOrMoreClassModeSpecifiers
1702 : ClassModeSpecifier
1703 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1705         $$ = $1 | $2;
1709 ClassModeSpecifier
1710 : Identifier
1712         const char * id = $1->strip( @1 );
1713         DeleteOnExit< const char > strDeleter( id );
1714         $$ = 0;
1715         if( strcmp( id, "abstract" ) == 0 )
1716                 {
1717                         $$ = Ast::CLASS_MODE_ABSTRACT;
1718                 }
1719         else if( strcmp( id, "final" ) == 0 )
1720                 {
1721                         $$ = Ast::CLASS_MODE_FINAL;
1722                 }
1723         else
1724                 {
1725                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1726                 }
1730 ClassSections
1733         $$ = new std::list< Ast::ClassSection * >;
1735 | OneOrMoreClassSections
1738 OneOrMoreClassSections
1739 : ClassSection
1741         $$ = new std::list< Ast::ClassSection * >;
1742         $$->push_back( $1 );
1744 | OneOrMoreClassSections ClassSection
1746         $$ = $1;
1747         $$->push_back( $2 );
1751 ClassSection
1752 : '(' T_members MemberDeclarations ')'
1754         $$ = $3;
1756 | '(' T_prepare Group ')'
1758         $$ = new Ast::PrepareSection( @$, $3 );
1760 | '(' Identifier MethodDeclarations ')'
1762         const char * id = $2->strip( @2 );
1763         DeleteOnExit< const char > accessSpecDeleter( id );
1764         unsigned int accessSpec = 0;
1765         if( strcmp( id, "__methods__" ) == 0 )
1766                 {
1767                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1768                 }
1769         else if( strcmp( id, "__abstract__" ) == 0 )
1770                 {
1771                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1772                 }
1773         else if( strcmp( id, "__final__" ) == 0 )
1774                 {
1775                         accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1776                 }
1777         else if( strcmp( id, "__protected__" ) == 0 )
1778                 {
1779                         accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1780                 }
1781         else if( strcmp( id, "__private__" ) == 0 )
1782                 {
1783                         /* OK, no change */
1784                 }
1785         else
1786                 {
1787                         Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1788                 }
1789         $3->addModeBits( accessSpec );
1790         $$ = $3;
1792 | '(' T_abstract OrderedFormals ')'
1794         $$ = new Ast::AbstractSection( @$, $3 );
1796 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1798         $$ = new Ast::OverridesSection( $3, $5 );
1802 MemberDeclarations
1805         $$ = new Ast::MemberSection;
1807 | OneOrMoreMemberDeclarations
1810 OneOrMoreMemberDeclarations
1811 : MemberDeclaration
1813         $$ = new Ast::MemberSection;
1814         $$->push_back( $1 );
1816 | OneOrMoreMemberDeclarations MemberDeclaration
1818         $$ = $1;
1819         $$->push_back( $2 );
1823 MemberDeclaration
1824 : '(' Identifier Expr ')'
1826         const char * id = $2->strip( @2 );
1827         $$ = new Ast::MemberDeclaration( @$, id, $3, 0 );
1829 | '(' Identifier Expr MemberAccessList ')'
1831         const char * id = $2->strip( @2 );
1832         $$ = new Ast::MemberDeclaration( @$, id, $3, $4 );
1836 MemberAccessList
1837 : MemberAccessSpecifier
1838 | MemberAccessList MemberAccessSpecifier
1840         $$ = $1 | $2;
1844 MemberAccessSpecifier
1845 : '.'
1847         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1849 | T_llthan
1851         $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1853 | '(' '#' '.' ')'
1855         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1857 | '(' '#' T_llthan ')'
1859         $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1861 | '^'
1863         $$ = Ast::MEMBER_TRANSFORMING;
1867 MethodDeclarations
1870         $$ = new Ast::MemberSection;
1872 | OneOrMoreMethodDeclarations
1875 OneOrMoreMethodDeclarations
1876 : MethodDeclaration
1878         $$ = new Ast::MemberSection;
1879         $$->push_back( $1 );
1881 | OneOrMoreMethodDeclarations MethodDeclaration
1883         $$ = $1;
1884         $$->push_back( $2 );
1888 MethodDeclaration
1889 : '(' Identifier Expr ')'
1891         const char * id = $2->strip( @2 );
1892         $$ = new Ast::MemberDeclaration( @$, id, $3, Ast::MEMBER_CONST | Ast::MEMBER_METHOD );
1894 | '(' '[' Identifier Formals ']' FunctionModeList GroupElem ')'
1896         const char * id = $3->strip( @3 );
1897         Ast::Expression * body = dynamic_cast< Ast::Expression * >( $7 );
1898         if( body == 0 )
1899                 {
1900                         std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1901                         bracket->push_back( $7 );
1902                         body = new Ast::CodeBracket( @7, bracket );
1903                 }
1904         Ast::ArgListExprs * args = new Ast::ArgListExprs( false );
1905         Ast::FunctionFunction * res = new Ast::FunctionFunction( @$, $4, body, $6 );
1906         res->push_exprs( args );
1907         $$ = new Ast::MemberDeclaration( @$, id, new Ast::CallExpr( @$,
1908                                                                                                                                                                                                                                                         RefCountPtr< const Lang::Function >( res ),
1909                                                                                                                                                                                                                                                         args ),
1910                                                                                                                                          Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1914 FunctionModeList
1917         $$ = 0;
1919 | OneOrMoreFunctionModeSpecifiers
1922 OneOrMoreFunctionModeSpecifiers
1923 : FunctionModeSpecifier
1924 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1926         $$ = $1 | $2;
1930 FunctionModeSpecifier
1931 : '^'
1933         $$ = Ast::FUNCTION_TRANSFORMING;
1937 Split
1938 : T_split Expr
1940         $$ = $2;
1944 Identifier
1945 : T_pathed_identifier
1946 | T_identifier_tex
1947 | T_identifier_except_tex
1953 /* The closing %% above marks the end of the Rules section and the beginning
1954  * of the User Subroutines section. All text from here to the end of the
1955  * file is copied verbatim to the end of the generated y.tab.c file.
1956  * This section is where you put definitions of helper functions.
1957  */