In documentation for lreduce and rreduce, supply second argument as an explicit list
[maxima.git] / share / translators / m2mj / M2M.java
blob0b9552c516c49f980cf54ff779bddb604605787f
1 /* François Thomasset -- INRIA Rocquencourt -- Octobre 2001 *)
3 (* Translation from Maple to MuPad : syntaxic specification of maple *)
5 (*
6 Copyright © 2001-2002 François Thomasset, all rights reserved.
7 All of Dan Stanger's changes are Copyright © 2021 Dan Stanger, all rights reserved.
8 Copying is covered by the GNU General Public License (GPL).
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. */
20 At this time, the file is preprocessed to remove any backspaces.
21 The translation does not handle end of line comments yet.
23 import org.antlr.v4.runtime.*;
24 import org.antlr.v4.runtime.tree.*;
25 import org.stringtemplate.v4.ST;
26 import org.stringtemplate.v4.STGroup;
27 import org.stringtemplate.v4.STGroupFile;
29 import java.io.FileInputStream;
30 import java.io.BufferedReader;
31 import java.io.InputStreamReader;
32 import java.io.PrintWriter;
34 public class M2M {
35 public static Templates theTemplates=null;
36 public static TokenStreamRewriter rewriter;
37 public static void main(String[] args) throws Exception {
38 theTemplates = new Templates("Macsyma.stg");
39 FileInputStream fis = new FileInputStream(args[0]);
40 PrintWriter pw = new PrintWriter(args[1]);
41 StringBuilder sb = preprocess(fis);
42 ANTLRInputStream input = new ANTLRInputStream(sb.toString());
43 mapleLexer lexer = new mapleLexer(input);
44 CommonTokenStream tokens = new CommonTokenStream(lexer);
45 mapleParserParser parser = new mapleParserParser(tokens);
46 rewriter = new TokenStreamRewriter(tokens);
47 parser.setTrace(true);
48 ParseTree tree = parser.program();
49 ParseTreeWalker walker = new ParseTreeWalker();
50 mapleParserVisitorImpl visitor = new mapleParserVisitorImpl();
51 ST t=visitor.visit(tree);
52 pw.println(t.render());
53 pw.flush();
54 pw.close();
55 //System.out.println(tree.toStringTree(parser));
57 public static StringBuilder preprocess(FileInputStream fis) throws Exception
59 StringBuilder b = new StringBuilder();
60 try(BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
61 for(String line; (line = br.readLine()) != null; ) {
62 line.replace('\b',' ');
63 int i=-1;
64 if(line.indexOf('#')==0)line=line+'\b';
65 else if ((i=line.indexOf("#")) > 0){
66 line=line.substring(0,i-1); // Delete the comment
68 b.append(line+'\n');
71 return b;