Questions tagged [parsing]

Analyzing (un)structured data to convert it into a structured, normalized format.

Filter by
Sorted by
Tagged with
1
vote
1answer
424 views

Desired pattern for expression parsing into RPN

I'm writing a interpreter/compiler I have encountered a problem which I have solved before, but not optimally perhaps. The problem goes like this, expressions can express a lot of things like scopes,...
2
votes
2answers
306 views

Is implementing operator overloading with variable arity possible?

Implementing operator overloading for e.g. + (plus) isn't terribly difficult if you know it's a binary operator. One can just parse expression + expression But what if the programmer can choose ...
0
votes
3answers
2k views

What approaches can be used to convert existing JSON structure to existing XML structure?

I am working on a component for an enterprise message queue that consumes a message from a queue and sends it as a text message. The message is picked up by my consumer in JSON format (I do not have ...
1
vote
4answers
357 views

Is it common to write File Parsers in higher languages like Java?

I work with an older framework (15 years+) at work which is fully built on Perl. Its main tasks are calling external programs via command-line calls, parsing their output and presenting some of the ...
4
votes
2answers
459 views

Correct terminology for if-blocks

I am using lex/yacc to parse a simple language which allows 'if blocks': IF something something [ELSE IF something][ELSE] END IF and also other nested logic under a 'DEFINE' statement: DEFINE ...
0
votes
0answers
77 views

Parsing nested structure from facebook pfff - how to decide on parser

I'm playing around since a while with building a little open source project based on the output of facebooks pfff tool, that can parse multiple programming languages and output some kind of unified ...
5
votes
3answers
826 views

Proper separation between lexing and parsing

I am currently writing a parser which, given a source file, turns it into an AST of some language, respecting the idiomatic process of lexing and then parsing using well-known parser generators (think ...
1
vote
0answers
103 views

Concurrently parsing records in a binary file in Go

I have a binary file that I want to parse. The file is broken up into records that are 1024 bytes each. The high level steps needed are: Read 1024 bytes at a time from the file. Parse each 1024-byte "...
3
votes
3answers
377 views

How to create simulator for distributed algorithms written in simple language

I started development of simulator for simulation of distributed algorithms in language C. My work consist of creating simple language for algorithm description and simulator which takes the described ...
8
votes
1answer
482 views

What makes some things easier to parse than others?

I was just reading the Wikipedia page for WebAssembly and it says: “WebAssembly is… designed to be faster to parse than JavaScript” , which got me thinking, what makes a certain language or data ...
1
vote
2answers
170 views

Is there a good single byte delimeter for use with utf-8 strings that isn't a null terminator?

I'm looking for a quick way to split strings containing individual JSON payloads. Currently, I'm using newlines and searching for the newline ASCII character, but I figure if I start using utf-8 this ...
2
votes
2answers
583 views

Best approach parsing input in multiple scenarios

I am developing an API that has one call that accepts a big JSON object. Based on this object, there are 10 possible parsing scenarios, i.e. if field xxxx.xxx is present, go with scenario 5. We ...
4
votes
1answer
482 views

How to parse a simple custom syntax in Go?

I have a limited amount of input types: 34:56 = sensorA#, sensorA#, sensorB# 2:5 = { led# } 66 = otherSensor 2,3,4,5 = greenRelay#, redRelay#, relayA#, relayA# a:b implies range. {name} implies a ...
5
votes
2answers
569 views

SAX-like parser: what is this pattern called?

I wrote a parser for a certain type of binary file with recursive structure. I made its API to be similar to SAX, that is: the parser accepts an object of a specific interface, this interface has ...
3
votes
1answer
876 views

Exception Hierarchy and Use of What Message for Parsing Strings

I have a piece of code parsing a text file line by line. I have to goals: Testing the syntax of the text and extracting information of it. It is quite likely that syntax errors occur so I want to ...
70
votes
4answers
11k views

When to use a Parser Combinator? When to use a Parser Generator?

I've taken a deep dive into the world of parsers recently, wanting to create my own programming language. However, I found out that there exist two somewhat different approaches of writing parsers: ...
5
votes
4answers
2k views

Approach for parsing and indexing very large files

I have been tasked with developing a web based (i.e runs in browser) viewer for a proprietary log file. I have no control over the format of the logs, I just consume them. The log file contains ...
4
votes
2answers
2k views

Postfix vs Prefix

I have read at a few places, that Postfix is easier to evaluate & easier to convert to Code than Prefix. I understand that if you parse a prefix expression from left to right, you might not be ...
0
votes
1answer
184 views

Is MVC (or variations) the right pattern when retrieving data, then parsing and displaying it?

Due to these answers, I've decided to implement MVC (or a variation of it) into my application. But the more I read the more confused about this topic I get. Some people say the business logic belongs ...
5
votes
1answer
378 views

How do parsers search for token patterns?

Could you explain how parsers search for token patterns like in markdown? I probably could come up with something matching only the braces pattern []() as soon as nested patterns are involved it ...
3
votes
3answers
2k views

How exactly is bytecode “parsed”?

How is Bytecode "parsed"? It is my understand that Bytecode is a binary, intermediate representation of the syntax of a given programming language. Certain programming languages convert their source ...
2
votes
1answer
2k views

Understanding abstract syntax trees in compilers

I have attached the problem below with the answer. My problem is that I can't understand it. Can you provide an overall explanation in detail about parse trees and ETF grammar by deriving the first ...
0
votes
3answers
135 views

What is a good strategy for reading XML like hiearchical text data?

I want to read data in a format like the following using Java. [scenario] id=my_first_scenario next_scenario=null name=_"My First Scenario." map_data="{~add-ons/my_first_campaign/...
3
votes
1answer
181 views

What data structures are used to represent source code by programs that do source-to-source transformations?

For programs that read in source code, transform that source code, and then write back out the transformed source code so that it can be read and edited by humans, what sorts of data structures are ...
6
votes
3answers
1k views

Best way to consume very dynamic/inconsistent xml/json

I don't know whether to call the data dynamic or inconsistent. But I need to create profile pages for people generated from xml or json. The challenge is in the data the is returned. The data is ...
0
votes
0answers
109 views

LALR parsing (with Ply) non-deterministic and sometimes fails

I have written a parser using Python Ply library. While doing tests with an input file I have noticed a strange behaviour : sometimes the input is correctly parsed with no error and sometimes, there ...
5
votes
1answer
633 views

How should a lexer deal with multi-line statements(eg. Functions definitions, Control-Flow statements)?

tl;dr-ers: How does a lexer normally deal with none-inline statements. statements that do not end with a specified statement delimiter. Such as control flow statements? I believe that I have a ...
5
votes
2answers
3k views

How is a abstract syntax tree used to execute source code?

After researching how a parser generates an AST, I believe that I can know attempt to create one. Before I started on this project, I began to ponder what I should be done next after creating a AST ...
1
vote
3answers
1k views

Writing a parser [closed]

Writing SQL like parser in .NET At this point on the first basic parse select col1, col2, col4 from documents where col1 any ('a','b','c') and col2 all ('b','c') I can identify what I call ...
-7
votes
1answer
151 views

Parsing odd JSON Request [closed]

I know how to parse normal JSON objects using the org.json library, but I am confused as how I would parse this one as it has no array/object names. [ { "value1": null, "value2": ...
1
vote
2answers
254 views

How to write multi-format parsers?

I'm about to create a specific file format for a particular project. There is no special metadata related to the file, as it can be saved in the database, in a file, etc. So the extension of the file,...
4
votes
2answers
250 views

How do you adapt to changes to product specifications during development?

Problem Changes to product requirements/specifications during the development cycle are inevitable in a professional setting. In particular, I'm constantly dealing with changes to the specification ...
2
votes
2answers
86 views

How can I provide a user edit-level control over currently hardcoded formulas?

Current Situation I maintain a website that has a simple form that users fill out with simple engineering data. They press Submit, and the PHP code takes over and does various basic arithmetic on ...
5
votes
1answer
12k views

Alternative for eval() in javascript for expression evaluation

I'm looking at the alternative that can substitute the use of eval() and new Function() javascript techniques. I'm developing a solution build with javascript and the platform on which it is built (...
16
votes
2answers
7k views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function on) the source code character-by-...
5
votes
5answers
2k views

How to store math expression in c++ list

I am parsing a infix math expression to a postfix form. I want to store it in a list like [4.5, 3, 0.25, +, -] so that I can process it once it's parsed. I could store it in a string again, but I ...
0
votes
1answer
187 views

Inheritance and Parcels

In Android development, we have Parcelable interface. Since I wish to build Data Models that will run on multiple apps and services (not just Android), I would like to add two jar libs that will share ...
4
votes
1answer
90 views

Code style for parse-methods in Scala?

Say I have a class with multiple parameters: case class Foo(a: String, b: String, c: String, d: String, ... ) Now say I want to parse an instance of Foo from a Map[String, String]: // returns ...
1
vote
1answer
563 views

An elegant way to split text into words combined with adjacent punctuation and determine which punctuation mark it is

Firstly, I realize that question title is about as terrible as the sample code I'll post below, so please bear with me while I explain the problem more clearly, and if you have a better idea for the ...
4
votes
1answer
951 views

Right way to read from token list to implement parse tree

I'm trying to tackle the While Language problem on HackerRank using Scala. I've been given a set of grammar rules and have to implement the actual interpreter underlying it. I've decided to approach ...
1
vote
1answer
222 views

OOP: how to keep some state for a brief moment?

My job and my personal interests often have me writing parsing code, that is, code that converts from an input string written in a given formal language to a tree of model objects. I come from a C ...
23
votes
3answers
3k views

In which process does syntax error occur? (tokenizing or parsing)

I'm trying to understand compilation and interpretation, step by step figuring out a total image. So I came up to a question while reading http://www.cs.man.ac.uk/~pjj/farrell/comp3.html this article ...
27
votes
8answers
5k views

Is it possible to statically predict when to deallocate memory---from source code only?

Memory (and resource locks) are returned to the OS at deterministic points during a program's execution. The control flow of a program by itself is enough to know where, for sure, a given resource can ...
4
votes
2answers
252 views

Testing strategies for interpreter language parser

For a recent personal project, I started working on an interpreter for my own programming language. One of the ground rules I set for myself on this project is that I need to properly test as much of ...
11
votes
2answers
829 views

language with two binary operators of same precedence, left-associative & right-associative

Are there any programming (or scripting) language (or some domain specific language) having two binary operators opl and opr of same precedence with opl being left-associative and opr being right-...
0
votes
1answer
374 views

Is it possible to parse my grammar with multi-line productions without backtracking?

I'm playing around with creating a parser in PHP for my own flavor of BNF, to match strings against grammar in this BNF variant. It's still a work in progress and subject to change (I may even end up ...
1
vote
2answers
581 views

“Fuzzy” parsing in different languages

I have a bunch of plain-text like this: 1 MILE, PACE, PURSE $1,100. FILLIES & MARES N/W $541 L5 STARTS AE N/A $301 L5 & N/A $60 PS IN 2015-16 DRAW INSIDE ...
2
votes
4answers
217 views

Is the var token necessary to signal variable declaration?

When creating a variable foo, Python lets you just write foo = bar. However many languages, like C# or JavaScript, require additional syntax like var foo = bar or foo := bar to signal the same thing. ...
1
vote
1answer
49 views

How to handle user created expressions in application

In our application users can enter custom expressions to calculate certain things. For instance they can specify an invoice and define a number of lines for cost calculation. Example for a course ...
1
vote
1answer
443 views

What is a lattice parser?

My friend asked me for help with his task: "Redeem a lattice parser with any programming language" - the problem is that he can't clearly explain me how the lattice parser should work. I've tried to ...