aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-04-30 17:52:13 +0100
committerAkshay <[email protected]>2021-04-30 17:52:13 +0100
commit8a57bedc04fff7a92ef6d2762cfe5fc17050f021 (patch)
tree192ea2a1bd2eec0c0f84a9cb7adc9b10d005e1db
parent30047205e440e9ad8984e1830b8b819b5fe1f9f7 (diff)
add yacc programs
l---------.direnv/flake-profile2
-rw-r--r--.direnv/flake-profile.rc22
-rw-r--r--10/input1
-rw-r--r--10/main.l22
-rw-r--r--10/main.y33
-rw-r--r--11/input1
-rw-r--r--11/main.l33
-rw-r--r--11/main.y76
-rw-r--r--6/main.l16
-rw-r--r--6/main.y28
-rw-r--r--7/main.l22
-rw-r--r--7/main.y34
-rw-r--r--8/input1
-rw-r--r--8/main.l15
-rw-r--r--8/main.y28
-rw-r--r--9/input1
-rw-r--r--9/main.l16
-rw-r--r--9/main.y30
-rw-r--r--flake.nix73
19 files changed, 426 insertions, 28 deletions
diff --git a/.direnv/flake-profile b/.direnv/flake-profile
index e2fe106..444fae1 120000
--- a/.direnv/flake-profile
+++ b/.direnv/flake-profile
@@ -1 +1 @@
/nix/store/n8fwn588p25fgik3z6jr49x7l7ypsvkc-nix-shell-env \ No newline at end of file /nix/store/q89kklg6h19vm15s7wh5lwjrj1jdz7k4-nix-shell-env \ No newline at end of file
diff --git a/.direnv/flake-profile.rc b/.direnv/flake-profile.rc
index 34911e2..611c1da 100644
--- a/.direnv/flake-profile.rc
+++ b/.direnv/flake-profile.rc
@@ -32,7 +32,7 @@ NIX_CC=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0
32export NIX_CC 32export NIX_CC
33NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1 33NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1
34export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu 34export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu
35NIX_CFLAGS_COMPILE=' -frandom-seed=n8fwn588p2 -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include' 35NIX_CFLAGS_COMPILE=' -frandom-seed=q89kklg6h1 -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include'
36export NIX_CFLAGS_COMPILE 36export NIX_CFLAGS_COMPILE
37NIX_ENFORCE_NO_NATIVE=1 37NIX_ENFORCE_NO_NATIVE=1
38export NIX_ENFORCE_NO_NATIVE 38export NIX_ENFORCE_NO_NATIVE
@@ -55,7 +55,7 @@ export OBJDUMP
55OPTERR=1 55OPTERR=1
56OPTIND=1 56OPTIND=1
57OSTYPE=linux-gnu 57OSTYPE=linux-gnu
58PATH=/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/bin:/nix/store/caxc3dmxqwy1ks03han5mlkr7sy6wh8y-gnum4-1.4.18/bin:/nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6/bin:/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0/bin:/nix/store/sjfbbay5xhifzpipm4k007svlrpjbx2p-gcc-10.2.0/bin:/nix/store/l6blpd7anij8pzzgr30srmf919rg169v-glibc-2.32-39-bin/bin:/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32/bin:/nix/store/6zb7whdhsn7pq9vw086z5j3kw0qpgr3m-binutils-wrapper-2.35.1/bin:/nix/store/fx4kvd2440kgrq73irdkmwqf6vvzwf2m-binutils-2.35.1/bin:/nix/store/q5yia079krwdhp1ld00fv44sy072q5f5-patchelf-0.12/bin:/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32/bin:/nix/store/a7kzz70vzpsq3s2pgfw49q8ll356l13f-findutils-4.7.0/bin:/nix/store/b2rmyng3dryanc5g1jnsqqrbaclw52b3-diffutils-3.7/bin:/nix/store/xyd1a8i3sn1iah73sr3p15fx3y9v0rkc-gnused-4.8/bin:/nix/store/x604v97a5yi0yc07zfid76n7xqbcykmj-gnugrep-3.6/bin:/nix/store/3w93n4d1f0gj7xc2x7si46njlz9vkad9-gawk-5.1.0/bin:/nix/store/ym4ygxjyyym82j6mc3bjzx6527r1j9rj-gnutar-1.34/bin:/nix/store/fj1cn54yvinnd8ypi202jq3kd761d5sh-gzip-1.10/bin:/nix/store/ip4mcnr199dw3f750ka6543zgjpr3pgd-bzip2-1.0.6.0.2-bin/bin:/nix/store/chy0dyh9imv0qj4x3xd1a2w4rw9v77pj-gnumake-4.3/bin:/nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23/bin:/nix/store/ay3j8pm23pilyj8gqqj7rkbzk7mdcfr0-patch-2.7.6/bin:/nix/store/k25g03svkjzl74c1bqkzx9anpg0438v1-xz-5.2.5-bin/bin 58PATH=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0/bin:/nix/store/sjfbbay5xhifzpipm4k007svlrpjbx2p-gcc-10.2.0/bin:/nix/store/l6blpd7anij8pzzgr30srmf919rg169v-glibc-2.32-39-bin/bin:/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32/bin:/nix/store/6zb7whdhsn7pq9vw086z5j3kw0qpgr3m-binutils-wrapper-2.35.1/bin:/nix/store/fx4kvd2440kgrq73irdkmwqf6vvzwf2m-binutils-2.35.1/bin:/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/bin:/nix/store/caxc3dmxqwy1ks03han5mlkr7sy6wh8y-gnum4-1.4.18/bin:/nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6/bin:/nix/store/q5yia079krwdhp1ld00fv44sy072q5f5-patchelf-0.12/bin:/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32/bin:/nix/store/a7kzz70vzpsq3s2pgfw49q8ll356l13f-findutils-4.7.0/bin:/nix/store/b2rmyng3dryanc5g1jnsqqrbaclw52b3-diffutils-3.7/bin:/nix/store/xyd1a8i3sn1iah73sr3p15fx3y9v0rkc-gnused-4.8/bin:/nix/store/x604v97a5yi0yc07zfid76n7xqbcykmj-gnugrep-3.6/bin:/nix/store/3w93n4d1f0gj7xc2x7si46njlz9vkad9-gawk-5.1.0/bin:/nix/store/ym4ygxjyyym82j6mc3bjzx6527r1j9rj-gnutar-1.34/bin:/nix/store/fj1cn54yvinnd8ypi202jq3kd761d5sh-gzip-1.10/bin:/nix/store/ip4mcnr199dw3f750ka6543zgjpr3pgd-bzip2-1.0.6.0.2-bin/bin:/nix/store/chy0dyh9imv0qj4x3xd1a2w4rw9v77pj-gnumake-4.3/bin:/nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23/bin:/nix/store/ay3j8pm23pilyj8gqqj7rkbzk7mdcfr0-patch-2.7.6/bin:/nix/store/k25g03svkjzl74c1bqkzx9anpg0438v1-xz-5.2.5-bin/bin
59export PATH 59export PATH
60PIPESTATUS=([0]="0") 60PIPESTATUS=([0]="0")
61PS4='+ ' 61PS4='+ '
@@ -107,13 +107,13 @@ doInstallCheck=
107export doInstallCheck 107export doInstallCheck
108dontAddDisableDepTrack=1 108dontAddDisableDepTrack=1
109export dontAddDisableDepTrack 109export dontAddDisableDepTrack
110envHostHostHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars") 110envHostHostHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars" [2]="ccWrapper_addCVars")
111envHostTargetHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars") 111envHostTargetHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars" [2]="ccWrapper_addCVars")
112fixupOutputHooks=([0]="if [ -z \"\${dontPatchELF-}\" ]; then patchELF \"\$prefix\"; fi" [1]="_makeSymlinksRelative" [2]="if [ -z \"\${dontGzipMan-}\" ]; then compressManPages \"\$prefix\"; fi" [3]="_doStrip" [4]="patchShebangsAuto" [5]="_pruneLibtoolFiles" [6]="if [[ -z \"\${noAuditTmpdir-}\" && -e \"\$prefix\" ]]; then auditTmpdir \"\$prefix\"; fi" [7]="_moveSystemdUserUnits" [8]="_moveSbin" [9]="_moveLib64") 112fixupOutputHooks=([0]="if [ -z \"\${dontPatchELF-}\" ]; then patchELF \"\$prefix\"; fi" [1]="_makeSymlinksRelative" [2]="if [ -z \"\${dontGzipMan-}\" ]; then compressManPages \"\$prefix\"; fi" [3]="_doStrip" [4]="patchShebangsAuto" [5]="_pruneLibtoolFiles" [6]="if [[ -z \"\${noAuditTmpdir-}\" && -e \"\$prefix\" ]]; then auditTmpdir \"\$prefix\"; fi" [7]="_moveSystemdUserUnits" [8]="_moveSbin" [9]="_moveLib64")
113initialPath='/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32 /nix/store/a7kzz70vzpsq3s2pgfw49q8ll356l13f-findutils-4.7.0 /nix/store/b2rmyng3dryanc5g1jnsqqrbaclw52b3-diffutils-3.7 /nix/store/xyd1a8i3sn1iah73sr3p15fx3y9v0rkc-gnused-4.8 /nix/store/x604v97a5yi0yc07zfid76n7xqbcykmj-gnugrep-3.6 /nix/store/3w93n4d1f0gj7xc2x7si46njlz9vkad9-gawk-5.1.0 /nix/store/ym4ygxjyyym82j6mc3bjzx6527r1j9rj-gnutar-1.34 /nix/store/fj1cn54yvinnd8ypi202jq3kd761d5sh-gzip-1.10 /nix/store/ip4mcnr199dw3f750ka6543zgjpr3pgd-bzip2-1.0.6.0.2-bin /nix/store/chy0dyh9imv0qj4x3xd1a2w4rw9v77pj-gnumake-4.3 /nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23 /nix/store/ay3j8pm23pilyj8gqqj7rkbzk7mdcfr0-patch-2.7.6 /nix/store/k25g03svkjzl74c1bqkzx9anpg0438v1-xz-5.2.5-bin' 113initialPath='/nix/store/485sqh570qixsv9wk0d59vrvs35pqja0-coreutils-8.32 /nix/store/a7kzz70vzpsq3s2pgfw49q8ll356l13f-findutils-4.7.0 /nix/store/b2rmyng3dryanc5g1jnsqqrbaclw52b3-diffutils-3.7 /nix/store/xyd1a8i3sn1iah73sr3p15fx3y9v0rkc-gnused-4.8 /nix/store/x604v97a5yi0yc07zfid76n7xqbcykmj-gnugrep-3.6 /nix/store/3w93n4d1f0gj7xc2x7si46njlz9vkad9-gawk-5.1.0 /nix/store/ym4ygxjyyym82j6mc3bjzx6527r1j9rj-gnutar-1.34 /nix/store/fj1cn54yvinnd8ypi202jq3kd761d5sh-gzip-1.10 /nix/store/ip4mcnr199dw3f750ka6543zgjpr3pgd-bzip2-1.0.6.0.2-bin /nix/store/chy0dyh9imv0qj4x3xd1a2w4rw9v77pj-gnumake-4.3 /nix/store/p886sbvvzpqpxnb8a60djpp8dir9zfp9-bash-4.4-p23 /nix/store/ay3j8pm23pilyj8gqqj7rkbzk7mdcfr0-patch-2.7.6 /nix/store/k25g03svkjzl74c1bqkzx9anpg0438v1-xz-5.2.5-bin'
114name=nix-shell 114name=nix-shell
115export name 115export name
116nativeBuildInputs='/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4 /nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6 /nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0' 116nativeBuildInputs='/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0 /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4 /nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6 /nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0'
117export nativeBuildInputs 117export nativeBuildInputs
118nobuildPhase=$'echo\necho "This derivation is not meant to be built, aborting";\necho\nexit 1\n' 118nobuildPhase=$'echo\necho "This derivation is not meant to be built, aborting";\necho\nexit 1\n'
119export nobuildPhase 119export nobuildPhase
@@ -135,7 +135,7 @@ export patches
135phases=nobuildPhase 135phases=nobuildPhase
136export phases 136export phases
137pkg=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0 137pkg=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0
138pkgsBuildHost=([0]="/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4" [1]="/nix/store/caxc3dmxqwy1ks03han5mlkr7sy6wh8y-gnum4-1.4.18" [2]="/nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6" [3]="/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0" [4]="/nix/store/6zb7whdhsn7pq9vw086z5j3kw0qpgr3m-binutils-wrapper-2.35.1" [5]="/nix/store/q5yia079krwdhp1ld00fv44sy072q5f5-patchelf-0.12" [6]="/nix/store/mjjy30kxz775bhhi6j9phw81qh6dsbrf-move-docs.sh" [7]="/nix/store/kxw6q8v6isaqjm702d71n2421cxamq68-make-symlinks-relative.sh" [8]="/nix/store/cl3qd985p1yxyfkj96v0hqxiy3w69xq5-compress-man-pages.sh" [9]="/nix/store/h54dzwd7rdh2jlcv91424csl6d0ccgjy-strip.sh" [10]="/nix/store/bnj8d7mvbkg3vdb07yz74yhl3g107qq5-patch-shebangs.sh" [11]="/nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh" [12]="/nix/store/8zxndz5ag0p6s526c2xyllhk1nrn4c3i-audit-tmpdir.sh" [13]="/nix/store/c8n9kcdddp9np665xz6ri61b383nxvz8-move-systemd-user-units.sh" [14]="/nix/store/1i5y55x4b4m9qkx5dqbmr1r6bvrqbanw-multiple-outputs.sh" [15]="/nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh" [16]="/nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh" [17]="/nix/store/ngg1cv31c8c7bcm2n8ww4g06nq7s4zhm-set-source-date-epoch-to-latest.sh" [18]="/nix/store/pr6nzbscdpg94yvr151lrif2kg0csx7b-reproducible-builds.sh") 138pkgsBuildHost=([0]="/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0" [1]="/nix/store/6zb7whdhsn7pq9vw086z5j3kw0qpgr3m-binutils-wrapper-2.35.1" [2]="/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4" [3]="/nix/store/caxc3dmxqwy1ks03han5mlkr7sy6wh8y-gnum4-1.4.18" [4]="/nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6" [5]="/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0" [6]="/nix/store/q5yia079krwdhp1ld00fv44sy072q5f5-patchelf-0.12" [7]="/nix/store/mjjy30kxz775bhhi6j9phw81qh6dsbrf-move-docs.sh" [8]="/nix/store/kxw6q8v6isaqjm702d71n2421cxamq68-make-symlinks-relative.sh" [9]="/nix/store/cl3qd985p1yxyfkj96v0hqxiy3w69xq5-compress-man-pages.sh" [10]="/nix/store/h54dzwd7rdh2jlcv91424csl6d0ccgjy-strip.sh" [11]="/nix/store/bnj8d7mvbkg3vdb07yz74yhl3g107qq5-patch-shebangs.sh" [12]="/nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh" [13]="/nix/store/8zxndz5ag0p6s526c2xyllhk1nrn4c3i-audit-tmpdir.sh" [14]="/nix/store/c8n9kcdddp9np665xz6ri61b383nxvz8-move-systemd-user-units.sh" [15]="/nix/store/1i5y55x4b4m9qkx5dqbmr1r6bvrqbanw-multiple-outputs.sh" [16]="/nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh" [17]="/nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh" [18]="/nix/store/ngg1cv31c8c7bcm2n8ww4g06nq7s4zhm-set-source-date-epoch-to-latest.sh" [19]="/nix/store/pr6nzbscdpg94yvr151lrif2kg0csx7b-reproducible-builds.sh")
139postFixupHooks=([0]="_multioutPropagateDev") 139postFixupHooks=([0]="_multioutPropagateDev")
140postUnpackHooks=([0]="_updateSourceDateEpochFromSourceRoot") 140postUnpackHooks=([0]="_updateSourceDateEpochFromSourceRoot")
141preConfigureHooks=([0]="_multioutConfig") 141preConfigureHooks=([0]="_multioutConfig")
@@ -955,7 +955,7 @@ getRole ()
955 role_post='_FOR_TARGET' 955 role_post='_FOR_TARGET'
956 ;; 956 ;;
957 *) 957 *)
958 echo "binutils-wrapper-2.35.1: used as improper sort of dependency" > 2; 958 echo "gcc-wrapper-10.2.0: used as improper sort of dependency" > 2;
959 return 1 959 return 1
960 ;; 960 ;;
961 esac 961 esac
@@ -972,16 +972,16 @@ getTargetRoleWrapper ()
972{ 972{
973 case $targetOffset in 973 case $targetOffset in
974 -1) 974 -1)
975 export NIX_BINTOOLS_WRAPPER_TARGET_BUILD_x86_64_unknown_linux_gnu=1 975 export NIX_CC_WRAPPER_TARGET_BUILD_x86_64_unknown_linux_gnu=1
976 ;; 976 ;;
977 0) 977 0)
978 export NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1 978 export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1
979 ;; 979 ;;
980 1) 980 1)
981 export NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu=1 981 export NIX_CC_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu=1
982 ;; 982 ;;
983 *) 983 *)
984 echo "binutils-wrapper-2.35.1: used as improper sort of dependency" > 2; 984 echo "gcc-wrapper-10.2.0: used as improper sort of dependency" > 2;
985 return 1 985 return 1
986 ;; 986 ;;
987 esac 987 esac
diff --git a/10/input b/10/input
new file mode 100644
index 0000000..fdfb61b
--- /dev/null
+++ b/10/input
@@ -0,0 +1 @@
1+2-3*6/2
diff --git a/10/main.l b/10/main.l
new file mode 100644
index 0000000..9962054
--- /dev/null
+++ b/10/main.l
@@ -0,0 +1,22 @@
1%{
2extern int yylval;
3%}
4
5d [0-9]+
6
7%%
8"+" return ADD;
9"-" return SUB;
10"*" return MUL;
11"/" return DIV;
12[0-9]+ {
13 yylval = atoi(yytext);
14 return NUM;
15};
16. return yytext[0];
17\n return 0;
18%%
19
20int yywrap() {
21 return 1;
22}
diff --git a/10/main.y b/10/main.y
new file mode 100644
index 0000000..f45e23f
--- /dev/null
+++ b/10/main.y
@@ -0,0 +1,33 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yylex();
5int yyerror(char *);
6%}
7
8%token ADD SUB MUL DIV NUM
9%left ADD SUB MUL DIV
10
11%%
12R: E {
13 printf("result: %d", $$);
14 return 0;
15 }
16E: E ADD T { $$ = $1 + $3; }
17 | E SUB T { $$ = $1 - $3; }
18 | T
19 ;
20T: T MUL NUM { $$ = $1 * $3; }
21 | T DIV NUM { $$ = $1 / $3; }
22 | NUM { $$ = $1; }
23 ;
24%%
25
26int main() {
27 yyparse();
28}
29
30int yyerror(char *s) {
31 printf("error: %s", s);
32 exit(0);
33}
diff --git a/11/input b/11/input
new file mode 100644
index 0000000..7e9718c
--- /dev/null
+++ b/11/input
@@ -0,0 +1 @@
for(i=0;i!=20;i--){for(;;){for(;;)i=1;}}
diff --git a/11/main.l b/11/main.l
new file mode 100644
index 0000000..5cc2a4e
--- /dev/null
+++ b/11/main.l
@@ -0,0 +1,33 @@
1%{
2#include "y.tab.h"
3extern int yylval;
4%}
5
6%%
7"++" return INC;
8"--" return DEC;
9"+" return ADD;
10"-" return SUB;
11"*" return MUL;
12"/" return DIV;
13"=" return ASSIGN;
14"==" return EQ;
15"!=" return NEQ;
16"<" return LT;
17">" return GT;
18"<=" return LTE;
19">=" return GTE;
20";" return ENDL;
21"for" return FOR;
22[0-9]+ {
23 yylval = atoi(yytext);
24 return NUM;
25};
26[a-zA-Z_][a-zA-Z_0-9]* return ID;
27. return yytext[0];
28\n return 0;
29%%
30
31int yywrap() {
32 return 1;
33}
diff --git a/11/main.y b/11/main.y
new file mode 100644
index 0000000..9ed51a0
--- /dev/null
+++ b/11/main.y
@@ -0,0 +1,76 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4#include "lex.yy.cc"
5int yylex();
6int yyerror(char *);
7int loop_count = 0;
8%}
9
10%token ADD SUB MUL DIV INC DEC
11%token LT GT LTE GTE EQ NEQ ASSIGN
12%token FOR
13%token ENDL
14%token NUM ID
15
16%start statement
17
18%%
19primary_expr: NUM
20 | ID
21 ;
22
23postfix_expr: postfix_expr INC
24 | postfix_expr DEC
25 | primary_expr
26 ;
27
28unary_expr: INC unary_expr
29 | DEC unary_expr
30 | postfix_expr
31 ;
32
33boolean_expr: unary_expr LT unary_expr
34 | unary_expr GT unary_expr
35 | unary_expr LTE unary_expr
36 | unary_expr GTE unary_expr
37 | unary_expr EQ unary_expr
38 | unary_expr NEQ unary_expr
39 ;
40
41assignment_expr: unary_expr ASSIGN unary_expr
42 | unary_expr ASSIGN boolean_expr
43 ;
44
45expression: unary_expr
46 | boolean_expr
47 | assignment_expr
48 ;
49
50block: '{' statement block_cont
51 ;
52block_cont: statement block_cont
53 | '}'
54 ;
55
56statement: expression ENDL
57 | block
58 | for_expr {loop_count++;}
59 | ENDL
60 ;
61
62for_expr: FOR '(' statement statement expression ')' statement
63 | FOR '(' statement statement ')' statement
64 ;
65
66%%
67
68int main() {
69 yyparse();
70 printf("valid expression, nested %d", loop_count);
71}
72
73int yyerror(char *s) {
74 printf("error: %s", s);
75 exit(0);
76}
diff --git a/6/main.l b/6/main.l
new file mode 100644
index 0000000..55dac30
--- /dev/null
+++ b/6/main.l
@@ -0,0 +1,16 @@
1%{
2#include "y.tab.h"
3#include <stdlib.h>
4%}
5
6%%
7
8a return A;
9b return B;
10. return yytext[0];
11\n return 0;
12%%
13
14int yywrap() {
15 return 1;
16}
diff --git a/6/main.y b/6/main.y
new file mode 100644
index 0000000..25005df
--- /dev/null
+++ b/6/main.y
@@ -0,0 +1,28 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yylex();
5int yyerror(char *);
6%}
7
8%token A B ERR
9
10%%
11
12S:
13 A S B
14 |
15 ;
16
17%%
18
19int yyerror(char *s) {
20 printf("error: %s", s);
21 exit(0);
22}
23
24int main() {
25 yyparse();
26 printf("valid string\n");
27 return 0;
28}
diff --git a/7/main.l b/7/main.l
new file mode 100644
index 0000000..7e1332f
--- /dev/null
+++ b/7/main.l
@@ -0,0 +1,22 @@
1%{
2#include "y.tab.h"
3extern int yylval;
4%}
5
6%%
7[0-9]+ {
8 yylval = atoi(yytext);
9 return NUM;
10}
11"+" return ADD;;
12"-" return SUB;
13"*" return MUL;
14"/" return DIV;
15"(" return LPAR;
16")" return RPAR;
17\n return 0;
18%%
19
20int yywrap() {
21 return 1;
22}
diff --git a/7/main.y b/7/main.y
new file mode 100644
index 0000000..26a2007
--- /dev/null
+++ b/7/main.y
@@ -0,0 +1,34 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yylex();
5int yyerror(char *);
6%}
7
8%token NUM ADD SUB MUL DIV LPAR RPAR
9%left ADD SUB MUL DIV
10%right NEG
11
12%%
13
14S:
15 E { printf("\n"); };
16E:
17 E ADD E { printf("+ "); }
18 | E MUL E { printf("* "); }
19 | E SUB E { printf("- "); }
20 | E DIV E { printf("/ "); }
21 | LPAR E RPAR
22 | SUB E %prec NEG { printf("- "); }
23 | NUM { printf("%d ", yylval); }
24 ;
25%%
26
27int main() {
28 yyparse();
29}
30
31int yyerror(char *s) {
32 printf("error: %s", s);
33 exit(0);
34}
diff --git a/8/input b/8/input
new file mode 100644
index 0000000..5c11124
--- /dev/null
+++ b/8/input
@@ -0,0 +1 @@
aaaab
diff --git a/8/main.l b/8/main.l
new file mode 100644
index 0000000..3db9d6d
--- /dev/null
+++ b/8/main.l
@@ -0,0 +1,15 @@
1%{
2#include "y.tab.h"
3extern int yylval;
4%}
5
6%%
7a return A;
8b return B;
9. return yytext[0];
10\n return 0;
11%%
12
13int yywrap() {
14 return 1;
15}
diff --git a/8/main.y b/8/main.y
new file mode 100644
index 0000000..04e98a7
--- /dev/null
+++ b/8/main.y
@@ -0,0 +1,28 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yyerror(char *);
5%}
6
7%token A B
8%start S
9
10%%
11
12S: C B
13 |
14 ;
15C: A C
16 | A A A A
17 ;
18%%
19
20int main() {
21 yyparse();
22 printf("valid string");
23}
24
25int yyerror(char *s) {
26 printf("error: %s", s);
27 exit(0);
28}
diff --git a/9/input b/9/input
new file mode 100644
index 0000000..01efb5e
--- /dev/null
+++ b/9/input
@@ -0,0 +1 @@
aaabbbbc
diff --git a/9/main.l b/9/main.l
new file mode 100644
index 0000000..04c6bf0
--- /dev/null
+++ b/9/main.l
@@ -0,0 +1,16 @@
1%{
2#include "y.tab.h"
3extern int yylval;
4%}
5
6%%
7a return A;
8b return B;
9c return C;
10. return yytext[0];
11\n return 0;
12%%
13
14int yywrap() {
15 return 1;
16}
diff --git a/9/main.y b/9/main.y
new file mode 100644
index 0000000..0db29c1
--- /dev/null
+++ b/9/main.y
@@ -0,0 +1,30 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yylex();
5int yyerror(char *);
6%}
7
8%token A B C
9
10%%
11S: X Y
12 |
13 ;
14X: A X B
15 |
16 ;
17Y: B Y C
18 |
19 ;
20%%
21
22int main() {
23 yyparse();
24 printf("valid string");
25}
26
27int yyerror(char *s) {
28 printf("error: %s", s);
29 exit(0);
30}
diff --git a/flake.nix b/flake.nix
index c85db6e..2e717b8 100644
--- a/flake.nix
+++ b/flake.nix
@@ -8,23 +8,67 @@
8 let 8 let
9 pkgs = nixpkgs.legacyPackages."${system}"; 9 pkgs = nixpkgs.legacyPackages."${system}";
10 nativeBuildInputs = with pkgs; [ 10 nativeBuildInputs = with pkgs; [
11 gcc
11 flex 12 flex
12 bison 13 bison
13 ]; 14 ];
15 defs = [
16 { name = "1"; yacc = false; }
17 { name = "2"; yacc = false; }
18 { name = "3"; yacc = false; }
19 { name = "4"; yacc = false; }
20 { name = "5"; yacc = false; }
21 { name = "6"; yacc = true; }
22 { name = "7"; yacc = true; }
23 { name = "8"; yacc = true; }
24 ];
25 apps = builtins.listToAttrs (builtins.map
26 (def:
27 let
28 builder = pkgs.stdenv.mkDerivation {
29 name = "${def.name}-v0.1.0";
30 src = ./.;
31 buildInputs = nativeBuildInputs;
32 unpackCmd = ''
33 cp -r $src/${def.name} .
34 '';
35 buildPhase = ''
36 flex -o ${def.name}.yy.cc main.l
37 if [[ ${pkgs.lib.trivial.boolToString def.yacc} = true ]]; then
38 yacc -d main.y
39 gcc -o exec y* ${def.name}.yy.cc
40 else
41 gcc -o exec ${def.name}.yy.cc
42 fi
43 '';
44 installPhase = ''
45 mkdir -p $out/bin
46 install -m 755 -D exec -t $out/bin/
47 '';
48 };
49 in
50 {
51 name = def.name;
52 value = {
53 type = "app";
54 program = "${builder}/bin/exec";
55 };
56 })
57 defs);
58 # buildYacc = pkgs.writeScriptBin "build-yacc"
59 # ''
60 # set -e
61 # prog_name="$1"
62 # outdir="outputs/$prog_name"
63 # mkdir -p "$outdir"
14 64
15 buildScript = pkgs.writeScriptBin "build-script" 65 # ${pkgs.flex}/bin/flex -o "$outdir"/lex.yy.cc "$prog_name"/main.l
16 '' 66 # ${pkgs.bison}/bin/yacc -b "$outdir"/y -d "$prog_name"/main.y
17 set -e 67 # ${pkgs.gcc}/bin/gcc -o "$outdir"/exec "$outdir"/y.*
18 prog_name="$1"
19 outdir="outputs/$prog_name"
20 mkdir -p "$outdir"
21
22 ${pkgs.flex}/bin/flex -o "$outdir"/lex.yy.cc "$prog_name"/main.l
23 ${pkgs.gcc}/bin/gcc "$outdir"/lex.yy.cc -o "$outdir"/exec
24 68
25 ./"$outdir"/exec < "$prog_name"/input 69 # ./"$outdir"/exec < "$prog_name"/input
26 rm -r outputs 70 # rm -r outputs
27 ''; 71 # '';
28 72
29 in 73 in
30 rec { 74 rec {
@@ -33,9 +77,6 @@
33 gcc 77 gcc
34 ]); 78 ]);
35 }; 79 };
36 defaultApp = { 80 inherit apps;
37 type = "app";
38 program = "${buildScript}/bin/build-script";
39 };
40 }); 81 });
41} 82}