Skip to content

Instantly share code, notes, and snippets.

@SamuelMarks
Created November 22, 2013 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamuelMarks/7602557 to your computer and use it in GitHub Desktop.
Save SamuelMarks/7602557 to your computer and use it in GitHub Desktop.
\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