Update of /cvsroot/bprocessor/bscript/src/etc
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9471/src/etc
Modified Files:
bscript.g
Log Message:
Improved scripting
Index: bscript.g
===================================================================
RCS file: /cvsroot/bprocessor/bscript/src/etc/bscript.g,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** bscript.g 14 Sep 2006 09:21:46 -0000 1.7
--- bscript.g 17 Sep 2006 17:29:21 -0000 1.8
***************
*** 25,30 ****
Comma : ',' ;
Bar : '|' ;
! Open : '<' ;
! Close : '>' ;
protected Letter
--- 25,33 ----
Comma : ',' ;
Bar : '|' ;
! Lt : '<' ;
! Gt : '>' ;
! Equal: '=' ;
! LtEq: "<=" ;
! GtEq: ">=" ;
protected Letter
***************
*** 88,91 ****
--- 91,106 ----
statement[Function env]
+ : procedurecall[env]
+ | ifstatement[env]
+ | whilestatement[env]
+ | assignment[env]
+ ;
+
+ assignment[Function env]
+ : name:Identifier Equal simpleton[env]
+ { env.append(new Assign(name.getText())); }
+ ;
+
+ procedurecall[Function env]
: name:Identifier { env.append(new Mark()); }
( simpleton[env] )*
***************
*** 93,104 ****
;
simpleton[Function env]
: variable[env]
| literal[env]
| StartTerm expression[env] EndTerm
! | Open statement[env] Close
;
expression[Function env]
: term[env]
( Plus term[env] { env.append(new Primitive(Primitive.ADD)); }
--- 108,173 ----
;
+ whilestatement[Function env]
+ : { BranchFalse branchend = new BranchFalse();
+ int before = env.length();
+ }
+ "while" expression[env]
+ { env.append(branchend); }
+ "do" ( statement[env] End ) * "end"
+ { int after = env.length();
+ Branch branch = new Branch(before - after);
+ env.append(branch);
+ branchend.setOffset(after - before + 1);
+ }
+ ;
+
+
+ ifstatement[Function env]
+ : { BranchFalse branchelse = new BranchFalse(); }
+ "if" expression[env] "then"
+ { int before = env.length();
+ env.append(branchelse);
+ }
+ ( statement[env] End) *
+
+ ( "end"
+ { int after = env.length();
+ branchelse.setOffset(after - before);
+ }
+ | { Branch branchend = new Branch();
+ int beforeelse = env.length();
+ env.append(branchend);
+ branchelse.setOffset(beforeelse - before + 1);
+ }
+ "else"
+ ( statement[env] End) *
+ "end"
+ {
+ int afterelse = env.length();
+ branchend.setOffset(afterelse - beforeelse);
+ }
+ )
+ ;
+
simpleton[Function env]
: variable[env]
| literal[env]
| StartTerm expression[env] EndTerm
! | Lt statement[env] Gt
;
+
expression[Function env]
+ : evaluation[env]
+ ( Equal evaluation[env] { env.append(new Primitive(Primitive.EQ)); }
+ | Lt evaluation[env] { env.append(new Primitive(Primitive.LT)); }
+ | Gt evaluation[env] { env.append(new Primitive(Primitive.GT)); }
+ ) ?
+
+ ;
+
+
+
+ evaluation[Function env]
: term[env]
( Plus term[env] { env.append(new Primitive(Primitive.ADD)); }
|