grammar

Creating diagram of grammar (bison)

Hey, Do you know guys how to create a diagram like following: http://www.svgopen.org/2009/papers/58-Interactive_Documentation_using_JavaScript_and_SVG/oracle_graph.png from bison grammar? ...

How to solve a shift/reduce conflict?

Hi, I'm using CUP to create a parser that I need for my thesis. I have a shift/reduce conflict in my grammar. I have this production rule: command ::= IDENTIFIER | IDENTIFIER LPAREN parlist RPAREN; and I have this warning: Warning : *** Shift/Reduce conflict found in state #3 between command ::= IDENTIFIER (*) and command :...

LL(1) grammars, looking for a good, clear resource.

I am taking a principals of programming class right now. We are learning about LL(1) grammars. I found the book and lectures to be somewhat unclear and was hoping that someone could refer me to a good resource. I found some good youtube tutorials for finate state automatons and determinate state automatons, but I cannot find any...

Grammar: difference between a top down and bottom up?

What is the difference between a top down and bottom up grammar? An example would be awesome. ...

Grammar: difference between a top down and bottom up? (Example)

This is a follow up question from Grammar: difference between a top down and bottom up? I understand from that question that: the grammar itself isn't top-down or bottom-up, the parser is there are grammars that can be parsed by one but not the other (thanks Jerry Coffin So for this grammar (all possible mathematical formulas): ...

vxml: defining grammars with equivalent inputs

I am using an engine based on TellMe. I have seen examples of grammars where the user can say one of a few different things that are considered the same. However, all the examples i've seen have been for in-line grammars (which dont work with the vxml engine im using). I want to know how i can change my .grxml file to do this. This is th...

Poker hand range parser ... how do I write the grammar?

Hi all - I'd like to build a poker hand-range parser, whereby I can provider a string such as the following (assume a standard 52-card deck, ranks 2-A, s = suited, o = offsuit): "22+,A2s+,AKo-ATo,7d6d" The parser should be able to produce the following combinations: 6 combinations for each of 22, 33, 44, 55, 66, 77, 88, 99, TT, JJ, ...

Counting definite clause grammar recursions in Prolog

I have the following Prolog definite clause grammar: s-->[a],s,[b]. s-->[]. This will result in words like [a,a,b,b] being accepted in opposite to words like [a,b,a,b]. To put it in a nutshell the grammar is obviously a^n b^n. Now I want to return n to the user. How can I calculate n? ...

Parsing numbers with multiple digits in Prolog

I have the following simple expression parser: expr(+(T,E))-->term(T),"+",expr(E). expr(T)-->term(T). term(*(F,T))-->factor(F),"*",term(T). term(F)-->factor(F). factor(N)-->nat(N). factor(E)-->"(",expr(E),")". nat(0)-->"0". nat(1)-->"1". nat(2)-->"2". nat(3)-->"3". nat(4)-->"4". nat(5)-->"5". nat(6)-->"6". nat(7)-->"7". nat(8)-->"8"....

Left recursion in grammar with "." operator

So, I'm writing an LL(1) parser (for kicks) and I ran into a problem with the member selection operator ("." as in "var.function()"). Here's a simplified grammar I'm trying to analyze with the parser: postfix_expression : postfix_expression '(' ')' | postfix_expression '.' identifier | identifier ; The above grammar i...

Two Different Grammars Over One Set of Outputs

Hello everyone! Can you give me 2 different grammars which outputs the same set of words? Illustration: Given a grammar A and B over the alphabet {0,1}, if grammar A can produce the word 0101001, grammar B could as well. If grammar B can produce 0101111 then grammar A could as well. And if grammar A can't produce 01001 then B can neit...

Help ... LL Grammar And Recursive descent parser

I'm using ANTRL and this is my some grammar which give error to me. statement : (name)( | BECOMES expression | LPAREN (expression (COMMA expression)*)? RPAREN | SHIFTLEFT name LPAREN (expression ( COMMA expression )*)? RPAREN ) | OUTPUT LPAREN expression ( COMMA expression)* RPAREN | IF expression THEN state...

POSIX shell like implementation in Java

Does anybody know of an implementation of POSIX shell like language for scripting things in Java? If this is not available, does anybody know if there is a ANTLR or JavaCC grammar available somewhere which I might have missed? edit: I know that I have Jython, JRuby, Groovy, JavaScript available for scripting, but none of them have ba...

Where to find info on ODBC SQL dialect/grammar, incl. built-in functions/operators?

I'm looking into writing a C++ database library that will run on top of either ODBC or on top of another library that itself uses ODBC (possibly DTL, OTL, or SOCI). At this point I need to know what SQL functions (MIN, MAX, AVG, EXISTS, IN, etc.) and operators (+, -, /, *, etc.) I'll have available through the ODBC SQL dialect without n...

Strange problem with context free grammar

I begin with an otherwise well formed (and well working) grammar for a language. Variables, binary operators, function calls, lists, loops, conditionals, etc. To this grammar I'd like to add what I'm calling the object construct: object : object_name ARROW more_objects ; more_objects : object_name | object_name ARROW more_ob...

Follow sets for self-recursive rules

Alright, I'm trying to understand follow sets and I think I got it except for one thing: X -> a X X -> b X X -> epsilon Following the rules of this page, FOLLOW(X) should contains $, the end of file character (rule 1). Then, following rule 3, FOLLOW(X) contains everything of FOLLOW(X) which makes my brain melt. To me, intuitively, FO...

What does ^ and ! stand for in ANTLR grammar

I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology. ...

Grammar vs. Semantic analysis

I am wondering where is the borderline between grammar specification and semantic analysis. What is better: to use a detailed grammar description or leave the details for semantic phase? For example: imagine an OO-language like C# with enum type, that can "derive" from a primitive type enum X : int { a = 1 } Now, should the correctnes...

Implementing parser for markdown-like language

I have markup language which is similar to markdown and the one used by SO. Legacy parser was based on regexes and was complete nightmare to maintain, so I've come up with my own solution based on EBNF grammar and implemented via mxTextTools/SimpleParse. However, there are issues with some tokens which may include each other, and I don...

Printing and concatenation with Parse::RecDescent

I am testing the grammar from P::RD tutorial in order to develop my own grammar. I haven't figured out how to print a string declaration and append '$' to the front of it. For example "STRING sDir" should print out "$sDir". It is simple enough to just do a $string =~ s/STRING /\$/, but what about the case where there is assignment? eg. "...