Subversion Repositories programming

Rev

Rev 243 | Rev 258 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 243 Rev 244
Line 16... Line 16...
16
 
16
 
17
/* Token Declarations */
17
/* Token Declarations */
18
%token PUT
18
%token PUT
19
%token TAKE
19
%token TAKE
20
%token NL
20
%token NL
21
%token RESET
-
 
22
 
21
 
23
/* Robot Grammar */
22
/* Robot Grammar */
24
%%
23
%%
25
 
24
 
26
program : program line
25
program : program line
27
    | ;
26
    | ;
28
 
27
 
29
line: NL        { if (interactive) System.out.print ("Line: "); }
28
line: NL        { if (interactive) System.out.print (input_str); r.reset(); }
30
    | S NL      { System.out.println ("There are: " + r.getVal() + " apples in the bag!");
29
    | S NL      { System.out.println ("There are: " + r.getVal() + " apples in the bag!");
31
                  if (interactive) System.out.print ("Line: "); }
30
                  if (interactive) System.out.print (input_str); r.reset(); };
32
    | RESET     { r.reset(); System.out.println ("Reset the robot"); };
-
 
33
 
31
 
34
S : PUT S TAKE S    { System.out.println ("S -> PUT S TAKE S"); }
32
S : PUT S TAKE S    { System.out.println ("S -> PUT S TAKE S"); }
35
    | PUT S         { System.out.println ("S -> PUT S"); r.incVal(); }
33
    | PUT S         { System.out.println ("S -> PUT S"); r.incVal(); }
36
    |               { System.out.println ("S -> epsilon"); };
34
    |               { System.out.println ("S -> epsilon"); };
37
 
35
 
38
%%
36
%%
39
 
37
 
40
private Yylex lexer;
38
private Yylex lexer;
41
static boolean interactive = false;
39
static boolean interactive = false;
-
 
40
static String input_str = "Input: ";
42
 
41
 
43
public void yyerror (String error)
42
public void yyerror (String error)
44
{
43
{
45
    System.out.println ("Parse Error: " + error);
44
    //System.out.println ("Parse Error: " + error);
46
}
45
}
47
 
46
 
48
int yylex ()
47
int yylex ()
49
{
48
{
50
    int lex_return = -1;
49
    int lex_return = -1;
Line 77... Line 76...
77
    }
76
    }
78
    else
77
    else
79
    {
78
    {
80
        // interactive mode
79
        // interactive mode
81
        yyparser = new Parser (new InputStreamReader (System.in));
80
        yyparser = new Parser (new InputStreamReader (System.in));
82
        /*
-
 
83
        System.out.println ("Specify the file to use as the first command-line");
-
 
84
        System.out.println ("option. (EX: java Parser filename.txt)");
-
 
85
        System.exit (1);
-
 
86
        */
-
 
87
        System.out.println("[Quit with CTRL-D]");
81
        System.out.println("[Quit with CTRL-D]");
88
        System.out.print("Expression: ");
82
        System.out.print(input_str);
89
        interactive = true;
83
        interactive = true;
90
    }
84
    }
91
 
85
 
92
    try
86
    try
93
    {
87
    {