coco/r笔记-扫描器的字符规则定义

本文详细介绍了扫描器规格定义的基本概念及其组成部分,包括字符集声明、令牌声明等,并通过实例展示了如何定义字符集。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

扫描器的字符规则定义

Scanner Specification
A scanner has to read source text, skip meaningless characters, recognize tokens and
pass them to the parser. This is described in a scanner specification, which consists of
five optional parts:
ScannerSpecification =
["IGNORECASE"]
["CHARACTERS" {SetDecl}]
["TOKENS" {TokenDecl}]
["PRAGMAS" {PragmaDecl}]
{CommentDecl}
{WhiteSpaceDecl}.
2.3.1 Character sets
This section allows the user to declare character sets such as letters or digits. Their
names can then be used in the other sections of the scanner specification. Coco/R
supports the Unicode character set (UTF-8-encoded).
SetDecl = ident '=' Set '.'.
Set = BasicSet {('+'|'-') BasicSet}.
BasicSet = string | ident | char [".." char] | "ANY".
SetDecl associates a name with a character set. Basic character sets are denoted as:
string a set consisting of all the characters in the string
ident a previously declared character set with this name
char a set containing the character char
char1..char2 the set of all characters from char1 to char2
ANY the set of all characters in the range 0 .. 65535
Character sets may be formed from basic sets using the operators
+ set union
- set difference
Examples
digit = "0123456789". /* the set of all digits */
hexDigit = digit + "ABCDEF". /* the set of all hexadecimal digits */
letter = 'A' .. 'Z'. /* the set of all upper case letters */
eol = '/r'. /* the end-of-line character */
noDigit = ANY - digit. /* any character that is not a digit */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值