grammar

Time/Date range grammars

I need to parse strings containing time spans such as: Thursday 6:30-7:30 AM December 30, 2009 - January 1, 2010 1/15/09, 7:30 to 8:30 PM Thursday, from 6:30 to 7:30 AM and others... added 6:30 to 7:30 and date/times such as most any cases that Word's insert->date can generate As I'd be extremely surprised if anything out there ...

Learning Treetop

I'm trying to teach myself Ruby's Treetop grammar generator. I am finding that not only is the documentation woefully sparse for the "best" one out there, but that it doesn't seem to work as intuitively as I'd hoped. On a high level, I'd really love a better tutorial than the on-site docs or the video, if there is one. On a lower leve...

Writing XSS Filter for (X)HTML Based on White List

Hello, I need to implement a simple and efficient XSS Filter in C++ for CppCMS. I can't use existing high quality filters written in PHP because because it is high performance framework that uses C++. The basic idea is provide a filter that have a while list of HTML tags and a white list of options for these tags. For example. typical H...

Standard format for concrete and abstract syntax trees

I have an idea for a hobby project which performs some code analysis and manipulation. This project will require both the concrete and abstract syntax trees of a given source file. Additionally, bi-directional references between the two trees would be helpful. I would like to avoid the work of transcribing a grammar to construct my own l...

Regular vs Context Free Grammars

I'm studying for my Computing languages test and there's one idea I'm having problems wrapping my head around. I understand that Regular Grammars are simpler and cannot contain ambiguity but can't do a lot of tasks that are required for programming languages. I also understand that Context Free Grammars allow ambiguity, but allow for s...

BNF grammar matching

My teacher has given me two bnf grammars: A ::= 'd' | A 'e' A | A 'f' A B ::= 'd' | B B 'e' | B B 'f' and four strings to match with them: dffd dddefddfe dedf deded I've figured out two of them, but the other two have me stumped. I don't want anyone to tell me the answers, but if someone could give me some hints as to where I'm...

How do I generate sentences from a formal grammar?

What's a common way of generating sentences from a grammar? I want an algorithm that's sort of the opposite of a parser. That is, given a formal context-free grammar (say LL), I want to generate an arbitrary sentence that conforms to that grammar. I use sentence here to mean any valid body of text, so it can actually be a whole program ...

Grammar for Arithmetic Expressions

I was assigned a task for creating a parser for Arithmetic Expressions (with parenthesis and unary operators). So I just wanna know if this grammar correct or not and is it in LL(1) form and having real problems constructing the parse table for this S -> TS' S' -> +TS' | -TS' | epsilon T -> UT' T' -> *UT' | /UT' | epsilon U -> VX...

First & Follow set for Arithmetic Expressions

I want to know if my FIRST and FOLLOW set I made for this grammar is correct or not S -> TS' S' -> +TS' | -TS' | epsilon T -> UT' T' -> *UT' | /UT' | epsilon U -> VX X -> ^U | epsilon V -> (W) | -W | W | epsilon W -> S | number FIRST(S) = FIRST(T) = FIRST(U) = FIRST(V) = FIRST(W) = { ( , - , + , number , epsilon } FIRST(T') = {...

JavaME-suitable grammar compiler recommendations?

I want to parse some data, and I have a BNF grammar to parse it with. Can anyone recommend any grammar compilers capable of generating code that can be used on a mobile device? Since this is for JavaME, the generated code must be: Hopefully pretty small Low dependencies on exotic Java libraries Not dependant on any runtime jar files. ...

Ruby Grammar

I'm looking for Ruby grammar in BNF form. Is there an official version? ...

Can ANTLR generate a parser class that is final?

I'm using ANTLR 3.1 and ANTLRWorks to generate a parser class in Java. The parser performs better if I mark the generated class with the Java final keyword. The problem is: I am adding this keyword manually after each time I re-generated the code from the ANTLR grammar. Is there anyway, in the grammar, of telling ANTLR to add the final k...

Haskell - How to best to represent a programming language's grammar?

Hey, I've been looking at Haskell and I'd quite like to write a compiler (as a learning exercise) in it, since a lot of it's innate features can be readily applied to a compiler (particularly a recursive decent compiler). What I can't quite get my head around is how to represent a language's grammar in a Haskell-ian way. My first thoug...

MGrammar grammar and variable declaration

I'm sure I'll get told to do it another way, but for specific reasons it has to be done this way. If it didn't, I wouldn't be stuck :-P The scripting language I'm working on has to accept variables defined like this: Variables: x(1), y("hi"); This is a requirement. I wrote a small grammar before that would let me define them like t...

What is a tree parser in ANTLR and am I forced to write one?

I'm writing a lexer/parser for a small subset of C in ANTLR that will be run in a Java environment. I'm new to the world of language grammars and in many of the ANTLR tutorials, they create an AST - Abstract Syntax Tree, am I forced to create one and why? ...

Please help me define a language in EBNF

Give the EBNF specification for the language L that is made up of the chars a, b and c such that sentences in the language have the form L : sqsR -s is a string of any combination of the characters a and b -sR is that same string s reversed -q is an odd number of c's followed by either an odd number of b's or an even number ...

What is the simplest/clearest XSD for this XML?

What is the simplest/clearest style of XSD for this kind of XML? (it's from this answer) <object name="contact"> <object name="home"> <object name="tel"> <string name="area" value="910"/> <string name="num" value="1234 5678"/> </object> </object> <object name="work"> <object name="tel"> <string nam...

Is there a grammar parser (similar to yapps for python) for C++?

Hi all, I'm writing an experimental language, which is very close to pseudocode, for fun and to learn more about C++. One of the problems is that I need to parse some grammar, and my search to find a good C++ grammar parser has been unsuccessful (I couldn't find anything). What I want to accomplish is this: set a to 4 And I want th...

Appropriate article (a/an) in String.Format

I'm looking for a culturally-sensitive way to properly insert a noun into a sentence while using the appropriate article (a/an). It could use String.Format, or possibly something else if the appropriate way to do this exists elsewhere. For example: Base Sentence: "You are looking at a/an {0}" This should format to: "You are looking at...

What is the best book for Programming Language Theory?

What is a good book that covers the topics of grammars (context-free and context-sensitive) and their notations (EBNF, BNF, etc), syntax, type and programming language theory, etc? I'm not really digging the textbook we used at my school for our "Programming Languages" class and I'm looking to supplement some of the topics we covered wi...