Code Monkey home page Code Monkey logo

Comments (8)

atorstling avatar atorstling commented on June 28, 2024

Try parser.nextIs(EndToken.get()). The end token is unparseable by design and is used by LexParser to assure that the entire input is consumed when calling parseFully. If you are writing statements and not expressions, you will most likely want to do this

from bychan.

atorstling avatar atorstling commented on June 28, 2024

In the minilang example, the semicolon is simply a separator between sub-expressions, and the whole language is expression based. If you use this approach, you won't need to check for an end token. This is due to the fact that the end token has LBP 0. When you parse the whole expression using LexParser, it will continue until it finds a token with LBP <=0. If you call parseFully it will also check that only the end token remains as i mentioned above.

from bychan.

danvim avatar danvim commented on June 28, 2024

@atorstling "The end token is unparseable by design" I thought I read that part correctly. I did try parser.nextIs(EndToken.get()) before, but the IDE simply says no instance(s) of type variable(s) N exist so that EndToken<N> conforms to TokenKey I'm sorry, I may not be that advance in Java to figure out a solution. :(

from bychan.

atorstling avatar atorstling commented on June 28, 2024

Ah, my bad, let me get back to you when I'm at a computer.

from bychan.

danvim avatar danvim commented on June 28, 2024

http://stackoverflow.com/questions/40949670/is-there-a-way-to-check-if-next-token-is-end

from bychan.

atorstling avatar atorstling commented on June 28, 2024

Thanks for the stackoverflow post. That was an omission, see the stackoverflow. Fix applied.

from bychan.

atorstling avatar atorstling commented on June 28, 2024

Hey @danvim, I don't know how to reach you, do you have gitter? Anyway, I decided to clean up a lot of cruft in Bychan, and broke backwards compatibility while doing it. Basically as the end of the README says, the support for statements was not that great. The Repl and LexParser more or less assumed that you would always start by parsing an expression. I've changed that assumption now and made the API against the Parser identical irrespective if you are parsing from a token callback or not. So you are now able to move code out of token callbacks into functions and call functions in a recursive descend fashion. Check ReadmeExamples::statements for an example. I hope this makes it easier for you to parse statements, certainly if your topmost production is a statement.

from bychan.

danvim avatar danvim commented on June 28, 2024

@atorstling Thanks, I'll check that out very soon. :)

from bychan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.