LEX(1) General Commands Manual LEX(1)NAME
lex - generator of lexical analysis programs
SYNOPSIS
lex [ -tvfn ] [ file ] ...
DESCRIPTION
Lex generates programs to be used in simple lexical analyis of text. The input files (standard input default) contain regular expressions
to be searched for, and actions written in C to be executed when expressions are found.
A C source program, `lex.yy.c' is generated, to be compiled thus:
cc lex.yy.c -ll
This program, when run, copies unrecognized portions of the input to the output, and executes the associated C action for each regular
expression that is recognized.
The following lex program converts upper case to lower, removes blanks at the end of lines, and replaces multiple blanks by single blanks.
%%
[A-Z] putchar(yytext[0]+'a'-'A');
[ ]+$
[ ]+ putchar(' ');
The options have the following meanings.
-t Place the result on the standard output instead of in file `lex.yy.c'.
-v Print a one-line summary of statistics of the generated analyzer.
-n Opposite of -v; -n is default.
-f `Faster' compilation: don't bother to pack the resulting tables; limited to small programs.
SEE ALSO yacc(1)
M. E. Lesk and E. Schmidt, LEX - Lexical Analyzer Generator
LEX(1)
Check Out this Related Man Page
lex(1) General Commands Manual lex(1)Name
lex - generate lexical analyzer
Syntax
lex [-tvfn] file...
Description
The command generates programs to be used in simple lexical analysis of text. The input files (standard input default) contain regular
expressions to be searched for, and actions written in C to be executed when expressions are found.
A C source program, 'lex.yy.c', is generated. It is compiled using the following command line:
cc lex.yy.c -ll
This program copies unrecognized portions of the input to the output, and executes the associated C action for each regular expression that
is recognized.
Options-f Runs a faster compilation (does not pack resulting tables). This is limited to small programs.
-n Prints no summary information (default option).
-t Writes to standard output instead of to file
-v Prints one-line summary of generated statistics.
Examples
In the following example, the command
lex lexcommands
draws instructions from the file lexcommands, and places the output in lex.yy.c. The command
%%
[A-Z] putchar(yytext[0]+'a'-'A');
[ ]+$
[ ]+ putchar(' ');
is an example of a program that would be put into a command file. This program converts upper case to lower, removes blanks at the end of
lines, and replaces multiple blanks by single blanks.
See Alsosed(1), yacc(1)
"LEX - Lexical Analyzer Generator", Supplementary Documents, Volume 2: Programmer
lex(1)
I receive windows files via the internet on my solaris server. Since unix doesn't handle blanks well I change the blanks to ? which works just fine. I take these files and ftp them to windows so our analysts can work with them. Recently I received a file with the following structure:
... (3 Replies)
Hi all
I am using lex for my application scanning and I need to skip some lines for which I don't know the exact pattern.
So, could anybody tell me the regular expression to display lines NOT beginning with the specified pattern.
I know how to display lines beginning with the... (1 Reply)
Hi everyone,
I would like to know how to compile and run lex programs on solaris 10.
the conventional way is
$ lex <name.l>
$ cc lex.yy.c -ll
$ ./a.out
but while trying to execute the 2nd command :i get a reference saying that the command is old or that main is not supported...
Hence... (1 Reply)
Hi ,
I need to develop a parser which should match something like
1. text a=5 " a=20";
2. text a=..."
a=20";
3 text a=..."
a=20
b=34
c=12
";
I have used this regular expression in my Lex file to generate the tokens:
\".\s*.*\s.\" (8 Replies)
Hi
While installing Glimpse on Unix, I am getting the following error.
Can someone please help to resolve the same ?
flex -F -8 htuml2txt.lex
make: flex: Command not found
make: *** Error 127
make: Leaving directory `/home/user30/glimpse-4.18.6/dynfilters'
make: *** Error 2
Regards... (1 Reply)
Hey all, im trying to create a makefile in unix. cpp2html is a program created from the files cpp2html.o and lex.yy.o.
cpp2html.o is created from compiling cpp2html.c and lex.yy.o is created from another created file lex.yy.c. and lex.yy.c is created from a command "flex cppscanner.l" and here is... (1 Reply)
Hi, I want to be able to write a simple program that takes in input from the command line. I;m am at the level of getchar and putchar. Any examples would be a great help thanks.
I intend/prefer also to use the pipe command | eg: input | file1
---------- Post updated at 04:08 PM ----------... (4 Replies)
Hi everyone!
This is my very first post, sorry if I'm not posting in the right category.
I'm trying to match a newline "/n" using lex/yacc.
For example,
print(9,'\n',8)
should print
9
8
now do I write a regular expression to match exactly " '\n' "
Thanks! (1 Reply)
Hi all,
I wrote a couple noobie programs and had them compiled over Putty (using gcc), but I don't know what command I should use to run them.
Please assume that I'm a complete noob when it comes to programming and putty commands.
Thank you for your help! (1 Reply)
Alright, so I'm writing a file for the lexical analyzer (lex). It will be used to check C code (collecting the identifiers and storing those names along with the line numbers the identifier was found on). I'm not used to 'C' so I'm having some difficulty.
I am using a function (insertId()) to... (4 Replies)
Florida State University, Tallahassee, FL USA, Dr. Whalley, COP4342
1. The problem statement, all variables and given/known data:
Create a lex specification file that reads a C source program that ignores keywords and collects all identifiers (regular variable names) and also displays the line... (3 Replies)
Hello
I have a questions and m stuck on it.
Theoritcally the phases of compiler.
1. Lexical analyis -- genrates tokes
NOW MY QUESTION IS: where i can see these token if i make a simple C program.
Please guys tell me step to see it. and other phases too.
your help will be appreciated... (1 Reply)
Well as the title describes, its a pretty straight forward problem. I have a series of psql tables where there are lots of blanks. However there is at least one column, called name, that will never be blank. I want to write a select statement to get all of the contents of the table and then turn... (3 Replies)
Greetings all
I have a delimited text file (the delimiter is ';') where certain fields consist of many blanks e.g. ; ; and ; ;
Before I separate the data I need to eliminate these blanks altogether.
I tried the sed command using the following syntax:
sed -i 's/; *;/;;/g' <filename>
... (15 Replies)
I have a test file a.txt
001 123 456 789
002 This is just a
001 test data
003 file.
I want to clear columns 5 and 6 if the first 3 characters are 001 using awk.
I tried following but does not work. Any suggestions?
awk 'BEGIN{OFS=FS=""} {if (substr($0,1,3)=="123") $5=" "; $6="... (20 Replies)