-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.y
93 lines (68 loc) · 1.51 KB
/
net.y
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%{
# include <net-parser.H>
/* # include <iostream> */
/* using namespace std; */
extern int get_input(char *buf, int size);
# undef YY_INPUT
# define YY_INPUT(buf,result,max_size) result = get_input(buf, max_size);
int yylex(void);
void yyerror(char const *);
/* bool error_found = false; */
/* CommandList * command_list; */
/* using CommandListPtr = CommandList*; */
/* using CommandPtr = Command*; */
%}
/* %union { */
/* char * symbol; */
/* char * error_msg; */
/* }; */
%token LOAD SAVE RIF COD EXIT STRCONST VARNAME
/* %token <symbol> STRCONST */
/* %token <symbol> VARNAME */
/* %type <symbol> cmd_unit */
%%
input: line
;
line: cmd_unit '\n'
{
cout << "PARSED LINE" << endl;
}
;
cmd_unit: LOAD STRCONST
{
cout << "LOAD" << endl;
}
| SAVE STRCONST
{
cout << "SAVE" << endl;
}
;
%%
void yyerror(char const * s)
{
cout << "ERROR " << s << " " << endl;
}
int yylex()
{
static int count = 0;
switch (count++)
{
case 0: cout << "LOAD" << endl; return LOAD;
case 1: cout << "STRCONST" << endl; return STRCONST;
case 2: cout << "EOL" << endl; return '\n';
default: cout << "EOF" << endl; return EOF;
}
}
int main()
{
/* while (true) */
/* { */
/* char * line = // readline("> "); */
/* "Load \"name\"\n\n"; */
/* YY_BUFFER_STATE bp = yy_scan_string(line); */
/* yy_switch_to_buffer(bp); */
int status = yyparse();
cout << "STATUS = " << status << endl;
/* yy_delete_buffer(bp); */
// }
}