grammar

Are there any programs to help with reading the grammar in a yacc file?

I'm trying to figure out what legal statements I can make by looking at the grammar in a yacc file, but it's kind of hard. Are there any programs to make this sort of thing easier? ...

What's wrong with my grammar

I try to input the following into my yacc parser: int main(void) { return; } It looks valid to me according to what's defined in the yacc file, but I get a "syntax error" message after the return. Why is that? The yacc file: /* C-Minus BNF Grammar */ %{ #include "parser.h" #include <string.h> %} %union { int intval; struct...

Is there a shift/reduce error in this yacc code?

I'm getting a message from yacc saying that there is a shift/reduce conflict. I think it's coming from this part of the yacc file. statement : expression_stmt | compound_stmt | selection_stmt | iteration_stmt | return_stmt ; selection_stmt : IF '(' expression ')' statement | IF '(...

Grammars, Scala Parsing Combinators and Orderless Sets

I'm writing an application that will take in various "command" strings. I've been looking at the Scala combinator library to tokenize the commands. I find in a lot of cases I want to say: "These tokens are an orderless set, and so they can appear in any order, and some might not appear". With my current knowledge of grammars I would hav...

Why does my yacc program not recognize function declarations?

I think my program should be able to recognize the following as a function declaration int fn(int i) { int n; return; } but it doesn't. Here's the relevant part of my yacc file program : declaration_list ; declaration_list : declaration_list declaration | declaration ; declaration : var_declaration | fun_declaration ...

Tips on Using Bison --graph=[file] on Linux

Recently (about a month ago) I was trying to introduce new constructs to my company's in-house extension language, and struggling with a couple of reduce-reduce errors. While I eventually solved this problem, digging into the y.output file was no picnic. As an experiment, I tried using Bison's --graph=<file> option to output a DOT file ...

Question about building a symbol table with a yacc parser

If my yacc parser encounters the following code: int foo(int a, int b) should it add int a and int b as attributes of foo? The way I have it now, it enters a and b as separate table entries. ...

AS3 Grammar: Most accurate

I'm looking for an accurate AS3 grammar (format in not an issue, but I presume ANTLR will feature the most) to use for a practice grammar I'm making. What is the most accurate grammar available for AS3? ...

C++ create a parser

What's the best way to create a parser in C++ from a file with grammar? ...

ANTLR “Cannot launch the debugger. Time-out waiting to connect to the remote parser.”

One of my ANTLR grammars running in AntlrWorks throws: “Cannot launch the debugger. Time-out waiting to connect to the remote parser.” In the past this message usxually goes away but this one is persistent. On searching the ANTLR lists (e.g. http://www.antlr.org/pipermail/antlr-interest/2009-June/034659.html) there are hints that the ...

Does anyone recognise this unfamiliar notation?

I have a question from a test in a Programming Languages class that is confusing me. Give a context-free grammar to generate the following language L = { aibjck | 0 <= i <= j <= i + k } I am completely unfamiliar with this notation. I cant seem to find anything in the book or my notes about it, and I have no idea how to query google f...

ANTLR grammar license

I'm planning to make an implementation of Lua for the DLR, and i would like to use the listed Lua 5.1 grammar here. However i can't see a license that it was released under, so can someone please kindly point me in the direction of the license it uses? ...

Does this grammar allow scope nesting?

I'm only able to make functions inside the global scope. Scope nesting means being able make functions within functions, right? I'm not able to do that with this grammar. Is it possible? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %tok...

ANTLRWorks error compiling grammar: "syntax error: invalid char literal: INVALID"

I wrote a stub for a grammar (only matches comments so far), and it's giving me the error "syntax error: invalid char literal: <INVALID>". Moreover, i've tracked down the error to being in the following command: ... ~LINE_ENDING* ... LINE_ENDING : ( '\n' | '\r' | '\r\n'); Can someone help me fix this? ...

Reserved keywords in Objective-C?

At the CocoaHeads Öresund meeting yesterday, peylow had constructed a great ObjC quiz. The competition was intense and three people were left with the same score when the final question was to be evaluated: How many reserved keywords does Objective-C add to C? Some spirited debate followed. All agreed that @interface, @implementation et...

Keyword Matching in Pyparsing: non-greedy slurping of tokens

Pythonistas: Suppose you want to parse the following string using Pyparsing: 'ABC_123_SPEED_X 123' were ABC_123 is an identifier; SPEED_X is a parameter, and 123 is a value. I thought of the following BNF using Pyparsing: Identifier = Word( alphanums + '_' ) Parameter = Keyword('SPEED_X') or Keyword('SPEED_Y') or Keyword('SPEED_Z') ...

Libraries to help implement a CLI in Ruby?

Hi, I'm trying to implement a CLI type application in Ruby. The CLI should accept commands using a grammar that I wish to define. I've found some leads on how to implement and parse a grammar (RParsec) but I don't see how I can hook that up to some code to acutally execute the command. Commands would be something like (very rough id...

Grammar Syntax and Linguistics...

I REALLY need a description of the english sentence structure in a way that can be translated by machine and is strictly rule based(no statistical stuff), it doesn't have to be a context-free grammar but that would be preferable(as it can't be and fully describe it). The best I've found was for a BNF but it was really basic. I need somet...

Is this grammar not LR(1)?

I'm working on parse generator for PHP. Currently I'm trying to implement canonical LR(1) parser, but it outputs reduce-reduce conflict on following grammar. Is this grammar not LR(1)? Or should I recheck my algorithms? Grammar in Bison(-like) notation: syntax : toplevels rules ; toplevels : toplevel | toplevel toplevels ;...

PHP_ParserGenerator - bug in grammar or in the parser generator?

I'm trying to create a parser for a simple language with the lemon port to PHP, and it works, almost. The following grammar: %name SP_ %declare_class { class SpecParser } %token_prefix SP_ %include_class { public $retvalue = '<todo: error handling>'; public function singleKey($elem) { end($elem); return key($elem); } } %pa...