
% \documentclass{article}
% \title{Language syntax}

% \setlength{\oddsidemargin}{-0.2in}
% \setlength{\evensidemargin}{-0.2in}
% \setlength{\textwidth}{7in}
% \setlength{\textheight}{9in}

% \begin{document}
% \maketitle

%

\section{Lexical rules}

\begin{flushleft}

\textbf{alpha} $\to$ 'a'..'z' $|$ 'A'..'Z' $|$ '\_'

\textbf{digit} $\to$ '0'..'9'

\textbf{id} $\to$ \textbf{alpha} (\textbf{alpha}$|$\textbf{digit})*

\textbf{number} $\to$ ( (digit)+ ('.' (digit)*)? $|$ '.' (digit)+ ) ( (E$|$e) (+$|$-)? (digit)+ )?

\textbf{string} $\to$ '$''$' ($\sim$('$''$' ) $|$ ( '$''$' '$''$' ))* '$''$'

\subsubsection{Skipped tokens}

\textbf{linebreak} $\to$ '$\backslash n$'

\textbf{whitespace} $\to$ ' ' $|$ '$\backslash t$' $|$ '$\backslash r$' $|$ \textbf{linebreak}

\textbf{comment} $\to$ ( '$/*$' ($\sim$'$*/$')* '$*/$' ) $|$ '$//$' ($\sim$\textbf{linebreak})* \textbf{linebreak}


\end{flushleft}

\section{Syntactic rules}

\begin{flushleft}

program $\to$ ( statement $|$ func-def )*

statement $\to$ for-stmt $|$ if-stmt $|$ loop-stmt $|$ break-stmt $|$ return-stmt \\
\hspace{0.7in} $|$ load-stmt $|$ assignment $|$ func-call-stmt $|$ '\{' (statement)* '\}'

for-stmt $\to$ 'for' '(' \textbf{id} '=' range ( ',' \textbf{id} '=' range )* ')' statement

if-stmt $\to$ 'if' '(' expression ')' statement ( 'else' statement )?

loop-stmt $\to$ 'loop' ( '(' \textbf{id} ')' )? statement

break-stmt $\to$ 'break' (\textbf{id})? ';'

cont-stmt $\to$ 'continue' (\textbf{id})? ';'

return-stmt $\to$ 'return' expression ';'

load-stmt $\to$ 'include' \textbf{string} ';'

assignment $\to$ l-value ('=' $|$ '$+$=' $|$ '$-$=' $|$ '$*$=' $|$ '$/$=' $|$ '\%=' $|$ '/$'$=' ) expression ';'

func-call-stmt $\to$ func-call ';'

func-call $\to$ \textbf{id} '(' expr-list ')'

expr-list $\to$ expression ( ',' expression )* $|$ $\epsilon$

func-def $\to$ 'func' \textbf{id} '(' var-list ')' func-body

var-list $\to$ \textbf{id} ( ',' \textbf{id} )* $|$ $\epsilon$

func-body $\to$ '=' expression ';' $|$ '\{' (statement)* '\}'

expression $\to$ logic-term ( 'or' logic-term )* 

logic-term $\to$ logic-factor ( 'and' logic-factor )*

logic-factor $\to$ ('not')? relat-expr

relat-expr $\to$ arith-expr ( ('$>=$' $|$ '$<=$' $|$ '$>$' $|$ '$<$' $|$ '$==$' $|$ '$!=$') arith-expr )?

arith-expr $\to$ arith-term ( ('$+$'$|$'$-$') arith-term )*

arith-term $\to$ arith-factor ( ('$*$'$|$'$/$'$|$'$\%$'$|$'$/'$') arith-factor )*

arith-factor $\to$ ('$+$'$|$'$-$') r-value $|$ r-value '$'$'

r-value $\to$ l-value $|$ func-call $|$ constant $|$ array

l-value $\to$ \textbf{id} ( '[' index ']' )*

index $\to$ range (',' range)?

range $\to$ expression (':' (expression)? $|$ '::' expression )? $|$ ':'

constant $\to$ \textbf{number}

array $\to$ '[' expression ( (','$|$';') expression )* ']'

\end{flushleft}

% \end{document}

