pyparsing: parsing nested C-style comments verbatim - pyparsing

I'm working on a parser/code transformer for a simple command language (Visual TrueType). It uses C-style comments, but accepts nesting them. pyparsing.cStyleComment chokes on that, so I'm looking for something else.
Input looks like (note that everything is commented out):
/* VTTTalk glyph 1023, char 0xffff */
/* GUI generated Tue Jul 08 15:52:37 2014 */
/* Y direction
YAnchor(255)
YDist(305,433,>=)
[...]
/* X direction */
Smooth()
*/
I'd like to get the following parsed output with spacing/newlines inside the comments intact:
["/* VTTTalk glyph 1023, char 0xffff */",
"/* GUI generated Tue Jul 08 15:52:37 2014 */",
"/* Y direction\nYAnchor(255)\nYDist(305,433,>=)\n[...]\n\n/* X direction */\n\nSmooth()\n*/"]
So far, I can at least keep the general structure with nestedExpr(opener="/*", closer="*/") and attach a parse action that (recursively) generates a C-style comment string, but that loses the comment's formatting. Is there a canonical way to do it?

Related

Program not working for IAR EW for msp430

the #include isnt blue like it is in my lab manual for my class. I dont know if this is the issue or not. I have just installed the software according to the dirrections and restarted 3 times and I havent found any answers online
enter image description here
The format of an Assembly source line for the IAR Assembler is as follows:
[label [:]] [operation] [operands] [; comment ]
where the components are as follows:
label: A definition of a label, which is a symbol that represents an address. If the label starts in the first column - that is, at the far left on the line. The : (colon) is optional.
operation: An assembler instruction or directive. This must not start in the first column - there must be at least one (whitespace) or a → (TAB) character prior it.
operands: An assembler instruction or directive can have from zero up to several operands. The operands are separated by , (commas) or (whitespaces).
comment: Comment, preceded by a ; (semicolon) -or- by a C/C++ comment styles (/* ... */ or //).

/usr/bin/time file inputs / outputs

I'm struggling to find any detailed information about exactly what the various outputs of /usr/bin/time -v mean. Namely I'm confused about the meaning of file inputs / outputs.
If anyone has some experience with '/usr/bin/time' I'dd be grateful if you could straighten this out for me.
What is your OS, is it linux of BSD?
There is some description of fields in man page of time utility (section 1), for example in Linux: http://man7.org/linux/man-pages/man1/time.1.html
But time itself uses some interface to kernel to get the information, probably wait3 / wait4 http://man7.org/linux/man-pages/man2/wait3.2.html
Data printed in time -v is from struct rusage which is described in getrusage(2) man page: Linux http://man7.org/linux/man-pages/man2/getrusage.2.html
Linux have many fields in rusage, but not all fields are used:
The resource usages are returned in the structure pointed to by
usage, which has the following form:
struct rusage {
struct timeval ru_utime; /* user CPU time used */
struct timeval ru_stime; /* system CPU time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims (soft page faults) */
long ru_majflt; /* page faults (hard page faults) */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* IPC messages sent */
long ru_msgrcv; /* IPC messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
The http://man7.org/linux/man-pages/man2/getrusage.2.html also give some description and mark unmaintained fields:
ru_utime
ru_stime
ru_maxrss (since Linux 2.6.32)
ru_ixrss (unmaintained)
ru_idrss (unmaintained)
ru_isrss (unmaintained)
ru_minflt
ru_majflt
ru_nswap (unmaintained)
ru_inblock (since Linux 2.6.22)
The number of times the filesystem had to perform input.
ru_oublock (since Linux 2.6.22)
The number of times the filesystem had to perform output.
ru_msgsnd (unmaintained)
ru_msgrcv (unmaintained)
ru_nsignals (unmaintained)
ru_nvcsw (since Linux 2.6)
ru_nivcsw (since Linux 2.6)
POSIX 2004 have no exact list to implement, so it is implementation-specific http://pubs.opengroup.org/onlinepubs/009695399/functions/getrusage.html
The header shall define the rusage structure that includes at least the following members:
struct timeval ru_utime User time used.
struct timeval ru_stime System time used.

running COBOL program error - mfcobol, CALL ... RETURNING

i got a problem with simple cobol call - returning test program.
I am using micro focus cobol.
here are my 2 codes.
***************** CALLING PROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. callreturning.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VA PIC S9(8) USAGE DISPLAY.
01 VB PIC S9(8) USAGE DISPLAY.
01 VC PIC 9(4) USAGE DISPLAY value 0.
PROCEDURE DIVISION.
MOVE 1 TO VA.
MOVE 2 TO VB.
move 3 to VC.
CALL "add_two" USING VA VB returning VC.
* DISPLAY VA VB VC.
EXIT PROGRAM.
END PROGRAM callreturning.
*********CALLED PROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. add_two.
ENVIRONMENT DIVISION.
DATA DIVISION.
LINKAGE SECTION.
01 PARM_A PIC S9(8) USAGE DISPLAY.
01 PARM_B PIC S9(8) USAGE DISPLAY.
01 PARM_C PIC 9(4) USAGE DISPLAY value 0.
PROCEDURE DIVISION USING PARM_A PARM_B returning PARM_C.
move 3 to PARM_C.
* ADD PARM_A TO PARM_B GIVING PARM_C.
goback.
END PROGRAM add_two.
CALLING program simply calls the second program with using returing value.
But when i compile both program and run, error happens.
error code: 114, pc=0, call=1, seg=0
114 Attempt to access item beyond bounds of memory (Signal 11)
Did i make a wrong code? or other problem? please help me :)
I am testing 'RETURNING' phrase
Your program compiles and works just fine if you get rid of the returning statement.
Background
01 levels defined in the linkage section are more like pointers in a C program. For normal parameters they are set by the calling program. But returning parameters will be unassigned.
The error is probably caused by trying to use an unallocated pointer.
Solution
Do not use returning as it is for working with languages like java.
Allocate storage to the return-value before using it.
See:
Microfocus Manual, Look at the returning example
IBM Manual Look at the Returning Phrase Section
Finally, returning is for working with java. Anything "type" defined on returning should be java compatible (i.e. binary-long and not 9(4)). I strongly suggest not using Returning in Cobol unless you are calling other languages.
Old Question, so i try a short Answer:
First, there is nothing wrong with using returning in MF-COBOL.
So, this is native COBOL (NetExpress as IDE, i assume). To correct ist just change the second Program:
Move PARM_C from the linkage to the working-storage section
The Procedure Division doesn't get the returning Phrase in its opening declaration. Move it instead to the goback phrase:
PROCEDURE DIVISION USING PARM_A PARM_B.
*>...
goback returning PARM_C.

Newline while writing a text file in Ada

I am opening a text file in Ada with the following code:
Open (File => out_parcial_variante1, Name => "c.txt", Mode => append_file);
put(File => out_parcial_variante1, Item=> "r");
close(out_parcial_variante1);
The file as a structure like this inside:
01 #510.00:1003.00,512.04:1110.00,515.00:998.00,-98.00,-100.00
<second empty line, this text is not in the file>
Note that besides the initial line the cursor is in a second line there with nothing written.
Whenever my code writes in the file, this happens:
01 #510.00:1003.00,512.04:1110.00,515.00:998.00,-98.00,-100.00
r
It creates another newline instead of appending on the 2nd line like this:
01 #510.00:1003.00,512.04:1110.00,515.00:998.00,-98.00,-100.00
r
How do I fix this?
EDIT: It's a pointer problem since I read the whole line before, but I try to close and open the file again and the pointer remains in the second line instead of going back to the beginning.
I threw together a quick test program with GNAT 2012 on Windows and it works as expected.
Code:
with Ada.Text_IO;
use Ada.Text_IO;
procedure Append_Test is
OPV: File_Type;
begin
Open (OPV, Append_File, "c.txt");
Put (OPV, "r");
Close (OPV);
end Append_Test;
I programmatically created the c.txt file, using Put_Line to output the text, this was the contents of the file:
01 #510.00:1003.00,512.04:1110.00,515.00:998.00,-98.00,-100.00
I used Cygwin's od -t x1 to dump the file, and saw that it terminated with a 0d 0a EOL sequence, i.e. CR/LF.
Running the above code resulted in a file containing the expected output:
01 #510.00:1003.00,512.04:1110.00,515.00:998.00,-98.00,-100.00
r
Again dumping with od showed the file ending with 0d 0a 72 0d 0a. That's the original EOL, to which is appended the 'r' and another EOL.
If this isn't happening for you, then it's not clear what you're actually doing. (Note that on Linux the 0d 0a sequences would instead be simply 0a.)

Displaying unicode string using opengl, qt and freetype

I want to display text in OGL using FTGL(wrapper for FreeType2) in Qt. I have problem with unicode->FTGL must have charcode of actually rendering char, to get glyph from truetype font, which is problematic when this char is for example one of: 'Zażółć gęślą jaźń'.
Do you have any ideas, why this code:
const unsigned char *string=(const unsigned char*)"POCZUJ GĘŚLĄ JAŹŃ";
// for multibyte - we can't rely on sizeof(T) == character
FTUnicodeStringItr<T> ustr(string);
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
{
unsigned int thisChar = *ustr++;
unsigned int nextChar = *ustr;
if(CheckGlyph(thisChar))
{
position += glyphList->Render(thisChar, nextChar,
position, renderMode);
}
}
works in Visual, but in Qt doesn't(it doesn't get proper charcodes, so it displays brackets)?
FTUnicodeStringItr template looks like this: http://www.nopaste.pl/11xt
Thanks.
The problem you're running into is, that C/C++ don't really support Unicode/wide characters in the source code. To be done properly you'd have to specify unicode characters either by \uXXXX escape sequences (if the compiler supports these), or by \xXX\xXX sequences building the code points from scratch. Visual C++ has wide character support (for the simple reason that all string manipulation in Windows is done in wide characters – don't confuse that with Unicode code points!).
I suggest you do the following: Qt has internationalization support built in. It boils down to define strings through the tr(...) helper function/macro with default language, i.e. english strings. Qt Linguist can then is used to create substitution rules, that are applied through the usage of tr(...) and does this with full Unicode support.

Resources