Created
November 22, 2013 16:20
-
-
Save SamuelMarks/7602557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[a4paper,11pt]{article} | |
\usepackage[english]{babel} | |
\usepackage{amsmath,amssymb,cancel,array,graphics,enumerate,fancyhdr,graphviz,psfrag,minted} | |
\usepackage{ucs} | |
\usepackage[utf8x]{inputenc} | |
\title{} | |
\author{Samuel Marks} | |
\begin{document} | |
%\maketitle | |
\section{Lexical analyser} | |
\ \\[5mm] | |
\digraph[scale=1.0]{lexicalAnalyserOverview} { | |
rankdir=LR; | |
Regex->NDFA | |
subgraph cluster0 { | |
label="scanner generator"; | |
NDFA->DFA | |
}; | |
DFA->Program | |
} | |
\section{Scanner generator} | |
\begin{enumerate} | |
\item Flex \(\rightarrow\) generates C program \(\rightarrow\) \emph{lex.yy.c} | |
\item JLex \(\rightarrow\) generates Java program | |
\end{enumerate} | |
\subsection{Flex example} | |
\begin{minted}{text} | |
%% | |
// definition section | |
#include <stdio.h> | |
DIGIT [0-9] | |
NUMBER 0 | [1-9][DIGIT]* | |
IDENTIFIER [a-z A-Z][a-z A-Z 0-9]* | |
%% | |
//Rules section | |
RE ACTION | |
DIGIT { printf("Digit Found: %s\n", yy_text); } | |
IDENTIFIER { populateSymbolTable(yy_text); } | |
%% | |
//User action | |
void populateSymbolTable(); | |
main() { | |
while(yy_lex()) | |
printf("Token found: %s\n", yy_text); | |
} | |
\end{minted} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment