I am trying to parse formula in C# language like
"5*3 + 2"
"(3*4 - 2)/5"
Is it possible to do in C# or scripts like VBScript, JavaScript (which will be called in c# program).
Hi guys, I am helping my nephew for his C lab homework, it is a string manipulation assignment and applying Wang's algorithm.
Here is the BNF representation for the input.
<sequent> ::= <lhs> # <rhs>
<lhs> ::= <formulalist>| e
<rhs> ::= <formulalist>| e
<formulalist> ::= <formula>|<formula> , <formulalist>
<formula> ::= <letter>| - <formula>| (<formula><in?xop><formula>)
<in?xop> ::= & | | | >
<letter> ::= A | B | ... | Z
What is the best practice to handle and parse this kind of input in C? How can I parse this structure without using struct? Thanks in advance.
I have a string like this:
"foo=bar&bar=foo&hello=hi"
Does Ruby on Rails provide methods to parse this as if it is a querystring, so I get a hash like this:
{
:foo => "bar",
:bar => "foo",
:hello => "hi"
}
Or must I write it myself?
EDIT
Please note that the string above is not a real querystring from a URL, but rather a string stored in a cookie from Facebook Connect.
How can I get some part of string that I need?
accountid=xxxxxx type=prem servertime=1256876305 addtime=1185548735 validuntil=1265012019 username=noob directstart=1 protectfiles=0 rsantihack=1 plustrafficmode=1 mirrors= jsconfig=1 [email protected] lots=0 fpoints=6076 ppoints=149 curfiles=38 curspace=3100655714 bodkb=60000000 premkbleft=25000000 ppointrate=116
I want data after email= but up to live.com.?
Greetings!
I have a text file with parameter set as follows:
NameOfParameter Value1 Value2 Value3 ...
...
I want to find needed parameter by its NameOfParameter using regexp pattern and return a selected Value to my Bash script.
I tried to do this with grep, but it returns a whole line instead of Value.
Could you help me to find as approach please?
I would like to create simple xml parser using bison/flex. I don't need validation, comments, arguments, only <tag>value</tag>, where value can be number, string or other <tag>value</tag>.
So for example:
<div>
<mul>
<num>20</num>
<add>
<num>1</num>
<num>5</num>
</add>
</mul>
<id>test</id>
</div>
If it helps, I know the names of all tags that may occur. I know how many sub-tag can be hold by given tag. Is it possible to create bison parser that would do something like that:
- new Tag("num", 1) // tag1
- new Tag("num", 5) // tag2
- new Tag("add", tag1, tag2) // tag3
- new Tag("num", 20) // tag4
- new Tag("mul", tag4, tag3)
...
- root = top_tag
Tag & number of sub-tags:
num: 1 (only value)
str: 1 (only value)
add | sub | mul | div: 2 (num | str | tag, num | str | tag)
Could you help me with grammar to be able to create AST like given above?
I'm trying to use reserved words in my grammar:
reserved = {
'if' : 'IF',
'then' : 'THEN',
'else' : 'ELSE',
'while' : 'WHILE',
}
tokens = [
'DEPT_CODE',
'COURSE_NUMBER',
'OR_CONJ',
'ID',
] + list(reserved.values())
t_DEPT_CODE = r'[A-Z]{2,}'
t_COURSE_NUMBER = r'[0-9]{4}'
t_OR_CONJ = r'or'
t_ignore = ' \t'
def t_ID(t):
r'[a-zA-Z_][a-zA-Z_0-9]*'
if t.value in reserved.values():
t.type = reserved[t.value]
return t
return None
However, the t_ID rule somehow swallows up DEPT_CODE and OR_CONJ. How can I get around this? I'd like those two to take higher precedence than the reserved words.
I was wondering whether the standard Scala parser combinators contain a parser that accepts the same identifiers that the Scala language itself also accepts (as specified in the Scala Language Specification, Section 1.1).
The StdTokenParsers trait has an ident parser, but it rejects identifiers like empty_?.
(If there is indeed no such parser, I could also just instantiate the Scala parser itself, but that wouldn't be as lightweight anymore.)
Hello everyone,
I am writing a text-based Scrabble implementation for a college project.
The specification states that the user's position input must be read from single line, like this:
Coordinates of the word's first letter and orientation (<A – P> <1 – 15> <H ou V>): G 5 H
G 5 H is the user's input for that particular example. The order, as shown, must be char int char.
What is the best way to read the user's input?
cin >> row >> column >> orientation will cause crashes if the user screws up.
A getline and a subsequent string parser are a valid solution, but represent a bit of work.
Is there another, better, way to do this, that I am missing?
Thanks for your time!
Hi,
I a bit overwhelmed with all of the sample code I've seen on the apple dev site.
I'm looking for a simple example to show me how to load an xml file from a server into iphone.
I would like to read url's from this xml file and load an image.
Hi I know about several PDF Generators for php (fpdf, dompdf, etc.)
What I want to know is about a parser.
For reasons beyond my control, certain information I need is only in a table inside a pdf
and I need to extract that table and convert it to an array.
Any suggestions?
Every time I write a simple lexer and parser, I stumble upon the same question: how should the lexer and the parser communicate? I see four different approaches:
The lexer eagerly converts the entire input string into a vector of tokens. Once this is done, the vector is fed to the parser which converts it into a tree. This is by far the simplest solution to implement, but since all tokens are stored in memory, it wastes a lot of space.
Each time the lexer finds a token, it invokes a function on the parser, passing the current token. In my experience, this only works if the parser can naturally be implemented as a state machine like LALR parsers. By contrast, I don't think it would work at all for recursive descent parsers.
Each time the parser needs a token, it asks the lexer for the next one. This is very easy to implement in C# due to the yield keyword, but quite hard in C++ which doesn't have it.
The lexer and parser communicate through an asynchronous queue. This is commonly known under the title "producer/consumer", and it should simplify the communication between the lexer and the parser a lot. Does it also outperform the other solutions on multicores? Or is lexing too trivial?
Is my analysis sound? Are there other approaches I haven't thought of? What is used in real-world compilers? It would be really cool if compiler writers like Eric Lippert could shed some light on this issue.
Hello!
Please take a look here: http://www.binarymark.com/Products/FLVDownloader/order.aspx
What I am trying to do is to get rid of the prices inside the option tag. On that page you can see a drop-down box under Order Information, Product. I want to remove the prices from all the options that contain them in that box, so get rid of " - $75.98" for example. I am not used to JQuery, but I realize it would be possible - just not sure how to do it, so your help would be greatly appreciated.
Thanks.
George
I've been trying to figure out how to parse textures in directx for two reasons: to write my own texture format and to manipulate data in existing IDirect3DTexture9 type textures.
I've been looking at the IDirect3DTexture9::LockRect() function but I'm unsure how it works, are the void* pBits I get out of it in D3DLOCKED_RECT the data in the texture? Does that mean I can read it in by converting it to D3DXCOLOR or something?
Really not sure where to go, any help would be appreciated!
Another day, another strange error with SAX, Java, and friends.
I need to iterate over a list of File objects and pass them to a SAX parser. However, the parser fails because of an IOException. However, the various File object methods confirm that the file does indeed exist.
The output which I get:
11:53:57.838 [MainThread] DEBUG DefaultReactionFinder - C:\project\trunk\application\config\reactions\TestReactions.xml
11:53:57.841 [MainThread] ERROR DefaultReactionFinder - C:\project\trunk\application\config\reactions\null (The system cannot find the file specified)
So the problem is obviously that null in the second line. I've tried nearly all variations of passing the file as a parameter to the parser, including as a String (both from getAbsolutePath() and entered by hand), as a URI and, even more weirdly, as a FileInputStream (for this I get the same error, except that the entire relative path gets reported as null, so C:\project\trunk\null).
All that I can think of is that the SAXParserFactory is incorrectly configured. I have no idea what is wrong, though.
Here is the code concerned:
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
try {
parser = factory.newSAXParser();
}
catch (ParserConfigurationException e) {
throw new InstantiationException("Error configuring an XML parser. Given error message: \"" + e.getMessage() + "\".");
}
catch (SAXException e) {
throw new InstantiationException("Error creating a SAX parser. Given error message: \"" + e.getMessage() + "\".");
}
...
for (File f : fileLister.getFileList()) {
logger.debug(f.getAbsolutePath());
try {
parser.parse(f, new ReactionHandler(input));
//FileInputStream fs = new FileInputStream(f);
//parser.parse(fs, new ReactionHandler(input));
//fs.close();
}
catch (IOException e) {
logger.error(e.getMessage());
throw new ReactionNotFoundException("An error occurred processing file \"" + f + "\".");
}
...
}
I have made no special provisions to provide a custom SAX parser implementation: I use the system default. Any help would be greatly appreciated!
Probably question title is rather cryptic but I will try to explain myself here so please bare with me :)
Let's assume this configuration:
server-side is PHP application responding for requests with data (list of items, single item details, etc.) in json format
client-side is JQuery application sending ajax request to that PHP app and creating html content corresponding with received data
So, for example: client requests "list of all animals with names staring with 'A'", gets the json response from server, and for every "animal" creates some html gizmo like div with animal description or something like that. It doesn't really matter what html element it will be but it has to point exactly to specific record by "containing" id of that record.
And here is my dilemma: is it good solution to use "id" property for that? So it would be like:
<div id="10" class="animal">
<p>
This is animal of very mysterious kind...
</p>
</div>
<div id="11" class="animal">
<p>
And this one is very common to our country...
</p>
</div>
where id="10" is of course indication that this is representation of record with id = 10.
Or maybe I should store this record id in some custom made tag like
<record_id>10</record_id>
and leave an "id" strictly for what it was meant to be (css selector)?
I need that record id for further stuff like updating database with some user input or deleting some of "animals" or creating new ones or anything that will be needed. All manipulations will be done with JQuery and ajax requests and responses will be visualized also with dynamic creation of html interface.
I'm sure that somebody had to deal with that kind of stuff before so I would be grateful for some tips on that topic.
This seems like a fairly simple question, and I'm surprised not to have required it before.
What is the most efficient way of testing a string input is a numeric (or conversely Not A Number).
I guess I can do a Double.Parse or a regex (see below)
public static bool IsNumeric(this string value)
{
return Regex.IsMatch(value, "^\\d+$");
}
but I was wondering if there was a implemented way to do it, such as javascript's NaN() or IsNumeric() (was that VB, I can't remember).
I am relatively new to implementing JQuery throughout an entire system, and I am enjoying the opportunity.
I have come across one issue I would love to find the correct resolve for.
Here is a simple case example of what I want to do:
I have a button on a page, and on the click event I want to call a jquery function I have defined.
Here is the code I have used to define my method (Page.js):
(function($) {
$.fn.MessageBox = function(msg) {
alert(msg);
};
});
And here is my HTML page:
<HTML>
<head>
<script type="text/javascript" src="C:\Sandpit\jQueryTest\jquery-1.3.2.js"></script>
<script language="javascript" src="Page.js"></script>
</head>
<body>
<div class="Title">Welcome!</div>
<input type="button" value="ahaha" onclick="$().MessageBox('msg');" />
</body>
</HTML>
(The above code displays the button, but clicking does nothing.)
I am aware I could add the click event in the document ready event, however it seems more maintainable to put events in the HTML element instead. However I have not found a way to do this.
Is there a way to call a jquery function on a button element (or any input element)? Or is there a better way to do this?
Thanks
I am working on an app which calls a rest web service. Sometimes the xml responses contain characters which the phone can not display. When displaying these characters, an empty box is displayed instead. I would like to filter out these characters. How can I detect if a character will be able to be displayed on the screen?
I use a jquery datepicker then i read it in my servlet like that:
String dateimput=request.getParameter("datepicker");//1
then parse it like that:
System.out.println("datepicker:" +dateimput);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date dt = null;
try
{
dt = df.parse(dateimput);
System.out.println("date imput parssé1 est:" +dt);
System.out.println("date imput parsée2 est:" +df.format(dt));
} catch (ParseException e)
{
e.printStackTrace();
}
and insert query like that:
String query = "Insert into dailytimesheet(trackingDate,activity,projectCode) values ("+df.format(dt)+", \""+activity+"\" ,\""+projet+"\")";
it pass successfully untill now but if i check the record inserted i found the date:
01/01/0001 00:00:00
l've tried to fix it but it still a mess for me.
I have to parse the XML file and build objects representation based on that, now once I get all these data I create entries in various database for these data objects. I have to do second pass over that for value as in the first pass all I could do is build the assets in various databases. and in second pass I get the values for all the data and put it in the database.
I have a feeling that this can be done in a single pass but I just want to see what are your opinions. As I am just a student who started with professional work, experienced ppl please help.
Can someone who have ideas or done similar work, please provide some light on the topic so that I can think over the possibility of the work and get the prototype going based on your suggestion.
Thanks a lot for your precious time, I honestly appreciate it.
This is my code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Gallery</title>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/lightbox.js"></script>
<link href="css/lightbox.css" rel="stylesheet" />
</head>
<body>
<?php
$value=$_GET["value"];
$handle = opendir("content/$value/gallery/");
while($file = readdir($handle))
{
if($file !== '.' && $file !== '..')
{
do_something;
}
}
?>
</body>
</html>
Passing value "?a??????",
gives Warning: opendir(content/?a??????/gallery/): failed to open dir: No such file or directory.
But if i do this :
$handle = opendir("content/?a??????/gallery/");
it works fine.
Something to do with character encoding? How could i solve this?
Thank you.
I have a binary content of image/pdf in java script variable downloaded from server. There will be indication server about the typr of the file. I have to display the content in respective file format. If it is image , i have to display the image. If it is a pdf, i have to open the content in pdf format. and so on. How to parse the binary content and display it? I have searched for it. But I couldn't find exact solution. I'm using jquery mobile framework. Pls help..
I am trying to parse a file generated by LGA Tracon that lists the position data for aircraft over a given time frame. The data of interest starts with TRACKING DATA and ends with SST and there are thousands of entries per file. The system generating the file, Common ARTS, is very rigid in its formatting and we can expect the column spacing to be consistent. Any help would be greatly appreciated.
Thanks,
Here is an image to preserve the exact formatting
Here is a reduced text file.
link text
Hi,
I've just read Apple's docu of NSScanner.
I'm trying to get the integer of that string: @"user logged (3 attempts)".
I can't find any example, how to scan within parentheses. Any ideas?
Here's the code:
NSString *logString = @"user logged (3 attempts)";
NSScanner *aScanner = [NSScanner scannerWithString:logString];
[aScanner scanInteger:anInteger];
NSLog(@"Attempts: %i", anInteger);
Regrads,
Ruby