-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLexema.java
71 lines (60 loc) · 1.26 KB
/
Lexema.java
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
/*
* by Gerardo Ayala
* UDLAP
* September 2015
*/
public class Lexema
{
// Elements of a Lexema
private String tokenId;
// a lexema can have a reserved word
private String reservedWord;
// or can have a dfa
private DFA dfa;
/////////////////
// constructor
// if the lexema has a dfa
public Lexema(String id, DFA aDFA)
{
tokenId = id;
dfa = aDFA;
reservedWord = null;
}//end constructor
// constructor
// if the lexema has a reserved word
public Lexema(String id, String aReservedWord)
{
tokenId = id;
reservedWord = aReservedWord;
dfa = null;
}//end constructor
// A method that determines
// if a given string is this Lexema
public boolean isThisLexema(String string)
{
boolean stringIsValid;
///////////////
stringIsValid = false;
// If the lexema does not imply a reserved word
if(reservedWord == null)
{
// we ask the DFA if the string is valid
stringIsValid = dfa.isValid(string);
}//end if
else
{
// we check if the string
// is the reserved word
if(reservedWord.equals(string))
{
stringIsValid = true;
}// end if
}//end else
return stringIsValid;
}//end isThisLexema
// Get the token of the lexema
public String getToken()
{
return tokenId;
}//end getToken
}//end class