社保局是干什么的| 农历10月19日是什么星座| 鼻炎吃什么消炎药效果最好| 取环挂什么科| alan英文名什么意思| 这个季节吃什么水果最好| 手足口病是什么原因引起的| 微波炉可以做什么美食| 真丝和桑蚕丝有什么区别| 孕妇熬夜对胎儿有什么影响| 异地办理临时身份证需要什么材料| 水瓶座是什么星象| 小辣椒是什么意思| 失眠吃什么水果| 石字旁有什么字| 避孕套有什么作用| 菜心是什么菜| 基围虾为什么叫基围虾| 腰疼挂什么科| 篦子是什么东西| 很无奈是什么意思| 家慈是什么意思| 饭中吃药是什么时候吃| 安全是什么| 被告不出庭有什么后果| 梦见买床是什么意思| 胃气上逆吃什么中成药| 为什么会生化| 什么是窦性心律不齐| 仙灵脾又叫什么| 床塌了有什么预兆| 骨质疏松吃什么药| 鸭梨是什么颜色| 胎停有什么症状或征兆吗| 脚踏一星是什么命| 做彩超为什么要憋尿| 黄芪有什么功效| 金水宝胶囊有什么作用| 两个c交叉是什么牌子| 一是什么意思| 睡觉放屁是什么原因| 什么叫同人文| oem贴牌是什么意思| 缓刑什么意思| 经常头晕吃什么食物好| 乌鸦长什么样| 搬家有什么讲究和忌讳| 画肖指什么生肖| 高温天气喝什么茶解暑| 隐性梅毒是什么意思| 一天吃一个苹果有什么好处| 看病人送什么| 高光是什么意思| 红参和高丽参有什么区别| 萎缩性胃炎吃什么药最好| 重度抑郁症吃什么药| 什么都能吃| 射手座属于什么星象| 裳能组什么词| 补铁的药什么时候吃最好| 下巴下面长痣代表什么| 皮肤白斑是什么原因| 什么是川崎病是什么病| 氯化钙是什么| 顾虑是什么意思| 肉卷炒什么菜好吃| 澳大利亚人说什么语言| 云丝是什么| 严密是什么意思| ed是什么| 龙王庙是指什么生肖| 鬼死了叫什么| 钾高是什么原因引起的| 吃薄荷对人身体有什么好处| 肺结节吃什么中成药| 走四方是什么生肖| 珍惜当下是什么意思| 脸红什么| 液体面包是什么| 三文鱼配什么酒| 碳素笔是什么笔| 奥美拉唑与雷贝拉唑有什么区别| 爱爱是什么感觉| 咽颊炎吃什么药| 卒中中心是干什么的| 7月25日是什么星座| 阑尾炎挂什么科室| 做蹲起有什么好处| 肠胃感冒吃什么药最好| r商标是什么意思| 胃气上逆是什么原因| 女人吃什么养颜又美白| 621什么星座| 布加综合征是什么病| 定心丸什么意思| 什么是耐药性| 打嗝吃什么药效果好| 瓜子脸适合剪什么发型| 绿豆汤不能和什么一起吃| 抗炎是什么意思| 丹凤眼是什么样| 熟石灰是什么| 1024是什么星座| 猪精是什么| 刚出生的宝宝要注意什么| 披什么散什么| 男人额头凹陷预示什么| 自来卷的头发适合什么发型| 仓鼠爱吃什么| 腈纶是什么面料| 自己是什么意思| 凹是什么意思| 嗓子疼吃什么药最管用| 化工厂是干什么的| 7o年属什么生肖| 红苋菜不能和什么一起吃| 小青柑是什么茶类| 10月21日是什么星座| 耳鸣脑鸣是什么原因引起的| 腹泻什么意思| 鸡的祖先是什么| 户口是什么意思| 尿分叉是什么原因| 乙肝表面抗体阴性什么意思| 申属于五行属什么| 两个水念什么| 腊八有什么讲究| 女人眼角有痣代表什么| 不想怀孕有什么办法| 吃鱼对身体有什么好处| 有什么办法可以怀孕| 艾迪生病是什么病| 7月14什么星座| 耳鸣吃什么药| 彩礼什么时候给女方| 什么什么不断| 互联网是干什么的| 分散片是什么意思| 误机是什么意思| 2月14日什么星座| 女性什么时间是排卵期| 常喝黑苦荞茶有什么好处| 汉族人是什么人种| 为什么会拉血| 姘头是什么意思| 猪油吃多了有什么好处和坏处| bb粥指的是什么意思| 翡翠是什么材质| 硬性要求是什么意思| 布病是什么症状| 儿童坐飞机需要带什么证件| s档是什么档| 朋友搬家送什么礼物好| 老是打哈欠是什么原因| 猪鬃为什么是战略物资| 螃蟹不能和什么食物一起吃| 须尽欢什么意思| 生抽和老抽有什么区别| 薄荷叶泡水喝有什么好处| 精益求精下一句是什么| pmi是什么| ysl是什么牌子| sd值是什么意思| 贸易壁垒是什么意思| 独显是什么意思| 你为什么| 梦见好多衣服是什么意思| dx是什么意思| 王字旁一个行念什么| 什么猫最好养| 笔记本电脑什么品牌好| 龙生九子下一句是什么| 果五行属什么| 黑色上衣配什么颜色的裤子| 推拿和按摩有什么区别| 蚂蚁搬家是什么意思| 为什么医院不建议药流| 未曾谋面什么意思| 无以言表是什么意思| 户籍所在地是指什么| 六神无主是什么生肖| 减肥期间能吃什么水果| 战国时期是什么时候| 碳素墨水用什么能洗掉| 手脚浮肿是什么原因引起的| 吃猪皮有什么好处和坏处| 阳寿是什么意思| 卵巢囊肿术后吃什么食物好| sandals是什么意思| 空调嗡嗡响是什么原因| 尿酸高是为什么| 西红柿和番茄有什么区别| 中秋节送什么水果好| 转网是什么意思| 叛逆是什么意思| 艮五行属什么| 宝宝大便发白是什么原因| whoo是什么牌子| 效果是什么意思| 九月二十号是什么星座| 非营运车辆是什么意思| 胆固醇高吃什么食物最好| 蜻蜓点水是什么生肖| 食少便溏是什么意思| 什么笔不能写字| 宫寒可以吃什么水果| 婧字五行属什么| 克加寸念什么| 牙齿过敏吃什么药| 大暑是什么意思啊| 绞肠痧是什么病| 鸽子是什么意思| 甲减有什么症状表现| 吃什么油好| 今天冲什么生肖| 降钙素原偏高说明什么| 985是什么学校| 喝冰美式有什么好处| 40什么意思| 石灰的主要成分是什么| 早餐做什么简单又好吃| g750和au750有什么区别| 月经多是什么原因| 二级警监是什么级别| 海黄瓜是什么| 小腹胀痛什么原因| 宝宝干呕是什么原因| 蒲公英是什么样子| 女人梦见老鼠什么征兆| 养什么鱼招财转运| 为什么叫买东西不叫买南北| 吃什么对头发好| 泰安有什么大学| 什么是积食| 世界上最软的东西是什么| c4是什么驾驶证| 秘书是什么意思| 胎位左枕前是什么意思| 双鱼和什么星座最配| 芒果过敏用什么药| 咳嗽不停是什么原因| via什么意思| 婚车头车一般用什么车| 血小板低会有什么症状| otc是什么意思| 福报是什么意思| 梦见手抓屎是什么意思| 脊柱侧弯拍什么片子| 6月22号是什么星座| 逸搏心律什么意思| 宝宝咬人是什么原因| 老气横秋是什么意思| 内分泌代谢科是看什么病的| 什么是绘本| 食物中毒吃什么解毒最快| 157是什么意思| 螳螂喜欢吃什么| 为什么爱出汗| 野格是什么酒| ABA是什么植物激素| 为什么做着做着就软了| m2是什么意思啊| 阴茎插入阴道什么感觉| 汴去掉三点水念什么| 百度
Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
{from an alt.perl post I just made, reposted here to solicit feedback from fellow monks...}

>>>>> "Makhno" == Makhno <mak@imakhno.freeserve.co.uk> writes: Makhno> I'm thinking of writing a GUI Perl-syntax-aware editor, and Makhno> wondering what's the best way to parse perl? Highlighting Makhno> reserved words is easy (using, eg, index()) but indentifying Makhno> things like comments is a bit more difficult. Makhno> A regex like /#.*\n/ will catch comments when they are used Makhno> simply, ie: Makhno> print "hello\n"; #print hello Makhno> but will get it wrong when the '#' is used as part of a regex Makhno> (or in a string) Makhno> s#hello#goodbye#; Makhno> print "will behave like a #comment"; Makhno> Does anybody have any ideas on how I go about parsing perl Makhno> syntax in such a way, before I go to a lot of potentially Makhno> unnecessary work?
Perl is extremely difficult to parse. In fact, some would say impossible.

One thing that makes it difficult is the dual nature of a half dozen characters like "/". If that / is being used in a place that's expecting an operator, it's divide. If it's being used in a place that's expecting an operand, it's the beginning of a regular expression. So you have to keep track at all times of whether you're looking for an operator or an operand.

"No problem", you say? Quick... for the following, play the game of "regex or divide?"

sin / ... time / ... localtime / ... caller / ... eof / ...
Got those right? How about these?
use constant FOO => 35; FOO / ... use Fcntl qw(LOCK_SH); LOCK_SH / ...
OK, and now some of your own:
sub no_args (); sub one_arg ($); sub normal (@); no_args / ... one_arg / ... normal / ...
Got those too? How about these (same problem, different file):
use Random::Module qw(aaa bbb ccc); aaa / ... bbb / ... ccc / ...
A little harder, eh? So now you have to parse OUTSIDE the file to get your answer. And as if that wasn't enough, let's get weird:
BEGIN { eval (time % 2 ? 'sub zany ();' : 'sub zany (@);'); } zany / ...
Quick, was that last one a divide or a regex start?

Why does it matter? Look at this:

sin / 25 ; # / ; die "this dies!"; time / 25 ; # / ; die "this doesn't die";
The first one is computing the sin of the true/false value gotten by matching " 25 ; # " against $_. Then it dies. The second one is computing the time of day divided by 25, then ignoring the comment.

Starting to see the trouble?

This leads people to say "the only thing which can parse Perl (the language) is perl (the binary)". Maybe not for Perl6. But for the Perl we know and can use today, certainly so.

-- Randal L. Schwartz, Perl hacker


In reply to On Parsing Perl by merlyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and all is quiet...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2025-08-07 02:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.


      打鼾挂什么科 烁字五行属什么 尿维生素c弱阳性是什么意思 多愁善感什么意思 假借是什么意思
      身不由己是什么生肖 汗多是什么原因 快递客服主要做什么 结节性硬化症是什么病 漏斗胸为什么长不胖
      抗宫炎软胶囊主要治什么 50分贝相当于什么声音 父亲节送什么好 经常低血糖是什么原因 长春有什么好吃的
      下午18点是什么时辰 gopro是什么 血管硬化吃什么能软化 狼入虎口是什么意思 公卿是什么意思
      死鬼什么意思hcv8jop0ns2r.cn 西兰花和什么菜搭配hcv7jop6ns1r.cn 吃三七有什么功效hcv8jop4ns3r.cn 鸭屎香为什么叫鸭屎香imcecn.com 宫腔占位什么意思baiqunet.com
      淋巴细胞百分比偏高是什么意思hcv8jop5ns5r.cn 蓓字五行属什么shenchushe.com 头发是什么组织hcv8jop6ns8r.cn 疱疹是一种什么病hcv9jop6ns8r.cn 女生下体长什么样子hcv9jop0ns0r.cn
      炁是什么意思hcv8jop5ns3r.cn 早上八点到九点属于什么时辰hcv8jop7ns1r.cn 总胆固醇低是什么原因hcv9jop6ns6r.cn 现在是什么季节hcv9jop6ns7r.cn 肺部感染有什么症状xinmaowt.com
      尿蛋白阴性是什么意思cl108k.com 什么路最窄打一生肖hcv7jop5ns2r.cn 牛属相和什么属相配hcv9jop0ns8r.cn 降尿酸吃什么药hcv7jop4ns5r.cn 缺钾吃什么水果hcv8jop4ns8r.cn
      百度