Antlr4 saying my rule is mutually left recursive with itself - recursion

I'm working on an assignment where we make a compiler for a simple language and we are using ANTLR4 for Java. After finally getting my grammar working i had to add some Java code to the language parser to build an AST. Here's where i get confused. Antlr is supposed to throw an error if rules are mutually left recursive and as i understand it it happens when one rule references another rule and the second rule reference the first rule. What i don't understand is why antlr is telling me that my rule is mutually left recursive with itself? Here is the error message i keep getting: error(119): PrevParser.g4::: The following sets of rules are mutually left-recursive [expr]. I looked around and noone seems to be having this issue. I did find someone saying that mutually left recursive rules have in common that their first token is another rule so i tried putting a regular . token right before the rule token and now it magically compiles. Why does it do that when the rule is only referencing itself? Heres the bit of code thats causing the issue:
expr returns [AstExpr ast]
: (VOID_CONST {$ast = new AstAtomExpr(loc($VOID_CONST), AstAtomExpr.Type.VOID, $VOID_CONST.text);})
| (INT_CONST {$ast = new AstAtomExpr(loc($INT_CONST), AstAtomExpr.Type.INT, $INT_CONST.text);})
| (CHAR_CONST {$ast = new AstAtomExpr(loc($CHAR_CONST), AstAtomExpr.Type.CHAR, $CHAR_CONST.text);})
| (POINT_CONST {$ast = new AstAtomExpr(loc($POINT_CONST), AstAtomExpr.Type.POINTER, $POINT_CONST.text);})
| (STRING_CONST {$ast = new AstAtomExpr(loc($STRING_CONST), AstAtomExpr.Type.STRING, $STRING_CONST.text);})
| (BOOL_CONST {$ast = new AstAtomExpr(loc($BOOL_CONST), AstAtomExpr.Type.BOOL, $BOOL_CONST.text);})
| (IDENTIFIER {$ast = new AstNameExpr(loc($IDENTIFIER), $IDENTIFIER.text);})
| ( e1=expr O_OKLEPAJ e2=expr O_ZAKLEPAJ {$ast = new AstArrExpr(loc($e1.ast, $O_ZAKLEPAJ), $e1.ast, $e2.ast);} )
;
The error appears in the last line where the rule expr references itself as e1=expr.
If i change the rule to look like this: ( DOT e1=expr O_OKLEPAJ e2=expr O_ZAKLEPAJ {$ast = new AstArrExpr(loc($e1.ast, $O_ZAKLEPAJ), $e1.ast, $e2.ast);} ) the whole thing compiles normally. Does anyone know how i can resolve this issue? Any help is aprecciated.

I've seems this on stackoverflow before (but can't find it anymore). This seems to be a bug that is caused by the parenthesis before the left-recursive expr. Just remove the parenthesis (which are redundant anyway).
So not:
expr returns [AstExpr ast]
: ...
| ( e1=expr O_OKLEPAJ e2=expr O_ZAKLEPAJ {$ast = new AstArrExpr(loc($e1.ast, $O_ZAKLEPAJ), $e1.ast, $e2.ast);} )
;
but this instead:
expr returns [AstExpr ast]
: ...
| e1=expr O_OKLEPAJ e2=expr O_ZAKLEPAJ {$ast = new AstArrExpr(loc($e1.ast, $O_ZAKLEPAJ), $e1.ast, $e2.ast);}
;

Related

Strange behavior with todatetime function

| extend CommandTimeStamp = tostring(customDimensions['CommandTimeStamp'])
| extend originalValue = CommandTimeStamp
| extend constantValue = "11/16/2021 6:04:17 AM +00:00"
| project originalValue, constantValue, equals = (CommandTimeStamp == constantValue), originalTime = CommandTimeStamp, timeColum1 = todatetime(constantValue), timeColum2 = todatetime(CommandTimeStamp)
Get Result:
The last column is empty. It is strange.
Can someone explain it? It blocks us a lot.
the list of supported datetime formats is available here: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/datetime
the format you're using isn't included in that list, and you may want to first manipulate it in the origin, or using query functions, prior to casting it using todatetime()
the fact that casting the constant string literal works is because it's handled in a separate code path, that (currently) happens to support undocumented formats.

So, a mutant escaped. Now what?

I've just managed to get mutation testing working for the first time. My usual testing framework is Codeception but as of writing, it is not compatible with mutation testing (although I believe work is being done on it and it's not far off). I'm using PHPUnit and Infection, neither of which seem easy to work out how to use.
My test suite generated ten mutants. Nine were killed and one escaped. However, I don't know what part of the code or the tests needs to be improved to kill the final mutant.
How do you get information about what code allowed the mutant to escape?
I found in this blog what I couldn't find in Infection's documentation: the results are saved in infection.log.
The log file looks like this:
Escaped mutants:
================
1) <full-path-to-source-file>.php:7 [M] ProtectedVisibility
--- Original
+++ New
## ##
use stdClass;
trait HiddenValue
{
- protected function hidden_value($name = null, $value = null)
+ private function hidden_value($name = null, $value = null)
{
static $data = [];
$keys = array_map(function ($item) {
Timed Out mutants:
==================
Not Covered mutants:
====================
It says that the mutation changed the protected visibility to private and that no tests failed as a result. If this is important, I can now either change the code or write another test to cover this case.
Now that I've found this, I've searched on the Infection website for infection.log and found --show-mutations or -s which will output escaped mutants to the console while running.

How does the assignment part work in the following line of code in Angular2?

I am learning from the project angular2-rxjs-chat application ong github. In the code here there is a line of code given below:
threads[message.thread.id] = threads[message.thread.id] ||
message.thread;
where threads has earlier been defined on line 29 in the code as shown below:
let threads: {[key: string]: Thread} = {};
The comments in the code states that "store the message's thread in our acuuculator 'threads'. I need a little bit explanation of how does the assignment works on line 31 as on both sides of the assignment operator we have the same thing i.e., threads[message.thread.id]. If the statement on line 31 was like
(threads[message.thread.id] = message.thread;)
then I would explain it as a value is being assigned to a key in the map "threads". But I don't understand the full line.
This means if threads[message.thread.id] already has a value then keep it, otherwise set the value to meassage.thread.
If the part before || evaluates to a value that is truthy (not null, undefined, false, ...)then the part after||is not evaluated and the result from the part before||is returned otherwise the result from the expression after||` is returned.
You could also write it as
if(!threads[message.thread.id]) {
threads[message.thread.id] = message.thread;
}

How to declare and initialize integer variable in Decision Table?

I want to declare and initialize integer variable in Decision Table. I created a sample rule in .drl file. It's working fine but i want that rule in drool spreadsheet. Anybody know How to do it?
Sample Rule code.
rule "GoodBye1"
salience 5
when
a : Message(count == 45)
then
System.out.println("-----------------");
int temp = a.getTemplatesFromDba("123");
System.out.println("-Raj--> "+temp);
a.setPriority(temp);
update(a);
end
You'll have to write it in to the Action part of your decision table. Here's one way to do it with a decision table. What suites best for your needs requires a bit more info on the details.
Condition | Action
a : Message |
$param | a.setPrio( a.getTemplate( $param) ); update(a);
--------------------------
count == 45 | "123"
If you need, you can add the System.out.prinln calls in the Action block as well. If you have a lot of operations to execute, it might be better to create a helper function for that.

UDK "Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'"

Upon compiling, I am getting the following error:
C:\UDK\UDK-2010-03\Development\Src\FixIt\Classes\ZInteraction.uc(41) : Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'
Line 41 is the following:
GetSceneClient().OpenMenu("ZInterface.ZNLGWindow");
But when I search for OpenMenu, I find that it is indeed defined in GameUISceneClient.uc of the UDK:
Line 1507: exec function OpenMenu( string MenuPath, optional int PlayerIndex=INDEX_NONE )
It looks like I have everything correct. So what's wrong? Why can't it find the OpenMenu function?
From the wiki page on Legacy:Exec Function:
Exec Functions are functions that a player or user can execute by typing its name in the console. Basically, they provide a way to define new console commands in UnrealScript code.
Okay, so OpenMenu has been converted to a console command. Great. But still, how do I execute it in code? The page doesn't say!
More searching revealed this odd documentation page, which contains the answer:
Now then, there is also a function
within class Console called 'bool
ConsoleCommand(coerce string s)'. to
call your exec'd function,
'myFunction' from code, you type:
* bool isFunctionThere; //optional
isFunctionThere = ConsoleCommand("myFunction myArgument");
So, I replaced my line with the following:
GetSceneClient().ConsoleCommand("OpenMenu ZInterface.ZNLGWindow");
Now this causes another error which I covered in my other question+answer a few minutes ago. But that's it!
Not sure if this is your intent, but if you are trying to create a UIScene based on an Archetype that has been created in the UI Editor, you want to do something like this:
UIScene openedScene;
UIScene mySceneArchetype;
mySceneArchetype = UIScene'Package.Scene';
GameSceneClient = class'UIRoot'.static.GetSceneClient();
//Open the Scene
if( GameSceneClient != none && MySceneArchetype != none )
{
GameSceneClient.OpenScene(mySceneArchetype,LocalPlayer(PlayerOwner.Player), openedScene);
}

Resources