什么是魔法背后的逃脱(\)角色 [英] What's the Magic Behind Escape(\) Character

查看:188
本文介绍了什么是魔法背后的逃脱(\)角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C / C ++编译器如何在源代码中操作转义字符[\]?如何编写用于处理该字符的编译器语法?编译器在遇到该字符后会做什么?

How does the C/C++ compiler manipulate the escape character ["\"] in source code? How is compiler grammar written for processing that character? What does the compiler do after encountering that character?

推荐答案

大多数编译器分为几部分:编译器前端称为词汇分析器或扫描仪。编译器的这部分读取实际的字符并创建令牌。它有一个状态机,在看到转义字符时,决定它是否是真的(例如当它出现在字符串中时)或者修改下一个字符。令牌相应地作为转义字符或其他令牌(如标签或换行符)输出到编译器的下一部分(解析器)。状态机可以将多个字符组合成令牌。

Most compilers are divided into parts: the compiler front-end is called a lexical analyzer or a scanner. This part of the compiler reads the actual characters and creates tokens. It has a state machine which decides, upon seeing an escape character, whether it is genuine (for example when it appears inside a string) or it modifies the next character. The token is output accordingly as the escape character or some other token (such as a tab or a newline) to the next part of the compiler (the parser). The state machine can group several characters into a token.

这篇关于什么是魔法背后的逃脱(\)角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆