31439

How to match the empty case in CUP parser grammar

Question:

I am using CUP to generate a parser, and I want an empty file to be an acceptable program. I have tried add the empty case to my start symbol, based off the response to a similar question <a href="https://stackoverflow.com/questions/15064980/in-cup-how-to-make-something-optional-to-parse" rel="nofollow">here</a>.

start with prog; /* The grammar rules */ prog ::= class_block:cb | class_block:cb stmts:sb | stmts:sb | // desired empty case ;

Including the desired empty case gives me the following error:

parser.java:516: error: incompatible types: Object cannot be converted to Symbol CUP$parser$result = parser.getSymbolFactory().newSymbol("prog",0, ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);

How can I modify my grammar so that the parser accepts an empty file? I am using Jflex as my lexer, and ComplexSymbolFactory as the type of the symbols.

EDIT: I've confirmed that the grammar above is the correct way to include empty. However, ComplexSymbolFactory is having problems converting the empty object to a symbol. I get this error even when running <a href="http://www2.in.tum.de/repos/cup/develop/testgrammars/minijava2/" rel="nofollow">this example</a> from the official CUP website.

Answer1:

I downloaded the .jars from a friend github project and problem solved.

You can see it's a BUG here: <a href="https://github.com/jflex-de/jflex/issues/384" rel="nofollow">https://github.com/jflex-de/jflex/issues/384</a>

Try to downgrade the version.

Recommend

  • Leap year logic confusion [duplicate]
  • mypy: Signature of “__getitem__” incompatible with supertype “Sequence”
  • \\w in PHP preg_replace covers only second byte of UTF-8 chars
  • incompatible pointer type - why?
  • Typescript Angular2 errors when returning a promise and creating an observable from it
  • C question: no warning?
  • relinking applications that use updated shared library with implicit linking?
  • Incompatible wildcard types that should be compatible [duplicate]
  • R: Join two tables (tibbles) by *list* columns
  • Calling an Objective-C class method from C++
  • AWS Java SDK is taking old version of jackson jar
  • Subclassing Sequence with proper type hints in Python
  • Capture literal brackets inside brackets in pyparsing
  • How do i convert a List to List in c#
  • java use Regular Expressions to generate a string [duplicate]
  • Load balanced Fiware Orion
  • Why is JSON.NET adding all these backslashes
  • Viewing MJPEG Video Streams
  • How can I include multiple models in one view for in a Joomla 3.x component built with Component Cre
  • Express JS Display Data By ID
  • How to eliminate warning for passing multidimensional array as const multidimensional array?
  • NSIS decompiler
  • NUnit 3.0 TestCase const custom object arguments
  • ASP.NET MVC 2 Preview 2 - display directory list rather than home/index
  • Suppressing passwd when calling sqlplus from shell script
  • C: Incompatible pointer type initializing
  • jQuery .attr() and value
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Azure Cloud Service Web Role web pages do not load
  • Cross-Platform Protobuf Serialization
  • Join two tables and save into third-sql
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • How to format a variable of double type
  • Revoking OAuth Access Token Results in 404 Not Found
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy