|
1 | 1 | package org.srcgll |
2 | 2 |
|
3 | | -import kotlinx.cli.ArgParser |
4 | | -import kotlinx.cli.ArgType |
5 | | -import kotlinx.cli.default |
6 | | -import kotlinx.cli.required |
7 | | -import org.srcgll.grammar.readRSMFromTXT |
8 | | -import org.srcgll.grammar.symbol.Terminal |
9 | | -import org.srcgll.grammar.writeRSMToDOT |
10 | | -import org.srcgll.input.IGraph |
11 | | -import org.srcgll.input.LinearInput |
12 | | -import org.srcgll.input.LinearInputLabel |
13 | | -import java.io.* |
14 | | -import org.srcgll.lexer.GeneratedLexer |
15 | | -import org.srcgll.lexer.SymbolCode |
16 | | -import org.srcgll.lexer.Token |
17 | | -import org.srcgll.sppf.writeSPPFToDOT |
18 | | -import org.srcgll.sppf.buildStringFromSPPF |
19 | | - |
20 | | -enum class RecoveryMode |
21 | | -{ |
| 3 | +import org.srcgll.grammar.combinator.Grammar |
| 4 | +import org.srcgll.grammar.combinator.regexp.NT |
| 5 | +import org.srcgll.grammar.combinator.regexp.Term |
| 6 | +import org.srcgll.grammar.combinator.regexp.or |
| 7 | +import org.srcgll.grammar.combinator.regexp.times |
| 8 | +import org.srcgll.rsm.writeRSMToDOT |
| 9 | + |
| 10 | +enum class RecoveryMode { |
22 | 11 | ON, |
23 | 12 | OFF, |
24 | 13 | } |
25 | 14 |
|
26 | | -enum class Mode |
27 | | -{ |
| 15 | +enum class Mode { |
28 | 16 | Reachability, |
29 | 17 | AllPairs, |
30 | 18 | } |
31 | 19 |
|
32 | | -fun main(args : Array<String>) |
33 | | -{ |
34 | | - val parser = ArgParser("srcgll") |
35 | | - |
36 | | - val recoveryMode by |
37 | | - parser |
38 | | - .option(ArgType.Choice<RecoveryMode>(), fullName = "recovery", description = "Recovery mode") |
39 | | - .default(RecoveryMode.ON) |
40 | | - |
41 | | - val pathToInput by |
42 | | - parser |
43 | | - .option(ArgType.String, fullName = "inputPath", description = "Path to input txt file") |
44 | | - .required() |
45 | | - |
46 | | - val pathToGrammar by |
47 | | - parser |
48 | | - .option(ArgType.String, fullName = "grammarPath", description = "Path to grammar txt file") |
49 | | - .required() |
50 | | - |
51 | | - val pathToOutputString by |
52 | | - parser |
53 | | - .option(ArgType.String, fullName = "outputStringPath", description = "Path to output txt file") |
54 | | - .required() |
55 | | - |
56 | | - val pathToOutputSPPF by |
57 | | - parser |
58 | | - .option(ArgType.String, fullName = "outputSPPFPath", description = "Path to output dot file") |
59 | | - .required() |
60 | | - |
61 | | - parser.parse(args) |
62 | | - |
63 | | - |
64 | | - val input = File(pathToInput).readText().replace("\n","").trim() |
65 | | - val grammar = readRSMFromTXT(pathToGrammar) |
66 | | - var lexer = GeneratedLexer(StringReader(input)) |
67 | | - var token : Token<SymbolCode> |
68 | | - var vertexId = 0 |
69 | | - |
70 | | - val inputGraph = LinearInput<Int, LinearInputLabel>() |
71 | | - |
72 | | - inputGraph.addVertex(vertexId) |
73 | | - inputGraph.addStartVertex(vertexId) |
74 | | - |
75 | | -// while (!lexer.yyatEOF()) { |
76 | | -// token = lexer.yylex() as Token<SymbolCode> |
77 | | -// println("(" + token.value + ")" + token.type.toString()) |
78 | | -// inputGraph.addEdge(vertexId, LinearInputLabel(Terminal(token)), ++vertexId) |
79 | | -// inputGraph.addVertex(vertexId) |
80 | | -// } |
81 | | - |
82 | | - for (x in input) { |
83 | | - inputGraph.addEdge(vertexId, LinearInputLabel(Terminal(x.toString())), ++vertexId) |
84 | | - inputGraph.addVertex(vertexId) |
85 | | - } |
86 | | - |
87 | | - val result = GLL(grammar, inputGraph, recoveryMode).parse() |
88 | | - |
89 | | - writeSPPFToDOT(result.first!!, "./result_sppf.dot") |
90 | | - writeRSMToDOT(grammar, "./rsm.dot") |
| 20 | +fun main(args: Array<String>) { |
| 21 | + class SGrammar : Grammar() { |
| 22 | + var S by NT() |
91 | 23 |
|
92 | | - File(pathToOutputString).printWriter().use { |
93 | | - out -> out.println(buildStringFromSPPF(result.first!!)) |
| 24 | + init { |
| 25 | + setStart(S) |
| 26 | + S = Term("a") or Term("a") * S or S * S |
| 27 | + } |
94 | 28 | } |
| 29 | + writeRSMToDOT(SGrammar().getRsm(), "./rsm.dot") |
95 | 30 | } |
0 commit comments