weesan@eon:~> svn co https://svn.cs.ucr.edu/svn/cs152/weesan Error validating server certificate for 'https://svn.cs.ucr.edu:443': - The certificate is not issued by a trusted authority. Use the fingerprint to validate the certificate manually! Certificate information: - Hostname: svn.cs.ucr.edu - Valid: from Nov 26 23:58:06 2005 GMT until Nov 26 23:58:06 2006 GMT - Issuer: Department of Computer Science and Engineering, UCR, Riverside, California, US - Fingerprint: c0:aa:07:ad:16:60:c1:3c:7a:25:2f:0e:47:b3:bb:5e:8b:ec:08:de (R)eject, accept (t)emporarily or accept (p)ermanently? p Checked out revision 0. weesan@eon:~> weesan@eon:~> cd weesan weesan@eon:~/weesan> weesan@eon:~/weesan> svn mkdir lab1 A lab1 weesan@eon:~/weesan> cd lab1 weesan@eon:~/weesan/lab1> weesan@eon:~/weesan/lab1> vi README weesan@eon:~/weesan/lab1> cat README WeeSan Leeweesan@eon:~/weesan/lab1> weesan@eon:~/weesan/lab1> svn ci Adding lab1 Adding lab1/README Transmitting file data . Committed revision 1. weesan@eon:~/weesan/lab1> weesan@eon:~/weesan/lab1> cd weesan@eon:~> weesan@eon:~> rm -rf weesan weesan@eon:~> weesan@eon:~> svn co https://svn.cs.ucr.edu/svn/cs152/weesan/lab1 A lab1/README Checked out revision 1. weesan@eon:~> weesan@eon:~> cd lab1 weesan@eon:~/lab1> weesan@eon:~/lab1> ls -l total 0 -rw------- 1 weesan csgrads 31 Jan 9 17:41 README weesan@eon:~/lab1> weesan@eon:~/lab1> cat README WeeSan Lee weesan@eon:~/lab1> weesan@eon:~/lab1> cd weesan@eon:~> rm -rf lab1 weesan@eon:~>
Flex program: lab1.l
%{
/*
* lab1.l
*
* To compile, do the following:
* $ flex lab1.l
* $ gcc lex.yy.c -o lab1 -lfl
*
* To run, do the following:
* $ lab1 < Factorial.java
*/
#include <stdio.h>
%}
ws [ \n\t]+
%%
[A-Za-z0-9_]+ {
printf("[%s]\n", yytext);
}
{ws} {
}
.
%%
int main(void) {
yylex();
return (0);
}
Input file: Factorial.java
class Factorial{
public static void main(String[] a){
System.out.println(new Fac().ComputeFac(10));
}
}
class Fac {
public int ComputeFac(int num){
int num_aux ;
if (num < 1)
num_aux = 1 ;
else
num_aux = num * (this.ComputeFac(num-1)) ;
return num_aux ;
}
}
%{
/*
* stl_list.l
*
* To compile, do the following:
* $ flex -t stl_list.l > stl_list.cc
* $ g++ stl_list.cc -o stl_list -lfl
*
* To run, do the following:
* $ stl_list < Factorial.java
*/
#include <stdio.h>
#include <list>
#include <string>
using namespace std;
typedef list<string> ids_t;
static ids_t ids;
%}
ws [ \n\t]+
%%
[A-Za-z0-9_]+ {
ids.push_back(yytext);
}
{ws} {
}
.
%%
int main(void) {
yylex();
for (ids_t::iterator itr = ids.begin(); itr != ids.end(); itr++) {
printf("[%s]\n", itr->c_str());
}
return (0);
}
%{
/*
* stl_vector.l
*
* To compile, do the following:
* $ flex -t stl_vector.l > stl_vector.cc
* $ g++ stl_vector.cc -o stl_vector -lfl
*
* To run, do the following:
* $ stl_vector < Factorial.java
*/
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> ids_t;
static ids_t ids;
%}
ws [ \n\t]+
%%
[A-Za-z0-9_]+ {
ids.push_back(yytext);
}
{ws} {
}
.
%%
int main(void) {
yylex();
for (int i = 0; i < ids.size(); i++) {
printf("[%s]\n", ids[i].c_str());
}
return (0);
}
$ gcc -g gdb_ex.c -o gdb_ex
$ gdb gdb_ex
(gdb) b main
Breakpoint 1 at 0x8048389: file gdb_ex.c, line 13.
(gdb)
(gdb) run
Starting program: /home/weesan/public_html/cs152/lab1/gdb_ex
Breakpoint 1, main () at gdb_ex.c:13
13 func1();
(gdb)
(gdb) list
8 void func1(void) {
9 func2();
10 }
11
12 int main(void) {
13 func1();
14 return (0);
15 }
(gdb)
(gdb) n
14 func1();
(gdb)
(gdb) s
func1 () at gdb_ex.c:9
9 func2();
(gdb)
(gdb) s
func2 () at gdb_ex.c:4
4 int *p = NULL;
(gdb)
(gdb) p pt
$1 = (int *) 0xbfc8f63c
(gdb) n
5 *pt = 1234;
(gdb) p pt
$2 = (int *) 0x0
(gdb)
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x08048389 in main at gdb_ex.c:13
breakpoint already hit 1 time
(gdb)
(gdb) d 1
(gdb)
(gdb) cont
Continuing.
(gdb) q
The program is running. Exit anyway? (y or n) y
$
$ gdb_ex
Segmentation fault (core dumped)
$ gdb gdb_ex core
GNU gdb 6.3
...
Core was generated by `gdb_ex'.
Program terminated with signal 11, Segmentation fault.
warning: current_sos: Can't read pathname for load map: Input/output error
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0 0x08048364 in func2 () at gdb_ex.c:5
5 *pt = 1234;
(gdb)
(gdb) bt
#0 0x08048364 in func2 () at gdb_ex.c:5
#1 0x08048377 in func1 () at gdb_ex.c:9
#2 0x08048395 in main () at gdb_ex.c:14
(gdb)
(gdb) f 0
#0 0x08048364 in func2 () at gdb_ex.c:5
5 *pt = 1234;
(gdb)
(gdb) up
#1 0x08048377 in func1 () at gdb_ex.c:9
9 func2();
(gdb)
(gdb) down
#0 0x08048364 in func2 () at gdb_ex.c:5
5 *pt = 1234;
(gdb)
(gdb) q
$