You are here

Mx parser for multiple groups

The Mx script attached works ok. The parser generates a lot of errors. It is possible that my installation of the parser is the problem, as it has never yet worked for me.

Michael-Neales-Macbook-Pro-2% ~/mx/openmx/OpenMx/trunk/inst/tools/mxAlgebraParser.py ~/mx/openmxscripts/testalgebraparser.out
Traceback (most recent call last):
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxAlgebraParser.py", line 149, in
print(parser.parse(input))
File "build/bdist.macosx-10.3-i386/egg/ply/yacc.py", line 265, in parse
File "build/bdist.macosx-10.3-i386/egg/ply/yacc.py", line 921, in parseopt_notrack
File "build/bdist.macosx-10.3-i386/egg/ply/lex.py", line 384, in token
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxAlgebraParser.py", line 42, in t_error
raise Exception("Illegal character " + str(t.value[0]))
Exception: Illegal character #
Michael-Neales-Macbook-Pro-2% cat ~/mx/openmxscripts/testalgebraparser.out

AttachmentSize
Plain text icon testalgebraparser.txt156 bytes
Reporter: 
Created: 
Fri, 11/06/2009 - 11:38
Updated: 
Fri, 08/26/2016 - 10:47

Comments

So ./mxParser.py is the tool you want to use to parse entire Mx scripts. I ran it on your input and it works. ./mxAlgebraParser.py only works on the right-hand side of a algebra expression (and no semicolon). The algebra parser will freak out if you give it a whole model. So you can feed ./mxAlgebraParser.py the following input:

A+C+E       |       A+C _
                        A+C             |       A+C+E 

Doh! Well it had to be something simple... and omfg it actually works! Kinda sorta.

makeLabels matrixA matrixC matrixE algebraB

model model model

Two issues remain:

1. I encounter errors running mxRun(model) in OpenMx
2. The Algebra is not correct, apologies to Muhammad ibn Mūsā al-Khwārizmī, as I suspect that the operators | and _ have not been given sufficiently low priority (they come below + and - in precedence).

Oh and another thing, the attached script generates errors thusly:

Michael-Neales-Macbook-Pro-2% ~/mx/openmx/OpenMx/trunk/inst/tools/mxParser.py ~/mx/openmx/Mx\ 1.0\ Scriptsutneloc.o
Traceback (most recent call last):
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxParser.py", line 254, in
parseModel(sys.stdin.read())
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxParser.py", line 235, in parseModel
mxInput = tryDirectives(mxInput)
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxParser.py", line 220, in tryDirectives
subtract = mxDirectives[directive](mxInput)
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxParser.py", line 63, in parseMatrices
declareLines = block.group(1).strip().split('\n')
AttributeError: 'NoneType' object has no attribute 'group'

OK I got this script to work. It turns out that "_" has the lowest precedence, and then "|" has a higher precedence, and then followed by "+" and "-" and the rest of the operators. Also the Mx 1.0 parser is case insensitive and will recognize the matrix type "full". But it doesn't convert the label to "Full" and so R currently throws an error. This is an error in the parser, I'll get around to fixing it. But for now just label the matrices "Full" and it will work.

Yeah sorry I can't parse more than one group at present.

The Mx parser supports only one group at the present time.

I don't think we will be pursuing this potentially nice addition. One group at a time if you have to...