Saturday, February 12, 2011

Javacc LOOKAHEAD - Lvalue in MiniJava

Sometimes you need to break a choice conflict out into a new function in order to
eliminate the choice conflict.

Choice conflict in [...] construct at line 298, column 5.
Expansion nested within construct and expansion following construct
have common prefixes, one of which is: "."
Consider using a lookahead of 2 or more for nested expansion.

This Grammar:
Factor -> ('-'|'!') Factor
| Lvalue ['.' "length" '(' ')' | '(' [Args] ')']
| '(' Expr ')'
| Literal

Lvalue -> ["this" '.'] {'[' Expr ']' | '.' }


Had to be expanded to :

Exp Factor(): {}
{
("-"|"!") Factor()
| Lvalue() ["." "length" "(" ")" | "(" [Args()] ")"]
| "(" Expr() ")"
| Literal()
}


//Lvalue -> ["this" '.'] {LvalueLower}
Exp Lvalue(): {}
{
["this" "."]
[ LOOKAHEAD(2) LvalueLower()]
}

// LvalueLower -> '[' Expr ']' | '.'
void LvalueLower():{}
{
"." | "[" Expr() "]"
}

https://bitbucket.org/aaron_skomra/minijava2/src/af557e14135e/proj3/parser/miniParser.jj

Thursday, October 21, 2010

error: invalid operands of types ‘const char

code.cpp:126: error: invalid operands of types ‘const char [5]’ and ‘const char [2]’ to binary ‘operator+’

message = string("DATA" + "\n");

to

message = string("DATA\n");

Thursday, September 23, 2010

tar

Making a tar file (from http://web.cecs.pdx.edu/~suhui/classes/cs201/inst-submit.html)


Below is an example that creates a tar file for email submission. Assume that your CS login name is "john". First, you will create the directory "john-A1" (say, under /u/john/cs201) and copy all the files and directories to be submitted into the directory /u/john/cs201/john-A1/. Below shows a screen shot of making the tar ball, assuming that you've created the directory for submission in /u/john/cs201/john-A1 and you are at /u/john/cs201/.

/u/john/cs201/> ls john-A1/
Makefile test.c typescript
/u/john/cs201/> tar cvf john-A1.tar john-A1/*
john-A1/Makefile
john-A1/test.c
john-A1/typescript
/u/john/cs201/> ls -l john-A1.tar
-rw------- 1 john them 10240 Mar 31 10:00 john-A1.tar

Related commands:

1. To verify the content of a tar file, say "john-A1.tar", do the following:
tar tvf john-A1.tar
Note this command does not extract files from john-A1.tar, but rather it shows what're inside it. This is very useful before you actually extract a tar file.
2. To untar a tar file, say "john-A1.tar", do the following:
tar xvf john-A1.tar
This will create the directory "john" with all the files that are inside it. Warning: whatever files and directories in john-A1.tar will overwrite existing ones with the same names. To test this command, it's better that you do it under a temporary directory so that you don't overwrite anything by accident.

Saturday, June 19, 2010

here document

(Because the document is right
here in the source code rather than in an external file.)

The Ruby Programming Language, 1st Edition p 51

Tuesday, June 15, 2010

c++ ** stack smashing detected ***

http://ubuntuforums.org/archive/index.php/t-352672.html

changed

char wordFromFile[36];

to

char wordFromFile[256];

to make it work

I think the stack smashing was detected only after the function returned, not when the stack was actually getting smashed.

Thursday, June 3, 2010

unix utils

ldd a.out
strace

Sunday, May 30, 2010

moving pointers around

if(*(*(args->arg_array+i)+1) == '\0'){
args->rdfilename[0] = (args->arg_array[i+1]); // point to the filename
}
// if the next character is a character make that character the start of the filename
else{
args->rdfilename[0] = (*(args->arg_array+i)+1);// point to the filename
//not args->rdfilename[0] = *(*(args->arg_array+i)+1);

// **(args->arg_array+i) = '\0'; // remove the < // I deleted the < but the pointer is still pointing to its slot

Saturday, May 29, 2010

ld.so.1: sh.out: fatal: relocation error: R_SPARC_JMP_SLOT: unidentifiable procedure reference: link-map 0xff3f7368, offset 0x49, called from 0x10ed0

ld.so.1: sh.out: fatal: relocation error: R_SPARC_JMP_SLOT: unidentifiable procedure reference: link-map 0xff3f7368, offset 0x49, called from 0x10ed0

Tuesday, May 25, 2010

-lpthread: linker input file unused because linking not done

gcc: -lpthread: linker input file unused because linking not done
gcc: -lrt: linker input file unused because linking not done

I got this error/warning when I put the -lpthread in my general flags macro.
It should only be on the final (top level) linking.

Friday, May 14, 2010

passing arg 3 of `pthread_create' from incompatible pointer type

http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_create.3.html

[Switching to LWP 2]

mutex problem?

Saturday, August 8, 2009

Memory Problem

new char[strlen(vertex_name+1)];

Saturday, August 1, 2009

No rule to make target `preprocessing'

Makefile.win
[Build Error] No rule to make target `preprocessing', needed by `bst.o'. Stop.

#inclue "bst.h"

Wednesday, July 29, 2009

undeclared (first use this function)

undeclared (first use this function)

used the same varaible name for two things - a variable and a struct

phone_number->number = phone_number

Tuesday, July 28, 2009

semicolon missing after declaration of `

semicolon missing after declaration of `

i actually forgot the semicolon after the class declaration

Monday, July 27, 2009

(first use this function)

`xxx' undeclared (first use this function)

happens when you forget to use the scope resolution operator to identify a function as a member of a class

calling type like a method c++

struct contact_node
{
char * first_name;
char * last_name;
int phone_number;
char * address;
char * email;
int fax_number;
call_list calls_made;
contact_node * next;
};

trying to call member function through the type (call list) instead of through the variable (calls_made)

array of lists c++

i tried to use a pointer to a pointer, which was not needed

call_node * call_array[367];

not

call_node ** call_array[367];

Monday, July 20, 2009

writing in the calling routine's memory

?// write in the calling routine's memory (pass by reference) to say
?// here is the data I just got that was at the front

http://bytes.com/groups/cpp/163953-pass-reference-vs-pass-pointer

> Aside from the NULL PTR safety of the reference version, is there a
> performance advantage in the way the function and parameters are
> placed/copied onto the stack for either version?

No, but I can imagine the reference version to be easier to optimize (because
no analysis is needed to check what the reference refers to in each
statement), so it might be that it's better optimized with some compilers.

However, the NULL pointer safety is important, and there are other
non-efficiency related issues.

One particularly important such issue is that the reference cannot be
re-seated within the function. Another is that arithmetic cannot be performed
on the reference, only on the object it refers to (think of e.g. a std::string
argument). A third is that the reference signature clearly indicates a single
object, whereas the pointer signature matches object or array or null.

Sunday, July 19, 2009

erminating

error code using Dev C++:

No rule to make target `erminating', needed by `main.o'. Stop.

This happened because I had a stray apostrophe character : " ' "