1 // A Bison parser, made by GNU Bison 3.7.2.
2 
3 // Skeleton implementation for Bison LALR(1) parsers in C++
4 
5 // Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
6 
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 
17 // You should have received a copy of the GNU General Public License
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 
20 // As a special exception, you may create a larger work that contains
21 // part or all of the Bison parser skeleton and distribute that work
22 // under terms of your choice, so long as that work isn't itself a
23 // parser generator using the skeleton or a modified version thereof
24 // as a parser skeleton.  Alternatively, if you modify or redistribute
25 // the parser skeleton itself, you may (at your option) remove this
26 // special exception, which will cause the skeleton and the resulting
27 // Bison output files to be licensed under the GNU General Public
28 // License without this special exception.
29 
30 // This special exception was added by the Free Software Foundation in
31 // version 2.2 of Bison.
32 
33 // DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
34 // especially those whose name start with YY_ or yy_.  They are
35 // private implementation details that can be changed or removed.
36 
37 
38 
39 
40 
41 #include "parser.hpp"
42 
43 
44 // Unqualified %code blocks.
45 
46     #include "pio_assembler.h"
47   #ifdef _MSC_VER
48   #pragma warning(disable : 4244) // possible loss of data (valid warning, but there is a software check / missing cast)
49   #endif
50 
51 
52 
53 #ifndef YY_
54 # if defined YYENABLE_NLS && YYENABLE_NLS
55 #  if ENABLE_NLS
56 #   include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
57 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
58 #  endif
59 # endif
60 # ifndef YY_
61 #  define YY_(msgid) msgid
62 # endif
63 #endif
64 
65 
66 // Whether we are compiled with exception support.
67 #ifndef YY_EXCEPTIONS
68 # if defined __GNUC__ && !defined __EXCEPTIONS
69 #  define YY_EXCEPTIONS 0
70 # else
71 #  define YY_EXCEPTIONS 1
72 # endif
73 #endif
74 
75 #define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
76 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
77    If N is 0, then set CURRENT to the empty location which ends
78    the previous symbol: RHS[0] (always defined).  */
79 
80 # ifndef YYLLOC_DEFAULT
81 #  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
82     do                                                                  \
83       if (N)                                                            \
84         {                                                               \
85           (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
86           (Current).end    = YYRHSLOC (Rhs, N).end;                     \
87         }                                                               \
88       else                                                              \
89         {                                                               \
90           (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
91         }                                                               \
92     while (false)
93 # endif
94 
95 
96 // Enable debugging if requested.
97 #if YYDEBUG
98 
99 // A pseudo ostream that takes yydebug_ into account.
100 # define YYCDEBUG if (yydebug_) (*yycdebug_)
101 
102 # define YY_SYMBOL_PRINT(Title, Symbol)         \
103   do {                                          \
104     if (yydebug_)                               \
105     {                                           \
106       *yycdebug_ << Title << ' ';               \
107       yy_print_ (*yycdebug_, Symbol);           \
108       *yycdebug_ << '\n';                       \
109     }                                           \
110   } while (false)
111 
112 # define YY_REDUCE_PRINT(Rule)          \
113   do {                                  \
114     if (yydebug_)                       \
115       yy_reduce_print_ (Rule);          \
116   } while (false)
117 
118 # define YY_STACK_PRINT()               \
119   do {                                  \
120     if (yydebug_)                       \
121       yy_stack_print_ ();                \
122   } while (false)
123 
124 #else // !YYDEBUG
125 
126 # define YYCDEBUG if (false) std::cerr
127 # define YY_SYMBOL_PRINT(Title, Symbol)  YYUSE (Symbol)
128 # define YY_REDUCE_PRINT(Rule)           static_cast<void> (0)
129 # define YY_STACK_PRINT()                static_cast<void> (0)
130 
131 #endif // !YYDEBUG
132 
133 #define yyerrok         (yyerrstatus_ = 0)
134 #define yyclearin       (yyla.clear ())
135 
136 #define YYACCEPT        goto yyacceptlab
137 #define YYABORT         goto yyabortlab
138 #define YYERROR         goto yyerrorlab
139 #define YYRECOVERING()  (!!yyerrstatus_)
140 
141 namespace yy {
142 
143   /// Build a parser object.
parser(pio_assembler & pioasm_yyarg)144   parser::parser (pio_assembler& pioasm_yyarg)
145 #if YYDEBUG
146     : yydebug_ (false),
147       yycdebug_ (&std::cerr),
148 #else
149     :
150 #endif
151       yy_lac_established_ (false),
152       pioasm (pioasm_yyarg)
153   {}
154 
~parser()155   parser::~parser ()
156   {}
157 
~syntax_error()158   parser::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
159   {}
160 
161   /*---------------.
162   | symbol kinds.  |
163   `---------------*/
164 
165 
166 
167   // by_state.
by_state()168   parser::by_state::by_state () YY_NOEXCEPT
169     : state (empty_state)
170   {}
171 
by_state(const by_state & that)172   parser::by_state::by_state (const by_state& that) YY_NOEXCEPT
173     : state (that.state)
174   {}
175 
176   void
clear()177   parser::by_state::clear () YY_NOEXCEPT
178   {
179     state = empty_state;
180   }
181 
182   void
move(by_state & that)183   parser::by_state::move (by_state& that)
184   {
185     state = that.state;
186     that.clear ();
187   }
188 
by_state(state_type s)189   parser::by_state::by_state (state_type s) YY_NOEXCEPT
190     : state (s)
191   {}
192 
193   parser::symbol_kind_type
kind() const194   parser::by_state::kind () const YY_NOEXCEPT
195   {
196     if (state == empty_state)
197       return symbol_kind::S_YYEMPTY;
198     else
199       return YY_CAST (symbol_kind_type, yystos_[+state]);
200   }
201 
stack_symbol_type()202   parser::stack_symbol_type::stack_symbol_type ()
203   {}
204 
stack_symbol_type(YY_RVREF (stack_symbol_type)that)205   parser::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that)
206     : super_type (YY_MOVE (that.state), YY_MOVE (that.location))
207   {
208     switch (that.kind ())
209     {
210       case symbol_kind::S_if_full: // if_full
211       case symbol_kind::S_if_empty: // if_empty
212       case symbol_kind::S_blocking: // blocking
213         value.YY_MOVE_OR_COPY< bool > (YY_MOVE (that.value));
214         break;
215 
216       case symbol_kind::S_condition: // condition
217         value.YY_MOVE_OR_COPY< enum condition > (YY_MOVE (that.value));
218         break;
219 
220       case symbol_kind::S_in_source: // in_source
221       case symbol_kind::S_out_target: // out_target
222       case symbol_kind::S_set_target: // set_target
223         value.YY_MOVE_OR_COPY< enum in_out_set > (YY_MOVE (that.value));
224         break;
225 
226       case symbol_kind::S_irq_modifiers: // irq_modifiers
227         value.YY_MOVE_OR_COPY< enum irq > (YY_MOVE (that.value));
228         break;
229 
230       case symbol_kind::S_mov_target: // mov_target
231       case symbol_kind::S_mov_source: // mov_source
232         value.YY_MOVE_OR_COPY< enum mov > (YY_MOVE (that.value));
233         break;
234 
235       case symbol_kind::S_mov_op: // mov_op
236         value.YY_MOVE_OR_COPY< enum mov_op > (YY_MOVE (that.value));
237         break;
238 
239       case symbol_kind::S_INT: // "integer"
240         value.YY_MOVE_OR_COPY< int > (YY_MOVE (that.value));
241         break;
242 
243       case symbol_kind::S_instruction: // instruction
244       case symbol_kind::S_base_instruction: // base_instruction
245         value.YY_MOVE_OR_COPY< std::shared_ptr<instruction> > (YY_MOVE (that.value));
246         break;
247 
248       case symbol_kind::S_value: // value
249       case symbol_kind::S_expression: // expression
250       case symbol_kind::S_delay: // delay
251       case symbol_kind::S_sideset: // sideset
252         value.YY_MOVE_OR_COPY< std::shared_ptr<resolvable> > (YY_MOVE (that.value));
253         break;
254 
255       case symbol_kind::S_label_decl: // label_decl
256       case symbol_kind::S_symbol_def: // symbol_def
257         value.YY_MOVE_OR_COPY< std::shared_ptr<symbol> > (YY_MOVE (that.value));
258         break;
259 
260       case symbol_kind::S_wait_source: // wait_source
261         value.YY_MOVE_OR_COPY< std::shared_ptr<wait_source> > (YY_MOVE (that.value));
262         break;
263 
264       case symbol_kind::S_ID: // "identifier"
265       case symbol_kind::S_STRING: // "string"
266       case symbol_kind::S_NON_WS: // "text"
267       case symbol_kind::S_CODE_BLOCK_START: // "code block"
268       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
269       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
270         value.YY_MOVE_OR_COPY< std::string > (YY_MOVE (that.value));
271         break;
272 
273       default:
274         break;
275     }
276 
277 #if 201103L <= YY_CPLUSPLUS
278     // that is emptied.
279     that.state = empty_state;
280 #endif
281   }
282 
stack_symbol_type(state_type s,YY_MOVE_REF (symbol_type)that)283   parser::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that)
284     : super_type (s, YY_MOVE (that.location))
285   {
286     switch (that.kind ())
287     {
288       case symbol_kind::S_if_full: // if_full
289       case symbol_kind::S_if_empty: // if_empty
290       case symbol_kind::S_blocking: // blocking
291         value.move< bool > (YY_MOVE (that.value));
292         break;
293 
294       case symbol_kind::S_condition: // condition
295         value.move< enum condition > (YY_MOVE (that.value));
296         break;
297 
298       case symbol_kind::S_in_source: // in_source
299       case symbol_kind::S_out_target: // out_target
300       case symbol_kind::S_set_target: // set_target
301         value.move< enum in_out_set > (YY_MOVE (that.value));
302         break;
303 
304       case symbol_kind::S_irq_modifiers: // irq_modifiers
305         value.move< enum irq > (YY_MOVE (that.value));
306         break;
307 
308       case symbol_kind::S_mov_target: // mov_target
309       case symbol_kind::S_mov_source: // mov_source
310         value.move< enum mov > (YY_MOVE (that.value));
311         break;
312 
313       case symbol_kind::S_mov_op: // mov_op
314         value.move< enum mov_op > (YY_MOVE (that.value));
315         break;
316 
317       case symbol_kind::S_INT: // "integer"
318         value.move< int > (YY_MOVE (that.value));
319         break;
320 
321       case symbol_kind::S_instruction: // instruction
322       case symbol_kind::S_base_instruction: // base_instruction
323         value.move< std::shared_ptr<instruction> > (YY_MOVE (that.value));
324         break;
325 
326       case symbol_kind::S_value: // value
327       case symbol_kind::S_expression: // expression
328       case symbol_kind::S_delay: // delay
329       case symbol_kind::S_sideset: // sideset
330         value.move< std::shared_ptr<resolvable> > (YY_MOVE (that.value));
331         break;
332 
333       case symbol_kind::S_label_decl: // label_decl
334       case symbol_kind::S_symbol_def: // symbol_def
335         value.move< std::shared_ptr<symbol> > (YY_MOVE (that.value));
336         break;
337 
338       case symbol_kind::S_wait_source: // wait_source
339         value.move< std::shared_ptr<wait_source> > (YY_MOVE (that.value));
340         break;
341 
342       case symbol_kind::S_ID: // "identifier"
343       case symbol_kind::S_STRING: // "string"
344       case symbol_kind::S_NON_WS: // "text"
345       case symbol_kind::S_CODE_BLOCK_START: // "code block"
346       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
347       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
348         value.move< std::string > (YY_MOVE (that.value));
349         break;
350 
351       default:
352         break;
353     }
354 
355     // that is emptied.
356     that.kind_ = symbol_kind::S_YYEMPTY;
357   }
358 
359 #if YY_CPLUSPLUS < 201103L
360   parser::stack_symbol_type&
operator =(const stack_symbol_type & that)361   parser::stack_symbol_type::operator= (const stack_symbol_type& that)
362   {
363     state = that.state;
364     switch (that.kind ())
365     {
366       case symbol_kind::S_if_full: // if_full
367       case symbol_kind::S_if_empty: // if_empty
368       case symbol_kind::S_blocking: // blocking
369         value.copy< bool > (that.value);
370         break;
371 
372       case symbol_kind::S_condition: // condition
373         value.copy< enum condition > (that.value);
374         break;
375 
376       case symbol_kind::S_in_source: // in_source
377       case symbol_kind::S_out_target: // out_target
378       case symbol_kind::S_set_target: // set_target
379         value.copy< enum in_out_set > (that.value);
380         break;
381 
382       case symbol_kind::S_irq_modifiers: // irq_modifiers
383         value.copy< enum irq > (that.value);
384         break;
385 
386       case symbol_kind::S_mov_target: // mov_target
387       case symbol_kind::S_mov_source: // mov_source
388         value.copy< enum mov > (that.value);
389         break;
390 
391       case symbol_kind::S_mov_op: // mov_op
392         value.copy< enum mov_op > (that.value);
393         break;
394 
395       case symbol_kind::S_INT: // "integer"
396         value.copy< int > (that.value);
397         break;
398 
399       case symbol_kind::S_instruction: // instruction
400       case symbol_kind::S_base_instruction: // base_instruction
401         value.copy< std::shared_ptr<instruction> > (that.value);
402         break;
403 
404       case symbol_kind::S_value: // value
405       case symbol_kind::S_expression: // expression
406       case symbol_kind::S_delay: // delay
407       case symbol_kind::S_sideset: // sideset
408         value.copy< std::shared_ptr<resolvable> > (that.value);
409         break;
410 
411       case symbol_kind::S_label_decl: // label_decl
412       case symbol_kind::S_symbol_def: // symbol_def
413         value.copy< std::shared_ptr<symbol> > (that.value);
414         break;
415 
416       case symbol_kind::S_wait_source: // wait_source
417         value.copy< std::shared_ptr<wait_source> > (that.value);
418         break;
419 
420       case symbol_kind::S_ID: // "identifier"
421       case symbol_kind::S_STRING: // "string"
422       case symbol_kind::S_NON_WS: // "text"
423       case symbol_kind::S_CODE_BLOCK_START: // "code block"
424       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
425       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
426         value.copy< std::string > (that.value);
427         break;
428 
429       default:
430         break;
431     }
432 
433     location = that.location;
434     return *this;
435   }
436 
437   parser::stack_symbol_type&
operator =(stack_symbol_type & that)438   parser::stack_symbol_type::operator= (stack_symbol_type& that)
439   {
440     state = that.state;
441     switch (that.kind ())
442     {
443       case symbol_kind::S_if_full: // if_full
444       case symbol_kind::S_if_empty: // if_empty
445       case symbol_kind::S_blocking: // blocking
446         value.move< bool > (that.value);
447         break;
448 
449       case symbol_kind::S_condition: // condition
450         value.move< enum condition > (that.value);
451         break;
452 
453       case symbol_kind::S_in_source: // in_source
454       case symbol_kind::S_out_target: // out_target
455       case symbol_kind::S_set_target: // set_target
456         value.move< enum in_out_set > (that.value);
457         break;
458 
459       case symbol_kind::S_irq_modifiers: // irq_modifiers
460         value.move< enum irq > (that.value);
461         break;
462 
463       case symbol_kind::S_mov_target: // mov_target
464       case symbol_kind::S_mov_source: // mov_source
465         value.move< enum mov > (that.value);
466         break;
467 
468       case symbol_kind::S_mov_op: // mov_op
469         value.move< enum mov_op > (that.value);
470         break;
471 
472       case symbol_kind::S_INT: // "integer"
473         value.move< int > (that.value);
474         break;
475 
476       case symbol_kind::S_instruction: // instruction
477       case symbol_kind::S_base_instruction: // base_instruction
478         value.move< std::shared_ptr<instruction> > (that.value);
479         break;
480 
481       case symbol_kind::S_value: // value
482       case symbol_kind::S_expression: // expression
483       case symbol_kind::S_delay: // delay
484       case symbol_kind::S_sideset: // sideset
485         value.move< std::shared_ptr<resolvable> > (that.value);
486         break;
487 
488       case symbol_kind::S_label_decl: // label_decl
489       case symbol_kind::S_symbol_def: // symbol_def
490         value.move< std::shared_ptr<symbol> > (that.value);
491         break;
492 
493       case symbol_kind::S_wait_source: // wait_source
494         value.move< std::shared_ptr<wait_source> > (that.value);
495         break;
496 
497       case symbol_kind::S_ID: // "identifier"
498       case symbol_kind::S_STRING: // "string"
499       case symbol_kind::S_NON_WS: // "text"
500       case symbol_kind::S_CODE_BLOCK_START: // "code block"
501       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
502       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
503         value.move< std::string > (that.value);
504         break;
505 
506       default:
507         break;
508     }
509 
510     location = that.location;
511     // that is emptied.
512     that.state = empty_state;
513     return *this;
514   }
515 #endif
516 
517   template <typename Base>
518   void
yy_destroy_(const char * yymsg,basic_symbol<Base> & yysym) const519   parser::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const
520   {
521     if (yymsg)
522       YY_SYMBOL_PRINT (yymsg, yysym);
523   }
524 
525 #if YYDEBUG
526   template <typename Base>
527   void
yy_print_(std::ostream & yyo,const basic_symbol<Base> & yysym) const528   parser::yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const
529   {
530     std::ostream& yyoutput = yyo;
531     YYUSE (yyoutput);
532     if (yysym.empty ())
533       yyo << "empty symbol";
534     else
535       {
536         symbol_kind_type yykind = yysym.kind ();
537         yyo << (yykind < YYNTOKENS ? "token" : "nterm")
538             << ' ' << yysym.name () << " ("
539             << yysym.location << ": ";
540         switch (yykind)
541     {
542       case symbol_kind::S_ID: // "identifier"
543                  { yyo << "..."; }
544         break;
545 
546       case symbol_kind::S_STRING: // "string"
547                  { yyo << "..."; }
548         break;
549 
550       case symbol_kind::S_NON_WS: // "text"
551                  { yyo << "..."; }
552         break;
553 
554       case symbol_kind::S_CODE_BLOCK_START: // "code block"
555                  { yyo << "..."; }
556         break;
557 
558       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
559                  { yyo << "..."; }
560         break;
561 
562       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
563                  { yyo << "..."; }
564         break;
565 
566       case symbol_kind::S_INT: // "integer"
567                  { yyo << "..."; }
568         break;
569 
570       case symbol_kind::S_label_decl: // label_decl
571                  { yyo << "..."; }
572         break;
573 
574       case symbol_kind::S_value: // value
575                  { yyo << "..."; }
576         break;
577 
578       case symbol_kind::S_expression: // expression
579                  { yyo << "..."; }
580         break;
581 
582       case symbol_kind::S_instruction: // instruction
583                  { yyo << "..."; }
584         break;
585 
586       case symbol_kind::S_base_instruction: // base_instruction
587                  { yyo << "..."; }
588         break;
589 
590       case symbol_kind::S_delay: // delay
591                  { yyo << "..."; }
592         break;
593 
594       case symbol_kind::S_sideset: // sideset
595                  { yyo << "..."; }
596         break;
597 
598       case symbol_kind::S_condition: // condition
599                  { yyo << "..."; }
600         break;
601 
602       case symbol_kind::S_wait_source: // wait_source
603                  { yyo << "..."; }
604         break;
605 
606       case symbol_kind::S_in_source: // in_source
607                  { yyo << "..."; }
608         break;
609 
610       case symbol_kind::S_out_target: // out_target
611                  { yyo << "..."; }
612         break;
613 
614       case symbol_kind::S_mov_target: // mov_target
615                  { yyo << "..."; }
616         break;
617 
618       case symbol_kind::S_mov_source: // mov_source
619                  { yyo << "..."; }
620         break;
621 
622       case symbol_kind::S_mov_op: // mov_op
623                  { yyo << "..."; }
624         break;
625 
626       case symbol_kind::S_set_target: // set_target
627                  { yyo << "..."; }
628         break;
629 
630       case symbol_kind::S_if_full: // if_full
631                  { yyo << "..."; }
632         break;
633 
634       case symbol_kind::S_if_empty: // if_empty
635                  { yyo << "..."; }
636         break;
637 
638       case symbol_kind::S_blocking: // blocking
639                  { yyo << "..."; }
640         break;
641 
642       case symbol_kind::S_irq_modifiers: // irq_modifiers
643                  { yyo << "..."; }
644         break;
645 
646       case symbol_kind::S_symbol_def: // symbol_def
647                  { yyo << "..."; }
648         break;
649 
650       default:
651         break;
652     }
653         yyo << ')';
654       }
655   }
656 #endif
657 
658   void
yypush_(const char * m,YY_MOVE_REF (stack_symbol_type)sym)659   parser::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym)
660   {
661     if (m)
662       YY_SYMBOL_PRINT (m, sym);
663     yystack_.push (YY_MOVE (sym));
664   }
665 
666   void
yypush_(const char * m,state_type s,YY_MOVE_REF (symbol_type)sym)667   parser::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym)
668   {
669 #if 201103L <= YY_CPLUSPLUS
670     yypush_ (m, stack_symbol_type (s, std::move (sym)));
671 #else
672     stack_symbol_type ss (s, sym);
673     yypush_ (m, ss);
674 #endif
675   }
676 
677   void
yypop_(int n)678   parser::yypop_ (int n)
679   {
680     yystack_.pop (n);
681   }
682 
683 #if YYDEBUG
684   std::ostream&
debug_stream() const685   parser::debug_stream () const
686   {
687     return *yycdebug_;
688   }
689 
690   void
set_debug_stream(std::ostream & o)691   parser::set_debug_stream (std::ostream& o)
692   {
693     yycdebug_ = &o;
694   }
695 
696 
697   parser::debug_level_type
debug_level() const698   parser::debug_level () const
699   {
700     return yydebug_;
701   }
702 
703   void
set_debug_level(debug_level_type l)704   parser::set_debug_level (debug_level_type l)
705   {
706     yydebug_ = l;
707   }
708 #endif // YYDEBUG
709 
710   parser::state_type
yy_lr_goto_state_(state_type yystate,int yysym)711   parser::yy_lr_goto_state_ (state_type yystate, int yysym)
712   {
713     int yyr = yypgoto_[yysym - YYNTOKENS] + yystate;
714     if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
715       return yytable_[yyr];
716     else
717       return yydefgoto_[yysym - YYNTOKENS];
718   }
719 
720   bool
yy_pact_value_is_default_(int yyvalue)721   parser::yy_pact_value_is_default_ (int yyvalue)
722   {
723     return yyvalue == yypact_ninf_;
724   }
725 
726   bool
yy_table_value_is_error_(int yyvalue)727   parser::yy_table_value_is_error_ (int yyvalue)
728   {
729     return yyvalue == yytable_ninf_;
730   }
731 
732   int
operator ()()733   parser::operator() ()
734   {
735     return parse ();
736   }
737 
738   int
parse()739   parser::parse ()
740   {
741     int yyn;
742     /// Length of the RHS of the rule being reduced.
743     int yylen = 0;
744 
745     // Error handling.
746     int yynerrs_ = 0;
747     int yyerrstatus_ = 0;
748 
749     /// The lookahead symbol.
750     symbol_type yyla;
751 
752     /// The locations where the error started and ended.
753     stack_symbol_type yyerror_range[3];
754 
755     /// The return value of parse ().
756     int yyresult;
757 
758     /// Discard the LAC context in case there still is one left from a
759     /// previous invocation.
760     yy_lac_discard_ ("init");
761 
762 #if YY_EXCEPTIONS
763     try
764 #endif // YY_EXCEPTIONS
765       {
766     YYCDEBUG << "Starting parse\n";
767 
768 
769     /* Initialize the stack.  The initial state will be set in
770        yynewstate, since the latter expects the semantical and the
771        location values to have been already stored, initialize these
772        stacks with a primary value.  */
773     yystack_.clear ();
774     yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla));
775 
776   /*-----------------------------------------------.
777   | yynewstate -- push a new symbol on the stack.  |
778   `-----------------------------------------------*/
779   yynewstate:
780     YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
781     YY_STACK_PRINT ();
782 
783     // Accept?
784     if (yystack_[0].state == yyfinal_)
785       YYACCEPT;
786 
787     goto yybackup;
788 
789 
790   /*-----------.
791   | yybackup.  |
792   `-----------*/
793   yybackup:
794     // Try to take a decision without lookahead.
795     yyn = yypact_[+yystack_[0].state];
796     if (yy_pact_value_is_default_ (yyn))
797       goto yydefault;
798 
799     // Read a lookahead token.
800     if (yyla.empty ())
801       {
802         YYCDEBUG << "Reading a token\n";
803 #if YY_EXCEPTIONS
804         try
805 #endif // YY_EXCEPTIONS
806           {
807             symbol_type yylookahead (yylex (pioasm));
808             yyla.move (yylookahead);
809           }
810 #if YY_EXCEPTIONS
811         catch (const syntax_error& yyexc)
812           {
813             YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';
814             error (yyexc);
815             goto yyerrlab1;
816           }
817 #endif // YY_EXCEPTIONS
818       }
819     YY_SYMBOL_PRINT ("Next token is", yyla);
820 
821     if (yyla.kind () == symbol_kind::S_YYerror)
822     {
823       // The scanner already issued an error message, process directly
824       // to error recovery.  But do not keep the error token as
825       // lookahead, it is too special and may lead us to an endless
826       // loop in error recovery. */
827       yyla.kind_ = symbol_kind::S_YYUNDEF;
828       goto yyerrlab1;
829     }
830 
831     /* If the proper action on seeing token YYLA.TYPE is to reduce or
832        to detect an error, take that action.  */
833     yyn += yyla.kind ();
834     if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ())
835       {
836         if (!yy_lac_establish_ (yyla.kind ()))
837            goto yyerrlab;
838         goto yydefault;
839       }
840 
841     // Reduce or error.
842     yyn = yytable_[yyn];
843     if (yyn <= 0)
844       {
845         if (yy_table_value_is_error_ (yyn))
846           goto yyerrlab;
847         if (!yy_lac_establish_ (yyla.kind ()))
848            goto yyerrlab;
849 
850         yyn = -yyn;
851         goto yyreduce;
852       }
853 
854     // Count tokens shifted since error; after three, turn off error status.
855     if (yyerrstatus_)
856       --yyerrstatus_;
857 
858     // Shift the lookahead token.
859     yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla));
860     yy_lac_discard_ ("shift");
861     goto yynewstate;
862 
863 
864   /*-----------------------------------------------------------.
865   | yydefault -- do the default action for the current state.  |
866   `-----------------------------------------------------------*/
867   yydefault:
868     yyn = yydefact_[+yystack_[0].state];
869     if (yyn == 0)
870       goto yyerrlab;
871     goto yyreduce;
872 
873 
874   /*-----------------------------.
875   | yyreduce -- do a reduction.  |
876   `-----------------------------*/
877   yyreduce:
878     yylen = yyr2_[yyn];
879     {
880       stack_symbol_type yylhs;
881       yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);
882       /* Variants are always initialized to an empty instance of the
883          correct type. The default '$$ = $1' action is NOT applied
884          when using variants.  */
885       switch (yyr1_[yyn])
886     {
887       case symbol_kind::S_if_full: // if_full
888       case symbol_kind::S_if_empty: // if_empty
889       case symbol_kind::S_blocking: // blocking
890         yylhs.value.emplace< bool > ();
891         break;
892 
893       case symbol_kind::S_condition: // condition
894         yylhs.value.emplace< enum condition > ();
895         break;
896 
897       case symbol_kind::S_in_source: // in_source
898       case symbol_kind::S_out_target: // out_target
899       case symbol_kind::S_set_target: // set_target
900         yylhs.value.emplace< enum in_out_set > ();
901         break;
902 
903       case symbol_kind::S_irq_modifiers: // irq_modifiers
904         yylhs.value.emplace< enum irq > ();
905         break;
906 
907       case symbol_kind::S_mov_target: // mov_target
908       case symbol_kind::S_mov_source: // mov_source
909         yylhs.value.emplace< enum mov > ();
910         break;
911 
912       case symbol_kind::S_mov_op: // mov_op
913         yylhs.value.emplace< enum mov_op > ();
914         break;
915 
916       case symbol_kind::S_INT: // "integer"
917         yylhs.value.emplace< int > ();
918         break;
919 
920       case symbol_kind::S_instruction: // instruction
921       case symbol_kind::S_base_instruction: // base_instruction
922         yylhs.value.emplace< std::shared_ptr<instruction> > ();
923         break;
924 
925       case symbol_kind::S_value: // value
926       case symbol_kind::S_expression: // expression
927       case symbol_kind::S_delay: // delay
928       case symbol_kind::S_sideset: // sideset
929         yylhs.value.emplace< std::shared_ptr<resolvable> > ();
930         break;
931 
932       case symbol_kind::S_label_decl: // label_decl
933       case symbol_kind::S_symbol_def: // symbol_def
934         yylhs.value.emplace< std::shared_ptr<symbol> > ();
935         break;
936 
937       case symbol_kind::S_wait_source: // wait_source
938         yylhs.value.emplace< std::shared_ptr<wait_source> > ();
939         break;
940 
941       case symbol_kind::S_ID: // "identifier"
942       case symbol_kind::S_STRING: // "string"
943       case symbol_kind::S_NON_WS: // "text"
944       case symbol_kind::S_CODE_BLOCK_START: // "code block"
945       case symbol_kind::S_CODE_BLOCK_CONTENTS: // "%}"
946       case symbol_kind::S_UNKNOWN_DIRECTIVE: // UNKNOWN_DIRECTIVE
947         yylhs.value.emplace< std::string > ();
948         break;
949 
950       default:
951         break;
952     }
953 
954 
955       // Default location.
956       {
957         stack_type::slice range (yystack_, yylen);
958         YYLLOC_DEFAULT (yylhs.location, range, yylen);
959         yyerror_range[1].location = yylhs.location;
960       }
961 
962       // Perform the reduction.
963       YY_REDUCE_PRINT (yyn);
964 #if YY_EXCEPTIONS
965       try
966 #endif // YY_EXCEPTIONS
967         {
968           switch (yyn)
969             {
970   case 2: // file: lines "end of file"
971               { if (pioasm.error_count || pioasm.write_output()) YYABORT; }
972     break;
973 
974   case 5: // line: ".program" "identifier"
975                                                 { if (!pioasm.add_program(yylhs.location, yystack_[0].value.as < std::string > ())) { std::stringstream msg; msg << "program " << yystack_[0].value.as < std::string > () << " already exists"; error(yylhs.location, msg.str()); abort(); } }
976     break;
977 
978   case 7: // line: instruction
979                                                 { pioasm.get_current_program(yystack_[0].location, "instruction").add_instruction(yystack_[0].value.as < std::shared_ptr<instruction> > ()); }
980     break;
981 
982   case 8: // line: label_decl instruction
983                                                 { auto &p = pioasm.get_current_program(yystack_[0].location, "instruction"); p.add_label(yystack_[1].value.as < std::shared_ptr<symbol> > ()); p.add_instruction(yystack_[0].value.as < std::shared_ptr<instruction> > ()); }
984     break;
985 
986   case 9: // line: label_decl
987                                                 { pioasm.get_current_program(yystack_[0].location, "label").add_label(yystack_[0].value.as < std::shared_ptr<symbol> > ()); }
988     break;
989 
990   case 12: // line: error
991                                                 { if (pioasm.error_count > 6) { std::cerr << "\ntoo many errors; aborting.\n"; YYABORT; } }
992     break;
993 
994   case 13: // code_block: "code block" "%}"
995                                                 { std::string of = yystack_[1].value.as < std::string > (); if (of.empty()) of = output_format::default_name; pioasm.get_current_program(yylhs.location, "code block", false, false).add_code_block( code_block(yylhs.location, of, yystack_[0].value.as < std::string > ())); }
996     break;
997 
998   case 14: // label_decl: symbol_def ":"
999                             { yystack_[1].value.as < std::shared_ptr<symbol> > ()->is_label = true; yylhs.value.as < std::shared_ptr<symbol> > () = yystack_[1].value.as < std::shared_ptr<symbol> > (); }
1000     break;
1001 
1002   case 15: // directive: ".define" symbol_def expression
1003                                       { yystack_[1].value.as < std::shared_ptr<symbol> > ()->is_label = false; yystack_[1].value.as < std::shared_ptr<symbol> > ()->value = yystack_[0].value.as < std::shared_ptr<resolvable> > (); pioasm.get_current_program(yystack_[2].location, ".define", false, false).add_symbol(yystack_[1].value.as < std::shared_ptr<symbol> > ()); }
1004     break;
1005 
1006   case 16: // directive: ".origin" value
1007                                       { pioasm.get_current_program(yystack_[1].location, ".origin", true).set_origin(yylhs.location, yystack_[0].value.as < std::shared_ptr<resolvable> > ()); }
1008     break;
1009 
1010   case 17: // directive: ".side_set" value "opt" "pindirs"
1011                                       { pioasm.get_current_program(yystack_[3].location, ".side_set", true).set_sideset(yylhs.location, yystack_[2].value.as < std::shared_ptr<resolvable> > (), true, true); }
1012     break;
1013 
1014   case 18: // directive: ".side_set" value "opt"
1015                                       { pioasm.get_current_program(yystack_[2].location, ".side_set", true).set_sideset(yylhs.location, yystack_[1].value.as < std::shared_ptr<resolvable> > (), true, false); }
1016     break;
1017 
1018   case 19: // directive: ".side_set" value "pindirs"
1019                                       { pioasm.get_current_program(yystack_[2].location, ".side_set", true).set_sideset(yylhs.location, yystack_[1].value.as < std::shared_ptr<resolvable> > (), false, true); }
1020     break;
1021 
1022   case 20: // directive: ".side_set" value
1023                                       { pioasm.get_current_program(yystack_[1].location, ".side_set", true).set_sideset(yylhs.location, yystack_[0].value.as < std::shared_ptr<resolvable> > (), false, false); }
1024     break;
1025 
1026   case 21: // directive: ".wrap_target"
1027                                       { pioasm.get_current_program(yystack_[0].location, ".wrap_target").set_wrap_target(yylhs.location); }
1028     break;
1029 
1030   case 22: // directive: ".wrap"
1031                                       { pioasm.get_current_program(yystack_[0].location, ".wrap").set_wrap(yylhs.location); }
1032     break;
1033 
1034   case 23: // directive: ".word" value
1035                                       { pioasm.get_current_program(yystack_[1].location, "instruction").add_instruction(std::shared_ptr<instruction>(new instr_word(yylhs.location, yystack_[0].value.as < std::shared_ptr<resolvable> > ()))); }
1036     break;
1037 
1038   case 24: // directive: ".lang_opt" "text" "text" "=" "integer"
1039                                       { pioasm.get_current_program(yystack_[4].location, ".lang_opt").add_lang_opt(yystack_[3].value.as < std::string > (), yystack_[2].value.as < std::string > (), std::to_string(yystack_[0].value.as < int > ())); }
1040     break;
1041 
1042   case 25: // directive: ".lang_opt" "text" "text" "=" "string"
1043                                         { pioasm.get_current_program(yystack_[4].location, ".lang_opt").add_lang_opt(yystack_[3].value.as < std::string > (), yystack_[2].value.as < std::string > (), yystack_[0].value.as < std::string > ()); }
1044     break;
1045 
1046   case 26: // directive: ".lang_opt" "text" "text" "=" "text"
1047                                         { pioasm.get_current_program(yystack_[4].location, ".lang_opt").add_lang_opt(yystack_[3].value.as < std::string > (), yystack_[2].value.as < std::string > (), yystack_[0].value.as < std::string > ()); }
1048     break;
1049 
1050   case 27: // directive: ".lang_opt" error
1051                                       { error(yylhs.location, "expected format is .lang_opt language option_name = option_value"); }
1052     break;
1053 
1054   case 28: // directive: UNKNOWN_DIRECTIVE
1055                                       { std::stringstream msg; msg << "unknown directive " << yystack_[0].value.as < std::string > (); throw syntax_error(yylhs.location, msg.str()); }
1056     break;
1057 
1058   case 29: // value: "integer"
1059            { yylhs.value.as < std::shared_ptr<resolvable> > () = resolvable_int(yylhs.location, yystack_[0].value.as < int > ()); }
1060     break;
1061 
1062   case 30: // value: "identifier"
1063           { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<resolvable>(new name_ref(yylhs.location, yystack_[0].value.as < std::string > ())); }
1064     break;
1065 
1066   case 31: // value: "(" expression ")"
1067                                 { yylhs.value.as < std::shared_ptr<resolvable> > () = yystack_[1].value.as < std::shared_ptr<resolvable> > (); }
1068     break;
1069 
1070   case 32: // expression: value
1071      { yylhs.value.as < std::shared_ptr<resolvable> > () = yystack_[0].value.as < std::shared_ptr<resolvable> > (); }
1072     break;
1073 
1074   case 33: // expression: expression "+" expression
1075                                   { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::add, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1076     break;
1077 
1078   case 34: // expression: expression "-" expression
1079                                    { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::subtract, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1080     break;
1081 
1082   case 35: // expression: expression "*" expression
1083                                       { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::multiply, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ()));  }
1084     break;
1085 
1086   case 36: // expression: expression "/" expression
1087                                     { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::divide, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1088     break;
1089 
1090   case 37: // expression: expression "|" expression
1091                                 { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::or_, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1092     break;
1093 
1094   case 38: // expression: expression "&" expression
1095                                  { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::and_, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1096     break;
1097 
1098   case 39: // expression: expression "^" expression
1099                                  { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<binary_operation>(new binary_operation(yylhs.location, binary_operation::xor_, yystack_[2].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1100     break;
1101 
1102   case 40: // expression: "-" expression
1103                         { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<unary_operation>(new unary_operation(yylhs.location, unary_operation::negate, yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1104     break;
1105 
1106   case 41: // expression: "::" expression
1107                           { yylhs.value.as < std::shared_ptr<resolvable> > () = std::shared_ptr<unary_operation>(new unary_operation(yylhs.location, unary_operation::reverse, yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1108     break;
1109 
1110   case 42: // instruction: base_instruction sideset delay
1111                                    { yylhs.value.as < std::shared_ptr<instruction> > () = yystack_[2].value.as < std::shared_ptr<instruction> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->sideset = yystack_[1].value.as < std::shared_ptr<resolvable> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->delay = yystack_[0].value.as < std::shared_ptr<resolvable> > (); }
1112     break;
1113 
1114   case 43: // instruction: base_instruction delay sideset
1115                                    { yylhs.value.as < std::shared_ptr<instruction> > () = yystack_[2].value.as < std::shared_ptr<instruction> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->delay = yystack_[1].value.as < std::shared_ptr<resolvable> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->sideset = yystack_[0].value.as < std::shared_ptr<resolvable> > (); }
1116     break;
1117 
1118   case 44: // instruction: base_instruction sideset
1119                              { yylhs.value.as < std::shared_ptr<instruction> > () = yystack_[1].value.as < std::shared_ptr<instruction> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->sideset = yystack_[0].value.as < std::shared_ptr<resolvable> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->delay = resolvable_int(yylhs.location, 0); }
1120     break;
1121 
1122   case 45: // instruction: base_instruction delay
1123                            { yylhs.value.as < std::shared_ptr<instruction> > () = yystack_[1].value.as < std::shared_ptr<instruction> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->delay = yystack_[0].value.as < std::shared_ptr<resolvable> > (); }
1124     break;
1125 
1126   case 46: // instruction: base_instruction
1127                      { yylhs.value.as < std::shared_ptr<instruction> > () = yystack_[0].value.as < std::shared_ptr<instruction> > (); yylhs.value.as < std::shared_ptr<instruction> > ()->delay = resolvable_int(yylhs.location, 0); }
1128     break;
1129 
1130   case 47: // base_instruction: "nop"
1131                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_nop(yylhs.location)); }
1132     break;
1133 
1134   case 48: // base_instruction: "jmp" condition comma expression
1135                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_jmp(yylhs.location, yystack_[2].value.as < enum condition > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1136     break;
1137 
1138   case 49: // base_instruction: "wait" value wait_source
1139                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_wait(yylhs.location, yystack_[1].value.as < std::shared_ptr<resolvable> > (), yystack_[0].value.as < std::shared_ptr<wait_source> > ())); }
1140     break;
1141 
1142   case 50: // base_instruction: "wait" value "," value
1143                                                           { std::stringstream msg; location l; l.begin = yystack_[2].location.end; l.end = yystack_[1].location.end; msg << "expected irq, gpio or pin after the polarity value and before the \",\""; throw yy::parser::syntax_error(l, msg.str()); }
1144     break;
1145 
1146   case 51: // base_instruction: "wait" wait_source
1147                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_wait(yylhs.location, resolvable_int(yylhs.location, 1),  yystack_[0].value.as < std::shared_ptr<wait_source> > ())); }
1148     break;
1149 
1150   case 52: // base_instruction: "in" in_source comma value
1151                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_in(yylhs.location, yystack_[2].value.as < enum in_out_set > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1152     break;
1153 
1154   case 53: // base_instruction: "out" out_target comma value
1155                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_out(yylhs.location, yystack_[2].value.as < enum in_out_set > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1156     break;
1157 
1158   case 54: // base_instruction: "push" if_full blocking
1159                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_push(yylhs.location, yystack_[1].value.as < bool > (), yystack_[0].value.as < bool > ())); }
1160     break;
1161 
1162   case 55: // base_instruction: "pull" if_empty blocking
1163                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_pull(yylhs.location, yystack_[1].value.as < bool > (), yystack_[0].value.as < bool > ())); }
1164     break;
1165 
1166   case 56: // base_instruction: "mov" mov_target comma mov_op mov_source
1167                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_mov(yylhs.location, yystack_[3].value.as < enum mov > (), yystack_[0].value.as < enum mov > (), yystack_[1].value.as < enum mov_op > ())); }
1168     break;
1169 
1170   case 57: // base_instruction: "irq" irq_modifiers value "rel"
1171                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_irq(yylhs.location, yystack_[2].value.as < enum irq > (), yystack_[1].value.as < std::shared_ptr<resolvable> > (), true)); }
1172     break;
1173 
1174   case 58: // base_instruction: "irq" irq_modifiers value
1175                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_irq(yylhs.location, yystack_[1].value.as < enum irq > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1176     break;
1177 
1178   case 59: // base_instruction: "set" set_target comma value
1179                                                           { yylhs.value.as < std::shared_ptr<instruction> > () = std::shared_ptr<instruction>(new instr_set(yylhs.location, yystack_[2].value.as < enum in_out_set > (), yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1180     break;
1181 
1182   case 60: // delay: "[" expression "]"
1183                                  { yylhs.value.as < std::shared_ptr<resolvable> > () = yystack_[1].value.as < std::shared_ptr<resolvable> > (); }
1184     break;
1185 
1186   case 61: // sideset: "side" value
1187                { yylhs.value.as < std::shared_ptr<resolvable> > () = yystack_[0].value.as < std::shared_ptr<resolvable> > (); }
1188     break;
1189 
1190   case 62: // condition: "!" "x"
1191                             { yylhs.value.as < enum condition > () = condition::xz; }
1192     break;
1193 
1194   case 63: // condition: "x" "--"
1195                             { yylhs.value.as < enum condition > () = condition::xnz__; }
1196     break;
1197 
1198   case 64: // condition: "!" "y"
1199                             { yylhs.value.as < enum condition > () = condition::yz; }
1200     break;
1201 
1202   case 65: // condition: "y" "--"
1203                             { yylhs.value.as < enum condition > () = condition::ynz__; }
1204     break;
1205 
1206   case 66: // condition: "x" "!=" "y"
1207                             { yylhs.value.as < enum condition > () = condition::xney; }
1208     break;
1209 
1210   case 67: // condition: "pin"
1211                             { yylhs.value.as < enum condition > () = condition::pin; }
1212     break;
1213 
1214   case 68: // condition: "!" "osre"
1215                             { yylhs.value.as < enum condition > () = condition::osrez; }
1216     break;
1217 
1218   case 69: // condition: %empty
1219                             { yylhs.value.as < enum condition > () = condition::al; }
1220     break;
1221 
1222   case 70: // wait_source: "irq" comma value "rel"
1223                             { yylhs.value.as < std::shared_ptr<wait_source> > () = std::shared_ptr<wait_source>(new wait_source(wait_source::irq, yystack_[1].value.as < std::shared_ptr<resolvable> > (), true)); }
1224     break;
1225 
1226   case 71: // wait_source: "irq" comma value
1227                             { yylhs.value.as < std::shared_ptr<wait_source> > () = std::shared_ptr<wait_source>(new wait_source(wait_source::irq, yystack_[0].value.as < std::shared_ptr<resolvable> > (), false)); }
1228     break;
1229 
1230   case 72: // wait_source: "gpio" comma value
1231                             { yylhs.value.as < std::shared_ptr<wait_source> > () = std::shared_ptr<wait_source>(new wait_source(wait_source::gpio, yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1232     break;
1233 
1234   case 73: // wait_source: "pin" comma value
1235                             { yylhs.value.as < std::shared_ptr<wait_source> > () = std::shared_ptr<wait_source>(new wait_source(wait_source::pin, yystack_[0].value.as < std::shared_ptr<resolvable> > ())); }
1236     break;
1237 
1238   case 76: // in_source: "pins"
1239                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_pins; }
1240     break;
1241 
1242   case 77: // in_source: "x"
1243                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_x; }
1244     break;
1245 
1246   case 78: // in_source: "y"
1247                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_y; }
1248     break;
1249 
1250   case 79: // in_source: "null"
1251                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_null; }
1252     break;
1253 
1254   case 80: // in_source: "isr"
1255                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_isr; }
1256     break;
1257 
1258   case 81: // in_source: "osr"
1259                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_osr; }
1260     break;
1261 
1262   case 82: // in_source: "status"
1263                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_status; }
1264     break;
1265 
1266   case 83: // out_target: "pins"
1267                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_pins; }
1268     break;
1269 
1270   case 84: // out_target: "x"
1271                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_x; }
1272     break;
1273 
1274   case 85: // out_target: "y"
1275                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_y; }
1276     break;
1277 
1278   case 86: // out_target: "null"
1279                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_null; }
1280     break;
1281 
1282   case 87: // out_target: "pindirs"
1283                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_pindirs; }
1284     break;
1285 
1286   case 88: // out_target: "isr"
1287                  { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_isr; }
1288     break;
1289 
1290   case 89: // out_target: "pc"
1291                  { yylhs.value.as < enum in_out_set > () = in_out_set::out_set_pc; }
1292     break;
1293 
1294   case 90: // out_target: "exec"
1295                  { yylhs.value.as < enum in_out_set > () = in_out_set::out_exec; }
1296     break;
1297 
1298   case 91: // mov_target: "pins"
1299                  { yylhs.value.as < enum mov > () = mov::pins; }
1300     break;
1301 
1302   case 92: // mov_target: "x"
1303                  { yylhs.value.as < enum mov > () = mov::x; }
1304     break;
1305 
1306   case 93: // mov_target: "y"
1307                  { yylhs.value.as < enum mov > () = mov::y; }
1308     break;
1309 
1310   case 94: // mov_target: "exec"
1311                  { yylhs.value.as < enum mov > () = mov::exec; }
1312     break;
1313 
1314   case 95: // mov_target: "pc"
1315                  { yylhs.value.as < enum mov > () = mov::pc; }
1316     break;
1317 
1318   case 96: // mov_target: "isr"
1319                  { yylhs.value.as < enum mov > () = mov::isr; }
1320     break;
1321 
1322   case 97: // mov_target: "osr"
1323                  { yylhs.value.as < enum mov > () = mov::osr; }
1324     break;
1325 
1326   case 98: // mov_source: "pins"
1327                  { yylhs.value.as < enum mov > () = mov::pins; }
1328     break;
1329 
1330   case 99: // mov_source: "x"
1331                  { yylhs.value.as < enum mov > () = mov::x; }
1332     break;
1333 
1334   case 100: // mov_source: "y"
1335                  { yylhs.value.as < enum mov > () = mov::y; }
1336     break;
1337 
1338   case 101: // mov_source: "null"
1339                  { yylhs.value.as < enum mov > () = mov::null; }
1340     break;
1341 
1342   case 102: // mov_source: "status"
1343                  { yylhs.value.as < enum mov > () = mov::status; }
1344     break;
1345 
1346   case 103: // mov_source: "isr"
1347                  { yylhs.value.as < enum mov > () = mov::isr; }
1348     break;
1349 
1350   case 104: // mov_source: "osr"
1351                  { yylhs.value.as < enum mov > () = mov::osr; }
1352     break;
1353 
1354   case 105: // mov_op: "!"
1355                 { yylhs.value.as < enum mov_op > () = mov_op::invert; }
1356     break;
1357 
1358   case 106: // mov_op: "::"
1359                 { yylhs.value.as < enum mov_op > () = mov_op::bit_reverse; }
1360     break;
1361 
1362   case 107: // mov_op: %empty
1363                 { yylhs.value.as < enum mov_op > () = mov_op::none; }
1364     break;
1365 
1366   case 108: // set_target: "pins"
1367                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_pins; }
1368     break;
1369 
1370   case 109: // set_target: "x"
1371                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_x; }
1372     break;
1373 
1374   case 110: // set_target: "y"
1375                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_y; }
1376     break;
1377 
1378   case 111: // set_target: "pindirs"
1379                 { yylhs.value.as < enum in_out_set > () = in_out_set::in_out_set_pindirs; }
1380     break;
1381 
1382   case 112: // if_full: "iffull"
1383            { yylhs.value.as < bool > () = true; }
1384     break;
1385 
1386   case 113: // if_full: %empty
1387            { yylhs.value.as < bool > () = false; }
1388     break;
1389 
1390   case 114: // if_empty: "ifempty"
1391             { yylhs.value.as < bool > () = true; }
1392     break;
1393 
1394   case 115: // if_empty: %empty
1395             { yylhs.value.as < bool > () = false; }
1396     break;
1397 
1398   case 116: // blocking: "block"
1399             { yylhs.value.as < bool > () = true; }
1400     break;
1401 
1402   case 117: // blocking: "noblock"
1403             { yylhs.value.as < bool > () = false; }
1404     break;
1405 
1406   case 118: // blocking: %empty
1407             { yylhs.value.as < bool > () = true; }
1408     break;
1409 
1410   case 119: // irq_modifiers: "clear"
1411                    { yylhs.value.as < enum irq > () = irq::clear; }
1412     break;
1413 
1414   case 120: // irq_modifiers: "wait"
1415                    { yylhs.value.as < enum irq > () = irq::set_wait; }
1416     break;
1417 
1418   case 121: // irq_modifiers: "nowait"
1419                    { yylhs.value.as < enum irq > () = irq::set; }
1420     break;
1421 
1422   case 122: // irq_modifiers: "set"
1423                    { yylhs.value.as < enum irq > () = irq::set; }
1424     break;
1425 
1426   case 123: // irq_modifiers: %empty
1427                    { yylhs.value.as < enum irq > () = irq::set; }
1428     break;
1429 
1430   case 124: // symbol_def: "identifier"
1431                     { yylhs.value.as < std::shared_ptr<symbol> > () = std::shared_ptr<symbol>(new symbol(yylhs.location, yystack_[0].value.as < std::string > ())); }
1432     break;
1433 
1434   case 125: // symbol_def: "public" "identifier"
1435                     { yylhs.value.as < std::shared_ptr<symbol> > () = std::shared_ptr<symbol>(new symbol(yylhs.location, yystack_[0].value.as < std::string > (), true)); }
1436     break;
1437 
1438   case 126: // symbol_def: "*" "identifier"
1439                     { yylhs.value.as < std::shared_ptr<symbol> > () = std::shared_ptr<symbol>(new symbol(yylhs.location, yystack_[0].value.as < std::string > (), true)); }
1440     break;
1441 
1442 
1443 
1444             default:
1445               break;
1446             }
1447         }
1448 #if YY_EXCEPTIONS
1449       catch (const syntax_error& yyexc)
1450         {
1451           YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';
1452           error (yyexc);
1453           YYERROR;
1454         }
1455 #endif // YY_EXCEPTIONS
1456       YY_SYMBOL_PRINT ("-> $$ =", yylhs);
1457       yypop_ (yylen);
1458       yylen = 0;
1459 
1460       // Shift the result of the reduction.
1461       yypush_ (YY_NULLPTR, YY_MOVE (yylhs));
1462     }
1463     goto yynewstate;
1464 
1465 
1466   /*--------------------------------------.
1467   | yyerrlab -- here on detecting error.  |
1468   `--------------------------------------*/
1469   yyerrlab:
1470     // If not already recovering from an error, report this error.
1471     if (!yyerrstatus_)
1472       {
1473         ++yynerrs_;
1474         context yyctx (*this, yyla);
1475         std::string msg = yysyntax_error_ (yyctx);
1476         error (yyla.location, YY_MOVE (msg));
1477       }
1478 
1479 
1480     yyerror_range[1].location = yyla.location;
1481     if (yyerrstatus_ == 3)
1482       {
1483         /* If just tried and failed to reuse lookahead token after an
1484            error, discard it.  */
1485 
1486         // Return failure if at end of input.
1487         if (yyla.kind () == symbol_kind::S_YYEOF)
1488           YYABORT;
1489         else if (!yyla.empty ())
1490           {
1491             yy_destroy_ ("Error: discarding", yyla);
1492             yyla.clear ();
1493           }
1494       }
1495 
1496     // Else will try to reuse lookahead token after shifting the error token.
1497     goto yyerrlab1;
1498 
1499 
1500   /*---------------------------------------------------.
1501   | yyerrorlab -- error raised explicitly by YYERROR.  |
1502   `---------------------------------------------------*/
1503   yyerrorlab:
1504     /* Pacify compilers when the user code never invokes YYERROR and
1505        the label yyerrorlab therefore never appears in user code.  */
1506     if (false)
1507       YYERROR;
1508 
1509     /* Do not reclaim the symbols of the rule whose action triggered
1510        this YYERROR.  */
1511     yypop_ (yylen);
1512     yylen = 0;
1513     YY_STACK_PRINT ();
1514     goto yyerrlab1;
1515 
1516 
1517   /*-------------------------------------------------------------.
1518   | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1519   `-------------------------------------------------------------*/
1520   yyerrlab1:
1521     yyerrstatus_ = 3;   // Each real token shifted decrements this.
1522     // Pop stack until we find a state that shifts the error token.
1523     for (;;)
1524       {
1525         yyn = yypact_[+yystack_[0].state];
1526         if (!yy_pact_value_is_default_ (yyn))
1527           {
1528             yyn += symbol_kind::S_YYerror;
1529             if (0 <= yyn && yyn <= yylast_
1530                 && yycheck_[yyn] == symbol_kind::S_YYerror)
1531               {
1532                 yyn = yytable_[yyn];
1533                 if (0 < yyn)
1534                   break;
1535               }
1536           }
1537 
1538         // Pop the current state because it cannot handle the error token.
1539         if (yystack_.size () == 1)
1540           YYABORT;
1541 
1542         yyerror_range[1].location = yystack_[0].location;
1543         yy_destroy_ ("Error: popping", yystack_[0]);
1544         yypop_ ();
1545         YY_STACK_PRINT ();
1546       }
1547     {
1548       stack_symbol_type error_token;
1549 
1550       yyerror_range[2].location = yyla.location;
1551       YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);
1552 
1553       // Shift the error token.
1554       yy_lac_discard_ ("error recovery");
1555       error_token.state = state_type (yyn);
1556       yypush_ ("Shifting", YY_MOVE (error_token));
1557     }
1558     goto yynewstate;
1559 
1560 
1561   /*-------------------------------------.
1562   | yyacceptlab -- YYACCEPT comes here.  |
1563   `-------------------------------------*/
1564   yyacceptlab:
1565     yyresult = 0;
1566     goto yyreturn;
1567 
1568 
1569   /*-----------------------------------.
1570   | yyabortlab -- YYABORT comes here.  |
1571   `-----------------------------------*/
1572   yyabortlab:
1573     yyresult = 1;
1574     goto yyreturn;
1575 
1576 
1577   /*-----------------------------------------------------.
1578   | yyreturn -- parsing is finished, return the result.  |
1579   `-----------------------------------------------------*/
1580   yyreturn:
1581     if (!yyla.empty ())
1582       yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1583 
1584     /* Do not reclaim the symbols of the rule whose action triggered
1585        this YYABORT or YYACCEPT.  */
1586     yypop_ (yylen);
1587     YY_STACK_PRINT ();
1588     while (1 < yystack_.size ())
1589       {
1590         yy_destroy_ ("Cleanup: popping", yystack_[0]);
1591         yypop_ ();
1592       }
1593 
1594     return yyresult;
1595   }
1596 #if YY_EXCEPTIONS
1597     catch (...)
1598       {
1599         YYCDEBUG << "Exception caught: cleaning lookahead and stack\n";
1600         // Do not try to display the values of the reclaimed symbols,
1601         // as their printers might throw an exception.
1602         if (!yyla.empty ())
1603           yy_destroy_ (YY_NULLPTR, yyla);
1604 
1605         while (1 < yystack_.size ())
1606           {
1607             yy_destroy_ (YY_NULLPTR, yystack_[0]);
1608             yypop_ ();
1609           }
1610         throw;
1611       }
1612 #endif // YY_EXCEPTIONS
1613   }
1614 
1615   void
error(const syntax_error & yyexc)1616   parser::error (const syntax_error& yyexc)
1617   {
1618     error (yyexc.location, yyexc.what ());
1619   }
1620 
1621   /* Return YYSTR after stripping away unnecessary quotes and
1622      backslashes, so that it's suitable for yyerror.  The heuristic is
1623      that double-quoting is unnecessary unless the string contains an
1624      apostrophe, a comma, or backslash (other than backslash-backslash).
1625      YYSTR is taken from yytname.  */
1626   std::string
yytnamerr_(const char * yystr)1627   parser::yytnamerr_ (const char *yystr)
1628   {
1629     if (*yystr == '"')
1630       {
1631         std::string yyr;
1632         char const *yyp = yystr;
1633 
1634         for (;;)
1635           switch (*++yyp)
1636             {
1637             case '\'':
1638             case ',':
1639               goto do_not_strip_quotes;
1640 
1641             case '\\':
1642               if (*++yyp != '\\')
1643                 goto do_not_strip_quotes;
1644               else
1645                 goto append;
1646 
1647             append:
1648             default:
1649               yyr += *yyp;
1650               break;
1651 
1652             case '"':
1653               return yyr;
1654             }
1655       do_not_strip_quotes: ;
1656       }
1657 
1658     return yystr;
1659   }
1660 
1661   std::string
symbol_name(symbol_kind_type yysymbol)1662   parser::symbol_name (symbol_kind_type yysymbol)
1663   {
1664     return yytnamerr_ (yytname_[yysymbol]);
1665   }
1666 
1667 
1668 
1669   // parser::context.
context(const parser & yyparser,const symbol_type & yyla)1670   parser::context::context (const parser& yyparser, const symbol_type& yyla)
1671     : yyparser_ (yyparser)
1672     , yyla_ (yyla)
1673   {}
1674 
1675   int
expected_tokens(symbol_kind_type yyarg[],int yyargn) const1676   parser::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const
1677   {
1678     // Actual number of expected tokens
1679     int yycount = 0;
1680 
1681 #if YYDEBUG
1682     // Execute LAC once. We don't care if it is successful, we
1683     // only do it for the sake of debugging output.
1684     if (!yyparser_.yy_lac_established_)
1685       yyparser_.yy_lac_check_ (yyla_.kind ());
1686 #endif
1687 
1688     for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
1689       {
1690         symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
1691         if (yysym != symbol_kind::S_YYerror
1692             && yysym != symbol_kind::S_YYUNDEF
1693             && yyparser_.yy_lac_check_ (yysym))
1694           {
1695             if (!yyarg)
1696               ++yycount;
1697             else if (yycount == yyargn)
1698               return 0;
1699             else
1700               yyarg[yycount++] = yysym;
1701           }
1702       }
1703     if (yyarg && yycount == 0 && 0 < yyargn)
1704       yyarg[0] = symbol_kind::S_YYEMPTY;
1705     return yycount;
1706   }
1707 
1708 
1709   bool
yy_lac_check_(symbol_kind_type yytoken) const1710   parser::yy_lac_check_ (symbol_kind_type yytoken) const
1711   {
1712     // Logically, the yylac_stack's lifetime is confined to this function.
1713     // Clear it, to get rid of potential left-overs from previous call.
1714     yylac_stack_.clear ();
1715     // Reduce until we encounter a shift and thereby accept the token.
1716 #if YYDEBUG
1717     YYCDEBUG << "LAC: checking lookahead " << symbol_name (yytoken) << ':';
1718 #endif
1719     std::ptrdiff_t lac_top = 0;
1720     while (true)
1721       {
1722         state_type top_state = (yylac_stack_.empty ()
1723                                 ? yystack_[lac_top].state
1724                                 : yylac_stack_.back ());
1725         int yyrule = yypact_[+top_state];
1726         if (yy_pact_value_is_default_ (yyrule)
1727             || (yyrule += yytoken) < 0 || yylast_ < yyrule
1728             || yycheck_[yyrule] != yytoken)
1729           {
1730             // Use the default action.
1731             yyrule = yydefact_[+top_state];
1732             if (yyrule == 0)
1733               {
1734                 YYCDEBUG << " Err\n";
1735                 return false;
1736               }
1737           }
1738         else
1739           {
1740             // Use the action from yytable.
1741             yyrule = yytable_[yyrule];
1742             if (yy_table_value_is_error_ (yyrule))
1743               {
1744                 YYCDEBUG << " Err\n";
1745                 return false;
1746               }
1747             if (0 < yyrule)
1748               {
1749                 YYCDEBUG << " S" << yyrule << '\n';
1750                 return true;
1751               }
1752             yyrule = -yyrule;
1753           }
1754         // By now we know we have to simulate a reduce.
1755         YYCDEBUG << " R" << yyrule - 1;
1756         // Pop the corresponding number of values from the stack.
1757         {
1758           std::ptrdiff_t yylen = yyr2_[yyrule];
1759           // First pop from the LAC stack as many tokens as possible.
1760           std::ptrdiff_t lac_size = std::ptrdiff_t (yylac_stack_.size ());
1761           if (yylen < lac_size)
1762             {
1763               yylac_stack_.resize (std::size_t (lac_size - yylen));
1764               yylen = 0;
1765             }
1766           else if (lac_size)
1767             {
1768               yylac_stack_.clear ();
1769               yylen -= lac_size;
1770             }
1771           // Only afterwards look at the main stack.
1772           // We simulate popping elements by incrementing lac_top.
1773           lac_top += yylen;
1774         }
1775         // Keep top_state in sync with the updated stack.
1776         top_state = (yylac_stack_.empty ()
1777                      ? yystack_[lac_top].state
1778                      : yylac_stack_.back ());
1779         // Push the resulting state of the reduction.
1780         state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]);
1781         YYCDEBUG << " G" << int (state);
1782         yylac_stack_.push_back (state);
1783       }
1784   }
1785 
1786   // Establish the initial context if no initial context currently exists.
1787   bool
yy_lac_establish_(symbol_kind_type yytoken)1788   parser::yy_lac_establish_ (symbol_kind_type yytoken)
1789   {
1790     /* Establish the initial context for the current lookahead if no initial
1791        context is currently established.
1792 
1793        We define a context as a snapshot of the parser stacks.  We define
1794        the initial context for a lookahead as the context in which the
1795        parser initially examines that lookahead in order to select a
1796        syntactic action.  Thus, if the lookahead eventually proves
1797        syntactically unacceptable (possibly in a later context reached via a
1798        series of reductions), the initial context can be used to determine
1799        the exact set of tokens that would be syntactically acceptable in the
1800        lookahead's place.  Moreover, it is the context after which any
1801        further semantic actions would be erroneous because they would be
1802        determined by a syntactically unacceptable token.
1803 
1804        yy_lac_establish_ should be invoked when a reduction is about to be
1805        performed in an inconsistent state (which, for the purposes of LAC,
1806        includes consistent states that don't know they're consistent because
1807        their default reductions have been disabled).
1808 
1809        For parse.lac=full, the implementation of yy_lac_establish_ is as
1810        follows.  If no initial context is currently established for the
1811        current lookahead, then check if that lookahead can eventually be
1812        shifted if syntactic actions continue from the current context.  */
1813     if (!yy_lac_established_)
1814       {
1815 #if YYDEBUG
1816         YYCDEBUG << "LAC: initial context established for "
1817                  << symbol_name (yytoken) << '\n';
1818 #endif
1819         yy_lac_established_ = true;
1820         return yy_lac_check_ (yytoken);
1821       }
1822     return true;
1823   }
1824 
1825   // Discard any previous initial lookahead context.
1826   void
yy_lac_discard_(const char * evt)1827   parser::yy_lac_discard_ (const char* evt)
1828   {
1829    /* Discard any previous initial lookahead context because of Event,
1830       which may be a lookahead change or an invalidation of the currently
1831       established initial context for the current lookahead.
1832 
1833       The most common example of a lookahead change is a shift.  An example
1834       of both cases is syntax error recovery.  That is, a syntax error
1835       occurs when the lookahead is syntactically erroneous for the
1836       currently established initial context, so error recovery manipulates
1837       the parser stacks to try to find a new initial context in which the
1838       current lookahead is syntactically acceptable.  If it fails to find
1839       such a context, it discards the lookahead.  */
1840     if (yy_lac_established_)
1841       {
1842         YYCDEBUG << "LAC: initial context discarded due to "
1843                  << evt << '\n';
1844         yy_lac_established_ = false;
1845       }
1846   }
1847 
1848   int
yy_syntax_error_arguments_(const context & yyctx,symbol_kind_type yyarg[],int yyargn) const1849   parser::yy_syntax_error_arguments_ (const context& yyctx,
1850                                                  symbol_kind_type yyarg[], int yyargn) const
1851   {
1852     /* There are many possibilities here to consider:
1853        - If this state is a consistent state with a default action, then
1854          the only way this function was invoked is if the default action
1855          is an error action.  In that case, don't check for expected
1856          tokens because there are none.
1857        - The only way there can be no lookahead present (in yyla) is
1858          if this state is a consistent state with a default action.
1859          Thus, detecting the absence of a lookahead is sufficient to
1860          determine that there is no unexpected or expected token to
1861          report.  In that case, just report a simple "syntax error".
1862        - Don't assume there isn't a lookahead just because this state is
1863          a consistent state with a default action.  There might have
1864          been a previous inconsistent state, consistent state with a
1865          non-default action, or user semantic action that manipulated
1866          yyla.  (However, yyla is currently not documented for users.)
1867          In the first two cases, it might appear that the current syntax
1868          error should have been detected in the previous state when
1869          yy_lac_check was invoked.  However, at that time, there might
1870          have been a different syntax error that discarded a different
1871          initial context during error recovery, leaving behind the
1872          current lookahead.
1873     */
1874 
1875     if (!yyctx.lookahead ().empty ())
1876       {
1877         if (yyarg)
1878           yyarg[0] = yyctx.token ();
1879         int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1);
1880         return yyn + 1;
1881       }
1882     return 0;
1883   }
1884 
1885   // Generate an error message.
1886   std::string
yysyntax_error_(const context & yyctx) const1887   parser::yysyntax_error_ (const context& yyctx) const
1888   {
1889     // Its maximum.
1890     enum { YYARGS_MAX = 5 };
1891     // Arguments of yyformat.
1892     symbol_kind_type yyarg[YYARGS_MAX];
1893     int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX);
1894 
1895     char const* yyformat = YY_NULLPTR;
1896     switch (yycount)
1897       {
1898 #define YYCASE_(N, S)                         \
1899         case N:                               \
1900           yyformat = S;                       \
1901         break
1902       default: // Avoid compiler warnings.
1903         YYCASE_ (0, YY_("syntax error"));
1904         YYCASE_ (1, YY_("syntax error, unexpected %s"));
1905         YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
1906         YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1907         YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1908         YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1909 #undef YYCASE_
1910       }
1911 
1912     std::string yyres;
1913     // Argument number.
1914     std::ptrdiff_t yyi = 0;
1915     for (char const* yyp = yyformat; *yyp; ++yyp)
1916       if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1917         {
1918           yyres += symbol_name (yyarg[yyi++]);
1919           ++yyp;
1920         }
1921       else
1922         yyres += *yyp;
1923     return yyres;
1924   }
1925 
1926 
1927   const signed char parser::yypact_ninf_ = -52;
1928 
1929   const signed char parser::yytable_ninf_ = -12;
1930 
1931   const short
1932   parser::yypact_[] =
1933   {
1934        3,   -52,   -41,   -39,   -52,   -52,    -3,     5,     5,     5,
1935        7,    44,    10,     0,   101,    18,    30,    94,    51,    50,
1936      -52,    20,   -52,    13,   -52,    88,    17,   -52,   -52,   129,
1937      -52,   -52,     2,    85,   -52,   -52,     1,     1,   -52,   -52,
1938       40,   -52,   -52,   -52,    42,    58,   -52,    28,    96,   120,
1939      120,   120,   120,    15,   -52,   -52,   -52,   -52,   -52,   -52,
1940      -52,   -52,   120,   -52,   -52,   -52,   -52,   -52,   -52,   -52,
1941      -52,   120,   -52,    63,   -52,    63,   -52,   -52,   -52,   -52,
1942      -52,   -52,   -52,   120,   -52,   -52,   -52,   -52,     5,   -52,
1943      -52,   -52,   -52,   120,   -52,   -52,   -52,   -52,     3,   -52,
1944        1,     5,    45,   130,   -52,     1,     1,   -52,   177,   162,
1945      -52,    97,   132,   -52,   -52,   -52,   -52,    87,   -52,   -52,
1946        1,     5,     5,     5,     5,   -52,     5,     5,   -52,   -52,
1947      -52,   -52,    29,   118,     5,   -52,   170,   -52,   -52,   -52,
1948      182,   177,     1,     1,     1,     1,     1,     1,     1,   -52,
1949      -52,   -51,   -52,   177,   119,   -52,   -52,   -52,   -52,   -52,
1950      -52,   -52,    82,   -52,   -52,   -52,   182,   182,   107,   107,
1951      -52,   -52,   -52,   -52,   -52,   -52,   -52,   -52,   -52,   -52,
1952      -52,   -52,   -52,   -52,   -52
1953   };
1954 
1955   const signed char
1956   parser::yydefact_[] =
1957   {
1958        0,    12,     0,     0,    21,    22,     0,     0,     0,     0,
1959        0,    69,     0,     0,     0,   113,   115,     0,   123,     0,
1960       47,     0,   124,     0,    28,     0,     0,     3,    10,     9,
1961        6,     7,    46,     0,   126,     5,     0,     0,    30,    29,
1962       20,    23,    16,    27,     0,     0,    67,     0,     0,    75,
1963       75,    75,    75,     0,    51,    76,    79,    77,    78,    80,
1964       81,    82,    75,    83,    86,    87,    84,    85,    90,    89,
1965       88,    75,   112,   118,   114,   118,    91,    92,    93,    94,
1966       95,    96,    97,    75,   120,   122,   121,   119,     0,   108,
1967      111,   109,   110,    75,   125,    13,     1,     2,     0,     8,
1968        0,     0,    45,    44,    14,     0,     0,    32,    15,     0,
1969       19,    18,     0,    68,    62,    64,    63,     0,    65,    74,
1970        0,     0,     0,     0,     0,    49,     0,     0,   116,   117,
1971       54,    55,   107,    58,     0,     4,     0,    61,    43,    42,
1972       40,    41,     0,     0,     0,     0,     0,     0,     0,    31,
1973       17,     0,    66,    48,    71,    73,    72,    50,    52,    53,
1974      105,   106,     0,    57,    59,    60,    33,    34,    35,    36,
1975       37,    38,    39,    25,    26,    24,    70,    98,   101,    99,
1976      100,   103,   104,   102,    56
1977   };
1978 
1979   const short
1980   parser::yypgoto_[] =
1981   {
1982      -52,   -52,   -52,   102,   -52,   -52,   -52,    -7,   -14,   172,
1983      -52,    99,   103,   -52,   146,    25,   -52,   -52,   -52,   -52,
1984      -52,   -52,   -52,   -52,   128,   -52,   198
1985   };
1986 
1987   const short
1988   parser::yydefgoto_[] =
1989   {
1990       -1,    25,    26,    27,    28,    29,    30,   107,   108,    31,
1991       32,   102,   103,    49,    54,   120,    62,    71,    83,   184,
1992      162,    93,    73,    75,   130,    88,    33
1993   };
1994 
1995   const short
1996   parser::yytable_[] =
1997   {
1998       40,    41,    42,   -11,     1,    53,   -11,    37,    43,     2,
1999      100,    37,   105,   173,   174,     2,    37,    97,   175,   124,
2000       98,   106,    34,   109,    35,     3,     4,     5,     6,     7,
2001        8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
2002       18,    19,    20,    55,    56,   116,   117,    50,   160,   161,
2003       51,    52,    50,    57,    58,    51,    52,    59,    60,    21,
2004       22,    61,   101,    45,    38,    21,    22,    72,    38,    23,
2005       39,    24,    44,    38,    39,   121,   122,   123,    74,    39,
2006       95,   133,    84,    94,    46,   110,   136,   126,    96,    85,
2007      104,   140,   141,    89,   137,    90,   127,    47,    48,   111,
2008      113,    86,    87,    91,    92,   101,   153,   112,   132,   128,
2009      129,   114,   115,   118,   154,   155,   156,   157,   134,   158,
2010      159,   146,   147,   148,   119,   177,   178,   164,   166,   167,
2011      168,   169,   170,   171,   172,   179,   180,    76,   100,   181,
2012      182,   152,   150,   183,    63,    64,    65,    77,    78,    79,
2013       80,    81,    82,   151,    66,    67,    68,    69,    70,    11,
2014       12,    13,    14,    15,    16,    17,    18,    19,    20,   149,
2015      163,   176,   142,   143,   144,   145,   146,   147,   148,   165,
2016      142,   143,   144,   145,   146,   147,   148,   142,   143,   144,
2017      145,   146,   147,   148,   144,   145,   146,   147,   148,   125,
2018      135,    99,   139,   131,    36,   138
2019   };
2020 
2021   const unsigned char
2022   parser::yycheck_[] =
2023   {
2024        7,     8,     9,     0,     1,    12,     3,     6,     1,    12,
2025        8,     6,    11,    64,    65,    12,     6,     0,    69,     4,
2026        3,    20,    63,    37,    63,    22,    23,    24,    25,    26,
2027       27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
2028       37,    38,    39,    43,    44,    17,    18,    37,    19,    20,
2029       40,    41,    37,    53,    54,    40,    41,    57,    58,    62,
2030       63,    61,    60,    19,    63,    62,    63,    49,    63,    66,
2031       69,    68,    65,    63,    69,    50,    51,    52,    48,    69,
2032       67,    88,    31,    63,    40,    45,   100,    62,     0,    38,
2033        5,   105,   106,    43,   101,    45,    71,    53,    54,    59,
2034       42,    50,    51,    53,    54,    60,   120,    65,    83,    46,
2035       47,    53,    54,    17,   121,   122,   123,   124,    93,   126,
2036      127,    14,    15,    16,     4,    43,    44,   134,   142,   143,
2037      144,   145,   146,   147,   148,    53,    54,    43,     8,    57,
2038       58,    54,    45,    61,    43,    44,    45,    53,    54,    55,
2039       56,    57,    58,    21,    53,    54,    55,    56,    57,    30,
2040       31,    32,    33,    34,    35,    36,    37,    38,    39,     7,
2041       52,    52,    10,    11,    12,    13,    14,    15,    16,     9,
2042       10,    11,    12,    13,    14,    15,    16,    10,    11,    12,
2043       13,    14,    15,    16,    12,    13,    14,    15,    16,    53,
2044       98,    29,   103,    75,     6,   102
2045   };
2046 
2047   const signed char
2048   parser::yystos_[] =
2049   {
2050        0,     1,    12,    22,    23,    24,    25,    26,    27,    28,
2051       29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
2052       39,    62,    63,    66,    68,    71,    72,    73,    74,    75,
2053       76,    79,    80,    96,    63,    63,    96,     6,    63,    69,
2054       77,    77,    77,     1,    65,    19,    40,    53,    54,    83,
2055       37,    40,    41,    77,    84,    43,    44,    53,    54,    57,
2056       58,    61,    86,    43,    44,    45,    53,    54,    55,    56,
2057       57,    87,    49,    92,    48,    93,    43,    53,    54,    55,
2058       56,    57,    58,    88,    31,    38,    50,    51,    95,    43,
2059       45,    53,    54,    91,    63,    67,     0,     0,     3,    79,
2060        8,    60,    81,    82,     5,    11,    20,    77,    78,    78,
2061       45,    59,    65,    42,    53,    54,    17,    18,    17,     4,
2062       85,    85,    85,    85,     4,    84,    85,    85,    46,    47,
2063       94,    94,    85,    77,    85,    73,    78,    77,    82,    81,
2064       78,    78,    10,    11,    12,    13,    14,    15,    16,     7,
2065       45,    21,    54,    78,    77,    77,    77,    77,    77,    77,
2066       19,    20,    90,    52,    77,     9,    78,    78,    78,    78,
2067       78,    78,    78,    64,    65,    69,    52,    43,    44,    53,
2068       54,    57,    58,    61,    89
2069   };
2070 
2071   const signed char
2072   parser::yyr1_[] =
2073   {
2074        0,    70,    71,    72,    72,    73,    73,    73,    73,    73,
2075       73,    73,    73,    74,    75,    76,    76,    76,    76,    76,
2076       76,    76,    76,    76,    76,    76,    76,    76,    76,    77,
2077       77,    77,    78,    78,    78,    78,    78,    78,    78,    78,
2078       78,    78,    79,    79,    79,    79,    79,    80,    80,    80,
2079       80,    80,    80,    80,    80,    80,    80,    80,    80,    80,
2080       81,    82,    83,    83,    83,    83,    83,    83,    83,    83,
2081       84,    84,    84,    84,    85,    85,    86,    86,    86,    86,
2082       86,    86,    86,    87,    87,    87,    87,    87,    87,    87,
2083       87,    88,    88,    88,    88,    88,    88,    88,    89,    89,
2084       89,    89,    89,    89,    89,    90,    90,    90,    91,    91,
2085       91,    91,    92,    92,    93,    93,    94,    94,    94,    95,
2086       95,    95,    95,    95,    96,    96,    96
2087   };
2088 
2089   const signed char
2090   parser::yyr2_[] =
2091   {
2092        0,     2,     2,     1,     3,     2,     1,     1,     2,     1,
2093        1,     0,     1,     2,     2,     3,     2,     4,     3,     3,
2094        2,     1,     1,     2,     5,     5,     5,     2,     1,     1,
2095        1,     3,     1,     3,     3,     3,     3,     3,     3,     3,
2096        2,     2,     3,     3,     2,     2,     1,     1,     4,     3,
2097        4,     2,     4,     4,     3,     3,     5,     4,     3,     4,
2098        3,     2,     2,     2,     2,     2,     3,     1,     2,     0,
2099        4,     3,     3,     3,     1,     0,     1,     1,     1,     1,
2100        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2101        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2102        1,     1,     1,     1,     1,     1,     1,     0,     1,     1,
2103        1,     1,     1,     0,     1,     0,     1,     1,     0,     1,
2104        1,     1,     1,     0,     1,     2,     2
2105   };
2106 
2107 
2108 #if YYDEBUG || 1
2109   // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2110   // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
2111   const char*
2112   const parser::yytname_[] =
2113   {
2114   "\"end of file\"", "error", "\"invalid token\"", "\"end of line\"",
2115   "\",\"", "\":\"", "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"+\"", "\"-\"",
2116   "\"*\"", "\"/\"", "\"|\"", "\"&\"", "\"^\"", "\"--\"", "\"!=\"", "\"!\"",
2117   "\"::\"", "\"=\"", "\".program\"", "\".wrap_target\"", "\".wrap\"",
2118   "\".define\"", "\".side_set\"", "\".word\"", "\".origin\"",
2119   "\".lang_opt\"", "\"jmp\"", "\"wait\"", "\"in\"", "\"out\"", "\"push\"",
2120   "\"pull\"", "\"mov\"", "\"irq\"", "\"set\"", "\"nop\"", "\"pin\"",
2121   "\"gpio\"", "\"osre\"", "\"pins\"", "\"null\"", "\"pindirs\"",
2122   "\"block\"", "\"noblock\"", "\"ifempty\"", "\"iffull\"", "\"nowait\"",
2123   "\"clear\"", "\"rel\"", "\"x\"", "\"y\"", "\"exec\"", "\"pc\"",
2124   "\"isr\"", "\"osr\"", "\"opt\"", "\"side\"", "\"status\"", "\"public\"",
2125   "\"identifier\"", "\"string\"", "\"text\"", "\"code block\"", "\"%}\"",
2126   "UNKNOWN_DIRECTIVE", "\"integer\"", "$accept", "file", "lines", "line",
2127   "code_block", "label_decl", "directive", "value", "expression",
2128   "instruction", "base_instruction", "delay", "sideset", "condition",
2129   "wait_source", "comma", "in_source", "out_target", "mov_target",
2130   "mov_source", "mov_op", "set_target", "if_full", "if_empty", "blocking",
2131   "irq_modifiers", "symbol_def", YY_NULLPTR
2132   };
2133 #endif
2134 
2135 
2136 #if YYDEBUG
2137   const short
2138   parser::yyrline_[] =
2139   {
2140        0,   136,   136,   140,   141,   144,   145,   146,   147,   148,
2141      149,   150,   151,   155,   159,   162,   163,   164,   165,   166,
2142      167,   168,   169,   170,   171,   172,   173,   174,   175,   180,
2143      181,   182,   186,   187,   188,   189,   190,   191,   192,   193,
2144      194,   195,   199,   200,   201,   202,   203,   207,   208,   209,
2145      210,   211,   212,   213,   214,   215,   216,   217,   218,   219,
2146      224,   228,   232,   233,   234,   235,   236,   237,   238,   239,
2147      243,   244,   245,   246,   248,   248,   251,   252,   253,   254,
2148      255,   256,   257,   260,   261,   262,   263,   264,   265,   266,
2149      267,   270,   271,   272,   273,   274,   275,   276,   279,   280,
2150      281,   282,   283,   284,   285,   289,   290,   291,   295,   296,
2151      297,   298,   302,   303,   307,   308,   312,   313,   314,   318,
2152      319,   320,   321,   322,   326,   327,   328
2153   };
2154 
2155   void
yy_stack_print_() const2156   parser::yy_stack_print_ () const
2157   {
2158     *yycdebug_ << "Stack now";
2159     for (stack_type::const_iterator
2160            i = yystack_.begin (),
2161            i_end = yystack_.end ();
2162          i != i_end; ++i)
2163       *yycdebug_ << ' ' << int (i->state);
2164     *yycdebug_ << '\n';
2165   }
2166 
2167   void
yy_reduce_print_(int yyrule) const2168   parser::yy_reduce_print_ (int yyrule) const
2169   {
2170     int yylno = yyrline_[yyrule];
2171     int yynrhs = yyr2_[yyrule];
2172     // Print the symbols being reduced, and their result.
2173     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
2174                << " (line " << yylno << "):\n";
2175     // The symbols being reduced.
2176     for (int yyi = 0; yyi < yynrhs; yyi++)
2177       YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
2178                        yystack_[(yynrhs) - (yyi + 1)]);
2179   }
2180 #endif // YYDEBUG
2181 
2182 
2183 } // yy
2184 
2185 
error(const location_type & l,const std::string & m)2186 void yy::parser::error(const location_type& l, const std::string& m)
2187 {
2188    if (l.begin.filename) {
2189       std::cerr << l << ": " << m << '\n';
2190       pioasm.error_count++;
2191       if (l.begin.line == l.end.line && *l.begin.filename == *l.end.filename) {
2192         std::ifstream file(l.begin.filename->c_str());
2193         std::string line;
2194         for(int i = 0; i < l.begin.line; ++i) {
2195              std::getline(file, line);
2196         }
2197         fprintf(stderr, "%5d | %s\n", l.begin.line, line.c_str());
2198         fprintf(stderr, "%5s | %*s", "", l.begin.column, "^");
2199         for (int i = l.begin.column; i < l.end.column - 1; i++) {
2200               putc ('~', stderr);
2201         }
2202         putc ('\n', stderr);
2203       }
2204   } else {
2205       std::cerr << m << '\n';
2206   }
2207 }
2208 
2209