JavaCC
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) { Test parser = new Test(System.in); while (true) { try { parser.Input(); } catch (ParseException e) { System.out.println(e.getMessage()); } } …
任意の規則が書けるのかな? PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : </space:>…
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> } void Input() : {</c:></b:></a:></space:>…
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } void Input() : {} { ( LOOKAHEAD("a"</space:>…
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
複数 LOOKAHEAD を書いたときの動作再確認 PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : …
二つ書くと? PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> | </d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> | <C: "c"> | <D: "d"> } void Inpu…</d:></c:></b:></a:></space:>
PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> } void Input() : {} { In</a:></space:>…
特に何もせずにシンプルに PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) { Test parser = new Test(System.in); while (true) { try { parser.Input(); } catch (ParseException e) { System.out.prin…
1行ごとに処理するとした場合毎行 parser を生成 options { STATIC = false; } PARSER_BEGIN(Test) import java.io.*; public class Test { public static void main(String args[]) { String line = null; try { BufferedReader inStream = new BufferedRea…
PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> } void Input() : {} { ( <A> )+ <EOF> } で、 a a</eof></a></b:></a:></space:>…
PARSER_BEGIN(Test) public class Test { } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> } void Input() : { Token t; } { ( (t = <A> | t = <B> | t = "c" | t = "def") { System.out.println("*" + t.image + "*"); } )+ <EOF> } と、 public class TestMain { public</eof></b></a></b:></a:></space:>…
options { USER_TOKEN_MANAGER = true; } PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(new TestMyTokenManager()); parser.Input(); } } PARSER_END(Test) void Input(…
『JavaCC―コンパイラ・コンパイラfor Java』の simple/sent3/sent3tdbg.java を参考にして、 昨日はちょっと勘違いして .jj に埋め込んでしまったので、独立した .java として動作させ、 a TOKEN="a" image="a" c TOKEN="c" image="c" def TOKEN="def" image…
『JavaCC―コンパイラ・コンパイラfor Java』の simple/sent3/sent3tdbg.java を参考にして、 a TOKEN="a" image="a" c TOKEN="c" image="c" def TOKEN="def" image="def" TOKEN=<EOF> image=""</eof>
options { DEBUG_TOKEN_MANAGER = true; } PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"></b:></a:></space:>…
PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> | <B: "b"> } void Input() : {} { ( <A> | <B> | "c" | "de</b></a></b:></a:></space:>…
字句解析内での呼び出し PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> { getNextToken(); }</a:></space:>…
matchedToken も Token クラスだから、それと同じか〜 PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TO</space:>…
SKIP 内では、matchedToken が使えないから、input_stream.get*() を使うらしい(使う機会は余りなさそうな気もするけど) PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(S…
PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) <*>SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> : STATE1 } <STATE1>TOKEN : { <S1A: "a"> { SwitchTo(0); } }</s1a:></state1></a:></space:>…
PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> { System.out.print(input_stream); } } void</a:></space:>…