parsing

Validate a statment from string in Java

I have a string; String allIn = "(50 > 100) AND (85< 100)"; Now I need to evaluate if the conditions inside are TRUE or FALSE, how can I do it? In real the string will be a value from a field in my DB, where I will substitute different values and they will form a string as shown above. ...

Postback of delimited text from javascript and parsing on server side

In my ASP.NET page, I have a Javascript object, like this: var args = new Object(); args.Data1 = document.getElementById("Data1").value; args.Data2 = document.getElementById("Data2").value; args.Data3 = document.getElementById("Data3").value; The object is populated on client side using user input data. I am passing th...

JavaCC: How can one exclude a string from a token? (A.k.a. understanding token ambiguity.)

Hello, everyone! I had already many problems with understanding, how ambiguous tokens can be handled elegantly (or somehow at all) in JavaCC. Let's take this example: I want to parse XML processing instruction. The format is: "<?" <target> <data> "?>": target is an XML name, data can be anything except ?>, because it's the closing tag...

How to convert a string with escaped characters into a "normal" string

Let's say that I have like this: "\\n", I need to convert it to a string like if the interpreter would do it: \n. A simple replace like this wouldn't work: function aaa(s){ return s.replace(/\\n/gm,'\n').replace(/\\\\/gm,'\\'); } I need this behaviour: "Line 1\nLine 2" => Line 1<Line break>Line 2 "Line 1\\nLine 1" => Line 1\n...

Getting content of the node having childs via DOMDocument

I have following html: <html ><body >Body text <div >div content</div></body></html> How could I get content of body without nested <div>? I need to get 'Body text', but do not have a clue how to do this. result of running $domhtml = DOMDocument::loadHTML($html); print $domhtml->getElementsByTagName('body')->item(0)->nodeValue; ...

How to get strptime to raise ArgumentError with garbage trailing characters

We have to handle user specified date formats in our application. We decided to go with Date.strptime for parsing and validation, which works great, except for how it just ignores any garbage data entered. Here is an irb session demonstrating the issue ree-1.8.7-2010.01 > require 'date' => true ree-1.8.7-2010.01 > d = Date.strptime '2...

Retrieving the first picture with a HTML parser

Hey guys, (Not a native english speaker) I'm doing a personal project in PHP in which I use the Simple HTML Parser to parse the HTML of a given URL and retrieve the first image in a DIV that have a specific ID or class (maincontent, content, main, wrapper, etc. - it's all in an array) and ignore ads. The goal is to take this image and ...

RSS parsing last build Date. Fastest way to do so please.

Dim myRequest As System.Net.WebRequest = System.Net.WebRequest.Create(url) Dim myResponse As System.Net.WebResponse = myRequest.GetResponse() Dim rssStream As System.IO.Stream = myResponse.GetResponseStream() Dim rssDoc As New System.Xml.XmlDocument() Try rssDoc.Load(rssStream) Catch nosupport As NotSuppor...

How to parse mathematical expressions involving parentheses

This isn't a school assignment or anything, but I realize it's a mostly academic question. But, what I've been struggling to do is parse 'math' text and come up with an answer. For Example - I can figure out how to parse '5 + 5' or '3 * 5' - but I fail when I try to correctly chain operations together. (5 + 5) * 3 It's mostly just bu...

Ruby , Parsing an XML Document, How can i print the number of subtags for a given tag

ref xml doc I want to parse on EACH <HOST> and get the number of <OID> , along with Values of each <TYPE> <HOST> <IP>10.1.3.1</IP> <TRACKING_METHOD>IP</TRACKING_METHOD> <DNS><![CDATA[.demo.com]]></DNS> <OPERATING_SYSTEM><![CDATA[abcd Version 7]]></OPERATING_SYSTEM> <ASSET_GROUPS> <ASSET_GROUP_TITLE><![CDATA[Demo Lab ]...

Most Lite-Weight XML Parser with XPath and Wide-char Support

I want a lite-weight C++ XML parser/DOM that: Can take UTF-8 as input, and parse into UTF-16. Maybe it does this directly (ideal!), or perhaps it provides a hook for the conversion (such as taking a custom stream object that does the conversion before parsing). Offers some XPath support. I've been looking at RapidXML, the Kranf xmlP...

BNF to handle escape sequence

I use this BNF to parser my script: ` {identset} = {ASCII} - {"\{\}}; //<--all ascii charset except '\"' '{' and '}' {strset} = {ASCII} - {"}; ident = {identset}*; str = {strset}*; node ::= ident "{" nodes "}" | //<--entry point "\"" str "\"" | ident; nodes ::= node nodes | ...

protocol parsing in c

I have been playing around with trying to implement some protocol decoders, but each time I run into a "simple" problem and I feel the way I am solving the problem is not optimal and there must be a better way to do things. I'm using C. Currently I'm using some canned data and reading it in as a file, but later on it would be via TCP or ...

Does C# have (direct) flex/yacc port? Or what lexer/parser people use for C#?

I might be wrong, but it looks like that there's no direct flex/bison (lex/yacc) port for C#/.NET so far. For LALR parser, I found GPPG/GPLEX, and for LL parser, there is the famous ANTLR. But, I want to reuse my flex/bison grammar as much as possible. Is there any direct port of flex/bison for C#? What lexer/parser people normally ...

What's a good machine-readable formal way of describing telecom protocols such as SMPP or CIMD2?

I've implemented several telecom protocols from human-readable specs in various languages during my career, and frankly, I'm not enjoying it very much anymore. Instead, I'd like to translate the human-readable protocol specs into machine-readable protocol specs, and automatically generate protocol handlers in various languages. I'm sp...

Capturing Field Name Metadata from a CSV File in Altova MapForce

I've been asked to prototype a replacement "file transformation process" (that currently is a mess of SQL) using Altova's MapForce. My input is a CSV file with headers. My problem is that I need to capture both the data AND the column name to use in downstream processing. I need to have MapForce feed a C# method (imported as that takes ...

Reverse Streamreader

I have an application that I've been tasked with cleaning up after. The application itself is relatively simple - it runs a SQL query, consumes a web service, and spews the results to a log file. My job is to archive the files to our NAS after the application is done with them. It locks the files exclusively until it's done with them so ...

How do i ignore rows with unique string while parsing a csv file in ruby

i want to ignore ALL TopLevel, Result,,,,,,,, AddHost,10.1.3.1,,,,,,,, and Flush,,,,,,,,, AddHost,10.1.3.4,,,,,,,, from TopLevel, Result,,,,,,,, AddHost,10.1.3.1,,,,,,,, Add,10.1.3.1,43172 Add,10.1.3.1,44172 Add,10.1.3.1,4172 Add,10.1.3.1,432 Add,10.1.3.1,435472 Flush,,,,,,,,, AddHost,10.1.3.4,,,,,,,, ...

Perl module for parsing natural language time duration specifications (similar to the "at" command)?

I'm writing a perl script that takes a "duration" option, and I'd like to be able to specify this duration in a fairly flexible manner, as opposed to only taking a single unit (e.g. number of seconds). The UNIX at command implements this kind of behavior, by allowing specifications such as "now + 3 hours + 2 days". For my program, the "n...

JDT ASTParser to get the value of a string field

Is there a way to use jdt ASTParser to get the value of a String field declared in a java file. Actually what I need is to resolve any possible dependencies from other classes e.g. public String str = "somethig"+SomeTherClass.SOMETHING_ELSE. ...