Saad Ahmed
2012-12-11 17:39:39 UTC
Hi,
I have a grammar on which i am applying semantic rules. But my rules does
not seem to be fired . Here is an example .
compilation_unit
@init{
BufferedWriter out=null;
try{
// Create file
FileWriter fstream = new FileWriter("D:\\out.txt");
out = new BufferedWriter(fstream);
// out.write("Hello Java");
//Close the output stream
//out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
@after {
try {
out.write($str.text);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
: (str=unit_statement)* EOF
;
unit_statement
returns [String str="Main Prodcution"]:
s1=create_procedure_body {$str+=$s1.text;}|
s2=create_package{System.out.println($s2.text);$str+=$s2.text;}
;
create_package
returns[String str=""]: c=create_key ( o=or_key r=replace_key )?
p=package_key
( p1=package_spec | p2=package_body )?
SEMICOLON? SOLIDUS //{$str=//$c.text+"kill"+$o.text+" changes made
here "+$p1.text;*/}
;
Now what is written on out.txt is the input stream as it is . No changes
that we have made in our semantic rules appear in the file ... Any help
would be appreciated.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
I have a grammar on which i am applying semantic rules. But my rules does
not seem to be fired . Here is an example .
compilation_unit
@init{
BufferedWriter out=null;
try{
// Create file
FileWriter fstream = new FileWriter("D:\\out.txt");
out = new BufferedWriter(fstream);
// out.write("Hello Java");
//Close the output stream
//out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
@after {
try {
out.write($str.text);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
: (str=unit_statement)* EOF
;
unit_statement
returns [String str="Main Prodcution"]:
s1=create_procedure_body {$str+=$s1.text;}|
s2=create_package{System.out.println($s2.text);$str+=$s2.text;}
;
create_package
returns[String str=""]: c=create_key ( o=or_key r=replace_key )?
p=package_key
( p1=package_spec | p2=package_body )?
SEMICOLON? SOLIDUS //{$str=//$c.text+"kill"+$o.text+" changes made
here "+$p1.text;*/}
;
Now what is written on out.txt is the input stream as it is . No changes
that we have made in our semantic rules appear in the file ... Any help
would be appreciated.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address