-
Notifications
You must be signed in to change notification settings - Fork 1
/
Parser.cup
108 lines (78 loc) · 2.2 KB
/
Parser.cup
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java_cup.runtime.*;
import java.util.*;
import java.lang.* ;
import java.io.*;
action code
{:
:};
parser code
{:
public void syntax_error(Symbol cur_token) {
String linea = obtText();
report_error("Error de Sintaxis en la linea "+obtLine()+": "+ linea,cur_token);
}
public void unrecovered_syntax_error(Symbol cur_token){
report_error("Error irrecuperable. No se pudo generar el migrador.",cur_token);
}
public int obtLine(){
return lex.obtYyline();
}
public int obtChar(){
return lex.obtYychar();
}
public String obtText(){
return lex.obtYytext();
}
Yylex lex;
:};
init with
{:
lex=new Yylex(System.in);
:};
scan with
{:
return lex.next_token();
:};
terminal String var, ctte, nomb;
terminal oparen, cparen;
terminal imp, coma;
non terminal Vector EXPERIMENTO, CUERPO, LIST;
non terminal Query CQ;
non terminal Subgoal SO;
non terminal Argument ITEM;
start with EXPERIMENTO;
EXPERIMENTO::=
CQ:a
{: Vector l = new Vector();
l.add(a);
RESULT = l; :}
| EXPERIMENTO:l CQ:a
{: l.add(a);
RESULT = l; :}
;
CQ ::= SO:h imp CUERPO:c {: RESULT = new Query(h.getName(), h, c); :}
;
CUERPO ::=
SO:a
{: Vector l = new Vector();
l.add(a);
RESULT = l; :}
| CUERPO:l coma SO:a
{: l.add(a);
RESULT = l; :}
;
SO ::= nomb:n oparen LIST:l cparen {: RESULT = new Subgoal(n,l); :}
;
LIST ::=
ITEM:a
{: Vector l = new Vector();
l.add(a);
RESULT = l; :}
| LIST:l coma ITEM:a
{: l.add(a);
RESULT = l; :}
;
ITEM ::=
var:v {: RESULT = new Argument(v);:}
| ctte:c {: RESULT = new Argument(c);:}
;