【问题标题】:Parsing a text file to SQLite so the data can be queried using objective c?将文本文件解析为 SQLite,以便可以使用目标 c 查询数据?
【发布时间】:2012-02-08 00:25:52
【问题描述】:

使用objective-c,我希望将不同数量的文本文件解析到SQLite 数据库,然后查询这些数据。文本将采用以下格式:

PokerStars Hand #74875631942:  Hold'em No Limit ($0.50/$1.00 USD) - 2012/02/01 17:08:58 ET
Table 'Psyche II' 2-max Seat #2 is the button
Seat 1: demaredemare ($100 in chips) 
Seat 2: Bren Stokes ($100 in chips) 
Bren Stokes: posts small blind $0.50
demaredemare: posts big blind $1
*** HOLE CARDS ***
Dealt to Bren Stokes [Th 9d]
Bren Stokes: raises $2 to $3
demaredemare: folds 
Uncalled bet ($2) returned to Bren Stokes
Bren Stokes collected $2 from pot
Bren Stokes: doesn't show hand 
*** SUMMARY ***
Total pot $2 | Rake $0 
Seat 1: demaredemare (big blind) folded before Flop
Seat 2: Bren Stokes (button) (small blind) collected ($2)



PokerStars Hand #74875657847:  Hold'em No Limit ($0.50/$1.00 USD) - 2012/02/01 17:09:23 ET
Table 'Psyche II' 2-max Seat #1 is the button
Seat 1: demaredemare ($99 in chips) 
Seat 2: Bren Stokes ($101 in chips) 
demaredemare: posts small blind $0.50
Bren Stokes: posts big blind $1
*** HOLE CARDS ***
Dealt to Bren Stokes [9d Qs]
demaredemare: raises $1 to $2
Bren Stokes: calls $1
*** FLOP *** [Tc Ah 8c]
Bren Stokes: checks 
demaredemare: bets $2
Bren Stokes: calls $2
*** TURN *** [Tc Ah 8c] [4c]
Bren Stokes: checks 
demaredemare: checks 
*** RIVER *** [Tc Ah 8c 4c] [4s]
Bren Stokes: checks 
demaredemare: checks 
*** SHOW DOWN ***
Bren Stokes: shows [9d Qs] (a pair of Fours)
demaredemare: shows [3d Qh] (a pair of Fours)
Bren Stokes collected $3.82 from pot
demaredemare collected $3.82 from pot
*** SUMMARY ***
Total pot $8 | Rake $0.36 
Board [Tc Ah 8c 4c 4s]
Seat 1: demaredemare (button) (small blind) showed [3d Qh] and won ($3.82) with a pair of     Fours
Seat 2: Bren Stokes (big blind) showed [9d Qs] and won ($3.82) with a pair of Fours

由于我需要从每一行“提取”不同的信息位,我相信我需要使用解析器来执行此操作?但是我看到了一些代码,例如: NSString stringWithContentsOfFile NSArray 文件内容组件SeparatedByString NSMutableDictionary NSScanner NSBundle ......你们认为最好的解决方法是什么?非常感谢您的帮助。

热爱你的工作!

【问题讨论】:

    标签: objective-c sqlite parsing parser-generator


    【解决方案1】:

    我会使用已建立的解析器生成器来为您的输入字符串生成词法分析器和解析器。手动解析更容易出错且难以维护。

    至于使用哪个生成器的问题,您可能可以选择一点。如果您选择走这条路,重要的是为输入字符串生成语法。一旦在 BNF 的某个变体中解决了该语法,您应该可以轻松地将其转换为您选择的任何生成器。

    如果您可以考虑混合使用一点 C++,您可以使用 Boost.spirit。要开发语法本身,您可以使用久经考验的 flex/bison 路线来快速启动和运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-21
      • 2017-10-18
      • 2015-01-20
      • 2018-08-19
      • 1970-01-01
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多