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
5
votes
1 answer

Parse tree generation with Java CUP

I am using CUP with JFlex to validate expression syntax. I have the basic functionality working: I can tell if an expression is valid or not. Next step is to implement simple arithmetic operations, such as "add 1". For example, if my expression is…
user443854
  • 7,096
  • 13
  • 48
  • 63
5
votes
1 answer

Shift/reduce conflict in java cup - dangling else issue

I am getting the following error: Warning : *** Shift/Reduce conflict found in state #116 between Statement ::= Matched (*) and Unmatched ::= IF LPAREN Condition RPAREN Matched (*) ELSE Unmatched and Matched ::= IF LPAREN Condition RPAREN…
Shibby
  • 53
  • 1
  • 4
4
votes
1 answer

How to solve SHIFT/REDUCE conflict - in parser generator

I need help to solve this one and explanation how to deal with this SHIFT/REDUCE CONFLICTS in future. I have some conflicts between few states in my cup file. Grammer look like this: I have conflicts between "(" [ActPars] ")" states. 1. Statement =…
Milan Bojovic
  • 199
  • 4
  • 10
3
votes
1 answer

Setting up Cup/JLex parsing properly

I have a very basic lexer here: import java_cup.runtime.*; import java.io.IOException; %% %class AnalyzerLex %function next_token %type java_cup.runtime.Symbol %unicode //%line //%column // %public %final // %abstract %cupsym…
user2192677
  • 327
  • 1
  • 5
  • 12
2
votes
0 answers

How to express optional tokens in CUP

I'm using java CUP to generate a LARL(1) parser for a tiny programming language. Is there a compact form to express optional non-terminals in a rule? For example, in the following rule statement ::= IDENT WHITE EQ WHITE value WHITE SEMICOLON | …
2
votes
1 answer

How to define a syntax that uses multiple dashes for nested "if" instructions?

I'm trying to create a Syntax Analyzer in Java (using CUP) that could recognise this piece of code: if ¿b? then ~ a = 2; ~ if ¿b && c? then ~ ~ a = 3; else ~ a = 4; My productions used by the "if" statement are these that follow: Instr ::= ... …
2
votes
1 answer

CUP parser returns syntax error for a valid input

I'm trying to write a very simple parser. I'm using JFlex with Java CUP. Here's my code: LEX file: import java_cup.runtime.*; %% %class Lexer %line %column %cup %{ …
Plex
  • 21
  • 1
  • 2
2
votes
1 answer

JFlex with CUP compile errors

I am trying to run an example provided by CUP: Parsing directly to XML. I stored the 'Minijava Grammar' in a file named minijava.cup and the scanner into a file named xml.flex. I ran JFlex to obtain Lexer.java from the xml.flex file. After that I…
Dragos Geornoiu
  • 527
  • 2
  • 8
  • 17
2
votes
2 answers

Concatenation shift-reduce conflict

I have a simple grammar for JavaCUP's LR(1) parser that recognises concatenation expressions of identifiers and strings. I also want to add some empty function calls as a possible concatenation argument. However, when I try that, it leads to a…
2
votes
1 answer

Is it possible to test a lexer made in JFlex without writing a parser?

I am beginning to use JFlex and I want to try to write a lexer first, and then move onto the parser. However, it seems like there is no way to test your JFlex lexer without writing a parser in CUP as well. All I want to do is write a lexer, give it…
John Smith
  • 21
  • 2
2
votes
2 answers

Change Object type in Java CUP

I am creating a parser using CUP together with JFLex to create the scanner. I was following this link Parse tree generation with Java CUP but I got stuck because I do not know how to change the type to Node because by default the type is Object. I…
sc1234
  • 127
  • 3
  • 10
2
votes
1 answer

shift/reduce Error with Cup

Hi i am writing a Parser for a Programming language my university uses, with jflex and Cup I started with just the first basic structures such as Processes an Variable Declarations. I get the following Errors Warning : *** Shift/Reduce conflict…
2
votes
3 answers

Parse EOF token in CUP

I'm having trouble making my CUP parser parse the EOF token. I read in the documentation that using the %cup flag in my Jflex code implies that there is something present like this: %eofval{ return new…
Christophe De Troyer
  • 2,852
  • 3
  • 30
  • 47
2
votes
1 answer

CUP LALR parser generator: warning: production never reduced

this is the first time i am using CUP parser and I keep getting the following error: "warning: * production "..." never used. I can't figure out what is wrong, please help. see code and eror log attached below, thanks. package adtl; import…
user2778318
  • 73
  • 2
  • 5
2
votes
0 answers

shift/reduce conflict in cup parser

I wrote this grammar: /* Precedences */ precedence left UMINUS; precedence left ID; Expr ::= ID:e | NUM:e | Expr:e1 TIMES Expr:e2 | LP Expr:e RP ; Call ::= ID:id LP ExprComma:args…
GO VEGAN
  • 1,113
  • 3
  • 15
  • 44
1
2 3 4 5 6