This project is a fork of OMetaJS by Alex Warth master branch.
It is also initially based on nodejs conversion written by Sergey Berezhnoy nodejs branch.
To learn more:
- OMeta mailing list
- mailing list archirves
The goal of this project is to provide a tool-chain tool for easily working with OMetaJS.
ometajsnode allows one to specify grammar, interpreter, and compiler files, utility modules, and program files via command line, and offers a number of options of linking them together into an execution chain such as parse mode, interpreter mode, and compile mode.
Work in progress
I'm not sure if packaging works with
npm yet, but I'll get there.
stdin input is not working yet.
Currently, parsing, interpreting, and "compiling" works. See below walkthrough.
see usage via
./ometajsnode -h or
./ometajsnode -P -g ../examples/grammar_to_ir.ometajs --parser-root expr -o output.file ../examples/program.file ../examples/program2.file --debug
Let's breakdown that command step by step:
ometajsnodeinto Parse mode, which will essentially output the Abstract Syntax Tree for each of the programs
-g ../examples/grammar_to_ir.ometajsspecifies the file containing ometajs grammar to use
--parser-root exprspecifies 'expr' as the root element of the grammar for the parser to try to match
-o output.filespecifies the file to which output will be written ( if
-ois not present, output is directed to
../examples/program.file ../examples/program2.filespecifies two programs to process
--debugsets mode to debug, which will display a lot of information detailing the execution process
Combined parser and interpreter example:
./ometajsnode -I -g ../examples/grammar_and_interpreter.ometajs --interpreter-root expr -o output.file ../examples/program.file ../examples/program2.file --verbose
This command is similar to the one above with some differences:
ometajsnodeinto Interpret mode, which will actually interpret each of the programs and display the result
--interpreter-root exprsimilarly to
--parser-root, this specifies the root element of the grammar for the interpreter to try to match
--verbosesets mode to verbose, which is not as detailed as
debug, but will give you more detailed information
Parser to intermediate representation which then is interpreted example:
./ometajsnode -I -g ../examples/grammar_to_ir.ometajs --parser-root expr -i ../examples/interpreter.ometajs --interpreter-root interp -o output.file ../examples/program.file ../examples/program2.file --debug
We have little bit more going on here:
-iin addition to
-gwhich specified the grammar file, we add an interpreter file that will work with the output of parsing according to grammar file
- because we specified both a grammar and an interpreter, we need to provide both
Parser to intermediate representation, then intermediate representation to "assembly" code example:
./ometajsnode -C -g ../examples/grammar_to_ir.ometajs --parser-root expr -c ../examples/compiler.ometajs --compiler-root comp -o output.file -u example-utilities ../examples/program.file --debug
-Cindicates compile mode. I'm not yet sure this is named correctly, perhaps a more appropriate name would be emit mode. Nevertheless, in this example it uses
compiler.ometajsto emit assembly-like code to a file
-c ../examples/compiler.ometajsspecifies the OMetaJS compiler file
-u example-utilitiesspecifies a comma separated list of utility modules (here only one) that
compiler.ometajsuses in order to help it to generate "assembly".
ometajsnodewill attempt to
require('module name')and will make it available to any
__Utilities[ <utilityName> ].
utilityNamemust be exported by the module: `exports.utilityName = 'some name';
I am not quite convinced that the 'parse', 'interpret', 'compile' mode breakdown makes sense, I'm open to suggestions on how to better organize execution modes. And of course, I welcome any other input or feedback.