+++ /dev/null
-package edu.uci.eecs.specCompiler.codeGenerator;
-
-public class IDExtractor {
- private String code;
- private int index = 0;
-
- private int idBeginIdx, idEndIdx;
-
- public IDExtractor(String code) {
- this.code = code;
- this.index = 0;
- }
-
- public IDExtractor(String code, int beginIdx) {
- this.code = code;
- this.index = beginIdx;
- }
-
- public void reset(int beginIdx) {
- this.index = beginIdx;
- }
-
- public void reset() {
- this.index = 0;
- }
-
- public int getIDBeginIdx() {
- return this.idBeginIdx;
- }
-
- public int getIDEndIdx() {
- return this.idEndIdx;
- }
-
- public int lineNumOfID() {
- int cnt = 0;
- for (int i = 0; i < idBeginIdx; i++) {
- if (code.charAt(i) == '\n')
- cnt++;
- }
- return cnt;
- }
-
- public int lineBeginIdxOfID() {
- int i;
- for (i = idBeginIdx - 1; i >= 0; i--) {
- if (code.charAt(i) == '\n')
- break;
- }
- return i + 1;
- }
-
- public int lineEndIdxOfID() {
- int i = 0;
- for (i = idEndIdx + 1; i < code.length(); i++) {
- if (code.charAt(i) == '\n') {
- break;
- }
- }
- return i - 1;
- }
-
- public String getPrevID() {
- int beginIdx = index;
- int endIdx = index;
- char ch;
- while (true) {
- ch = code.charAt(endIdx);
- if ((ch == '_' || (ch >= 'a' && ch <= 'z') || ch >= 'A'
- && ch <= 'Z')) {
- break;
- }
- endIdx--;
- }
- beginIdx = endIdx;
- while (true) {
- ch = code.charAt(beginIdx);
- if (!((ch == '_' || (ch >= 'a' && ch <= 'z') || ch >= 'A'
- && ch <= 'Z'))) {
- break;
- }
- beginIdx--;
- }
- index = beginIdx;
- if (beginIdx > endIdx)
- return null;
- idBeginIdx = beginIdx + 1;
- idEndIdx = endIdx;
- return code.substring(beginIdx + 1, endIdx + 1);
- }
-
- public String getNextID() {
- int beginIdx = index;
- int endIdx = index;
- char ch;
- while (true) {
- ch = code.charAt(beginIdx);
- if ((ch == '_' || (ch >= 'a' && ch <= 'z') || ch >= 'A'
- && ch <= 'Z')) {
- break;
- }
- beginIdx++;
- }
- endIdx = beginIdx;
- while (true) {
- ch = code.charAt(endIdx);
- if (!((ch == '_' || (ch >= 'a' && ch <= 'z') || ch >= 'A'
- && ch <= 'Z'))) {
- break;
- }
- endIdx++;
- }
- index = endIdx;
- if (beginIdx > endIdx)
- return null;
- idBeginIdx = beginIdx;
- idEndIdx = endIdx - 1;
- return code.substring(beginIdx, endIdx);
- }
-}