From: <ega...@us...> - 2003-06-24 22:34:42
|
Update of /cvsroot/jrman/drafts/javacc In directory sc8-pr-cvs1:/tmp/cvs-serv24456/javacc Added Files: SLParser.jj Log Message: Added javacc SLParser --- NEW FILE: SLParser.jj --- /* SLParser.jj Copyright (C) 2003 Elmer Garduno Hernandez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ options { LOOKAHEAD = 1; JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(SLParser) import java.io.FileInputStream; import java.io.IOException; public class SLParser { public static void main(String args[]) throws ParseException, IOException { if (args.length == 0) { SLParser parser = new SLParser(System.in); parser.compilationUnit(); } else if (args.length == 1) { String filename = args[0]; SLParser parser = new SLParser(new FileInputStream(filename)); parser.compilationUnit(); } } } PARSER_END(SLParser) /* WHITE SPACE */ SKIP : { " " | "\t" | "\n" | "\r" | "\f" } /* COMMENTS */ MORE : { "//" : IN_SINGLE_LINE_COMMENT | "/*" : IN_MULTI_LINE_COMMENT } <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN : { <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT } <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN : { <MULTI_LINE_COMMENT: "*/" > : DEFAULT } <IN_SINGLE_LINE_COMMENT,IN_MULTI_LINE_COMMENT> MORE : { < ~[] > } /* RESERVED WORDS AND LITERALS */ TOKEN : { < LIGHT: "light" > | < SURFACE: "surface" > | < VOLUME: "volume" > | < DISPLACEMENT: "displacement" > | < IMAGER: "imager" > | < FLOAT: "float" > | < STRING: "string" > | < COLOR: "color" > | < POINT: "point" > | < VECTOR: "vector" > | < NORMAL: "normal" > | < MATRIX: "matrix" > | < VOID: "void" > | < OUTPUT: "output" > | < VARYING: "varying" > | < UNIFORM: "uniform" > | < TEXTURE: "texture" > | < ENVIRONMENT: "environment" > | < SHADOW: "shadow" > | < RETURN: "return" > | < EXTERN: "extern" > } /* LITERALS */ TOKEN : { < INTEGER_LITERAL: <DECIMAL_LITERAL> (["l","L"])? | <HEX_LITERAL> (["l","L"])? | <OCTAL_LITERAL> (["l","L"])? > | < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > | < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | < #OCTAL_LITERAL: "0" (["0"-"7"])* > | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < CHARACTER_LITERAL: "'" ( (~["'","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) ) "'" > | < STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > } /* IDENTIFIERS */ TOKEN : { < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* > | < #LETTER: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] > | < #DIGIT: [ "\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049" ] > } /* SEPARATORS */ TOKEN : { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE: "{" > | < RBRACE: "}" > | < LBRACKET: "[" > | < RBRACKET: "]" > | < SEMICOLON: ";" > | < COMMA: "," > | < DOT: "." > } /* OPERATORS */ TOKEN : { < PLUS: "+" > | < MINUS: "-" > | < STAR: "*" > | < SLASH: "/" > | < EXP: "^" > | < BANG: "!" > | < ASSIGN: "=" > | < HOOK: "?" > | < PLUSASSIGN: "+=" > | < MINUSASSIGN: "-=" > | < STARASSIGN: "*=" > | < SLASHASSIGN: "/=" > | < COLON: ":" > } void compilationUnit(): {} { definitions() <EOF> } void definitions(): {} { (shaderDefinition() | functionDefinition())+ } void shaderDefinition(): {} { shaderType() identifier() "("formals()")" "{"statements()"}" } void functionDefinition(): {} { [type()] identifier() "("formals()")" "{"statements()"}" } void identifier(): {} { <IDENTIFIER> } void shaderType(): {} { <LIGHT> | <SURFACE> | <VOLUME> | <DISPLACEMENT> | <IMAGER> } void type(): {} { <FLOAT> | <STRING> | <COLOR> | <POINT> | <VECTOR> | <NORMAL> | <MATRIX> | <VOID> } void formals(): {} { formalVariableDefinitions() (";" formalVariableDefinitions() )* } void formalVariableDefinitions(): {} { [outputspec()] typespec() defExpressions() } void outputspec(): {} { <OUTPUT> } void typespec(): {} { [detail()] type() } void detail(): {} { <VARYING> | <UNIFORM> } void defExpressions(): {} { [ defExpression() ("," defExpression() )* ] } void defExpression(): {} { identifier() [defInit()] } void defInit(): {} { "=" expression() } void expression(): {} { primary() /* | expression() binop() expression() | "-" expression() | relation() "?" expression() ":" expression() | typecast() expression()*/ } void primary(): {} { number() | stringconstant() /*| texture()*/ /*| identifier() [arrayindex()] | procedurecall()*/ | assignexpression() /*| triple() | sixteentuple()*/ } void number(): {} { <INTEGER_LITERAL> | <FLOATING_POINT_LITERAL> } void stringconstant(): {} { <STRING_LITERAL> } void texture(): {} { textureType() textureFilename() [chanel()] [textureArguments()] } void textureType(): {} { <TEXTURE> | <ENVIRONMENT> | <SHADOW> } void textureFilename(): {} { expression() } void chanel(): {} { "[" expression() "]" } void textureArguments(): {} { expression() ("," expression() )* } void arrayindex(): {} { "["expression()"]" } void procedurecall(): {} { identifier() "(" procArguments() ")" } void procArguments(): {} { [ expression() ("," expression() )* ] } void assignexpression(): {} { identifier() [arrayindex()] asgnop() expression() } void asgnop(): {} { "=" | "*=" | "/=" | "+=" | "-=" } void triple(): {} { "("expression()","expression()","expression()")" } void sixteentuple(): {} { "("expression()","expression()","expression()","expression() ","expression()","expression()","expression()","expression() ","expression()","expression()","expression()","expression() ","expression()","expression()","expression()","expression()")" } void statements(): {} { (statement())+ } void statement(): {} { variableDefinitions() ";" | assignexpression() ";" /*| procedurecall() ";"*/ | <RETURN> expression() ";" } void variableDefinitions(): {} { [externspec()] typespec() defExpressions() ";" } void externspec(): {} { <EXTERN> } |