home services resume portfolio contact us about me


Return To Portfolio Home


BRE Language Features

  • Fully typed language (integer, boolean, float, string).
  • Supports arrays and sets.
  • Grouping functions (MIN, MAX, SUM, COUNT)
  • Has functions, constants and special group definitions.
  • Can call external functions.
  • Has the For All, For Some, Exists logical predicates
  • Generates portable byte-codes.
  • Local Variables, Recursion supported.
  • Complex String matching capabilities.

BRE Language Samples

The BRE language consists of a series of rule & function definitions. The language is parsed using yacc and compiled into a byte-code representation. The rules are evaluated by executing the bytes codes and checking for a TRUE/FALSE return value. Here are some actual rules from our rule file:

--
-- Returns TRUE if 'str' consists of all letters.
--
function is_alpha(str) is
	str: string;
	for all ch in str
		ch in "abcdefghijklmnopqrstuvwxyz"
			or
		ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


--  The sum of the line items tax fields must equal
--  the header's tax field.
rule cc1 is
	sum(ORDER_LINE_ITEMS.TAX-AMT) = ORDER_HEADER.TAX-AMT

rule 703 using ORDER_LINE_ITEMS is
	if ENTRY-KEY in {" ", "M", "#"} and PURCH-AGREE <> null
		then BT <> null

-- DLR-LINE-TOTAL
-- Changed by Peter Weck to allow for both OP-ORDER-PRICE and
-- DLR-LINE-TOTAL to be zero
rule 857 using ORDER_LINE_ITEMS is
	if ENTRY-KEY in {" ","M","#"} and ORDER_HEADER.TRADE-IC = "T" then
		(OP-ORDER-PRICE > 0.0 and DLR-LINE-TOTAL >= 0.0)
		or (OP-ORDER-PRICE < 0.0 and DLR-LINE-TOTAL <= 0.0)
		or (OP-ORDER-PRICE = 0.0 and DLR-LINE-TOTAL = 0.0)

rule cc19 is
	if (for all li in ORDER_LINE_ITEMS
		li.ENTRY-KEY <> " " or li.HP-GSA = "     ") then
		ORDER_HEADER.COMMERCE-CODE <> "4"
fail with: li.ENTRY-KEY, ORDER_HEADER.COMMERCE-CODE

Byte Code Sample

The following is a disassembly of the byte-codes that were generated for the is_alpha() function. In software a stack based machine is implemented to execute these instructions. This sample occupies only 160 bytes of storage.

00000: ENTRY        S0=1      ; ----- function is_alpha -----
00004: GETFP        S0=-2 
00008: PUSH_I       L0=0 
00016: GETSP        S0=-2 
00020: COUNT_S      
00021: GETSP        S0=-2 
00024: SUB_I        
00025: BRANCH_ZERO  B0=1 L0=152 
00032: GETSP        S0=-2 
00036: GETSP        S0=-2 
00040: FETCH_CHAR   
00041: ASSIGN       B0=1 S0=1 
00046: INCSP        S0=-1 
00050: GETFP        S0=1 
00054: PUSH_S       S0=26 STR0="abcdefghijklmnopqrstuvwxyz" 
00085: IN_SS        
00086: BRANCH_TRUE  B0=0 L0=128 
00092: POP          
00093: GETFP        S0=1 
00096: PUSH_S       S0=26 STR0="ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
00127: IN_SS        
00128: BRANCH_TRUE  B0=1 L0=16 
00136: POP          
00137: POP          
00138: PUSH_I       L0=0 
00144: BRANCH       L0=160 
00152: POP          
00153: POP          
00154: PUSH_I       L0=1 
00160: RETURN       S0=1 

Return To Portfolio Home

compilers • parsers • translators • C++ • yacc &bull lex • bison • unix • windows • eiffel • grammars