I was writing my parser and I am getting an awkward error.
One of my rules is like the following:
operatorTerm[ReadOptions Options, int priority] returns [Term t]
#init
{
int p = priority;
Term t2 = null;
Term t = null;
CompoundTermTag f = null;
}
: {testFY($Options, $priority)}?
a=op[$Options, p] {f = $a.tag;}
b=term[$Options, p] {$t = $b.t; $t = createTerm(f, $t); }
| {testFX($Options, $priority)}?
d=op[$Options, p] {f = $d.tag;}
e=term[$Options, p-1] {$t = $e.t; $t = createTerm(f, $t);}
;
This will throw the following error an using the alias ANTLR4
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 199, Size: 199
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at org.antlr.v4.automata.ATNSerializer.serialize(ATNSerializer.java:201)
at org.antlr.v4.automata.ATNSerializer.getSerialized(ATNSerializer.java:375)
at org.antlr.v4.codegen.model.SerializedATN.<init>(SerializedATN.java:46)
at org.antlr.v4.codegen.model.Parser.<init>(Parser.java:96)
at org.antlr.v4.codegen.ParserFactory.parser(ParserFactory.java:92)
at org.antlr.v4.codegen.OutputModelController.parser(OutputModelController.java:165)
at org.antlr.v4.codegen.OutputModelController.buildParserOutputModel(OutputModelController.java:114)
at org.antlr.v4.codegen.CodeGenerator.generateParser(CodeGenerator.java:169)
at org.antlr.v4.codegen.CodeGenPipeline.process(CodeGenPipeline.java:73)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:422)
at org.antlr.v4.Tool.process(Tool.java:384)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
at org.antlr.v4.Tool.main(Tool.java:190)
Now if I chope off a few lines from the code this would compile. Making this new rule has thrown this exception. Also, If I chope off a few lines from this rule itself the exception won't be thrown.
Is it because the size of my grammar has become very large ?
Unable to figure this error out.
Also, I am experiencing no such error even if I trim off some other independent rule. Is there a limit to the size of a grammar file ?
My grammar file is around 800 lines.
This sounds like a bug in a specific version of the ANTLR 4 tool. You can report bugs to the project issue tracker on GitHub:
https://github.com/antlr/antlr4/issues
Note: I cannot reproduce this issue in the latest source code, which will be available as ANTLR 4.1 released at the end of this month.
I had the same issue, I tried 4.8 and it worked, hope this helps you too.
Related
I'm trying to Skip a line in a Visual C++ managed String^ or String^ array but I haven't found any easy way to do so. In-fact, I've spent two days on something that would take less than 30 seconds in C#. There is a method .Skip() within C# Enumerable
https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.skip?view=netframework-4.7.2
and I'd like something similar for VC++ if possible.
Here's what I've tried:
auto a = gcnew cli::array<String ^>{ "Alpha", "Bravo", "Charlie", "Delta" };
auto xs = gcnew System::Collections::Generic::List<String^>(a);
System::Collections::Generic::IEnumerator<String^>^ e = xs->GetEnumerator();
e->MoveNext();
^^ that throws exception class System::EventArgs has no member "MoveNext"
EDIT: I know what's causing the exception System::EventArgs has no member "MoveNext" .. using ' e ' in Visual Studio causes the compiler to think I'm referring to the e for EventArgs as in e) click_method .. I switched to another name and it populates as this: System.Collections.Generic.List`1+Enumerator[System.String]
I also tried referencing System::Linq and then
System::Collections::Generic::List<String ^>^ _list = gcnew System::Collections::Generic::List<String ^>(System::IO::File::ReadAllLines(filename));
System::Collections::Generic::List<String ^>^ _list2 = _list->Skip(1);
which seems like it would work in C# but get the following exception
class System::Collections::Generic::List has no member skip
so the .NET library doesn't work in CLI / C++
Another thing I attempted was:
System::Collections::Generic::List<String ^>^ _list = gcnew System::Collections::Generic::List<String ^>(System::IO::File::ReadAllLines(filename));
System::Collections::Generic::List<String ^>^ _list2 = _list->RemoveAt(0);
but got exception:
a value of type "void" cannot be used to initialize an entity of type System::Collections::Generic::List^
I'm trying to do it without using marshal_string if possible, but I'm open for any suggestions, as I've been pulling my hair out on this, not sure what else to try =[
EDIT: this reads as an array not a String^ but I couldn't figure out how to do it with a String^ on it's own.
definitely not the quickest way but this skips x number of lines.
I am sick of CLI/C++/VC++ and can't wait to stop using it (I should have never used it in the first place and kick myself daily for not making this in C#).
//read the file to a CLI array (each line is a member)
auto a = System::IO::File::ReadAllLines("test66.txt");
//create a List from the array
auto xs = gcnew System::Collections::Generic::List<String^>(a);
//create a collection from the List
System::Collections::Generic::IEnumerator<String^>^ test66 = xs->GetEnumerator();
//the number of lines we want to skip
int x = 0;
//for loop stopping # x
for (int nxt; nxt <= x; nxt++)
{
test66->MoveNext();
}
//present selected array item to user or you could feed this into a String^
textBox11->Text = test66->Current;
feel free to give a better answer. I couldn't find much information since CLI/C++ is absolutely awful compared to C# and just about every other modern language. (IMO)
I am trying to build a BDD for monotone multiplication and need to use the negation of the input bits.
I am using the following code:
DdNode *x[N], *y[N], *nx[N], *ny[N];
gbm = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); /* Initialize a new BDD manager. */
for(k=0;k<N;k++)
{
x[k] = Cudd_bddNewVar(gbm);
nx[k] = Cudd_Not(x[k]);
y[k] = Cudd_bddNewVar(gbm);
ny[k] = Cudd_Not(y[k]);
}
The error that I am getting is:
cuddGarbageCollect: problem in table 0
dead count != deleted
This problem is often due to a missing call to Cudd_Ref
or to an extra call to Cudd_RecursiveDeref.
See the CUDD Programmer's Guide for additional details.Aborted (core dumped)
The multiplier compiles and runs fine when I am using
x[k] = Cudd_bddNewVar(gbm);
nx[k] = Cudd_bddNewVar(gbm);
y[k] = Cudd_bddNewVar(gbm);
ny[k] = Cudd_bddNewVar(gbm);
What should I do, the manual does not help not truing to ref x[k],nx[k]...
Every BDD node that is not referenced is subject to deletion by any Cudd operation. If you want to make sure that all nodes stored in your array remain valid, you need to Cudd_Ref them immediately after they are returned by CUDD. Hence, you need to correct your code to:
for(k=0;k<N;k++)
{
x[k] = Cudd_bddNewVar(gbm);
Cudd_Ref(x[k]);
nx[k] = Cudd_Not(x[k]);
Cudd_Ref(nx[k]);
y[k] = Cudd_bddNewVar(gbm);
Cudd_Ref(y[k]);
ny[k] = Cudd_Not(y[k]);
Cudd_Ref(yn[k]);
}
Before deallocating the Cudd manager, you then need to dereference the nodes:
for(k=0;k<N;k++)
{
Cudd_RecursiveDeref(gbm,x[k]);
Cudd_RecursiveDeref(gbm,nx[k]);
Cudd_RecursiveDeref(gbm,y[k]);
Cudd_RecursiveDeref(gbm,ny[k]);
}
Note that the fact that your code works when allocating more variables does not show that referencing is not needed. It may simply be that you do not ever use enough nodes for the garbage collector to trigger -- and before that, the problem is not detected.
Recently I use torch7 to run a model, but this mistake occurs frequently, which drives me crazy.
Who can help me?
I'm not familiar with torch7 but I'll refer you to this thread, seems to be the same or similar issue, caused by too small of a dataset.
https://github.com/jcjohnson/torch-rnn/issues/201
When this line is failing in your run:
self.val_left[i] = self.ldata[img_id][{{}, {center_y-self.psz, center_y+self.psz}, {center_x-self.psz, center_x+self.psz}}]
the stack trace tells us that a function in Tensor.c has a failing argument check:
static int torch_Tensor_(__index__)(lua_State *L)
{
...
for(dim = 0; dim < ndims; dim++)
{
...
else if(lua_istable(L, 2))
{
...
THArgCheck((start >= 0) && (start < tensor->size[cdim]), 2, "start index out of bound");
...
}
...
}
}
It is the implementation of the indexing operator with a table argument to narrow and select. It seems, the computed first indices in either one dimension is too big/too small.
Try to print the values of center_y-self.psz and center_x-self.psz to see which one is the culprit and on what end of the interval you exceed the bounds. I cannot give further advice, because I am not familiar with the rest of the code or the data.
sorry for avoiding you guys
i have a problem with reverse function in circular linked list.
void reverse() {
int num = many;
node* current = head;
node* previous = 0;
while (num != 0) {
cout << "1" << '\t';
node* r = previous;
previous = current;
current = current->next;
previous->next = r;
num--;
}
head = previous;
}
in this func after 2 while sentence
problem comes up in line that current = current->next;
(exception throw : read access violation,
current was 0xDDDDDDDD)
how to handle it??
This is from Visual Studio trying to help you (and succeeding, IMO).
As Mark Ingraham pointed out in another answer a long time ago, Visual Studio's runtime library will fill a block of data with 0xDDDDDDDD when you release a block of heap memory.
So, although you haven't shown any code that's deleting from your list, if there is such code, that's probably the first place to look--at least at first glance, it looks like there's a fair chance that when you try erase a node from the list, you're deleting the memory the node lives in, but still leaving a pointer to that deleted memory.
It's also possible (but less likely, IMO) that you're just using memory without initializing it--and you happen to be hitting a block of memory that was previously allocated and then released back to the heap manager.
The bottom line, however, is that you don't "handle" the access violation. Instead, you need to find the bug in your code that's leading to the access violation happening, and fix it so that doesn't happen any more.
I'm programming in visual c++, and I have about 60 pictures (indexed p0...p63). I want to make a loop that goes through all the pictures and change their ImageLocation under some conditions.
I figured the Tag property and one of my attempts was like this:
I tagged my pictures from 0 to 63 and then tried the following:
for(int i=0; i<64; i++)
{
PictureBox->Tag[i]->ImageLocation="possible-.gif";
}
It's not working... I get this error:
syntax error : missing ';' before '->' line: 1514
syntax error : missing ';' before '->' line: 1514
(twice, same line)
What's the right way of doing it?
Thank you!
edit:
OK now I have the pictures in an array. Is there a way to have a common rule for all of them? I want to make a click event for each and every one of the pictures. Is the only way setting a rule for each independently? Or can I set a rule for the array itself by saying something like:
if(Pictureboxes[i]_Clicked)
{
Pictureboxes[i].something = "something else";
}
I found the way to solve it. So I guess I'm gonna answer myself:
I made an array of PictureBoxes:
private: static array<System::Windows::Forms::PictureBox^>^ pictures=(gcnew array<System::Windows::Forms::PictureBox^>(64));
and filled it with the pictures:
pictures[0] = p0;
pictures[1] = p1;
pictures[2] = p2;
...
Then i clicked each of the pictures to create click_events.
In each event i typed this:
int place = (/*pic number*/);
IndexOf(pictures);
This code sends to a function named IndexOf the picture i clicked.
And here is IndexOf():
static System::Void IndexOf(int& place)
{
int flag = 0;
if(pictures[place]->ImageLocation == "possible-.bmp")
{
flag = 1;
/*DO CODE*/
}
if(flag)
/*OTHER CODE*/
}
Now i can do whatever code i want for pictures[i] at /do code/ above.