Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.216.473 Times

LLg 1.07 Alpha

  Date Added: June 02, 2010  |  Visits: 784

LLg 1.07

Report Broken Link
Printer Friendly Version


Product Homepage
Download (93 downloads)



LLg is a recursive descent parser generator. SYNOPSIS use LLg; @tokens = ( ADDOP => [-+], LEFTP => [(], RIGHTP => [)], INTEGER => 0|[1-9][0-9]*, ); $reader = Lex->new(@tokens); $ADDOP->debug; $expr = And->new(($factor, Any->new($ADDOP, $factor)), sub { shift(@_); my $result = shift(@_); my ($op, $integer); while ($#_ >= 0) { ($op, $integer) = (shift(@_), shift(@_)); if ($op eq +) { $result += $integer; } else { $result -= $integer; } } $result; }); $factor = Or->new($INTEGER, $parexp); $parexp = And->new($LEFTP, $expr, $RIGHTP, sub { $_[2] }); print STDERR "Type your arithmetic expression: "; print "Result: ", $expr->next, "n"; Creating parsers by hand is tedious even for simple languages. This activity can be automated by parser-generators - yacc is a well-known example. But using such tools is quite demanding and requires a reasonable knowlege of the principles of syntactic analysis. LLg is a set of Perl5 packages which allow the generation of recursive descent parsers for context-free grammars. LLg is provided with the packages Lex and Token which are object-based. The use of these packages presupposes that you know how to write a BNF grammar and that you know (just a little) about programming in Perl. Specifying the parser does not require any extension to Perl syntax. The specification is carried out entirely in standard Perl, be it definition of tokens, syntactic rules or associated semantic actions. LLg allows the easy specification of translation schemes, that is parsers for which the semantic action is given by actions directly associated with each production. The packages Token and LLg allow respectively the definition of objects corresponding to terminals (tokens) and non-terminals of the grammar. Lex handles the reading and "eating" of tokens in the input stream. Before using these packages you need to define a BNF grammar without left recursion (an LL(1) grammar). Given this, making the parser consists in: 1. create a lexical analyser by specifying the terminals, 2. create a parser (syntactic analyser) by creating a LLg object (or, more precisely, one of the packages which inherits from LLg) for each non-terminal. 3. define the semantics by associating an anonymous function with each LLg object. Take as an example arithmetic expressions having only + and - as operators. In the Camel book we find the following grammar: expr ::= factor { ADDOP factor } ADDOP ::= + | - factor ::= NUMBER | ( expr ) Creating the parser for this language involves defining a lexical analyser and a syntactic analyser. The lexical analyser is defined thusly: @tokens = ( ADDOP => [-+], LEFTP => [(], RIGHTP => [)], INTEGER => [1-9][0-9]*, ); $reader = Lex->new(@tokens); The argument of the method new() is a list of pairs: the identity of the terminal and the corresponding regular expression. Each such pair leads to the creation of a terminal of type Token. The package LLg is the base package of a set : And, Any, Do, Hook, Opt, Or. These packages allow the creation of the different types of rules normally found in context-free grammars. We use a prefix notation with the following equivalences. A | B Or->new($A, $B) symbol A or symbol B A B And->new($A, $B) symbol A followed by symbol B { A } Any->new($A) arbitrary number of A [ A ] Opt->new($A) zero or one occurrence of A The rules in our example are given by creating the following objects: $expr = And->new(($factor, Any->new($ADDOP, $factor)); $factor = Or->new($NUMBER, $parexp); $parexp = And->new($LEFTP, $expr, $RIGHTP); The arguments of the method new() are references to LLg or Token objects. (The written order of the rule has no significance, since scalars can be references before they are assigned a value. These references are resolved when each object is used. As the example shows, references can be obtained to the objects returned by a rule.) The semantics is defined by putting an anonymous function at the end of the list of object references. The anonymous function uses information associated with the objects. This information is transmitted by positional parameters (the array @_). The nth argument designates the result of the nth parameter of the method new(). Information returned by the function is associated with the object and is transmitted by means of positional parameters wherever the object is used. In our example we will have: $expr = And->new(($factor, Any->new($ADDOP, $factor)), sub { shift(@_); my $result = shift(@_); my ($op, $integer); while ($#_ >= 0) { ($op, $integer) = (shift(@_), shift(@_)); if ($op eq +) { $result += $integer; } else { $result -= $integer; } } $result; }); $factor = Or->new($INTEGER, $parexp); $parexp = And->new($LEFTP, $expr, $RIGHTP, sub { $_[2] }); print STDERR "Type your arithmetic expression: "; print "Result: ", $expr->next, "n"; When an integer is recognised it is returned by the anonymous function associated with the object $factor. This returned information (or, more precisely, synthesised, since it comes from a a terminal and is transmitted to non-terminals) is also available in the anonymous function associated with the object $expr. The information returned by the following object is used to calculate the value of the arithmetical expression. The analyser is started up by applying the method next() to the axiom of the grammar: $expr->next; By default the input for analysis is read from the standard input. The example parser analyses and interprets individual expressions typed in at the terminal. The example calculator.pl delivered with the LLg package shows how to create an input loop allowing reading and interpretation of arbitrary many expressions. The parser generator can be used for other purposes than the analysis of a character stream. Given that the packages Lex, LLg and Token, it is perfectly possible to define terminals which are objects i.e. instances of a class other than Token. Each new package defining terminals ought at least to have the methods status() and next() - see vonkoch.pl as an example..

Requirements: No special requirements
Platforms: Linux
Keyword: Addop Anonymous Function Expr Factor Integer Leftp Llg New Object Parser Recursive Descent Recursive Descent Parser Result Rightp
Users rating: 0/10

License: Freeware Size: 20.48 KB
USER REVIEWS
More Reviews or Write Review


LLG 1.07 RELATED
Development Tools  -  Temporary (or anonymous) function handles for ML 6
The anonymous function handle feature of ML 7 is a long-needed feature, and one that I have longed for since I began writing scripts in early ML 6.Unfortunately, I am still forced to use ML 6 most of the time, so I came up with a way to create...
10 KB  
Libraries  -  Math::Expr 0.2
Math::Expr is a Perl module that parses mathematical expressions. SYNOPSIS require Math::Expr; $p=new Math::Expr; $e=$p->Parse("a+4*b-d/log(s)+f(d,e)"); Parses mathematical expressions into a tree structure. The expressions may contain...
13.31 KB  
Programming  -  Scheme2Js 20060718
Scheme2Js is a Scheme to Javascript compiler. While some effort has been spent on being as close as possible to R5rs, we concentrated mainly on efficiency. Usually Scheme2Js produces Javascript code, that is comparable to hand-written code. In...
78.85 KB  
Science  -  Similarity Evaluator 0.0.01
Similarity Evaluator is a tool to analyse similarity function implementations and algorithms, where is possible to compare several APIs on performance, best result, similarity and discernability values.
2.67 MB  
Programming  -  The Nice Programming Language 1.0
New object-oriented programming language based on Java, with the following advanced features: parametric types, anonymous functions, multi-methods, tuples, optional parameters.Nice also detects more errors during compilation (null pointers, casts).
1.29 MB  
Miscellaneous  -  Extensible object to XML converter 1.0
This function generates XML for any Python object through recursive functions. It is easy to add specific handlers for your own object types for more complex output options.
 
Development Tools  -  PATEL TEJA EQUATION OF STATE 1.0
With this equation we can find the specific volume of a real gas, in a rank of pressures, isothermally, knowing the factor acentrico the compound. The equation this in function to the understandability factor
10 KB  
Networking  -  Anonymous Posting 1.3
It allows anonymous users/readers to write their own posts, writing is protected with reCAPTCHA. Plugin can be used for some kind of message board or public forum, you can configure comments under anonymous posts. Writing is avaialbe via special...
10 KB  
Development Tools  -  LMFnlsq - Solution of nonlinear least squares 1.0
The function The LMFnlsq.m serves for finding optimal solution of an overdetermined system of nonlinear equations in the least-squares sense. The standard Levenberg- Marquardt algorithm was modified by Fletcher and coded in FORTRAN many years ago...
870.4 KB  
Networking  -  Growyn Search 1.0.2
Growyn Search allows you to add a widget with a growyn searchbox on your site. You can also get the searchbox by calling the growyn_search() function. (See installation or the Growyn Search plugin homepage.) You can easily choose if the search...
10 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB