From 184c16c533cd8c962136a14b82db253cf9359ceb Mon Sep 17 00:00:00 2001 From: ishmal Date: Wed, 18 Jun 2008 22:09:20 +0000 Subject: [PATCH] parser --- src/dom/work/Idlp.java | 394 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 src/dom/work/Idlp.java diff --git a/src/dom/work/Idlp.java b/src/dom/work/Idlp.java new file mode 100644 index 000000000..2f45cf175 --- /dev/null +++ b/src/dom/work/Idlp.java @@ -0,0 +1,394 @@ +import java.io.*; +import java.util.*; + + +public class Idlp +{ +String parsebuf; +int len; + + +void error(String msg) +{ + System.out.println("Idlp err : " + msg); +} + +void trace(String msg) +{ + System.out.println("Idlp : " + msg); +} + + + + + + +int get(int pos) +{ + if (pos<0 || pos>=len) + return -1; + else + return (int) parsebuf.charAt(pos); +} + + +int skipwhite(int pos) +{ + trace("skipwhite()"); + while (pos < len) + { + int ch = get(pos); + if (ch == '/' && get(pos + 1) == '/') + { + pos += 2; + while (pos < len) + { + ch = get(pos); + if (ch == '\n' || ch == '\r') + break; + pos++; + } + } + else if (!Character.isWhitespace(ch)) + { + break; + } + pos++; + } + return pos; +} + +boolean match(String key) +{ + trace("match(" + key + ")"); + int p = 0; + for (int i=0 ; i= len) + break; + int ch = get(pos); + int p = getword(pos); + if (p < 0) + return false; + if (p<=pos) + { + error("expected word"); + return false; + } + trace("word: " + word); + if (word.length() == 0) + break; + if (word.charAt(0) == '#') + { + p = getDirective(word, pos); + if (p < 0) + return false; + } + else if (word.equals("module")) + { + pos = p; + p = getModule(pos); + if (p<0) + return false; + } + pos = p; + } + + return true; +} + + +boolean run() +{ + parsebuf = ""; + boolean ret = true; + try + { + StringBuffer inbuf = new StringBuffer(); + FileReader in = new FileReader("svg.idl"); + while (true) + { + int ch = in.read(); + if (ch < 0) + break; + inbuf.append((char)ch); + } + in.close(); + parsebuf = inbuf.toString(); + ret = parse(); + } + catch (IOException e) + { + error("run : " + e); + return false; + } + return ret; +} + + +public Idlp() +{ +} + + +public static void main(String argv[]) +{ + Idlp idlp = new Idlp(); + idlp.run(); +} + + + +} -- 2.30.2