// This code determines if any defined event should be triggered. // For all such events, it executes the statements associated with // them. Main { traversal doEvents (EventVisitor) { through Event through {Once, Yearly, Monthly} to *; } } // a shortcut for getting the Eventname string Eventname { public String toString() {{ return get_ident().toString(); }} } EventVisitor { {{ boolean matches; boolean matches_year; boolean matches_month; boolean add_name_if_matches; String names = new String(); }} public String getNames() {{ return names; }} before Event {{ matches = false; add_name_if_matches = true; }} after Event {{ if (matches) { // Add to the list of matches if (add_name_if_matches) { names = names + " " + host.get_eventname().toString(); } // execute statements associated with this event host.get_statements().doStatements(new StatementVisitor()); } }} before Year {{ matches_year = (year == host.get_integer().doubleValue()); }} before Month {{ matches_month = (month == host.getMonth()); }} after Monthly {{ matches = true; // done all the time add_name_if_matches = false; // no need to print this clutter }} after Yearly {{ matches = matches_month; }} after Date {{ matches = matches_year && matches_month; }} after Eventname {{ // Events with names are implemented as boolean-valued trigger symbols Symbol sym = Main.symbolTable.findSymbol(host.toString()); if (sym == null) { System.out.println ("Error: unknown event " + host.toString()); Main.stopSimulation = true; } else { matches = (sym.getValue() == 1); } }} }