// Parse a Pascal source program and generate the symbol table and the intermediate code.
public override void parse()
{
long startTime = DateTime.Now.Ticks;
iCode = ICodeFactory.CreateICode();
try
{
Token token = NextToken();
ICodeNode rootNode = null;
// Look for the BEGIN token to parse a compound statement.
if (token.type == PascalTokenType.BEGIN)
{
StatementParser statementParser = new StatementParser(this);
rootNode = statementParser.Parse(token);
token = CurrentToken();
}
else
errorHandler.flag(token, PascalErrorCode.UNEXPECTED_TOKEN, this);
// Look for the final period.
if (token.type != PascalTokenType.DOT)
errorHandler.flag(token, PascalErrorCode.MISSING_PERIOD, this);
token = CurrentToken();
// Set parse tree root node.
if (rootNode != null)
iCode.SetRoot(rootNode);
// Send parser summary message.
float elapsedTime = (DateTime.Now.Ticks - startTime) / 10000000f;
sendMessage(new Message(MessageType.PARSER_SUMMARY,
new IConvertible[] { token.lineNumber, getErrorCount(), elapsedTime }));
}
catch (System.IO.IOException e)
{
errorHandler.abortTranslation(PascalErrorCode.IO_ERROR, this);
}
}