开发者

Read an expression [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

开发者_开发知识库

Closed 9 years ago.

Improve this question

Can someone explain to me how can I do to read some information from a file using regex?

The information that I want to read is in this format:

INT    "integer"
FLOAT  "real"

To be more precise, I hardly know how to do this using boost, so I need help.


It appears as though the language you wish to parse using regular expressions contains a finite number of keywords follows by identifiers consisting of a subset of symbols from your alphabet surrounded by quotation marks. Here is how to think about forming such a regular expression.

Let Σ be the set of terminal characters in your language. For each identifier, you must form a regular expression that looks like

  • Rκ = κ · ' ' · " · (α ∪ β ∪ ... ∪ ψ ∪ ω)* · "

where κ is the desired keyword formed by concatenation of terminal symbols and α, β,..., ψ, ωΣ are the permissible identifier terminals. For instance, let Σ = {I,N,T,F,L,O,A,i,n,t,e,g,r,a,l,",,' '}. Then

  • RINT = I · N · T · ' ' · " · (i ∪ n ∪ t ∪ e ∪ g ∪ r ∪ a ∪ l)* · "
  • RREAL = R · E · A · L · ' ' · " · (i ∪ n ∪ t ∪ e ∪ g ∪ r ∪ a ∪ l)* · "

To form a regular expression that matches any sequence of the Rκ, merely form the Kleene closure of the union of the Rκ with whatever additions are necessary for the syntax you're working with, or the Kleene closure of the concatenation of the union of the subexpressions matching identifiers and the Kleene closure of the union of the permissible identifiers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜