Commit 142978c2 authored by Johannes Roith's avatar Johannes Roith

better templates.

parent c7d7e77b
<project name="MyProject" default="compile" basedir=".">
<target name="compile">
</target>
<property name="java" location="src" />
<property name="classes" location="bin/cls" />
<property name="result" location="bin/jar" />
<property name="lib" location="lib" />
<property name="tools" location="tools" />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
<jflex file="lexer.jflex" destdir="${java}" />
<cup srcfile="parser.cup" destdir="${java}"
parser="Parser"
interface="true"
locations="true"
debugsymbols="true" />
</target>
<path id="libraries">
<files includes="${lib}/java-cup-11b-runtime.jar" />
</path>
<target name="compile" depends="generate">
<mkdir dir="${classes}"/>
<mkdir dir="${result}"/>
<javac srcdir="${java}" destdir="${classes}">
<classpath refid="libraries" />
</javac>
</target>
<target name="clean">
<delete file="${java}/Parser.java" />
<delete file="${java}/sym.java" />
<delete file="${java}/Scanner.java" />
<delete dir="${classes}" />
<delete dir="${result}" />
</target>
</project>
\ No newline at end of file
my lexer.
\ No newline at end of file
package de.in.tum.www2.cup.internal;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.ComplexSymbolFactory.Location;
import java_cup.runtime.Symbol;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.ErrorManager;
import de.in.tum.www2.cup.ErrorSource;
import java.lang.Error;
import java.io.InputStreamReader;
%%
%class Lexer
%implements sym
%public
%unicode
%line
%column
%cup
%char
%{
private ErrorManager errMan;
public Lexer(ComplexSymbolFactory sf, java.io.InputStream is){
this(is);
symbolFactory = sf;
}
public Lexer(ComplexSymbolFactory sf, java.io.Reader reader){
this(reader);
symbolFactory = sf;
}
private StringBuffer sb;
private ComplexSymbolFactory symbolFactory;
private int csline,cscolumn;
public Symbol symbol(String name, int code){
return symbolFactory.newSymbol(name, code,
new Location(yyline+1,yycolumn+1, yychar), // -yylength()
new Location(yyline+1,yycolumn+yylength(), yychar+yylength())
);
}
public Symbol symbol(String name, int code, String lexem){
return symbolFactory.newSymbol(name, code,
new Location(yyline+1, yycolumn +1, yychar),
new Location(yyline+1,yycolumn+yylength(), yychar+yylength()), lexem);
}
protected void emit_warning(String message){
System.out.println("scanner warning: " + message + " at : 2 +
(yyline+1) + " " + (yycolumn+1) + " " + yychar);
}
protected void emit_error(String message){
System.out.println("scanner error: " + message + " at : 2 +
(yyline+1) + " " + (yycolumn+1) + " " + yychar);
}
%}
Newline = \r | \n | \r\n
Whitespace = [ \t\f] | {Newline}
/* comments */
Comment = {TraditionalComment} | {EndOfLineComment}
TraditionalComment = "/*" {CommentContent} \*+ "/"
EndOfLineComment = "//" [^\r\n]* {Newline}
CommentContent = ( [^*] | \*+[^*/] )*
ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
%eofval{
return symbolFactory.newSymbol("EOF",sym.EOF);
%eofval}
%state CODESEG
%%
<YYINITIAL> {
{Whitespace} { }
"my" { return symbol("MYTERMINAL",MYTERMINAL); }
"other" { return symbol("OTHERTERMINAL",OTHERTERMINAL); }
}
<CODESEG> {
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn),new Location(yyline+1,yycolumn+1+yylength()), sb.toString()); }
.|\n { sb.append(yytext()); }
}
// error fallback
.|\n { emit_warning("Unrecognized character '" +yytext()+"' -- ignored"); }
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