Theory C0
chapter ‹Appendix II: Examples for C11 Lexis and Syntax; and Isabelle/C User-Interaction›
theory C0
imports "../main/C_Main"
begin
declare[[C_lexer_trace]]
section ‹Regular C Code›
subsection ‹Comments, Keywords and Pragmas›
C ‹
int a = "outside";
int a = "outside";
int a = "outside";
int a = "outside";
›
C ‹
i\
n\
t a = "/* // /\
*\
fff */\
";
›
C ‹
# defi\
ne FO\
O 10\
20›
C ‹
#ifdef a
#elif
#else
#if
#endif
#endif
›
C ‹
#define a zz
#define a(x1,x2) z erz(( zz
#define a (x1,x2) z erz(( zz
#undef z
#if
#define a zz
#define a(x1,x2) z erz(( zz
#define a (x1,x2) z erz(( zz
#endif
›
subsection ‹Scala/jEdit Latency on Multiple Bindings›
C ‹
#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_
_-_-_-_
}
›
text ‹ Select inside the ball, experience the latency.
A special keyboard combination ``Ctrl-like key⁋‹on Apple: Cmd› + Shift +
Enter'' lets Isabelle/Scala/jEdit enter in a mode where the selected bound occurrences can be all
simultaneously replaced by new input characters typed on the keyboard. (The ``select-entity'' action
exists since Isabelle2016-1, see the respective section ``Prover IDE -- Isabelle/Scala/jEdit'' in
the NEWS.)›
subsection ‹Lexing and Parsing Obfuscated Sources›
text ‹Another lexer/parser - stress test: parsing an obfuscated C source.›
C ‹
#defineLfor
#include<stdio.h>
char*r,F[1<<21]="~T/}3(|+G{>/zUhy;Jx+5wG<v>>u55t.?sIZrC]n.;m+:l+Hk]WjNJi/Sh+2f1>c2H`)(_2(^L\
-]=([1/Z<2Y7/X12W:.VFFU1,T77S+;N?;M/>L..K1+JCCI<<H:(G*5F--E11C=5?.(>+(=3)Z-;*(:*.Y/5(-=)2*-U,\
/+-?5'(,+++***''EE>T,215IEUF:N`2`:?GK;+^`+?>)5?>U>_)5GxG).2K.2};}_235(]:5,S7E1(vTSS,-SSTvU(<-HG\
-2E2/2L2/EE->E:?EE,2XMMMM1Hy`)5rHK;+.T+?[n2/_2{LKN2/_|cK2+.2`;}:?{KL57?|cK:2{NrHKtMMMK2nrH;rH[n"
"CkM_E21-E,-1->E(_:mSE/LhLE/mm:2Ul;2M>,2KW-+.-u).5Lm?fM`2`2nZXjj?[n<YcK?2}yC}H[^7N7LX^7N7UN</:-\
ZWXI<^I2K?>T+?KH~-?f<;G_x2;;2XT7LXIuuVF2X(G(GVV-:-:KjJ]HKLyN7UjJ3.WXjNI2KN<l|cKt2~[IsHfI2w{[<VV"
"GIfZG>x#&#&&$#$;ZXIc###$&$$#>7[LMv{&&&&#&##L,l2TY.&$#$#&&$,(iiii,#&&&#$#$?TY2.$#$1(x###;2EE[t,\
SSEz.SW-k,T&&jC?E-.$## &#&57+$$# &&&W1-&$$7W -J$#$kEN&#& $##C^+$##W,h###n/+L2YE"
"2nJk/H;YNs#$[,:TU(#$ ,: &&~H>&# Y; &&G_x ,mT&$YE-#& 5G $#VVF$#&zNs$$&Ej]HELy\
CN/U^Jk71<(#&:G7E+^&# l|?1 $$Y.2$$ 7lzs WzZw>&$E -<V-wE(2$$ G>x; 2zsW/$$#HKt&$$v>+t1(>"
"7>S7S,;TT,&$;S7S>7&#>E_::U $$'",op ,*G= F,*I=957+F ;int*t,k,O, i, j,T[+060<<+020];int M(
int m,int nop){;;;return+ m%(0+nop );;} int*tOo,w, h,z,W;void(C) (int n){n=putchar(n);}int
f,c,H=11,Y=64<<2,Z,pq,X ;void(E)( intn ){L(Z=k+00; Z; Z/=+2+000)G[000]=*G*!!f
|M(n,2)<<f,pq=2,f=+06 <f?++pq,++pq ,G++ ,z:f+001,n /=2;;}void (V)( intn){C(n
%Y);;C(n/Y+00);;}void J(){L(pq--,pq =j =O=-1+0;++ j<240;I[6+ (h +6+j/12/2*2+M(j/2,2))*
W+M(j/2/2,+06)*2+w*014 +00+M(00+ 000+j,002 +00)]=000 +00+k)k=M(G[j/2/2+(*r-+
32)**"<nopqabdeg"],3);;}intmain()
{L(X=Y-1;i<21*3;i++,I++)L(r=G,G+=2;*G++;)*G>=13*3?*G-*r?*I++=*G:(*I++=r[1],*I++=r[2]):1;L(j=12,r
=I;(*I=i=getchar())>-1;I++)i-7-3?I-=i<32||127<=i,j+=12:(H+=17+3,W=W<j?j:W,j=12);L(;*r>-1;r++)*r-
7-3?J(),w++:(w=z,h+=17+3);C(71);C(73);V('*'*'1'*7);C(57);C(32*3+1);V(W);V(H);C(122*2);L(V(i=z);i
<32*3;)C(i++/3*X/31);C(33);C(X);C(11);L(G="SJYXHFUJ735";*G;)C(*G++-5);C(3);V(1);L(V(j=z);j<21*3;
j++){k=257;V(63777);V(k<<2);V(M(j,32)?11:511);V(z);C(22*2);V(i=f=z);V(z);V(W);V(H);V(1<<11);r=
G=I+W*H;L(t=T;i<1<<21;i++)T[i]=i<Y?i:-1;E(Y);L(i=-1;++i<W*H;t=T+Z*Y+Y)c=I[i]?I[i]*31-31:(31<
j?j-31:31-j),Z=c[t[c]<z?E(Z),k<(1<<12)-2?t[c]=++k,T:T:t];E(Z);E(257);L(G++;k=G-r>X?X:G-r
,C(k),k;)L(;k--;C(*r++));}C(53+6);return(z);}
›
section ‹Testsuite with 🗀‹../../src_ext/parser_menhir››
declare[[C_lexer_trace = false]]
subsection ‹Expected to succeed:›
C_file ‹../../src_ext/parser_menhir/tests/argument_scope.c›
C_file ‹../../src_ext/parser_menhir/tests/atomic_parenthesis.c›
C_file ‹../../src_ext/parser_menhir/tests/bitfield_declaration_ambiguity.c›
C_file ‹../../src_ext/parser_menhir/tests/bitfield_declaration_ambiguity.ok.c›
C_file ‹../../src_ext/parser_menhir/tests/block_scope.c›
C_file ‹../../src_ext/parser_menhir/tests/char-literal-printing.c›
C_file ‹../../src_ext/parser_menhir/tests/c-namespace.c›
C_file ‹../../src_ext/parser_menhir/tests/control-scope.c›
C_file ‹../../src_ext/parser_menhir/tests/dangling_else.c›
C_file ‹../../src_ext/parser_menhir/tests/declarators.c›
C_file ‹../../src_ext/parser_menhir/tests/designator.c›
C_file ‹../../src_ext/parser_menhir/tests/enum.c›
C_file ‹../../src_ext/parser_menhir/tests/enum_constant_visibility.c›
C_file ‹../../src_ext/parser_menhir/tests/enum_shadows_typedef.c›
C_file ‹../../src_ext/parser_menhir/tests/enum-trick.c›
C_file ‹../../src_ext/parser_menhir/tests/expressions.c›
C_file ‹../../src_ext/parser_menhir/tests/function-decls.c›
C_file ‹../../src_ext/parser_menhir/tests/local_scope.c›
C_file ‹../../src_ext/parser_menhir/tests/local_typedef.c›
C_file ‹../../src_ext/parser_menhir/tests/long-long-struct.c›
C_file ‹../../src_ext/parser_menhir/tests/namespaces.c›
C_file ‹../../src_ext/parser_menhir/tests/no_local_scope.c›
C_file ‹../../src_ext/parser_menhir/tests/parameter_declaration_ambiguity.c›
C_file ‹../../src_ext/parser_menhir/tests/parameter_declaration_ambiguity.test.c›
C_file ‹../../src_ext/parser_menhir/tests/statements.c›
C_file ‹../../src_ext/parser_menhir/tests/struct-recursion.c›
C_file ‹../../src_ext/parser_menhir/tests/typedef_star.c›
C_file ‹../../src_ext/parser_menhir/tests/types.c›
C_file ‹../../src_ext/parser_menhir/tests/variable_star.c›
subsection ‹Expected to fail:›
C_file ‹../../src_ext/parser_menhir/tests/bitfield_declaration_ambiguity.fail.c›
end