Hot answers tagged

25 votes
Accepted

Is it important that the front-end has a built-in parser?

Is it strictly necessary? In most cases, no, but doing so gives us many advantages. Most of those advantages might be worked around with various heuristics. But most importantly, it would have been ...
John Fultz's user avatar
  • 12.6k
23 votes
Accepted

Shell Emulation inside Mathematica

First of all, I agree, as OP mentioned in his comment, ANTLR is one of the proper ways to go. Now for this specific task, it might be easier to just compose a parser in the "dirty" way, except we don'...
Silvia's user avatar
  • 27.5k
17 votes
Accepted

How to parse a clojure expression?

This answer is based on the Mathematica functional parsers package FunctionalParsers.m used and described in these blog posts. This command loads that package: ...
Anton Antonov's user avatar
16 votes

How can I ingest and analyze benchmark results posted at MSE?

Ingestion Get all answers from MSE discussion in an XML object: ...
Anton Antonov's user avatar
15 votes

Is it important that the front-end has a built-in parser?

Not really an answer and I may have to delete it, but...I had something of a different reaction to this business of the front end having its own parser, circa 2004. For motivation I recommend the ...
Daniel Lichtblau's user avatar
14 votes

Why is this syntax for patterns with Optional values not supported?

The Documentation states (emphasis is mine): Pattern (:): s:obj represents the pattern object ...
Alexey Popkov's user avatar
13 votes

Tokenize Mathematica input in a simple way

I am a developer at Wolfram Research and I am trying to share some of the work I have been doing with parsing WL code. I have written a package for parsing WL code and retaining interesting metadata, ...
brenton's user avatar
  • 521
12 votes
Accepted

FullForm with context for each symbol?

To not mess with $ContextPath you can Block it just for that evaluation. e.g. ...
Kuba's user avatar
  • 137k
12 votes

How to convert a string having nested parentheses into an expression?

I'd do the minimum necessary to make a legitimate, unambiguous Mathematica expression, and then let Mathematica rewrite it. ...
John Doty's user avatar
  • 13.7k
12 votes
Accepted

What is the best way to parse differential equations and boundary conditions to a custom function?

Assuming everything is syntactically correct, the function that does what you want is Internal`ProcessEquations`SeparateEquations: ...
Michael E2's user avatar
  • 234k
11 votes

Is it important that the front-end has a built-in parser?

The result of the front-end's parsing is definitely used, but it does not need to be complete, it seems. This can be seen by constructing Cells/Boxes manually. Try ...
masterxilo's user avatar
  • 5,729
11 votes
Accepted

How to parse JSON

The example JSON string: ...
C. E.'s user avatar
  • 70.4k
11 votes

Is building an event-based parser possible/reasonable in Mathematica (WL)?

Note: If you want this type of parser added for JSON, I think WRI could do it easily. They already have Developer`ReadRawJSONStream so I think adding some event-...
b3m2a1's user avatar
  • 46.8k
11 votes

Lexical scanning and parsing in a toy language

This can be done using functional parsers. Does the solution below look like something you would be interested in? (If you are I will elaborate on the current answer...) Grammar ...
Anton Antonov's user avatar
11 votes

Repeated string pattern: difference between the FrontEnd and WolframScript?

The notebook interface and the kernel have different parsers, because the notebook needs to manipulate the input before the kernel sees it for a variety of reasons. There are many differences between ...
Robert Jacobson's user avatar
11 votes
Accepted

Removing banal words from a list

Please also see a related problem here, it might give you more ideas. Words can be banal wrt all words in the dictionary or wrt some particular list of words. Let's consider the later case. ...
Vitaliy Kaurov's user avatar
10 votes
Accepted

Validate `Box` grammar, is it possible?

You may try using MathLink`CallFrontEnd[FrontEnd`ReparseBoxStructurePacket[...]]. ...
Domen's user avatar
  • 22.3k
9 votes
Accepted

How to get "one Cell - one line" code format inside of NB files?

For producing a NB file without the line breaks you can Get it as a Notebook expression, then ...
Alexey Popkov's user avatar
9 votes

Shell Emulation inside Mathematica

I extended the original question to support piping like the following. wget -qO- "http://google.com" // cat and it outputs the following. ...
William's user avatar
  • 7,595
9 votes

Efficient JSON parser for Mathematica

Recent versions of Mathematica no longer use Java for parsing JSON, and work very fast. There are at least three ways to read JSON. Import[..., "JSON"] is fast an ...
Szabolcs's user avatar
  • 234k
9 votes
Accepted

Context inside Do[...]-loop

Begin["mycontext`"] affects the parser, not the evaluator. These are separate expressions: Begin["mycontext`"]; ...
Szabolcs's user avatar
  • 234k
8 votes

Is it important that the front-end has a built-in parser?

Maybe that is not exactly the point of your question but is relevant. We need the FronEnd's parser, it is the only one that knows what is $CellContext` in given ...
Kuba's user avatar
  • 137k
8 votes
Accepted

Repeated string pattern: difference between the FrontEnd and WolframScript?

I suspect, much to my chagrin, that the FE is right and the InputForm parser is wrong. For one thing, the kernel itself thinks that parens are needed for Repeated: ...
Itai Seggev's user avatar
  • 14.1k
8 votes

What is the best way to parse differential equations and boundary conditions to a custom function?

I'll just give an idea to make it easier to do this. Which is not to use the same API as NDSolve, as that requires much much more work to parse it. Instead, have ...
Nasser's user avatar
  • 142k
7 votes
Accepted

Can Read[] apply a custom function automatically to the read values?

Yes! This is documented under Details: You can use Read to get objects to insert into any expression structure, not necessarily a list. Example: ...
7 votes

How to get the longest bracket pairs from a string

This works: ...
Alexey Popkov's user avatar
7 votes
Accepted

Can we make preread replacements in an *.m* file before being run?

No. In fact, even $PreRead is ignored when reading .m files. What you can do is define a myGet as ...
Itai Seggev's user avatar
  • 14.1k
6 votes

How to parse a clojure expression?

I have a solution which is brittle only in that the Clojure expressions "(", ")" could mess up bracket detection and that I rely on strings like "<4>" to keep track of things. It's not very brittle ...
Patrick Stevens's user avatar
6 votes
Accepted

Can we make new definitions for InputForm in packages?

Unfortunately, I don't think there is. The association between characters and symbol names is burned into the kernel (in the form of a "yacc" grammar), with complete information about associativity, ...
Itai Seggev's user avatar
  • 14.1k

Only top scored, non community-wiki answers of a minimum length are eligible