My favorites | Sign in
Project Logo
                
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
import java.io.IOException;
import java.io.FileInputStream;
import java.io.File;
import java.io.InputStream;

import org.yuanheng.cookcc.*;

@CookCCOption
public class WC1 extends Lexer1
{
private int m_cc; // character count
private int m_wc; // word count
private int m_lc; // line count

@Shortcuts ( shortcuts = {
@Shortcut (name="nonws", pattern="[^ \\t\\n]"),
@Shortcut (name="ws", pattern="[ \\t]")
})
@Lex (pattern="{nonws}+", state="INITIAL")
void matchWord ()
{
m_cc += yyLength ();
++m_wc;
}

/**
* Match white space characters.
*/
@Lex (pattern="{ws}+")
void matchSpace ()
{
m_cc += yyLength ();
}

@Lex (pattern = "\\n")
void matchEOL ()
{
m_cc += yyLength ();
++m_lc;
}

/**
* This function is called when the end of file character (artificially
* created) is matched.
* <p>
* CookCC detects that there is an int (has to be int in Java) return
* type and would return this value as the return value from the lexer.
*
* @return 0
*/
@Lex (pattern="<<EOF>>")
int matchEOF ()
{
System.out.println (m_lc + ", " + m_wc + ", " + m_cc);
return 0;
}

public void parse (InputStream is) throws IOException
{
setInput (is);
yyLex ();
}

public static void main (String[] args) throws IOException
{
WC1 wc = new WC1 ();
if (args.length == 0)
wc.parse (System.in);
else
wc.parse (new FileInputStream (new File (args[0])));
}
}
Show details Hide details

Change log

r486 by superduperhengyuan on Nov 09, 2008   Diff
add java annotation as input.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1484 bytes, 72 lines

File properties

svn:keywords
Id Revision
Hosted by Google Code