/* Clock24To12.cs */
using System;
using System.Collections.Generic;
public class Clock24To12:Visitor
{
String[] hours =
{
"00","01","02","03","04","05",
"06","07","08","09","10","11",
"12","01","02","03","04","05",
"06","07","08","09","10","11"
};
String[] am_pm =
{
"AM","AM","AM","AM","AM","AM",
"AM","AM","AM","AM","AM","AM",
"PM","PM","PM","PM","PM","PM",
"PM","PM","PM","PM","PM","PM"
};
int hour;
public Object Visit(Rule_Clock rule)
{
VisitRules(rule.rules);
Console.Write(" " + am_pm[hour]);
return false;
}
public Object Visit(Rule_Hours rule)
{
/* USE 24 HOUR OF DAY AS INDEX */
hour = int.Parse(rule.spelling);
Console.Write(hours[hour]);
return false;
}
public Object Visit(Rule_Minutes rule)
{
/* SIMPLY OUTPUT MINUTES */
Console.Write(rule.spelling);
return false;
}
public Object Visit(Rule_Seconds rule)
{
/* SIMPLY OUTPUT SECONDS */
Console.Write(rule.spelling);
return false;
}
public Object Visit(Rule_Separator rule)
{
/* SIMPLY OUTPUT SEPARATOR */
Console.Write(rule.spelling);
return false;
}
public Object Visit(Terminal_StringValue value)
{
/* WON'T BE VISITED */
return true;
}
public Object Visit(Terminal_NumericValue value)
{
/* WON'T BE VISITED */
return true;
}
private Object VisitRules(List<Rule> rules)
{
foreach (Rule rule in rules)
rule.Accept(this);
return null;
}
}
/* eof */