Code Monkey home page Code Monkey logo

Comments (11)

igordejanovic avatar igordejanovic commented on June 19, 2024

There are two ways to define grammars in Arpeggio. A canonical is based on Python expressions and statements. The other is a textual PEG syntax and it is implemented using the Arpeggio itself (you can find the grammar of PEG language in the arpeggio.peg module). This implementation is based on PEG language and it requires that each rule terminates with ";" (see the rule function in the arpeggio.peg).

The PEG grammar definition is parsed using Arpeggio instantiated with the grammar from arpeggio.peg and during semantic analysis a new parser is constructed using your PEG definition. While a PEG should be more or less portable between different parsers if you want maximum performance use Python for grammar definition. Or, if you want to build a language give textX a try.

Best regards,
Igor

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

I'm not interested in python based functions as they will make it very specific to this lib.

Yes I agree for portability it should contain but it should be optional in lib itself. I mean if someone write it internally ignore that and make lib grammar reading easy.

<- can become =
Generic case ( Current version)
operation <- symbol operator (literal, functioncall);
expression <- literal operation functioncall;
expressionlist <- expression ("," expression)*;

Clean looking ( Requested version)
operation = symbol operator (literal, functioncall)
expression = literal operation functioncall
expressionlist = expression ("," expression)*

I guess I may be wrong but I found this style much everywhere so yes you can use it. Or provide some internal ways to support both. If it sounds interesting.

I want to parse PHP and similar web languages I'm not sure textX will be suited in that case or not. I don't want to parse full things only desired portion from PHP files and similar other langs. I'm not designing any lang just parsing few existing web langs.

Thanks,
Yash

from arpeggio.

igordejanovic avatar igordejanovic commented on June 19, 2024

I agree that this is cleaner looking. The current syntax is based on the original papers on PEG.

PEG language in arpeggio.peg module is just one of the languages implemented in Arpeggio. Consider it as an example of what can be done in Arpeggio and change it as you see fit.

The syntax is very easy to alter. Make a copy of module arpeggio.peg and remove ";" from the end of the rule and change "<-" to "=" in the LEFT_ARROW.
Use this altered module in place of the original arpeggio.peg.

Let me now if this works for you.

Best,
Igor

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

Cool . Thank you. Let me try it. 😄

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

I followed your instruction and created a cleanpeg module with above mention changes.

Unfortunately it didn't work
Error log
http://pastebin.com/Z7m6FND9

Used grammer

// Grammar is defined using textual specification based on PEG language.
calc_grammar = """
number = r'\d_.\d_|\d+'
factor = ("+" / "-")? (number / "(" expression ")")
term = factor (( "" / "/") factor)
expression = term (("+" / "-") term)*
calc = expression+ EOF
"""
Imp point from log..I think is
!! EOF not matched.

Please let me know if I'm doing anything wrong.

Thanks,
Yash

from arpeggio.

igordejanovic avatar igordejanovic commented on June 19, 2024

Don't have time to look more thoroughly but I think that the grammar is ambiguous now.
The lhs of the next rule is matched as the part of the previous rule. Your best bet is to leave rule termination as is (";") so that the parser will now when the rule ends. The "=" is ok.

Regards,
Igor

from arpeggio.

igordejanovic avatar igordejanovic commented on June 19, 2024

Actually, the PEG grammar can't be ambiguous and in this case the lhs will always be matched as a part of previous rule so the "=" will never be matched. Still, the best is to leave rule termination (";") or you could alter the grammar to use syntax predicates (e.g. Not) to check if the next part of the rule is not followed by the "=" and to match is only if it is not. This will ensure that lhs of the following rule is never matched by the previous rule.
Hope this helps,
Igor

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

ok with ; and <- it works perfectly. It looks we need to change little more about handling ending of rules.

I've a idea internally you can check for /n if that is possible instead of ;

Thanks,
Yash

from arpeggio.

igordejanovic avatar igordejanovic commented on June 19, 2024

Just added change on branch cleanpeg. Check this commit.

Regards,
Igor

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

Great 👍 😄 Let me try it

from arpeggio.

codeyash avatar codeyash commented on June 19, 2024

Work superbly no error reported this time. Thank you.

from arpeggio.

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.