public void PrintPyramid(ParseForest tree, bool force = false) { if (!py && !force) { return; } SyntaxParser.PrintPyramid(tree); }
public Complish() { SyntaxParse = new SyntaxParser(); SyntaxParse.debug(); SyntaxParse.RuleCheck(); t.Initialize(); Verbs.Initialize(); Scope.Initialize(); DataSegment = new DataSegment(); SemanticChecker = new SemanticChecks(); }
protected Symbol CreateTypes(ParseForest forest, SemanticContext context) { try { // "A wheel is a number" can define either a struct or a subclass. Here we disambiguate. if (forest.SentenceType == 0 && forest.Count == 2 && forest.SentenceTypes().Aggregate("", (a, b) => a + " " + b) == " aSVO DeObj") { forest.SentenceType = Rs.ObjectDefinition; } // Imperative functions span multiple sentences. Here, if the new sentence isn't an imperative, end any previous function body. if (AnInvokedImperative.Contains(forest.SentenceType)) { EndPreviousFunctionBody(context); string.Join(" ", forest.a).Log(); } // ok, start parsing based on sentence type switch (forest.SentenceType) { case Rs.FunctionDefinition: DefineFuncSymbol(forest, context); break; case Rs.ImperativeInvocationVO: case Rs.ImperativeInvocationSV: case Rs.ImperativeInvocationSVO: case Rs.ImperativeInvocationV: DefineImpInvSymbol(forest, context); break; case Rs.ObjectDefinition: CreateSymbol(forest, new ParseTreeVisitor(forest), context); break; case Rs.UnaryRelationDefinition: case Rs.RelationDefinition: DefineRelationVerb(forest, context); break; case Rs.TemporalConstraint: DefineTemporalConstraint(forest, context); break; case Rs.VarInstanceDefinition: CreateSymbol(forest, new ParseTreeVisitor(forest), context); break; case 0: if (forest.Count == 0) { "ERROR. This doesn't parse:".Log(string.Join(" ", forest.a)); SyntaxParser.PrintPyramid(forest); } else { "ERROR. This is ambiguous:".Log(forest.SentenceTypes().Aggregate("", (a, b) => a + " " + b)); } break; } } catch (Exception ex) { "EXCEPTION:".Log(ex.Message); } return(context.FunctionBeingDefined); }