-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.java
More file actions
120 lines (107 loc) · 2.94 KB
/
constants.java
File metadata and controls
120 lines (107 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author Suleman
*/
public class constants {
int value;
public boolean chk_constant(String a) {
if (intconstant(a)) {
value = 0;
return true;
}
if (Stringconstant(a)) {
value = 1;
return true;
}
if (charconstant(a)) {
value = 2;
return true;
}
if (floatconstant(a)) {
value = 3;
return true;
}
if (lexine(a))
{ value = 4;
return true;
}
return false;
}
public int getValue() {
return value;
}
public boolean intconstant(String in) {
//String s = n;
Pattern p = Pattern.compile("[0-9]+");
Matcher m = p.matcher(in);
if (m.matches() == true) //{value=0;
{
return true;
}
return false;
}
public boolean Stringconstant(String in) {
// String s = n;
Pattern p = Pattern.compile("\".*(\"|\".*\")"); /// //^\".*?\"$
Matcher m = p.matcher(in);
if (m.matches() == true) //{value=0;
{
return true;
}
return false;
}
public boolean charconstant(String in) {
//String s = n;
Pattern p = Pattern.compile("('.')|('')");
Matcher m = p.matcher(in);
if (m.matches() == true) //{value=0;
{
return true;
}
return false;
}
public boolean lexine (String in) {
//int value;
//String s = n;
Pattern p = Pattern.compile(" \\.[0-9]+[A-Z]+[a-z]6");
Matcher m = p.matcher(in);
if (m.matches() == true) //{value=0;
{
return true;
} //else {
// Pattern p1 = Pattern.compile("[+-]?[0-9]{0,}\\.[0-9]{0,}([eE][+-]?[0-9]{0,})?");
// Matcher m1 = p1.matcher(in);
// if (m1.matches() == true) // value = 4;
// {
//
// }
// }
return false;
}
public boolean floatconstant(String in) {
//int value;
//String s = n;
Pattern p = Pattern.compile("[0-9]+\\.[0-9]*");
Matcher m = p.matcher(in);
if (m.matches() == true) //{value=0;
{
return true;
} //else {
// Pattern p1 = Pattern.compile("[+-]?[0-9]{0,}\\.[0-9]{0,}([eE][+-]?[0-9]{0,})?");
// Matcher m1 = p1.matcher(in);
// if (m1.matches() == true) // value = 4;
// {
//
// }
// }
return false;
}
}