-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirst1.java
More file actions
63 lines (57 loc) · 1.13 KB
/
Copy pathFirst1.java
File metadata and controls
63 lines (57 loc) · 1.13 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
import java.io.*;
import java.lang.*;
class First1
{
static String grammar;
static String rule[];
static String var[];
static String list;
public static void main(String ar[])
{
input();
rule = grammar.split(" ");
System.out.println();
for(int i=0; i<list.length();i++)
{
char c=list.charAt(i);
System.out.println("First("+c+")={"+First(c)+"}");
}
}
static void input()
{
DataInputStream din=new DataInputStream(System.in);
try{
System.out.println("enter the grammar");
grammar=din.readLine();
System.out.println("List");
list=din.readLine();
}catch(Exception e){
System.exit(0);
}
}
static String First(char c)
{
if(!isNonTerminal(c))
return c+"";
String First="";
for(int i=0;i<rule.length;i++)
{
String s="";
for(int j=2;j<rule[i].length();j++)
{
char ch=rule[i].charAt(j);
s=First(ch);
if(!s.equals(" "))
break;
}
First+=s+" ";
}
return First.trim;
}
static boolean isNonterminal(char c);
{
if('A'<=c&&c<='Z')
return true;
return false;
}
}