Questions tagged [cup]

CUP is a parser generator for Java.

CUP generates Look-Ahead Left Recursive parser in Java.

It is related to two other projects:

  • is a scanner generator which can rely on CUP
  • Classgen is a tool to generate class frameworks and visitor patterns
76 questions
0
votes
1 answer

Ambiguous Context-free grammar? / Shift/Reduce conflict in CUP

I have the following context-free grammar for a simplified version of C++. When I run it with JFLEX and CUP I get a list of errors like that: Warning : *** Reduce/Reduce conflict found in state #173 between especificador ::= (*) and …
Rômulo Borges
  • 127
  • 1
  • 3
  • 9
0
votes
1 answer

Java cup: Shift/Reduce conflict

I'm trying to write a parser using JFlex and Cup, but I have some issues dealing with recursive pointed notation like function call with recursive properties access like : var x = obj.property1.functionCall(p1, p2).property2; Here is the related…
Polla Toube
  • 178
  • 3
  • 10
0
votes
0 answers

How to remove ambiguity in grammar using CUP?

I have this grammar S-> Stat Stat -> Exprs WRITE Stat -> Vars READ Vars -> ID COMMA Vars Vars -> ID Exprs -> Expr COMMA Exprs Exprs -> Expr Expr -> ID Expr -> ... ... (You can test it here http://jsmachines.sourceforge.net/machines/lalr1.html) The…
Alexander
  • 1
  • 1
0
votes
0 answers

unary negation in parsing java

What I am trying to do is allowing expression like 8 - - - 2 + 3. program ::= expr:e {: RESULT = ...; :} ; expr ::= INTCONST:c {: RESULT = ...; :} | binaryExpr:e {: RESULT = e; :} | LPAREN…
DLIM7
  • 41
  • 5
0
votes
1 answer

Why do Symbol's fields (left and right) always return 0?

I'm working on a pascal compiler using CUP and JFLEX. One of the requirements is to recover from errors and show where the errors are. I've been using CUP's method of syntax_error and unrecovered_syntax_error This is the parser code in my…
0
votes
1 answer

Do Prefix Notation with Cup

I create this code: import java_cup.runtime.*; terminal MAS,MENOS,POR,DIV,AP,CP,MINUS; terminal String NUMERO,IDENT; non terminal A; precedence left MAS,MENOS; precedence left POR,DIV; precedence left AP,CP; precedence left MINUS; A ::= A:a1…
Julio Gomez
  • 33
  • 1
  • 5
0
votes
1 answer

reduce/reduce conflict in CUP

I am implementing a parser for a subset of Java using Java CUP. The grammar is like vardecl ::= type ID type ::= ID | INT | FLOAT | ... exp ::= ID | exp LBRACKET exp RBRACKET | ... stmt ::= ID ASSIGN exp SEMI This works fine, but when I…
0
votes
1 answer

Java CUP (Parser) produces shift/reduce conflict when Type of variable or function is user defined

My grammer needs to have user defined Type ID combinations. The problem with the code below is that it generates the following: [java] Warning : *** Shift/Reduce conflict found in state #67 [java] between VariableDecls ::= (*) [java] and …
Radon5K
  • 47
  • 1
  • 9
0
votes
1 answer

Cast a non-terminal to java_cup.runtime.Symbol for empty case in grammar

I am writing a compiler using JFlex and CUP. I am trying to parse the empty state in my .cup file. To simplify things, consider this grammar: terminal Integer INT_LIT; nonterminal List stmtlist; nonterminal Statement …
adhdj
  • 352
  • 4
  • 17
0
votes
1 answer

Debugging a CUP grammar

I got stuck debugging a CUP grammar. So I have the following grammar in CUP: /* Integer operators */ precedence left SUM_OP, SUBS_OP; precedence left PROD_OP, DIV_OP; /* Boolean operators */ precedence left EQ_OP, LT_OP, GT_OP, LET_OP,…
Jsevillamol
  • 2,425
  • 2
  • 23
  • 46
0
votes
1 answer

Parsing blocks as Python

I am writing a lexer + parser in JFlex + CUP, and I wanted to have Python-like syntax regarding blocks; that is, indentation marks the block level. I am unsure of how to tackle this, and whether it should be done at the lexical or sintax level. My…
Jsevillamol
  • 2,425
  • 2
  • 23
  • 46
0
votes
1 answer

If then else ambiguity in CUP

I am constructing a grammar in CUP, and I have ran into a roadblock on defining IF-THEN-ELSE statements. My code looked like this: start with statements; /* Top level statements */ statements ::= statement | statement SEPARATOR statements…
Jsevillamol
  • 2,425
  • 2
  • 23
  • 46
0
votes
1 answer

parsing and semantic analysis using CUP - Access parser stack

I have a rule in my grammar such as A -> B C D E {: ...some actions... :} ; D -> /*empty*/ {: some actions using attributes of B and C :} ; To implement the actions associated with production rule of D, I need to access the parser stack. How…
0
votes
0 answers

Small Shift/Reduce conflict in CUP

I'm having a minor problem in trying to figure out how to resolve a conflict in my CUP parser project. I understand why the error is occurring, VariableDeclStar's first terminal can be ID, as well as Type, which brings up the conflict, however I…
Hacker Zen
  • 11
  • 3
0
votes
1 answer

wrong output in parser generator CUP

I have some problem when i use the JAVA parser generator CUP, and I don't know why, could somebody help me? here is the cup file: import java_cup.runtime.*; /* Terminals (tokens returned by the scanner). */ terminal FCONST; terminal…
esrrhs
  • 1
  • 2