Commit b21c0cab authored by Anders Nilsson's avatar Anders Nilsson

Can now parse and build AST for extremely simplified xml input files

parent 1b483860
parser/semantic.cache
AST
*.class
/*
* Created on 2005-mar-09
*
*/
// package programs;
import AST.Start;
public class Dumper extends Parser {
public static void main(String args[]) {
Start ast = parse(args);
// Dump the AST
ast.dumpTree(" ", System.out);
}
}
\ No newline at end of file
This diff is collapsed.
/*
* Created on 2005-mar-10
*
*/
// package programs;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import AST.OwlParser;
import AST.ParseException;
import AST.Start;
/**
* @author gorel
*
*/
public class Parser {
protected static Start parse(String args[]) {
Reader r = getReader(args);
Start ast = null;
try {
OwlParser parser = new OwlParser(r);
// Start parsing from the nonterminal "Start".
ast = parser.Start();
} catch (ParseException e) {
System.out.println(e.getMessage());
}
return ast;
}
private static Reader getReader(String[] args) {
Reader r = null;
if (args.length != 1) {
r = new InputStreamReader(System.in);
} else {
try {
r = new FileReader(args[0]);
} catch (FileNotFoundException e1) {
System.err.println("Dumper: file " + args[0] + " not found");
}
}
return r;
}
}
\ No newline at end of file
......@@ -16,6 +16,8 @@
<property name="javacc.home" value="tools/javacc-4.0"/>
<property name="parser.name" value="OwlParser"/>
<!-- "jflex" is an ant task class for the scanner generator in JFlex.jar -->
<!-- <taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="tools/JFlex.jar"/> -->
<!-- "beaver" is an ant task class for the parser generator in beaver.jar -->
......@@ -25,7 +27,7 @@
<!-- compile sources -->
<target name="build" depends="gen">
<javac compiler="jikes" debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="test/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/>
<javac compiler="jikes" debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="tools/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/>
</target>
<!-- generate compiler source files -->
......@@ -33,15 +35,33 @@
<!-- create AST node types and weave aspect modules -->
<echo message = "Running JastAdd"/>
<!-- <jastadd package="${package}" rewrite="true" beaver="true" novisitcheck="true"> -->
<jastadd package="${package}" rewrite="true" beaver="false" novisitcheck="true">
<jastadd package="${package}" grammar="${parser.name}" rewrite="true" jjtree="true">
<fileset dir=".">
<include name="**/*.ast"/>
<include name="**/*.jrag"/>
<include name="**/*.jadd"/>
</fileset>
</jastadd>
<jjtree target="owl.jjt" outputdirectory="${package}" javacchome="${javacc.home}"/>
<javacc target="${package}/owl.jj" outputdirectory="${package}" javacchome="${javacc.home}"/>
<jjtree
target="owl.jjt"
outputdirectory="${package}"
javacchome="${javacc.home}"
buildnodefiles="true"
static="false"
multi="true"
visitor="true"
nodedefaultvoid="true"
nodeprefix='""'
nodepackage="${package}"
/>
<javacc
target="${package}/owl.jj"
outputdirectory="${package}"
javacchome="${javacc.home}"
buildparser="true"
buildtokenmanager="true"
static="false"
/>
<!-- generate the scanner -->
<!-- <echo message = "Running jflex"/> -->
......
// -*-Java-*-
Start ::= Specification;
Specification ::= Attribute*;
Attribute ::= Id Value;
Id ::= <IDENTIFIER>;
Value ::= <STRING_LITERAL>;
\ No newline at end of file
......@@ -3,6 +3,7 @@ options {
VISITOR = true;
NODE_DEFAULT_VOID = true;
NODE_SCOPE_HOOK = false;
NODE_PREFIX = "";
JAVA_UNICODE_ESCAPE = true;
STATIC = false;
} // options
......@@ -192,9 +193,9 @@ SPECIAL_TOKEN : /* COMMENTS */
}// SEPARATORS
// <DEFAULT,BOUNDS> TOKEN : /* OPERATORS */
// {
// < ASSIGN : "=" >
<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */
{
< ASSIGN : "=" >
// | < GT : ">" >
// | < LT : "<" >
// | < BANG : "!" >
......@@ -231,16 +232,42 @@ SPECIAL_TOKEN : /* COMMENTS */
// | < LSHIFTASSIGN : "<<=" >
// | < RSIGNEDSHIFTASSIGN : ">>=" >
// | < RUNSIGNEDSHIFTASSIGN : ">>>=" >
// }// OPERATORS
}// OPERATORS
//--------------------------------------------------------------------//
// THE OWL LANGUAGE GRAMMAR //
//--------------------------------------------------------------------//
Specification Specification() #Specification : {}
Start Start() #Start : {}
{
"<?" <XML> AttributeList() "?>"
Specification()
{ return jjtThis; }
}
void Specification() #Specification : {}
{
"<?" <XML> AttributeList() "?>"
}
void AttributeList() #List : {}
{
(Attribute())*
}
void Attribute() #Attribute : { Token t; }
{
Id() <ASSIGN> Value()
}
void Id() #Id : { Token t; }
{
t = <IDENTIFIER>
{jjtThis.setIDENTIFIER(t.image);}
}
void Value() #Value : { Token t; }
{
t = <STRING_LITERAL>
{jjtThis.setSTRING_LITERAL(t.image);}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment