next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Código de aSb.output Sup: Apéndice Ant: Código de Calc.yp Err: Si hallas una errata ...


Código de Calc.pm

Este es el resultado de la traducción mediante yapp del programa de la calculadora descrito en la página [*]. Para ver un resumen de las tablas vaya a la página [*].

 1 ####################################################################
 2 #
 3 #    This file was generated using Parse::Yapp version 1.05.
 4 #
 5 #        Don't edit this file, use source file instead.
 6 #
 7 #             ANY CHANGE MADE HERE WILL BE LOST !
 8 #
 9 ####################################################################
10 package Calc;
11 use vars qw ( @ISA );
12 use strict;
13 
14 @ISA= qw ( Parse::Yapp::Driver );
15 use Parse::Yapp::Driver;
16 
17 sub new {
18         my($class)=shift;
19         ref($class)
20     and $class=ref($class);
21 
22     my($self)=$class->SUPER::new( yyversion => '1.05',
23                                   yystates => [
24 	{#State 0
25 		DEFAULT => -1, GOTOS => { 'input' => 1 }
26 	},
27 	{#State 1
28 		ACTIONS => { 'NUM' => 6, '' => 4, "-" => 2, "(" => 7, 'VAR' => 8, "\n" => 5, 'error' => 9 },
29 		GOTOS => { 'exp' => 3, 'line' => 10
30 		}
31 	},
32 	{#State 2
33 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
34 		GOTOS => { 'exp' => 11 }
35 	},
36 	{#State 3
37 		ACTIONS => { "-" => 12, "^" => 16, "*" => 17, "\n" => 14, "+" => 13, "/" => 15 }
38 	},
39 	{#State 4
40 		DEFAULT => 0
41 	},
42 	{#State 5
43 		DEFAULT => -3
44 	},
45 	{#State 6
46 		DEFAULT => -6
47 	},
48 	{#State 7
49 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
50 		GOTOS => { 'exp' => 18 }
51 	},
52 	{#State 8
53 		ACTIONS => { "=" => 19 },
54 		DEFAULT => -7
55 	},
56 	{#State 9
57 		ACTIONS => { "\n" => 20 }
58 	},
59 	{#State 10
60 		DEFAULT => -2
61 	},
62 	{#State 11
63 		ACTIONS => {
64 			"^" => 16
65 		},
66 		DEFAULT => -13
67 	},
68 	{#State 12
69 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8
70 		},
71 		GOTOS => { 'exp' => 21 }
72 	},
73 	{#State 13
74 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
75 		GOTOS => { 'exp' => 22 }
76 	},
77 	{#State 14
78 		DEFAULT => -4
79 	},
80 	{#State 15
81 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
82 		GOTOS => { 'exp' => 23 }
83 	},
84 	{#State 16
85 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
86 		GOTOS => { 'exp' => 24 }
87 	},
88 	{#State 17
89 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
90 		GOTOS => { 'exp' => 25 }
91 	},
92 	{#State 18
93 		ACTIONS => { "-" => 12, "^" => 16, "*" => 17, "+" => 13, "/" => 15, ")" => 26 }
94 	},
95 	{#State 19
96 		ACTIONS => { 'NUM' => 6, "-" => 2, "(" => 7, 'VAR' => 8 },
97 		GOTOS => { 'exp' => 27 }
98 	},
99 	{#State 20
100 		DEFAULT => -5
101 	},
102 	{#State 21
103 		ACTIONS => { "^" => 16, "*" => 17, "/" => 15 },
104 		DEFAULT => -10
105 	},
106 	{#State 22
107 		ACTIONS => { "^" => 16, "*" => 17, "/" => 15 },
108 		DEFAULT => -9
109 	},
110 	{#State 23
111 		ACTIONS => { "^" => 16 },
112 		DEFAULT => -12
113 	},
114 	{#State 24
115 		ACTIONS => {
116 			"^" => 16
117 		},
118 		DEFAULT => -14
119 	},
120 	{#State 25
121 		ACTIONS => {
122 			"^" => 16
123 		},
124 		DEFAULT => -11
125 	},
126 	{#State 26
127 		DEFAULT => -15
128 	},
129 	{#State 27
130 		ACTIONS => { "-" => 12, "^" => 16, "*" => 17, "+" => 13, "/" => 15 },
131 		DEFAULT => -8
132 	}
133 ],
134                                   yyrules  => [
135 	[#Rule 0
136 		 '$start', 2, undef ],
137 	[#Rule 1
138 		 'input', 0, undef ],
139 	[#Rule 2
140 		 'input', 2,
141 sub
142 #line 17 "Calc.yp"
143 { push(@{$_[1]},$_[2]); $_[1] }
144 	],
145 	[#Rule 3
146 		 'line', 1,
147 sub
148 #line 20 "Calc.yp"
149 { $_[1] }
150 	],
151 	[#Rule 4
152 		 'line', 2,
153 sub
154 #line 21 "Calc.yp"
155 { print "$_[1]\n" }
156 	],
157 	[#Rule 5
158 		 'line', 2,
159 sub
160 #line 22 "Calc.yp"
161 { $_[0]->YYErrok }
162 	],
163 	[#Rule 6
164 		 'exp', 1, undef
165 	],
166 	[#Rule 7
167 		 'exp', 1,
168 sub
169 #line 26 "Calc.yp"
170 { $_[0]->YYData->{VARS}{$_[1]} }
171 	],
172 	[#Rule 8
173 		 'exp', 3,
174 sub
175 #line 27 "Calc.yp"
176 { $_[0]->YYData->{VARS}{$_[1]}=$_[3] }
177 	],
178 	[#Rule 9
179 		 'exp', 3,
180 sub
181 #line 28 "Calc.yp"
182 { $_[1] + $_[3] }
183 	],
184 	[#Rule 10
185 		 'exp', 3,
186 sub
187 #line 29 "Calc.yp"
188 { $_[1] - $_[3] }
189 	],
190 	[#Rule 11
191 		 'exp', 3,
192 sub
193 #line 30 "Calc.yp"
194 { $_[1] * $_[3] }
195 	],
196 	[#Rule 12
197 		 'exp', 3,
198 sub
199 #line 31 "Calc.yp"
200 {
201                                       $_[3]
202                                   and return($_[1] / $_[3]);
203                                   $_[0]->YYData->{ERRMSG}
204                                     =   "Illegal division by zero.\n";
205                                   $_[0]->YYError;
206                                   undef
207                                 }
208 	],
209 	[#Rule 13
210 		 'exp', 2,
211 sub
212 #line 39 "Calc.yp"
213 { -$_[2] }
214 	],
215 	[#Rule 14
216 		 'exp', 3,
217 sub
218 #line 40 "Calc.yp"
219 { $_[1] ** $_[3] }
220 	],
221 	[#Rule 15
222 		 'exp', 3,
223 sub
224 #line 41 "Calc.yp"
225 { $_[2] }
226 	]
227 ],
228                                   @_);
229     bless($self,$class);
230 }
231 
232 #line 44 "Calc.yp"
233 
234 
235 sub _Error {
236         exists $_[0]->YYData->{ERRMSG}
237     and do {
238         print $_[0]->YYData->{ERRMSG};
239         delete $_[0]->YYData->{ERRMSG};
240         return;
241     };
242     print "Syntax error.\n";
243 }
244 
245 sub _Lexer {
246     my($parser)=shift;
247 
248         $parser->YYData->{INPUT}
249     or  $parser->YYData->{INPUT} = <STDIN>
250     or  return('',undef);
251 
252     $parser->YYData->{INPUT}=~s/^[ \t]//;
253 
254     for ($parser->YYData->{INPUT}) {
255         s/^([0-9]+(?:\.[0-9]+)?)//
256                 and return('NUM',$1);
257         s/^([A-Za-z][A-Za-z0-9_]*)//
258                 and return('VAR',$1);
259         s/^(.)//s
260                 and return($1,$1);
261     }
262 }
263 
264 sub Run {
265     my($self)=shift;
266     $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error) #, yydebug => 0x10 );
267 }
268 
272 1;


next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Código de aSb.output Sup: Apéndice Ant: Código de Calc.yp Err: Si hallas una errata ...
Casiano Rodríguez León
2006-02-21