grammar

First & Follow Sets check for simple grammar

Here's a few questions I had on a quiz in a class and just want to verify their correctness. Grammar: S -> ABC A -> df | epsilon B -> f | epsilon C -> g | epsilon 1.) The Follow set of B contains g and epsilon (T/F)? Ans: F. There is no epsilon in the Follow sets, correct? (Only $ aka end of input) 2.) The First set of S contains d, ...

Plural form of word "mutex"

What is the correct plural form of the portmanteau mutex. Is it mutexes or mutices? ...

ANTLR equivalent to bison REJECT action ?

I'm trying to parse a list of Name=Value pairs, where the value can contain anything except whitespace (i.e. values can contain equal signs). The name is restricted to usual identifier characters. The problem is, the 'Value' token matches everything. For example, for the input: dude=sweet the parser will match the whole input with a ...

MGrammar and more than one valid interpretation

I think what I may have is the dangling else problem, but I'm not really sure. The language I'm tasked with writing needs to support multi-line if statements as well as single line i.e. if(conditions){ print "multi"; print "line"; } and if(conditions) print "single line" Which in my language corresponds to if conditions t...

How can I parse a list of name=value pairs in a parser generator (ANTLR, YACC etc)?

I want to parse a list of (whitespace separated) pairs in the form of name1=value1 name2=value2 ... where: NAME can contain anything except whitespace and equal sign VALUE can contain anything except whitespace (including equal signs!) The problem is getting the parser to match input like name1=value1 as separate 'NAME EQUAL...

Problem with a shift-reduce conflict in my grammar

I'm trying to write a small parser with Irony. Unfortunately I get a "shift-reduce conflict". Grammars are not my strong point, and I only need to get this one small thingy done. Here's the reduced grammar that produces the error: ExpressionTerm := "asd" LogicalExpression := ExpressionTerm | LogicalExpression "AND" LogicalExpres...

What are some exotic parsing techniques?

I've been parsing poker hand histories for the past year and have learned quite a deal about parsing in general. We started with regexes but quickly realized that wouldn't scale easily. We skipped languages from ruby to c++ and finally came to grips that it was the algorithim that had to change. We picked up Boost::Spirit and watched o...

Composable Grammars

There are so many programming languages which support the inclusion of mini-languages. PHP is embedded within HTML. XML can be embedded within JavaScript. Linq can be embedded within C#. Regular expressions can be embedded in Perl. // JavaScript example var a = <node><child/></node> Come to think of it, most programming languages can ...

How to resolve a shift-reduce conflict in unambiguous grammar

I'm trying to parse a simple grammar using an LALR(1) parser generator (Bison, but the problem is not specific to that tool), and I'm hitting a shift-reduce conflict. The docs and other sources I've found about fixing these tend to say one or more of the following: If the grammar is ambiguous (e.g. if-then-else ambiguity), change the l...

Why is SQL's grammar inside-out?

In just about any formally structured set of information, you start reading either from the start towards the end, or occasionally from the end towards the beginning (street addresses, for example.) But in SQL, especially SELECT queries, in order to properly understand its meaning you have to start in the middle, at the FROM clause. Th...

Produce a sentence from a grammar with a given number of terminals

Say you've got a toy grammar, like: (updated so the output looks more natural) S -> ${NP} ${VP} | ${S} and ${S} | ${S}, after which ${S} NP -> the ${N} | the ${A} ${N} | the ${A} ${A} ${N} VP -> ${V} ${NP} N -> dog | fish | bird | wizard V -> kicks | meets | marries A -> red | striped | spotted e.g., "the dog kicks the red wizard...

ANTLR: Grammar Test for Optional Parameter (using ? operator)

I have an ANTLR grammar and am defining a function in my language that allows an optional parameter. How can I check whether the optional parameter is passed in or not within the code generation block? I'm basically looking for the syntax to do something like this hypothetical tree grammar statement: myFunc returns [int retval] : 'myFu...

javacc parseException... lookahead problem?

I'm writing a parser for a very simple grammar in javacc. It's beginning to come together but at the moment I'm completely stuck on this error: ParseException: Encountered "" at line 4, column 15. Was expecting one of: The line of input in question is z = y + z + 5 and the production that is giving me problems is my expression w...

How can I construct a grammar that generates this language?

I'm studying for a finite automata & grammars test and I'm stuck with this question: Construct a grammar that generates L: L = {a^n b^m c^m+n|n>=0, m>=0} I believe my productions should go along this lines: S->aA | aB B->bB | bC C->cC | c Here's where I have doubts How can my production for C remember the numbers of m a...

Generate Fortran 77 parser from a yacc grammar using Happy (Haskell)

I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&amp;view=markup. How can I make a Fortran 77 parser out of this file using Happy? Why is there some C?/C++? code in that .y file? UPDATE: Thank you for your replies! I've been playing with two fresh app...

Difference between an LL and Recursive Descent parser?

I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and most of it seems to be making sense, except for one thing. I'm focusing my attention in particular on LL(k) grammars, for which the two main algorithms seem to be the LL parser (using stack/parse table) and the Recursive Descent parser ...

Open Source Grammar Checker

For an online project I'm working on, I am looking for a open source grammar checker. I have searched Google, with some good results (http://www.link.cs.cmu.edu/link/, etc), but I am wondering what all of you think about this topic. I need this to be able to be used online, versus desktop based, but this is the only real specification ...

How can I construct a clean, Python like grammar in ANTLR?

G'day! How can I construct a simple ANTLR grammar handling multi-line expressions without the need for either semicolons or backslashes? I'm trying to write a simple DSLs for expressions: # sh style comments ThisValue = 1 ThatValue = ThisValue * 2 ThisOtherValue = (1 + 2 + ThisValue * ThatValue) YetAnotherValue = MAX(ThisOtherValue, ...

CLI grammar checker for determining tense

I like to use the present tense in my Git logs (for example, "Add feature" instead of "Added feature"). Currently, I have an extremely naive Git hook that aborts the commit if the first word of the log message ends in 'ed', but I'd like a more robust solution (where 'more robust' means 'not totally lame'). Is there a grammar checker th...

What program(s) generate grammar graphs?

I see grammar graphs on the websites for SQLite and JSON. What program can be used to generate these pretty pictures? ...