1 /* This file is part of Shapes.
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
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.
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/>.
16 * Copyright 2008, 2010, 2014 Henrik Tidefelt
19 /* File: shapesparser.y
21 * Yacc input file to generate the parser for the Shapes language
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
32 #include "shapestypes.h"
37 #include "astvalues.h"
40 #include "shapesexceptions.h"
42 #include "charptrless.h"
43 #include "autoonoff.h"
44 #include "shapescore.h"
45 #include "texlabelmanager.h"
47 using namespace Shapes;
49 extern YYLTYPE shapeslloc;
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.
60 #include "shapesscanner.h"
63 return Ast::theShapesScanner.yylex( );
65 #define yylex 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.
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.
110 Ast::Expression * expr;
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;
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;
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.
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
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.
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
203 %type <stateReference> StateReference
204 %type <splitFormals> SplitFormals OneOrMoreSplitFormals
205 %type <ident> Identifier
207 %nonassoc T_assign ':'
214 %left T_emptybrackets T_dddotbrackets T_ggthan
217 %left T_ampersandMore
219 %nonassoc T_dynamiccolon
225 %nonassoc T_eqeq T_eqneq T_lesseq T_greatereq
227 %left T_plusplus T_minusminus
232 %left '*' '/' T_projection
240 %left T_atat T_surrounding
246 %name-prefix "shapes"
250 * All productions and actions should be placed between the start and stop
251 * %% markers which delimit the Rules section.
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 = $$;
263 | T_interactiveMark Group T_EOF
265 Ast::theInteractiveInput = $2;
270 shapeserror( "Expecting end of file." );
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,
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,
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,
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,
318 : '(' Expr '^' Expr ')'
320 $$ = new Ast::PolarHandle2DExpr( @$, $2, $4 );
324 $$ = new Ast::PolarHandle2DExprFree_a( @$, $2 );
328 Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
329 args->orderedExprs_->push_back( $3 );
330 $$ = new Ast::CallExpr( @$,
331 Ast::THE_FUNCTION_polarHandle2DFree_r,
336 Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
337 $$ = new Ast::CallExpr( @$,
338 Ast::THE_FUNCTION_polarHandle2DFree_ra,
346 $$ = new Ast::LexiographicState( @1, $1, new Kernel::Environment::LexicalKey * ( 0 ) );
348 | T_dynamic_state_identifier
350 $$ = new Ast::DynamicState( @1, $1 );
357 $$ = new Ast::ArgListExprs( true );
359 | OneOrMoreArgListItems
362 OneOrMoreArgListItems
365 $$ = new Ast::ArgListExprs( true );
366 $$->orderedExprs_->push_back( $1 );
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
388 if( ! $$->namedExprs_->empty( ) )
390 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed expressions may not appear among named expressions." ) ) );
392 $$->orderedExprs_->push_back( $2 );
394 | OneOrMoreArgListItems StateReference
397 if( ! $$->namedStates_->empty( ) )
399 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Unnamed states may not appear among named states." ) ) );
401 $$->orderedStates_->push_back( $2 );
403 | OneOrMoreArgListItems Identifier ':' Expr
406 const char * id = $2->strip( @2 );
407 if( $$->namedExprs_->find( id ) != $$->namedExprs_->end( ) )
409 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id ) );
411 (*$$->namedExprs_)[ id ] = $4;
413 | OneOrMoreArgListItems T_state_identifier ':' StateReference
416 const char * id( $2->strip( @2 ) );
417 if( $$->namedStates_->find( id ) != $$->namedStates_->end( ) )
419 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id ) );
421 (*$$->namedStates_)[ id ] = $4;
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( @$,
441 Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
442 args->orderedExprs_->push_back( $1 );
443 $$ = new Ast::CallExpr( @$,
447 | Expr T_emptybrackets Split
449 $$ = new Ast::CallSplitExpr( @$,
453 | Expr T_dddotbrackets Expr
455 Ast::ArgListExprs * args = new Ast::ArgListExprs( true );
456 args->orderedExprs_->push_back( $3 );
457 $$ = new Ast::CallExpr( @$,
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( @$,
470 true ); /* true means Curry */
472 | Expr T_dddotbrackets Split
474 $$ = new Ast::CallSplitExpr( @$,
477 true ); /* true means Curry */
483 : '[' Expr ArgList T_dddot ']'
485 $$ = new Ast::CallExpr( @$, $2, $3, true ); /* true means Curry */
487 | '(' 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 ),
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 ),
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 ),
522 res->setMutatorSelf( $1 );
530 $$ = new Kernel::Formals( );
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.
545 | OneOrMoreFormalsItems
550 | OneOrMoreFormalsItems T_split Identifier
552 Ast::PlacedIdentifier * id = $3->place( @3 );
554 if( ! $$->appendArgumentFormal( *id ) )
556 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @3, id->strip( ) ) );
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.
567 OneOrMoreFormalsItems
570 $$ = new Kernel::Formals( );
571 Ast::PlacedIdentifier * id = $1->place( @1 );
572 $$->appendArgumentFormal( *id );
574 $$->defaultExprs_.push_back( NULL );
576 | Identifier ':' Expr
578 $$ = new Kernel::Formals( );
579 Ast::PlacedIdentifier * id = $1->place( @1 );
580 $$->appendArgumentFormal( *id );
582 $$->defaultExprs_.push_back( $3 );
586 $$ = new Kernel::Formals( );
587 Ast::PlacedIdentifier * id = $1->place( @1 );
588 $$->appendStateFormal( *id );
591 | OneOrMoreFormalsItems Identifier
594 Ast::PlacedIdentifier * id = $2->place( @2 );
595 if( $$->seenDefault_ )
597 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
599 if( ! $$->appendArgumentFormal( *id ) )
601 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
604 $$->defaultExprs_.push_back( NULL );
606 | OneOrMoreFormalsItems Identifier ':' Expr
609 Ast::PlacedIdentifier * id = $2->place( @2 );
610 $$->seenDefault_ = true;
611 if( ! $$->appendArgumentFormal( *id ) )
613 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
616 $$->defaultExprs_.push_back( $4 );
618 | OneOrMoreFormalsItems T_state_identifier
621 Ast::PlacedIdentifier * id = $2->place( @2 );
622 if( ! $$->appendStateFormal( *id ) )
624 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedFormal( @2, id->strip( ) ) );
634 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "The list of split assignment variables must not be empty." ) ) );
635 $$ = new Ast::SplitDefineVariables( );
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
646 | OneOrMoreSplitFormals T_split Identifier
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
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 ),
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 ),
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 ),
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 ),
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 ),
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 ),
720 | OneOrMoreSplitFormals Identifier
723 Ast::PlacedIdentifier * id = $2->place( @2 );
726 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
728 if( $$->seenDefault_ )
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." ) ) );
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 ),
738 | OneOrMoreSplitFormals Identifier ':' Expr
741 Ast::PlacedIdentifier * id = $2->place( @2 );
744 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "Order-based formals may not appear among named formals." ) ) );
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 ),
753 | OneOrMoreSplitFormals Identifier ':' '.' Identifier
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 ),
765 | OneOrMoreSplitFormals Identifier ':' '.' Identifier ':' Expr
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 ),
777 | OneOrMoreSplitFormals Identifier ':' '.' '\"'
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 ),
788 | OneOrMoreSplitFormals Identifier ':' '.' '\"' ':' Expr
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 ),
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 ),
812 | '(' OperatorFunction ')'
816 | ParenOperatorFunction
825 $$ = new list< RefCountPtr< const char > >( );
827 | OneOrMoreOrderedFormals
830 OneOrMoreOrderedFormals
833 $$ = new list< RefCountPtr< const char > >( );
834 RefCountPtr< const char > id = $1->refstrip( @1 );
837 | OneOrMoreOrderedFormals Identifier
840 RefCountPtr< const char > id = $2->refstrip( @2 );
848 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUSMINUS ) );
852 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUSPLUS ) );
856 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND ) );
860 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Ast::THE_FUNCTION_fcons ) );
864 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PLUS ) );
868 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_MINUS ) );
872 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_STAR ) );
876 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_SLASH ) );
880 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_PROJECTION ) );
884 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_ANGLE ) );
888 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_AMPERSAND_MORE ) );
892 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NEG ) );
896 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_COMPOSE ) );
900 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
904 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
908 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQEQ ) );
912 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_EQNEQ ) );
916 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
920 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
924 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_NOT ) );
928 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_AND ) );
932 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_FUNCTION_OR ) );
936 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_XOR ) );
940 ParenOperatorFunction
943 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESS ) );
947 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATER ) );
951 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_LESSEQ ) );
955 $$ = new Ast::Constant( @$, static_cast< RefCountPtr< const Lang::Value > >( Lang::THE_OPERATOR_GREATEREQ ) );
960 : ExprExceptConstStrings
963 $$ = new Ast::Constant( @1, $1 );
967 ExprExceptConstStrings
968 : ConstantExceptStrings
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,
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,
994 $$ = new Ast::Force( @$, $2 );
999 | SuperMemberReference
1007 $$ = new Ast::NegExpr( @$, @2, $3 );
1011 $$ = new Ast::RelativeExpr( @$, @2, $3 );
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( ),
1029 for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
1031 Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
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( ),
1042 bracket->push_back( call );
1046 bracket->push_back( new Ast::Insertion( dst, *i ) );
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 );
1061 Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1062 $$ = new Ast::LexiographicVariable( @$, $1, key );
1066 /* $1 contains a placed identifier just for communicating the namespace at the point of the
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 ),
1077 | T_dynamic_identifier
1079 $$ = new Ast::DynamicVariable( @$, $1 );
1081 | '(' StateReference ')'
1083 $$ = new Ast::Peek( @$, $2 );
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 ),
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 ),
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.
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 );
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
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 ;
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,
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 );
1180 $$ = new Ast::AmpersandExpr( @2, $1, $3 );
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,
1193 $$ = new Ast::PlusExpr( @2, $1, $3 );
1197 $$ = new Ast::MinusExpr( @2, $1, $3 );
1201 $$ = new Ast::AngleExpr( @2, $1, $3 );
1203 | Expr T_ampersandMore Expr
1205 $$ = new Ast::AmpersandMoreExpr( @2, $1, $3 );
1209 $$ = new Ast::StarExpr( @2, $1, $3 );
1211 | Expr T_projection Expr
1213 $$ = new Ast::ProjectionExpr( @2, $1, $3 );
1217 $$ = new Ast::SlashExpr( @2, $1, $3 );
1221 $$ = new Ast::NegExpr( @1, $2 );
1223 | Expr T_compose Expr
1225 $$ = new Ast::ComposeExpr( @2, $1, $3 );
1229 $$ = new Ast::LessExpr( @2, $1, $3 );
1233 $$ = new Ast::GreaterExpr( @2, $1, $3 );
1237 $$ = new Ast::EqualExpr( @2, $1, $3 );
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 );
1253 $$ = new Ast::NotExpr( @1, $2 );
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,
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,
1279 $$ = new Ast::XorExpr( @2, $1, $3 );
1283 Kernel::Environment::LexicalKey ** key = new Kernel::Environment::LexicalKey * ( 0 );
1284 $$ = new Ast::LexiographicType( @$, $1, key );
1288 $$ = new Ast::SpanLastExpr( @$ );
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
1314 $$ = new Ast::Constant( @1, new Lang::Float( $1 ) );
1318 $$ = new Ast::Constant( @1, new Lang::Length( $1 ) );
1322 $$ = new Ast::Constant( @1, new Lang::Integer( $1 ) );
1326 $$ = new Ast::Constant( @1, new Lang::Boolean( $1 ) );
1330 $$ = new Ast::Constant( @1, new Lang::Symbol( $1 ) );
1334 $$ = new Ast::Constant( @1, new Lang::Character( $1 ) );
1341 $$ = new Ast::CodeBracket( @$, $2 );
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 ) );
1410 $$ = new Ast::SourceLocationMark( @$ );
1417 $$ = new std::list< Ast::Expression * >( );
1418 $$->push_back( $1 );
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
1433 $$->push_back( $3 );
1435 | InsertionSequence T_llthan T_ggthan Expr
1438 Ast::SourceLocation loc( @3, @4 );
1439 $$->push_back( new Ast::InsertionMutatorCall( loc, $4 ) );
1441 | InsertionSequence T_llthan T_ggthan MutatorCallbackExpr
1444 Ast::SourceLocation loc( @3, @4 );
1445 $$->push_back( new Ast::InsertionMutatorCall( loc, $4 ) );
1452 $$ = new list< Ast::Node * >( );
1453 $$->push_back( $1 );
1455 | OneOrMoreGroupElems GroupElem
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 )
1466 Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
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( ),
1477 $$->push_back( call );
1481 $$->push_back( new Ast::Insertion( $1, *i ) );
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. */
1489 for( std::list< Ast::Expression * >::iterator i = $4->begin( ); i != $4->end( ); ++i )
1491 Ast::InsertionMutatorCall * mutExpr = dynamic_cast< Ast::InsertionMutatorCall * >( *i );
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( ),
1502 $$->push_back( call );
1506 $$->push_back( new Ast::Insertion( $2, *i ) );
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 )
1523 i->second->setStruct( @5, pos );
1524 $$->push_back( i->first );
1525 if( i->second->isOrdered( ) )
1531 if( $2->sinkDefine_ != 0 )
1533 $2->sinkExpr_->setStruct( @5, pos, orderedCount );
1534 $$->push_back( $2->sinkDefine_ );
1538 $$->push_back( new Ast::AssertNoSinkNeeded( @2, orderedCount, @5, pos ) );
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
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 )
1560 i->second->setStruct( @6, pos );
1561 $$->push_back( i->first );
1562 if( i->second->isOrdered( ) )
1568 if( $3->sinkDefine_ != 0 )
1570 $3->sinkExpr_->setStruct( @6, pos, orderedCount );
1571 $$->push_back( $3->sinkDefine_ );
1575 $$->push_back( new Ast::AssertNoSinkNeeded( @3, orderedCount, @6, pos ) );
1578 | OneOrMoreGroupElems T_splitLeft SplitFormals T_splitRight Expr
1580 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @4, strrefdup( "Expected ':'." ) ) );
1582 $$->push_back( new Ast::ErrorExpression( @$ ) );
1584 | T_namespaceSpecial
1586 $$ = new list< Ast::Node * >( );
1588 | OneOrMoreGroupElems T_namespaceSpecial
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 ),
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 );
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 ),
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 ),
1654 : '[' T_class '(' Expr Formals ')' Identifier '(' ListOfParentsWithInitargs ')'
1659 const char * id = $7->strip( @7 );
1660 DeleteOnExit< const char > isaDeleter( id );
1661 if( strcmp( id, "isa" ) != 0 )
1663 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @7, strrefdup( "Expected \"isa\"." ) ) );
1665 if( ( $11 & Ast::CLASS_MODE_ABSTRACT ) != 0 && ( $11 & Ast::CLASS_MODE_FINAL ) != 0 )
1667 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @11, strrefdup( "Declaring a class both abstract and final is forbidden." ) ) );
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 ),
1679 ListOfParentsWithInitargs
1680 : '(' Expr ArgList ')'
1682 $$ = new std::list< const Ast::CallExpr * >;
1683 $$->push_back( new Ast::CallExpr( @$, $2, $3 ) );
1685 | ListOfParentsWithInitargs '(' Expr ArgList ')'
1688 Ast::SourceLocation loc( @2, @5 );
1689 $$->push_back( new Ast::CallExpr( loc, $3, $4 ) );
1698 | OneOrMoreClassModeSpecifiers
1701 OneOrMoreClassModeSpecifiers
1702 : ClassModeSpecifier
1703 | OneOrMoreClassModeSpecifiers ClassModeSpecifier
1712 const char * id = $1->strip( @1 );
1713 DeleteOnExit< const char > strDeleter( id );
1715 if( strcmp( id, "abstract" ) == 0 )
1717 $$ = Ast::CLASS_MODE_ABSTRACT;
1719 else if( strcmp( id, "final" ) == 0 )
1721 $$ = Ast::CLASS_MODE_FINAL;
1725 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @$, strrefdup( "This is not a valid class mode specifier" ) ) );
1733 $$ = new std::list< Ast::ClassSection * >;
1735 | OneOrMoreClassSections
1738 OneOrMoreClassSections
1741 $$ = new std::list< Ast::ClassSection * >;
1742 $$->push_back( $1 );
1744 | OneOrMoreClassSections ClassSection
1747 $$->push_back( $2 );
1752 : '(' T_members MemberDeclarations ')'
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 )
1767 accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1769 else if( strcmp( id, "__abstract__" ) == 0 )
1771 accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ABSTRACT;
1773 else if( strcmp( id, "__final__" ) == 0 )
1775 accessSpec = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_FINAL;
1777 else if( strcmp( id, "__protected__" ) == 0 )
1779 accessSpec = Ast::MEMBER_ACCESS_PROTECTED_GET;
1781 else if( strcmp( id, "__private__" ) == 0 )
1787 Ast::theAnalysisErrorsList.push_back( new Exceptions::ParserError( @2, strrefdup( "This is not a valid method access specifier." ) ) );
1789 $3->addModeBits( accessSpec );
1792 | '(' T_abstract OrderedFormals ')'
1794 $$ = new Ast::AbstractSection( @$, $3 );
1796 | '(' T_overrides Expr T_gr__ MethodDeclarations ')'
1798 $$ = new Ast::OverridesSection( $3, $5 );
1805 $$ = new Ast::MemberSection;
1807 | OneOrMoreMemberDeclarations
1810 OneOrMoreMemberDeclarations
1813 $$ = new Ast::MemberSection;
1814 $$->push_back( $1 );
1816 | OneOrMoreMemberDeclarations MemberDeclaration
1819 $$->push_back( $2 );
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 );
1837 : MemberAccessSpecifier
1838 | MemberAccessList MemberAccessSpecifier
1844 MemberAccessSpecifier
1847 $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PROTECTED_GET;
1851 $$ = Ast::MEMBER_ACCESS_PUBLIC_GET | Ast::MEMBER_ACCESS_PUBLIC_INSERT | Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1855 $$ = Ast::MEMBER_ACCESS_PROTECTED_GET;
1857 | '(' '#' T_llthan ')'
1859 $$ = Ast::MEMBER_ACCESS_PROTECTED_GET | Ast::MEMBER_ACCESS_PROTECTED_INSERT;
1863 $$ = Ast::MEMBER_TRANSFORMING;
1870 $$ = new Ast::MemberSection;
1872 | OneOrMoreMethodDeclarations
1875 OneOrMoreMethodDeclarations
1878 $$ = new Ast::MemberSection;
1879 $$->push_back( $1 );
1881 | OneOrMoreMethodDeclarations MethodDeclaration
1884 $$->push_back( $2 );
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 );
1900 std::list< Ast::Node * > * bracket = new std::list< Ast::Node * >( );
1901 bracket->push_back( $7 );
1902 body = new Ast::CodeBracket( @7, bracket );
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 ),
1910 Ast::MEMBER_CONST | Ast::MEMBER_METHOD | ( (($6 & Ast::FUNCTION_TRANSFORMING) != 0) ? Ast::MEMBER_TRANSFORMING : 0 ) );
1919 | OneOrMoreFunctionModeSpecifiers
1922 OneOrMoreFunctionModeSpecifiers
1923 : FunctionModeSpecifier
1924 | OneOrMoreFunctionModeSpecifiers FunctionModeSpecifier
1930 FunctionModeSpecifier
1933 $$ = Ast::FUNCTION_TRANSFORMING;
1945 : T_pathed_identifier
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.