查胃病做什么检查合适| 十万个为什么儿童版| 跌宕起伏什么意思| 冬阴功汤是什么味道| 什么是红肉| 甲亢是一种什么病严重吗| 氧气湿化瓶里加什么水| 心跳加速心慌吃什么药| 盆腔炎是什么引起的| 游走性疼痛挂什么科| 头晕眼睛模糊是什么原因| 陶渊明是什么派诗人| 塔罗是什么意思| 收放自如是什么意思| 最多是什么意思| 爱屋及乌是什么意思| 足金什么意思| 九王念什么| 岩茶属于什么茶| 囊肿挂什么科| 打呼噜的原因是什么| 药物流产最佳时间什么时候| 五月二十九是什么日子| 黄色鞋子配什么颜色裤子| 切糕为什么这么贵| 黄柏的功效与作用是什么| 法国鳄鱼属于什么档次| 遗精是什么原因引起的| 身份证最后一位x是什么意思| 凝血五项是检查什么病| 脚心发热是什么原因| 什么是负离子| 58什么意思| 芊芊学子是什么意思| 日照香炉生紫烟的香炉是什么意思| 体寒吃什么好| 四面受敌是什么动物| 食管鳞状上皮增生是什么意思| 什么是有限公司| 守宫砂是什么| 脚气脱皮用什么药最好| 老年人腿无力是什么原因导致的| 心悸心慌焦虑吃什么药能缓解| 乙肝两对半145阳性是什么意思| 水里有什么| 对口升学什么意思| 马车标志是什么品牌| 台州为什么念第一声| 抹胸是什么| 70年属狗的是什么命| 警察和公安有什么区别| 持续低烧不退是什么原因| 芭乐什么味道| 乐哉是什么意思| 肌酐高是什么原因| 母亲节在什么时候| 胸长什么样| d代表什么| kiv是什么车| 吃杏有什么好处| 血稠吃什么食物好得快| 侃大山什么意思| 11月28是什么星座| 玄关挂什么装饰画好| 双子座是什么象| 什么原因导致月经量少| 血小板高是什么病| 什么将什么相| 炖牛骨头放什么调料| 爸爸是什么意思| 什么是玻尿酸| 磕头虫吃什么| 朝代表什么生肖| 什么是植物油| 一个口一个且念什么字| 秉着是什么意思| 什么是胃肠型更年期| 谷草谷丙比值偏高代表什么| 同房什么意思| 海鸥手表是什么档次| 无的放矢是什么意思| 口苦是什么问题| 未免是什么意思| 淋巴细胞比率偏高是什么意思| 看不起是什么意思| 冰冻三尺的下一句是什么| evisu是什么牌子| 人突然瘦了要检查什么| 静修是什么意思| 现在吃什么水果| as是什么病| 喜人是什么意思| 手指关节痛吃什么药好| 九点是什么时辰| 小孩吃什么补脑更聪明| 肩周炎看什么科| 为什么十五的月亮十六圆| 唐朝灭亡后是什么朝代| audrey是什么意思| 信阳毛尖属于什么茶| 忘忧草是什么意思| 半月板后角变性什么意思| 洗牙有什么危害吗| 八月十五是什么星座| 备孕前需要做什么检查| 甲状腺阳性是什么意思| 刘备的儿子叫什么| 床虱咬了要擦什么药膏| 为什么打喷嚏| 扁桃体发炎吃什么药好得快| 小儿支气管炎咳嗽吃什么药好得快| 单亲家庭什么意思| 精美的什么| 氧化钙是什么| 隐形眼镜护理液可以用什么代替| 碳酸钠为什么显碱性| 鸡蛋不能和什么食物一起吃| 高压低是什么原因| 痛经什么原因| butter是什么意思| 直肠炎是什么原因引起的| 肝肾功能检查挂什么科| 安康鱼长什么样| 男同叫什么| 许久是什么意思| 氮泵有什么作用| 为什么不能送手表| 尿道痒男吃什么消炎药| 宫内妊娠是什么意思| 19属什么| 什么的遗产| 北京什么时候最热| 弯男是什么意思| 丝光棉是什么材质| od值是什么| 连云港有什么特产| 棉是什么面料| ppt什么意思| 吃益生菌有什么好处| 手指为什么会脱皮| 女娲补天是什么生肖| 慢性炎症是什么| 反酸是什么意思| 飞行员妻子有什么待遇| po是什么| 会厌炎吃什么药| 飞检是什么意思| 精分是什么| 种牙和假牙有什么区别| 贾珍和贾政是什么关系| 总警司相当于大陆什么官| 心眼是什么意思| 白芍的功效与作用是什么| 适宜是什么意思| 芭比q是什么意思| 梦见打牌是什么意思| 结石排出来是什么感觉| 吃什么可以修复子宫内膜| 胆碱酯酶偏高说明什么| 早早孕是什么意思| 带状疱疹什么不能吃| bi是什么意思| 三叉神经痛吃什么药效果好| 阴血是什么| 医保统筹支付什么意思| 春暖花开是什么生肖| 环磷酰胺是什么药| 什么的野鸡| 路征和景甜什么关系| 为什么不能在床上打坐| 十万为什么| 什么里什么间| 霸王别姬是什么意思| 秦始皇叫什么| 放屁臭吃什么药| 肝囊性灶是什么意思| ldpe是什么材料| 结婚年数代表什么婚| 人体缺钾是什么原因引起的| 每天头疼是什么原因引起的| 补肾吃什么药最好| 什么不什么干| 脸上爱长痘痘是什么原因| 血小板计数偏高是什么意思| 口淡无味是什么原因| 血小板过低有什么危害| 香草味是什么味道| 透析是什么| 女命劫财代表什么| 神机妙算是什么意思| 早泄是什么原因导致| 血小板高是什么引起的| 月经第二天属于什么期| 九岁属什么生肖| 接下来有什么节日| 西洋菜是什么菜| 男男叫什么| 什么驴技穷成语| 屁股疼什么原因| 磨牙齿是什么原因| 梦见卖东西是什么意思| 太阳是什么| 低血糖吃什么最快缓解| mr什么意思| 骑乘是什么意思| 什么什么于怀| 三次元是什么意思| 男人身体虚吃什么补| 六月十号是什么星座| 什么是漂洗| 脑震荡吃什么药| 淋巴是什么东西| 做梦梦见好多蛇是什么预兆| 柿子叶有什么功效| 什么机油好| 睾丸小是什么原因| 怀孕做糖耐是检查什么| 口腔溃疡要吃什么药| add什么意思| 清炖排骨放什么调料| 佝偻病是什么症状| cognac是什么酒| 脚臭是什么原因| 为什么尿有点偏红色| 豆沫是什么做的| nf是什么单位| 守宫砂是什么| 什么时候入秋| 内膜薄吃什么增长最快| 琉璃色是什么颜色| 羊肉和什么不能一起吃| 取保候审是什么意思还会判刑吗| 腋下是什么部位| 洗洗睡吧什么意思| 晚上吃什么不会胖| 肌电图挂什么科| 山鬼是什么| 胃疼吃什么止痛药| 提心吊胆是什么意思| 心穷是什么意思| 脑死亡是什么原因引起的| 为什么记忆力很差| 是什么星座| 离婚带什么证件才能办理| 西洋菜俗称叫什么| 什么是骨质疏松| 司长是什么级别的官| 舌炎是什么症状| 迷糊是什么原因| 肚子不饿是什么原因| 产检挂什么科| 骨髓穿刺能查出什么病| 什么是roi| 女人肾虚是什么原因| 乳腺增生的前兆是什么| 烧心吃什么马上能缓解| 为什么一睡觉就做梦| 轻度强化是什么意思| 怀孕初期流产有什么症状| 九七年属什么| 西宁有什么好玩的| 十一月二十六是什么星座| 为什么会梦到自己怀孕| 吃什么能瘦| 百度
Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 taking refuge in the Monastery: (5)
    As of 2025-08-07 09:12 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.


      吃什么去胃火口臭 7是什么意思 有龙则灵的灵是什么意思 来曲唑片什么时候吃最好 转氨酶偏高是什么原因引起的
      口加一笔变成什么字 导览是什么意思 内向的人适合什么工作 上热下寒吃什么药 水疗是什么意思
      72年是什么年 得偿所愿什么意思 臭鼬是什么动物 靶子是什么意思 菠菜什么时候传入中国
      舌头发白是什么情况 传教士是什么意思 7月八号是什么星座 幡然醒悟是什么意思 5月12是什么星座
      胆固醇高不能吃什么hcv8jop3ns2r.cn 梦到买房子是什么意思hcv7jop5ns2r.cn 龙虾喜欢吃什么hcv8jop9ns7r.cn nt检查是什么hcv7jop4ns6r.cn 尿路感染是什么原因hcv9jop1ns4r.cn
      同甘共苦什么意思hcv7jop6ns7r.cn 尿是绿色的是什么原因hcv7jop9ns9r.cn 血小板低是什么引起的hcv7jop9ns9r.cn 维生素是什么hcv9jop2ns7r.cn 什么魂什么魄hcv8jop1ns0r.cn
      什么的鼓励hcv8jop5ns3r.cn 茴三硫片主治什么xinmaowt.com 人生没有什么不可放下hcv9jop0ns1r.cn 心衰是什么病hcv7jop9ns5r.cn 银杏叶是什么颜色hcv9jop2ns3r.cn
      苯三酚注射有什么用mmeoe.com 不知道为了什么520myf.com 吃炒黑豆有什么好处和坏处gysmod.com 水光针是什么hcv8jop5ns5r.cn 狗狗为什么会得细小hcv8jop2ns9r.cn
      百度