• R/O
  • SSH
  • HTTPS

jobjectpascal: Commit


Commit MetaInfo

Revision134 (tree)
Time2015-06-14 07:32:10
Authoriga

Log Message

save

Change Summary

Incremental Difference

--- trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenTypeParser.java (nonexistent)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenTypeParser.java (revision 134)
@@ -0,0 +1,86 @@
1+package jp.igapyon.jobjectpascal.parser.syntax;
2+
3+import jp.igapyon.jobjectpascal.PascalConstants;
4+import jp.igapyon.jobjectpascal.parser.PascalLexicalToken;
5+import jp.igapyon.jobjectpascal.parser.PascalSyntaxProcessInfo;
6+import jp.igapyon.jobjectpascal.parser.PascalSyntaxTokenUtil;
7+import jp.igapyon.jobjectpascal.parser.ast.PascalAstType;
8+
9+public class PascalSyntaxTokenTypeParser {
10+ public void parseMuiti(PascalSyntaxProcessInfo processInfo) {
11+ varloop: for (; processInfo.lexicalIndex < processInfo.lexicalTokenList
12+ .size(); processInfo.lexicalIndex++) {
13+ parse(processInfo);
14+
15+ for (; processInfo.lexicalIndex < processInfo.lexicalTokenList
16+ .size(); processInfo.lexicalIndex++) {
17+ final PascalLexicalToken token = processInfo.lexicalTokenList
18+ .get(processInfo.lexicalIndex);
19+ if (PascalSyntaxTokenUtil.isWhitespaceTokenSeparators(token)) {
20+ continue;
21+ }
22+ if (PascalConstants.TokenType.WORD_SYMBOL == token.getType()) {
23+ processInfo.lexicalIndex--;
24+ break varloop;
25+ }
26+ if (PascalConstants.TokenType.IDENTIFIRE_OR_DIRECTIVE == token
27+ .getType()) {
28+ // continue type block
29+ processInfo.lexicalIndex--;
30+ break;
31+ }
32+ }
33+ }
34+ }
35+
36+ public void parse(PascalSyntaxProcessInfo processInfo) {
37+ final PascalAstType ast = new PascalAstType();
38+ ast.setName("type");
39+ processInfo.syntaxTokenList.add(ast);
40+
41+ final PascalLexicalToken nameToken = PascalSyntaxTokenUtil
42+ .readNextTokenWithoutWhitespaces(processInfo);
43+ ast.setTypeName(nameToken.getWord());
44+ if (PascalConstants.TokenType.IDENTIFIRE_OR_DIRECTIVE != nameToken
45+ .getType()) {
46+ System.out
47+ .println("ERROR: type: name must be IDENTIFIRE_OR_DIRECTIVE");
48+ }
49+
50+ {
51+ final PascalLexicalToken checkToken = PascalSyntaxTokenUtil
52+ .readNextTokenWithoutWhitespaces(processInfo);
53+ if (PascalConstants.TokenType.SPECIAL_SYMBOL_WITHOUT_WORD != checkToken
54+ .getType())
55+ System.out
56+ .println("ERROR: type: = must be SPECIAL_SYMBOL_WITHOUT_WORD");
57+ if (!"=".equals(checkToken.getWord()))
58+ System.out.println("ERROR: function: expected = but was: "
59+ + checkToken.getWord());
60+ }
61+
62+ // can be class, record,,,
63+ {
64+ final PascalLexicalToken nextToken = PascalSyntaxTokenUtil
65+ .readNextTokenWithoutWhitespaces(processInfo);
66+ if (PascalConstants.TokenType.WORD_SYMBOL == nextToken.getType()) {
67+ if ("class".equals(nextToken.getWord().toLowerCase())) {
68+ ast.setTypeType(nextToken.getWord());
69+ }else{
70+ System.out.println("type: NOT IMPLEMENTED");
71+ }
72+ }
73+ }
74+
75+ {
76+ final PascalLexicalToken checkToken = PascalSyntaxTokenUtil
77+ .checkNextTokenWithoutWhitespaces(processInfo);
78+ if (PascalConstants.TokenType.SPECIAL_SYMBOL_WITHOUT_WORD == checkToken
79+ .getType()){
80+ ast.setForwardDeclaration(true);
81+ // only for decl. return here.
82+ return;
83+ }
84+ }
85+ }
86+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenConstParser.java (revision 133)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenConstParser.java (revision 134)
@@ -5,7 +5,6 @@
55 import jp.igapyon.jobjectpascal.parser.PascalSyntaxProcessInfo;
66 import jp.igapyon.jobjectpascal.parser.PascalSyntaxTokenUtil;
77 import jp.igapyon.jobjectpascal.parser.ast.PascalAstConst;
8-import jp.igapyon.jobjectpascal.parser.ast.PascalAstNodeImpl;
98
109 public class PascalSyntaxTokenConstParser {
1110 public void parseMuiti(PascalSyntaxProcessInfo processInfo) {
@@ -26,7 +25,7 @@
2625 }
2726 if (PascalConstants.TokenType.IDENTIFIRE_OR_DIRECTIVE == token
2827 .getType()) {
29- // continue var block
28+ // continue const block
3029 processInfo.lexicalIndex--;
3130 break;
3231 }
--- trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenVarParser.java (revision 133)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/syntax/PascalSyntaxTokenVarParser.java (revision 134)
@@ -4,7 +4,6 @@
44 import jp.igapyon.jobjectpascal.parser.PascalLexicalToken;
55 import jp.igapyon.jobjectpascal.parser.PascalSyntaxProcessInfo;
66 import jp.igapyon.jobjectpascal.parser.PascalSyntaxTokenUtil;
7-import jp.igapyon.jobjectpascal.parser.ast.PascalAstNodeImpl;
87 import jp.igapyon.jobjectpascal.parser.ast.PascalAstVar;
98
109 public class PascalSyntaxTokenVarParser {
--- trunk/src/jp/igapyon/jobjectpascal/parser/ast/PascalAstType.java (revision 133)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/ast/PascalAstType.java (revision 134)
@@ -2,6 +2,15 @@
22
33 public class PascalAstType extends PascalAstNodeImpl {
44 protected String typeName;
5+ protected String typeType;
6+ public String getTypeType() {
7+ return typeType;
8+ }
9+
10+ public void setTypeType(String typeType) {
11+ this.typeType = typeType;
12+ }
13+
514 protected String parentTypeName;
615 protected boolean forwardDeclaration = false;
716
@@ -30,7 +39,7 @@
3039 }
3140
3241 public String getString() {
33- return getName() + ": " + getTypeName() + ": parent["
42+ return getName() + ": " + getTypeName() + ": "+getTypeType()+": parent["
3443 + getParentTypeName() + "]"
3544 + (isForwardDeclaration() ? " forwardDecl" : "");
3645 }
--- trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenParser.java (revision 133)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenParser.java (revision 134)
@@ -47,6 +47,7 @@
4747 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenConstParser;
4848 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenFunctionParser;
4949 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenProgramParser;
50+import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenTypeParser;
5051 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenUsesParser;
5152 import jp.igapyon.jobjectpascal.parser.syntax.PascalSyntaxTokenVarParser;
5253
@@ -74,7 +75,7 @@
7475 final PascalSyntaxTokenParser parser = new PascalSyntaxTokenParser();
7576 parser.setBreakOnImplementation(true);
7677 final List<PascalAstNode> syntaxTokenList = parser.parse(new File(
77- "./test/data/op/TestSrc005.pas"));
78+ "./test/data/op/TestSrc003.pas"));
7879 System.out.println("Result:");
7980 for (PascalAstNode syntax : syntaxTokenList) {
8081 System.out.println(syntax.getString());
@@ -133,7 +134,8 @@
133134 return;
134135 }
135136 } else if ("type".equals(wordSymbol)) {
136- parseType();
137+ processInfo.lexicalIndex++;
138+ new PascalSyntaxTokenTypeParser().parseMuiti(processInfo);
137139 } else if ("var".equals(wordSymbol)) {
138140 processInfo.lexicalIndex++;
139141 new PascalSyntaxTokenVarParser().parseMuiti(processInfo);
--- trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenUtil.java (revision 133)
+++ trunk/src/jp/igapyon/jobjectpascal/parser/PascalSyntaxTokenUtil.java (revision 134)
@@ -36,8 +36,6 @@
3636 import java.util.ArrayList;
3737 import java.util.List;
3838
39-import org.xml.sax.ext.LexicalHandler;
40-
4139 import jp.igapyon.jobjectpascal.PascalConstants;
4240 import jp.igapyon.jobjectpascal.parser.ast.PascalAstNode;
4341 import jp.igapyon.jobjectpascal.parser.ast.PascalAstType;
@@ -60,6 +58,27 @@
6058 return false;
6159 }
6260
61+ /**
62+ * only for check
63+ *
64+ * @param processInfo
65+ * @return
66+ */
67+ public static PascalLexicalToken checkNextTokenWithoutWhitespaces(
68+ final PascalSyntaxProcessInfo processInfo) {
69+ for (int index = processInfo.lexicalIndex; index < processInfo.lexicalTokenList
70+ .size(); index++) {
71+ final PascalLexicalToken token = processInfo.lexicalTokenList
72+ .get(index);
73+ if (isWhitespaceTokenSeparators(token)) {
74+ continue;
75+ }
76+ return token;
77+ }
78+
79+ return null;
80+ }
81+
6382 public static PascalLexicalToken readNextTokenWithoutWhitespaces(
6483 final PascalSyntaxProcessInfo processInfo) {
6584 for (; processInfo.lexicalIndex < processInfo.lexicalTokenList.size(); processInfo.lexicalIndex++) {
Show on old repository browser