From 96786829c23cf56a776f6ec022fdbe18a0732add Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Thu, 10 Sep 2015 18:29:09 -0700 Subject: [PATCH] Convert to C++ Bison output We have to step up to a GLR parser to do this without exceptions (for no reason other than Bison happens to use exceptions for the LALR(1) template and not for the GLR one), but this should let us smooth out integration going forward. Change-Id: Iff44662914b4a65dfa5612d07c3a1ede07e6e4a9 Signed-off-by: Casey Dahlin --- tools/aidl/aidl_language.cpp | 3 ++- tools/aidl/aidl_language_l.l | 35 ++++++++++++++++++----------------- tools/aidl/aidl_language_y.y | 18 ++++++++++-------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/tools/aidl/aidl_language.cpp b/tools/aidl/aidl_language.cpp index 5252920557553..e2540658b6200 100644 --- a/tools/aidl/aidl_language.cpp +++ b/tools/aidl/aidl_language.cpp @@ -1,4 +1,5 @@ #include "aidl_language.h" +#include "aidl_language_y.hpp" #include #include #include @@ -74,7 +75,7 @@ bool ParseState::OpenFileFromDisk() { } int ParseState::RunParser() { - int ret = yyparse(this); + int ret = yy::parser(this).parse(); free((void *)g_currentPackage); g_currentPackage = NULL; diff --git a/tools/aidl/aidl_language_l.l b/tools/aidl/aidl_language_l.l index 953e3709eb668..b8e53a83ebd88 100644 --- a/tools/aidl/aidl_language_l.l +++ b/tools/aidl/aidl_language_l.l @@ -1,6 +1,6 @@ %{ #include "aidl_language.h" -#include "aidl_language_y.h" +#include "aidl_language_y.hpp" #include "search_path.h" #include #include @@ -39,6 +39,7 @@ static void do_package_statement(const char* importText); %option noyywrap %option reentrant %option bison-bridge +%option bison-locations %x COPYING LONG_COMMENT @@ -65,13 +66,13 @@ idvalue (0|[1-9][0-9]*) \**\/ { BEGIN(INITIAL); } ^{whitespace}?import{whitespace}[^ \t\r\n]+{whitespace}?; { - SET_BUFFER(IMPORT); - return IMPORT; + SET_BUFFER(yy::parser::token::IMPORT); + return yy::parser::token::IMPORT; } ^{whitespace}?package{whitespace}[^ \t\r\n]+{whitespace}?; { do_package_statement(yytext); - SET_BUFFER(PACKAGE); - return PACKAGE; + SET_BUFFER(yy::parser::token::PACKAGE); + return yy::parser::token::PACKAGE; } <> { yyterminate(); } @@ -90,25 +91,25 @@ idvalue (0|[1-9][0-9]*) = { SET_BUFFER('='); return '='; } /* keywords */ -parcelable { SET_BUFFER(PARCELABLE); return PARCELABLE; } -interface { SET_BUFFER(INTERFACE); return INTERFACE; } -in { SET_BUFFER(IN); return IN; } -out { SET_BUFFER(OUT); return OUT; } -inout { SET_BUFFER(INOUT); return INOUT; } -oneway { SET_BUFFER(ONEWAY); return ONEWAY; } +parcelable { SET_BUFFER(yy::parser::token::PARCELABLE); return yy::parser::token::PARCELABLE; } +interface { SET_BUFFER(yy::parser::token::INTERFACE); return yy::parser::token::INTERFACE; } +in { SET_BUFFER(yy::parser::token::IN); return yy::parser::token::IN; } +out { SET_BUFFER(yy::parser::token::OUT); return yy::parser::token::OUT; } +inout { SET_BUFFER(yy::parser::token::INOUT); return yy::parser::token::INOUT; } +oneway { SET_BUFFER(yy::parser::token::ONEWAY); return yy::parser::token::ONEWAY; } -{brackets}+ { SET_BUFFER(ARRAY); return ARRAY; } -{idvalue} { SET_BUFFER(IDVALUE); return IDVALUE; } -{identifier} { SET_BUFFER(IDENTIFIER); return IDENTIFIER; } +{brackets}+ { SET_BUFFER(yy::parser::token::ARRAY); return yy::parser::token::ARRAY; } +{idvalue} { SET_BUFFER(yy::parser::token::IDVALUE); return yy::parser::token::IDVALUE; } +{identifier} { SET_BUFFER(yy::parser::token::IDENTIFIER); return yy::parser::token::IDENTIFIER; } {identifier}\<{whitespace}*{identifier}({whitespace}*,{whitespace}*{identifier})*{whitespace}*\> { - SET_BUFFER(GENERIC); return GENERIC; } + SET_BUFFER(yy::parser::token::GENERIC); return yy::parser::token::GENERIC; } /* syntax error! */ . { printf("UNKNOWN(%s)", yytext); yylval->buffer.lineno = yylineno; - yylval->buffer.token = IDENTIFIER; + yylval->buffer.token = yy::parser::token::IDENTIFIER; yylval->buffer.data = strdup(yytext); - return IDENTIFIER; + return yy::parser::token::IDENTIFIER; } %% diff --git a/tools/aidl/aidl_language_y.y b/tools/aidl/aidl_language_y.y index 90fd58c5353c5..7a2b78514ba4a 100644 --- a/tools/aidl/aidl_language_y.y +++ b/tools/aidl/aidl_language_y.y @@ -1,26 +1,23 @@ %{ #include "aidl_language.h" +#include "aidl_language_y.hpp" #include #include #include -int yyerror(ParseState* ps, char* errstr) -{ - ps->ReportError(errstr); - return 1; -} - -int yylex(lexer_type *, void *); +int yylex(lexer_type *, yy::parser::location_type *l, void *); static int count_brackets(const char*); -#define YYLEX_PARAM ps->Scanner() +#define lex_scanner ps->Scanner() %} %parse-param { ParseState* ps } +%lex-param { void *lex_scanner } %pure-parser +%skeleton "glr.cc" %token IMPORT %token PACKAGE @@ -339,3 +336,8 @@ static int count_brackets(const char* s) } return n; } + +void yy::parser::error(const yy::parser::location_type& l, const std::string& errstr) +{ + ps->ReportError(errstr); +}