Kirk Rader  1.0-SNAPSHOT
Static Public Member Functions | Static Package Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
us.rader.tt.app.TT Class Reference

Process a well-formed formula of the monadic predicate calculus. More...

Static Public Member Functions

static void main (final String[] args)
 Program entry point. More...
 

Static Package Functions

 [static initializer]
 

Private Member Functions

 TT ()
 Prevent instantiation of utility class. More...
 

Static Private Member Functions

static void tt (final InputStream inpuStream, final PrintStream outputStream) throws IOException
 Process the well-formed formula from the given stream. More...
 
static void tt (final String command, final String parameter) throws IOException
 Handle command-line arguments. More...
 
static void usage (final PrintStream stream)
 Print a usage message to the given stream. More...
 

Static Private Attributes

static final int BAD_ARGUMENTS_STATUS = 10
 Invalid command-line arguments. More...
 
static final int ERROR_STATUS = 30
 Other run-time error. More...
 
static final int INDENT = 0
 Number of spaces to indent generated markdown content. More...
 
static final Logger LOGGER
 Error logging and debug tracing. More...
 
static final int SYNTAX_ERROR_STATUS = 20
 Syntax error in formula. More...
 

Detailed Description

Process a well-formed formula of the monadic predicate calculus.

Definition at line 33 of file TT.java.

Constructor & Destructor Documentation

◆ TT()

us.rader.tt.app.TT.TT ( )
private

Prevent instantiation of utility class.

Definition at line 68 of file TT.java.

68  {
69 
70  // nothing to do here
71 
72  }

Member Function Documentation

◆ [static initializer]()

us.rader.tt.app.TT.[static initializer] ( )
staticpackage

◆ main()

static void us.rader.tt.app.TT.main ( final String []  args)
static

Program entry point.

Parameters
argsCommand-line arguments.

Definition at line 80 of file TT.java.

References us.rader.tt.app.TT.tt(), and us.rader.tt.app.TT.usage().

80  {
81 
82  try {
83 
84  switch (args.length) {
85 
86  case 0:
87 
88  tt(System.in, System.out); // NOSONAR
89  break;
90 
91  case 2:
92 
93  tt(args[0], args[1]);
94  break;
95 
96  default:
97 
98  usage(System.err); // NOSONAR
99  System.exit(BAD_ARGUMENTS_STATUS);
100 
101  }
102 
103  } catch (final IllegalArgumentException e) {
104 
105  LOGGER.logp(Level.FINE, TT.class.getName(), "main", "invalid command-line arguments", e);
106  usage(System.err); // NOSONAR
107  System.exit(BAD_ARGUMENTS_STATUS);
108 
109  } catch (final Expression.SyntaxError e) {
110 
111  LOGGER.logp(Level.SEVERE, TT.class.getName(), "main", "syntax error in formula", e);
112  System.exit(SYNTAX_ERROR_STATUS);
113 
114  } catch (final Exception e) {
115 
116  LOGGER.logp(Level.SEVERE, TT.class.getName(), "main", "error processing formula", e);
117  System.exit(ERROR_STATUS);
118 
119  }
120  }
static void usage(final PrintStream stream)
Print a usage message to the given stream.
Definition: TT.java:228
static final int ERROR_STATUS
Other run-time error.
Definition: TT.java:43
static void tt(final InputStream inpuStream, final PrintStream outputStream)
Process the well-formed formula from the given stream.
Definition: TT.java:134
static final Logger LOGGER
Error logging and debug tracing.
Definition: TT.java:53
static final int BAD_ARGUMENTS_STATUS
Invalid command-line arguments.
Definition: TT.java:38
TT()
Prevent instantiation of utility class.
Definition: TT.java:68
static final int SYNTAX_ERROR_STATUS
Syntax error in formula.
Definition: TT.java:57

◆ tt() [1/2]

static void us.rader.tt.app.TT.tt ( final InputStream  inpuStream,
final PrintStream  outputStream 
) throws IOException
staticprivate

Process the well-formed formula from the given stream.

Parameters
inpuStreamThe input stream.
outputStreamThe output stream.
Exceptions
IOExceptionThrown if an I/O error occurs.

Definition at line 134 of file TT.java.

References us.rader.tt.formula.Formula.parseFormula(), us.rader.tt.formula.Formula.toDigraph(), us.rader.tt.formula.Expression.toLaTeX(), and us.rader.tt.formula.Formula.toTruthTable().

Referenced by us.rader.tt.app.TT.main(), and us.rader.tt.app.TT.tt().

134  {
135 
136  final Formula term = Formula.parseFormula(inpuStream);
137  final String wff = term.toString();
138  outputStream.print("# ");
139  outputStream.println(wff);
140  outputStream.println();
141  outputStream.println("## Graphviz");
142  outputStream.println();
143  outputStream.println("```viz");
144  outputStream.println(term.toDigraph(INDENT));
145  outputStream.println("```");
146  outputStream.println();
147  outputStream.println("## LaTex");
148  outputStream.println();
149  outputStream.println("### Preamble");
150  outputStream.println();
151  outputStream.println("The LaTeX generated by this program assumes the following preamble:");
152  outputStream.println();
153  outputStream.println(" \\usepackage{amsmath}");
154  outputStream.println(" \\usepackage{amssymb}");
155  outputStream.println(" \\usepackage{graphicx}");
156  outputStream.println(" \\usepackage{natded}");
157  outputStream.println(" \\newcommand{\\lognot}{\\mathord{\\sim}}");
158  outputStream.println(" \\newcommand{\\uq}{\\mathord{\\bigwedge}}");
159  outputStream.println(" \\newcommand{\\eq}{\\mathord{\\bigvee}}");
160  outputStream.println(" \\newcommand{\\riota}{\\mathrm{\\rotatebox[origin=c]{180}{$\\iota$}}}");
161  outputStream.println();
162  outputStream.println("### Formula");
163  outputStream.println();
164  outputStream.println("```math");
165  outputStream.println(term.toLaTeX());
166  outputStream.println("```");
167  outputStream.println();
168  outputStream.println("## Truth Table");
169  outputStream.println();
170  final String truthTable = term.toTruthTable(INDENT);
171  outputStream.println("```math");
172  outputStream.print(truthTable);
173  outputStream.println("```");
174 
175  }
static final int INDENT
Number of spaces to indent generated markdown content.
Definition: TT.java:48

◆ tt() [2/2]

static void us.rader.tt.app.TT.tt ( final String  command,
final String  parameter 
) throws IOException
staticprivate

Handle command-line arguments.

Parameters
commandCommand selector string.
parameterCommand parameter string.
Exceptions
IOExceptionThrown if an I/O error occurs.

Definition at line 189 of file TT.java.

References us.rader.tt.app.TT.tt().

189  {
190 
191  switch (command) {
192 
193  case "-f":
194  case "--file": // NOSONAR
195 
196  try (FileInputStream stream = new FileInputStream(parameter)) {
197 
198  tt(stream, System.out); // NOSONAR
199 
200  }
201 
202  break;
203 
204  case "-e":
205  case "--expression": // NOSONAR
206 
207  try (ByteArrayInputStream stream = new ByteArrayInputStream(parameter.getBytes("UTF-8"))) {
208 
209  tt(stream, System.out); // NOSONAR
210 
211  }
212 
213  break;
214 
215  default:
216 
217  throw new IllegalArgumentException();
218 
219  }
220  }
static void tt(final InputStream inpuStream, final PrintStream outputStream)
Process the well-formed formula from the given stream.
Definition: TT.java:134

◆ usage()

static void us.rader.tt.app.TT.usage ( final PrintStream  stream)
staticprivate

Print a usage message to the given stream.

Parameters
streamThe output stream.

Definition at line 228 of file TT.java.

Referenced by us.rader.tt.app.TT.main().

228  {
229 
230  stream.println("usage:\tjava -jar TT.jar");
231  stream.println("\tjava -jar TT.jar (-f | --file) <input-file>");
232  stream.println("\tjava -jar TT.jar (-e | --expression) <expression>");
233  stream.println();
234  stream.println("if no <input-file> or <expression> is specified, reads from standard input stream");
235 
236  }

Member Data Documentation

◆ BAD_ARGUMENTS_STATUS

final int us.rader.tt.app.TT.BAD_ARGUMENTS_STATUS = 10
staticprivate

Invalid command-line arguments.

Definition at line 38 of file TT.java.

◆ ERROR_STATUS

final int us.rader.tt.app.TT.ERROR_STATUS = 30
staticprivate

Other run-time error.

Definition at line 43 of file TT.java.

◆ INDENT

final int us.rader.tt.app.TT.INDENT = 0
staticprivate

Number of spaces to indent generated markdown content.

Definition at line 48 of file TT.java.

◆ LOGGER

final Logger us.rader.tt.app.TT.LOGGER
staticprivate

Error logging and debug tracing.

Definition at line 53 of file TT.java.

◆ SYNTAX_ERROR_STATUS

final int us.rader.tt.app.TT.SYNTAX_ERROR_STATUS = 20
staticprivate

Syntax error in formula.

Definition at line 57 of file TT.java.


The documentation for this class was generated from the following file: