/* This file is part of the Maude 2 interpreter. Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ // // Parser for Maude surface syntax. // %{ #include #include // utility stuff #include "macros.hh" #include "vector.hh" // forward declarations #include "interface.hh" #include "core.hh" #include "higher.hh" #include "strategyLanguage.hh" #include "mixfix.hh" // core class definitions #include "lineNumber.hh" // front end class definitions #include "token.hh" #include "renaming.hh" #include "view.hh" #include "moduleExpression.hh" #include "fileTable.hh" #include "directoryManager.hh" #include "preModule.hh" #include "visibleModule.hh" // HACK #include "userLevelRewritingContext.hh" #include "interpreter.hh" #include "global.hh" #define clear() bubble.contractTo(0); #define store(token) bubble.append(token) #define fragClear() fragments.contractTo(0); #define fragStore(token) fragments.append(token) #define YYPARSE_PARAM parseResult #define PARSE_RESULT (*((UserLevelRewritingContext::ParseResult*) parseResult)) #define CM interpreter.getCurrentModule() #define CV interpreter.getCurrentView() void lexerInitialMode(); void lexerIdMode(); void lexerCmdMode(); void lexerFileNameMode(); void lexerStringMode(); void lexerLatexMode(); bool handleEof(); bool includeFile(const string& directory, const string& fileName, bool silent, int lineNr); void eatComment(bool firstNonWhite); Vector bubble; Vector fragments; Vector moduleExpr; Vector opDescription; stack moduleExpressions; Renaming* currentRenaming = 0; SyntaxContainer* currentSyntaxContainer = 0; SyntaxContainer* oldSyntaxContainer = 0; Int64 number; Int64 number2; static void yyerror(char *s); void cleanUpModuleExpression(); void cleanUpParser(); %} %pure_parser %union { bool yyBool; Int64 yyInt64; const char* yyString; Token yyToken; ImportModule::ImportMode yyImportMode; Interpreter::Flags yyFlags; Interpreter::PrintFlags yyPrintFlags; } %{ int yylex(YYSTYPE* lvalp); %} %token FILE_NAME_STRING UNINTERPRETED_STRING LATEX_STRING /* * Inert keywords: these are only recognized by lexer when in initial mode. */ %token KW_MOD KW_OMOD KW_VIEW %token KW_PARSE KW_NORMALIZE KW_REDUCE KW_REWRITE %token KW_LOOP KW_NARROW KW_MATCH KW_XMATCH KW_UNIFY KW_XUNIFY %token KW_EREWRITE KW_FREWRITE KW_SREWRITE %token KW_CONTINUE KW_SEARCH %token KW_SET KW_SHOW KW_ON KW_OFF %token KW_TRACE KW_BODY KW_WHOLE KW_SELECT KW_DESELECT KW_CONDITION KW_SUBSTITUTION %token KW_PRINT KW_GRAPH KW_MIXFIX KW_FLAT %token KW_WITH KW_PARENS KW_ALIASES KW_GC KW_TIME KW_STATS KW_TIMING %token KW_CMD KW_BREAKDOWN KW_BREAK KW_PATH %token KW_MODULE KW_MODULES KW_VIEWS KW_ALL KW_SORTS KW_OPS KW_VARS %token KW_MBS KW_EQS KW_RLS KW_SUMMARY KW_KINDS KW_ADVISE KW_VERBOSE %token KW_DO KW_CLEAR %token KW_PROTECT KW_EXTEND KW_INCLUDE KW_EXCLUDE %token KW_CONCEAL KW_REVEAL KW_COMPILE KW_COUNT %token KW_DEBUG KW_RESUME KW_ABORT KW_STEP KW_WHERE KW_CREDUCE KW_DUMP KW_PROFILE %token KW_NUMBER KW_RAT KW_COLOR %token SIMPLE_NUMBER %token KW_PWD KW_CD KW_PUSHD KW_POPD KW_LS KW_LOAD KW_QUIT KW_EOF /* * Start keywords: signal end of mixfix statement if following '.'. */ %token KW_ENDM KW_IMPORT KW_ENDV %token KW_SORT KW_SUBSORT KW_OP KW_OPS KW_MSGS KW_VAR KW_CLASS KW_SUBCLASS %token KW_MB KW_CMB KW_EQ KW_CEQ KW_RL KW_CRL /* * Mid keywords: need to be recognized in the middle of mixfix syntax. */ %token KW_IS KW_FROM %token KW_ARROW KW_ARROW2 KW_PARTIAL KW_IF %type ':' '=' '(' ')' '.' '<' '[' ']' ',' '|' /* * Module expression keywords. */ %token KW_LABEL KW_TO KW_COLON2 %left '+' %left '*' %type '{' '}' /* * Attribute keywords need to be recognized when parsing attributes. */ %token KW_ASSOC KW_COMM KW_ID KW_IDEM KW_ITER %token KW_LEFT KW_RIGHT KW_PREC KW_GATHER KW_METADATA KW_STRAT KW_POLY %token KW_MEMO KW_FROZEN KW_CTOR KW_LATEX KW_SPECIAL KW_CONFIG KW_OBJ KW_MSG %token KW_DITTO KW_FORMAT %token KW_ID_HOOK KW_OP_HOOK KW_TERM_HOOK /* * Command keywords need to be recognized when parsing commands. */ %token KW_IN /* * Special tokens. */ %token IDENTIFIER NUMERIC_ID ENDS_IN_DOT /* * Nonterminals that return tokens. */ %type identifier inert startKeyword startKeyword2 midKeyword attrKeyword attrKeyword2 %type token endToken endsInDot %type tokenBarColon tokenBarEqual tokenBarIf tokenBarArrow2 %type tokenBarColonTo tokenBarCommaLeft %type identityChunk tokenBarDot %type cToken cTokenBarDot cTokenBarDotColon cTokenBarIn %type cTokenBarLeftIn cTokenBarDotNumber cTokenBarDotRight %type cSimpleTokenBarDot %type cTokenBarDotCommaRight cTokenBarDotCommaNumber %type sortName sortToken startModule sortDot /* * Nonterminals that return bool. */ %type polarity select match optDebug conceal exclude arrow /* * Nonterminals that return int. */ %type optNumber /* * Nonterminals that return ImportMode. */ %type importMode /* * Nonterminals that return Flags. */ %type traceOption /* * Nonterminals that return PrintFlags. */ %type printOption %start top %% top : item { YYACCEPT; } | { PARSE_RESULT = UserLevelRewritingContext::QUIT; } ; item : module | view | directive | command ; /* * Directives. */ directive : KW_IN { lexerFileNameMode(); } FILE_NAME_STRING { int lineNr = lineNumber; eatComment(false); // eat \n so that line number is correct string directory; string fileName; if (findFile($3, directory, fileName, lineNr)) includeFile(directory, fileName, false, lineNr); } | KW_LOAD { lexerFileNameMode(); } FILE_NAME_STRING { int lineNr = lineNumber; eatComment(false); // eat \n so that line number is correct string directory; string fileName; if (findFile($3, directory, fileName, lineNr)) includeFile(directory, fileName, true, lineNr); } | KW_PWD { cout << directoryManager.getCwd() << '\n'; } | KW_CD { lexerFileNameMode(); } FILE_NAME_STRING { string directory; directoryManager.realPath($3, directory); if (!directoryManager.cd(directory)) { IssueWarning(LineNumber(lineNumber) << ": cd failed"); } } | KW_PUSHD { lexerFileNameMode(); } FILE_NAME_STRING { string directory; directoryManager.realPath($3, directory); if (directoryManager.pushd(directory) == UNDEFINED) { IssueWarning(LineNumber(lineNumber) << ": pushd failed"); } } | KW_POPD { const char* path = directoryManager.popd(); if (path != 0) cout << path << '\n'; else { IssueWarning(LineNumber(lineNumber) << ": popd failed"); } } | KW_LS { lexerStringMode(); } UNINTERPRETED_STRING { system((string("ls") + $3).c_str()); } | KW_QUIT { PARSE_RESULT = UserLevelRewritingContext::QUIT; YYACCEPT; } | KW_EOF { if(!handleEof()) { PARSE_RESULT = UserLevelRewritingContext::QUIT; } } ;