View Javadoc

1   /* Generated By:JavaCC: Do not edit this line. PoshParser.java */
2   package cz.cuni.amis.pogamut.sposh.elements;
3   
4   import cz.cuni.amis.pogamut.shady.ArgString;
5   import java.util.Collections;
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   public class PoshParser implements PoshParserConstants {
10      final static class Packet<FIRST, SECOND> {
11          Packet(FIRST first, SECOND second) {
12              this.first = first;
13              this.second = second;
14          }
15          public FIRST first;
16          public SECOND second;
17      }
18  
19      /**
20       * Take the token COMMENT and unescape its content.
21       */
22      private String unescape(String comment)  throws ParseException {
23          // comment token must have at least starting and ending double quote
24          int commentLength = comment.length();
25          if (commentLength < 2)
26              throw new ParseException();
27          if (comment.charAt(0) != '"' || comment.charAt(commentLength - 1) != '"')
28              throw new ParseException();
29  
30          String commentContent = comment.substring(1, commentLength - 1);
31          // ArgString throws different ParseException that this parser.
32          try {
33              return ArgString.unescape(commentContent);
34          } catch (Exception ex) {
35              throw new ParseException(ex.getMessage());
36          }
37      }
38  
39  /**
40   * FIXME: According to official grammar, plan can consists only from single
41   * competence or action pattern. Sorry, but I don't allow this for now.
42   * plan ::= "(" [ "(" <docstring> ]
43                  ( "(" <competence> | <action-pattern> )*
44                    "(" <drive-collection>
45                  ( "(" <competence> | <action-pattern> )* ")" 
46   */
47    final public PoshPlan parsePlan() throws ParseException {
48          PoshPlan plan = LapElementsFactory.createPlan();
49      jj_consume_token(LBRACE);
50      jj_consume_token(LBRACE);
51      planFirstElement(plan);
52      jj_consume_token(0);
53                                                          {if (true) return plan;}
54      throw new Error("Missing return statement in function");
55    }
56  
57  /**
58   * [ "(" <docstring> ]
59   * Part of plan rule. 
60   */
61    final public void planFirstElement(PoshPlan plan) throws ParseException {
62          ActionPattern ap;
63          Competence c;
64          DriveCollection dc;
65          Adopt ad;
66      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
67      case DOCUMENTATION:
68        docString(plan);
69        jj_consume_token(LBRACE);
70        planFirstHalf(plan);
71        break;
72      case AP:
73        ap = actionPattern();
74              plan.addActionPattern(ap);
75              // ex.currentToken = token;
76  
77        jj_consume_token(LBRACE);
78        planFirstHalf(plan);
79        break;
80      case COMPETENCE:
81        c = competence();
82              plan.addCompetence(c);
83              // ex.currentToken = token;
84  
85        jj_consume_token(LBRACE);
86        planFirstHalf(plan);
87        break;
88      case AD:
89        ad = adapt();
90                          plan.addAdopt(ad);
91                          // ex.currentToken = token;
92  
93        jj_consume_token(LBRACE);
94        planFirstHalf(plan);
95        break;
96      case DC:
97        driveCollection(plan.getDriveCollection());
98        planSecondHalf(plan);
99        break;
100     default:
101       jj_la1[0] = jj_gen;
102       jj_consume_token(-1);
103       throw new ParseException();
104     }
105   }
106 
107 /**
108  * First half of plan rule.
109  * ( "(" <competence> | <action-pattern> )*
110  */
111   final public void planFirstHalf(PoshPlan plan) throws ParseException {
112         ActionPattern ap;
113         Competence c;
114         Adopt ad;
115     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
116     case AP:
117       ap = actionPattern();
118             try {
119                 plan.addActionPattern(ap);
120             } catch (ParseException ex) {
121                 ex.currentToken = token;
122                 {if (true) throw ex;}
123             }
124       jj_consume_token(LBRACE);
125       planFirstHalf(plan);
126       break;
127     case COMPETENCE:
128       c = competence();
129             try {
130                 plan.addCompetence(c);
131             } catch (ParseException ex) {
132                 ex.currentToken = token;
133                 {if (true) throw ex;}
134             }
135       jj_consume_token(LBRACE);
136       planFirstHalf(plan);
137       break;
138     case AD:
139       ad = adapt();
140                         try {
141                 plan.addAdopt(ad);
142             } catch (ParseException ex) {
143                 ex.currentToken = token;
144                 {if (true) throw ex;}
145             }
146       jj_consume_token(LBRACE);
147       planFirstHalf(plan);
148       break;
149     case DC:
150       driveCollection(plan.getDriveCollection());
151       planSecondHalf(plan);
152       break;
153     default:
154       jj_la1[1] = jj_gen;
155       jj_consume_token(-1);
156       throw new ParseException();
157     }
158   }
159 
160 /**
161  * ( "(" <competence> | <action-pattern> )* 
162  *  Part of plan() rule
163  */
164   final public void planSecondHalf(PoshPlan plan) throws ParseException {
165     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
166     case LBRACE:
167       jj_consume_token(LBRACE);
168       planSecondHalfElements(plan);
169       break;
170     case RBRACE:
171       jj_consume_token(RBRACE);
172       break;
173     default:
174       jj_la1[2] = jj_gen;
175       jj_consume_token(-1);
176       throw new ParseException();
177     }
178   }
179 
180 /**
181  * ( <competence> | <action-pattern> ) planSecondHalf(plan)
182  */
183   final public void planSecondHalfElements(PoshPlan plan) throws ParseException {
184         ActionPattern ap;
185         Competence c;
186         Adopt ad;
187     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
188     case AP:
189       ap = actionPattern();
190             try {
191                 plan.addActionPattern(ap);
192             } catch (ParseException ex) {
193                 ex.currentToken = token;
194                 {if (true) throw ex;}
195             }
196       planSecondHalf(plan);
197       break;
198     case COMPETENCE:
199       c = competence();
200             try {
201                 plan.addCompetence(c);
202             } catch (ParseException ex) {
203                 ex.currentToken = token;
204                 {if (true) throw ex;}
205             }
206       planSecondHalf(plan);
207       break;
208     case AD:
209       ad = adapt();
210             try {
211                 plan.addAdopt(ad);
212             } catch (ParseException ex) {
213                 ex.currentToken = token;
214                 {if (true) throw ex;}
215             }
216       planSecondHalf(plan);
217       break;
218     default:
219       jj_la1[3] = jj_gen;
220       jj_consume_token(-1);
221       throw new ParseException();
222     }
223   }
224 
225 /**
226  * docstring ::= DOCUMENTATION COMMENT COMMENT COMMENT ")" 
227  */
228   final public void docString(PoshPlan plan) throws ParseException {
229     Token name, author, info;
230     jj_consume_token(DOCUMENTATION);
231     name = jj_consume_token(COMMENT);
232                      plan.setName(unescape(name.toString()));
233     author = jj_consume_token(COMMENT);
234                        plan.setAuthor(unescape(author.toString()));
235     info = jj_consume_token(COMMENT);
236                      plan.setInfo(unescape(info.toString()));
237     jj_consume_token(RBRACE);
238   }
239 
240 /**
241  * Take passed drive collection and put the data (name, drives) into it.
242  * <pre>
243  * driveCollection() :: "DC" <name> [ <goal> ] "(" "drives" ( "(" <drive-element>+ ")" )+ ")" ")"
244  * </pre>
245  * XXX: It has extra braces around <drive-element>, remove them
246  */
247   final public void driveCollection(DriveCollection dc) throws ParseException {
248     Token name;
249     DriveElement drive;
250     FormalParameters formalParameters = new FormalParameters();
251     jj_consume_token(DC);
252     name = jj_consume_token(NAME);
253                        dc.setName(name.toString());
254     driveCollectionGoal(dc, formalParameters);
255     label_1:
256     while (true) {
257       jj_consume_token(LBRACE);
258       label_2:
259       while (true) {
260         drive = driveElement(formalParameters);
261                                                      dc.addDrive(drive);
262         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
263         case LBRACE:
264           ;
265           break;
266         default:
267           jj_la1[4] = jj_gen;
268           break label_2;
269         }
270       }
271       jj_consume_token(RBRACE);
272       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
273       case LBRACE:
274         ;
275         break;
276       default:
277         jj_la1[5] = jj_gen;
278         break label_1;
279       }
280     }
281     jj_consume_token(RBRACE);
282     jj_consume_token(RBRACE);
283   }
284 
285 /**
286  * Process goal of DC (if exists).
287  * ( NIL | "(" <goal> | ) "(" <DRIVES>
288  * Part of driveCollection() rule.
289  */
290   final public void driveCollectionGoal(DriveCollection dc, FormalParameters formalParameters) throws ParseException {
291     List<Sense> goalSenses;
292     jj_consume_token(LBRACE);
293     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
294     case GOAL:
295       goalSenses = goal(formalParameters);
296                                            dc.getGoal().addAll(goalSenses);
297       jj_consume_token(LBRACE);
298       jj_consume_token(DRIVES);
299       break;
300     case DRIVES:
301       jj_consume_token(DRIVES);
302       break;
303     default:
304       jj_la1[6] = jj_gen;
305       jj_consume_token(-1);
306       throw new ParseException();
307     }
308   }
309 
310 /**
311  * Process goal sense and return them.
312  * goal ::= GOAL <senses> ")"
313  */
314   final public List<Sense> goal(FormalParameters formalParameters) throws ParseException {
315     List<Sense> senses;
316     jj_consume_token(GOAL);
317     senses = senses(formalParameters);
318     jj_consume_token(RBRACE);
319      {if (true) return senses;}
320     throw new Error("Missing return statement in function");
321   }
322 
323 /**
324  * Create a drive and return it.
325  * <pre>
326  * drive-element ::= "(" NAME ( NIL | "(" <trigger> | ) NAME ( NIL | "(" <freq> | ) <opt-comment> ")"
327  * </pre>
328  */
329   final public DriveElement driveElement(FormalParameters formalParameters) throws ParseException {
330     Token name;
331     Packet<Arguments, Freq> packet;
332     Token actionName;
333     List<Sense> triggerSenses;
334     String comment;
335     jj_consume_token(LBRACE);
336     name = jj_consume_token(NAME);
337     triggerSenses = driveElementTrigger(formalParameters);
338     actionName = jj_consume_token(NAME);
339     packet = driveElementActionFreq(formalParameters);
340     comment = optComment();
341     jj_consume_token(RBRACE);
342             {if (true) return LapElementsFactory.createDriveElement(name.toString(), triggerSenses, new PrimitiveCall(actionName.toString(), packet.first), packet.second, comment);}
343     throw new Error("Missing return statement in function");
344   }
345 
346 /**
347  * Nonterminal for possible arguments of the action call of the drive action and 
348  * the frequency.
349  * <code>
350  * driveElementActionFreq:: ( <nil> | "(" ( <freq> | <args> <freq> ) | )
351  * </code>
352  * I should probably use lookahead of 2 or more, but I really need this fast 
353  * for continuous syntax highlighting.  
354  */
355   final public Packet<Arguments, Freq> driveElementActionFreq(FormalParameters formalParameters) throws ParseException {
356     Arguments arguments = new Arguments();
357     Freq freq = Freq.INFINITE;
358     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
359     case NIL:
360       jj_consume_token(NIL);
361             {if (true) return new Packet<Arguments, Freq>(arguments, freq);}
362       break;
363     case LBRACE:
364       jj_consume_token(LBRACE);
365       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
366       case HOURS:
367       case MINUTES:
368       case SECONDS:
369       case HZ:
370       case PM:
371       case NONE:
372         freq = freq();
373                     {if (true) return new Packet<Arguments, Freq>(arguments, freq);}
374         break;
375       case NIL:
376       case TRUE:
377       case FALSE:
378       case NUMFLOAT:
379       case NUMINT:
380       case ENUM_VALUE:
381       case COMMENT:
382       case VARIABLE:
383         arguments = callParametersList(formalParameters);
384         freq = driveElementFreq();
385                     {if (true) return new Packet<Arguments, Freq>(arguments, freq);}
386         break;
387       default:
388         jj_la1[7] = jj_gen;
389         jj_consume_token(-1);
390         throw new ParseException();
391       }
392       break;
393     default:
394       jj_la1[8] = jj_gen;
395             {if (true) return new Packet<Arguments, Freq>(arguments, freq);}
396     }
397     throw new Error("Missing return statement in function");
398   }
399 
400 /**
401  * Read trigger (list of senses) and return it.
402  * <p/>
403  * <code>( NIL | "(" <trigger> | ) </code>
404  * Part of driveElement rule
405  */
406   final public List<Sense> driveElementTrigger(FormalParameters formalParameters) throws ParseException {
407     List<Sense> senses;
408     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
409     case NIL:
410       jj_consume_token(NIL);
411       {if (true) return Collections.<Sense>emptyList();}
412       break;
413     case LBRACE:
414       jj_consume_token(LBRACE);
415       senses = trigger(formalParameters);
416       {if (true) return senses;}
417       break;
418     default:
419       jj_la1[9] = jj_gen;
420       {if (true) return Collections.<Sense>emptyList();}
421     }
422     throw new Error("Missing return statement in function");
423   }
424 
425 /**
426  * Get specified frequency. If no frequency specified, return {@link Freq#INFINITE}.
427  * ( NIL | "(" <freq> | )
428  * Part of driveElementRule
429  */
430   final public Freq driveElementFreq() throws ParseException {
431     Freq _freq;
432     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
433     case NIL:
434       jj_consume_token(NIL);
435       {if (true) return Freq.INFINITE;}
436       break;
437     case LBRACE:
438       jj_consume_token(LBRACE);
439       _freq = freq();
440      {if (true) return _freq;}
441       break;
442     default:
443       jj_la1[10] = jj_gen;
444      {if (true) return Freq.INFINITE;}
445     }
446     throw new Error("Missing return statement in function");
447   }
448 
449 /**
450  * competence ::= C NAME ( NIL | "(" <time> | ) ( NIL | "(" <goal> | ) "(" ELEMENTS <competence-priorities> ")" <opt-comment> ")" 
451  */
452   final public Competence competence() throws ParseException {
453         Token _name;
454         FormalParameters params = new FormalParameters();
455         List<CompetenceElement> competenceElements;
456         String _comment="";
457     jj_consume_token(COMPETENCE);
458     _name = jj_consume_token(NAME);
459     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
460     case VARS:
461       params = parameters();
462       break;
463     default:
464       jj_la1[11] = jj_gen;
465       ;
466     }
467     jj_consume_token(LBRACE);
468     jj_consume_token(ELEMENTS);
469     competenceElements = competencePriorities(params);
470     jj_consume_token(RBRACE);
471     _comment = optComment();
472     jj_consume_token(RBRACE);
473                 {if (true) return new Competence(_name.toString(), params, competenceElements);}
474     throw new Error("Missing return statement in function");
475   }
476 
477 /**
478  * Declare parameters in C or AP.
479  * parameters:: "vars" "(" varDeclaration() ( "," varDeclaration() )* ")"
480  */
481   final public FormalParameters parameters() throws ParseException {
482     FormalParameters.Parameter param = null;
483     FormalParameters params = new FormalParameters();
484     jj_consume_token(VARS);
485     jj_consume_token(LBRACE);
486     param = varDeclaration();
487           params.add(param);
488     label_3:
489     while (true) {
490       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
491       case COMMA:
492         ;
493         break;
494       default:
495         jj_la1[12] = jj_gen;
496         break label_3;
497       }
498       jj_consume_token(COMMA);
499       param = varDeclaration();
500           try {
501             params.add(param);
502           } catch (IllegalArgumentException ex) {
503             ParseException parseException = new ParseException(ex.getMessage());
504             parseException.currentToken = token;
505             {if (true) throw parseException;}
506           }
507     }
508     jj_consume_token(RBRACE);
509          {if (true) return params;}
510     throw new Error("Missing return statement in function");
511   }
512 
513 /**
514  * varDeclare:: <VARIABLE> "=" value()
515  */
516   final public FormalParameters.Parameter varDeclaration() throws ParseException {
517     Token variable = null;
518     Object defaultValue = null;
519     variable = jj_consume_token(VARIABLE);
520     jj_consume_token(EQUAL_SIGN);
521     defaultValue = value();
522                                                    {if (true) return new FormalParameters.Parameter(variable.toString(), defaultValue);}
523     throw new Error("Missing return statement in function");
524   }
525 
526 /**
527  * ( NIL | "(" <time> | ) ( NIL | "(" <goal> | ) "(" ELEMENTS
528  * Part of competence() rule, Really ugly, but it has to check 8 combinations.
529  */
530 /*
531 TimeGoal competenceTimeGoal(FormalParameters formalParameters):
532 {
533 	TimeGoal tg = new TimeGoal();
534 }
535 {
536     <NIL> tg.goal=competenceGoal(formalParameters) { return tg; }
537 |
538     "(" ( 
539 			 		tg.time=time()   tg.goal=competenceGoal(formalParameters) { return tg;} 
540 			 | 
541 					<ELEMENTS> { return tg;}
542 		   | 
543 			    tg.goal=goal(formalParameters) "(" <ELEMENTS> { return tg;}
544 			 	 )
545 }*/
546 
547 /**
548  * ( NIL | "(" <goal> | ) "(" ELEMENTS
549  * Part of competence() rule
550  */
551   final public List<Sense> competenceGoal(FormalParameters formalParameters) throws ParseException {
552     List<Sense> goalSenses;
553     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
554     case NIL:
555       jj_consume_token(NIL);
556       jj_consume_token(LBRACE);
557       jj_consume_token(ELEMENTS);
558                           {if (true) return Collections.<Sense>emptyList();}
559       break;
560     case LBRACE:
561       jj_consume_token(LBRACE);
562       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
563       case GOAL:
564         goalSenses = goal(formalParameters);
565         break;
566       case ELEMENTS:
567         jj_consume_token(ELEMENTS);
568                                                           {if (true) return Collections.<Sense>emptyList();}
569         break;
570       default:
571         jj_la1[13] = jj_gen;
572         jj_consume_token(-1);
573         throw new ParseException();
574       }
575       jj_consume_token(LBRACE);
576       jj_consume_token(ELEMENTS);
577                                                                                                                     {if (true) return goalSenses;}
578       break;
579     default:
580       jj_la1[14] = jj_gen;
581       jj_consume_token(-1);
582       throw new ParseException();
583     }
584     throw new Error("Missing return statement in function");
585   }
586 
587 /**
588  * competence-priorities ::= <competence-elements>+
589  * competence-elements ::= "(" <competence-element>+ ")"
590  *
591  * => competence-priorities ::= ( "(" <competence-element>+ ")" )+.
592  */
593   final public List<CompetenceElement> competencePriorities(FormalParameters formalParameters) throws ParseException {
594     CompetenceElement ce;
595     List<CompetenceElement> result = new LinkedList<CompetenceElement>();
596     label_4:
597     while (true) {
598       jj_consume_token(LBRACE);
599       label_5:
600       while (true) {
601         ce = competenceElement(formalParameters);
602                     result.add(ce);
603         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
604         case LBRACE:
605           ;
606           break;
607         default:
608           jj_la1[15] = jj_gen;
609           break label_5;
610         }
611       }
612       jj_consume_token(RBRACE);
613       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
614       case LBRACE:
615         ;
616         break;
617       default:
618         jj_la1[16] = jj_gen;
619         break label_4;
620       }
621     }
622         {if (true) return result;}
623     throw new Error("Missing return statement in function");
624   }
625 
626 /**
627  * competence-element ::= "(" NAME [ "(" <trigger> ] NAME [ INTNUM ] <opt-comment> ")"
628  */
629   final public CompetenceElement competenceElement(FormalParameters formalParameters) throws ParseException {
630         CompetenceElement _element;
631         Token name= null;
632         int retries;
633         PrimitiveCall actionCall = null;
634         List<Sense> triggerSenses = Collections.<Sense>emptyList();
635         String comment;
636     jj_consume_token(LBRACE);
637     name = jj_consume_token(NAME);
638     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
639     case LBRACE:
640       jj_consume_token(LBRACE);
641       triggerSenses = trigger(formalParameters);
642       break;
643     default:
644       jj_la1[17] = jj_gen;
645       ;
646     }
647     actionCall = senseCall(formalParameters);
648     retries = optRetries();
649     comment = optComment();
650     jj_consume_token(RBRACE);
651         {if (true) return new CompetenceElement(name.toString(), triggerSenses, actionCall, retries, comment);}
652     throw new Error("Missing return statement in function");
653   }
654 
655 /**
656  * Optional number of retries. If missing, return {@link CompetenceElement#INFINITE_RETRIES}.
657  */
658   final public int optRetries() throws ParseException {
659     Token retries;
660     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
661     case NUMINT:
662       retries = jj_consume_token(NUMINT);
663                        {if (true) return Integer.parseInt(retries.toString());}
664       break;
665     default:
666       jj_la1[18] = jj_gen;
667      {if (true) return CompetenceElement.INFINITE_RETRIES;}
668     }
669     throw new Error("Missing return statement in function");
670   }
671 
672 /**
673  * Optional comment, if no comment, return blank string.
674  * opt-comment ::= COMMENT | 
675  * @return Comment or if comment is missing, blank string.
676  */
677   final public String optComment() throws ParseException {
678         Token _comment;
679     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
680     case COMMENT:
681       _comment = jj_consume_token(COMMENT);
682                 {if (true) return unescape(_comment.toString());}
683       break;
684     default:
685       jj_la1[19] = jj_gen;
686      {if (true) return "";}
687     }
688     throw new Error("Missing return statement in function");
689   }
690 
691 /**
692  * action-pattern ::= AP NAME ( NIL | "(" <time> | ) "(" <action-pattern-elements> <opt-comment> ")"  
693  */
694   final public ActionPattern actionPattern() throws ParseException {
695     ActionPattern ap;
696     Token name;
697     FormalParameters params = new FormalParameters();
698     String comment;
699     jj_consume_token(AP);
700     name = jj_consume_token(NAME);
701     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
702     case VARS:
703       params = parameters();
704       break;
705     default:
706       jj_la1[20] = jj_gen;
707       ;
708     }
709         ap = LapElementsFactory.createActionPattern(name.toString(), params);
710     jj_consume_token(LBRACE);
711     actionPatternElements(ap, params);
712     comment = optComment();
713                                                                 ap.setComment(comment);
714     jj_consume_token(RBRACE);
715      {if (true) return ap;}
716     throw new Error("Missing return statement in function");
717   }
718 
719 /**
720  * adapt ::= AD NAME [ <parameters> ] "(" "(" <goal> "(" <actionCall> ")"  
721  */
722   final public Adopt adapt() throws ParseException {
723     Token name;
724     FormalParameters params = new FormalParameters();
725     List<Sense> exitCondition = Collections.<Sense>emptyList();
726     PrimitiveCall actionCall = null;
727     jj_consume_token(AD);
728     name = jj_consume_token(NAME);
729     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
730     case VARS:
731       params = parameters();
732       break;
733     default:
734       jj_la1[21] = jj_gen;
735       ;
736     }
737     jj_consume_token(LBRACE);
738     jj_consume_token(LBRACE);
739     exitCondition = goal(params);
740     jj_consume_token(LBRACE);
741     actionCall = senseCall(params);
742     jj_consume_token(RBRACE);
743     jj_consume_token(RBRACE);
744     jj_consume_token(RBRACE);
745         {if (true) return new Adopt(name.toString(), params, exitCondition, actionCall);}
746     throw new Error("Missing return statement in function");
747   }
748 
749 /**
750  * process actions of the AP and add them into the passed ap.
751  * action-pattern-elements ::= ( <full-sense> | NAME )+ ")"
752  * FIXME: full-sense is not implemented here, because I have no idea what to do with it.
753  *        I have't even seen it used anywhere so it is doable for now.
754  */
755   final public void actionPatternElements(ActionPattern ap, FormalParameters formalParameters) throws ParseException {
756     List<TriggeredAction> _actList = new LinkedList<TriggeredAction>();
757     PrimitiveCall actionCall;
758     label_6:
759     while (true) {
760       actionCall = senseCall(formalParameters);
761             ap.addAction(LapElementsFactory.createAction(actionCall));
762       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
763       case NAME:
764         ;
765         break;
766       default:
767         jj_la1[22] = jj_gen;
768         break label_6;
769       }
770     }
771     jj_consume_token(RBRACE);
772   }
773 
774 /**
775  * time ::= <time-unit> <numfloat> ")" 
776  */
777   final public SolTime time() throws ParseException {
778      SolTime.TimeUnits _units;
779         Token _ammount;
780     _units = timeUnit();
781     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
782     case NUMFLOAT:
783       _ammount = jj_consume_token(NUMFLOAT);
784       break;
785     case NUMINT:
786       _ammount = jj_consume_token(NUMINT);
787       break;
788     default:
789       jj_la1[23] = jj_gen;
790       jj_consume_token(-1);
791       throw new ParseException();
792     }
793     jj_consume_token(RBRACE);
794                 {if (true) return new SolTime( _units, _ammount.toString() );}
795     throw new Error("Missing return statement in function");
796   }
797 
798 /**
799  * time-unit ::= HOURS | MINUTES | SECONDS | NONE
800  */
801   final public SolTime.TimeUnits timeUnit() throws ParseException {
802     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
803     case HOURS:
804       jj_consume_token(HOURS);
805                {if (true) return SolTime.TimeUnits.HOURS;}
806       break;
807     case MINUTES:
808       jj_consume_token(MINUTES);
809                {if (true) return SolTime.TimeUnits.MINUTES;}
810       break;
811     case SECONDS:
812       jj_consume_token(SECONDS);
813                {if (true) return SolTime.TimeUnits.SECONDS;}
814       break;
815     case NONE:
816       jj_consume_token(NONE);
817                {if (true) return SolTime.TimeUnits.NONE;}
818       break;
819     default:
820       jj_la1[24] = jj_gen;
821       jj_consume_token(-1);
822       throw new ParseException();
823     }
824     throw new Error("Missing return statement in function");
825   }
826 
827 /**
828  * freq ::= <freq-unit> <numfloat> ")"
829  */
830   final public Freq freq() throws ParseException {
831     Freq.FreqUnits _units;
832         Token _count;
833     _units = freqUnit();
834     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
835     case NUMFLOAT:
836       _count = jj_consume_token(NUMFLOAT);
837       break;
838     case NUMINT:
839       _count = jj_consume_token(NUMINT);
840       break;
841     default:
842       jj_la1[25] = jj_gen;
843       jj_consume_token(-1);
844       throw new ParseException();
845     }
846     jj_consume_token(RBRACE);
847                 {if (true) return new Freq(Double.parseDouble(_count.toString()), _units);}
848     throw new Error("Missing return statement in function");
849   }
850 
851 /**
852  *  freq-unit ::= HOURS | MINUTES | SECONDS | HZ | PM | NONE
853  */
854   final public Freq.FreqUnits freqUnit() throws ParseException {
855     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
856     case HOURS:
857       jj_consume_token(HOURS);
858               {if (true) return Freq.FreqUnits.HOURS;}
859       break;
860     case MINUTES:
861       jj_consume_token(MINUTES);
862                 {if (true) return Freq.FreqUnits.MINUTES;}
863       break;
864     case SECONDS:
865       jj_consume_token(SECONDS);
866                 {if (true) return Freq.FreqUnits.SECONDS;}
867       break;
868     case HZ:
869       jj_consume_token(HZ);
870            {if (true) return Freq.FreqUnits.HZ;}
871       break;
872     case PM:
873       jj_consume_token(PM);
874            {if (true) return Freq.FreqUnits.PM;}
875       break;
876     case NONE:
877       jj_consume_token(NONE);
878              {if (true) return Freq.FreqUnits.NONE;}
879       break;
880     default:
881       jj_la1[26] = jj_gen;
882       jj_consume_token(-1);
883       throw new ParseException();
884     }
885     throw new Error("Missing return statement in function");
886   }
887 
888 /**
889  * Get list of senses of a trigger.
890  * trigger ::= <TRIGGER> <senses> ")" 
891  */
892   final public List<Sense> trigger(FormalParameters formalParameters) throws ParseException {
893         List<Sense> triggerSenses;
894     jj_consume_token(TRIGGER);
895     triggerSenses = senses(formalParameters);
896     jj_consume_token(RBRACE);
897           {if (true) return triggerSenses;}
898     throw new Error("Missing return statement in function");
899   }
900 
901 /**
902  * Get senses (if there are any) and return them.
903  * senses ::= ( NIL | "(" ( NAME | <full-sense> )+ ")" )
904  */
905   final public List<Sense> senses(FormalParameters formalParameters) throws ParseException {
906     List<Sense> senses;
907     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
908     case NIL:
909       jj_consume_token(NIL);
910      {if (true) return Collections.<Sense>emptyList();}
911       break;
912     case LBRACE:
913       jj_consume_token(LBRACE);
914       senses = sensesList(formalParameters);
915       jj_consume_token(RBRACE);
916      {if (true) return senses;}
917       break;
918     default:
919       jj_la1[27] = jj_gen;
920       jj_consume_token(-1);
921       throw new ParseException();
922     }
923     throw new Error("Missing return statement in function");
924   }
925 
926 /**
927  * ( NAME | <full-sense> )+ 
928  * Part of sense() rule.
929  */
930   final public List<Sense> sensesList(FormalParameters formalParameters) throws ParseException {
931     Sense sense;
932     List<Sense> sensesList = new LinkedList<Sense>();
933     label_7:
934     while (true) {
935       sense = sensesListElement(formalParameters);
936           sensesList.add(sense);
937       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
938       case LBRACE:
939       case NAME:
940         ;
941         break;
942       default:
943         jj_la1[28] = jj_gen;
944         break label_7;
945       }
946     }
947       {if (true) return sensesList;}
948     throw new Error("Missing return statement in function");
949   }
950 
951 /**
952  * NAME | <full-sense>
953  * Part of sensesList() rule
954  * XXX: I am using <NAME> in first case, so it is impossible to have (sense1(sense2)) vs (sense1(simple_string))
955  *      because the calling vars are not compulsory, yet   
956  */
957   final public Sense sensesListElement(FormalParameters formalParameters) throws ParseException {
958     Token senseName;
959     Sense _sense;
960     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
961     case NAME:
962       senseName = jj_consume_token(NAME);
963       {if (true) return new Sense(senseName.toString());}
964       break;
965     case LBRACE:
966       _sense = fullSense(formalParameters);
967       {if (true) return _sense;}
968       break;
969     default:
970       jj_la1[29] = jj_gen;
971       jj_consume_token(-1);
972       throw new ParseException();
973     }
974     throw new Error("Missing return statement in function");
975   }
976 
977 /**
978  * full-sense ::= "(" NAME [<value> [<predicate>]] ")"
979  */
980   final public Sense fullSense(FormalParameters formalParameters) throws ParseException {
981     SenseComponents _senseComp = new SenseComponents();
982     PrimitiveCall senseCall;
983     jj_consume_token(LBRACE);
984     senseCall = senseCall(formalParameters);
985     senseValue(_senseComp);
986         // didn't assign
987         if (_senseComp.value == null) {
988             {if (true) return new Sense(senseCall);}
989         } else {
990             {if (true) return new Sense( senseCall, _senseComp.value, _senseComp.predicate == null
991                 ? cz.cuni.amis.pogamut.sposh.elements.Sense.Predicate.DEFAULT
992                 : _senseComp.predicate);}
993         }
994     throw new Error("Missing return statement in function");
995   }
996 
997 /**
998  * SenseCall
999  * sense:: <NAME> [ "(" callParametersList() ]
1000  */
1001   final public PrimitiveCall senseCall(FormalParameters formalParameters) throws ParseException {
1002     Arguments arguments = new Arguments();
1003     Token name;
1004     name = jj_consume_token(NAME);
1005     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1006     case LBRACE:
1007       jj_consume_token(LBRACE);
1008       arguments = callParametersList(formalParameters);
1009       break;
1010     default:
1011       jj_la1[30] = jj_gen;
1012       ;
1013     }
1014             {if (true) return new PrimitiveCall(name.toString(), arguments);}
1015     throw new Error("Missing return statement in function");
1016   }
1017 
1018 /**
1019  * callParametersList:: callParameter() ( "," callParameter() )* ")" 
1020  */
1021   final public Arguments callParametersList(FormalParameters formalParameters) throws ParseException {
1022     int index=0;
1023     Arguments arguments = new Arguments();
1024     Packet<Arguments.Argument, Boolean> packet = null;
1025     boolean named = false;
1026     packet = callParameter(index, named);
1027             named = packet.second;
1028             try {
1029                 arguments.addFormal(packet.first, formalParameters);
1030                 ++index;
1031             } catch (IllegalArgumentException ex) {
1032                 ParseException parseEx = new ParseException(ex.getMessage());
1033                 parseEx.currentToken = token;
1034                 {if (true) throw parseEx;}
1035             }
1036     label_8:
1037     while (true) {
1038       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1039       case COMMA:
1040         ;
1041         break;
1042       default:
1043         jj_la1[31] = jj_gen;
1044         break label_8;
1045       }
1046       jj_consume_token(COMMA);
1047       packet = callParameter(index, named);
1048             named = packet.second;
1049             try {
1050                 arguments.addFormal(packet.first, formalParameters);
1051                 ++index;
1052             } catch (IllegalArgumentException ex) {
1053                 ParseException parseEx = new ParseException(ex.getMessage());
1054                 parseEx.currentToken = token;
1055                 {if (true) throw parseEx;}
1056             }
1057     }
1058     jj_consume_token(RBRACE);
1059         {if (true) return arguments;}
1060     throw new Error("Missing return statement in function");
1061   }
1062 
1063 /**
1064  * Parameter used when calling C/AP/sense/action
1065  * callParameter :: <VARIABLE> [ "=" ( <VARIABLE> | value() ) ]
1066  * @param named was at least one named call parameter specified in the list before this one?     
1067  */
1068   final public Packet<Arguments.Argument, Boolean> callParameter(int index, boolean named) throws ParseException {
1069     Token variable = null;
1070     Object value = null;
1071     Token valueVariable = null;
1072     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1073     case NIL:
1074     case TRUE:
1075     case FALSE:
1076     case NUMFLOAT:
1077     case NUMINT:
1078     case ENUM_VALUE:
1079     case COMMENT:
1080       value = value();
1081             if (named) {
1082                 // sonar is complaining about \" transformed into unicode \ 
1083                 char doubleQuote = '"';
1084                 ParseException ex = new ParseException("Specified unnamed parameter " + doubleQuote + index + doubleQuote + " after at least one named parameter.");
1085                 ex.currentToken = token;
1086                 {if (true) throw ex;}
1087             }
1088             {if (true) return new Packet<Arguments.Argument, Boolean>(new Arguments.ValueArgument(index, value), false);}
1089       break;
1090     case VARIABLE:
1091       variable = jj_consume_token(VARIABLE);
1092       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1093       case EQUAL_SIGN:
1094         jj_consume_token(EQUAL_SIGN);
1095         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1096         case VARIABLE:
1097           valueVariable = jj_consume_token(VARIABLE);
1098                 {if (true) return new Packet<Arguments.Argument, Boolean>(
1099                     new Arguments.VariableArgument(variable.toString(), valueVariable.toString()),
1100                     true);}
1101           break;
1102         case NIL:
1103         case TRUE:
1104         case FALSE:
1105         case NUMFLOAT:
1106         case NUMINT:
1107         case ENUM_VALUE:
1108         case COMMENT:
1109           value = value();
1110                 {if (true) return new Packet<Arguments.Argument, Boolean>(new Arguments.ValueArgument(variable.toString(), value), true);}
1111           break;
1112         default:
1113           jj_la1[32] = jj_gen;
1114           jj_consume_token(-1);
1115           throw new ParseException();
1116         }
1117         break;
1118       default:
1119         jj_la1[33] = jj_gen;
1120         ;
1121       }
1122             if (named) {
1123                 // sonar is complaining about \" transformed into unicode \ 
1124                 char doubleQuote = '"';
1125                 ParseException ex = new ParseException("Specified unnamed parameter " + doubleQuote + index + doubleQuote + " after at least one named parameter.");
1126                 ex.currentToken = token;
1127                 {if (true) throw ex;}
1128             }
1129             {if (true) return new Packet<Arguments.Argument, Boolean>(new Arguments.VariableArgument(index, variable.toString()), false);}
1130       break;
1131     default:
1132       jj_la1[34] = jj_gen;
1133       jj_consume_token(-1);
1134       throw new ParseException();
1135     }
1136     throw new Error("Missing return statement in function");
1137   }
1138 
1139 /**
1140  * value ::= NUMINT | NUMFLOAT | NAME | ENUM_VALUE | NIL
1141  * Part of full-sense parsing.
1142  */
1143   final public void senseValue(SenseComponents _senseComp) throws ParseException {
1144     Object _value;
1145     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1146     case RBRACE:
1147       jj_consume_token(RBRACE);
1148       break;
1149     case NIL:
1150     case TRUE:
1151     case FALSE:
1152     case NUMFLOAT:
1153     case NUMINT:
1154     case ENUM_VALUE:
1155     case COMMENT:
1156       _value = value();
1157       sensePredicate(_senseComp);
1158         _senseComp.value = _value;
1159       break;
1160     default:
1161       jj_la1[35] = jj_gen;
1162       jj_consume_token(-1);
1163       throw new ParseException();
1164     }
1165   }
1166 
1167 /**
1168  * predicate ::= PREDICATE
1169  */
1170   final public void sensePredicate(SenseComponents _senseComp) throws ParseException {
1171     Token _predicateToken;
1172     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1173     case RBRACE:
1174       jj_consume_token(RBRACE);
1175       break;
1176     case PREDICATE:
1177       _predicateToken = jj_consume_token(PREDICATE);
1178       jj_consume_token(RBRACE);
1179         _senseComp.predicate = Sense.Predicate.getPredicate(_predicateToken.toString());
1180       break;
1181     default:
1182       jj_la1[36] = jj_gen;
1183       jj_consume_token(-1);
1184       throw new ParseException();
1185     }
1186   }
1187 
1188   final public Object value() throws ParseException {
1189     Token _value;
1190     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
1191     case NUMINT:
1192       _value = jj_consume_token(NUMINT);
1193         {if (true) return Integer.parseInt(_value.toString());}
1194       break;
1195     case NUMFLOAT:
1196       _value = jj_consume_token(NUMFLOAT);
1197         {if (true) return Double.parseDouble(_value.toString());}
1198       break;
1199     case TRUE:
1200       _value = jj_consume_token(TRUE);
1201         {if (true) return Boolean.TRUE;}
1202       break;
1203     case FALSE:
1204       _value = jj_consume_token(FALSE);
1205         {if (true) return Boolean.FALSE;}
1206       break;
1207     case ENUM_VALUE:
1208       _value = jj_consume_token(ENUM_VALUE);
1209         {if (true) return new EnumValue(_value.toString().substring(1));}
1210       break;
1211     case NIL:
1212       _value = jj_consume_token(NIL);
1213         {if (true) return null;}
1214       break;
1215     case COMMENT:
1216       _value = jj_consume_token(COMMENT);
1217         {if (true) return unescape(_value.toString());}
1218       break;
1219     default:
1220       jj_la1[37] = jj_gen;
1221       jj_consume_token(-1);
1222       throw new ParseException();
1223     }
1224     throw new Error("Missing return statement in function");
1225   }
1226 
1227   /** Generated Token Manager. */
1228   public PoshParserTokenManager token_source;
1229   SimpleCharStream jj_input_stream;
1230   /** Current token. */
1231   public Token token;
1232   /** Next token. */
1233   public Token jj_nt;
1234   private int jj_ntk;
1235   private int jj_gen;
1236   final private int[] jj_la1 = new int[38];
1237   static private int[] jj_la1_0;
1238   static private int[] jj_la1_1;
1239   static {
1240       jj_la1_init_0();
1241       jj_la1_init_1();
1242    }
1243    private static void jj_la1_init_0() {
1244       jj_la1_0 = new int[] {0x800f00,0xf00,0xc0,0xe00,0x40,0x40,0x402000,0xd82fc000,0x200040,0x200040,0x200040,0x1000000,0x2000000,0x3000,0x200040,0x40,0x40,0x40,0x80000000,0x0,0x1000000,0x1000000,0x0,0xc0000000,0x9c000,0xc0000000,0xfc000,0x200040,0x40,0x40,0x40,0x2000000,0xd8200000,0x4000000,0xd8200000,0xd8200080,0x20000080,0xd8200000,};
1245    }
1246    private static void jj_la1_init_1() {
1247       jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x1c,0x0,0x1c,0xc,0x0,0xc,};
1248    }
1249 
1250   /** Constructor with InputStream. */
1251   public PoshParser(java.io.InputStream stream) {
1252      this(stream, null);
1253   }
1254   /** Constructor with InputStream and supplied encoding */
1255   public PoshParser(java.io.InputStream stream, String encoding) {
1256     try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
1257     token_source = new PoshParserTokenManager(jj_input_stream);
1258     token = new Token();
1259     jj_ntk = -1;
1260     jj_gen = 0;
1261     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1262   }
1263 
1264   /** Reinitialise. */
1265   public void ReInit(java.io.InputStream stream) {
1266      ReInit(stream, null);
1267   }
1268   /** Reinitialise. */
1269   public void ReInit(java.io.InputStream stream, String encoding) {
1270     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
1271     token_source.ReInit(jj_input_stream);
1272     token = new Token();
1273     jj_ntk = -1;
1274     jj_gen = 0;
1275     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1276   }
1277 
1278   /** Constructor. */
1279   public PoshParser(java.io.Reader stream) {
1280     jj_input_stream = new SimpleCharStream(stream, 1, 1);
1281     token_source = new PoshParserTokenManager(jj_input_stream);
1282     token = new Token();
1283     jj_ntk = -1;
1284     jj_gen = 0;
1285     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1286   }
1287 
1288   /** Reinitialise. */
1289   public void ReInit(java.io.Reader stream) {
1290     jj_input_stream.ReInit(stream, 1, 1);
1291     token_source.ReInit(jj_input_stream);
1292     token = new Token();
1293     jj_ntk = -1;
1294     jj_gen = 0;
1295     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1296   }
1297 
1298   /** Constructor with generated Token Manager. */
1299   public PoshParser(PoshParserTokenManager tm) {
1300     token_source = tm;
1301     token = new Token();
1302     jj_ntk = -1;
1303     jj_gen = 0;
1304     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1305   }
1306 
1307   /** Reinitialise. */
1308   public void ReInit(PoshParserTokenManager tm) {
1309     token_source = tm;
1310     token = new Token();
1311     jj_ntk = -1;
1312     jj_gen = 0;
1313     for (int i = 0; i < 38; i++) jj_la1[i] = -1;
1314   }
1315 
1316   private Token jj_consume_token(int kind) throws ParseException {
1317     Token oldToken;
1318     if ((oldToken = token).next != null) token = token.next;
1319     else token = token.next = token_source.getNextToken();
1320     jj_ntk = -1;
1321     if (token.kind == kind) {
1322       jj_gen++;
1323       return token;
1324     }
1325     token = oldToken;
1326     jj_kind = kind;
1327     throw generateParseException();
1328   }
1329 
1330 
1331 /** Get the next Token. */
1332   final public Token getNextToken() {
1333     if (token.next != null) token = token.next;
1334     else token = token.next = token_source.getNextToken();
1335     jj_ntk = -1;
1336     jj_gen++;
1337     return token;
1338   }
1339 
1340 /** Get the specific Token. */
1341   final public Token getToken(int index) {
1342     Token t = token;
1343     for (int i = 0; i < index; i++) {
1344       if (t.next != null) t = t.next;
1345       else t = t.next = token_source.getNextToken();
1346     }
1347     return t;
1348   }
1349 
1350   private int jj_ntk() {
1351     if ((jj_nt=token.next) == null)
1352       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
1353     else
1354       return (jj_ntk = jj_nt.kind);
1355   }
1356 
1357   private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
1358   private int[] jj_expentry;
1359   private int jj_kind = -1;
1360 
1361   /** Generate ParseException. */
1362   public ParseException generateParseException() {
1363     jj_expentries.clear();
1364     boolean[] la1tokens = new boolean[38];
1365     if (jj_kind >= 0) {
1366       la1tokens[jj_kind] = true;
1367       jj_kind = -1;
1368     }
1369     for (int i = 0; i < 38; i++) {
1370       if (jj_la1[i] == jj_gen) {
1371         for (int j = 0; j < 32; j++) {
1372           if ((jj_la1_0[i] & (1<<j)) != 0) {
1373             la1tokens[j] = true;
1374           }
1375           if ((jj_la1_1[i] & (1<<j)) != 0) {
1376             la1tokens[32+j] = true;
1377           }
1378         }
1379       }
1380     }
1381     for (int i = 0; i < 38; i++) {
1382       if (la1tokens[i]) {
1383         jj_expentry = new int[1];
1384         jj_expentry[0] = i;
1385         jj_expentries.add(jj_expentry);
1386       }
1387     }
1388     int[][] exptokseq = new int[jj_expentries.size()][];
1389     for (int i = 0; i < jj_expentries.size(); i++) {
1390       exptokseq[i] = jj_expentries.get(i);
1391     }
1392     return new ParseException(token, exptokseq, tokenImage);
1393   }
1394 
1395   /** Enable tracing. */
1396   final public void enable_tracing() {
1397   }
1398 
1399   /** Disable tracing. */
1400   final public void disable_tracing() {
1401   }
1402 
1403 }
1404 
1405 final class SenseComponents {
1406     public String name;
1407     public Object value;
1408     public Sense.Predicate predicate;
1409 }