in reply to C-like structures parsing and validation

Feels like an opportunity to use Inline::C.

-Paul

  • Comment on Re: C-like structures parsing and validation

Replies are listed 'Best First'.
Re^2: C-like structures parsing and validation
by przemo (Scribe) on Nov 16, 2009 at 13:31 UTC

    It crossed my mind, but it looks like a lot of magic. TeX runs Perl which compiles and runs C... I'll try a tiny example, thanks.

Re^2: C-like structures parsing and validation
by przemo (Scribe) on Nov 16, 2009 at 15:13 UTC

    Unfortunatelly, I have problems with using Inline in PerlTeX.

    Here's a little LaTeX code I wrote to test the concept:

    \documentclass{article} \usepackage{perltex} \perldo{ `rm -rf ./_Inline && mkdir ./_Inline`; use Inline Config => DIRECTORY => './_Inline/'; } \perlnewcommand{\compilec}[1]{ { my $cc = "void just_compile() { $_[0] };"; Inline->bind(C => $cc); just_compile(); ""; } } \begin{document} \compilec{1 + 1;} \end{document}

    It works fine, i.e. the code compiles. However, when I change the expression to something invalid, e.g.:

    \compilec{1 + nonexisting;}

    TeX spits no errors and just hangs at 100% CPU for both Perl and Tex.

    Running the corresponding "clean" Perl code outside PerlTeX and looking I see it dies:

    /home/jest/perl/perl-5.10.1/bin/perl /home/jest/perl/perl-5.10.1/lib/s +ite_perl/5.10.1/ExtUtils/xsubpp -typemap /home/jest/perl/perl-5.10.1 +/lib/5.10.1/ExtUtils/typemap perltext1_pl_f7f6.xs > perltext1_pl_f7 +f6.xsc && mv perltext1_pl_f7f6.xsc perltext1_pl_f7f6.c cc -c -I/home/jest/temp/t -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-st +rict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFI +LE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"0.00\" -DXS_VERSIO +N=\"0.00\" -fPIC "-I/home/jest/perl/perl-5.10.1/lib/5.10.1/i486-linux +-gnu-thread-multi/CORE" perltext1_pl_f7f6.c perltext1_pl_f7f6.xs: In function ‘just_compile’: perltext1_pl_f7f6.xs:5: error: ‘bla’ undeclared (first use in this fun +ction) perltext1_pl_f7f6.xs:5: error: (Each undeclared identifier is reported + only once perltext1_pl_f7f6.xs:5: error: for each function it appears in.) make: *** [perltext1_pl_f7f6.o] Error 1 A problem was encountered while attempting to compile and install your + Inline C code. The command that failed was: make > out.make 2>&1 The build directory was: /home/jest/temp/t/_Inline/build/perltext1_pl_f7f6 To debug the problem, cd to the build directory, and inspect the outpu +t files. at perltext1.pl line 8

    BTW, PerlTeX handles normal die-s just fine; but in this case it can't handle errors.

      I contacted Scott Pakin, author of PerlTeX. He corrected the program to be more robust under complicated environments, like Inline::C. It will soon hit CTAN. I checked the corrected PerlTeX, works with the above example just fine!

      However, I was in a (time-constrained) need to parse the mentioned structures, so I wrote a little module of my own, Data::Typed::Expression. The very early version should be on CPAN soon.