what is the procedure to separate the identifier from any program?
i want to implement the following .how would i do this in c ?
id ::= letter { letter | digit | _ } | _main
letter ::= a | b | c | d | e | f | g | h | i | j | k | l |
m | n | o | p | q | r | s | t | u | v | w | x |
y | z |
A | B | C | D | E | F | G | H | I | J | K | L |
M | N | O | P | Q | R | S | T | U | V | W | X |
Y | Z
digit ::= 0 | 1 | 开发者_StackOverflow中文版2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
That a specification for a lexical analyser, something which takes a sequence of characters and turns them into lexical elements (or tokens).
Writing a lexical analyser is not a task for the faint of heart and, if you're asking this question, you may want to look into lex or flex to assist you :-) If you have to do it yourself in C, you should investigate finite state machines - these will allow you to convert the textual elements into lexical tokens.
What this is most likely saying is that an identifier consists of either a letter followed by a (possibly optional) letter, digit or _
character or the characters _main
(or the token _main
, it's not clear without further information.
Another example may be something like:
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
integer ::= digit+
float ::= integer '.' integer
which defines:
- a
digit
as one of the numeric characters. - an
integer
as a sequence of one or more digits. - a
float
as two integers separated by the.
character.
精彩评论