diff options
author | Akshay <[email protected]> | 2021-04-30 17:52:13 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-30 17:52:13 +0100 |
commit | 8a57bedc04fff7a92ef6d2762cfe5fc17050f021 (patch) | |
tree | 192ea2a1bd2eec0c0f84a9cb7adc9b10d005e1db | |
parent | 30047205e440e9ad8984e1830b8b819b5fe1f9f7 (diff) |
add yacc programs
l--------- | .direnv/flake-profile | 2 | ||||
-rw-r--r-- | .direnv/flake-profile.rc | 22 | ||||
-rw-r--r-- | 10/input | 1 | ||||
-rw-r--r-- | 10/main.l | 22 | ||||
-rw-r--r-- | 10/main.y | 33 | ||||
-rw-r--r-- | 11/input | 1 | ||||
-rw-r--r-- | 11/main.l | 33 | ||||
-rw-r--r-- | 11/main.y | 76 | ||||
-rw-r--r-- | 6/main.l | 16 | ||||
-rw-r--r-- | 6/main.y | 28 | ||||
-rw-r--r-- | 7/main.l | 22 | ||||
-rw-r--r-- | 7/main.y | 34 | ||||
-rw-r--r-- | 8/input | 1 | ||||
-rw-r--r-- | 8/main.l | 15 | ||||
-rw-r--r-- | 8/main.y | 28 | ||||
-rw-r--r-- | 9/input | 1 | ||||
-rw-r--r-- | 9/main.l | 16 | ||||
-rw-r--r-- | 9/main.y | 30 | ||||
-rw-r--r-- | flake.nix | 73 |
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 | |||
32 | export NIX_CC | 32 | export NIX_CC |
33 | NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1 | 33 | NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1 |
34 | export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu | 34 | export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu |
35 | NIX_CFLAGS_COMPILE=' -frandom-seed=n8fwn588p2 -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include -isystem /nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4/include' | 35 | NIX_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' |
36 | export NIX_CFLAGS_COMPILE | 36 | export NIX_CFLAGS_COMPILE |
37 | NIX_ENFORCE_NO_NATIVE=1 | 37 | NIX_ENFORCE_NO_NATIVE=1 |
38 | export NIX_ENFORCE_NO_NATIVE | 38 | export NIX_ENFORCE_NO_NATIVE |
@@ -55,7 +55,7 @@ export OBJDUMP | |||
55 | OPTERR=1 | 55 | OPTERR=1 |
56 | OPTIND=1 | 56 | OPTIND=1 |
57 | OSTYPE=linux-gnu | 57 | OSTYPE=linux-gnu |
58 | PATH=/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 | 58 | PATH=/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 |
59 | export PATH | 59 | export PATH |
60 | PIPESTATUS=([0]="0") | 60 | PIPESTATUS=([0]="0") |
61 | PS4='+ ' | 61 | PS4='+ ' |
@@ -107,13 +107,13 @@ doInstallCheck= | |||
107 | export doInstallCheck | 107 | export doInstallCheck |
108 | dontAddDisableDepTrack=1 | 108 | dontAddDisableDepTrack=1 |
109 | export dontAddDisableDepTrack | 109 | export dontAddDisableDepTrack |
110 | envHostHostHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars") | 110 | envHostHostHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars" [2]="ccWrapper_addCVars") |
111 | envHostTargetHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars") | 111 | envHostTargetHooks=([0]="ccWrapper_addCVars" [1]="bintoolsWrapper_addLDVars" [2]="ccWrapper_addCVars") |
112 | fixupOutputHooks=([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") | 112 | fixupOutputHooks=([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") |
113 | initialPath='/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' | 113 | initialPath='/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' |
114 | name=nix-shell | 114 | name=nix-shell |
115 | export name | 115 | export name |
116 | nativeBuildInputs='/nix/store/qrq8px6m7v85j9jcp7zzk1pkawmrll43-flex-2.6.4 /nix/store/ybl3zad6ihv60d4w0nprcj5a9g94z1z3-bison-3.7.6 /nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0' | 116 | nativeBuildInputs='/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' |
117 | export nativeBuildInputs | 117 | export nativeBuildInputs |
118 | nobuildPhase=$'echo\necho "This derivation is not meant to be built, aborting";\necho\nexit 1\n' | 118 | nobuildPhase=$'echo\necho "This derivation is not meant to be built, aborting";\necho\nexit 1\n' |
119 | export nobuildPhase | 119 | export nobuildPhase |
@@ -135,7 +135,7 @@ export patches | |||
135 | phases=nobuildPhase | 135 | phases=nobuildPhase |
136 | export phases | 136 | export phases |
137 | pkg=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0 | 137 | pkg=/nix/store/gdg97kdw8k7nqg704g4gm3cn8280bmgr-gcc-wrapper-10.2.0 |
138 | pkgsBuildHost=([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") | 138 | pkgsBuildHost=([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") |
139 | postFixupHooks=([0]="_multioutPropagateDev") | 139 | postFixupHooks=([0]="_multioutPropagateDev") |
140 | postUnpackHooks=([0]="_updateSourceDateEpochFromSourceRoot") | 140 | postUnpackHooks=([0]="_updateSourceDateEpochFromSourceRoot") |
141 | preConfigureHooks=([0]="_multioutConfig") | 141 | preConfigureHooks=([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 | %{ | ||
2 | extern int yylval; | ||
3 | %} | ||
4 | |||
5 | d [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 | |||
20 | int 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> | ||
4 | int yylex(); | ||
5 | int yyerror(char *); | ||
6 | %} | ||
7 | |||
8 | %token ADD SUB MUL DIV NUM | ||
9 | %left ADD SUB MUL DIV | ||
10 | |||
11 | %% | ||
12 | R: E { | ||
13 | printf("result: %d", $$); | ||
14 | return 0; | ||
15 | } | ||
16 | E: E ADD T { $$ = $1 + $3; } | ||
17 | | E SUB T { $$ = $1 - $3; } | ||
18 | | T | ||
19 | ; | ||
20 | T: T MUL NUM { $$ = $1 * $3; } | ||
21 | | T DIV NUM { $$ = $1 / $3; } | ||
22 | | NUM { $$ = $1; } | ||
23 | ; | ||
24 | %% | ||
25 | |||
26 | int main() { | ||
27 | yyparse(); | ||
28 | } | ||
29 | |||
30 | int 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" | ||
3 | extern 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 | |||
31 | int 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" | ||
5 | int yylex(); | ||
6 | int yyerror(char *); | ||
7 | int 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 | %% | ||
19 | primary_expr: NUM | ||
20 | | ID | ||
21 | ; | ||
22 | |||
23 | postfix_expr: postfix_expr INC | ||
24 | | postfix_expr DEC | ||
25 | | primary_expr | ||
26 | ; | ||
27 | |||
28 | unary_expr: INC unary_expr | ||
29 | | DEC unary_expr | ||
30 | | postfix_expr | ||
31 | ; | ||
32 | |||
33 | boolean_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 | |||
41 | assignment_expr: unary_expr ASSIGN unary_expr | ||
42 | | unary_expr ASSIGN boolean_expr | ||
43 | ; | ||
44 | |||
45 | expression: unary_expr | ||
46 | | boolean_expr | ||
47 | | assignment_expr | ||
48 | ; | ||
49 | |||
50 | block: '{' statement block_cont | ||
51 | ; | ||
52 | block_cont: statement block_cont | ||
53 | | '}' | ||
54 | ; | ||
55 | |||
56 | statement: expression ENDL | ||
57 | | block | ||
58 | | for_expr {loop_count++;} | ||
59 | | ENDL | ||
60 | ; | ||
61 | |||
62 | for_expr: FOR '(' statement statement expression ')' statement | ||
63 | | FOR '(' statement statement ')' statement | ||
64 | ; | ||
65 | |||
66 | %% | ||
67 | |||
68 | int main() { | ||
69 | yyparse(); | ||
70 | printf("valid expression, nested %d", loop_count); | ||
71 | } | ||
72 | |||
73 | int 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 | |||
8 | a return A; | ||
9 | b return B; | ||
10 | . return yytext[0]; | ||
11 | \n return 0; | ||
12 | %% | ||
13 | |||
14 | int 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> | ||
4 | int yylex(); | ||
5 | int yyerror(char *); | ||
6 | %} | ||
7 | |||
8 | %token A B ERR | ||
9 | |||
10 | %% | ||
11 | |||
12 | S: | ||
13 | A S B | ||
14 | | | ||
15 | ; | ||
16 | |||
17 | %% | ||
18 | |||
19 | int yyerror(char *s) { | ||
20 | printf("error: %s", s); | ||
21 | exit(0); | ||
22 | } | ||
23 | |||
24 | int 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" | ||
3 | extern 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 | |||
20 | int 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> | ||
4 | int yylex(); | ||
5 | int 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 | |||
14 | S: | ||
15 | E { printf("\n"); }; | ||
16 | E: | ||
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 | |||
27 | int main() { | ||
28 | yyparse(); | ||
29 | } | ||
30 | |||
31 | int yyerror(char *s) { | ||
32 | printf("error: %s", s); | ||
33 | exit(0); | ||
34 | } | ||
@@ -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" | ||
3 | extern int yylval; | ||
4 | %} | ||
5 | |||
6 | %% | ||
7 | a return A; | ||
8 | b return B; | ||
9 | . return yytext[0]; | ||
10 | \n return 0; | ||
11 | %% | ||
12 | |||
13 | int 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> | ||
4 | int yyerror(char *); | ||
5 | %} | ||
6 | |||
7 | %token A B | ||
8 | %start S | ||
9 | |||
10 | %% | ||
11 | |||
12 | S: C B | ||
13 | | | ||
14 | ; | ||
15 | C: A C | ||
16 | | A A A A | ||
17 | ; | ||
18 | %% | ||
19 | |||
20 | int main() { | ||
21 | yyparse(); | ||
22 | printf("valid string"); | ||
23 | } | ||
24 | |||
25 | int yyerror(char *s) { | ||
26 | printf("error: %s", s); | ||
27 | exit(0); | ||
28 | } | ||
@@ -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" | ||
3 | extern int yylval; | ||
4 | %} | ||
5 | |||
6 | %% | ||
7 | a return A; | ||
8 | b return B; | ||
9 | c return C; | ||
10 | . return yytext[0]; | ||
11 | \n return 0; | ||
12 | %% | ||
13 | |||
14 | int 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> | ||
4 | int yylex(); | ||
5 | int yyerror(char *); | ||
6 | %} | ||
7 | |||
8 | %token A B C | ||
9 | |||
10 | %% | ||
11 | S: X Y | ||
12 | | | ||
13 | ; | ||
14 | X: A X B | ||
15 | | | ||
16 | ; | ||
17 | Y: B Y C | ||
18 | | | ||
19 | ; | ||
20 | %% | ||
21 | |||
22 | int main() { | ||
23 | yyparse(); | ||
24 | printf("valid string"); | ||
25 | } | ||
26 | |||
27 | int yyerror(char *s) { | ||
28 | printf("error: %s", s); | ||
29 | exit(0); | ||
30 | } | ||
@@ -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 | } |