My download complains about unreachable Functioncall.
I have ignored that warning, but you might be on something with it since function calls are the ones who could not be processed with compiled grammar loaded into Lazarus Gold Engine. It looks like engine is more rigorous then Gold Test Window, since you can see from the screenshot that Gold Tester successfully parsed the code with given grammar.
For pascal itself, there is fcl-passrc.
This time I am not that much interested in parsing Pascal it self. I am just investigating how much effort would be to parse Pascal like FCL - an IEC 61131-7 fuzzy logic extension to ST (Structured Text) used for example in PLCs (programmable logic controllers) for industrial automation, or even games AI (with FCL compiler which generates source code as it's output). Since FCL function blocks are small, I do not need speed of a hand crafted or plex/pyacc parser - so Gold sounded pretty attractive.
https://en.wikipedia.org/wiki/Fuzzy_Control_LanguageHere are some simple FCL examples:
function_block Test
var_input
Light : Real [lux];
end_var
var_output
Switch : Nominal (On, Off);
end_var
fuzzify Light
term Dark := ( 100 lux, 1)( 1000 lux, 0);
term Twilight := ( 500 lux, 0)( 1000 lux, 1)(15000 lux, 1)(20000 lux, 0);
term Bright := (10000 lux, 0)(20000 lux, 1);
end_fuzzify
ruleblock Rules
if Light is Dark then Switch is On;
if Light is Bright then Switch is Off;
end_ruleblock
end_function_block
FUNCTION_BLOCK
VAR_INPUT
Our_Health REAL; (* RANGE(0 .. 100) *)
Enemy_Health REAL; (* RANGE(0 .. 100) *)
END_VAR
VAR_OUTPUT
Aggressiveness REAL; (* RANGE(0 .. 4) *)
END_VAR
FUZZIFY Our_Health
TERM Near_Death := (0, 0) (0, 1) (50, 0) ;
TERM Good := (14, 0) (50, 1) (83, 0) ;
TERM Excellent := (50, 0) (100, 1) (100, 0) ;
END_FUZZIFY
FUZZIFY Enemy_Health
TERM Near_Death := (0, 0) (0, 1) (50, 0) ;
TERM Good := (14, 0) (50, 1) (83, 0) ;
TERM Excellent := (50, 0) (100, 1) (100, 0) ;
END_FUZZIFY
FUZZIFY Aggressiveness
TERM Run_Away := 1 ;
TERM Fight_Defensively := 2 ;
TERM All_Out_Attack := 3 ;
END_FUZZIFY
DEFUZZIFY valve
METHOD: MoM;
END_DEFUZZIFY
RULEBLOCK first
AND:MIN;
ACCU:MAX;
RULE 0: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS Fight_Defensively);
RULE 1: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Good) THEN (Aggressiveness IS Run_Away);
RULE 2: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Run_Away);
RULE 3: IF (Our_Health IS Good) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS All_Out_Attack);
RULE 4: IF (Our_Health IS Good) AND (Enemy_Health IS Good) THEN (Aggressiveness IS Fight_Defensively);
RULE 5: IF (Our_Health IS Good) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Fight_Defensively);
RULE 6: IF (Our_Health IS Excellent) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS All_Out_Attack);
RULE 7: IF (Our_Health IS Excellent) AND (Enemy_Health IS Good) THEN (Aggressiveness IS All_Out_Attack);
RULE 8: IF (Our_Health IS Excellent) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Fight_Defensively);
END_RULEBLOCK
END_FUNCTION_BLOCK
Btw. I apologize everyone, since for successful parsing of test code you have to add one 'do' at the end of a 'for' loop line. I will edit my original message to correct just that.