First of all, sorry for my bad English but I'm not native.
I'm studying jflex and byaccj at university and I've done a simple exercise to learn how things work.
I've a test.xml file like this:
<collezione_film><film></film></collezione_film>
My exercise.flex is
%%
%byaccj
%{
private Parser yyparser;
public Yylex(java.io.Reader r, Parser yyparser) {
this(r);
this.yyparser = yyparser;
}
%}
%x IN_GROUP IN_PROPERTY
%state COLLEZIONE_FILM
TAG_COLLEZIONE_FILM_START = <collezione_film>
TAG_FILM_OPEN_START = <film+[ \t]
%%
<YYINITIAL> {
{TAG_COLLEZIONE_FILM_START} {
yyparser.yylval = new ParserVal("collezione_film");
yybegin(COLLEZIONE_FILM);
return Parser.TAG_START;
}
[^] { /* Non fare nulla */ }
}
<COLLEZIONE_FILM> {
{TAG_FILM_OPEN_START} {
yyparser.yylval = new ParserVal("film");
return Parser.TAG_START;
}
[^] { /* Non fare nulla */ }
}
and my exercise.y is
%token<sval> TAG_START
%type<sval> tags
%%
config : tags { System.out.print($1); }
tags : TAG_START tags {
$$ = $1 + " " + $2;
}
| TAG_START { $$ = $1; }
;
%%
private Yylex lexer;
private int yylex () {
int yyl_return = -1;
try {
yylval = new ParserVal(0);
yyl_return = lexer.yylex();
}
catch (java.io.IOException e) {
System.err.println("IO error :"+e);
}
return yyl_return;
}
public void yyerror (String error) {
System.err.println ("Error: " + error);
}
public Parser(java.io.Reader r) {
lexer = new Yylex(r, this);
}
public static void main(String args[]) throws java.io.IOException {
Parser yyparser;
if ( args.length > 0 ) {
yyparser = new Parser(new java.io.FileReader(args[0]));
yyparser.yyparse();
}
else {
System.out.println("Nessun file specificato.");
}
}
I understand that you can't use this code to a more general example, but my question is: Why the parser in this particular example (see test.xml) prints only "collezione_film" and not "collezione_film film"? What I'm missing?