⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encode.g

📁 編譯器的accent語法分析器
💻 G
📖 第 1 页 / 共 2 页
字号:
-- ACCENT -- -- A Compiler Compiler for the Entire Class of Context-Free Languages-- -- Copyright (C) 1999  Friedrich Wilhelm Schroeer-- -- 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., 675 Mass Ave, Cambridge, MA 02139, USA.'module' encode'use'   bnf   lexinfo'export'   INIT_ENCODE   START_RULE   END_RULE   ADD_NONTERM_MEMBER   ADD_TOKEN_MEMBER   ADD_SUBPHRASE_REFERENCE   START_ALTERNATIVE   END_ALTERNATIVE   ENCODE   OpenOutput   CloseOutput   PutI   Put   Nl   LHSKEYS   LHSKEY   LHS_List   LHS   CLAUSEKEYS   CLAUSEKEY   ELEMS   GRAMMARREF   TableUpb2--------------------------------------------------------------------------------'var' LHS_List: LHSKEYS'type' LHSKEYS   keys(LHSKEYS, LHSKEY)   nil'table' LHSKEY   (Lhs: LHS, RulePrelude: ACTIONBLOCK, Clauses: CLAUSEKEYS, Pos: INT)'type' CLAUSEKEYS   clausekeys(CLAUSEKEYS, CLAUSEKEY)   nil'table' CLAUSEKEY (   Elems: ELEMS,   GrammarRef: GRAMMARREF,   Pos: INT,   RuleAnnotation: RULEANNOTATION,   Coordinate: POS,   RuleHandle: INT, Number: INT, LhsPos: INT, NextClausePos: INT   )'type' GRAMMARREF   members(MEMBERLIST)   none'type' ELEMS   elems(ELEMS, ELEM)   nil'type' ELEM   nonterm(IDENT, MEMBERANNOTATION, POS)   token(INT)   subphrase(SUBPHRASEKEY, MEMBERANNOTATION, POS)   'type' LHS   nonterm(IDENT)   subphrase(SUBPHRASEKEY)--------------------------------------------------------------------------------'var' term_base: INT'action' INIT_ENCODE'rule' INIT_ENCODE   term_base <- 50000   LHS_List <- nil   get_max_char(-> MAXCHAR)   TABLEUPB2 <- MAXCHAR   init_ana'action' ENCODE'rule' ENCODE   NontermList -> L   PC <- 1   LHS_List -> LhsKeys   calc_positions_LHSKEYS(LhsKeys)   -- OpenOutput("yygrammar.c")   PC -> N   Put("extern int c_length;")   Nl   Put("int c_length = ")   PutI(N-1)   Put(";")   Nl   Put("extern int yygrammar[];") Nl   Put("int yygrammar[] = {") Nl   Put("0,") Nl   -- xxx encode_root_rule   FieldIndex <- 1   write_code_LHSKEYS(LhsKeys)   Put("0") Nl   Put("};") Nl   -- annotation   Put("extern int yyannotation[];") Nl   Put("int yyannotation[] = {") Nl   Put("0,") Nl   FieldIndex <- 1   write_annotation_LHSKEYS(LhsKeys)   Put("0") Nl   Put("};") Nl   -- coordinates   Put("extern int yycoordinate[];") Nl   Put("int yycoordinate[] = {") Nl   Put("0,") Nl   FieldIndex <- 1   write_coordinates_LHSKEYS(LhsKeys)   Put("0") Nl   Put("};") Nl   run_ana   Put("/* only for BIGHASH (see art.c)") Nl   Put("extern int DHITS[];") Nl   Put("int DHITS[") PutI(N+1) Put("];") Nl   Put("*/") Nl   get_rulecount(-> Upb1)   TABLEUPB2 -> Upb2   Put("int TABLE[") PutI(Upb1+1) Put("][") PutI(Upb2+1) Put("];") Nl   Put("init_dirsets() {") Nl   write_dir_sets_LHSKEYS(LhsKeys)   Put("}") Nl   Nl   Put("extern int yydirset();") Nl   Put("int yydirset(i,j)") Nl   Put("   int i,j;") Nl   Put("{") Nl   Put("   return TABLE[i][j];") Nl   Put("}") Nl   write_printnames'action' get_rulecount(-> INT)--------------------------------------------------------------------------------'var' CurLhs: LHSKEY'var' CurClause: CLAUSEKEY'action' START_RULE   (IDENT, NONTERMKEY, INT, RULEKEY, ACTIONBLOCK, RULEANNOTATION, POS)'rule' START_RULE(Id, NKey, N, RKey, Prelude, Annotation, Coordinate)   RKey'RuleNumber -> R   id_to_string(Id -> Str)   start_rule (N -> RuleHandle)   RKey'RuleHandle <- RuleHandle   LhsKeyForNonterm(Id -> LhsKey)   CurLhs <- LhsKey   ClauseKey :: CLAUSEKEY   ClauseKey'Elems <- nil   CurClause <- ClauseKey   ClauseKey'RuleHandle <- RuleHandle   ClauseKey'Number <- R   RKey'Members -> Members   ClauseKey'GrammarRef <- members(Members)   ClauseKey'RuleAnnotation <- Annotation   ClauseKey'Coordinate <- Coordinate   LhsKey'RulePrelude <- Prelude   LhsKey'Clauses -> Clauses   LhsKey'Clauses <- clausekeys(Clauses,ClauseKey)'action' END_RULE'rule' END_RULE'action' ADD_NONTERM_MEMBER(IDENT, INT, MEMBERANNOTATION, POS)'rule' ADD_NONTERM_MEMBER(Id, N, Annotation, Coordinate)   append_nonterm_member(N)   CurClause -> ClauseKey   ClauseKey'Elems -> Elems   ClauseKey'Elems <-  elems(Elems, nonterm(Id, Annotation, Coordinate))'action' ADD_TOKEN_MEMBER(INT)'rule' ADD_TOKEN_MEMBER(N)   append_token_member(N)   CurClause -> ClauseKey   ClauseKey'Elems -> Elems   ClauseKey'Elems <-  elems(Elems, token(N))'action' ADD_SUBPHRASE_REFERENCE(SUBPHRASEKEY, MEMBERANNOTATION, POS)'rule' ADD_SUBPHRASE_REFERENCE(Key, Annotation, Pos)   Key'SubphraseNumber -> N   NumberOfNonterms(-> NNo)   where(N+NNo -> SNo)   append_nonterm_member(SNo)   CurClause -> ClauseKey   ClauseKey'Elems -> Elems   ClauseKey'Elems <- elems(Elems, subphrase(Key, Annotation, Pos))'action' START_ALTERNATIVE      (SUBPHRASEKEY, ALTERNATIVEKEY, GRAMMARREF, RULEANNOTATION, POS)'rule' START_ALTERNATIVE(SKey, AKey, GrammarRef, Annotation, Coordinate)   SKey'SubphraseNumber -> SubphraseNumber   NumberOfNonterms(-> NNont)   where(SubphraseNumber+NNont -> SNo)   AKey'AlternativeNumber -> N   NumberOfRules(-> NRules)   where(N+NRules -> ANo)   start_rule(SNo -> RuleHandle)   AKey'RuleHandle <- RuleHandle   LhsKeyForSubphrase(SKey -> LhsKey)   CurLhs <- LhsKey   ClauseKey :: CLAUSEKEY   AKey'ClauseKey <- ClauseKey   ClauseKey'Elems <- nil   CurClause <- ClauseKey   ClauseKey'RuleHandle <- RuleHandle   ClauseKey'Number <- ANo   ClauseKey'GrammarRef <- GrammarRef   ClauseKey'RuleAnnotation <- Annotation   ClauseKey'Coordinate <- Coordinate   LhsKey'Clauses -> Clauses   LhsKey'Clauses <- clausekeys(Clauses,ClauseKey)'action' END_ALTERNATIVE'rule' END_ALTERNATIVE------------------------------------------------------------------------------------ Interface to Rule Analysis---- Init'action' init_ana-- Grammar Definition'action' start_rule (Lhs: INT -> RuleId: INT)'action' append_nonterm_member(Member: INT)'action' append_token_member(Member: INT)-- Analysis'action' run_ana-- compute director set for each rule-- Access Result'action' get_dirset(RuleId: INT -> DirSet: SET)-- sets:'type' SET'action' emit_set(SET)------------------------------------------------------------------------------------ Emit Results--'action' OpenOutput(STRING)'action' CloseOutput'action' Put(STRING)'action' PutI(INT)'action' Nl--------------------------------------------------------------------------------'var' PC: INT'var' LastClauseKey: CLAUSEKEY'var' CurLhsPos: INT'action' calc_positions_LHSKEYS(LHSKEYS)   'rule' calc_positions_LHSKEYS(keys(Keys,Key))      calc_positions_LHSKEYS(Keys)      calc_positions_LHSKEY(Key)   'rule' calc_positions_LHSKEYS(nil)'action' calc_positions_LHSKEY(LHSKEY)   'rule' calc_positions_LHSKEY(Key)      Key'Clauses -> Clauses      PC -> Pos      Key'Pos <- Pos      CurLhsPos <- Pos      calc_positions_CLAUSEKEYS(Clauses)      LastClauseKey -> LastClause      LastClause'NextClausePos <- 0'action' calc_positions_CLAUSEKEYS(CLAUSEKEYS)   'rule' calc_positions_CLAUSEKEYS(clausekeys(Clauses, Clause))      calc_positions_CLAUSEKEYS(Clauses)      calc_positions_CLAUSEKEY(Clause)   'rule' calc_positions_CLAUSEKEYS(nil)'action' calc_positions_CLAUSEKEY(CLAUSEKEY)   'rule' calc_positions_CLAUSEKEY(Key)      PC -> Pos      Key'Elems -> Elems      Length(Elems -> N)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -