لقطة شاشة ٢٠٢٤-٠٣-٢١ في ٩.١٢.٣٢ ص
لقطة شاشة ٢٠٢٤-٠٣-٢١ في ٩.١٢.٣٢ ص
■ Type the password for your Linux Account and press Enter, if ask for your password.
■ Type “y” and press Enter, ifask for your permissions to update.
20
3. Setting up Lex and Ycc Tools via Terminal
Commands.
22
LEX
1. Lex: a tool for automatically generating a lexer or scanner given a lex
specification (.l file)
%}
[DEFINITION SECTION]
%%
[RULES SECTION]
%%
[RULES SECTION]
%%
For example:
%%
%%
x|y x or y
{i} definition of i
x{m,n} m to n occurrences of x
"s" exactly what is in the quotes (except for "\" and following character)
– meta-characters (do not match themselves, because they are used in the
preceding reg exps):
» ( )[]{}<>+/,^*|. \"$?-%
• an integer: 12345
[1-9][0-9]*
• a word: cat
[a-zA-Z]+
[-+]?[1-9][0-9]*
[0-9]*”.”[0-9]+
(c: character, x,y: regular expressions, s: string, m,n integers and i: identifier).
5. xy concatenation of x and y
6. x* same as x*
8. x? an optional x (same as x+ )
1. lex will always match the longest (number of characters) token possible.
2. If two or more possible tokens are of the same length, then the token with the
regular expression that is defined first in the lex specification is favored.
• white space
[ \t]+
Special Functions
• yytext
– where text matched most recently is stored
• yyleng
– number of characters in text most recently matched
• yylval
– associated value of current token
• yymore()
– append next string matched to current contents of yytext
• yyless(n)
– remove from yytext all but the first n characters
• unput(c)
– return character c to input stream
• yywrap()
– may be replaced by user
– The yywrap method is called by the lexical analyser whenever it inputs
an EOF as the first character when trying to match a regular expression