bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PHP support


From: Chris Morley
Subject: PHP support
Date: Thu, 28 Jun 2012 13:35:06 +0100

Hi All,

I have a project where I am evaluating moving a parser from C++ to PHP.

Google found me https://github.com/scfc/bison-php

I couldn't get it to compile from the source so I started with 2.5.1 and patched it, taking the PHP skeleton files from scfc/bison_php

I chose to handle the $ & @ in PHP by adding tri/quad graphs to "scan-code.l".

.y -> output
$$$ -> $
$$$$ -> $$
@@@ -> @

Thus the Bison rules remain untouched and if you need a PHP variable in a rule the use '$$$variable' or '$$$$variablevariable'.

e.g.
(y)
exp: '(' exp ')'        { $$ = $2;  $$$myvar->func($2);}

(php)
{ $yyval = ($yystack->valueAt (3-(2))); $myvar->func(($yystack->valueAt (3-(2)))); };

This seems tidier to me than the PHP specific ifs in the scfc/bison_php code.

It might be helpful to add this to the release with a argument to enable it.

I don't propose PHP should be added to the main distribution but support for $/@ languages doesn't seem hard to include - then it is up to the user to take it from there.

Hope this helps someone else. If I do any development on the skeleton I'll make that available.

Chris

---- 8< -------- 8< -------- 8< -------- 8< ----

--- bison-2.5.1\src\scan-code.l 2012-03-30 13:39:20.000000000 +-0100
+++ bison-2.5.1\src\scan-code.l 2012-06-28 13:05:51.000000000 +-0100
@@ -177,12 +177,15 @@
    BEGIN SC_LINE_COMMENT;
  }
}

<SC_RULE_ACTION>
{
+  "$$$" obstack_sgrow (&obstack_for_string, "$][");
+  "$$$$" obstack_sgrow (&obstack_for_string, "$][$][");
+  "@@@" obstack_sgrow (&obstack_for_string, "@@");
  "$"("<"{tag}">")?{ref}  {
    ref_tail_fields = 0;
    handle_action_dollar (self->rule, yytext, *loc);
    if (ref_tail_fields) {
      obstack_sgrow (&obstack_for_string, ref_tail_fields);
    }

---- 8< -------- 8< -------- 8< -------- 8< ----

--- bison-2.5.1\src\getargs.c   2012-05-09 08:57:58.000000000 +-0100
+++ bison-2.5.1\src\getargs.c   2012-06-28 12:12:27.000000000 +-0100
@@ -69,12 +69,13 @@
                    | warnings_other;

static struct bison_language const valid_languages[] = {
  { "c", "c-skel.m4", ".c", ".h", true },
  { "c++", "c++-skel.m4", ".cc", ".hh", true },
  { "java", "java-skel.m4", ".java", ".java", false },
+  { "php", "php-skel.m4", ".php", ".php", false },
  { "", "", "", "", false }
};

int skeleton_prio = default_prio;
const char *skeleton = NULL;
int language_prio = default_prio;

---- 8< -------- 8< -------- 8< -------- 8< ----






reply via email to

[Prev in Thread] Current Thread [Next in Thread]