Update of /cvsroot/bprocessor/bscript/src/etc
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv1549/src/etc
Added Files:
bscript.g
Log Message:
Base version
--- NEW FILE: bscript.g ---
header {
package net.sourceforge.bprocessor.model.parser;
import net.sourceforge.bprocessor.model.evaluator.*;
}
class ScriptLexer extends Lexer;
options {
k=2; // needed for newline junk
charVocabulary='\u0000'..'\u007F'; // allow ascii
}
StartTerm: '(' ;
EndTerm: ')' ;
Plus : '+' ;
Minus : '-' ;
Multiply : '*' ;
Divide : '/' ;
Period : '.' ;
End : ';' ;
protected Letter
: Upper | Lower
;
protected Upper
: 'A' .. 'Z'
;
protected Lower
: 'a' .. 'z'
;
protected Digit : '0'..'9' ;
protected Integer : (Digit)+ ;
protected Real : Integer Period Integer ;
Number : (Integer Period Integer) => Real | ( Integer ) => Integer ;
Identifier
: (Letter | '_' ) ( Letter | Digit | '_' )*
;
WhiteSpace
: ( ' '
| '\r' '\n'
| '\n'
| '\t'
)
{$setType(Token.SKIP);}
;
class ScriptParser extends Parser;
program[Function env]
: expression[env] End
;
expression[Function env]
: term[env]
( Plus term[env] { env.append(new Primitive(Primitive.ADD)); }
| Minus term[env] { env.append(new Primitive(Primitive.SUB)); }
)*
;
term[Function env]
: atom[env]
( Multiply atom[env] { env.append(new Primitive(Primitive.MUL)); }
| Divide atom[env] { env.append(new Primitive(Primitive.DIV)); }
)*
;
atom[Function env]
: literal[env]
| variable[env]
| StartTerm expression[env] EndTerm
| unary[env]
;
unary[Function env]
: Plus atom[env]
| Minus atom[env] { env.append(new Primitive(Primitive.NEG)); }
;
literal[Function env]
: n:Number { env.append(new Literal(new Double(n.getText()))); }
;
variable[Function env]
: i:Identifier { env.append(new Variable(i.getText())); }
;
|