Skip to content

Commit

Permalink
add simple LL(2) rule with ATN debug output.
Browse files Browse the repository at this point in the history
Signed-off-by: Terence Parr <parrt@antlr.org>
  • Loading branch information
parrt committed Nov 12, 2022
1 parent 319524a commit bca48be
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[type]
Parser

[grammar]
grammar T;
s : t EOF ;
t : ID ';' | ID '.' ;
ID : [a-zA-Z]+ ;
WS : [ \r\n\t]+ -> skip ;

[start]
s

[input]
xyz.

[output]
"""adaptivePredict decision 0 exec LA(1)==ID<3> line 1:0
predictATN decision 0 exec LA(1)==ID<3>, outerContext=[t s]
closure((7,1,[$]))
closure((9,2,[$]))
adding new DFA state: 0:[(7,1,[$]), (9,2,[$])]
execATN decision 0 exec LA(1)==ID<3> line 1:0
s0 = 0:[(7,1,[$]), (9,2,[$])]
in computeReachSet, starting closure: [(7,1,[$]), (9,2,[$])]
testing ID<3> at (7,1,[$])
testing ID<3> at (9,2,[$])
closure((8,1,[$]))
closure((10,2,[$]))
SLL altSubSets=[{1}, {2}], configs=[(8,1,[$]), (10,2,[$])], predict=0, allSubsetsConflict=false, conflictingAlts={1, 2}
EDGE 0:[(7,1,[$]), (9,2,[$])] -> -1:[(8,1,[$]), (10,2,[$])] upon ID<3>
adding new DFA state: 1:[(8,1,[$]), (10,2,[$])]
DFA=
s0-ID->s1

in computeReachSet, starting closure: [(8,1,[$]), (10,2,[$])]
testing '.'<2> at (8,1,[$])
testing '.'<2> at (10,2,[$])
SLL altSubSets=[{2}], configs=[(12,2,[$])], predict=2, allSubsetsConflict=false, conflictingAlts={2}
EDGE 1:[(8,1,[$]), (10,2,[$])] -> -1:[(12,2,[$])],uniqueAlt=2=>2 upon '.'<2>
adding new DFA state: 2:[(12,2,[$])],uniqueAlt=2=>2
DFA=
s0-ID->s1
s1-'.'->:s2=>2

DFA after predictATN: s0-ID->s1
s1-'.'->:s2=>2

"""

[flags]
traceATN
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,21 @@ private ExecutedState execCommon(JavaCompiledState compiledState) {
stdoutReader.start();
stderrReader.start();

PrintStream saveStdout = System.out;
ByteArrayOutputStream captureNormalStdout = new ByteArrayOutputStream();
System.setOut(new PrintStream(captureNormalStdout));

recognizeMethod.invoke(null, new File(getTempDirPath(), "input").getAbsolutePath(),
new PrintStream(stdoutOut), new PrintStream(stderrOut));

System.setOut(saveStdout);

stdoutOut.close();
stderrOut.close();
stdoutReader.join();
stderrReader.join();
output = stdoutReader.toString();
// include normal stdout to get print statements from ATN simulation debugging
output = stdoutReader.toString() + captureNormalStdout;
errors = stderrReader.toString();
} catch (Exception ex) {
exception = ex;
Expand Down

0 comments on commit bca48be

Please sign in to comment.