お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"RE:HTLM の TABLE タグを解析(2)"

この発言は
#00954 DUDE さんのHTLM の TABLE タグを解析
に対するコメントです

この発言に対し以下のコメントが寄せられています
#00962 DUDE さん RE^2:HTLM の TABLE タグを解析(2)

1つ上のソースの続きです。 pars.y と main.pas です。 <---- pars.y ---- /* HTML TABLE tag parser for sample-gura. Written by Yutaka Iizuka(DUDE) */ %{ unit pars; interface uses SysUtils, Dialogs, ComCtrls, YaccLib, LexLib, Main; function yyparse : Integer; procedure yyinit; var CurrentTable:array [0..15] of TTreeNode; CurrentTablePointer:Integer; CurrentRow:array [0..15] of TTreeNode; CurrentRowPointer:Integer; CurrentCell:array [0..15] of TTreeNode; CurrentCellPointer:Integer; implementation %} %token TABLE _TABLE %token TR _TR %token TH _TH %token TD _TD %token <ShortString> SP %token <ShortString> CH %token ILLEGAL %type <ShortString> string %% s : /* empty */ | s element ; element : table | string { Form1.TreeView1.Items.AddChild(nil, $1); } ; table : table_begin table_rows table_end | table_begin error table_end { ShowMessage(Format('error at line %d : %s',[yylineno, yyline])); yyerrok; } ; table_begin : TABLE { Inc(CurrentTablePointer); CurrentTable[CurrentTablePointer] := Form1.TreeView1.Items.AddChild(CurrentCell[CurrentCellPointer], '<TABLE>'); } ; table_end : _TABLE { Dec(CurrentTablePointer); } ; table_rows : /* empty */ | table_rows table_row ; table_row : tr_begin table_data_list tr_end | SP ; tr_begin : TR { if CurrentTablePointer > 0 then begin Inc(CurrentRowPointer); CurrentRow[CurrentRowPointer] := Form1.TreeView1.Items.AddChild(CurrentTable[CurrentTablePointer], '<TR>'); end; } ; tr_end : _TR { Dec(CurrentRowPointer); } | /* </TR> tag omitted - causes 1 shift/reduce conflict */ { Dec(CurrentRowPointer); } ; table_data_list : /* empty */ | table_data_list table_data ; table_data : th_begin table_string th_end | td_begin table_string td_end | SP ; th_begin : TH { if CurrentRowPointer > 0 then begin Inc(CurrentCellPointer); CurrentCell[CurrentCellPointer] := Form1.TreeView1.Items.AddChild(CurrentRow[CurrentRowPointer], '<TH>'); end; } ; th_end : _TH { Dec(CurrentCellPointer); } ; td_begin : TD { if CurrentRowPointer > 0 then begin Inc(CurrentCellPointer); CurrentCell[CurrentCellPointer] := Form1.TreeView1.Items.AddChild(CurrentRow[CurrentRowPointer], '<TD>'); end; } ; td_end : _TD { Dec(CurrentCellPointer); } ; table_string : /* empty */ | table_string string { if CurrentCellPointer > 0 then begin if Trim($2) <> '' then Form1.TreeView1.Items.AddChild(CurrentCell[CurrentCellPointer], $2); end; } | table_string table ; string : CH { $$ := $1; } | SP { $$ := $1; } | string CH { $$ := $1 + $2; } | string SP { $$ := $1 + $2; } ; %% procedure yyinit; var I:Integer; begin for I := Low(CurrentTable) to High(CurrentTable) do CurrentTable[I] := nil; CurrentTablePointer := 0; for I := Low(CurrentRow) to High(CurrentRow) do CurrentRow[I] := nil; CurrentRowPointer := 0; for I := Low(CurrentCell) to High(CurrentCell) do CurrentCell[I] := nil; CurrentCellPointer := 0; end; {$I token.pas} <---- main.pas ---- unit Main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; TreeView1: TTreeView; procedure Button1Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.DFM} uses Pars, LexLib, YaccLib; procedure TForm1.Button1Click(Sender: TObject); var OD:TOpenDialog; OutFileName:string; begin OD := TOpenDialog.Create(Self); try OD.Options := [ofHideReadOnly]; OD.Filter := 'HTML Files|*.html;*.htm|Text Files|*.txt'; if OD.Execute then begin TreeView1.Items.BeginUpdate; try TreeView1.Items.Clear; finally TreeView1.Items.EndUpdate; end; yyinit; AssignFile(yyinput, OD.FileName); Reset(yyinput); OutFileName := ChangeFileExt(OD.FileName, '.out'); AssignFile(yyoutput, OutFileName); Rewrite(yyoutput); if yyparse = 0 then begin DeleteFile(OutFileName); end; TreeView1.Items.BeginUpdate; try TreeView1.FullExpand; finally TreeView1.Items.EndUpdate; end; end; finally OD.Free; end; end; end. Original document by DUDE 氏 ID:(PFF01344)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum