更新时间:2022-02-23 00:14:06
There is a basic implementation of a lexical scanner in the examples section of the bison manual. (Slightly less basic versions are later in the manual.)
这不会直接为您提供帮助,因为它基于fscanf
,这意味着它适用于输入流.大多数C库包含使您可以将字符串视为FILE*
的函数(例如,参见Posix标准
That won't help you directly because it is based on fscanf
, which means that it works on an input stream. Most C libraries contain functions which let you treat a character string as a FILE*
(see, for example, the Posix standard fmemopen). Failing that, you'd have to replace the getc and scanf calls with string based alternatives, which means you will need to keep track of a buffer and input pointer somewhere. strtoul
(or strtod
) will prove useful because the second argument helps you keep track of how much of the string was used by the number.