/** * Analyzes a parse tree node by traversing all it's child nodes. * The tree traversal is depth-first, and the appropriate * callback methods will be called. If the node is a production * node, a new production node will be created and children will * be added by recursively processing the children of the * specified production node. This method is used to process a * parse tree after creation. * * @param node the parse tree node to process * @param log the parser error log * * @return the resulting parse tree node */ public virtual Node Analyze(Node node, ParserLogException log) { Production prod; int errorCount; Node res = null; errorCount = log.Count; if (node is Production) { prod = (Production)node; prod = NewProduction(prod.Pattern); try { Enter(prod); } catch (ParseException e) { log.AddError(e); } for (int i = 0; i < node.Count; i++) { try { Child(prod, Analyze(node[i], log)); } catch (ParseException e) { log.AddError(e); } } try { res = Exit(prod); return(res); } catch (ParseException e) { if (errorCount == log.Count) { log.AddError(e); } } } else { node.Values.Clear(); try { Enter(node); } catch (ParseException e) { log.AddError(e); } try { res = Exit(node); return(res); } catch (ParseException e) { if (errorCount == log.Count) { log.AddError(e); } } } return(null); }
/** * Adds an error to the error log. If the parser is in error * recovery mode, the error will not be added to the log. If the * recovery flag is set, this method will set the error recovery * counter thus enter error recovery mode. Only lexical or * syntactical errors require recovery, so this flag shouldn't be * set otherwise. * * @param e the error to add * @param recovery the recover flag */ internal void AddError(ParseException e, bool recovery) { if (errorRecovery <= 0) { errorLog.AddError(e); } if (recovery) { errorRecovery = 3; } }