public void Parse() { while(true) { switch (_parser.Parse()) { case ParseMessage.Empty: break; case ParseMessage.TokenRead: _parser.TokenSyntaxNode = _context.GetTokenText(); break; case ParseMessage.Reduction: _parser.TokenSyntaxNode = _context.ExecuteReductionRule(); break; case ParseMessage.Accept: Program = (GlifStatement)_parser.TokenSyntaxNode; return; case ParseMessage.LexicalError: throw new InvalidDataException("LEXICAL ERROR. Line " + _parser.LineNumber + ". Cannot recognize token: " + _parser.TokenText); case ParseMessage.SyntaxError: var text = new StringBuilder(); foreach (Symbol tokenSymbol in _parser.GetExpectedTokens()) { text.Append(' '); text.Append(tokenSymbol.ToString()); } throw new InvalidDataException("SYNTAX ERROR. Line " + _parser.LineNumber + ". Expecting:" + text); case ParseMessage.InternalError: throw new InvalidOperationException("INTERNAL ERROR! Something is horribly wrong"); case ParseMessage.NotLoadedError: throw new InvalidDataException("NOT LOADED ERROR! Compiled Grammar Table not loaded"); case ParseMessage.CommentError: throw new InvalidDataException("COMMENT ERROR! Unexpected end of file"); case ParseMessage.CommentBlockRead: break; case ParseMessage.CommentLineRead: break; default: throw new ArgumentOutOfRangeException(); } } }
public GlifStatementList(GlifContext context, GlifStatement currentStatement, GlifStatement nextStatement) : base(context) { _current = currentStatement; _next = nextStatement; }