2010/05/09

Fixed Memo on Narwhal #2

Narwhal v.0.2 is released. I updated to the version.

Other found bugs are the following:

The ' " ' rule cannot be compiled as C language
Compiling a parser generated from the grammar that contains rules with double-quote (") fails because generated string literals are not enclosed by " well. For example, the rule ' " ' is generated as L" " ". Furthermore, ' \" ' and " \" " are generated as L" \\" ". I could not escape the double quote.
Escaped character cannot match input.
For example, the '\n' rule, which consists of a single character, cannot match an input single character '\n' in the S macro, because the print_escape function generated the rule as the two characters "\n".
If it is necessary to escape the rule for C language, input characters should be necessary to be escaped or the rule should be restored before matching.
When I tried to escape such characters in input_buffer_read_char, it seems the characters became matched (but, it is not enough tested ).

because my multi-line testing grammar did not work well, I debugged it. But, perhaps because Narwhal's example calculator is single-line, the bugs might be hard to find before. I found the Narwhal's source code is clear and simple C, which is easy to fix. Although I did not provide my fixed code because it contains my customization (it is maybe unnecessary for others), information I think helpful for others was reported to the Narwhal project .

Other local customization

  • trace dump is added. It is available if the prefix_debug is not zero.
  • Generated time stamp is removed because it is detected as difference.
  • other tribal modifications

2010/05/07

Fixed Memo on Narwhal

I changed the following:

Customization

  • BUF_LEN in c_generator.c was changed to 4096 because stack overflow occurs on generating parser.
  • Preprocessor condition on swprintf's parameter was added to generated parser because the warning 4706 occurred and it causes the access violation at runtime.

Fixed Bugs?

  • It is necessary to escape double quote (") in print_escape function because it causes such compile errors as C2308, C2001, and C1057 during compiling the generated parser, if grammar includes double quote.
  • Generated str_dup and wcs_dup functions became 'static' because compile errors on multiple definition occurred during compiling the generated parser if there are two or more parsers in a program.
  • Order of the following expressions in c_generator.c was swapped because the warning 4702 occurred when compiling the generated parser.
    ib->buf_size -= INPUT_BUFFER_SIZE_INCREMENT;\n"
    return WEOF;\n"
  • Type of 'eol_pos' of find_line_endings generated by print_utility_source function at c_generator.c was fixed to int because the warning 4244 occurred during compiling the generated parser.
  • The local variable 'n' of find_line function generated by the print_utility_source function became initialized as -1 because the warning 4701 occurred during compiling the generated parser.

Note

  • I set compiler option to suppress the warning 4706 and 4100 during compiling the generated parser.

2010/05/05

Narwhal Parser Generator

I am trying other parser, Narwhal.
  • The parser is provided under BSD-style license.
  • The parser uses not BNF but Parsing Expression Grammer (PEG).
  • The parser (and PEG) is not LALR/LL and does not separate lexical analyzer and syntax analyzer.
  • The parser uses wchar_t.
  • The parser generated C source code.
  • The parser builds a syntax tree without user-defined closures and procedures.
Tthe official binary version 0.1 depends on VC8 or later because generated source code uses fopen_s of Secure C Library proposed by Microsoft. But, such dependency was fixed in the version 0.1.2 provided as source code only. Thus, I use the version 0.1.2.
However, there was other issue to use with VC7.1. Although source code generated by the version 0.1.2 can build an execution module, the module caused access violation at parsing. When I debug it, I found that the access violation occurs in swprintf. Its cause was mismatch of function parameters.

Difference of swprinf sigunature between VC8 and VC7.1

In ISO/IEC9899:1999 (C99), the second argument of swprintf is size of the buffer in the first parameter, but in old C library of VC7.1 not supporting the C99, such size parameter did not exist, which causes the access violation.
Furthermore, in not C but C++ of VC7.1, the second parameter is supported because standard C++ refers to the version C99 explicitly and requires the compatible library with C99. So, implementation of VC7.1 uses #ifdef __cplusplus. As, the parser generates source code in not C++ but C, the access violation occurred.
On the other hand, in VC9, there is not such problem because the second parameter of swprintf has been supported.

How to set parameters to debugging program on Visual Studio 2019 with CMake

Solution: MSDN Sometimes the "Debug and Launch Settings for CMake" bottun is disabled. In this case, change to the target view. ...