Regular scanner vs Lex
Författare
Jesus Alvarez
Last Updated
för 6 år sedan
Licens
Creative Commons CC BY 4.0
Sammanfattning
comparison of lex and a c scanner
comparison of lex and a c scanner
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%2345678901234567890123456789012345678901234567890123456789012345678901234567890
% 1 2 3 4 5 6 7 8
\documentclass[letterpaper, 10 pt, conference]{ieeeconf} % Comment this line out
% if you need a4paper
%\documentclass[a4paper, 10pt, conference]{ieeeconf} % Use this line for a4
% paper
\IEEEoverridecommandlockouts % This command is only
% needed if you want to
% use the \thanks command
\overrideIEEEmargins
% See the \addtolength command later in the file to balance the column lengths
% on the last page of the document
\usepackage{graphicx}
\graphicspath{ {images/} }
% The following packages can be found on http:\\www.ctan.org
%\usepackage{graphics} % for pdf, bitmapped graphics files
%\usepackage{epsfig} % for postscript graphics files
%\usepackage{mathptmx} % assumes new font selection scheme installed
%\usepackage{times} % assumes new font selection scheme installed
%\usepackage{amsmath} % assumes amsmath package installed
%\usepackage{amssymb} % assumes amsmath package installed
\title{\LARGE \bf
Regular scanner vs Lex
}
\author{Jesus Alvarez}
\begin{document}
\maketitle
\thispagestyle{empty}
\pagestyle{empty}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{abstract}
This paper will try to determine if the use of lex is faster than a c code implementation for a basic scanner
\end{abstract}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{INTRODUCTION}
When trying to create a compiler one of the first steps to be able to make one is to generate a lexical analyzer which purpose is to scan through an input set of characters and be able to classify them.
\section{PROBLEM}
While creating a basic scanner is quite simple in a c code, because the scanner is one of the fundamentals and it has to interpret the input as whole, optimization is something that is very critical in this part as a little bit of difference in time can affect performance of the compiler in production use. Lex offers a way to generate a scanner that can do the same as a c code and more by using regular expressions. The main issue to discuss is if lex really offers an advantage over a plain c code.
\section{SOLUTION}
In order to prove this it is necessary to test the time it takes to process a file in which both do the same level of analysis and abstraction. The analyzed input will be a set of randomly generated code snippets that are analyzed by both. Time command will be used to know how much total time as well as CPU time (user + sys) it takes for each one to execute with the same input.
\section{RESULTS}
\subsection{Execution with prints to console}
\includegraphics[scale=0.5]{printall}
\subsection{Execution with prints to console without line breaks}
\includegraphics[scale=0.5]{nobreak}
\subsection{Execution with no prints}
\includegraphics[scale=0.5]{noprint}
\section{CONCLUSIONS}
As seen in the graphics we can conclude that the time difference of lex and a c code is almost non-existent to the point where lex takes a tiny amount of time more. While this is true the power and ease of use of lex makes it a better option to use especially when doing more than a scanner as using it paired with YACC allows to develop a more efficient basis for the compiler than doing it all in c.
\begin{thebibliography}{99}
\bibitem{c1} Hubert, B. (2004, September 20). Lex and YACC primer/HOWTO. Retrieved February 23, 2019, from https://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html
\end{thebibliography}
\end{document}