LoginSignup
0
0

file not found:大川知、鈴木大郎 著「コンパイラ 言語処理系の基礎からyacc/lexまで」近代科学社(2008)のソースをMacintoshでコンパイル(C++版) error(59)

Last updated at Posted at 2017-12-17

大川知、鈴木大郎 著 「コンパイラ 言語処理系の基礎からyacc/lexまで」近代科学社(2008)のソースをMacintoshでコンパイルする(C++版)

ソースコードは近代科学社のsuppportにある。

学内での利用を前提としている。「学外での配布を禁止」している。
[リンク]https://www.kindaikagaku.co.jp/support/compiler_kindaikagaku.zip

ダウンロードして解凍する。さらに、フォルダの中のtglc-c++.tar.gzも解凍し、コンパイルしてみる。

cd compiler_kindaikagaku
tar -xzf tglc-c++.tar.gz
cd tglc/src
make

道具類が揃っておらず、

interpreter.cc:13:10: fatal error: 'X11/Xlib.h' file not found #include
といったコンパイルエラーなどが出たら。

準備1。yacc導入。名前はbison

brew install bison

準備2.flex導入。

brew install flex

準備3. リンク時にX11のライブラリを使用している。X11を導入。名前はxquartz。

brew cask install xquartz

準備4. 環境設定 INCLUDE

$ printenv

コマンドを実行し、

INCLUDE=/opt/X11/include

という項目があればOK。なければ追加。他の設定は消さずに追加設定すること。

$ vi ~/.bash_profile
export INCLUDE=-I/opt/X11/include:$INCLUDE

「esc」「:」「w」「q」

$ source ~/.bash_profile

あるいは

FLAGS =

FLAGS = -I/opt/X11/include

と追記する。

準備5 Clang++が入っていれば

CC = g++

CC = clang++

と変更しても良い。

main関数でエラーが出れば、次のように先頭にintを追加し関数の終わりにreturn argc;を追記。

tgl.y
...
int main(int argc, char **argv) 
...
return argc;
}
...

argcを返しているのは一つの技法。ここでは議論しない。

Q&A

なぜOSおよび言語の関連する試験プログラムではmainでargcを返すか。 
https://researchmap.jp/jo16jmzyy-1797580/#_1797580

#すべての例を順次実行するシェルスクリプト。例えば名前をtgl.shにする。

tgl.sh
./tglc ../sample/asteroid.tgl	
./tglc ../sample/epicycl.tgl	
./tglc ../sample/key.tgl		
./tglc ../sample/rect.tgl	
./tglc ../sample/sin2.tgl
./tglc ../sample/c.tgl		
./tglc ../sample/hilbert.tgl	
./tglc ../sample/koch.tgl	
./tglc ../sample/sin.tgl		
./tglc ../sample/spiral.tgl

実行権限を与える

$ chmod +x tgl.sh

一枚画像を表示して、閉じると次の処理をする。

文字コードのエラー

エラーなどが出たら、文字コード変換のcvfilesで文字コードを指定する。src, sampleの両方のコードを一括変換してくれる。README-C++ファイルに記載あり。文字コード(utf8, sjis, jis , euc),改行コード(unix, win, mac)

$ cvfiles 文字コード 改行コード

上記スクリプトはnkfを使っている。

nkfがなければ導入。nkfなしでcvfilesを実行すると、すべてのファイルを0バイトにしてくれる。泣)

$ brew install nkf

参考1。 brewの導入方法

[リンク]https://qiita.com/megu_ma/items/820695ac525030285682

参考2。Xcodeの導入。下記からダウンロード。

[リンク]https://developer.apple.com/jp/xcode/

参考3。xcodeではなく、llvm/clang ++を使うためにllvmを導入する場合は

$ brew install --with-clang llvm

PATH
INCLUDE
LIB
などの設定が必要かも。

$ clang++ -v
$ make -v
$ flex -v
$ bison -v

などでそれぞれの道具類の版を出力し記録すると良い。

参考文献

参考1。 brewの導入方法
[リンク]https://qiita.com/megu_ma/items/820695ac525030285682

参考2。Xcodeの導入。下記からダウンロード。
[リンク]https://developer.apple.com/jp/xcode/

言語を作る!bisonとflexを使ってみた
https://qiita.com/toru0408/items/483c77cb76198d4c6ceb

構文解析ツール『Lex&Yacc』の簡易版をアプリに埋め込む
https://qiita.com/tohmas/items/d0a2a6a7b560c9fa8ffb

goyaccを使う
https://qiita.com/draftcode/items/c9f2422fca14133c7f6a

C++でbison(パーサジェネレーター)を使う
https://qiita.com/tosyama/items/6766321025c6a2875109

goyaccで構文解析を行う
https://qiita.com/k0kubun/items/1b641dfd186fe46feb65

CGoでYacc & Bison
https://qiita.com/chobie@github/items/8bc8d1c7104f0a3ad3fe

Markdown記法の一部を理解してHTMLに変換する処理をyacc,lexで実装してみる
https://qiita.com/toshiya/items/7fa39bd9c06fc1c0a44c

FlexとBisonをVisualStudio2017で使う
https://qiita.com/alphya/items/ca668c1315e23dac6e15

自己参照

物理記事 上位100
https://qiita.com/kaizen_nagoya/items/66e90fe31fbe3facc6ff

数学関連記事100
https://qiita.com/kaizen_nagoya/items/d8dadb49a6397e854c6d

言語・文学記事 100
https://qiita.com/kaizen_nagoya/items/42d58d5ef7fb53c407d6

医工連携関連記事一覧
https://qiita.com/kaizen_nagoya/items/6ab51c12ba51bc260a82

通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7

自動車 記事 100
https://qiita.com/kaizen_nagoya/items/f7f0b9ab36569ad409c5

日本語(0)一欄
https://qiita.com/kaizen_nagoya/items/7498dcfa3a9ba7fd1e68

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

仮説(0)一覧(目標100現在40)
https://qiita.com/kaizen_nagoya/items/f000506fe1837b3590df

安全(0)安全工学シンポジウムに向けて: 21
https://qiita.com/kaizen_nagoya/items/c5d78f3def8195cb2409

Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

OSEK OS設計の基礎 OSEK(100)
https://qiita.com/kaizen_nagoya/items/7528a22a14242d2d58a3

通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.

文献履歴

ver, 1.00 初稿 2017/12/28
ver, 1.01 shell指定 2018/03/28
ver. 1.02 ありがとう追記 20230511

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0