-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcmd.y
More file actions
66 lines (58 loc) · 2.8 KB
/
Copy pathcmd.y
File metadata and controls
66 lines (58 loc) · 2.8 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
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "handler.h"
%}
/* delcare token */
%token NUMBER
%token ADD SUB MUL DIV OP CP
%token REG LOGIN LOGOUT SHOW TABLES PLAYERS IN MK JOIN PWD QUIT EXIT HELP
%token BET RAISE CALL CHECK FOLD ALL_IN CHAT PROMPT TYPE START
%token IDENTIFIER STRING
%token EOL
%union
{
int intval;
char *strval;
}
%type <intval> exp factor term NUMBER
%type <strval> IDENTIFIER STRING
%%
calclist: /* empty */
| calclist REG IDENTIFIER IDENTIFIER EOL { reg($3, $4); free($3); free($4); }
| calclist LOGIN IDENTIFIER IDENTIFIER EOL { login($3, $4); free($3); free($4); }
| calclist LOGOUT EOL { logout(); }
| calclist MK IDENTIFIER EOL { create_table($3); free($3); }
| calclist JOIN IDENTIFIER EOL { join_table($3); free($3); }
| calclist QUIT EOL { quit_table(); }
| calclist EXIT EOL { exit_game(); }
| calclist SHOW TABLES EOL { show_tables(); }
| calclist SHOW PLAYERS EOL { show_players(); }
| calclist SHOW PLAYERS IN IDENTIFIER EOL { show_players_in_table($5); free($5); }
| calclist PWD EOL { pwd(); }
| calclist START EOL { start(); }
| calclist BET exp EOL { bet($3); }
| calclist RAISE exp EOL { raise_($3); }
| calclist CALL EOL { call(); }
| calclist FOLD EOL { fold(); }
| calclist CHECK EOL { check(); }
| calclist ALL_IN EOL { all_in(); }
| calclist HELP EOL { print_help(); }
| calclist CHAT STRING EOL { chat($3); free($3); }
| calclist PROMPT STRING EOL { prompt($3); free($3); }
| calclist exp EOL { reply("%d","{\"type\":\"calc\",\"data\":{[%d]}}", $2);}
| calclist EOL { reply("","{\"type\":\"empty\",\"data\":{}}");}
;
exp: factor
| exp ADD factor { $$ = $1 + $3; }
| exp SUB factor { $$ = $1 - $3; }
;
factor: term
| factor MUL term { $$ = $1 * $3; }
| factor DIV term { $$ = $1 / $3; }
;
term: NUMBER
| OP exp CP { $$ = $2; }
;
%%