G
giulianodammando
In the development of a simple numerical simulation software i need to
read
some initialization parameters from a file that looks like:
# Global Setup
species = 1;
\begin{specie}<1>
name = NITROGEN;
aindex = 7;
ionstages = 1;
\begin{ionstage}<1>
nmax = -1;
iindex = 10;
ionDB = XSTAR;
eLevsDB = XSTAR;
bbCollDB = CHIANTI;
bfCollDB = NIST, XSTAR;
bbRadDB = OPIP;
bfRadDB = XSTAR;
ffRadDB = off;
\end{ionstage}<1>
\end{specie}<1>
# Here stay transport calculation
# related options.
# spatial mesh options
\begin{GridOpt}
Grid = Uniform; # uniform spacing
GridStep = 20; # step size in (cm)
\end{GridOpt}
# set physical domain extension
\begin{DomainOpt}
DomainLength = 100; # cm
\end{DomainOpt}
# Specify Boundary Conditions on intensity
\begin{RadBoundaryCond}
RadBoundaryPolicy = ZeroOnBoth; # no radiation
\end{RadBoundaryCond}
# NEEDS_WORK
# set other stuff
\begin{OtherOpt}
edenPolicy = ConstField;
eden = 1e12; # cm^-3
adenPolicy = ConstField;
aden = 1e16; # cm^-3
etemPolicy = ConstField
\end{OtherOpt}
I'm not a professional programmer, so i've implemented the reading
scheme as a simple token
iterator (basically jump #comments and tokenize the rest) which feeds a
simple parser.
The parser basically recognizes 3 kind of token:
1. \environment --> start an environment of some kind
2. variable names/ variable comma-separated lists
3. the "=" token, meaning assigment (typically an internal variable is
assignd with a numeric/string value or a list of these)
3. the ";" token, meaning end of the right hand side in an assigment
This result in about 2000 lines of code because of an enormous switch
statement testing for each valid
option (and reporting an error in case there's something wrong).
I'd like to use a more flexible approach but i've not idea were to
start. It would be useful for me also to
read small matrices and vectors of floats (to restart a simulation from
a previously interrupted one).
So i need something more similar to a grammar driven parsing approach,
but i've not idea were to start.
I would appreciate any suggestion or pointers to resources (availables
libraries, documents) useful
to solve this design problem.
Thanks
read
some initialization parameters from a file that looks like:
# Global Setup
species = 1;
\begin{specie}<1>
name = NITROGEN;
aindex = 7;
ionstages = 1;
\begin{ionstage}<1>
nmax = -1;
iindex = 10;
ionDB = XSTAR;
eLevsDB = XSTAR;
bbCollDB = CHIANTI;
bfCollDB = NIST, XSTAR;
bbRadDB = OPIP;
bfRadDB = XSTAR;
ffRadDB = off;
\end{ionstage}<1>
\end{specie}<1>
# Here stay transport calculation
# related options.
# spatial mesh options
\begin{GridOpt}
Grid = Uniform; # uniform spacing
GridStep = 20; # step size in (cm)
\end{GridOpt}
# set physical domain extension
\begin{DomainOpt}
DomainLength = 100; # cm
\end{DomainOpt}
# Specify Boundary Conditions on intensity
\begin{RadBoundaryCond}
RadBoundaryPolicy = ZeroOnBoth; # no radiation
\end{RadBoundaryCond}
# NEEDS_WORK
# set other stuff
\begin{OtherOpt}
edenPolicy = ConstField;
eden = 1e12; # cm^-3
adenPolicy = ConstField;
aden = 1e16; # cm^-3
etemPolicy = ConstField
\end{OtherOpt}
I'm not a professional programmer, so i've implemented the reading
scheme as a simple token
iterator (basically jump #comments and tokenize the rest) which feeds a
simple parser.
The parser basically recognizes 3 kind of token:
1. \environment --> start an environment of some kind
2. variable names/ variable comma-separated lists
3. the "=" token, meaning assigment (typically an internal variable is
assignd with a numeric/string value or a list of these)
3. the ";" token, meaning end of the right hand side in an assigment
This result in about 2000 lines of code because of an enormous switch
statement testing for each valid
option (and reporting an error in case there's something wrong).
I'd like to use a more flexible approach but i've not idea were to
start. It would be useful for me also to
read small matrices and vectors of floats (to restart a simulation from
a previously interrupted one).
So i need something more similar to a grammar driven parsing approach,
but i've not idea were to start.
I would appreciate any suggestion or pointers to resources (availables
libraries, documents) useful
to solve this design problem.
Thanks