@Override public String visitBoilerplate(@NotNull InfixParser.BoilerplateContext ctx) { // Declare all functions. ListIterator<InfixParser.FuncContext> funcIt = ctx.func().listIterator(); String funcDefinitions = ""; while (funcIt.hasNext()) { funcDefinitions += visit(funcIt.next()); funcDefinitions += " "; } // Declare all variable names. String varDeclarations = ""; for (VariableSymbol variableSymbol : variableSymbols) { varDeclarations += "variable "; varDeclarations += variableSymbol.getCompiledVariableName(); varDeclarations += " "; } // Generate program code. String formatString = "%s%s: program %s ; program"; forthSource = String.format(formatString, varDeclarations, funcDefinitions, visit(ctx.sequence())); // This is to allow generation of the postscript parse tree at a later time. rootCtx = ctx; return forthSource; }
/** * Prints the postscript parsetree to a .ps file with the given name * * @param filename used to generate a file of the form <filename>.ps */ public void outputPSGraphToFile(String filename) { try { rootCtx.save(Arrays.asList(parser.getRuleNames()), filename + ".ps"); } catch (IOException | PrintException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }