Skip to content

Commit

Permalink
use generated .g.tex files in syntax.tex
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Oct 11, 2019
1 parent 89f2e3d commit f3c53a8
Showing 1 changed file with 9 additions and 345 deletions.
354 changes: 9 additions & 345 deletions chapters/syntax.tex
Expand Up @@ -13,22 +13,8 @@ \section{Lexical conventions}\doublelabel{lexical-conventions}
ones used in the grammar, the rest are just internal to the definition
of other lexical units):

\begin{lstlisting}[language=grammar]
IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT
Q-IDENT = "'" ( Q-CHAR | S-ESCAPE ) { Q-CHAR | S-ESCAPE | """ } "'"
NONDIGIT = "_" | letters "a" to "z" | letters "A" to "Z"
STRING = """ { S-CHAR | S-ESCAPE } """
S-CHAR = see below
Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," |
"-" | "." | "/" | ":" | ";" | "<" | ">" | "=" | "?" | "@" | "[" | "]" | "^" |
"{" | "}" | "|" | "~" | " "
S-ESCAPE = "\'" | "\"" | "\?" | "\\" |
"\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
UNSIGNED-INTEGER = DIGIT { DIGIT }
UNSIGNED-NUMBER = UNSIGNED-INTEGER [ "." [ UNSIGNED-INTEGER ] ]
[ ( "e" | "E" ) [ "+" | "-" ] UNSIGNED-INTEGER ]
\end{lstlisting}
\input{grammar/B1_lexical_conventions.g.tex}

\textrm{S-CHAR} is any member of the Unicode character set
(\url{http://www.unicode.org}; see \autoref{mapping-package-class-structures-to-a-hierarchical-file-system} for storing as UTF-8 on files) except double-quote """, and backslash "\textbackslash{}"

Expand Down Expand Up @@ -76,345 +62,23 @@ \section{Lexical conventions}\doublelabel{lexical-conventions}

\section{Grammar}\doublelabel{grammar}
\subsection{Stored Definition -- Within}\doublelabel{stored-definition-within}
\begin{lstlisting}[language=grammar]
stored-definition:
[ within [ name ] ";" ]
{ [ final ] class-definition ";" }
\end{lstlisting}
\input{grammar/B21_stored_definition.g.tex}

\subsection{Class Definition}\doublelabel{class-definition}
\begin{lstlisting}[language=grammar]
class-definition :
[ encapsulated ] class-prefixes
class-specifier

class-prefixes :
[ partial ]
( class | model | [ operator ] record | block | [ expandable ] connector | type |
package | [ pure | impure ] [ operator ] function | operator )

class-specifier :
long-class-specifier | short-class-specifier | der-class-specifier

long-class-specifier :
IDENT string-comment composition end IDENT
| extends IDENT [ class-modification ] string-comment composition
end IDENT

short-class-specifier :
IDENT "=" base-prefix type-specifier [ array-subscripts ]
[ class-modification ] comment
| IDENT "=" enumeration "(" ( [ enum-list ] | ":" ) ")" comment

der-class-specifier :
IDENT "=" der "(" type-specifier "," IDENT { "," IDENT } ")" comment

base-prefix :
[ input | output ]

enum-list : enumeration-literal { "," enumeration-literal}

enumeration-literal : IDENT comment

composition :
element-list
{ public element-list |
protected element-list |
equation-section |
algorithm-section
}
[ external [ language-specification ]
[ external-function-call ] [ annotation-comment ] ";" ]
[ annotation-comment ";" ]

language-specification :
STRING

external-function-call :
[ component-reference "=" ]
IDENT "(" [ expression-list ] ")"

element-list :
{ element ";" }

element :
import-clause |
extends-clause |
[ redeclare ]
[ final ]
[ inner ] [ outer ]
( class-definition | component-clause |
replaceable ( class-definition | component-clause )
[ constraining-clause comment ] )

import-clause :
import ( IDENT "=" name | name ["." ( "*" | "{" import-list "}" ) ] ) comment

import-list :
IDENT { "," IDENT }
\end{lstlisting}
\input{grammar/B22_class_definition.g.tex}

\subsection{Extends}\doublelabel{extends}
\begin{lstlisting}[language=grammar]
extends-clause :
extends type-specifier [ class-modification ] [ annotation-comment ]

constraining-clause :
constrainedby type-specifier [ class-modification ]
\end{lstlisting}
\input{grammar/B23_extends.g.tex}

\subsection{Component Clause}\doublelabel{component-clause}
\begin{lstlisting}[language=grammar]
component-clause:
type-prefix type-specifier [ array-subscripts ] component-list

type-prefix :
[ flow | stream ]
[ discrete | parameter | constant ] [ input | output ]
component-list :
component-declaration { "," component-declaration }

component-declaration :
declaration [ condition-attribute ] comment

condition-attribute:
if expression

declaration :
IDENT [ array-subscripts ] [ modification ]
\end{lstlisting}
\input{grammar/B24_component_clause.g.tex}

\subsection{Modification}\doublelabel{modification}
\begin{lstlisting}[language=grammar]
modification :
class-modification [ "=" expression ]
| "=" expression
| ":=" expression

class-modification :
"(" [ argument-list ] ")"

argument-list :
argument { "," argument }

argument :
element-modification-or-replaceable
| element-redeclaration

element-modification-or-replaceable:
[ each ] [ final ] ( element-modification | element-replaceable )

element-modification :
name [ modification ] string-comment

element-redeclaration :
redeclare [ each ] [ final ]
( short-class-definition | component-clause1 | element-replaceable )

element-replaceable:
replaceable ( short-class-definition | component-clause1 )
[ constraining-clause ]

component-clause1 :
type-prefix type-specifier component-declaration1

component-declaration1 :
declaration comment

short-class-definition :
class-prefixes short-class-specifier
\end{lstlisting}
\input{grammar/B25_modification.g.tex}

\subsection{Equations}\doublelabel{equations1}
\begin{lstlisting}[language=grammar]
equation-section :
[ initial ] equation { equation ";" }
\input{grammar/B26_equations.g}

algorithm-section :
[ initial ] algorithm { statement ";" }

equation :
( simple-expression "=" expression
| if-equation
| for-equation
| connect-clause
| when-equation
| component-reference function-call-args )
comment

statement :
( component-reference ( ":=" expression | function-call-args )
| "(" output-expression-list ")" ":=" component-reference function-call-args
| break
| return
| if-statement
| for-statement
| while-statement
| when-statement )
comment

if-equation :
if expression then
{ equation ";" }
{ elseif expression then
{ equation ";" }
}
[ else
{ equation ";" }
]
end if

if-statement :
if expression then
{ statement ";" }
{ elseif expression then
{ statement ";" }
}
[ else
{ statement ";" }
]
end if

for-equation :
for for-indices loop
{ equation ";" }
end for

for-statement :
for for-indices loop
{ statement ";" }
end for

for-indices :
for-index {"," for-index}

for-index:
IDENT [ in expression ]

while-statement :
while expression loop
{ statement ";" }
end while

when-equation :
when expression then
{ equation ";" }
{ elsewhen expression then
{ equation ";" } }
end when

when-statement :
when expression then
{ statement ";" }
{ elsewhen expression then
{ statement ";" } }
end when

connect-clause :
connect "(" component-reference "," component-reference ")"
\end{lstlisting}
\subsection{Expressions}\doublelabel{expressions1}
\begin{lstlisting}[language=grammar]
expression :
simple-expression
| if expression then expression { elseif expression then expression }
else expression

simple-expression :
logical-expression [ ":" logical-expression [ ":" logical-expression ] ]

logical-expression :
logical-term { or logical-term }

logical-term :
logical-factor { and logical-factor }

logical-factor :
[ not ] relation

relation :
arithmetic-expression [ relational-operator arithmetic-expression ]

relational-operator :
"<" | "<=" | ">" | ">=" | "==" | "<>"

arithmetic-expression :
[ add-operator ] term { add-operator term }

add-operator :
"+" | "-" | ".+" | ".-"

term :
factor { mul-operator factor }

mul-operator :
"*" | "/" | ".*" | "./"

factor :
primary [ ("^" | ".^") primary ]

primary :
UNSIGNED-NUMBER
| STRING
| false
| true
| ( component-reference | der | initial | pure ) function-call-args
| component-reference
| "(" output-expression-list ")"
| "[" expression-list { ";" expression-list } "]"
| "{" array-arguments "}"
| end

type-specifier : ["."] name

name : IDENT { "." IDENT }

component-reference :
[ "." ] IDENT [ array-subscripts ] { "." IDENT [ array-subscripts ] }

function-call-args :
"(" [ function-arguments ] ")"

function-arguments :
expression [ "," function-arguments-non-first | for for-indices ]
| function name "(" [ named-arguments ] ")" [ "," function-arguments-non-first ]
| named-arguments

function-arguments-non-first :
function-argument [ "," function-arguments-non-first ]
| named-arguments

array-arguments :
expression [ "," array-arguments-non-first | for for-indices ]

array-arguments-non-first :
expression [ "," array-arguments-non-first ]

named-arguments: named-argument [ "," named-arguments ]

named-argument: IDENT "=" function-argument

function-argument :
function name "(" [ named-arguments ] ")" | expression

output-expression-list:
[ expression ] { "," [ expression ] }

expression-list :
expression { "," expression }

array-subscripts :
"[" subscript { "," subscript } "]"

subscript :
":" | expression

comment :
string-comment [ annotation-comment ]

string-comment :
[ STRING { "+" STRING } ]
\input{grammar/B27_expressions.g}

annotation-comment :
annotation class-modification
\end{lstlisting}

0 comments on commit f3c53a8

Please sign in to comment.